psub.pas 54 KB

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