psub.pas 55 KB

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