psub.pas 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007
  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,globals,
  23. node,nbas,
  24. symdef,procinfo;
  25. type
  26. tcgprocinfo = class(tprocinfo)
  27. private
  28. procedure add_entry_exit_code;
  29. public
  30. { code for the subroutine as tree }
  31. code : tnode;
  32. { positions in the tree for init/final }
  33. entry_asmnode,
  34. loadpara_asmnode,
  35. exitlabel_asmnode,
  36. init_asmnode,
  37. final_asmnode : tasmnode;
  38. { list to store the procinfo's of the nested procedures }
  39. nestedprocs : tlinkedlist;
  40. constructor create(aparent:tprocinfo);override;
  41. destructor destroy;override;
  42. procedure generate_code;
  43. procedure resetprocdef;
  44. procedure add_to_symtablestack;
  45. procedure remove_from_symtablestack;
  46. procedure parse_body;
  47. end;
  48. procedure printnode_reset;
  49. { reads the declaration blocks }
  50. procedure read_declarations(islibrary : boolean);
  51. { reads declarations in the interface part of a unit }
  52. procedure read_interface_declarations;
  53. implementation
  54. uses
  55. { common }
  56. cutils,
  57. { global }
  58. globtype,tokens,verbose,comphook,
  59. systems,
  60. { aasm }
  61. cpubase,aasmtai,
  62. { symtable }
  63. symconst,symbase,symsym,symtype,symtable,defutil,
  64. paramgr,
  65. ppu,fmodule,
  66. { pass 1 }
  67. nutils,nld,ncal,ncon,nflw,nadd,ncnv,nmem,
  68. pass_1,
  69. {$ifdef state_tracking}
  70. nstate,
  71. {$endif state_tracking}
  72. { pass 2 }
  73. {$ifndef NOPASS2}
  74. pass_2,
  75. {$endif}
  76. { parser }
  77. scanner,
  78. pbase,pstatmnt,pdecl,pdecsub,pexports,
  79. { codegen }
  80. tgobj,cgobj,
  81. ncgutil,regvars
  82. {$ifdef arm}
  83. ,aasmcpu
  84. {$endif arm}
  85. {$ifndef NOOPT}
  86. {$ifdef i386}
  87. ,aopt386
  88. {$else i386}
  89. ,aoptcpu
  90. {$endif i386}
  91. {$endif}
  92. ;
  93. {****************************************************************************
  94. PROCEDURE/FUNCTION BODY PARSING
  95. ****************************************************************************}
  96. procedure initializevars(p:tnamedindexitem;arg:pointer);
  97. var
  98. b : tblocknode;
  99. begin
  100. if tsym(p).typ<>varsym then
  101. exit;
  102. with tvarsym(p) do
  103. begin
  104. if assigned(defaultconstsym) then
  105. begin
  106. b:=tblocknode(arg);
  107. b.left:=cstatementnode.create(
  108. cassignmentnode.create(
  109. cloadnode.create(tsym(p),tsym(p).owner),
  110. cloadnode.create(defaultconstsym,defaultconstsym.owner)),
  111. b.left);
  112. end;
  113. end;
  114. end;
  115. procedure check_finalize_paras(p : tnamedindexitem;arg:pointer);
  116. begin
  117. if (tsym(p).typ=varsym) and
  118. (tvarsym(p).varspez=vs_value) and
  119. not is_class(tvarsym(p).vartype.def) and
  120. tvarsym(p).vartype.def.needs_inittable then
  121. include(current_procinfo.flags,pi_needs_implicit_finally);
  122. end;
  123. procedure check_finalize_locals(p : tnamedindexitem;arg:pointer);
  124. begin
  125. case tsym(p).typ of
  126. varsym :
  127. begin
  128. if (tvarsym(p).refs>0) and
  129. not(vo_is_funcret in tvarsym(p).varoptions) and
  130. not(is_class(tvarsym(p).vartype.def)) and
  131. tvarsym(p).vartype.def.needs_inittable then
  132. include(current_procinfo.flags,pi_needs_implicit_finally);
  133. end;
  134. typedconstsym :
  135. begin
  136. if ttypedconstsym(p).typedconsttype.def.needs_inittable then
  137. include(current_procinfo.flags,pi_needs_implicit_finally);
  138. end;
  139. end;
  140. end;
  141. function block(islibrary : boolean) : tnode;
  142. begin
  143. { parse const,types and vars }
  144. read_declarations(islibrary);
  145. { do we have an assembler block without the po_assembler?
  146. we should allow this for Delphi compatibility (PFV) }
  147. if (token=_ASM) and (m_delphi in aktmodeswitches) then
  148. include(current_procinfo.procdef.procoptions,po_assembler);
  149. { Handle assembler block different }
  150. if (po_assembler in current_procinfo.procdef.procoptions) then
  151. begin
  152. block:=assembler_block;
  153. exit;
  154. end;
  155. {Unit initialization?.}
  156. if (
  157. assigned(current_procinfo.procdef.localst) and
  158. (current_procinfo.procdef.localst.symtablelevel=main_program_level) and
  159. (current_module.is_unit)
  160. ) or
  161. islibrary then
  162. begin
  163. if (token=_END) then
  164. begin
  165. consume(_END);
  166. { We need at least a node, else the entry/exit code is not
  167. generated and thus no PASCALMAIN symbol which we need (PFV) }
  168. if islibrary then
  169. block:=cnothingnode.create
  170. else
  171. block:=nil;
  172. end
  173. else
  174. begin
  175. if token=_INITIALIZATION then
  176. begin
  177. { The library init code is already called and does not
  178. need to be in the initfinal table (PFV) }
  179. if not islibrary then
  180. current_module.flags:=current_module.flags or uf_init;
  181. block:=statement_block(_INITIALIZATION);
  182. end
  183. else if (token=_FINALIZATION) then
  184. begin
  185. if (current_module.flags and uf_finalize)<>0 then
  186. block:=statement_block(_FINALIZATION)
  187. else
  188. begin
  189. { can we allow no INITIALIZATION for DLL ??
  190. I think it should work PM }
  191. block:=nil;
  192. exit;
  193. end;
  194. end
  195. else
  196. begin
  197. { The library init code is already called and does not
  198. need to be in the initfinal table (PFV) }
  199. if not islibrary then
  200. current_module.flags:=current_module.flags or uf_init;
  201. block:=statement_block(_BEGIN);
  202. end;
  203. end;
  204. end
  205. else
  206. begin
  207. block:=statement_block(_BEGIN);
  208. if symtablestack.symtabletype=localsymtable then
  209. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}initializevars,block);
  210. end;
  211. end;
  212. {****************************************************************************
  213. PROCEDURE/FUNCTION COMPILING
  214. ****************************************************************************}
  215. procedure printnode_reset;
  216. begin
  217. assign(printnodefile,treelogfilename);
  218. {$I-}
  219. rewrite(printnodefile);
  220. {$I+}
  221. if ioresult<>0 then
  222. begin
  223. Comment(V_Error,'Error creating '+treelogfilename);
  224. exit;
  225. end;
  226. close(printnodefile);
  227. end;
  228. procedure printnode_procdef(pd:tprocdef);
  229. begin
  230. assign(printnodefile,treelogfilename);
  231. {$I-}
  232. append(printnodefile);
  233. if ioresult<>0 then
  234. rewrite(printnodefile);
  235. {$I+}
  236. if ioresult<>0 then
  237. begin
  238. Comment(V_Error,'Error creating '+treelogfilename);
  239. exit;
  240. end;
  241. writeln(printnodefile);
  242. writeln(printnodefile,'*******************************************************************************');
  243. writeln(printnodefile,current_procinfo.procdef.fullprocname(false));
  244. writeln(printnodefile,'*******************************************************************************');
  245. printnode(printnodefile,pd.inlininginfo^.code);
  246. close(printnodefile);
  247. end;
  248. function generate_bodyentry_block:tnode;
  249. var
  250. srsym : tsym;
  251. para : tcallparanode;
  252. newstatement : tstatementnode;
  253. htype : ttype;
  254. begin
  255. result:=internalstatements(newstatement);
  256. if assigned(current_procinfo.procdef._class) then
  257. begin
  258. { a constructor needs a help procedure }
  259. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  260. begin
  261. if is_class(current_procinfo.procdef._class) then
  262. begin
  263. include(current_procinfo.flags,pi_needs_implicit_finally);
  264. srsym:=search_class_member(current_procinfo.procdef._class,'NEWINSTANCE');
  265. if assigned(srsym) and
  266. (srsym.typ=procsym) then
  267. begin
  268. { if vmt<>0 then newinstance }
  269. addstatement(newstatement,cifnode.create(
  270. caddnode.create(unequaln,
  271. load_vmt_pointer_node,
  272. cnilnode.create),
  273. cassignmentnode.create(
  274. ctypeconvnode.create_explicit(
  275. load_self_pointer_node,
  276. voidpointertype),
  277. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_vmt_pointer_node,[])),
  278. nil));
  279. end
  280. else
  281. internalerror(200305108);
  282. end
  283. else
  284. if is_object(current_procinfo.procdef._class) then
  285. begin
  286. htype.setdef(current_procinfo.procdef._class);
  287. htype.setdef(tpointerdef.create(htype));
  288. { parameter 3 : vmt_offset }
  289. { parameter 2 : address of pointer to vmt,
  290. this is required to allow setting the vmt to -1 to indicate
  291. that memory was allocated }
  292. { parameter 1 : self pointer }
  293. para:=ccallparanode.create(
  294. cordconstnode.create(current_procinfo.procdef._class.vmt_offset,s32inttype,false),
  295. ccallparanode.create(
  296. ctypeconvnode.create_explicit(
  297. load_vmt_pointer_node,
  298. voidpointertype),
  299. ccallparanode.create(
  300. ctypeconvnode.create_explicit(
  301. load_self_pointer_node,
  302. voidpointertype),
  303. nil)));
  304. addstatement(newstatement,cassignmentnode.create(
  305. ctypeconvnode.create_explicit(
  306. load_self_pointer_node,
  307. voidpointertype),
  308. ccallnode.createintern('fpc_help_constructor',para)));
  309. end
  310. else
  311. internalerror(200305103);
  312. { if self=nil then exit
  313. calling fail instead of exit is useless because
  314. there is nothing to dispose (PFV) }
  315. addstatement(newstatement,cifnode.create(
  316. caddnode.create(equaln,
  317. load_self_pointer_node,
  318. cnilnode.create),
  319. cexitnode.create(nil),
  320. nil));
  321. end;
  322. { maybe call BeforeDestruction for classes }
  323. if (current_procinfo.procdef.proctypeoption=potype_destructor) and
  324. is_class(current_procinfo.procdef._class) then
  325. begin
  326. srsym:=search_class_member(current_procinfo.procdef._class,'BEFOREDESTRUCTION');
  327. if assigned(srsym) and
  328. (srsym.typ=procsym) then
  329. begin
  330. { if vmt<>0 then beforedestruction }
  331. addstatement(newstatement,cifnode.create(
  332. caddnode.create(unequaln,
  333. load_vmt_pointer_node,
  334. cnilnode.create),
  335. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  336. nil));
  337. end
  338. else
  339. internalerror(200305104);
  340. end;
  341. end;
  342. end;
  343. function generate_bodyexit_block:tnode;
  344. var
  345. srsym : tsym;
  346. para : tcallparanode;
  347. newstatement : tstatementnode;
  348. begin
  349. result:=internalstatements(newstatement);
  350. if assigned(current_procinfo.procdef._class) then
  351. begin
  352. { maybe call AfterConstruction for classes }
  353. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  354. is_class(current_procinfo.procdef._class) then
  355. begin
  356. srsym:=search_class_member(current_procinfo.procdef._class,'AFTERCONSTRUCTION');
  357. if assigned(srsym) and
  358. (srsym.typ=procsym) then
  359. begin
  360. { Self can be nil when fail is called }
  361. { if self<>nil and vmt<>nil then afterconstruction }
  362. addstatement(newstatement,cifnode.create(
  363. caddnode.create(andn,
  364. caddnode.create(unequaln,
  365. load_self_pointer_node,
  366. cnilnode.create),
  367. caddnode.create(unequaln,
  368. load_vmt_pointer_node,
  369. cnilnode.create)),
  370. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  371. nil));
  372. end
  373. else
  374. internalerror(200305106);
  375. end;
  376. { a destructor needs a help procedure }
  377. if (current_procinfo.procdef.proctypeoption=potype_destructor) then
  378. begin
  379. if is_class(current_procinfo.procdef._class) then
  380. begin
  381. srsym:=search_class_member(current_procinfo.procdef._class,'FREEINSTANCE');
  382. if assigned(srsym) and
  383. (srsym.typ=procsym) then
  384. begin
  385. { if self<>0 and vmt=1 then freeinstance }
  386. addstatement(newstatement,cifnode.create(
  387. caddnode.create(andn,
  388. caddnode.create(unequaln,
  389. load_self_pointer_node,
  390. cnilnode.create),
  391. caddnode.create(equaln,
  392. ctypeconvnode.create(
  393. load_vmt_pointer_node,
  394. voidpointertype),
  395. cpointerconstnode.create(1,voidpointertype))),
  396. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  397. nil));
  398. end
  399. else
  400. internalerror(200305108);
  401. end
  402. else
  403. if is_object(current_procinfo.procdef._class) then
  404. begin
  405. { finalize object data }
  406. if current_procinfo.procdef._class.needs_inittable then
  407. addstatement(newstatement,finalize_data_node(load_self_node));
  408. { parameter 3 : vmt_offset }
  409. { parameter 2 : pointer to vmt }
  410. { parameter 1 : self pointer }
  411. para:=ccallparanode.create(
  412. cordconstnode.create(current_procinfo.procdef._class.vmt_offset,s32inttype,false),
  413. ccallparanode.create(
  414. ctypeconvnode.create_explicit(
  415. load_vmt_pointer_node,
  416. voidpointertype),
  417. ccallparanode.create(
  418. ctypeconvnode.create_explicit(
  419. load_self_pointer_node,
  420. voidpointertype),
  421. nil)));
  422. addstatement(newstatement,
  423. ccallnode.createintern('fpc_help_destructor',para));
  424. end
  425. else
  426. internalerror(200305105);
  427. end;
  428. end;
  429. end;
  430. function generate_except_block:tnode;
  431. var
  432. pd : tprocdef;
  433. newstatement : tstatementnode;
  434. dummycall : tcallnode;
  435. begin
  436. generate_except_block:=internalstatements(newstatement);
  437. { a constructor needs call destructor (if available) when it
  438. is not inherited }
  439. if assigned(current_procinfo.procdef._class) and
  440. (current_procinfo.procdef.proctypeoption=potype_constructor) then
  441. begin
  442. pd:=current_procinfo.procdef._class.searchdestructor;
  443. if assigned(pd) then
  444. begin
  445. { if vmt<>0 then call destructor }
  446. addstatement(newstatement,cifnode.create(
  447. caddnode.create(unequaln,
  448. load_vmt_pointer_node,
  449. cnilnode.create),
  450. ccallnode.create(nil,tprocsym(pd.procsym),pd.procsym.owner,load_self_node,[]),
  451. nil));
  452. end;
  453. end
  454. else
  455. begin
  456. { no constructor }
  457. { must be the return value finalized before reraising the exception? }
  458. if (not is_void(current_procinfo.procdef.rettype.def)) and
  459. (current_procinfo.procdef.rettype.def.needs_inittable) and
  460. (not is_class(current_procinfo.procdef.rettype.def)) then
  461. addstatement(newstatement,finalize_data_node(load_result_node));
  462. end;
  463. end;
  464. {****************************************************************************
  465. TCGProcInfo
  466. ****************************************************************************}
  467. constructor tcgprocinfo.create(aparent:tprocinfo);
  468. begin
  469. inherited Create(aparent);
  470. nestedprocs:=tlinkedlist.create;
  471. end;
  472. destructor tcgprocinfo.destroy;
  473. begin
  474. nestedprocs.free;
  475. if assigned(code) then
  476. code.free;
  477. inherited destroy;
  478. end;
  479. procedure tcgprocinfo.add_entry_exit_code;
  480. var
  481. finalcode,
  482. bodyentrycode,
  483. bodyexitcode,
  484. exceptcode : tnode;
  485. newblock : tblocknode;
  486. codestatement,
  487. newstatement : tstatementnode;
  488. oldfilepos : tfileposinfo;
  489. begin
  490. oldfilepos:=aktfilepos;
  491. { Generate code/locations used at start of proc }
  492. aktfilepos:=entrypos;
  493. entry_asmnode:=casmnode.create_get_position;
  494. loadpara_asmnode:=casmnode.create_get_position;
  495. init_asmnode:=casmnode.create_get_position;
  496. bodyentrycode:=generate_bodyentry_block;
  497. { Generate code/locations used at end of proc }
  498. aktfilepos:=exitpos;
  499. exitlabel_asmnode:=casmnode.create_get_position;
  500. final_asmnode:=casmnode.create_get_position;
  501. bodyexitcode:=generate_bodyexit_block;
  502. { Generate procedure by combining init+body+final,
  503. depending on the implicit finally we need to add
  504. an try...finally...end wrapper }
  505. newblock:=internalstatements(newstatement);
  506. if (cs_implicit_exceptions in aktmoduleswitches) and
  507. (pi_needs_implicit_finally in flags) and
  508. { but it's useless in init/final code of units }
  509. not(procdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) then
  510. begin
  511. { Generate special exception block only needed when
  512. implicit finaly is used }
  513. aktfilepos:=exitpos;
  514. exceptcode:=generate_except_block;
  515. { Generate code that will be in the try...finally }
  516. finalcode:=internalstatements(codestatement);
  517. addstatement(codestatement,bodyexitcode);
  518. addstatement(codestatement,final_asmnode);
  519. { Initialize before try...finally...end frame }
  520. addstatement(newstatement,entry_asmnode);
  521. addstatement(newstatement,loadpara_asmnode);
  522. addstatement(newstatement,init_asmnode);
  523. addstatement(newstatement,bodyentrycode);
  524. aktfilepos:=entrypos;
  525. addstatement(newstatement,ctryfinallynode.create_implicit(
  526. code,
  527. finalcode,
  528. exceptcode));
  529. addstatement(newstatement,exitlabel_asmnode);
  530. { set flag the implicit finally has been generated }
  531. include(flags,pi_has_implicit_finally);
  532. end
  533. else
  534. begin
  535. addstatement(newstatement,entry_asmnode);
  536. addstatement(newstatement,loadpara_asmnode);
  537. addstatement(newstatement,init_asmnode);
  538. addstatement(newstatement,bodyentrycode);
  539. addstatement(newstatement,code);
  540. addstatement(newstatement,exitlabel_asmnode);
  541. addstatement(newstatement,bodyexitcode);
  542. addstatement(newstatement,final_asmnode);
  543. end;
  544. do_firstpass(newblock);
  545. code:=newblock;
  546. aktfilepos:=oldfilepos;
  547. end;
  548. procedure clearrefs(p : tnamedindexitem;arg:pointer);
  549. begin
  550. if (tsym(p).typ=varsym) then
  551. if tvarsym(p).refs>1 then
  552. tvarsym(p).refs:=1;
  553. end;
  554. procedure tcgprocinfo.generate_code;
  555. var
  556. oldprocinfo : tprocinfo;
  557. oldaktmaxfpuregisters : longint;
  558. oldfilepos : tfileposinfo;
  559. templist : Taasmoutput;
  560. headertai : tai;
  561. usesacc,
  562. usesfpu,
  563. usesacchi : boolean;
  564. begin
  565. { the initialization procedure can be empty, then we
  566. don't need to generate anything. When it was an empty
  567. procedure there would be at least a blocknode }
  568. if not assigned(code) then
  569. exit;
  570. { We need valid code }
  571. if Errorcount<>0 then
  572. exit;
  573. { The RA and Tempgen shall not be available yet }
  574. if assigned(tg) then
  575. internalerror(200309201);
  576. oldprocinfo:=current_procinfo;
  577. oldfilepos:=aktfilepos;
  578. oldaktmaxfpuregisters:=aktmaxfpuregisters;
  579. current_procinfo:=self;
  580. aktfilepos:=entrypos;
  581. { get new labels }
  582. aktbreaklabel:=nil;
  583. aktcontinuelabel:=nil;
  584. templist:=Taasmoutput.create;
  585. { add parast/localst to symtablestack }
  586. add_to_symtablestack;
  587. { when size optimization only count occurrence }
  588. if cs_littlesize in aktglobalswitches then
  589. cg.t_times:=1
  590. else
  591. { reference for repetition is 100 }
  592. cg.t_times:=100;
  593. { clear register count }
  594. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}clearrefs,nil);
  595. symtablestack.next.foreach_static({$ifdef FPCPROCVAR}@{$endif}clearrefs,nil);
  596. { there's always a call to FPC_INITIALIZEUNITS/FPC_DO_EXIT in the main program }
  597. if (procdef.localst.symtablelevel=main_program_level) and
  598. (not current_module.is_unit) then
  599. include(flags,pi_do_call);
  600. { set implicit_finally flag when there are locals/paras to be finalized }
  601. current_procinfo.procdef.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_finalize_paras,nil);
  602. current_procinfo.procdef.localst.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_finalize_locals,nil);
  603. { firstpass everything }
  604. flowcontrol:=[];
  605. do_firstpass(code);
  606. if code.registersfpu>0 then
  607. include(current_procinfo.flags,pi_uses_fpu);
  608. { add implicit entry and exit code }
  609. add_entry_exit_code;
  610. { only do secondpass if there are no errors }
  611. if ErrorCount=0 then
  612. begin
  613. { set the start offset to the start of the temp area in the stack }
  614. tg:=ttgobj.create;
  615. { Create register allocator }
  616. cg.init_register_allocators;
  617. set_first_temp_offset;
  618. generate_parameter_info;
  619. { Allocate space in temp/registers for parast and localst }
  620. aktfilepos:=entrypos;
  621. gen_alloc_parast(aktproccode,tparasymtable(procdef.parast));
  622. if procdef.localst.symtabletype=localsymtable then
  623. gen_alloc_localst(aktproccode,tlocalsymtable(procdef.localst));
  624. { Store temp offset for information about 'real' temps }
  625. tempstart:=tg.lasttemp;
  626. { Generate code to load register parameters in temps and insert local
  627. copies for values parameters. This must be done before the code for the
  628. body is generated because the localloc is updated.
  629. Note: The generated code will be inserted after the code generation of
  630. the body is finished, because only then the position is known }
  631. {$ifdef oldregvars}
  632. assign_regvars(code);
  633. {$endif oldreg}
  634. aktfilepos:=entrypos;
  635. gen_load_para_value(templist);
  636. { caller paraloc info is also necessary in the stackframe_entry
  637. code of the ppc (and possibly other processors) }
  638. if not procdef.has_paraloc_info then
  639. begin
  640. procdef.requiredargarea:=paramanager.create_paraloc_info(procdef,callerside);
  641. procdef.has_paraloc_info:=true;
  642. end;
  643. { generate code for the node tree }
  644. do_secondpass(code);
  645. aktproccode.concatlist(exprasmlist);
  646. {$ifdef i386}
  647. procdef.fpu_used:=code.registersfpu;
  648. {$endif i386}
  649. { The position of the loadpara_asmnode is now known }
  650. aktproccode.insertlistafter(loadpara_asmnode.currenttai,templist);
  651. { first generate entry and initialize code with the correct
  652. position and switches }
  653. aktfilepos:=entrypos;
  654. aktlocalswitches:=entryswitches;
  655. gen_entry_code(templist);
  656. aktproccode.insertlistafter(entry_asmnode.currenttai,templist);
  657. gen_initialize_code(templist,false);
  658. aktproccode.insertlistafter(init_asmnode.currenttai,templist);
  659. { now generate finalize and exit code with the correct position
  660. and switches }
  661. aktfilepos:=exitpos;
  662. aktlocalswitches:=exitswitches;
  663. gen_finalize_code(templist,false);
  664. { the finalcode must be concated if there was no position available,
  665. using insertlistafter will result in an insert at the start
  666. when currentai=nil }
  667. if assigned(final_asmnode.currenttai) then
  668. aktproccode.insertlistafter(final_asmnode.currenttai,templist)
  669. else
  670. aktproccode.concatlist(templist);
  671. { insert exit label at the correct position }
  672. cg.a_label(templist,aktexitlabel);
  673. if assigned(exitlabel_asmnode.currenttai) then
  674. aktproccode.insertlistafter(exitlabel_asmnode.currenttai,templist)
  675. else
  676. aktproccode.concatlist(templist);
  677. { exit code }
  678. gen_exit_code(templist);
  679. aktproccode.concatlist(templist);
  680. {$ifdef OLDREGVARS}
  681. { note: this must be done only after as much code as possible has }
  682. { been generated. The result is that when you ungetregister() a }
  683. { regvar, it will actually free the regvar (and alse free the }
  684. { the regvars at the same time). Doing this too early will }
  685. { confuse the register allocator, as the regvars will still be }
  686. { used. It should be done before loading the result regs (so }
  687. { they don't conflict with the regvars) and before }
  688. { gen_entry_code (that one has to be able to allocate the }
  689. { regvars again) (JM) }
  690. free_regvars(aktproccode);
  691. {$endif OLDREGVARS}
  692. { add code that will load the return value, this is not done
  693. for assembler routines when they didn't reference the result
  694. variable }
  695. usesacc:=false;
  696. usesfpu:=false;
  697. usesacchi:=false;
  698. gen_load_return_value(templist,usesacc,usesacchi,usesfpu);
  699. aktproccode.concatlist(templist);
  700. { generate symbol and save end of header position }
  701. aktfilepos:=entrypos;
  702. gen_proc_symbol(templist);
  703. headertai:=tai(templist.last);
  704. { insert symbol }
  705. aktproccode.insertlist(templist);
  706. { Free space in temp/registers for parast and localst, must be
  707. done after gen_entry_code }
  708. aktfilepos:=exitpos;
  709. if procdef.localst.symtabletype=localsymtable then
  710. gen_free_localst(aktproccode,tlocalsymtable(procdef.localst));
  711. gen_free_parast(aktproccode,tparasymtable(procdef.parast));
  712. { The procedure body is finished, we can now
  713. allocate the registers }
  714. cg.do_register_allocation(aktproccode,headertai);
  715. { Add save and restore of used registers }
  716. aktfilepos:=entrypos;
  717. gen_save_used_regs(templist);
  718. aktproccode.insertlistafter(headertai,templist);
  719. aktfilepos:=exitpos;
  720. gen_restore_used_regs(aktproccode,procdef.funcret_paraloc[calleeside]);
  721. { Add stack allocation code after header }
  722. aktfilepos:=entrypos;
  723. gen_stackalloc_code(templist);
  724. aktproccode.insertlistafter(headertai,templist);
  725. { Add exit code at the end }
  726. aktfilepos:=exitpos;
  727. gen_stackfree_code(templist,usesacc,usesacchi);
  728. aktproccode.concatlist(templist);
  729. { check if the implicit finally has been generated. The flag
  730. should already be set in pass1 }
  731. if (cs_implicit_exceptions in aktmoduleswitches) and
  732. not(procdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) and
  733. (pi_needs_implicit_finally in flags) and
  734. not(pi_has_implicit_finally in flags) then
  735. internalerror(200405231);
  736. {$ifndef NoOpt}
  737. if not(cs_no_regalloc in aktglobalswitches) then
  738. begin
  739. if (cs_optimize in aktglobalswitches) and
  740. { do not optimize pure assembler procedures }
  741. not(pi_is_assembler in flags) then
  742. optimize(aktproccode);
  743. end;
  744. {$endif NoOpt}
  745. { Add end symbol and debug info }
  746. aktfilepos:=exitpos;
  747. gen_proc_symbol_end(templist);
  748. aktproccode.concatlist(templist);
  749. {$ifdef ARM}
  750. insertpcrelativedata(aktproccode,aktlocaldata);
  751. {$endif ARM}
  752. { save local data (casetable) also in the same file }
  753. if assigned(aktlocaldata) and
  754. (not aktlocaldata.empty) then
  755. begin
  756. { because of the limited constant size of the arm, all data access is done pc relative }
  757. if target_info.cpu=cpu_arm then
  758. aktproccode.concatlist(aktlocaldata)
  759. else
  760. begin
  761. aktproccode.concat(Tai_section.Create(sec_data));
  762. aktproccode.concatlist(aktlocaldata);
  763. aktproccode.concat(Tai_section.Create(sec_code));
  764. end;
  765. end;
  766. { add the procedure to the codesegment }
  767. if (cs_create_smart in aktmoduleswitches) then
  768. codesegment.concat(Tai_cut.Create);
  769. codesegment.concatlist(aktproccode);
  770. { only now we can remove the temps }
  771. tg.resettempgen;
  772. { stop tempgen and ra }
  773. tg.free;
  774. cg.done_register_allocators;
  775. tg:=nil;
  776. end;
  777. { restore symtablestack }
  778. remove_from_symtablestack;
  779. { restore }
  780. templist.free;
  781. aktmaxfpuregisters:=oldaktmaxfpuregisters;
  782. aktfilepos:=oldfilepos;
  783. current_procinfo:=oldprocinfo;
  784. end;
  785. procedure tcgprocinfo.add_to_symtablestack;
  786. var
  787. _class,hp : tobjectdef;
  788. begin
  789. { insert symtables for the class, but only if it is no nested function }
  790. if assigned(procdef._class) and
  791. not(assigned(parent) and
  792. assigned(parent.procdef) and
  793. assigned(parent.procdef._class)) then
  794. begin
  795. { insert them in the reverse order }
  796. hp:=nil;
  797. repeat
  798. _class:=procdef._class;
  799. while _class.childof<>hp do
  800. _class:=_class.childof;
  801. hp:=_class;
  802. _class.symtable.next:=symtablestack;
  803. symtablestack:=_class.symtable;
  804. until hp=procdef._class;
  805. end;
  806. { insert parasymtable in symtablestack when parsing
  807. a function }
  808. if procdef.parast.symtablelevel>=normal_function_level then
  809. begin
  810. procdef.parast.next:=symtablestack;
  811. symtablestack:=procdef.parast;
  812. end;
  813. procdef.localst.next:=symtablestack;
  814. symtablestack:=procdef.localst;
  815. end;
  816. procedure tcgprocinfo.remove_from_symtablestack;
  817. begin
  818. { remove localst/parast }
  819. if procdef.parast.symtablelevel>=normal_function_level then
  820. symtablestack:=symtablestack.next.next
  821. else
  822. symtablestack:=symtablestack.next;
  823. { remove class member symbol tables }
  824. while symtablestack.symtabletype=objectsymtable do
  825. symtablestack:=symtablestack.next;
  826. end;
  827. procedure tcgprocinfo.resetprocdef;
  828. begin
  829. { the local symtables can be deleted, but the parast }
  830. { doesn't, (checking definitons when calling a }
  831. { function }
  832. { not for a inline procedure !! (PM) }
  833. { at lexlevel = 1 localst is the staticsymtable itself }
  834. { so no dispose here !! }
  835. if assigned(code) and
  836. not(cs_browser in aktmoduleswitches) and
  837. (procdef.proccalloption<>pocall_inline) then
  838. begin
  839. if procdef.parast.symtablelevel>=normal_function_level then
  840. procdef.localst.free;
  841. procdef.localst:=nil;
  842. end;
  843. { remove code tree, if not inline procedure }
  844. if assigned(code) then
  845. begin
  846. { the inline procedure has already got a copy of the tree
  847. stored in current_procinfo.procdef.code }
  848. code.free;
  849. code:=nil;
  850. if (procdef.proccalloption<>pocall_inline) then
  851. procdef.inlininginfo^.code:=nil;
  852. end;
  853. end;
  854. procedure tcgprocinfo.parse_body;
  855. var
  856. oldprocinfo : tprocinfo;
  857. oldblock_type : tblock_type;
  858. begin
  859. oldprocinfo:=current_procinfo;
  860. oldblock_type:=block_type;
  861. { reset break and continue labels }
  862. block_type:=bt_body;
  863. current_procinfo:=self;
  864. { calculate the lexical level }
  865. if procdef.parast.symtablelevel>maxnesting then
  866. Message(parser_e_too_much_lexlevel);
  867. { static is also important for local procedures !! }
  868. if (po_staticmethod in procdef.procoptions) then
  869. allow_only_static:=true
  870. else if (procdef.parast.symtablelevel=normal_function_level) then
  871. allow_only_static:=false;
  872. {$ifdef state_tracking}
  873. { aktstate:=Tstate_storage.create;}
  874. {$endif state_tracking}
  875. { create a local symbol table for this routine }
  876. if not assigned(procdef.localst) then
  877. procdef.insert_localst;
  878. { add parast/localst to symtablestack }
  879. add_to_symtablestack;
  880. { constant symbols are inserted in this symboltable }
  881. constsymtable:=symtablestack;
  882. { save entry info }
  883. entrypos:=aktfilepos;
  884. entryswitches:=aktlocalswitches;
  885. { parse the code ... }
  886. code:=block(current_module.islibrary);
  887. { save exit info }
  888. exitswitches:=aktlocalswitches;
  889. exitpos:=last_endtoken_filepos;
  890. { the procedure is now defined }
  891. procdef.forwarddef:=false;
  892. { Check for unused labels, forwards, symbols for procedures. Static
  893. symtable is checked in pmodules }
  894. if (Errorcount=0) and
  895. (tstoredsymtable(procdef.localst).symtabletype<>staticsymtable) then
  896. begin
  897. { check if forwards are resolved }
  898. tstoredsymtable(procdef.localst).check_forwards;
  899. { check if all labels are used }
  900. tstoredsymtable(procdef.localst).checklabels;
  901. { remove cross unit overloads }
  902. tstoredsymtable(procdef.localst).unchain_overloaded;
  903. { check for unused symbols, but only if there is no asm block }
  904. if not(pi_uses_asm in flags) then
  905. begin
  906. tstoredsymtable(procdef.localst).allsymbolsused;
  907. tstoredsymtable(procdef.parast).allsymbolsused;
  908. end;
  909. end;
  910. if assigned(code) then
  911. begin
  912. { get a better entry point }
  913. entrypos:=code.fileinfo;
  914. { Finish type checking pass }
  915. do_resulttypepass(code);
  916. end;
  917. { store a copy of the original tree for inline, for
  918. normal procedures only store a reference to the
  919. current tree }
  920. if (procdef.proccalloption=pocall_inline) then
  921. begin
  922. procdef.inlininginfo^.code:=code.getcopy;
  923. procdef.inlininginfo^.flags:=current_procinfo.flags;
  924. end
  925. else
  926. procdef.inlininginfo^.code:=code;
  927. { Print the node to tree.log }
  928. if paraprintnodetree=1 then
  929. printnode_procdef(procdef);
  930. { ... remove symbol tables }
  931. remove_from_symtablestack;
  932. {$ifdef state_tracking}
  933. { aktstate.destroy;}
  934. {$endif state_tracking}
  935. { reset to normal non static function }
  936. if (procdef.parast.symtablelevel=normal_function_level) then
  937. allow_only_static:=false;
  938. current_procinfo:=oldprocinfo;
  939. block_type:=oldblock_type;
  940. end;
  941. {****************************************************************************
  942. PROCEDURE/FUNCTION PARSING
  943. ****************************************************************************}
  944. procedure check_init_paras(p:tnamedindexitem;arg:pointer);
  945. begin
  946. if tsym(p).typ<>varsym then
  947. exit;
  948. with tvarsym(p) do
  949. if (not is_class(vartype.def) and
  950. vartype.def.needs_inittable and
  951. (varspez in [vs_value,vs_out])) then
  952. include(current_procinfo.flags,pi_do_call);
  953. end;
  954. procedure read_proc;
  955. {
  956. Parses the procedure directives, then parses the procedure body, then
  957. generates the code for it
  958. }
  959. procedure do_generate_code(pi:tcgprocinfo);
  960. var
  961. hpi : tcgprocinfo;
  962. begin
  963. { generate code for this procedure }
  964. pi.generate_code;
  965. { process nested procs }
  966. hpi:=tcgprocinfo(pi.nestedprocs.first);
  967. while assigned(hpi) do
  968. begin
  969. do_generate_code(hpi);
  970. hpi:=tcgprocinfo(hpi.next);
  971. end;
  972. pi.resetprocdef;
  973. end;
  974. var
  975. old_current_procinfo : tprocinfo;
  976. oldconstsymtable : tsymtable;
  977. oldfailtokenmode : tmodeswitch;
  978. pdflags : tpdflags;
  979. pd : tprocdef;
  980. isnestedproc : boolean;
  981. begin
  982. { save old state }
  983. oldconstsymtable:=constsymtable;
  984. old_current_procinfo:=current_procinfo;
  985. { reset current_procinfo.procdef to nil to be sure that nothing is writing
  986. to an other procdef }
  987. current_procinfo:=nil;
  988. { parse procedure declaration }
  989. if assigned(old_current_procinfo) and
  990. assigned(old_current_procinfo.procdef) then
  991. pd:=parse_proc_dec(old_current_procinfo.procdef._class)
  992. else
  993. pd:=parse_proc_dec(nil);
  994. { set the default function options }
  995. if parse_only then
  996. begin
  997. pd.forwarddef:=true;
  998. { set also the interface flag, for better error message when the
  999. implementation doesn't much this header }
  1000. pd.interfacedef:=true;
  1001. include(pd.procoptions,po_public);
  1002. pdflags:=[pd_interface];
  1003. end
  1004. else
  1005. begin
  1006. pdflags:=[pd_body];
  1007. if (not current_module.in_interface) then
  1008. include(pdflags,pd_implemen);
  1009. if (not current_module.is_unit) or
  1010. (cs_create_smart in aktmoduleswitches) then
  1011. include(pd.procoptions,po_public);
  1012. pd.forwarddef:=false;
  1013. end;
  1014. { parse the directives that may follow }
  1015. parse_proc_directives(pd,pdflags);
  1016. { hint directives, these can be separated by semicolons here,
  1017. that needs to be handled here with a loop (PFV) }
  1018. while try_consume_hintdirective(pd.symoptions) do
  1019. Consume(_SEMICOLON);
  1020. { Set calling convention }
  1021. handle_calling_convention(pd);
  1022. { everything of the proc definition is known, we can now
  1023. calculate the parameters }
  1024. calc_parast(pd);
  1025. { search for forward declarations }
  1026. if not proc_add_definition(pd) then
  1027. begin
  1028. { A method must be forward defined (in the object declaration) }
  1029. if assigned(pd._class) and
  1030. (not assigned(old_current_procinfo.procdef._class)) then
  1031. begin
  1032. MessagePos1(pd.fileinfo,parser_e_header_dont_match_any_member,pd.fullprocname(false));
  1033. tprocsym(pd.procsym).write_parameter_lists(pd);
  1034. end
  1035. else
  1036. begin
  1037. { Give a better error if there is a forward def in the interface and only
  1038. a single implementation }
  1039. if (not pd.forwarddef) and
  1040. (not pd.interfacedef) and
  1041. (tprocsym(pd.procsym).procdef_count>1) and
  1042. tprocsym(pd.procsym).first_procdef.forwarddef and
  1043. tprocsym(pd.procsym).first_procdef.interfacedef and
  1044. not(tprocsym(pd.procsym).procdef_count>2) then
  1045. begin
  1046. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,pd.fullprocname(false));
  1047. tprocsym(pd.procsym).write_parameter_lists(pd);
  1048. end;
  1049. end;
  1050. end;
  1051. { compile procedure when a body is needed }
  1052. if (pd_body in pdflags) then
  1053. begin
  1054. Message1(parser_d_procedure_start,pd.fullprocname(false));
  1055. { create a new procedure }
  1056. current_procinfo:=cprocinfo.create(old_current_procinfo);
  1057. current_module.procinfo:=current_procinfo;
  1058. current_procinfo.procdef:=pd;
  1059. isnestedproc:=(current_procinfo.procdef.parast.symtablelevel>normal_function_level);
  1060. { Insert mangledname }
  1061. pd.aliasnames.insert(pd.mangledname);
  1062. { Insert result variables in the localst }
  1063. insert_funcret_local(pd);
  1064. { check if there are para's which require initing -> set }
  1065. { pi_do_call (if not yet set) }
  1066. if not(pi_do_call in current_procinfo.flags) then
  1067. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_init_paras,nil);
  1068. { set _FAIL as keyword if constructor }
  1069. if (pd.proctypeoption=potype_constructor) then
  1070. begin
  1071. oldfailtokenmode:=tokeninfo^[_FAIL].keyword;
  1072. tokeninfo^[_FAIL].keyword:=m_all;
  1073. end;
  1074. tcgprocinfo(current_procinfo).parse_body;
  1075. { When it's a nested procedure then defer the code generation,
  1076. when back at normal function level then generate the code
  1077. for all defered nested procedures and the current procedure }
  1078. if isnestedproc then
  1079. tcgprocinfo(current_procinfo.parent).nestedprocs.insert(current_procinfo)
  1080. else
  1081. begin
  1082. { We can't support inlining for procedures that have nested
  1083. procedures because the nested procedures use a fixed offset
  1084. for accessing locals in the parent procedure (PFV) }
  1085. if (current_procinfo.procdef.proccalloption=pocall_inline) and
  1086. (tcgprocinfo(current_procinfo).nestedprocs.count>0) then
  1087. begin
  1088. Message1(parser_w_not_supported_for_inline,'nested procedures');
  1089. Message(parser_w_inlining_disabled);
  1090. current_procinfo.procdef.proccalloption:=pocall_default;
  1091. end;
  1092. do_generate_code(tcgprocinfo(current_procinfo));
  1093. end;
  1094. { reset _FAIL as _SELF normal }
  1095. if (pd.proctypeoption=potype_constructor) then
  1096. tokeninfo^[_FAIL].keyword:=oldfailtokenmode;
  1097. { release procinfo }
  1098. if tprocinfo(current_module.procinfo)<>current_procinfo then
  1099. internalerror(200304274);
  1100. current_module.procinfo:=current_procinfo.parent;
  1101. if not isnestedproc then
  1102. current_procinfo.free;
  1103. consume(_SEMICOLON);
  1104. end;
  1105. { Restore old state }
  1106. constsymtable:=oldconstsymtable;
  1107. current_procinfo:=old_current_procinfo;
  1108. end;
  1109. {****************************************************************************
  1110. DECLARATION PARSING
  1111. ****************************************************************************}
  1112. { search in symtablestack for not complete classes }
  1113. procedure check_forward_class(p : tnamedindexitem;arg:pointer);
  1114. begin
  1115. if (tsym(p).typ=typesym) and
  1116. (ttypesym(p).restype.def.deftype=objectdef) and
  1117. (oo_is_forward in tobjectdef(ttypesym(p).restype.def).objectoptions) then
  1118. MessagePos1(tsym(p).fileinfo,sym_e_forward_type_not_resolved,tsym(p).realname);
  1119. end;
  1120. procedure read_declarations(islibrary : boolean);
  1121. begin
  1122. repeat
  1123. if not assigned(current_procinfo) then
  1124. internalerror(200304251);
  1125. case token of
  1126. _LABEL:
  1127. label_dec;
  1128. _CONST:
  1129. const_dec;
  1130. _TYPE:
  1131. type_dec;
  1132. _VAR:
  1133. var_dec;
  1134. _THREADVAR:
  1135. threadvar_dec;
  1136. _CONSTRUCTOR,
  1137. _DESTRUCTOR,
  1138. _FUNCTION,
  1139. _PROCEDURE,
  1140. _OPERATOR,
  1141. _CLASS:
  1142. read_proc;
  1143. _EXPORTS:
  1144. begin
  1145. if not(assigned(current_procinfo.procdef.localst)) or
  1146. (current_procinfo.procdef.localst.symtablelevel>main_program_level) or
  1147. (current_module.is_unit) then
  1148. begin
  1149. Message(parser_e_syntax_error);
  1150. consume_all_until(_SEMICOLON);
  1151. end
  1152. else if islibrary or
  1153. (target_info.system in [system_i386_WIN32,system_i386_wdosx,system_i386_Netware]) then
  1154. read_exports
  1155. else
  1156. begin
  1157. Message(parser_w_unsupported_feature);
  1158. consume(_BEGIN);
  1159. end;
  1160. end
  1161. else
  1162. begin
  1163. case idtoken of
  1164. _RESOURCESTRING :
  1165. resourcestring_dec;
  1166. _PROPERTY:
  1167. begin
  1168. if (m_fpc in aktmodeswitches) then
  1169. property_dec
  1170. else
  1171. break;
  1172. end;
  1173. else
  1174. break;
  1175. end;
  1176. end;
  1177. end;
  1178. until false;
  1179. { check for incomplete class definitions, this is only required
  1180. for fpc modes }
  1181. if (m_fpc in aktmodeswitches) then
  1182. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_forward_class,nil);
  1183. end;
  1184. procedure read_interface_declarations;
  1185. begin
  1186. repeat
  1187. case token of
  1188. _CONST :
  1189. const_dec;
  1190. _TYPE :
  1191. type_dec;
  1192. _VAR :
  1193. var_dec;
  1194. _THREADVAR :
  1195. threadvar_dec;
  1196. _FUNCTION,
  1197. _PROCEDURE,
  1198. _OPERATOR :
  1199. read_proc;
  1200. else
  1201. begin
  1202. case idtoken of
  1203. _RESOURCESTRING :
  1204. resourcestring_dec;
  1205. _PROPERTY:
  1206. begin
  1207. if (m_fpc in aktmodeswitches) then
  1208. property_dec
  1209. else
  1210. break;
  1211. end;
  1212. else
  1213. break;
  1214. end;
  1215. end;
  1216. end;
  1217. until false;
  1218. { check for incomplete class definitions, this is only required
  1219. for fpc modes }
  1220. if (m_fpc in aktmodeswitches) then
  1221. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_forward_class,nil);
  1222. end;
  1223. end.
  1224. {
  1225. $Log$
  1226. Revision 1.193 2004-05-24 17:31:12 peter
  1227. * also check local typed const
  1228. Revision 1.192 2004/05/23 18:28:41 peter
  1229. * methodpointer is loaded into a temp when it was a calln
  1230. Revision 1.191 2004/05/23 15:06:21 peter
  1231. * implicit_finally flag must be set in pass1
  1232. * add check whether the implicit frame is generated when expected
  1233. Revision 1.190 2004/05/20 21:54:33 florian
  1234. + <pointer> - <pointer> result is divided by the pointer element size now
  1235. this is delphi compatible as well as resulting in the expected result for p1+(p2-p1)
  1236. Revision 1.189 2004/05/19 22:25:56 jonas
  1237. * fixed web bug 3104: if stack checking is on, procedures pi_do_call
  1238. must be set
  1239. Revision 1.188 2004/05/16 13:29:21 peter
  1240. * fix checking for forwards in static symtable
  1241. Revision 1.187 2004/04/11 12:37:30 peter
  1242. * fix tree printing
  1243. Revision 1.186 2004/02/19 17:07:42 florian
  1244. * fixed arg. area calculation
  1245. Revision 1.185 2004/02/08 18:08:59 jonas
  1246. * fixed regvars support. Needs -doldregvars to activate. Only tested with
  1247. ppc, other processors should however only require maxregvars and
  1248. maxfpuregvars constants in cpubase.pas. Remember to take scratch-
  1249. registers into account when defining that value.
  1250. Revision 1.184 2004/02/04 22:01:13 peter
  1251. * first try to get cpupara working for x86_64
  1252. Revision 1.183 2004/02/03 22:32:54 peter
  1253. * renamed xNNbittype to xNNinttype
  1254. * renamed registers32 to registersint
  1255. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  1256. Revision 1.182 2004/01/21 19:01:03 florian
  1257. * fixed handling of max. distance of pc relative symbols
  1258. Revision 1.181 2003/12/21 19:42:43 florian
  1259. * fixed ppc inlining stuff
  1260. * fixed wrong unit writing
  1261. + added some sse stuff
  1262. Revision 1.180 2003/12/19 22:08:44 daniel
  1263. * Some work to restore the MMX capabilities
  1264. Revision 1.179 2003/12/16 22:36:19 florian
  1265. * forgot a commit
  1266. Revision 1.178 2003/12/16 21:29:24 florian
  1267. + inlined procedures inherit procinfo flags
  1268. Revision 1.177 2003/12/15 21:25:48 peter
  1269. * reg allocations for imaginary register are now inserted just
  1270. before reg allocation
  1271. * tregister changed to enum to allow compile time check
  1272. * fixed several tregister-tsuperregister errors
  1273. Revision 1.176 2003/12/10 16:37:01 peter
  1274. * global property support for fpc modes
  1275. Revision 1.175 2003/12/03 23:13:20 peter
  1276. * delayed paraloc allocation, a_param_*() gets extra parameter
  1277. if it needs to allocate temp or real paralocation
  1278. * optimized/simplified int-real loading
  1279. Revision 1.174 2003/11/27 09:08:01 florian
  1280. * resourcestring is allowed in the interface
  1281. Revision 1.173 2003/11/23 17:05:16 peter
  1282. * register calling is left-right
  1283. * parameter ordering
  1284. * left-right calling inserts result parameter last
  1285. Revision 1.172 2003/11/22 00:40:19 jonas
  1286. * fixed optimiser so it compiles again
  1287. * fixed several bugs which were in there already for a long time, but
  1288. which only popped up now :) -O2/-O3 will now optimise less than in
  1289. the past (and correctly so), but -O2u/-O3u will optimise a bit more
  1290. * some more small improvements for -O3 are still possible
  1291. Revision 1.171 2003/11/10 22:02:52 peter
  1292. * cross unit inlining fixed
  1293. Revision 1.170 2003/11/07 15:58:32 florian
  1294. * Florian's culmutative nr. 1; contains:
  1295. - invalid calling conventions for a certain cpu are rejected
  1296. - arm softfloat calling conventions
  1297. - -Sp for cpu dependend code generation
  1298. - several arm fixes
  1299. - remaining code for value open array paras on heap
  1300. Revision 1.169 2003/10/31 15:52:18 peter
  1301. * fix crash with fail in constructor
  1302. Revision 1.168 2003/10/30 16:22:40 peter
  1303. * call firstpass before allocation and codegeneration is started
  1304. * move leftover code from pass_2.generatecode() to psub
  1305. Revision 1.167 2003/10/24 17:40:23 peter
  1306. * cleanup of the entry and exit code insertion
  1307. Revision 1.166 2003/10/21 15:14:33 peter
  1308. * fixed memleak for initfinalcode
  1309. * exit from generatecode when there are already errors
  1310. Revision 1.165 2003/10/20 19:28:51 peter
  1311. * disable inlining when nested procedures are found
  1312. Revision 1.164 2003/10/19 01:34:30 florian
  1313. * some ppc stuff fixed
  1314. * memory leak fixed
  1315. Revision 1.163 2003/10/17 14:38:32 peter
  1316. * 64k registers supported
  1317. * fixed some memory leaks
  1318. Revision 1.162 2003/10/10 17:48:13 peter
  1319. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1320. * tregisteralloctor renamed to trgobj
  1321. * removed rgobj from a lot of units
  1322. * moved location_* and reference_* to cgobj
  1323. * first things for mmx register allocation
  1324. Revision 1.161 2003/10/09 21:31:37 daniel
  1325. * Register allocator splitted, ans abstract now
  1326. Revision 1.160 2003/10/09 15:20:56 peter
  1327. * self is not a token anymore. It is handled special when found
  1328. in a code block and when parsing an method
  1329. Revision 1.159 2003/10/07 15:17:07 peter
  1330. * inline supported again, LOC_REFERENCEs are used to pass the
  1331. parameters
  1332. * inlineparasymtable,inlinelocalsymtable removed
  1333. * exitlabel inserting fixed
  1334. Revision 1.158 2003/10/06 22:23:41 florian
  1335. + added basic olevariant support
  1336. Revision 1.157 2003/10/03 14:45:09 peter
  1337. * more proc directive for procvar fixes
  1338. Revision 1.156 2003/10/02 21:20:32 peter
  1339. * handle_calling_convention removed from parse_proc_directive to
  1340. separate call
  1341. Revision 1.155 2003/10/01 20:34:49 peter
  1342. * procinfo unit contains tprocinfo
  1343. * cginfo renamed to cgbase
  1344. * moved cgmessage to verbose
  1345. * fixed ppc and sparc compiles
  1346. Revision 1.154 2003/09/29 20:58:56 peter
  1347. * optimized releasing of registers
  1348. Revision 1.153 2003/09/28 17:55:04 peter
  1349. * parent framepointer changed to hidden parameter
  1350. * tloadparentfpnode added
  1351. Revision 1.152 2003/09/27 13:29:43 peter
  1352. * fix reported file position for not matched forwards
  1353. Revision 1.151 2003/09/25 21:25:13 peter
  1354. * remove allocate_intterupt_parameter, allocation is platform
  1355. dependent and needs to be done in create_paraloc_info
  1356. Revision 1.150 2003/09/25 16:19:32 peter
  1357. * fix filepositions
  1358. * insert spill temp allocations at the start of the proc
  1359. Revision 1.149 2003/09/23 17:56:06 peter
  1360. * locals and paras are allocated in the code generation
  1361. * tvarsym.localloc contains the location of para/local when
  1362. generating code for the current procedure
  1363. Revision 1.148 2003/09/14 19:18:10 peter
  1364. * remove obsolete code already in comments
  1365. Revision 1.147 2003/09/14 12:58:00 peter
  1366. * support mulitple overloads in implementation, this is delphi
  1367. compatible
  1368. * procsym only stores the overloads available in the interface
  1369. Revision 1.146 2003/09/12 19:07:42 daniel
  1370. * Fixed fast spilling functionality by re-adding the code that initializes
  1371. precoloured nodes to degree 255. I would like to play hangman on the one
  1372. who removed that code.
  1373. Revision 1.145 2003/09/10 19:14:31 daniel
  1374. * Failed attempt to restore broken fastspill functionality
  1375. Revision 1.144 2003/09/09 20:59:27 daniel
  1376. * Adding register allocation order
  1377. Revision 1.143 2003/09/09 15:55:44 peter
  1378. * use register with least interferences in spillregister
  1379. Revision 1.142 2003/09/07 22:09:35 peter
  1380. * preparations for different default calling conventions
  1381. * various RA fixes
  1382. Revision 1.141 2003/09/04 14:46:12 peter
  1383. * abort with IE when spilling requires > 20 loops
  1384. Revision 1.140 2003/09/03 15:55:01 peter
  1385. * NEWRA branch merged
  1386. Revision 1.139 2003/09/03 11:18:37 florian
  1387. * fixed arm concatcopy
  1388. + arm support in the common compiler sources added
  1389. * moved some generic cg code around
  1390. + tfputype added
  1391. * ...
  1392. Revision 1.138.2.1 2003/08/31 13:50:16 daniel
  1393. * Remove sorting and use pregenerated indexes
  1394. * Some work on making things compile
  1395. Revision 1.138 2003/08/20 17:48:49 peter
  1396. * fixed stackalloc to not allocate localst.datasize twice
  1397. * order of stackalloc code fixed for implicit init/final
  1398. Revision 1.137 2003/08/20 15:50:35 peter
  1399. * define NOOPT until optimizer is fixed
  1400. Revision 1.136 2003/08/20 09:07:00 daniel
  1401. * New register coding now mandatory, some more convert_registers calls
  1402. removed.
  1403. Revision 1.135 2003/08/20 07:48:03 daniel
  1404. * Made internal assembler use new register coding
  1405. Revision 1.134 2003/08/17 16:59:20 jonas
  1406. * fixed regvars so they work with newra (at least for ppc)
  1407. * fixed some volatile register bugs
  1408. + -dnotranslation option for -dnewra, which causes the registers not to
  1409. be translated from virtual to normal registers. Requires support in
  1410. the assembler writer as well, which is only implemented in aggas/
  1411. agppcgas currently
  1412. Revision 1.133 2003/07/23 11:04:15 jonas
  1413. * split en_exit_code into a part that may allocate a register and a part
  1414. that doesn't, so the former can be done before the register colouring
  1415. has been performed
  1416. Revision 1.132 2003/07/06 17:58:22 peter
  1417. * framepointer fixes for sparc
  1418. * parent framepointer code more generic
  1419. Revision 1.131 2003/07/06 15:31:21 daniel
  1420. * Fixed register allocator. *Lots* of fixes.
  1421. Revision 1.130 2003/07/05 20:15:24 jonas
  1422. * set pi_do_call if range/overflow checking is on
  1423. Revision 1.129 2003/06/17 16:34:44 jonas
  1424. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1425. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  1426. processor dependent
  1427. Revision 1.128 2003/06/14 14:53:50 jonas
  1428. * fixed newra cycle for x86
  1429. * added constants for indicating source and destination operands of the
  1430. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  1431. Revision 1.127 2003/06/13 21:19:31 peter
  1432. * current_procdef removed, use current_procinfo.procdef instead
  1433. Revision 1.126 2003/06/12 16:43:07 peter
  1434. * newra compiles for sparc
  1435. Revision 1.125 2003/06/09 12:23:30 peter
  1436. * init/final of procedure data splitted from genentrycode
  1437. * use asmnode getposition to insert final at the correct position
  1438. als for the implicit try...finally
  1439. Revision 1.124 2003/06/07 19:37:43 jonas
  1440. * pi_do_call must always be set for the main program, since it always
  1441. ends with a call to FPC_DO_EXIT
  1442. Revision 1.123 2003/06/07 18:57:04 jonas
  1443. + added freeintparaloc
  1444. * ppc get/freeintparaloc now check whether the parameter regs are
  1445. properly allocated/deallocated (and get an extra list para)
  1446. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1447. * fixed lot of missing pi_do_call's
  1448. Revision 1.122 2003/06/03 13:01:59 daniel
  1449. * Register allocator finished
  1450. Revision 1.121 2003/05/31 20:23:39 jonas
  1451. * added pi_do_call if a procedure has a value shortstring parameter
  1452. (it's copied to the local stackframe with a helper)
  1453. Revision 1.120 2003/05/30 23:57:08 peter
  1454. * more sparc cleanup
  1455. * accumulator removed, splitted in function_return_reg (called) and
  1456. function_result_reg (caller)
  1457. Revision 1.119 2003/05/28 23:58:18 jonas
  1458. * added missing initialization of rg.usedintin,byproc
  1459. * ppc now also saves/restores used fpu registers
  1460. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1461. i386
  1462. Revision 1.118 2003/05/26 21:17:18 peter
  1463. * procinlinenode removed
  1464. * aktexit2label removed, fast exit removed
  1465. + tcallnode.inlined_pass_2 added
  1466. Revision 1.117 2003/05/25 08:59:47 peter
  1467. * do not generate code when there was an error
  1468. Revision 1.116 2003/05/23 18:49:55 jonas
  1469. * generate code for parent procedure before that of nested procedures as
  1470. well (I only need pass_1 to be done for the ppc, but pass_1 and pass_2
  1471. are grouped and it doesn't hurt that pass_2 is done as well)
  1472. Revision 1.115 2003/05/22 21:31:35 peter
  1473. * defer codegeneration for nested procedures
  1474. Revision 1.114 2003/05/16 20:00:39 jonas
  1475. * powerpc nested procedure fixes, should work completely now if all
  1476. local variables of the parent procedure are declared before the
  1477. nested procedures are declared
  1478. Revision 1.113 2003/05/16 14:33:31 peter
  1479. * regvar fixes
  1480. Revision 1.112 2003/05/13 21:26:38 peter
  1481. * only call destructor in except block when there is a destructor
  1482. available
  1483. Revision 1.111 2003/05/13 19:14:41 peter
  1484. * failn removed
  1485. * inherited result code check moven to pexpr
  1486. Revision 1.110 2003/05/13 15:18:49 peter
  1487. * fixed various crashes
  1488. Revision 1.109 2003/05/11 21:37:03 peter
  1489. * moved implicit exception frame from ncgutil to psub
  1490. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1491. Revision 1.108 2003/05/09 17:47:03 peter
  1492. * self moved to hidden parameter
  1493. * removed hdisposen,hnewn,selfn
  1494. Revision 1.107 2003/04/27 11:21:34 peter
  1495. * aktprocdef renamed to current_procinfo.procdef
  1496. * procinfo renamed to current_procinfo
  1497. * procinfo will now be stored in current_module so it can be
  1498. cleaned up properly
  1499. * gen_main_procsym changed to create_main_proc and release_main_proc
  1500. to also generate a tprocinfo structure
  1501. * fixed unit implicit initfinal
  1502. Revision 1.106 2003/04/27 07:29:50 peter
  1503. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  1504. a new procdef declaration
  1505. * aktprocsym removed
  1506. * lexlevel removed, use symtable.symtablelevel instead
  1507. * implicit init/final code uses the normal genentry/genexit
  1508. * funcret state checking updated for new funcret handling
  1509. Revision 1.105 2003/04/26 00:31:42 peter
  1510. * set return_offset moved to after_header
  1511. Revision 1.104 2003/04/25 20:59:34 peter
  1512. * removed funcretn,funcretsym, function result is now in varsym
  1513. and aliases for result and function name are added using absolutesym
  1514. * vs_hidden parameter for funcret passed in parameter
  1515. * vs_hidden fixes
  1516. * writenode changed to printnode and released from extdebug
  1517. * -vp option added to generate a tree.log with the nodetree
  1518. * nicer printnode for statements, callnode
  1519. Revision 1.103 2003/04/24 13:03:01 florian
  1520. * comp is now written with its bit pattern to the ppu instead as an extended
  1521. Revision 1.102 2003/04/23 12:35:34 florian
  1522. * fixed several issues with powerpc
  1523. + applied a patch from Jonas for nested function calls (PowerPC only)
  1524. * ...
  1525. Revision 1.101 2003/04/22 14:33:38 peter
  1526. * removed some notes/hints
  1527. Revision 1.100 2003/04/22 13:47:08 peter
  1528. * fixed C style array of const
  1529. * fixed C array passing
  1530. * fixed left to right with high parameters
  1531. Revision 1.99 2003/04/22 10:09:35 daniel
  1532. + Implemented the actual register allocator
  1533. + Scratch registers unavailable when new register allocator used
  1534. + maybe_save/maybe_restore unavailable when new register allocator used
  1535. Revision 1.98 2003/04/17 07:50:24 daniel
  1536. * Some work on interference graph construction
  1537. Revision 1.97 2003/04/16 09:26:55 jonas
  1538. * assembler procedures now again get a stackframe if they have local
  1539. variables. No space is reserved for a function result however.
  1540. Also, the register parameters aren't automatically saved on the stack
  1541. anymore in assembler procedures.
  1542. Revision 1.96 2003/04/05 21:09:31 jonas
  1543. * several ppc/generic result offset related fixes. The "normal" result
  1544. offset seems now to be calculated correctly and a lot of duplicate
  1545. calculations have been removed. Nested functions accessing the parent's
  1546. function result don't work at all though :(
  1547. Revision 1.95 2003/04/02 16:11:34 peter
  1548. * give error when exports is not supported
  1549. Revision 1.94 2003/03/12 22:43:38 jonas
  1550. * more powerpc and generic fixes related to the new register allocator
  1551. Revision 1.93 2003/03/08 08:59:07 daniel
  1552. + $define newra will enable new register allocator
  1553. + getregisterint will return imaginary registers with $newra
  1554. + -sr switch added, will skip register allocation so you can see
  1555. the direct output of the code generator before register allocation
  1556. Revision 1.92 2003/02/19 22:00:14 daniel
  1557. * Code generator converted to new register notation
  1558. - Horribily outdated todo.txt removed
  1559. Revision 1.91 2003/01/09 21:52:37 peter
  1560. * merged some verbosity options.
  1561. * V_LineInfo is a verbosity flag to include line info
  1562. Revision 1.90 2003/01/09 20:40:59 daniel
  1563. * Converted some code in cgx86.pas to new register numbering
  1564. Revision 1.89 2003/01/09 15:49:56 daniel
  1565. * Added register conversion
  1566. Revision 1.88 2003/01/08 18:43:56 daniel
  1567. * Tregister changed into a record
  1568. Revision 1.87 2003/01/03 20:35:08 peter
  1569. * check also interfacedef when checking for matching forwarddef
  1570. Revision 1.86 2003/01/02 11:14:02 michael
  1571. + Patch from peter to support initial values for local variables
  1572. Revision 1.85 2002/12/29 18:59:34 peter
  1573. * fixed parsing of declarations before asm statement
  1574. Revision 1.84 2002/12/29 18:25:18 peter
  1575. * parse declarations before check _ASM token
  1576. Revision 1.83 2002/12/29 14:57:50 peter
  1577. * unit loading changed to first register units and load them
  1578. afterwards. This is needed to support uses xxx in yyy correctly
  1579. * unit dependency check fixed
  1580. Revision 1.82 2002/12/25 01:26:56 peter
  1581. * duplicate procsym-unitsym fix
  1582. Revision 1.81 2002/12/15 13:37:15 peter
  1583. * don't include uf_init for library. The code is already called and
  1584. does not need to be in the initfinal table
  1585. Revision 1.80 2002/12/07 14:27:09 carl
  1586. * 3% memory optimization
  1587. * changed some types
  1588. + added type checking with different size for call node and for
  1589. parameters
  1590. Revision 1.79 2002/11/25 18:43:32 carl
  1591. - removed the invalid if <> checking (Delphi is strange on this)
  1592. + implemented abstract warning on instance creation of class with
  1593. abstract methods.
  1594. * some error message cleanups
  1595. Revision 1.78 2002/11/25 17:43:23 peter
  1596. * splitted defbase in defutil,symutil,defcmp
  1597. * merged isconvertable and is_equal into compare_defs(_ext)
  1598. * made operator search faster by walking the list only once
  1599. Revision 1.77 2002/11/23 22:50:06 carl
  1600. * some small speed optimizations
  1601. + added several new warnings/hints
  1602. Revision 1.76 2002/11/18 17:31:58 peter
  1603. * pass proccalloption to ret_in_xxx and push_xxx functions
  1604. Revision 1.75 2002/11/17 16:31:57 carl
  1605. * memory optimization (3-4%) : cleanup of tai fields,
  1606. cleanup of tdef and tsym fields.
  1607. * make it work for m68k
  1608. Revision 1.74 2002/11/15 01:58:53 peter
  1609. * merged changes from 1.0.7 up to 04-11
  1610. - -V option for generating bug report tracing
  1611. - more tracing for option parsing
  1612. - errors for cdecl and high()
  1613. - win32 import stabs
  1614. - win32 records<=8 are returned in eax:edx (turned off by default)
  1615. - heaptrc update
  1616. - more info for temp management in .s file with EXTDEBUG
  1617. Revision 1.73 2002/11/09 15:32:30 carl
  1618. * noopt for non-i386 targets
  1619. Revision 1.72 2002/09/10 20:31:48 florian
  1620. * call to current_procinfo.after_header added
  1621. Revision 1.71 2002/09/07 15:25:07 peter
  1622. * old logs removed and tabs fixed
  1623. Revision 1.70 2002/09/03 16:26:27 daniel
  1624. * Make Tprocdef.defs protected
  1625. Revision 1.69 2002/08/25 19:25:20 peter
  1626. * sym.insert_in_data removed
  1627. * symtable.insertvardata/insertconstdata added
  1628. * removed insert_in_data call from symtable.insert, it needs to be
  1629. called separatly. This allows to deref the address calculation
  1630. * procedures now calculate the parast addresses after the procedure
  1631. directives are parsed. This fixes the cdecl parast problem
  1632. * push_addr_param has an extra argument that specifies if cdecl is used
  1633. or not
  1634. Revision 1.68 2002/08/17 09:23:41 florian
  1635. * first part of procinfo rewrite
  1636. Revision 1.67 2002/08/16 14:24:59 carl
  1637. * issameref() to test if two references are the same (then emit no opcodes)
  1638. + ret_in_reg to replace ret_in_acc
  1639. (fix some register allocation bugs at the same time)
  1640. + save_std_register now has an extra parameter which is the
  1641. usedinproc registers
  1642. Revision 1.66 2002/08/11 14:32:27 peter
  1643. * renamed current_library to objectlibrary
  1644. Revision 1.65 2002/08/11 13:24:13 peter
  1645. * saving of asmsymbols in ppu supported
  1646. * asmsymbollist global is removed and moved into a new class
  1647. tasmlibrarydata that will hold the info of a .a file which
  1648. corresponds with a single module. Added librarydata to tmodule
  1649. to keep the library info stored for the module. In the future the
  1650. objectfiles will also be stored to the tasmlibrarydata class
  1651. * all getlabel/newasmsymbol and friends are moved to the new class
  1652. Revision 1.64 2002/08/09 19:14:28 carl
  1653. * fixed stackframe parameter (should only contain local size),
  1654. set to zero currently
  1655. Revision 1.63 2002/08/06 20:55:22 florian
  1656. * first part of ppc calling conventions fix
  1657. Revision 1.62 2002/07/26 21:15:41 florian
  1658. * rewrote the system handling
  1659. Revision 1.61 2002/07/20 11:57:56 florian
  1660. * types.pas renamed to defbase.pas because D6 contains a types
  1661. unit so this would conflicts if D6 programms are compiled
  1662. + Willamette/SSE2 instructions to assembler added
  1663. Revision 1.60 2002/07/19 11:41:36 daniel
  1664. * State tracker work
  1665. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1666. allows the state tracker to change while nodes automatically into
  1667. repeat nodes.
  1668. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1669. 'not(a>b)' is optimized into 'a<=b'.
  1670. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1671. by removing the notn and later switchting the true and falselabels. The
  1672. same is done with 'repeat until not a'.
  1673. Revision 1.59 2002/07/15 18:03:15 florian
  1674. * readded removed changes
  1675. Revision 1.57 2002/07/11 14:41:28 florian
  1676. * start of the new generic parameter handling
  1677. Revision 1.58 2002/07/14 18:00:44 daniel
  1678. + Added the beginning of a state tracker. This will track the values of
  1679. variables through procedures and optimize things away.
  1680. Revision 1.56 2002/07/07 09:52:32 florian
  1681. * powerpc target fixed, very simple units can be compiled
  1682. * some basic stuff for better callparanode handling, far from being finished
  1683. Revision 1.55 2002/07/04 20:43:01 florian
  1684. * first x86-64 patches
  1685. Revision 1.54 2002/07/01 18:46:25 peter
  1686. * internal linker
  1687. * reorganized aasm layer
  1688. Revision 1.53 2002/05/18 13:34:14 peter
  1689. * readded missing revisions
  1690. Revision 1.52 2002/05/16 19:46:44 carl
  1691. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1692. + try to fix temp allocation (still in ifdef)
  1693. + generic constructor calls
  1694. + start of tassembler / tmodulebase class cleanup
  1695. Revision 1.51 2002/05/14 19:34:49 peter
  1696. * removed old logs and updated copyright year
  1697. }