psub.pas 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  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. end;
  784. end;
  785. procedure read_proc;
  786. {
  787. Parses the procedure directives, then parses the procedure body, then
  788. generates the code for it
  789. }
  790. procedure do_generate_code(pi:tcgprocinfo);
  791. var
  792. hpi : tcgprocinfo;
  793. begin
  794. { generate code for this procedure }
  795. pi.generate_code;
  796. { process nested procs }
  797. hpi:=tcgprocinfo(pi.nestedprocs.first);
  798. while assigned(hpi) do
  799. begin
  800. do_generate_code(hpi);
  801. hpi:=tcgprocinfo(hpi.next);
  802. end;
  803. pi.resetprocdef;
  804. end;
  805. var
  806. oldprocdef : tprocdef;
  807. old_current_procinfo : tprocinfo;
  808. oldconstsymtable : tsymtable;
  809. oldselftokenmode,
  810. oldfailtokenmode : tmodeswitch;
  811. pdflags : tpdflags;
  812. pd : tprocdef;
  813. isnestedproc : boolean;
  814. begin
  815. { save old state }
  816. oldprocdef:=current_procdef;
  817. oldconstsymtable:=constsymtable;
  818. old_current_procinfo:=current_procinfo;
  819. { reset current_procdef to nil to be sure that nothing is writing
  820. to an other procdef }
  821. current_procdef:=nil;
  822. current_procinfo:=nil;
  823. { parse procedure declaration }
  824. if assigned(old_current_procinfo) and
  825. assigned(old_current_procinfo.procdef) then
  826. pd:=parse_proc_dec(old_current_procinfo.procdef._class)
  827. else
  828. pd:=parse_proc_dec(nil);
  829. { set the default function options }
  830. if parse_only then
  831. begin
  832. pd.forwarddef:=true;
  833. { set also the interface flag, for better error message when the
  834. implementation doesn't much this header }
  835. pd.interfacedef:=true;
  836. include(pd.procoptions,po_public);
  837. pdflags:=[pd_interface];
  838. end
  839. else
  840. begin
  841. pdflags:=[pd_body];
  842. if (not current_module.in_interface) then
  843. include(pdflags,pd_implemen);
  844. if (not current_module.is_unit) or
  845. (cs_create_smart in aktmoduleswitches) then
  846. include(pd.procoptions,po_public);
  847. pd.forwarddef:=false;
  848. end;
  849. { parse the directives that may follow }
  850. parse_proc_directives(pd,pdflags);
  851. { hint directives, these can be separated by semicolons here,
  852. that needs to be handled here with a loop (PFV) }
  853. while try_consume_hintdirective(pd.symoptions) do
  854. Consume(_SEMICOLON);
  855. { everything of the proc definition is known, we can now
  856. calculate the parameters }
  857. calc_parast(pd);
  858. { search for forward declarations }
  859. if not proc_add_definition(pd) then
  860. begin
  861. { A method must be forward defined (in the object declaration) }
  862. if assigned(pd._class) and
  863. (not assigned(old_current_procinfo.procdef._class)) then
  864. begin
  865. Message1(parser_e_header_dont_match_any_member,pd.fullprocname(false));
  866. tprocsym(pd.procsym).write_parameter_lists(pd);
  867. end
  868. else
  869. begin
  870. { Give a better error if there is a forward def in the interface and only
  871. a single implementation }
  872. if (not pd.forwarddef) and
  873. (not pd.interfacedef) and
  874. (tprocsym(pd.procsym).procdef_count>1) and
  875. tprocsym(pd.procsym).first_procdef.forwarddef and
  876. tprocsym(pd.procsym).first_procdef.interfacedef and
  877. not(tprocsym(pd.procsym).procdef_count>2) then
  878. begin
  879. Message1(parser_e_header_dont_match_forward,pd.fullprocname(false));
  880. tprocsym(pd.procsym).write_parameter_lists(pd);
  881. end
  882. else
  883. begin
  884. { check the global flag, for delphi this is not
  885. required }
  886. {if not(m_delphi in aktmodeswitches) and
  887. not(pd.procsym.owner.symtabletype=globalsymtable) then
  888. Message(parser_e_overloaded_must_be_all_global);}
  889. end;
  890. end;
  891. end;
  892. { compile procedure when a body is needed }
  893. if (pd_body in pdflags) then
  894. begin
  895. Message1(parser_d_procedure_start,pd.fullprocname(false));
  896. { create a new procedure }
  897. current_procinfo:=cprocinfo.create(old_current_procinfo);
  898. current_module.procinfo:=current_procinfo;
  899. current_procinfo.procdef:=pd;
  900. isnestedproc:=(current_procinfo.procdef.parast.symtablelevel>normal_function_level);
  901. { Insert mangledname }
  902. pd.aliasnames.insert(pd.mangledname);
  903. { Insert result variables in the localst }
  904. insert_funcret_local(pd);
  905. { Insert local copies for value para }
  906. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}insert_local_value_para,nil);
  907. { Update parameter information }
  908. current_procinfo.allocate_implicit_parameter;
  909. {$ifdef i386}
  910. { add implicit pushes for interrupt routines }
  911. if (po_interrupt in pd.procoptions) then
  912. current_procinfo.allocate_interrupt_stackframe;
  913. {$endif i386}
  914. { Calculate offsets }
  915. current_procinfo.after_header;
  916. { set _FAIL as keyword if constructor }
  917. if (pd.proctypeoption=potype_constructor) then
  918. begin
  919. oldfailtokenmode:=tokeninfo^[_FAIL].keyword;
  920. tokeninfo^[_FAIL].keyword:=m_all;
  921. end;
  922. { set _SELF as keyword if methods }
  923. if assigned(pd._class) then
  924. begin
  925. oldselftokenmode:=tokeninfo^[_SELF].keyword;
  926. tokeninfo^[_SELF].keyword:=m_all;
  927. end;
  928. tcgprocinfo(current_procinfo).parse_body;
  929. { When it's a nested procedure then defer the code generation,
  930. when back at normal function level then generate the code
  931. for all defered nested procedures and the current procedure }
  932. if isnestedproc then
  933. tcgprocinfo(current_procinfo.parent).nestedprocs.insert(current_procinfo)
  934. else
  935. begin
  936. if status.errorcount=0 then
  937. do_generate_code(tcgprocinfo(current_procinfo));
  938. end;
  939. { reset _FAIL as _SELF normal }
  940. if (pd.proctypeoption=potype_constructor) then
  941. tokeninfo^[_FAIL].keyword:=oldfailtokenmode;
  942. if assigned(pd._class) then
  943. tokeninfo^[_SELF].keyword:=oldselftokenmode;
  944. consume(_SEMICOLON);
  945. { release procinfo }
  946. if tprocinfo(current_module.procinfo)<>current_procinfo then
  947. internalerror(200304274);
  948. current_module.procinfo:=current_procinfo.parent;
  949. if not isnestedproc then
  950. current_procinfo.free;
  951. end;
  952. { Restore old state }
  953. constsymtable:=oldconstsymtable;
  954. current_procdef:=oldprocdef;
  955. current_procinfo:=old_current_procinfo;
  956. end;
  957. {****************************************************************************
  958. DECLARATION PARSING
  959. ****************************************************************************}
  960. { search in symtablestack for not complete classes }
  961. procedure check_forward_class(p : tnamedindexitem;arg:pointer);
  962. begin
  963. if (tsym(p).typ=typesym) and
  964. (ttypesym(p).restype.def.deftype=objectdef) and
  965. (oo_is_forward in tobjectdef(ttypesym(p).restype.def).objectoptions) then
  966. MessagePos1(tsym(p).fileinfo,sym_e_forward_type_not_resolved,tsym(p).realname);
  967. end;
  968. procedure read_declarations(islibrary : boolean);
  969. procedure Not_supported_for_inline(t : ttoken);
  970. begin
  971. if (current_procdef.proccalloption=pocall_inline) then
  972. Begin
  973. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  974. Message(parser_w_inlining_disabled);
  975. current_procdef.proccalloption:=pocall_fpccall;
  976. End;
  977. end;
  978. begin
  979. repeat
  980. if not assigned(current_procdef) then
  981. internalerror(200304251);
  982. case token of
  983. _LABEL:
  984. begin
  985. Not_supported_for_inline(token);
  986. label_dec;
  987. end;
  988. _CONST:
  989. begin
  990. Not_supported_for_inline(token);
  991. const_dec;
  992. end;
  993. _TYPE:
  994. begin
  995. Not_supported_for_inline(token);
  996. type_dec;
  997. end;
  998. _VAR:
  999. var_dec;
  1000. _THREADVAR:
  1001. threadvar_dec;
  1002. _CONSTRUCTOR,_DESTRUCTOR,
  1003. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1004. begin
  1005. Not_supported_for_inline(token);
  1006. read_proc;
  1007. end;
  1008. _RESOURCESTRING:
  1009. resourcestring_dec;
  1010. _EXPORTS:
  1011. begin
  1012. Not_supported_for_inline(token);
  1013. if not(assigned(current_procdef.localst)) or
  1014. (current_procdef.localst.symtablelevel>main_program_level) or
  1015. (current_module.is_unit) then
  1016. begin
  1017. Message(parser_e_syntax_error);
  1018. consume_all_until(_SEMICOLON);
  1019. end
  1020. else if islibrary or
  1021. (target_info.system in [system_i386_WIN32,system_i386_wdosx,system_i386_Netware]) then
  1022. read_exports
  1023. else
  1024. begin
  1025. Message(parser_w_unsupported_feature);
  1026. consume(_BEGIN);
  1027. end;
  1028. end
  1029. else break;
  1030. end;
  1031. until false;
  1032. { check for incomplete class definitions, this is only required
  1033. for fpc modes }
  1034. if (m_fpc in aktmodeswitches) then
  1035. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_forward_class,nil);
  1036. end;
  1037. procedure read_interface_declarations;
  1038. begin
  1039. repeat
  1040. case token of
  1041. _CONST :
  1042. const_dec;
  1043. _TYPE :
  1044. type_dec;
  1045. _VAR :
  1046. var_dec;
  1047. _THREADVAR :
  1048. threadvar_dec;
  1049. _RESOURCESTRING:
  1050. resourcestring_dec;
  1051. _FUNCTION,
  1052. _PROCEDURE,
  1053. _OPERATOR :
  1054. read_proc;
  1055. else
  1056. break;
  1057. end;
  1058. until false;
  1059. { check for incomplete class definitions, this is only required
  1060. for fpc modes }
  1061. if (m_fpc in aktmodeswitches) then
  1062. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_forward_class,nil);
  1063. end;
  1064. begin
  1065. cprocinfo:=tcgprocinfo;
  1066. end.
  1067. {
  1068. $Log$
  1069. Revision 1.120 2003-05-30 23:57:08 peter
  1070. * more sparc cleanup
  1071. * accumulator removed, splitted in function_return_reg (called) and
  1072. function_result_reg (caller)
  1073. Revision 1.119 2003/05/28 23:58:18 jonas
  1074. * added missing initialization of rg.usedintin,byproc
  1075. * ppc now also saves/restores used fpu registers
  1076. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1077. i386
  1078. Revision 1.118 2003/05/26 21:17:18 peter
  1079. * procinlinenode removed
  1080. * aktexit2label removed, fast exit removed
  1081. + tcallnode.inlined_pass_2 added
  1082. Revision 1.117 2003/05/25 08:59:47 peter
  1083. * do not generate code when there was an error
  1084. Revision 1.116 2003/05/23 18:49:55 jonas
  1085. * generate code for parent procedure before that of nested procedures as
  1086. well (I only need pass_1 to be done for the ppc, but pass_1 and pass_2
  1087. are grouped and it doesn't hurt that pass_2 is done as well)
  1088. Revision 1.115 2003/05/22 21:31:35 peter
  1089. * defer codegeneration for nested procedures
  1090. Revision 1.114 2003/05/16 20:00:39 jonas
  1091. * powerpc nested procedure fixes, should work completely now if all
  1092. local variables of the parent procedure are declared before the
  1093. nested procedures are declared
  1094. Revision 1.113 2003/05/16 14:33:31 peter
  1095. * regvar fixes
  1096. Revision 1.112 2003/05/13 21:26:38 peter
  1097. * only call destructor in except block when there is a destructor
  1098. available
  1099. Revision 1.111 2003/05/13 19:14:41 peter
  1100. * failn removed
  1101. * inherited result code check moven to pexpr
  1102. Revision 1.110 2003/05/13 15:18:49 peter
  1103. * fixed various crashes
  1104. Revision 1.109 2003/05/11 21:37:03 peter
  1105. * moved implicit exception frame from ncgutil to psub
  1106. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1107. Revision 1.108 2003/05/09 17:47:03 peter
  1108. * self moved to hidden parameter
  1109. * removed hdisposen,hnewn,selfn
  1110. Revision 1.107 2003/04/27 11:21:34 peter
  1111. * aktprocdef renamed to current_procdef
  1112. * procinfo renamed to current_procinfo
  1113. * procinfo will now be stored in current_module so it can be
  1114. cleaned up properly
  1115. * gen_main_procsym changed to create_main_proc and release_main_proc
  1116. to also generate a tprocinfo structure
  1117. * fixed unit implicit initfinal
  1118. Revision 1.106 2003/04/27 07:29:50 peter
  1119. * current_procdef cleanup, current_procdef is now always nil when parsing
  1120. a new procdef declaration
  1121. * aktprocsym removed
  1122. * lexlevel removed, use symtable.symtablelevel instead
  1123. * implicit init/final code uses the normal genentry/genexit
  1124. * funcret state checking updated for new funcret handling
  1125. Revision 1.105 2003/04/26 00:31:42 peter
  1126. * set return_offset moved to after_header
  1127. Revision 1.104 2003/04/25 20:59:34 peter
  1128. * removed funcretn,funcretsym, function result is now in varsym
  1129. and aliases for result and function name are added using absolutesym
  1130. * vs_hidden parameter for funcret passed in parameter
  1131. * vs_hidden fixes
  1132. * writenode changed to printnode and released from extdebug
  1133. * -vp option added to generate a tree.log with the nodetree
  1134. * nicer printnode for statements, callnode
  1135. Revision 1.103 2003/04/24 13:03:01 florian
  1136. * comp is now written with its bit pattern to the ppu instead as an extended
  1137. Revision 1.102 2003/04/23 12:35:34 florian
  1138. * fixed several issues with powerpc
  1139. + applied a patch from Jonas for nested function calls (PowerPC only)
  1140. * ...
  1141. Revision 1.101 2003/04/22 14:33:38 peter
  1142. * removed some notes/hints
  1143. Revision 1.100 2003/04/22 13:47:08 peter
  1144. * fixed C style array of const
  1145. * fixed C array passing
  1146. * fixed left to right with high parameters
  1147. Revision 1.99 2003/04/22 10:09:35 daniel
  1148. + Implemented the actual register allocator
  1149. + Scratch registers unavailable when new register allocator used
  1150. + maybe_save/maybe_restore unavailable when new register allocator used
  1151. Revision 1.98 2003/04/17 07:50:24 daniel
  1152. * Some work on interference graph construction
  1153. Revision 1.97 2003/04/16 09:26:55 jonas
  1154. * assembler procedures now again get a stackframe if they have local
  1155. variables. No space is reserved for a function result however.
  1156. Also, the register parameters aren't automatically saved on the stack
  1157. anymore in assembler procedures.
  1158. Revision 1.96 2003/04/05 21:09:31 jonas
  1159. * several ppc/generic result offset related fixes. The "normal" result
  1160. offset seems now to be calculated correctly and a lot of duplicate
  1161. calculations have been removed. Nested functions accessing the parent's
  1162. function result don't work at all though :(
  1163. Revision 1.95 2003/04/02 16:11:34 peter
  1164. * give error when exports is not supported
  1165. Revision 1.94 2003/03/12 22:43:38 jonas
  1166. * more powerpc and generic fixes related to the new register allocator
  1167. Revision 1.93 2003/03/08 08:59:07 daniel
  1168. + $define newra will enable new register allocator
  1169. + getregisterint will return imaginary registers with $newra
  1170. + -sr switch added, will skip register allocation so you can see
  1171. the direct output of the code generator before register allocation
  1172. Revision 1.92 2003/02/19 22:00:14 daniel
  1173. * Code generator converted to new register notation
  1174. - Horribily outdated todo.txt removed
  1175. Revision 1.91 2003/01/09 21:52:37 peter
  1176. * merged some verbosity options.
  1177. * V_LineInfo is a verbosity flag to include line info
  1178. Revision 1.90 2003/01/09 20:40:59 daniel
  1179. * Converted some code in cgx86.pas to new register numbering
  1180. Revision 1.89 2003/01/09 15:49:56 daniel
  1181. * Added register conversion
  1182. Revision 1.88 2003/01/08 18:43:56 daniel
  1183. * Tregister changed into a record
  1184. Revision 1.87 2003/01/03 20:35:08 peter
  1185. * check also interfacedef when checking for matching forwarddef
  1186. Revision 1.86 2003/01/02 11:14:02 michael
  1187. + Patch from peter to support initial values for local variables
  1188. Revision 1.85 2002/12/29 18:59:34 peter
  1189. * fixed parsing of declarations before asm statement
  1190. Revision 1.84 2002/12/29 18:25:18 peter
  1191. * parse declarations before check _ASM token
  1192. Revision 1.83 2002/12/29 14:57:50 peter
  1193. * unit loading changed to first register units and load them
  1194. afterwards. This is needed to support uses xxx in yyy correctly
  1195. * unit dependency check fixed
  1196. Revision 1.82 2002/12/25 01:26:56 peter
  1197. * duplicate procsym-unitsym fix
  1198. Revision 1.81 2002/12/15 13:37:15 peter
  1199. * don't include uf_init for library. The code is already called and
  1200. does not need to be in the initfinal table
  1201. Revision 1.80 2002/12/07 14:27:09 carl
  1202. * 3% memory optimization
  1203. * changed some types
  1204. + added type checking with different size for call node and for
  1205. parameters
  1206. Revision 1.79 2002/11/25 18:43:32 carl
  1207. - removed the invalid if <> checking (Delphi is strange on this)
  1208. + implemented abstract warning on instance creation of class with
  1209. abstract methods.
  1210. * some error message cleanups
  1211. Revision 1.78 2002/11/25 17:43:23 peter
  1212. * splitted defbase in defutil,symutil,defcmp
  1213. * merged isconvertable and is_equal into compare_defs(_ext)
  1214. * made operator search faster by walking the list only once
  1215. Revision 1.77 2002/11/23 22:50:06 carl
  1216. * some small speed optimizations
  1217. + added several new warnings/hints
  1218. Revision 1.76 2002/11/18 17:31:58 peter
  1219. * pass proccalloption to ret_in_xxx and push_xxx functions
  1220. Revision 1.75 2002/11/17 16:31:57 carl
  1221. * memory optimization (3-4%) : cleanup of tai fields,
  1222. cleanup of tdef and tsym fields.
  1223. * make it work for m68k
  1224. Revision 1.74 2002/11/15 01:58:53 peter
  1225. * merged changes from 1.0.7 up to 04-11
  1226. - -V option for generating bug report tracing
  1227. - more tracing for option parsing
  1228. - errors for cdecl and high()
  1229. - win32 import stabs
  1230. - win32 records<=8 are returned in eax:edx (turned off by default)
  1231. - heaptrc update
  1232. - more info for temp management in .s file with EXTDEBUG
  1233. Revision 1.73 2002/11/09 15:32:30 carl
  1234. * noopt for non-i386 targets
  1235. Revision 1.72 2002/09/10 20:31:48 florian
  1236. * call to current_procinfo.after_header added
  1237. Revision 1.71 2002/09/07 15:25:07 peter
  1238. * old logs removed and tabs fixed
  1239. Revision 1.70 2002/09/03 16:26:27 daniel
  1240. * Make Tprocdef.defs protected
  1241. Revision 1.69 2002/08/25 19:25:20 peter
  1242. * sym.insert_in_data removed
  1243. * symtable.insertvardata/insertconstdata added
  1244. * removed insert_in_data call from symtable.insert, it needs to be
  1245. called separatly. This allows to deref the address calculation
  1246. * procedures now calculate the parast addresses after the procedure
  1247. directives are parsed. This fixes the cdecl parast problem
  1248. * push_addr_param has an extra argument that specifies if cdecl is used
  1249. or not
  1250. Revision 1.68 2002/08/17 09:23:41 florian
  1251. * first part of procinfo rewrite
  1252. Revision 1.67 2002/08/16 14:24:59 carl
  1253. * issameref() to test if two references are the same (then emit no opcodes)
  1254. + ret_in_reg to replace ret_in_acc
  1255. (fix some register allocation bugs at the same time)
  1256. + save_std_register now has an extra parameter which is the
  1257. usedinproc registers
  1258. Revision 1.66 2002/08/11 14:32:27 peter
  1259. * renamed current_library to objectlibrary
  1260. Revision 1.65 2002/08/11 13:24:13 peter
  1261. * saving of asmsymbols in ppu supported
  1262. * asmsymbollist global is removed and moved into a new class
  1263. tasmlibrarydata that will hold the info of a .a file which
  1264. corresponds with a single module. Added librarydata to tmodule
  1265. to keep the library info stored for the module. In the future the
  1266. objectfiles will also be stored to the tasmlibrarydata class
  1267. * all getlabel/newasmsymbol and friends are moved to the new class
  1268. Revision 1.64 2002/08/09 19:14:28 carl
  1269. * fixed stackframe parameter (should only contain local size),
  1270. set to zero currently
  1271. Revision 1.63 2002/08/06 20:55:22 florian
  1272. * first part of ppc calling conventions fix
  1273. Revision 1.62 2002/07/26 21:15:41 florian
  1274. * rewrote the system handling
  1275. Revision 1.61 2002/07/20 11:57:56 florian
  1276. * types.pas renamed to defbase.pas because D6 contains a types
  1277. unit so this would conflicts if D6 programms are compiled
  1278. + Willamette/SSE2 instructions to assembler added
  1279. Revision 1.60 2002/07/19 11:41:36 daniel
  1280. * State tracker work
  1281. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1282. allows the state tracker to change while nodes automatically into
  1283. repeat nodes.
  1284. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1285. 'not(a>b)' is optimized into 'a<=b'.
  1286. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1287. by removing the notn and later switchting the true and falselabels. The
  1288. same is done with 'repeat until not a'.
  1289. Revision 1.59 2002/07/15 18:03:15 florian
  1290. * readded removed changes
  1291. Revision 1.57 2002/07/11 14:41:28 florian
  1292. * start of the new generic parameter handling
  1293. Revision 1.58 2002/07/14 18:00:44 daniel
  1294. + Added the beginning of a state tracker. This will track the values of
  1295. variables through procedures and optimize things away.
  1296. Revision 1.56 2002/07/07 09:52:32 florian
  1297. * powerpc target fixed, very simple units can be compiled
  1298. * some basic stuff for better callparanode handling, far from being finished
  1299. Revision 1.55 2002/07/04 20:43:01 florian
  1300. * first x86-64 patches
  1301. Revision 1.54 2002/07/01 18:46:25 peter
  1302. * internal linker
  1303. * reorganized aasm layer
  1304. Revision 1.53 2002/05/18 13:34:14 peter
  1305. * readded missing revisions
  1306. Revision 1.52 2002/05/16 19:46:44 carl
  1307. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1308. + try to fix temp allocation (still in ifdef)
  1309. + generic constructor calls
  1310. + start of tassembler / tmodulebase class cleanup
  1311. Revision 1.51 2002/05/14 19:34:49 peter
  1312. * removed old logs and updated copyright year
  1313. }