psub.pas 54 KB

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