psub.pas 58 KB

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