psub.pas 73 KB

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