psub.pas 56 KB

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