psub.pas 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  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. { process nested procs first }
  800. hpi:=tcgprocinfo(pi.nestedprocs.first);
  801. while assigned(hpi) do
  802. begin
  803. do_generate_code(hpi);
  804. hpi:=tcgprocinfo(hpi.next);
  805. end;
  806. { generate code for this procedure }
  807. pi.generate_code;
  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.115 2003-05-22 21:31:35 peter
  1072. * defer codegeneration for nested procedures
  1073. Revision 1.114 2003/05/16 20:00:39 jonas
  1074. * powerpc nested procedure fixes, should work completely now if all
  1075. local variables of the parent procedure are declared before the
  1076. nested procedures are declared
  1077. Revision 1.113 2003/05/16 14:33:31 peter
  1078. * regvar fixes
  1079. Revision 1.112 2003/05/13 21:26:38 peter
  1080. * only call destructor in except block when there is a destructor
  1081. available
  1082. Revision 1.111 2003/05/13 19:14:41 peter
  1083. * failn removed
  1084. * inherited result code check moven to pexpr
  1085. Revision 1.110 2003/05/13 15:18:49 peter
  1086. * fixed various crashes
  1087. Revision 1.109 2003/05/11 21:37:03 peter
  1088. * moved implicit exception frame from ncgutil to psub
  1089. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1090. Revision 1.108 2003/05/09 17:47:03 peter
  1091. * self moved to hidden parameter
  1092. * removed hdisposen,hnewn,selfn
  1093. Revision 1.107 2003/04/27 11:21:34 peter
  1094. * aktprocdef renamed to current_procdef
  1095. * procinfo renamed to current_procinfo
  1096. * procinfo will now be stored in current_module so it can be
  1097. cleaned up properly
  1098. * gen_main_procsym changed to create_main_proc and release_main_proc
  1099. to also generate a tprocinfo structure
  1100. * fixed unit implicit initfinal
  1101. Revision 1.106 2003/04/27 07:29:50 peter
  1102. * current_procdef cleanup, current_procdef is now always nil when parsing
  1103. a new procdef declaration
  1104. * aktprocsym removed
  1105. * lexlevel removed, use symtable.symtablelevel instead
  1106. * implicit init/final code uses the normal genentry/genexit
  1107. * funcret state checking updated for new funcret handling
  1108. Revision 1.105 2003/04/26 00:31:42 peter
  1109. * set return_offset moved to after_header
  1110. Revision 1.104 2003/04/25 20:59:34 peter
  1111. * removed funcretn,funcretsym, function result is now in varsym
  1112. and aliases for result and function name are added using absolutesym
  1113. * vs_hidden parameter for funcret passed in parameter
  1114. * vs_hidden fixes
  1115. * writenode changed to printnode and released from extdebug
  1116. * -vp option added to generate a tree.log with the nodetree
  1117. * nicer printnode for statements, callnode
  1118. Revision 1.103 2003/04/24 13:03:01 florian
  1119. * comp is now written with its bit pattern to the ppu instead as an extended
  1120. Revision 1.102 2003/04/23 12:35:34 florian
  1121. * fixed several issues with powerpc
  1122. + applied a patch from Jonas for nested function calls (PowerPC only)
  1123. * ...
  1124. Revision 1.101 2003/04/22 14:33:38 peter
  1125. * removed some notes/hints
  1126. Revision 1.100 2003/04/22 13:47:08 peter
  1127. * fixed C style array of const
  1128. * fixed C array passing
  1129. * fixed left to right with high parameters
  1130. Revision 1.99 2003/04/22 10:09:35 daniel
  1131. + Implemented the actual register allocator
  1132. + Scratch registers unavailable when new register allocator used
  1133. + maybe_save/maybe_restore unavailable when new register allocator used
  1134. Revision 1.98 2003/04/17 07:50:24 daniel
  1135. * Some work on interference graph construction
  1136. Revision 1.97 2003/04/16 09:26:55 jonas
  1137. * assembler procedures now again get a stackframe if they have local
  1138. variables. No space is reserved for a function result however.
  1139. Also, the register parameters aren't automatically saved on the stack
  1140. anymore in assembler procedures.
  1141. Revision 1.96 2003/04/05 21:09:31 jonas
  1142. * several ppc/generic result offset related fixes. The "normal" result
  1143. offset seems now to be calculated correctly and a lot of duplicate
  1144. calculations have been removed. Nested functions accessing the parent's
  1145. function result don't work at all though :(
  1146. Revision 1.95 2003/04/02 16:11:34 peter
  1147. * give error when exports is not supported
  1148. Revision 1.94 2003/03/12 22:43:38 jonas
  1149. * more powerpc and generic fixes related to the new register allocator
  1150. Revision 1.93 2003/03/08 08:59:07 daniel
  1151. + $define newra will enable new register allocator
  1152. + getregisterint will return imaginary registers with $newra
  1153. + -sr switch added, will skip register allocation so you can see
  1154. the direct output of the code generator before register allocation
  1155. Revision 1.92 2003/02/19 22:00:14 daniel
  1156. * Code generator converted to new register notation
  1157. - Horribily outdated todo.txt removed
  1158. Revision 1.91 2003/01/09 21:52:37 peter
  1159. * merged some verbosity options.
  1160. * V_LineInfo is a verbosity flag to include line info
  1161. Revision 1.90 2003/01/09 20:40:59 daniel
  1162. * Converted some code in cgx86.pas to new register numbering
  1163. Revision 1.89 2003/01/09 15:49:56 daniel
  1164. * Added register conversion
  1165. Revision 1.88 2003/01/08 18:43:56 daniel
  1166. * Tregister changed into a record
  1167. Revision 1.87 2003/01/03 20:35:08 peter
  1168. * check also interfacedef when checking for matching forwarddef
  1169. Revision 1.86 2003/01/02 11:14:02 michael
  1170. + Patch from peter to support initial values for local variables
  1171. Revision 1.85 2002/12/29 18:59:34 peter
  1172. * fixed parsing of declarations before asm statement
  1173. Revision 1.84 2002/12/29 18:25:18 peter
  1174. * parse declarations before check _ASM token
  1175. Revision 1.83 2002/12/29 14:57:50 peter
  1176. * unit loading changed to first register units and load them
  1177. afterwards. This is needed to support uses xxx in yyy correctly
  1178. * unit dependency check fixed
  1179. Revision 1.82 2002/12/25 01:26:56 peter
  1180. * duplicate procsym-unitsym fix
  1181. Revision 1.81 2002/12/15 13:37:15 peter
  1182. * don't include uf_init for library. The code is already called and
  1183. does not need to be in the initfinal table
  1184. Revision 1.80 2002/12/07 14:27:09 carl
  1185. * 3% memory optimization
  1186. * changed some types
  1187. + added type checking with different size for call node and for
  1188. parameters
  1189. Revision 1.79 2002/11/25 18:43:32 carl
  1190. - removed the invalid if <> checking (Delphi is strange on this)
  1191. + implemented abstract warning on instance creation of class with
  1192. abstract methods.
  1193. * some error message cleanups
  1194. Revision 1.78 2002/11/25 17:43:23 peter
  1195. * splitted defbase in defutil,symutil,defcmp
  1196. * merged isconvertable and is_equal into compare_defs(_ext)
  1197. * made operator search faster by walking the list only once
  1198. Revision 1.77 2002/11/23 22:50:06 carl
  1199. * some small speed optimizations
  1200. + added several new warnings/hints
  1201. Revision 1.76 2002/11/18 17:31:58 peter
  1202. * pass proccalloption to ret_in_xxx and push_xxx functions
  1203. Revision 1.75 2002/11/17 16:31:57 carl
  1204. * memory optimization (3-4%) : cleanup of tai fields,
  1205. cleanup of tdef and tsym fields.
  1206. * make it work for m68k
  1207. Revision 1.74 2002/11/15 01:58:53 peter
  1208. * merged changes from 1.0.7 up to 04-11
  1209. - -V option for generating bug report tracing
  1210. - more tracing for option parsing
  1211. - errors for cdecl and high()
  1212. - win32 import stabs
  1213. - win32 records<=8 are returned in eax:edx (turned off by default)
  1214. - heaptrc update
  1215. - more info for temp management in .s file with EXTDEBUG
  1216. Revision 1.73 2002/11/09 15:32:30 carl
  1217. * noopt for non-i386 targets
  1218. Revision 1.72 2002/09/10 20:31:48 florian
  1219. * call to current_procinfo.after_header added
  1220. Revision 1.71 2002/09/07 15:25:07 peter
  1221. * old logs removed and tabs fixed
  1222. Revision 1.70 2002/09/03 16:26:27 daniel
  1223. * Make Tprocdef.defs protected
  1224. Revision 1.69 2002/08/25 19:25:20 peter
  1225. * sym.insert_in_data removed
  1226. * symtable.insertvardata/insertconstdata added
  1227. * removed insert_in_data call from symtable.insert, it needs to be
  1228. called separatly. This allows to deref the address calculation
  1229. * procedures now calculate the parast addresses after the procedure
  1230. directives are parsed. This fixes the cdecl parast problem
  1231. * push_addr_param has an extra argument that specifies if cdecl is used
  1232. or not
  1233. Revision 1.68 2002/08/17 09:23:41 florian
  1234. * first part of procinfo rewrite
  1235. Revision 1.67 2002/08/16 14:24:59 carl
  1236. * issameref() to test if two references are the same (then emit no opcodes)
  1237. + ret_in_reg to replace ret_in_acc
  1238. (fix some register allocation bugs at the same time)
  1239. + save_std_register now has an extra parameter which is the
  1240. usedinproc registers
  1241. Revision 1.66 2002/08/11 14:32:27 peter
  1242. * renamed current_library to objectlibrary
  1243. Revision 1.65 2002/08/11 13:24:13 peter
  1244. * saving of asmsymbols in ppu supported
  1245. * asmsymbollist global is removed and moved into a new class
  1246. tasmlibrarydata that will hold the info of a .a file which
  1247. corresponds with a single module. Added librarydata to tmodule
  1248. to keep the library info stored for the module. In the future the
  1249. objectfiles will also be stored to the tasmlibrarydata class
  1250. * all getlabel/newasmsymbol and friends are moved to the new class
  1251. Revision 1.64 2002/08/09 19:14:28 carl
  1252. * fixed stackframe parameter (should only contain local size),
  1253. set to zero currently
  1254. Revision 1.63 2002/08/06 20:55:22 florian
  1255. * first part of ppc calling conventions fix
  1256. Revision 1.62 2002/07/26 21:15:41 florian
  1257. * rewrote the system handling
  1258. Revision 1.61 2002/07/20 11:57:56 florian
  1259. * types.pas renamed to defbase.pas because D6 contains a types
  1260. unit so this would conflicts if D6 programms are compiled
  1261. + Willamette/SSE2 instructions to assembler added
  1262. Revision 1.60 2002/07/19 11:41:36 daniel
  1263. * State tracker work
  1264. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1265. allows the state tracker to change while nodes automatically into
  1266. repeat nodes.
  1267. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1268. 'not(a>b)' is optimized into 'a<=b'.
  1269. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1270. by removing the notn and later switchting the true and falselabels. The
  1271. same is done with 'repeat until not a'.
  1272. Revision 1.59 2002/07/15 18:03:15 florian
  1273. * readded removed changes
  1274. Revision 1.57 2002/07/11 14:41:28 florian
  1275. * start of the new generic parameter handling
  1276. Revision 1.58 2002/07/14 18:00:44 daniel
  1277. + Added the beginning of a state tracker. This will track the values of
  1278. variables through procedures and optimize things away.
  1279. Revision 1.56 2002/07/07 09:52:32 florian
  1280. * powerpc target fixed, very simple units can be compiled
  1281. * some basic stuff for better callparanode handling, far from being finished
  1282. Revision 1.55 2002/07/04 20:43:01 florian
  1283. * first x86-64 patches
  1284. Revision 1.54 2002/07/01 18:46:25 peter
  1285. * internal linker
  1286. * reorganized aasm layer
  1287. Revision 1.53 2002/05/18 13:34:14 peter
  1288. * readded missing revisions
  1289. Revision 1.52 2002/05/16 19:46:44 carl
  1290. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1291. + try to fix temp allocation (still in ifdef)
  1292. + generic constructor calls
  1293. + start of tassembler / tmodulebase class cleanup
  1294. Revision 1.51 2002/05/14 19:34:49 peter
  1295. * removed old logs and updated copyright year
  1296. }