psub.pas 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Daniel Mantione
  4. Does the parsing and codegeneration at subroutine level
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit psub;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. node,
  24. symdef,cgbase;
  25. type
  26. tcgprocinfo=class(tprocinfo)
  27. { code for the subroutine as tree }
  28. code : tnode;
  29. { list to store the procinfo's of the nested procedures }
  30. nestedprocs : tlinkedlist;
  31. constructor create(aparent:tprocinfo);override;
  32. destructor destroy;override;
  33. procedure generate_code;
  34. procedure resetprocdef;
  35. procedure add_to_symtablestack;
  36. procedure remove_from_symtablestack;
  37. procedure parse_body;
  38. end;
  39. procedure printnode_reset;
  40. { reads the declaration blocks }
  41. procedure read_declarations(islibrary : boolean);
  42. { reads declarations in the interface part of a unit }
  43. procedure read_interface_declarations;
  44. implementation
  45. uses
  46. { common }
  47. cutils,
  48. { global }
  49. globtype,globals,tokens,verbose,comphook,
  50. systems,
  51. { aasm }
  52. cpubase,cpuinfo,aasmbase,aasmtai,
  53. { symtable }
  54. symconst,symbase,symsym,symtype,symtable,defutil,
  55. paramgr,
  56. ppu,fmodule,
  57. { pass 1 }
  58. nutils,nbas,nld,ncal,ncon,nflw,nadd,ncnv,nmem,
  59. pass_1,
  60. {$ifdef state_tracking}
  61. nstate,
  62. {$endif state_tracking}
  63. { pass 2 }
  64. {$ifndef NOPASS2}
  65. pass_2,
  66. {$endif}
  67. { parser }
  68. scanner,
  69. pbase,pstatmnt,pdecl,pdecsub,pexports,
  70. { codegen }
  71. tgobj,rgobj,
  72. ncgutil
  73. {$ifndef NOOPT}
  74. {$ifdef i386}
  75. ,aopt386
  76. {$else i386}
  77. ,aoptcpu
  78. {$endif i386}
  79. {$endif}
  80. ;
  81. {****************************************************************************
  82. PROCEDURE/FUNCTION BODY PARSING
  83. ****************************************************************************}
  84. procedure initializevars(p:tnamedindexitem;arg:pointer);
  85. var
  86. b : tblocknode;
  87. begin
  88. if tsym(p).typ<>varsym then
  89. exit;
  90. with tvarsym(p) do
  91. begin
  92. if assigned(defaultconstsym) then
  93. begin
  94. b:=tblocknode(arg);
  95. b.left:=cstatementnode.create(
  96. cassignmentnode.create(
  97. cloadnode.create(tsym(p),tsym(p).owner),
  98. cloadnode.create(defaultconstsym,defaultconstsym.owner)),
  99. b.left);
  100. end;
  101. end;
  102. end;
  103. function block(islibrary : boolean) : tnode;
  104. begin
  105. { parse const,types and vars }
  106. read_declarations(islibrary);
  107. current_procinfo.handle_body_start;
  108. { do we have an assembler block without the po_assembler?
  109. we should allow this for Delphi compatibility (PFV) }
  110. if (token=_ASM) and (m_delphi in aktmodeswitches) then
  111. include(current_procdef.procoptions,po_assembler);
  112. { Handle assembler block different }
  113. if (po_assembler in current_procdef.procoptions) then
  114. begin
  115. block:=assembler_block;
  116. exit;
  117. end;
  118. {Unit initialization?.}
  119. if (
  120. assigned(current_procdef.localst) and
  121. (current_procdef.localst.symtablelevel=main_program_level) and
  122. (current_module.is_unit)
  123. ) or
  124. islibrary then
  125. begin
  126. if (token=_END) then
  127. begin
  128. consume(_END);
  129. { We need at least a node, else the entry/exit code is not
  130. generated and thus no PASCALMAIN symbol which we need (PFV) }
  131. if islibrary then
  132. block:=cnothingnode.create
  133. else
  134. block:=nil;
  135. end
  136. else
  137. begin
  138. if token=_INITIALIZATION then
  139. begin
  140. { The library init code is already called and does not
  141. need to be in the initfinal table (PFV) }
  142. if not islibrary then
  143. current_module.flags:=current_module.flags or uf_init;
  144. block:=statement_block(_INITIALIZATION);
  145. end
  146. else if (token=_FINALIZATION) then
  147. begin
  148. if (current_module.flags and uf_finalize)<>0 then
  149. block:=statement_block(_FINALIZATION)
  150. else
  151. begin
  152. { can we allow no INITIALIZATION for DLL ??
  153. I think it should work PM }
  154. block:=nil;
  155. exit;
  156. end;
  157. end
  158. else
  159. begin
  160. { The library init code is already called and does not
  161. need to be in the initfinal table (PFV) }
  162. if not islibrary then
  163. current_module.flags:=current_module.flags or uf_init;
  164. block:=statement_block(_BEGIN);
  165. end;
  166. end;
  167. end
  168. else
  169. begin
  170. block:=statement_block(_BEGIN);
  171. if symtablestack.symtabletype=localsymtable then
  172. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}initializevars,block);
  173. end;
  174. if (current_procdef.localst.symtablelevel=main_program_level) and
  175. (not current_module.is_unit) then
  176. begin
  177. { there's always a call to FPC_DO_EXIT in the main program }
  178. include(current_procinfo.flags,pi_do_call);
  179. end;
  180. end;
  181. {****************************************************************************
  182. PROCEDURE/FUNCTION COMPILING
  183. ****************************************************************************}
  184. procedure printnode_reset;
  185. begin
  186. assign(printnodefile,treelogfilename);
  187. {$I-}
  188. rewrite(printnodefile);
  189. {$I+}
  190. if ioresult<>0 then
  191. begin
  192. Comment(V_Error,'Error creating '+treelogfilename);
  193. exit;
  194. end;
  195. close(printnodefile);
  196. end;
  197. procedure printnode_procdef(pd:tprocdef);
  198. begin
  199. assign(printnodefile,treelogfilename);
  200. {$I-}
  201. append(printnodefile);
  202. if ioresult<>0 then
  203. rewrite(printnodefile);
  204. {$I+}
  205. if ioresult<>0 then
  206. begin
  207. Comment(V_Error,'Error creating '+treelogfilename);
  208. exit;
  209. end;
  210. writeln(printnodefile);
  211. writeln(printnodefile,'*******************************************************************************');
  212. writeln(printnodefile,current_procdef.fullprocname(false));
  213. writeln(printnodefile,'*******************************************************************************');
  214. printnode(printnodefile,pd.code);
  215. close(printnodefile);
  216. end;
  217. function generate_initialize_block:tnode;
  218. var
  219. srsym : tsym;
  220. para : tcallparanode;
  221. newstatement : tstatementnode;
  222. htype : ttype;
  223. begin
  224. result:=internalstatements(newstatement,true);
  225. if assigned(current_procdef._class) then
  226. begin
  227. { a constructor needs a help procedure }
  228. if (current_procdef.proctypeoption=potype_constructor) then
  229. begin
  230. if is_class(current_procdef._class) then
  231. begin
  232. if (cs_implicit_exceptions in aktmoduleswitches) then
  233. include(current_procinfo.flags,pi_needs_implicit_finally);
  234. srsym:=search_class_member(current_procdef._class,'NEWINSTANCE');
  235. if assigned(srsym) and
  236. (srsym.typ=procsym) then
  237. begin
  238. { if vmt<>0 then newinstance }
  239. addstatement(newstatement,cifnode.create(
  240. caddnode.create(unequaln,
  241. load_vmt_pointer_node,
  242. cnilnode.create),
  243. cassignmentnode.create(
  244. ctypeconvnode.create_explicit(
  245. load_self_pointer_node,
  246. voidpointertype),
  247. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_vmt_pointer_node)),
  248. nil));
  249. end
  250. else
  251. internalerror(200305108);
  252. end
  253. else
  254. if is_object(current_procdef._class) then
  255. begin
  256. htype.setdef(current_procdef._class);
  257. htype.setdef(tpointerdef.create(htype));
  258. { parameter 3 : vmt_offset }
  259. { parameter 2 : address of pointer to vmt,
  260. this is required to allow setting the vmt to -1 to indicate
  261. that memory was allocated }
  262. { parameter 1 : self pointer }
  263. para:=ccallparanode.create(
  264. cordconstnode.create(current_procdef._class.vmt_offset,s32bittype,false),
  265. ccallparanode.create(
  266. ctypeconvnode.create_explicit(
  267. load_vmt_pointer_node,
  268. voidpointertype),
  269. ccallparanode.create(
  270. ctypeconvnode.create_explicit(
  271. load_self_pointer_node,
  272. voidpointertype),
  273. nil)));
  274. addstatement(newstatement,cassignmentnode.create(
  275. ctypeconvnode.create_explicit(
  276. load_self_pointer_node,
  277. voidpointertype),
  278. ccallnode.createintern('fpc_help_constructor',para)));
  279. end
  280. else
  281. internalerror(200305103);
  282. { if self=nil then exit
  283. calling fail instead of exit is useless because
  284. there is nothing to dispose (PFV) }
  285. addstatement(newstatement,cifnode.create(
  286. caddnode.create(equaln,
  287. load_self_pointer_node,
  288. cnilnode.create),
  289. cexitnode.create(nil),
  290. nil));
  291. end;
  292. { maybe call BeforeDestruction for classes }
  293. if (current_procdef.proctypeoption=potype_destructor) and
  294. is_class(current_procdef._class) then
  295. begin
  296. srsym:=search_class_member(current_procdef._class,'BEFOREDESTRUCTION');
  297. if assigned(srsym) and
  298. (srsym.typ=procsym) then
  299. begin
  300. { if vmt<>0 then beforedestruction }
  301. addstatement(newstatement,cifnode.create(
  302. caddnode.create(unequaln,
  303. load_vmt_pointer_node,
  304. cnilnode.create),
  305. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node),
  306. nil));
  307. end
  308. else
  309. internalerror(200305104);
  310. end;
  311. end;
  312. end;
  313. function generate_finalize_block:tnode;
  314. begin
  315. result:=cnothingnode.create;
  316. end;
  317. function generate_entry_block:tnode;
  318. begin
  319. result:=cnothingnode.create;
  320. end;
  321. function generate_exit_block:tnode;
  322. var
  323. srsym : tsym;
  324. para : tcallparanode;
  325. newstatement : tstatementnode;
  326. begin
  327. generate_exit_block:=internalstatements(newstatement,true);
  328. if assigned(current_procdef._class) then
  329. begin
  330. { maybe call AfterConstruction for classes }
  331. if (current_procdef.proctypeoption=potype_constructor) and
  332. is_class(current_procdef._class) then
  333. begin
  334. srsym:=search_class_member(current_procdef._class,'AFTERCONSTRUCTION');
  335. if assigned(srsym) and
  336. (srsym.typ=procsym) then
  337. begin
  338. { if vmt<>0 then afterconstruction }
  339. addstatement(newstatement,cifnode.create(
  340. caddnode.create(unequaln,
  341. load_vmt_pointer_node,
  342. cnilnode.create),
  343. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node),
  344. nil));
  345. end
  346. else
  347. internalerror(200305106);
  348. end;
  349. { a destructor needs a help procedure }
  350. if (current_procdef.proctypeoption=potype_destructor) then
  351. begin
  352. if is_class(current_procdef._class) then
  353. begin
  354. srsym:=search_class_member(current_procdef._class,'FREEINSTANCE');
  355. if assigned(srsym) and
  356. (srsym.typ=procsym) then
  357. begin
  358. { if self<>0 and vmt=1 then freeinstance }
  359. addstatement(newstatement,cifnode.create(
  360. caddnode.create(andn,
  361. caddnode.create(unequaln,
  362. load_self_pointer_node,
  363. cnilnode.create),
  364. caddnode.create(equaln,
  365. ctypeconvnode.create(
  366. load_vmt_pointer_node,
  367. voidpointertype),
  368. cpointerconstnode.create(1,voidpointertype))),
  369. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node),
  370. nil));
  371. end
  372. else
  373. internalerror(200305108);
  374. end
  375. else
  376. if is_object(current_procdef._class) then
  377. begin
  378. { finalize object data }
  379. if current_procdef._class.needs_inittable then
  380. addstatement(newstatement,finalize_data_node(load_self_node));
  381. { parameter 3 : vmt_offset }
  382. { parameter 2 : pointer to vmt }
  383. { parameter 1 : self pointer }
  384. para:=ccallparanode.create(
  385. cordconstnode.create(current_procdef._class.vmt_offset,s32bittype,false),
  386. ccallparanode.create(
  387. ctypeconvnode.create_explicit(
  388. load_vmt_pointer_node,
  389. voidpointertype),
  390. ccallparanode.create(
  391. ctypeconvnode.create_explicit(
  392. load_self_pointer_node,
  393. voidpointertype),
  394. nil)));
  395. addstatement(newstatement,
  396. ccallnode.createintern('fpc_help_destructor',para));
  397. end
  398. else
  399. internalerror(200305105);
  400. end;
  401. end;
  402. end;
  403. function generate_except_block:tnode;
  404. var
  405. pd : tprocdef;
  406. newstatement : tstatementnode;
  407. begin
  408. generate_except_block:=internalstatements(newstatement,true);
  409. { a constructor needs call destructor (if available) when it
  410. is not inherited }
  411. if assigned(current_procdef._class) and
  412. (current_procdef.proctypeoption=potype_constructor) then
  413. begin
  414. pd:=current_procdef._class.searchdestructor;
  415. if assigned(pd) then
  416. begin
  417. { if vmt<>0 then call destructor }
  418. addstatement(newstatement,cifnode.create(
  419. caddnode.create(unequaln,
  420. load_vmt_pointer_node,
  421. cnilnode.create),
  422. ccallnode.create(nil,tprocsym(pd.procsym),pd.procsym.owner,load_self_node),
  423. nil));
  424. end;
  425. end
  426. else
  427. begin
  428. { no constructor }
  429. { must be the return value finalized before reraising the exception? }
  430. if (not is_void(current_procdef.rettype.def)) and
  431. (current_procdef.rettype.def.needs_inittable) and
  432. (not is_class(current_procdef.rettype.def)) then
  433. finalize_data_node(load_result_node);
  434. end;
  435. end;
  436. procedure add_entry_exit_code(var code:tnode;const entrypos,exitpos:tfileposinfo);
  437. var
  438. initializecode,
  439. finalizecode,
  440. entrycode,
  441. exitcode,
  442. exceptcode : tnode;
  443. codeblock,
  444. newblock : tblocknode;
  445. codestatement,
  446. newstatement : tstatementnode;
  447. oldfilepos : tfileposinfo;
  448. begin
  449. oldfilepos:=aktfilepos;
  450. { Generate entry,exit and init,final blocks }
  451. aktfilepos:=entrypos;
  452. initializecode:=generate_initialize_block;
  453. entrycode:=generate_entry_block;
  454. aktfilepos:=exitpos;
  455. exitcode:=generate_exit_block;
  456. finalizecode:=generate_finalize_block;
  457. exceptcode:=generate_except_block;
  458. { Generate body of the procedure by combining entry+body+exit }
  459. codeblock:=internalstatements(codestatement,true);
  460. addstatement(codestatement,entrycode);
  461. addstatement(codestatement,code);
  462. addstatement(codestatement,exitcode);
  463. { Generate procedure by combining init+body+final,
  464. depending on the implicit finally we need to add
  465. an try...finally...end wrapper }
  466. newblock:=internalstatements(newstatement,true);
  467. if (pi_needs_implicit_finally in current_procinfo.flags) and
  468. { but it's useless in init/final code of units }
  469. not(current_procdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) then
  470. begin
  471. addstatement(newstatement,initializecode);
  472. aktfilepos:=entrypos;
  473. addstatement(newstatement,ctryfinallynode.create_implicit(
  474. codeblock,
  475. finalizecode,
  476. exceptcode));
  477. end
  478. else
  479. begin
  480. addstatement(newstatement,initializecode);
  481. addstatement(newstatement,codeblock);
  482. addstatement(newstatement,finalizecode);
  483. end;
  484. resulttypepass(newblock);
  485. code:=newblock;
  486. aktfilepos:=oldfilepos;
  487. end;
  488. {****************************************************************************
  489. TCGProcInfo
  490. ****************************************************************************}
  491. constructor tcgprocinfo.create(aparent:tprocinfo);
  492. begin
  493. inherited Create(aparent);
  494. nestedprocs:=tlinkedlist.create;
  495. end;
  496. destructor tcgprocinfo.destroy;
  497. begin
  498. nestedprocs.free;
  499. inherited destroy;
  500. end;
  501. procedure tcgprocinfo.generate_code;
  502. var
  503. oldprocdef : tprocdef;
  504. oldprocinfo : tprocinfo;
  505. oldexitlabel : tasmlabel;
  506. oldaktmaxfpuregisters : longint;
  507. oldfilepos : tfileposinfo;
  508. stackalloccode : Taasmoutput;
  509. begin
  510. { the initialization procedure can be empty, then we
  511. don't need to generate anything. When it was an empty
  512. procedure there would be at least a blocknode }
  513. if not assigned(code) then
  514. exit;
  515. oldprocinfo:=current_procinfo;
  516. oldprocdef:=current_procdef;
  517. oldfilepos:=aktfilepos;
  518. oldaktmaxfpuregisters:=aktmaxfpuregisters;
  519. current_procinfo:=self;
  520. current_procdef:=procdef;
  521. { save old labels }
  522. oldexitlabel:=aktexitlabel;
  523. { get new labels }
  524. objectlibrary.getlabel(aktexitlabel);
  525. aktbreaklabel:=nil;
  526. aktcontinuelabel:=nil;
  527. { add parast/localst to symtablestack }
  528. add_to_symtablestack;
  529. { reset the temporary memory }
  530. rg.cleartempgen;
  531. rg.usedinproc:=[];
  532. rg.usedintinproc:=[];
  533. rg.usedbyproc:=[];
  534. {$ifndef newra}
  535. rg.usedintbyproc:=[];
  536. {$endif}
  537. { set the start offset to the start of the temp area in the stack }
  538. tg.setfirsttemp(current_procinfo.firsttemp_offset);
  539. generatecode(code);
  540. { first generate entry code with the correct position and switches }
  541. aktfilepos:=current_procinfo.entrypos;
  542. aktlocalswitches:=current_procinfo.entryswitches;
  543. genentrycode(current_procinfo.aktentrycode,false);
  544. { now generate exit code with the correct position and switches }
  545. aktfilepos:=current_procinfo.exitpos;
  546. aktlocalswitches:=current_procinfo.exitswitches;
  547. genexitcode(current_procinfo.aktexitcode,false);
  548. { now all the registers used are known }
  549. { current_procdef.usedintregisters:=rg.usedintinproc;
  550. current_procdef.usedotherregisters:=rg.usedinproc;}
  551. current_procinfo.aktproccode.insertlist(current_procinfo.aktentrycode);
  552. current_procinfo.aktproccode.concatlist(current_procinfo.aktexitcode);
  553. {$ifdef newra}
  554. { rg.writegraph;}
  555. {$endif}
  556. if not(cs_no_regalloc in aktglobalswitches) then
  557. begin
  558. {$ifdef newra}
  559. {Do register allocation.}
  560. repeat
  561. rg.prepare_colouring;
  562. rg.colour_registers;
  563. rg.epilogue_colouring;
  564. until (rg.spillednodes='') or not rg.spill_registers(current_procinfo.aktproccode,rg.spillednodes);
  565. current_procinfo.aktproccode.translate_registers(rg.colour);
  566. current_procinfo.aktproccode.convert_registers;
  567. {$else newra}
  568. current_procinfo.aktproccode.convert_registers;
  569. {$ifndef NoOpt}
  570. if (cs_optimize in aktglobalswitches) and
  571. { do not optimize pure assembler procedures }
  572. not(pi_is_assembler in current_procinfo.flags) then
  573. optimize(current_procinfo.aktproccode);
  574. {$endif NoOpt}
  575. {$endif newra}
  576. end;
  577. stackalloccode:=Taasmoutput.create;
  578. gen_stackalloc_code(stackalloccode,0);
  579. stackalloccode.convert_registers;
  580. current_procinfo.aktproccode.insertlist(stackalloccode);
  581. stackalloccode.destroy;
  582. { now all the registers used are known }
  583. { Remove all imaginary registers from the used list.}
  584. {$ifdef newra}
  585. current_procdef.usedintregisters:=rg.usedintinproc*ALL_INTREGISTERS-rg.savedbyproc;
  586. {$else}
  587. current_procdef.usedintregisters:=rg.usedintinproc;
  588. {$endif}
  589. current_procdef.usedotherregisters:=rg.usedinproc;
  590. { save local data (casetable) also in the same file }
  591. if assigned(current_procinfo.aktlocaldata) and
  592. (not current_procinfo.aktlocaldata.empty) then
  593. begin
  594. current_procinfo.aktproccode.concat(Tai_section.Create(sec_data));
  595. current_procinfo.aktproccode.concatlist(current_procinfo.aktlocaldata);
  596. current_procinfo.aktproccode.concat(Tai_section.Create(sec_code));
  597. end;
  598. { add the procedure to the codesegment }
  599. if (cs_create_smart in aktmoduleswitches) then
  600. codesegment.concat(Tai_cut.Create);
  601. codesegment.concatlist(current_procinfo.aktproccode);
  602. { all registers can be used again }
  603. rg.resetusableregisters;
  604. { only now we can remove the temps }
  605. tg.resettempgen;
  606. { restore symtablestack }
  607. remove_from_symtablestack;
  608. { restore labels }
  609. aktexitlabel:=oldexitlabel;
  610. { restore }
  611. aktmaxfpuregisters:=oldaktmaxfpuregisters;
  612. aktfilepos:=oldfilepos;
  613. current_procdef:=oldprocdef;
  614. current_procinfo:=oldprocinfo;
  615. end;
  616. procedure tcgprocinfo.add_to_symtablestack;
  617. var
  618. _class,hp : tobjectdef;
  619. begin
  620. { insert symtables for the class, but only if it is no nested function }
  621. if assigned(procdef._class) and
  622. not(assigned(parent) and
  623. assigned(parent.procdef) and
  624. assigned(parent.procdef._class)) then
  625. begin
  626. { insert them in the reverse order }
  627. hp:=nil;
  628. repeat
  629. _class:=procdef._class;
  630. while _class.childof<>hp do
  631. _class:=_class.childof;
  632. hp:=_class;
  633. _class.symtable.next:=symtablestack;
  634. symtablestack:=_class.symtable;
  635. until hp=procdef._class;
  636. end;
  637. { insert parasymtable in symtablestack when parsing
  638. a function }
  639. if procdef.parast.symtablelevel>=normal_function_level then
  640. begin
  641. procdef.parast.next:=symtablestack;
  642. symtablestack:=procdef.parast;
  643. end;
  644. procdef.localst.next:=symtablestack;
  645. symtablestack:=procdef.localst;
  646. end;
  647. procedure tcgprocinfo.remove_from_symtablestack;
  648. begin
  649. { remove localst/parast }
  650. if procdef.parast.symtablelevel>=normal_function_level then
  651. symtablestack:=symtablestack.next.next
  652. else
  653. symtablestack:=symtablestack.next;
  654. { remove class member symbol tables }
  655. while symtablestack.symtabletype=objectsymtable do
  656. symtablestack:=symtablestack.next;
  657. end;
  658. procedure tcgprocinfo.resetprocdef;
  659. begin
  660. { the local symtables can be deleted, but the parast }
  661. { doesn't, (checking definitons when calling a }
  662. { function }
  663. { not for a inline procedure !! (PM) }
  664. { at lexlevel = 1 localst is the staticsymtable itself }
  665. { so no dispose here !! }
  666. if assigned(code) and
  667. not(cs_browser in aktmoduleswitches) and
  668. (procdef.proccalloption<>pocall_inline) then
  669. begin
  670. if procdef.parast.symtablelevel>=normal_function_level then
  671. procdef.localst.free;
  672. procdef.localst:=nil;
  673. end;
  674. { remove code tree, if not inline procedure }
  675. if assigned(code) then
  676. begin
  677. { the inline procedure has already got a copy of the tree
  678. stored in current_procdef.code }
  679. code.free;
  680. if (procdef.proccalloption<>pocall_inline) then
  681. procdef.code:=nil;
  682. end;
  683. end;
  684. procedure tcgprocinfo.parse_body;
  685. var
  686. oldprocdef : tprocdef;
  687. stackalloccode : Taasmoutput;
  688. oldprocinfo : tprocinfo;
  689. begin
  690. oldprocdef:=current_procdef;
  691. oldprocinfo:=current_procinfo;
  692. current_procinfo:=self;
  693. current_procdef:=procdef;
  694. { calculate the lexical level }
  695. if procdef.parast.symtablelevel>maxnesting then
  696. Message(parser_e_too_much_lexlevel);
  697. { static is also important for local procedures !! }
  698. if (po_staticmethod in procdef.procoptions) then
  699. allow_only_static:=true
  700. else if (procdef.parast.symtablelevel=normal_function_level) then
  701. allow_only_static:=false;
  702. { reset break and continue labels }
  703. block_type:=bt_general;
  704. {$ifdef state_tracking}
  705. { aktstate:=Tstate_storage.create;}
  706. {$endif state_tracking}
  707. { create a local symbol table for this routine }
  708. if not assigned(procdef.localst) then
  709. procdef.insert_localst;
  710. { add parast/localst to symtablestack }
  711. add_to_symtablestack;
  712. { constant symbols are inserted in this symboltable }
  713. constsymtable:=symtablestack;
  714. { reset the temporary memory }
  715. rg.cleartempgen;
  716. rg.usedintinproc:=[];
  717. rg.usedinproc:=[];
  718. rg.usedbyproc:=[];
  719. { save entry info }
  720. entrypos:=aktfilepos;
  721. entryswitches:=aktlocalswitches;
  722. { parse the code ... }
  723. code:=block(current_module.islibrary);
  724. { save exit info }
  725. exitswitches:=aktlocalswitches;
  726. exitpos:=last_endtoken_filepos;
  727. if assigned(code) then
  728. begin
  729. { get a better entry point }
  730. entrypos:=code.fileinfo;
  731. { the procedure is now defined }
  732. procdef.forwarddef:=false;
  733. { add implicit entry and exit code }
  734. add_entry_exit_code(code,entrypos,exitpos);
  735. if (Errorcount=0) then
  736. begin
  737. { check if forwards are resolved }
  738. tstoredsymtable(procdef.localst).check_forwards;
  739. { check if all labels are used }
  740. tstoredsymtable(procdef.localst).checklabels;
  741. { remove cross unit overloads }
  742. tstoredsymtable(procdef.localst).unchain_overloaded;
  743. end;
  744. { check for unused symbols, but only if there is no asm block }
  745. if not(pi_uses_asm in flags) then
  746. begin
  747. { not for unit init, becuase the var can be used in finalize,
  748. it will be done in proc_unit }
  749. if not(procdef.proctypeoption in [potype_proginit,potype_unitinit,potype_unitfinalize]) then
  750. tstoredsymtable(procdef.localst).allsymbolsused;
  751. tstoredsymtable(procdef.parast).allsymbolsused;
  752. end;
  753. { Finish type checking pass }
  754. do_resulttypepass(code);
  755. { Print the node to tree.log }
  756. if paraprintnodetree=1 then
  757. printnode_procdef(procdef);
  758. end;
  759. { store a copy of the original tree for inline, for
  760. normal procedures only store a reference to the
  761. current tree }
  762. if (procdef.proccalloption=pocall_inline) then
  763. procdef.code:=code.getcopy
  764. else
  765. procdef.code:=code;
  766. { ... remove symbol tables }
  767. remove_from_symtablestack;
  768. {$ifdef state_tracking}
  769. { aktstate.destroy;}
  770. {$endif state_tracking}
  771. { reset to normal non static function }
  772. if (current_procdef.parast.symtablelevel=normal_function_level) then
  773. allow_only_static:=false;
  774. current_procdef:=oldprocdef;
  775. current_procinfo:=oldprocinfo;
  776. end;
  777. {****************************************************************************
  778. PROCEDURE/FUNCTION PARSING
  779. ****************************************************************************}
  780. procedure insert_local_value_para(p:tnamedindexitem;arg:pointer);
  781. var
  782. vs : tvarsym;
  783. pd : tprocdef;
  784. begin
  785. if tsym(p).typ<>varsym then
  786. exit;
  787. with tvarsym(p) do
  788. begin
  789. if copy(name,1,3)='val' then
  790. begin
  791. pd:=tprocdef(owner.defowner);
  792. vs:=tvarsym.create(Copy(name,4,255),varspez,vartype);
  793. vs.fileinfo:=fileinfo;
  794. if not assigned(pd.localst) then
  795. pd.insert_localst;
  796. pd.localst.insert(vs);
  797. pd.localst.insertvardata(vs);
  798. include(vs.varoptions,vo_is_local_copy);
  799. vs.varstate:=vs_assigned;
  800. localvarsym:=vs;
  801. inc(refs); { the para was used to set the local copy ! }
  802. { warnings only on local copy ! }
  803. varstate:=vs_used;
  804. end;
  805. if is_shortstring(vartype.def) and
  806. (varspez = vs_value) then
  807. include(current_procinfo.flags,pi_do_call);
  808. end;
  809. end;
  810. procedure check_init_paras(p:tnamedindexitem;arg:pointer);
  811. var
  812. vs : tvarsym;
  813. pd : tprocdef;
  814. begin
  815. if tsym(p).typ<>varsym then
  816. exit;
  817. with tvarsym(p) do
  818. if (not is_class(vartype.def) and
  819. vartype.def.needs_inittable and
  820. (varspez in [vs_value,vs_out])) then
  821. include(current_procinfo.flags,pi_do_call);
  822. end;
  823. procedure read_proc;
  824. {
  825. Parses the procedure directives, then parses the procedure body, then
  826. generates the code for it
  827. }
  828. procedure do_generate_code(pi:tcgprocinfo);
  829. var
  830. hpi : tcgprocinfo;
  831. begin
  832. { generate code for this procedure }
  833. pi.generate_code;
  834. { process nested procs }
  835. hpi:=tcgprocinfo(pi.nestedprocs.first);
  836. while assigned(hpi) do
  837. begin
  838. do_generate_code(hpi);
  839. hpi:=tcgprocinfo(hpi.next);
  840. end;
  841. pi.resetprocdef;
  842. end;
  843. var
  844. oldprocdef : tprocdef;
  845. old_current_procinfo : tprocinfo;
  846. oldconstsymtable : tsymtable;
  847. oldselftokenmode,
  848. oldfailtokenmode : tmodeswitch;
  849. pdflags : tpdflags;
  850. pd : tprocdef;
  851. isnestedproc : boolean;
  852. begin
  853. { save old state }
  854. oldprocdef:=current_procdef;
  855. oldconstsymtable:=constsymtable;
  856. old_current_procinfo:=current_procinfo;
  857. { reset current_procdef to nil to be sure that nothing is writing
  858. to an other procdef }
  859. current_procdef:=nil;
  860. current_procinfo:=nil;
  861. { parse procedure declaration }
  862. if assigned(old_current_procinfo) and
  863. assigned(old_current_procinfo.procdef) then
  864. pd:=parse_proc_dec(old_current_procinfo.procdef._class)
  865. else
  866. pd:=parse_proc_dec(nil);
  867. { set the default function options }
  868. if parse_only then
  869. begin
  870. pd.forwarddef:=true;
  871. { set also the interface flag, for better error message when the
  872. implementation doesn't much this header }
  873. pd.interfacedef:=true;
  874. include(pd.procoptions,po_public);
  875. pdflags:=[pd_interface];
  876. end
  877. else
  878. begin
  879. pdflags:=[pd_body];
  880. if (not current_module.in_interface) then
  881. include(pdflags,pd_implemen);
  882. if (not current_module.is_unit) or
  883. (cs_create_smart in aktmoduleswitches) then
  884. include(pd.procoptions,po_public);
  885. pd.forwarddef:=false;
  886. end;
  887. { parse the directives that may follow }
  888. parse_proc_directives(pd,pdflags);
  889. { hint directives, these can be separated by semicolons here,
  890. that needs to be handled here with a loop (PFV) }
  891. while try_consume_hintdirective(pd.symoptions) do
  892. Consume(_SEMICOLON);
  893. { everything of the proc definition is known, we can now
  894. calculate the parameters }
  895. calc_parast(pd);
  896. { search for forward declarations }
  897. if not proc_add_definition(pd) then
  898. begin
  899. { A method must be forward defined (in the object declaration) }
  900. if assigned(pd._class) and
  901. (not assigned(old_current_procinfo.procdef._class)) then
  902. begin
  903. Message1(parser_e_header_dont_match_any_member,pd.fullprocname(false));
  904. tprocsym(pd.procsym).write_parameter_lists(pd);
  905. end
  906. else
  907. begin
  908. { Give a better error if there is a forward def in the interface and only
  909. a single implementation }
  910. if (not pd.forwarddef) and
  911. (not pd.interfacedef) and
  912. (tprocsym(pd.procsym).procdef_count>1) and
  913. tprocsym(pd.procsym).first_procdef.forwarddef and
  914. tprocsym(pd.procsym).first_procdef.interfacedef and
  915. not(tprocsym(pd.procsym).procdef_count>2) then
  916. begin
  917. Message1(parser_e_header_dont_match_forward,pd.fullprocname(false));
  918. tprocsym(pd.procsym).write_parameter_lists(pd);
  919. end
  920. else
  921. begin
  922. { check the global flag, for delphi this is not
  923. required }
  924. {if not(m_delphi in aktmodeswitches) and
  925. not(pd.procsym.owner.symtabletype=globalsymtable) then
  926. Message(parser_e_overloaded_must_be_all_global);}
  927. end;
  928. end;
  929. end;
  930. { compile procedure when a body is needed }
  931. if (pd_body in pdflags) then
  932. begin
  933. Message1(parser_d_procedure_start,pd.fullprocname(false));
  934. { create a new procedure }
  935. current_procinfo:=cprocinfo.create(old_current_procinfo);
  936. current_module.procinfo:=current_procinfo;
  937. current_procinfo.procdef:=pd;
  938. isnestedproc:=(current_procinfo.procdef.parast.symtablelevel>normal_function_level);
  939. { Insert mangledname }
  940. pd.aliasnames.insert(pd.mangledname);
  941. { Insert result variables in the localst }
  942. insert_funcret_local(pd);
  943. { Insert local copies for value para }
  944. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}insert_local_value_para,nil);
  945. { check if there are para's which require initing -> set }
  946. { pi_do_call (if not yet set) }
  947. if not(pi_do_call in current_procinfo.flags) then
  948. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_init_paras,nil);
  949. { Update parameter information }
  950. current_procinfo.allocate_implicit_parameter;
  951. {$ifdef i386}
  952. { add implicit pushes for interrupt routines }
  953. if (po_interrupt in pd.procoptions) then
  954. current_procinfo.allocate_interrupt_stackframe;
  955. {$endif i386}
  956. { Calculate offsets }
  957. current_procinfo.after_header;
  958. { set _FAIL as keyword if constructor }
  959. if (pd.proctypeoption=potype_constructor) then
  960. begin
  961. oldfailtokenmode:=tokeninfo^[_FAIL].keyword;
  962. tokeninfo^[_FAIL].keyword:=m_all;
  963. end;
  964. { set _SELF as keyword if methods }
  965. if assigned(pd._class) then
  966. begin
  967. oldselftokenmode:=tokeninfo^[_SELF].keyword;
  968. tokeninfo^[_SELF].keyword:=m_all;
  969. end;
  970. tcgprocinfo(current_procinfo).parse_body;
  971. { When it's a nested procedure then defer the code generation,
  972. when back at normal function level then generate the code
  973. for all defered nested procedures and the current procedure }
  974. if isnestedproc then
  975. tcgprocinfo(current_procinfo.parent).nestedprocs.insert(current_procinfo)
  976. else
  977. begin
  978. if status.errorcount=0 then
  979. do_generate_code(tcgprocinfo(current_procinfo));
  980. end;
  981. { reset _FAIL as _SELF normal }
  982. if (pd.proctypeoption=potype_constructor) then
  983. tokeninfo^[_FAIL].keyword:=oldfailtokenmode;
  984. if assigned(pd._class) then
  985. tokeninfo^[_SELF].keyword:=oldselftokenmode;
  986. consume(_SEMICOLON);
  987. { release procinfo }
  988. if tprocinfo(current_module.procinfo)<>current_procinfo then
  989. internalerror(200304274);
  990. current_module.procinfo:=current_procinfo.parent;
  991. if not isnestedproc then
  992. current_procinfo.free;
  993. end;
  994. { Restore old state }
  995. constsymtable:=oldconstsymtable;
  996. current_procdef:=oldprocdef;
  997. current_procinfo:=old_current_procinfo;
  998. end;
  999. {****************************************************************************
  1000. DECLARATION PARSING
  1001. ****************************************************************************}
  1002. { search in symtablestack for not complete classes }
  1003. procedure check_forward_class(p : tnamedindexitem;arg:pointer);
  1004. begin
  1005. if (tsym(p).typ=typesym) and
  1006. (ttypesym(p).restype.def.deftype=objectdef) and
  1007. (oo_is_forward in tobjectdef(ttypesym(p).restype.def).objectoptions) then
  1008. MessagePos1(tsym(p).fileinfo,sym_e_forward_type_not_resolved,tsym(p).realname);
  1009. end;
  1010. procedure read_declarations(islibrary : boolean);
  1011. procedure Not_supported_for_inline(t : ttoken);
  1012. begin
  1013. if (current_procdef.proccalloption=pocall_inline) then
  1014. Begin
  1015. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  1016. Message(parser_w_inlining_disabled);
  1017. current_procdef.proccalloption:=pocall_fpccall;
  1018. End;
  1019. end;
  1020. begin
  1021. repeat
  1022. if not assigned(current_procdef) then
  1023. internalerror(200304251);
  1024. case token of
  1025. _LABEL:
  1026. begin
  1027. Not_supported_for_inline(token);
  1028. label_dec;
  1029. end;
  1030. _CONST:
  1031. begin
  1032. Not_supported_for_inline(token);
  1033. const_dec;
  1034. end;
  1035. _TYPE:
  1036. begin
  1037. Not_supported_for_inline(token);
  1038. type_dec;
  1039. end;
  1040. _VAR:
  1041. var_dec;
  1042. _THREADVAR:
  1043. threadvar_dec;
  1044. _CONSTRUCTOR,_DESTRUCTOR,
  1045. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1046. begin
  1047. Not_supported_for_inline(token);
  1048. read_proc;
  1049. end;
  1050. _RESOURCESTRING:
  1051. resourcestring_dec;
  1052. _EXPORTS:
  1053. begin
  1054. Not_supported_for_inline(token);
  1055. if not(assigned(current_procdef.localst)) or
  1056. (current_procdef.localst.symtablelevel>main_program_level) or
  1057. (current_module.is_unit) then
  1058. begin
  1059. Message(parser_e_syntax_error);
  1060. consume_all_until(_SEMICOLON);
  1061. end
  1062. else if islibrary or
  1063. (target_info.system in [system_i386_WIN32,system_i386_wdosx,system_i386_Netware]) then
  1064. read_exports
  1065. else
  1066. begin
  1067. Message(parser_w_unsupported_feature);
  1068. consume(_BEGIN);
  1069. end;
  1070. end
  1071. else break;
  1072. end;
  1073. until false;
  1074. { check for incomplete class definitions, this is only required
  1075. for fpc modes }
  1076. if (m_fpc in aktmodeswitches) then
  1077. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_forward_class,nil);
  1078. end;
  1079. procedure read_interface_declarations;
  1080. begin
  1081. repeat
  1082. case token of
  1083. _CONST :
  1084. const_dec;
  1085. _TYPE :
  1086. type_dec;
  1087. _VAR :
  1088. var_dec;
  1089. _THREADVAR :
  1090. threadvar_dec;
  1091. _RESOURCESTRING:
  1092. resourcestring_dec;
  1093. _FUNCTION,
  1094. _PROCEDURE,
  1095. _OPERATOR :
  1096. read_proc;
  1097. else
  1098. break;
  1099. end;
  1100. until false;
  1101. { check for incomplete class definitions, this is only required
  1102. for fpc modes }
  1103. if (m_fpc in aktmodeswitches) then
  1104. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_forward_class,nil);
  1105. end;
  1106. begin
  1107. cprocinfo:=tcgprocinfo;
  1108. end.
  1109. {
  1110. $Log$
  1111. Revision 1.124 2003-06-07 19:37:43 jonas
  1112. * pi_do_call must always be set for the main program, since it always
  1113. ends with a call to FPC_DO_EXIT
  1114. Revision 1.123 2003/06/07 18:57:04 jonas
  1115. + added freeintparaloc
  1116. * ppc get/freeintparaloc now check whether the parameter regs are
  1117. properly allocated/deallocated (and get an extra list para)
  1118. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1119. * fixed lot of missing pi_do_call's
  1120. Revision 1.122 2003/06/03 13:01:59 daniel
  1121. * Register allocator finished
  1122. Revision 1.121 2003/05/31 20:23:39 jonas
  1123. * added pi_do_call if a procedure has a value shortstring parameter
  1124. (it's copied to the local stackframe with a helper)
  1125. Revision 1.120 2003/05/30 23:57:08 peter
  1126. * more sparc cleanup
  1127. * accumulator removed, splitted in function_return_reg (called) and
  1128. function_result_reg (caller)
  1129. Revision 1.119 2003/05/28 23:58:18 jonas
  1130. * added missing initialization of rg.usedintin,byproc
  1131. * ppc now also saves/restores used fpu registers
  1132. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1133. i386
  1134. Revision 1.118 2003/05/26 21:17:18 peter
  1135. * procinlinenode removed
  1136. * aktexit2label removed, fast exit removed
  1137. + tcallnode.inlined_pass_2 added
  1138. Revision 1.117 2003/05/25 08:59:47 peter
  1139. * do not generate code when there was an error
  1140. Revision 1.116 2003/05/23 18:49:55 jonas
  1141. * generate code for parent procedure before that of nested procedures as
  1142. well (I only need pass_1 to be done for the ppc, but pass_1 and pass_2
  1143. are grouped and it doesn't hurt that pass_2 is done as well)
  1144. Revision 1.115 2003/05/22 21:31:35 peter
  1145. * defer codegeneration for nested procedures
  1146. Revision 1.114 2003/05/16 20:00:39 jonas
  1147. * powerpc nested procedure fixes, should work completely now if all
  1148. local variables of the parent procedure are declared before the
  1149. nested procedures are declared
  1150. Revision 1.113 2003/05/16 14:33:31 peter
  1151. * regvar fixes
  1152. Revision 1.112 2003/05/13 21:26:38 peter
  1153. * only call destructor in except block when there is a destructor
  1154. available
  1155. Revision 1.111 2003/05/13 19:14:41 peter
  1156. * failn removed
  1157. * inherited result code check moven to pexpr
  1158. Revision 1.110 2003/05/13 15:18:49 peter
  1159. * fixed various crashes
  1160. Revision 1.109 2003/05/11 21:37:03 peter
  1161. * moved implicit exception frame from ncgutil to psub
  1162. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1163. Revision 1.108 2003/05/09 17:47:03 peter
  1164. * self moved to hidden parameter
  1165. * removed hdisposen,hnewn,selfn
  1166. Revision 1.107 2003/04/27 11:21:34 peter
  1167. * aktprocdef renamed to current_procdef
  1168. * procinfo renamed to current_procinfo
  1169. * procinfo will now be stored in current_module so it can be
  1170. cleaned up properly
  1171. * gen_main_procsym changed to create_main_proc and release_main_proc
  1172. to also generate a tprocinfo structure
  1173. * fixed unit implicit initfinal
  1174. Revision 1.106 2003/04/27 07:29:50 peter
  1175. * current_procdef cleanup, current_procdef is now always nil when parsing
  1176. a new procdef declaration
  1177. * aktprocsym removed
  1178. * lexlevel removed, use symtable.symtablelevel instead
  1179. * implicit init/final code uses the normal genentry/genexit
  1180. * funcret state checking updated for new funcret handling
  1181. Revision 1.105 2003/04/26 00:31:42 peter
  1182. * set return_offset moved to after_header
  1183. Revision 1.104 2003/04/25 20:59:34 peter
  1184. * removed funcretn,funcretsym, function result is now in varsym
  1185. and aliases for result and function name are added using absolutesym
  1186. * vs_hidden parameter for funcret passed in parameter
  1187. * vs_hidden fixes
  1188. * writenode changed to printnode and released from extdebug
  1189. * -vp option added to generate a tree.log with the nodetree
  1190. * nicer printnode for statements, callnode
  1191. Revision 1.103 2003/04/24 13:03:01 florian
  1192. * comp is now written with its bit pattern to the ppu instead as an extended
  1193. Revision 1.102 2003/04/23 12:35:34 florian
  1194. * fixed several issues with powerpc
  1195. + applied a patch from Jonas for nested function calls (PowerPC only)
  1196. * ...
  1197. Revision 1.101 2003/04/22 14:33:38 peter
  1198. * removed some notes/hints
  1199. Revision 1.100 2003/04/22 13:47:08 peter
  1200. * fixed C style array of const
  1201. * fixed C array passing
  1202. * fixed left to right with high parameters
  1203. Revision 1.99 2003/04/22 10:09:35 daniel
  1204. + Implemented the actual register allocator
  1205. + Scratch registers unavailable when new register allocator used
  1206. + maybe_save/maybe_restore unavailable when new register allocator used
  1207. Revision 1.98 2003/04/17 07:50:24 daniel
  1208. * Some work on interference graph construction
  1209. Revision 1.97 2003/04/16 09:26:55 jonas
  1210. * assembler procedures now again get a stackframe if they have local
  1211. variables. No space is reserved for a function result however.
  1212. Also, the register parameters aren't automatically saved on the stack
  1213. anymore in assembler procedures.
  1214. Revision 1.96 2003/04/05 21:09:31 jonas
  1215. * several ppc/generic result offset related fixes. The "normal" result
  1216. offset seems now to be calculated correctly and a lot of duplicate
  1217. calculations have been removed. Nested functions accessing the parent's
  1218. function result don't work at all though :(
  1219. Revision 1.95 2003/04/02 16:11:34 peter
  1220. * give error when exports is not supported
  1221. Revision 1.94 2003/03/12 22:43:38 jonas
  1222. * more powerpc and generic fixes related to the new register allocator
  1223. Revision 1.93 2003/03/08 08:59:07 daniel
  1224. + $define newra will enable new register allocator
  1225. + getregisterint will return imaginary registers with $newra
  1226. + -sr switch added, will skip register allocation so you can see
  1227. the direct output of the code generator before register allocation
  1228. Revision 1.92 2003/02/19 22:00:14 daniel
  1229. * Code generator converted to new register notation
  1230. - Horribily outdated todo.txt removed
  1231. Revision 1.91 2003/01/09 21:52:37 peter
  1232. * merged some verbosity options.
  1233. * V_LineInfo is a verbosity flag to include line info
  1234. Revision 1.90 2003/01/09 20:40:59 daniel
  1235. * Converted some code in cgx86.pas to new register numbering
  1236. Revision 1.89 2003/01/09 15:49:56 daniel
  1237. * Added register conversion
  1238. Revision 1.88 2003/01/08 18:43:56 daniel
  1239. * Tregister changed into a record
  1240. Revision 1.87 2003/01/03 20:35:08 peter
  1241. * check also interfacedef when checking for matching forwarddef
  1242. Revision 1.86 2003/01/02 11:14:02 michael
  1243. + Patch from peter to support initial values for local variables
  1244. Revision 1.85 2002/12/29 18:59:34 peter
  1245. * fixed parsing of declarations before asm statement
  1246. Revision 1.84 2002/12/29 18:25:18 peter
  1247. * parse declarations before check _ASM token
  1248. Revision 1.83 2002/12/29 14:57:50 peter
  1249. * unit loading changed to first register units and load them
  1250. afterwards. This is needed to support uses xxx in yyy correctly
  1251. * unit dependency check fixed
  1252. Revision 1.82 2002/12/25 01:26:56 peter
  1253. * duplicate procsym-unitsym fix
  1254. Revision 1.81 2002/12/15 13:37:15 peter
  1255. * don't include uf_init for library. The code is already called and
  1256. does not need to be in the initfinal table
  1257. Revision 1.80 2002/12/07 14:27:09 carl
  1258. * 3% memory optimization
  1259. * changed some types
  1260. + added type checking with different size for call node and for
  1261. parameters
  1262. Revision 1.79 2002/11/25 18:43:32 carl
  1263. - removed the invalid if <> checking (Delphi is strange on this)
  1264. + implemented abstract warning on instance creation of class with
  1265. abstract methods.
  1266. * some error message cleanups
  1267. Revision 1.78 2002/11/25 17:43:23 peter
  1268. * splitted defbase in defutil,symutil,defcmp
  1269. * merged isconvertable and is_equal into compare_defs(_ext)
  1270. * made operator search faster by walking the list only once
  1271. Revision 1.77 2002/11/23 22:50:06 carl
  1272. * some small speed optimizations
  1273. + added several new warnings/hints
  1274. Revision 1.76 2002/11/18 17:31:58 peter
  1275. * pass proccalloption to ret_in_xxx and push_xxx functions
  1276. Revision 1.75 2002/11/17 16:31:57 carl
  1277. * memory optimization (3-4%) : cleanup of tai fields,
  1278. cleanup of tdef and tsym fields.
  1279. * make it work for m68k
  1280. Revision 1.74 2002/11/15 01:58:53 peter
  1281. * merged changes from 1.0.7 up to 04-11
  1282. - -V option for generating bug report tracing
  1283. - more tracing for option parsing
  1284. - errors for cdecl and high()
  1285. - win32 import stabs
  1286. - win32 records<=8 are returned in eax:edx (turned off by default)
  1287. - heaptrc update
  1288. - more info for temp management in .s file with EXTDEBUG
  1289. Revision 1.73 2002/11/09 15:32:30 carl
  1290. * noopt for non-i386 targets
  1291. Revision 1.72 2002/09/10 20:31:48 florian
  1292. * call to current_procinfo.after_header added
  1293. Revision 1.71 2002/09/07 15:25:07 peter
  1294. * old logs removed and tabs fixed
  1295. Revision 1.70 2002/09/03 16:26:27 daniel
  1296. * Make Tprocdef.defs protected
  1297. Revision 1.69 2002/08/25 19:25:20 peter
  1298. * sym.insert_in_data removed
  1299. * symtable.insertvardata/insertconstdata added
  1300. * removed insert_in_data call from symtable.insert, it needs to be
  1301. called separatly. This allows to deref the address calculation
  1302. * procedures now calculate the parast addresses after the procedure
  1303. directives are parsed. This fixes the cdecl parast problem
  1304. * push_addr_param has an extra argument that specifies if cdecl is used
  1305. or not
  1306. Revision 1.68 2002/08/17 09:23:41 florian
  1307. * first part of procinfo rewrite
  1308. Revision 1.67 2002/08/16 14:24:59 carl
  1309. * issameref() to test if two references are the same (then emit no opcodes)
  1310. + ret_in_reg to replace ret_in_acc
  1311. (fix some register allocation bugs at the same time)
  1312. + save_std_register now has an extra parameter which is the
  1313. usedinproc registers
  1314. Revision 1.66 2002/08/11 14:32:27 peter
  1315. * renamed current_library to objectlibrary
  1316. Revision 1.65 2002/08/11 13:24:13 peter
  1317. * saving of asmsymbols in ppu supported
  1318. * asmsymbollist global is removed and moved into a new class
  1319. tasmlibrarydata that will hold the info of a .a file which
  1320. corresponds with a single module. Added librarydata to tmodule
  1321. to keep the library info stored for the module. In the future the
  1322. objectfiles will also be stored to the tasmlibrarydata class
  1323. * all getlabel/newasmsymbol and friends are moved to the new class
  1324. Revision 1.64 2002/08/09 19:14:28 carl
  1325. * fixed stackframe parameter (should only contain local size),
  1326. set to zero currently
  1327. Revision 1.63 2002/08/06 20:55:22 florian
  1328. * first part of ppc calling conventions fix
  1329. Revision 1.62 2002/07/26 21:15:41 florian
  1330. * rewrote the system handling
  1331. Revision 1.61 2002/07/20 11:57:56 florian
  1332. * types.pas renamed to defbase.pas because D6 contains a types
  1333. unit so this would conflicts if D6 programms are compiled
  1334. + Willamette/SSE2 instructions to assembler added
  1335. Revision 1.60 2002/07/19 11:41:36 daniel
  1336. * State tracker work
  1337. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1338. allows the state tracker to change while nodes automatically into
  1339. repeat nodes.
  1340. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1341. 'not(a>b)' is optimized into 'a<=b'.
  1342. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1343. by removing the notn and later switchting the true and falselabels. The
  1344. same is done with 'repeat until not a'.
  1345. Revision 1.59 2002/07/15 18:03:15 florian
  1346. * readded removed changes
  1347. Revision 1.57 2002/07/11 14:41:28 florian
  1348. * start of the new generic parameter handling
  1349. Revision 1.58 2002/07/14 18:00:44 daniel
  1350. + Added the beginning of a state tracker. This will track the values of
  1351. variables through procedures and optimize things away.
  1352. Revision 1.56 2002/07/07 09:52:32 florian
  1353. * powerpc target fixed, very simple units can be compiled
  1354. * some basic stuff for better callparanode handling, far from being finished
  1355. Revision 1.55 2002/07/04 20:43:01 florian
  1356. * first x86-64 patches
  1357. Revision 1.54 2002/07/01 18:46:25 peter
  1358. * internal linker
  1359. * reorganized aasm layer
  1360. Revision 1.53 2002/05/18 13:34:14 peter
  1361. * readded missing revisions
  1362. Revision 1.52 2002/05/16 19:46:44 carl
  1363. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1364. + try to fix temp allocation (still in ifdef)
  1365. + generic constructor calls
  1366. + start of tassembler / tmodulebase class cleanup
  1367. Revision 1.51 2002/05/14 19:34:49 peter
  1368. * removed old logs and updated copyright year
  1369. }