ncgutil.pas 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Helper routines for all code generators
  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 ncgutil;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,cpuinfo,
  23. globtype,
  24. cpubase,cgbase,
  25. aasmbase,aasmtai,aasmcpu,
  26. symconst,symbase,symdef,symsym,symtype,symtable
  27. {$ifndef cpu64bit}
  28. ,cg64f32
  29. {$endif cpu64bit}
  30. ;
  31. type
  32. tloadregvars = (lr_dont_load_regvars, lr_load_regvars);
  33. procedure firstcomplex(p : tbinarynode);
  34. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  35. // procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  36. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  37. procedure location_force_fpureg(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  38. procedure location_force_mem(list:TAAsmoutput;var l:tlocation);
  39. procedure location_force_mmregscalar(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  40. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  41. procedure gen_proc_symbol(list:Taasmoutput);
  42. procedure gen_proc_symbol_end(list:Taasmoutput);
  43. procedure gen_stackalloc_code(list:Taasmoutput);
  44. procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
  45. procedure gen_save_used_regs(list:TAAsmoutput);
  46. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tparalocation);
  47. procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean);
  48. procedure gen_finalize_code(list:TAAsmoutput;inlined:boolean);
  49. procedure gen_entry_code(list:TAAsmoutput);
  50. procedure gen_exit_code(list:TAAsmoutput);
  51. procedure gen_load_para_value(list:TAAsmoutput);
  52. procedure gen_load_return_value(list:TAAsmoutput; var uses_acc,uses_acchi,uses_fpu : boolean);
  53. (*
  54. procedure geninlineentrycode(list:TAAsmoutput;stackframe:longint);
  55. procedure geninlineexitcode(list:TAAsmoutput;inlined:boolean);
  56. *)
  57. {#
  58. Allocate the buffers for exception management and setjmp environment.
  59. Return a pointer to these buffers, send them to the utility routine
  60. so they are registered, and then call setjmp.
  61. Then compare the result of setjmp with 0, and if not equal
  62. to zero, then jump to exceptlabel.
  63. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  64. It is to note that this routine may be called *after* the stackframe of a
  65. routine has been called, therefore on machines where the stack cannot
  66. be modified, all temps should be allocated on the heap instead of the
  67. stack.
  68. }
  69. const
  70. EXCEPT_BUF_SIZE = 12;
  71. type
  72. texceptiontemps=record
  73. jmpbuf,
  74. envbuf,
  75. reasonbuf : treference;
  76. end;
  77. procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
  78. procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
  79. procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;exceptlabel:tasmlabel);
  80. procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;endexceptlabel:tasmlabel;onlyfree:boolean);
  81. procedure insertconstdata(sym : ttypedconstsym);
  82. procedure insertbssdata(sym : tvarsym);
  83. procedure gen_alloc_localst(list:TAAsmoutput;st:tlocalsymtable);
  84. procedure gen_free_localst(list:TAAsmoutput;st:tlocalsymtable);
  85. procedure gen_alloc_parast(list:TAAsmoutput;st:tparasymtable);
  86. procedure gen_alloc_inline_parast(list:TAAsmoutput;st:tparasymtable);
  87. procedure gen_free_parast(list:TAAsmoutput;st:tparasymtable);
  88. { rtti and init/final }
  89. procedure generate_rtti(p:Ttypesym);
  90. procedure generate_inittable(p:tsym);
  91. implementation
  92. uses
  93. {$ifdef Delphi}
  94. Sysutils,
  95. {$else}
  96. strings,
  97. {$endif}
  98. cutils,cclasses,
  99. globals,systems,verbose,
  100. ppu,defutil,
  101. procinfo,paramgr,fmodule,
  102. regvars,
  103. {$ifdef GDB}
  104. gdb,
  105. {$endif GDB}
  106. pass_1,pass_2,
  107. ncon,nld,nutils,
  108. tgobj,cgutils,cgobj;
  109. {*****************************************************************************
  110. Misc Helpers
  111. *****************************************************************************}
  112. { DO NOT RELY on the fact that the tnode is not yet swaped
  113. because of inlining code PM }
  114. procedure firstcomplex(p : tbinarynode);
  115. var
  116. hp : tnode;
  117. begin
  118. { always calculate boolean AND and OR from left to right }
  119. if (p.nodetype in [orn,andn]) and
  120. is_boolean(p.left.resulttype.def) then
  121. begin
  122. if nf_swaped in p.flags then
  123. internalerror(234234);
  124. end
  125. else
  126. if (
  127. (p.location.loc=LOC_FPUREGISTER) and
  128. (p.right.registersfpu > p.left.registersfpu)
  129. ) or
  130. (
  131. (
  132. (
  133. ((p.left.registersfpu = 0) and (p.right.registersfpu = 0)) or
  134. (p.location.loc<>LOC_FPUREGISTER)
  135. ) and
  136. (p.left.registersint<p.right.registersint)
  137. )
  138. ) then
  139. begin
  140. hp:=p.left;
  141. p.left:=p.right;
  142. p.right:=hp;
  143. if nf_swaped in p.flags then
  144. exclude(p.flags,nf_swaped)
  145. else
  146. include(p.flags,nf_swaped);
  147. end;
  148. end;
  149. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  150. {
  151. produces jumps to true respectively false labels using boolean expressions
  152. depending on whether the loading of regvars is currently being
  153. synchronized manually (such as in an if-node) or automatically (most of
  154. the other cases where this procedure is called), loadregvars can be
  155. "lr_load_regvars" or "lr_dont_load_regvars"
  156. }
  157. var
  158. opsize : tcgsize;
  159. storepos : tfileposinfo;
  160. begin
  161. if nf_error in p.flags then
  162. exit;
  163. storepos:=aktfilepos;
  164. aktfilepos:=p.fileinfo;
  165. if is_boolean(p.resulttype.def) then
  166. begin
  167. {$ifdef OLDREGVARS}
  168. if loadregvars = lr_load_regvars then
  169. load_all_regvars(list);
  170. {$endif OLDREGVARS}
  171. if is_constboolnode(p) then
  172. begin
  173. if tordconstnode(p).value<>0 then
  174. cg.a_jmp_always(list,truelabel)
  175. else
  176. cg.a_jmp_always(list,falselabel)
  177. end
  178. else
  179. begin
  180. opsize:=def_cgsize(p.resulttype.def);
  181. case p.location.loc of
  182. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  183. begin
  184. {$ifdef OLDREGVARS}
  185. if (p.location.loc = LOC_CREGISTER) then
  186. load_regvar_reg(list,p.location.register);
  187. {$endif OLDREGVARS}
  188. cg.a_cmp_const_loc_label(list,opsize,OC_NE,
  189. 0,p.location,truelabel);
  190. { !!! should happen right after cmp (JM) }
  191. location_release(list,p.location);
  192. cg.a_jmp_always(list,falselabel);
  193. end;
  194. LOC_JUMP:
  195. ;
  196. {$ifdef cpuflags}
  197. LOC_FLAGS :
  198. begin
  199. cg.a_jmp_flags(list,p.location.resflags,
  200. truelabel);
  201. cg.a_jmp_always(list,falselabel);
  202. end;
  203. {$endif cpuflags}
  204. else
  205. begin
  206. printnode(output,p);
  207. internalerror(200308241);
  208. end;
  209. end;
  210. end;
  211. end
  212. else
  213. internalerror(200112305);
  214. aktfilepos:=storepos;
  215. end;
  216. (*
  217. This code needs fixing. It is not safe to use rgint; on the m68000 it
  218. would be rgaddr.
  219. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  220. begin
  221. case t.loc of
  222. LOC_REGISTER:
  223. begin
  224. { can't be a regvar, since it would be LOC_CREGISTER then }
  225. exclude(regs,getsupreg(t.register));
  226. if t.registerhigh<>NR_NO then
  227. exclude(regs,getsupreg(t.registerhigh));
  228. end;
  229. LOC_CREFERENCE,LOC_REFERENCE:
  230. begin
  231. if not(cs_regvars in aktglobalswitches) or
  232. (getsupreg(t.reference.base) in cg.rgint.usableregs) then
  233. exclude(regs,getsupreg(t.reference.base));
  234. if not(cs_regvars in aktglobalswitches) or
  235. (getsupreg(t.reference.index) in cg.rgint.usableregs) then
  236. exclude(regs,getsupreg(t.reference.index));
  237. end;
  238. end;
  239. end;
  240. *)
  241. {*****************************************************************************
  242. EXCEPTION MANAGEMENT
  243. *****************************************************************************}
  244. procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
  245. begin
  246. tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,t.envbuf);
  247. tg.GetTemp(list,JMP_BUF_SIZE,tt_persistent,t.jmpbuf);
  248. tg.GetTemp(list,sizeof(aword),tt_persistent,t.reasonbuf);
  249. end;
  250. procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
  251. begin
  252. tg.Ungettemp(list,t.jmpbuf);
  253. tg.ungettemp(list,t.envbuf);
  254. tg.ungettemp(list,t.reasonbuf);
  255. end;
  256. procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;exceptlabel:tasmlabel);
  257. var
  258. paraloc1,paraloc2,paraloc3 : tparalocation;
  259. begin
  260. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  261. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  262. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  263. paramanager.allocparaloc(list,paraloc3);
  264. cg.a_paramaddr_ref(list,t.envbuf,paraloc3);
  265. paramanager.allocparaloc(list,paraloc2);
  266. cg.a_paramaddr_ref(list,t.jmpbuf,paraloc2);
  267. { push type of exceptionframe }
  268. paramanager.allocparaloc(list,paraloc1);
  269. cg.a_param_const(list,OS_S32,1,paraloc1);
  270. paramanager.freeparaloc(list,paraloc3);
  271. paramanager.freeparaloc(list,paraloc2);
  272. paramanager.freeparaloc(list,paraloc1);
  273. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  274. cg.a_call_name(list,'FPC_PUSHEXCEPTADDR');
  275. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  276. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  277. paramanager.allocparaloc(list,paraloc1);
  278. cg.a_param_reg(list,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  279. paramanager.freeparaloc(list,paraloc1);
  280. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  281. cg.a_call_name(list,'FPC_SETJMP');
  282. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  283. cg.g_exception_reason_save(list, t.reasonbuf);
  284. cg.a_cmp_const_reg_label(list,OS_S32,OC_NE,0,cg.makeregsize(list,NR_FUNCTION_RESULT_REG,OS_S32),exceptlabel);
  285. end;
  286. procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;endexceptlabel:tasmlabel;onlyfree:boolean);
  287. begin
  288. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  289. cg.a_call_name(list,'FPC_POPADDRSTACK');
  290. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  291. if not onlyfree then
  292. begin
  293. cg.g_exception_reason_load(list, t.reasonbuf);
  294. cg.a_cmp_const_reg_label(list,OS_INT,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
  295. end;
  296. end;
  297. {*****************************************************************************
  298. TLocation
  299. *****************************************************************************}
  300. {$ifndef cpu64bit}
  301. { 32-bit version }
  302. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  303. var
  304. hregister,
  305. hregisterhi : tregister;
  306. hreg64 : tregister64;
  307. hl : tasmlabel;
  308. oldloc : tlocation;
  309. begin
  310. oldloc:=l;
  311. if dst_size=OS_NO then
  312. internalerror(200309144);
  313. { handle transformations to 64bit separate }
  314. if dst_size in [OS_64,OS_S64] then
  315. begin
  316. if not (l.size in [OS_64,OS_S64]) then
  317. begin
  318. { load a smaller size to OS_64 }
  319. if l.loc=LOC_REGISTER then
  320. begin
  321. hregister:=cg.makeregsize(list,l.registerlow,OS_32);
  322. cg.a_load_reg_reg(list,l.size,OS_32,l.registerlow,hregister);
  323. end
  324. else
  325. begin
  326. location_release(list,l);
  327. hregister:=cg.getintregister(list,OS_INT);
  328. end;
  329. { load value in low register }
  330. case l.loc of
  331. LOC_FLAGS :
  332. cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
  333. LOC_JUMP :
  334. begin
  335. cg.a_label(list,truelabel);
  336. cg.a_load_const_reg(list,OS_INT,1,hregister);
  337. objectlibrary.getlabel(hl);
  338. cg.a_jmp_always(list,hl);
  339. cg.a_label(list,falselabel);
  340. cg.a_load_const_reg(list,OS_INT,0,hregister);
  341. cg.a_label(list,hl);
  342. end;
  343. else
  344. cg.a_load_loc_reg(list,OS_INT,l,hregister);
  345. end;
  346. { reset hi part, take care of the signed bit of the current value }
  347. hregisterhi:=cg.getintregister(list,OS_INT);
  348. if (l.size in [OS_S8,OS_S16,OS_S32]) then
  349. begin
  350. if l.loc=LOC_CONSTANT then
  351. begin
  352. if (longint(l.value)<0) then
  353. cg.a_load_const_reg(list,OS_32,$ffffffff,hregisterhi)
  354. else
  355. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  356. end
  357. else
  358. begin
  359. cg.a_op_const_reg_reg(list,OP_SAR,OS_32,31,hregister,
  360. hregisterhi);
  361. end;
  362. end
  363. else
  364. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  365. location_reset(l,LOC_REGISTER,dst_size);
  366. l.registerlow:=hregister;
  367. l.registerhigh:=hregisterhi;
  368. end
  369. else
  370. begin
  371. { 64bit to 64bit }
  372. if (l.loc=LOC_REGISTER) or
  373. ((l.loc=LOC_CREGISTER) and maybeconst) then
  374. begin
  375. hregister:=l.registerlow;
  376. hregisterhi:=l.registerhigh;
  377. end
  378. else
  379. begin
  380. hregister:=cg.getintregister(list,OS_INT);
  381. hregisterhi:=cg.getintregister(list,OS_INT);
  382. location_release(list,l);
  383. end;
  384. hreg64.reglo:=hregister;
  385. hreg64.reghi:=hregisterhi;
  386. { load value in new register }
  387. cg64.a_load64_loc_reg(list,l,hreg64);
  388. location_reset(l,LOC_REGISTER,dst_size);
  389. l.registerlow:=hregister;
  390. l.registerhigh:=hregisterhi;
  391. end;
  392. end
  393. else
  394. begin
  395. {Do not bother to recycle the existing register. The register
  396. allocator eliminates unnecessary moves, so it's not needed
  397. and trying to recycle registers can cause problems because
  398. the registers changes size and may need aditional constraints.}
  399. location_release(list,l);
  400. hregister:=cg.getintregister(list,dst_size);
  401. { load value in new register }
  402. case l.loc of
  403. LOC_FLAGS :
  404. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  405. LOC_JUMP :
  406. begin
  407. cg.a_label(list,truelabel);
  408. cg.a_load_const_reg(list,dst_size,1,hregister);
  409. objectlibrary.getlabel(hl);
  410. cg.a_jmp_always(list,hl);
  411. cg.a_label(list,falselabel);
  412. cg.a_load_const_reg(list,dst_size,0,hregister);
  413. cg.a_label(list,hl);
  414. end;
  415. else
  416. begin
  417. { load_loc_reg can only handle size >= l.size, when the
  418. new size is smaller then we need to adjust the size
  419. of the orignal and maybe recalculate l.register for i386 }
  420. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  421. begin
  422. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  423. l.register:=cg.makeregsize(list,l.register,dst_size);
  424. { for big endian systems, the reference's offset must }
  425. { be increased in this case, since they have the }
  426. { MSB first in memory and e.g. byte(word_var) should }
  427. { return the second byte in this case (JM) }
  428. if (target_info.endian = ENDIAN_BIG) and
  429. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  430. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  431. {$ifdef x86}
  432. l.size:=dst_size;
  433. {$endif x86}
  434. end;
  435. cg.a_load_loc_reg(list,dst_size,l,hregister);
  436. {$ifndef x86}
  437. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  438. l.size:=dst_size;
  439. {$endif not x86}
  440. end;
  441. end;
  442. if (l.loc <> LOC_CREGISTER) or
  443. not maybeconst then
  444. location_reset(l,LOC_REGISTER,dst_size)
  445. else
  446. location_reset(l,LOC_CREGISTER,dst_size);
  447. l.register:=hregister;
  448. end;
  449. { Release temp when it was a reference }
  450. if oldloc.loc=LOC_REFERENCE then
  451. location_freetemp(list,oldloc);
  452. end;
  453. {$else cpu64bit}
  454. { 64-bit version }
  455. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  456. var
  457. hregister : tregister;
  458. hl : tasmlabel;
  459. oldloc : tlocation;
  460. begin
  461. {Do not bother to recycle the existing register. The register
  462. allocator eliminates unnecessary moves, so it's not needed
  463. and trying to recycle registers can cause problems because
  464. the registers changes size and may need aditional constraints.}
  465. location_release(list,l);
  466. hregister:=cg.getintregister(list,dst_size);
  467. { load value in new register }
  468. case l.loc of
  469. LOC_FLAGS :
  470. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  471. LOC_JUMP :
  472. begin
  473. cg.a_label(list,truelabel);
  474. cg.a_load_const_reg(list,dst_size,1,hregister);
  475. objectlibrary.getlabel(hl);
  476. cg.a_jmp_always(list,hl);
  477. cg.a_label(list,falselabel);
  478. cg.a_load_const_reg(list,dst_size,0,hregister);
  479. cg.a_label(list,hl);
  480. end;
  481. else
  482. begin
  483. { load_loc_reg can only handle size >= l.size, when the
  484. new size is smaller then we need to adjust the size
  485. of the orignal and maybe recalculate l.register for i386 }
  486. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  487. begin
  488. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  489. l.register:=cg.makeregsize(list,l.register,dst_size);
  490. { for big endian systems, the reference's offset must }
  491. { be increased in this case, since they have the }
  492. { MSB first in memory and e.g. byte(word_var) should }
  493. { return the second byte in this case (JM) }
  494. if (target_info.endian = ENDIAN_BIG) and
  495. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  496. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  497. {$ifdef x86}
  498. l.size:=dst_size;
  499. {$endif x86}
  500. end;
  501. cg.a_load_loc_reg(list,dst_size,l,hregister);
  502. {$ifndef x86}
  503. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  504. l.size:=dst_size;
  505. {$endif not x86}
  506. end;
  507. end;
  508. if (l.loc <> LOC_CREGISTER) or
  509. not maybeconst then
  510. location_reset(l,LOC_REGISTER,dst_size)
  511. else
  512. location_reset(l,LOC_CREGISTER,dst_size);
  513. l.register:=hregister;
  514. { Release temp when it was a reference }
  515. if oldloc.loc=LOC_REFERENCE then
  516. location_freetemp(list,oldloc);
  517. end;
  518. {$endif cpu64bit}
  519. procedure location_force_fpureg(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  520. var
  521. reg : tregister;
  522. href : treference;
  523. begin
  524. if (l.loc<>LOC_FPUREGISTER) and
  525. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  526. begin
  527. { if it's in an mm register, store to memory first }
  528. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  529. begin
  530. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  531. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
  532. location_release(list,l);
  533. location_reset(l,LOC_REFERENCE,l.size);
  534. l.reference:=href;
  535. end;
  536. reg:=cg.getfpuregister(list,l.size);
  537. cg.a_loadfpu_loc_reg(list,l,reg);
  538. location_freetemp(list,l);
  539. location_release(list,l);
  540. location_reset(l,LOC_FPUREGISTER,l.size);
  541. l.register:=reg;
  542. end;
  543. end;
  544. procedure location_force_mmregscalar(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  545. var
  546. reg : tregister;
  547. href : treference;
  548. begin
  549. if (l.loc<>LOC_MMREGISTER) and
  550. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  551. begin
  552. { if it's in an fpu register, store to memory first }
  553. if (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  554. begin
  555. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  556. cg.a_loadfpu_reg_ref(list,l.size,l.register,href);
  557. location_release(list,l);
  558. location_reset(l,LOC_REFERENCE,l.size);
  559. l.reference:=href;
  560. end;
  561. reg:=cg.getmmregister(list,l.size);
  562. cg.a_loadmm_loc_reg(list,l.size,l,reg,mms_movescalar);
  563. location_freetemp(list,l);
  564. location_release(list,l);
  565. location_reset(l,LOC_MMREGISTER,l.size);
  566. l.register:=reg;
  567. end;
  568. end;
  569. procedure location_force_mem(list:TAAsmoutput;var l:tlocation);
  570. var
  571. r : treference;
  572. begin
  573. case l.loc of
  574. LOC_FPUREGISTER,
  575. LOC_CFPUREGISTER :
  576. begin
  577. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  578. cg.a_loadfpu_reg_ref(list,l.size,l.register,r);
  579. location_release(list,l);
  580. location_reset(l,LOC_REFERENCE,l.size);
  581. l.reference:=r;
  582. end;
  583. LOC_MMREGISTER,
  584. LOC_CMMREGISTER:
  585. begin
  586. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  587. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  588. location_release(list,l);
  589. location_reset(l,LOC_REFERENCE,l.size);
  590. l.reference:=r;
  591. end;
  592. LOC_CONSTANT,
  593. LOC_REGISTER,
  594. LOC_CREGISTER :
  595. begin
  596. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  597. if l.size in [OS_64,OS_S64] then
  598. begin
  599. cg64.a_load64_loc_ref(list,l,r);
  600. location_release(list,l);
  601. end
  602. else
  603. begin
  604. location_release(list,l);
  605. cg.a_load_loc_ref(list,l.size,l,r);
  606. end;
  607. location_reset(l,LOC_REFERENCE,l.size);
  608. l.reference:=r;
  609. end;
  610. LOC_CREFERENCE,
  611. LOC_REFERENCE : ;
  612. else
  613. internalerror(200203219);
  614. end;
  615. end;
  616. {*****************************************************************************
  617. Maybe_Save
  618. *****************************************************************************}
  619. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  620. begin
  621. {$ifdef i386}
  622. if (needed>=maxfpuregs) and
  623. (l.loc = LOC_FPUREGISTER) then
  624. begin
  625. location_force_mem(list,l);
  626. maybe_pushfpu:=true;
  627. end
  628. else
  629. maybe_pushfpu:=false;
  630. {$endif i386}
  631. end;
  632. {****************************************************************************
  633. Init/Finalize Code
  634. ****************************************************************************}
  635. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  636. var
  637. href1,href2 : treference;
  638. list:TAAsmoutput;
  639. hsym : tvarsym;
  640. l : longint;
  641. loadref : boolean;
  642. localcopyloc : tparalocation;
  643. begin
  644. list:=taasmoutput(arg);
  645. if (tsym(p).typ=varsym) and
  646. (tvarsym(p).varspez=vs_value) and
  647. (paramanager.push_addr_param(tvarsym(p).varspez,tvarsym(p).vartype.def,current_procinfo.procdef.proccalloption)) then
  648. begin
  649. loadref:=true;
  650. case tvarsym(p).localloc.loc of
  651. LOC_REGISTER :
  652. begin
  653. reference_reset_base(href1,tvarsym(p).localloc.register,0);
  654. loadref:=false;
  655. end;
  656. LOC_REFERENCE :
  657. reference_reset_base(href1,tvarsym(p).localloc.reference.index,
  658. tvarsym(p).localloc.reference.offset);
  659. else
  660. internalerror(200309181);
  661. end;
  662. if is_open_array(tvarsym(p).vartype.def) or
  663. is_array_of_const(tvarsym(p).vartype.def) then
  664. begin
  665. { cdecl functions don't have a high pointer so it is not possible to generate
  666. a local copy }
  667. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  668. begin
  669. hsym:=tvarsym(tsym(p).owner.search('high'+p.name));
  670. if not assigned(hsym) then
  671. internalerror(200306061);
  672. case hsym.localloc.loc of
  673. LOC_REFERENCE :
  674. begin
  675. { this code is only executed before the code for the body and the entry/exit code is generated
  676. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  677. }
  678. include(current_procinfo.flags,pi_do_call);
  679. reference_reset_base(href2,hsym.localloc.reference.index,hsym.localloc.reference.offset);
  680. cg.g_copyvaluepara_openarray(list,href1,href2,tarraydef(tvarsym(p).vartype.def).elesize)
  681. end
  682. else
  683. internalerror(200309182);
  684. end;
  685. end;
  686. end
  687. else
  688. begin
  689. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  690. internalerror(200309183);
  691. { Allocate space for the local copy }
  692. l:=tvarsym(p).getvaluesize;
  693. localcopyloc.loc:=LOC_REFERENCE;
  694. localcopyloc.size:=int_cgsize(l);
  695. tg.GetLocal(list,l,tvarsym(p).vartype.def,localcopyloc.reference);
  696. { Copy data }
  697. reference_reset_base(href2,localcopyloc.reference.index,localcopyloc.reference.offset);
  698. if is_shortstring(tvarsym(p).vartype.def) then
  699. begin
  700. { this code is only executed before the code for the body and the entry/exit code is generated
  701. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  702. }
  703. include(current_procinfo.flags,pi_do_call);
  704. cg.g_copyshortstring(list,href1,href2,tstringdef(tvarsym(p).vartype.def).len,false,loadref)
  705. end
  706. else
  707. cg.g_concatcopy(list,href1,href2,tvarsym(p).vartype.def.size,true,loadref);
  708. { update localloc of varsym }
  709. tg.Ungetlocal(list,tvarsym(p).localloc.reference);
  710. tvarsym(p).localloc:=localcopyloc;
  711. end;
  712. end;
  713. end;
  714. { generates the code for initialisation of local data }
  715. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  716. var
  717. oldexprasmlist : TAAsmoutput;
  718. hp : tnode;
  719. begin
  720. if (tsym(p).typ=varsym) and
  721. (tvarsym(p).refs>0) and
  722. not(is_class(tvarsym(p).vartype.def)) and
  723. tvarsym(p).vartype.def.needs_inittable then
  724. begin
  725. oldexprasmlist:=exprasmlist;
  726. exprasmlist:=taasmoutput(arg);
  727. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  728. firstpass(hp);
  729. secondpass(hp);
  730. hp.free;
  731. exprasmlist:=oldexprasmlist;
  732. end;
  733. end;
  734. { generates the code for finalisation of local data }
  735. procedure finalize_data(p : tnamedindexitem;arg:pointer);
  736. var
  737. oldexprasmlist : TAAsmoutput;
  738. hp : tnode;
  739. dofinalize : boolean;
  740. begin
  741. dofinalize:=false;
  742. case tsym(p).typ of
  743. varsym :
  744. begin
  745. if (tvarsym(p).refs>0) and
  746. not(vo_is_funcret in tvarsym(p).varoptions) and
  747. not(is_class(tvarsym(p).vartype.def)) and
  748. tvarsym(p).vartype.def.needs_inittable then
  749. dofinalize:=true;
  750. end;
  751. typedconstsym :
  752. begin
  753. if ttypedconstsym(p).is_writable and
  754. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  755. dofinalize:=true;
  756. end;
  757. end;
  758. if dofinalize then
  759. begin
  760. include(current_procinfo.flags,pi_needs_implicit_finally);
  761. oldexprasmlist:=exprasmlist;
  762. exprasmlist:=taasmoutput(arg);
  763. hp:=finalize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  764. firstpass(hp);
  765. secondpass(hp);
  766. hp.free;
  767. exprasmlist:=oldexprasmlist;
  768. end;
  769. end;
  770. { generates the code for incrementing the reference count of parameters and
  771. initialize out parameters }
  772. procedure init_paras(p : tnamedindexitem;arg:pointer);
  773. var
  774. href : treference;
  775. tmpreg : tregister;
  776. list:TAAsmoutput;
  777. begin
  778. list:=taasmoutput(arg);
  779. if (tsym(p).typ=varsym) and
  780. not is_class(tvarsym(p).vartype.def) and
  781. tvarsym(p).vartype.def.needs_inittable then
  782. begin
  783. case tvarsym(p).varspez of
  784. vs_value :
  785. begin
  786. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  787. internalerror(200309187);
  788. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  789. cg.g_incrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  790. end;
  791. vs_out :
  792. begin
  793. case tvarsym(p).localloc.loc of
  794. LOC_REFERENCE :
  795. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  796. else
  797. internalerror(2003091810);
  798. end;
  799. tmpreg:=cg.getaddressregister(list);
  800. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,tmpreg);
  801. reference_reset_base(href,tmpreg,0);
  802. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  803. cg.ungetregister(list,tmpreg);
  804. end;
  805. end;
  806. end;
  807. end;
  808. { generates the code for decrementing the reference count of parameters }
  809. procedure final_paras(p : tnamedindexitem;arg:pointer);
  810. var
  811. href : treference;
  812. list:TAAsmoutput;
  813. begin
  814. list:=taasmoutput(arg);
  815. if (tsym(p).typ=varsym) and
  816. not is_class(tvarsym(p).vartype.def) and
  817. tvarsym(p).vartype.def.needs_inittable then
  818. begin
  819. if (tvarsym(p).varspez=vs_value) then
  820. begin
  821. include(current_procinfo.flags,pi_needs_implicit_finally);
  822. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  823. internalerror(200309188);
  824. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  825. cg.g_decrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  826. end;
  827. end
  828. else if (tsym(p).typ=varsym) and
  829. (tvarsym(p).varspez=vs_value) and
  830. (is_open_array(tvarsym(p).vartype.def) or
  831. is_array_of_const(tvarsym(p).vartype.def)) then
  832. begin
  833. { cdecl functions don't have a high pointer so it is not possible to generate
  834. a local copy }
  835. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  836. begin
  837. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  838. cg.g_releasevaluepara_openarray(list,href);
  839. end;
  840. end;
  841. end;
  842. { Initialize temp ansi/widestrings,interfaces }
  843. procedure inittempvariables(list:taasmoutput);
  844. var
  845. hp : ptemprecord;
  846. href : treference;
  847. begin
  848. hp:=tg.templist;
  849. while assigned(hp) do
  850. begin
  851. if assigned(hp^.def) and
  852. hp^.def.needs_inittable then
  853. begin
  854. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  855. cg.g_initialize(list,hp^.def,href,false);
  856. end;
  857. hp:=hp^.next;
  858. end;
  859. end;
  860. procedure finalizetempvariables(list:taasmoutput);
  861. var
  862. hp : ptemprecord;
  863. href : treference;
  864. paraloc1 : tparalocation;
  865. begin
  866. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  867. hp:=tg.templist;
  868. while assigned(hp) do
  869. begin
  870. if assigned(hp^.def) and
  871. hp^.def.needs_inittable then
  872. begin
  873. include(current_procinfo.flags,pi_needs_implicit_finally);
  874. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  875. cg.g_finalize(list,hp^.def,href,false);
  876. end;
  877. hp:=hp^.next;
  878. end;
  879. end;
  880. procedure gen_load_return_value(list:TAAsmoutput; var uses_acc,uses_acchi,uses_fpu : boolean);
  881. var
  882. ressym : tvarsym;
  883. resloc : tlocation;
  884. href : treference;
  885. hreg : tregister;
  886. begin
  887. { Is the loading needed? }
  888. if is_void(current_procinfo.procdef.rettype.def) or
  889. (
  890. (po_assembler in current_procinfo.procdef.procoptions) and
  891. (not(assigned(current_procinfo.procdef.funcretsym)) or
  892. (tvarsym(current_procinfo.procdef.funcretsym).refs=0))
  893. ) then
  894. exit;
  895. { Constructors need to return self }
  896. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  897. begin
  898. cg.getexplicitregister(list,NR_FUNCTION_RETURN_REG);
  899. { return the self pointer }
  900. ressym:=tvarsym(current_procinfo.procdef.parast.search('self'));
  901. if not assigned(ressym) then
  902. internalerror(200305058);
  903. cg.ungetregister(list,NR_FUNCTION_RETURN_REG);
  904. // for the optimizer
  905. cg.a_reg_alloc(list,NR_FUNCTION_RETURN_REG);
  906. case ressym.localloc.loc of
  907. LOC_REFERENCE :
  908. begin
  909. reference_reset_base(href,ressym.localloc.reference.index,ressym.localloc.reference.offset);
  910. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_FUNCTION_RETURN_REG);
  911. end;
  912. LOC_REGISTER:
  913. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,ressym.localloc.register,NR_FUNCTION_RETURN_REG);
  914. else
  915. internalerror(2004020409);
  916. end;
  917. uses_acc:=true;
  918. exit;
  919. end;
  920. ressym := tvarsym(current_procinfo.procdef.funcretsym);
  921. if (ressym.refs>0) then
  922. begin
  923. case ressym.localloc.loc of
  924. LOC_FPUREGISTER,
  925. LOC_REGISTER :
  926. begin
  927. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  928. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  929. else
  930. if ressym.vartype.def.deftype = floatdef then
  931. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procinfo.procdef.rettype.def))
  932. else
  933. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  934. resloc.register:=ressym.localloc.register;
  935. end;
  936. LOC_REFERENCE :
  937. begin
  938. location_reset(resloc,LOC_REFERENCE,def_cgsize(current_procinfo.procdef.rettype.def));
  939. reference_reset_base(resloc.reference,ressym.localloc.reference.index,ressym.localloc.reference.offset);
  940. end;
  941. else
  942. internalerror(200309184);
  943. end;
  944. { Here, we return the function result. In most architectures, the value is
  945. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  946. function returns in a register and the caller receives it in an other one }
  947. case current_procinfo.procdef.rettype.def.deftype of
  948. orddef,
  949. enumdef :
  950. begin
  951. uses_acc:=true;
  952. {$ifndef cpu64bit}
  953. if resloc.size in [OS_64,OS_S64] then
  954. begin
  955. uses_acchi:=true;
  956. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  957. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  958. cg.ungetregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  959. cg.ungetregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  960. // for the optimizer
  961. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_LOW_REG);
  962. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_HIGH_REG);
  963. cg64.a_load64_loc_reg(list,resloc,joinreg64(NR_FUNCTION_RETURN64_LOW_REG,
  964. NR_FUNCTION_RETURN64_HIGH_REG));
  965. end
  966. else
  967. {$endif cpu64bit}
  968. begin
  969. cg.getexplicitregister(list,NR_FUNCTION_RETURN_REG);
  970. hreg:=cg.makeregsize(list,NR_FUNCTION_RETURN_REG,resloc.size);
  971. cg.ungetregister(list,hreg);
  972. // for the optimizer
  973. cg.a_reg_alloc(list,NR_FUNCTION_RETURN_REG);
  974. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  975. end;
  976. end;
  977. floatdef :
  978. begin
  979. uses_fpu := true;
  980. {$ifdef cpufpemu}
  981. if cs_fp_emulation in aktmoduleswitches then
  982. cg.a_loadfpu_loc_reg(list,resloc,NR_FUNCTION_RETURN_REG)
  983. else
  984. {$endif cpufpemu}
  985. cg.a_loadfpu_loc_reg(list,resloc,NR_FPU_RESULT_REG);
  986. end;
  987. else
  988. begin
  989. if not paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  990. begin
  991. uses_acc:=true;
  992. {$ifndef cpu64bit}
  993. { Win32 can return records in EAX:EDX }
  994. if resloc.size in [OS_64,OS_S64] then
  995. begin
  996. uses_acchi:=true;
  997. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  998. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  999. cg.ungetregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  1000. cg.ungetregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  1001. // for the optimizer
  1002. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_LOW_REG);
  1003. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_HIGH_REG);
  1004. cg64.a_load64_loc_reg(list,resloc,joinreg64(NR_FUNCTION_RETURN64_LOW_REG,
  1005. NR_FUNCTION_RETURN64_HIGH_REG));
  1006. end
  1007. else
  1008. {$endif cpu64bit}
  1009. begin
  1010. cg.getexplicitregister(list,NR_FUNCTION_RETURN_REG);
  1011. hreg:=cg.makeregsize(list,NR_FUNCTION_RETURN_REG,resloc.size);
  1012. cg.ungetregister(list,hreg);
  1013. // for the optimizer
  1014. cg.a_reg_alloc(list,NR_FUNCTION_RETURN_REG);
  1015. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  1016. end;
  1017. end
  1018. end;
  1019. end;
  1020. end;
  1021. end;
  1022. procedure gen_load_para_value(list:TAAsmoutput);
  1023. var
  1024. hp : tparaitem;
  1025. href : treference;
  1026. gotregvarparas : boolean;
  1027. begin
  1028. { Store register parameters in reference or in register variable }
  1029. if assigned(current_procinfo.procdef.parast) and
  1030. not (po_assembler in current_procinfo.procdef.procoptions) then
  1031. begin
  1032. { move register parameters which aren't regable into memory }
  1033. { we do this before init_paras because that one calls routines which may overwrite these }
  1034. { registers and it also expects the values to be in memory }
  1035. hp:=tparaitem(current_procinfo.procdef.para.first);
  1036. gotregvarparas := false;
  1037. while assigned(hp) do
  1038. begin
  1039. case tvarsym(hp.parasym).localloc.loc of
  1040. LOC_REGISTER,
  1041. LOC_MMREGISTER,
  1042. LOC_FPUREGISTER:
  1043. begin
  1044. gotregvarparas := true;
  1045. { cg.a_load_param_reg will first allocate and then deallocate paraloc }
  1046. { register (if the parameter resides in a register) and then allocate }
  1047. { the regvar (which is currently not allocated) }
  1048. cg.a_loadany_param_reg(list,hp.paraloc[calleeside],tvarsym(hp.parasym).localloc.register,nil);
  1049. end;
  1050. LOC_REFERENCE :
  1051. begin
  1052. if hp.paraloc[calleeside].loc<>LOC_REFERENCE then
  1053. begin
  1054. if getsupreg(hp.paraloc[calleeside].register)<first_int_imreg then
  1055. begin
  1056. {$ifndef cpu64bit}
  1057. if (hp.paraloc[calleeside].size in [OS_S64,OS_64]) then
  1058. begin
  1059. cg.getexplicitregister(list,hp.paraloc[calleeside].registerlow);
  1060. cg.getexplicitregister(list,hp.paraloc[calleeside].registerhigh);
  1061. end
  1062. else
  1063. {$endif cpu64bit}
  1064. cg.getexplicitregister(list,hp.paraloc[calleeside].register);
  1065. end;
  1066. { Release parameter register }
  1067. {$ifndef cpu64bit}
  1068. if (hp.paraloc[calleeside].size in [OS_S64,OS_64]) then
  1069. begin
  1070. cg.ungetregister(list,hp.paraloc[calleeside].registerlow);
  1071. cg.ungetregister(list,hp.paraloc[calleeside].registerhigh);
  1072. end
  1073. else
  1074. {$endif cpu64bit}
  1075. cg.ungetregister(list,hp.paraloc[calleeside].register);
  1076. reference_reset_base(href,tvarsym(hp.parasym).localloc.reference.index,tvarsym(hp.parasym).localloc.reference.offset);
  1077. cg.a_loadany_param_ref(list,hp.paraloc[calleeside],href,nil);
  1078. end;
  1079. end;
  1080. else
  1081. internalerror(200309185);
  1082. end;
  1083. hp:=tparaitem(hp.next);
  1084. end;
  1085. if gotregvarparas then
  1086. begin
  1087. { deallocate all register variables again }
  1088. hp:=tparaitem(current_procinfo.procdef.para.first);
  1089. while assigned(hp) do
  1090. begin
  1091. if (tvarsym(hp.parasym).localloc.loc=LOC_REGISTER) then
  1092. cg.ungetregister(list,tvarsym(hp.parasym).localloc.register);
  1093. hp:=tparaitem(hp.next);
  1094. end;
  1095. end;
  1096. end;
  1097. { generate copies of call by value parameters, must be done before
  1098. the initialization and body is parsed because the refcounts are
  1099. incremented using the local copies }
  1100. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1101. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1102. end;
  1103. procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean);
  1104. begin
  1105. { initialize local data like ansistrings }
  1106. case current_procinfo.procdef.proctypeoption of
  1107. potype_unitinit:
  1108. begin
  1109. { this is also used for initialization of variables in a
  1110. program which does not have a globalsymtable }
  1111. if assigned(current_module.globalsymtable) then
  1112. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1113. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1114. end;
  1115. { units have seperate code for initilization and finalization }
  1116. potype_unitfinalize: ;
  1117. { program init/final is generated in separate procedure }
  1118. potype_proginit: ;
  1119. else
  1120. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1121. end;
  1122. { initialisizes temp. ansi/wide string data }
  1123. inittempvariables(list);
  1124. { initialize ansi/widesstring para's }
  1125. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1126. {$ifdef OLDREGVARS}
  1127. load_regvars(list,nil);
  1128. {$endif OLDREGVARS}
  1129. end;
  1130. procedure gen_finalize_code(list:TAAsmoutput;inlined:boolean);
  1131. begin
  1132. {$ifdef OLDREGVARS}
  1133. cleanup_regvars(list);
  1134. {$endif OLDREGVARS}
  1135. { finalize temporary data }
  1136. finalizetempvariables(list);
  1137. { finalize local data like ansistrings}
  1138. case current_procinfo.procdef.proctypeoption of
  1139. potype_unitfinalize:
  1140. begin
  1141. { this is also used for initialization of variables in a
  1142. program which does not have a globalsymtable }
  1143. if assigned(current_module.globalsymtable) then
  1144. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1145. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1146. end;
  1147. { units/progs have separate code for initialization and finalization }
  1148. potype_unitinit: ;
  1149. { program init/final is generated in separate procedure }
  1150. potype_proginit: ;
  1151. else
  1152. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1153. end;
  1154. { finalize paras data }
  1155. if assigned(current_procinfo.procdef.parast) then
  1156. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1157. end;
  1158. procedure gen_entry_code(list:TAAsmoutput);
  1159. var
  1160. href : treference;
  1161. paraloc1,
  1162. paraloc2 : tparalocation;
  1163. hp : tused_unit;
  1164. begin
  1165. { the actual profile code can clobber some registers,
  1166. therefore if the context must be saved, do it before
  1167. the actual call to the profile code
  1168. }
  1169. if (cs_profile in aktmoduleswitches) and
  1170. not(po_assembler in current_procinfo.procdef.procoptions) then
  1171. begin
  1172. { non-win32 can call mcout even in main }
  1173. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  1174. cg.g_profilecode(list)
  1175. else
  1176. { wdosx, and win32 should not call mcount before monstartup has been called }
  1177. if not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1178. cg.g_profilecode(list);
  1179. end;
  1180. { call startup helpers from main program }
  1181. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1182. begin
  1183. { initialize profiling for win32 }
  1184. if (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1185. (cs_profile in aktmoduleswitches) then
  1186. begin
  1187. reference_reset_symbol(href,objectlibrary.newasmsymbol('etext',AB_EXTERNAL,AT_DATA),0);
  1188. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1189. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1190. paramanager.allocparaloc(list,paraloc2);
  1191. cg.a_paramaddr_ref(list,href,paraloc2);
  1192. reference_reset_symbol(href,objectlibrary.newasmsymbol('__image_base__',AB_EXTERNAL,AT_DATA),0);
  1193. paramanager.allocparaloc(list,paraloc1);
  1194. cg.a_paramaddr_ref(list,href,paraloc1);
  1195. paramanager.freeparaloc(list,paraloc2);
  1196. paramanager.freeparaloc(list,paraloc1);
  1197. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1198. cg.a_call_name(list,'_monstartup');
  1199. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1200. end;
  1201. { initialize units }
  1202. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1203. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1204. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1205. {$ifdef GDB}
  1206. if (cs_debuginfo in aktmoduleswitches) then
  1207. begin
  1208. { include reference to all debuginfo sections of used units }
  1209. hp:=tused_unit(usedunits.first);
  1210. while assigned(hp) do
  1211. begin
  1212. If (hp.u.flags and uf_has_debuginfo)=uf_has_debuginfo then
  1213. current_procinfo.aktlocaldata.concat(Tai_const_symbol.Createname(make_mangledname('DEBUGINFO',hp.u.globalsymtable,''),AT_DATA,0));
  1214. hp:=tused_unit(hp.next);
  1215. end;
  1216. { include reference to debuginfo for this program }
  1217. current_procinfo.aktlocaldata.concat(Tai_const_symbol.Createname(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
  1218. end;
  1219. {$endif GDB}
  1220. end;
  1221. {$ifdef GDB}
  1222. if (cs_debuginfo in aktmoduleswitches) then
  1223. list.concat(Tai_force_line.Create);
  1224. {$endif GDB}
  1225. {$ifdef OLDREGVARS}
  1226. load_regvars(list,nil);
  1227. {$endif OLDREGVARS}
  1228. end;
  1229. procedure gen_exit_code(list:TAAsmoutput);
  1230. begin
  1231. { call __EXIT for main program }
  1232. if (not DLLsource) and
  1233. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1234. cg.a_call_name(list,'FPC_DO_EXIT');
  1235. end;
  1236. {****************************************************************************
  1237. Entry/Exit
  1238. ****************************************************************************}
  1239. procedure gen_proc_symbol(list:Taasmoutput);
  1240. var
  1241. hs : string;
  1242. begin
  1243. { add symbol entry point as well as debug information }
  1244. { will be inserted in front of the rest of this list. }
  1245. { Insert alignment and assembler names }
  1246. { Align, gprof uses 16 byte granularity }
  1247. if (cs_profile in aktmoduleswitches) then
  1248. list.concat(Tai_align.create(16))
  1249. else
  1250. list.concat(Tai_align.create(aktalignment.procalign));
  1251. {$ifdef GDB}
  1252. if (cs_debuginfo in aktmoduleswitches) then
  1253. begin
  1254. if (po_public in current_procinfo.procdef.procoptions) then
  1255. Tprocsym(current_procinfo.procdef.procsym).is_global:=true;
  1256. current_procinfo.procdef.concatstabto(list);
  1257. Tprocsym(current_procinfo.procdef.procsym).isstabwritten:=true;
  1258. end;
  1259. {$endif GDB}
  1260. repeat
  1261. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1262. if hs='' then
  1263. break;
  1264. {$ifdef GDB}
  1265. if (cs_debuginfo in aktmoduleswitches) and
  1266. target_info.use_function_relative_addresses then
  1267. list.concat(Tai_stab_function_name.create(strpnew(hs)));
  1268. {$endif GDB}
  1269. if (cs_profile in aktmoduleswitches) or
  1270. (po_public in current_procinfo.procdef.procoptions) then
  1271. list.concat(Tai_symbol.createname_global(hs,AT_FUNCTION,0))
  1272. else
  1273. list.concat(Tai_symbol.createname(hs,AT_FUNCTION,0));
  1274. until false;
  1275. end;
  1276. procedure gen_proc_symbol_end(list:Taasmoutput);
  1277. {$ifdef GDB}
  1278. var
  1279. stabsendlabel : tasmlabel;
  1280. mangled_length : longint;
  1281. p : pchar;
  1282. {$endif GDB}
  1283. begin
  1284. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1285. {$ifdef GDB}
  1286. if (cs_debuginfo in aktmoduleswitches) then
  1287. begin
  1288. objectlibrary.getlabel(stabsendlabel);
  1289. cg.a_label(list,stabsendlabel);
  1290. { define calling EBP as pseudo local var PM }
  1291. { this enables test if the function is a local one !! }
  1292. {if assigned(current_procinfo.parent) and
  1293. (current_procinfo.procdef.parast.symtablelevel>normal_function_level) then
  1294. list.concat(Tai_stabs.Create(strpnew(
  1295. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1296. tostr(N_LSYM)+',0,0,'+tostr(current_procinfo.parent_framepointer_offset)))); }
  1297. if (not is_void(current_procinfo.procdef.rettype.def)) and
  1298. (tvarsym(current_procinfo.procdef.funcretsym).refs>0) then
  1299. begin
  1300. if tvarsym(current_procinfo.procdef.funcretsym).localloc.loc=LOC_REFERENCE then
  1301. begin
  1302. {$warning Need to add gdb support for ret in param register calling}
  1303. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1304. begin
  1305. list.concat(Tai_stabs.Create(strpnew(
  1306. '"'+current_procinfo.procdef.procsym.name+':X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1307. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1308. if (m_result in aktmodeswitches) then
  1309. list.concat(Tai_stabs.Create(strpnew(
  1310. '"RESULT:X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1311. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))))
  1312. end
  1313. else
  1314. begin
  1315. list.concat(Tai_stabs.Create(strpnew(
  1316. '"'+current_procinfo.procdef.procsym.name+':X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1317. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1318. if (m_result in aktmodeswitches) then
  1319. list.concat(Tai_stabs.Create(strpnew(
  1320. '"RESULT:X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1321. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1322. end;
  1323. end;
  1324. end;
  1325. mangled_length:=length(current_procinfo.procdef.mangledname);
  1326. getmem(p,2*mangled_length+50);
  1327. strpcopy(p,'192,0,0,');
  1328. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1329. if (target_info.use_function_relative_addresses) then
  1330. begin
  1331. strpcopy(strend(p),'-');
  1332. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1333. end;
  1334. list.concat(Tai_stabn.Create(strnew(p)));
  1335. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1336. +current_procinfo.procdef.mangledname))));
  1337. p[0]:='2';p[1]:='2';p[2]:='4';
  1338. strpcopy(strend(p),'_end');}
  1339. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1340. if (target_info.use_function_relative_addresses) then
  1341. begin
  1342. strpcopy(strend(p),'-');
  1343. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1344. end;
  1345. list.concatlist(withdebuglist);
  1346. list.concat(Tai_stabn.Create(strnew(p)));
  1347. { strpnew('224,0,0,'
  1348. +current_procinfo.procdef.mangledname+'_end'))));}
  1349. freemem(p,2*mangled_length+50);
  1350. end;
  1351. {$endif GDB}
  1352. end;
  1353. procedure gen_stackalloc_code(list:Taasmoutput);
  1354. var
  1355. hitemp,
  1356. lotemp,
  1357. stackframe : longint;
  1358. check : boolean;
  1359. paraloc1 : tparalocation;
  1360. href : treference;
  1361. begin
  1362. check:=(cs_check_stack in aktlocalswitches) and (current_procinfo.procdef.proctypeoption<>potype_proginit);
  1363. if check then
  1364. begin
  1365. { Allocate tempspace to store register parameter than
  1366. is destroyed when calling stackchecking code }
  1367. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1368. if paraloc1.loc=LOC_REGISTER then
  1369. tg.GetTemp(list,POINTER_SIZE,tt_normal,href);
  1370. end;
  1371. { Calculate size of stackframe }
  1372. stackframe:=current_procinfo.calc_stackframe_size;
  1373. { All temps are know, write offsets used for information }
  1374. if (cs_asm_source in aktglobalswitches) then
  1375. begin
  1376. if tg.direction>0 then
  1377. begin
  1378. lotemp:=current_procinfo.tempstart;
  1379. hitemp:=tg.lasttemp;
  1380. end
  1381. else
  1382. begin
  1383. lotemp:=tg.lasttemp;
  1384. hitemp:=current_procinfo.tempstart;
  1385. end;
  1386. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1387. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1388. end;
  1389. {$ifndef powerpc}
  1390. { at least for the ppc this applies always, so this code isn't usable (FK) }
  1391. { omit stack frame ? }
  1392. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1393. begin
  1394. CGmessage(cg_d_stackframe_omited);
  1395. if stackframe<>0 then
  1396. cg.g_stackpointer_alloc(list,stackframe);
  1397. end
  1398. else
  1399. {$endif powerpc}
  1400. begin
  1401. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1402. cg.g_interrupt_stackframe_entry(list);
  1403. cg.g_stackframe_entry(list,stackframe);
  1404. { Add stack checking code? }
  1405. if check then
  1406. begin
  1407. { The tempspace to store original register is already
  1408. allocated above before the stackframe size is calculated. }
  1409. if paraloc1.loc=LOC_REGISTER then
  1410. cg.a_load_reg_ref(list,OS_INT,OS_INT,paraloc1.register,href);
  1411. paramanager.allocparaloc(list,paraloc1);
  1412. cg.a_param_const(list,OS_INT,stackframe,paraloc1);
  1413. paramanager.freeparaloc(list,paraloc1);
  1414. { No register saving needed, saveregisters is used }
  1415. {$ifndef x86}
  1416. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1417. {$endif x86}
  1418. cg.a_call_name(list,'FPC_STACKCHECK');
  1419. {$ifndef x86}
  1420. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1421. {$endif x86}
  1422. if paraloc1.loc=LOC_REGISTER then
  1423. begin
  1424. cg.a_load_ref_reg(list,OS_INT,OS_INT,href,paraloc1.register);
  1425. tg.UnGetTemp(list,href);
  1426. end;
  1427. end;
  1428. end;
  1429. end;
  1430. procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
  1431. var
  1432. stacksize,
  1433. retsize : longint;
  1434. begin
  1435. {$ifndef powerpc}
  1436. { remove stackframe }
  1437. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1438. begin
  1439. stacksize:=current_procinfo.calc_stackframe_size;
  1440. if (stacksize<>0) then
  1441. cg.a_op_const_reg(list,OP_ADD,OS_ADDR,stacksize,current_procinfo.framepointer);
  1442. end
  1443. else
  1444. cg.g_restore_frame_pointer(list);
  1445. {$endif}
  1446. {$ifdef x86}
  1447. { at last, the return is generated }
  1448. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1449. cg.g_interrupt_stackframe_exit(list,usesacc,usesacchi)
  1450. else
  1451. {$endif x86}
  1452. begin
  1453. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1454. begin
  1455. retsize:=0;
  1456. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1457. inc(retsize,POINTER_SIZE);
  1458. end
  1459. else
  1460. retsize:=current_procinfo.para_stack_size;
  1461. cg.g_return_from_proc(list,retsize);
  1462. end;
  1463. {$ifndef cpu64bit}
  1464. if usesacchi then
  1465. begin
  1466. cg.a_reg_dealloc(list,NR_FUNCTION_RETURN64_LOW_REG);
  1467. cg.a_reg_dealloc(list,NR_FUNCTION_RETURN64_HIGH_REG);
  1468. end
  1469. else
  1470. {$endif cpu64bit}
  1471. if usesacc then
  1472. cg.a_reg_dealloc(list,NR_FUNCTION_RETURN_REG);
  1473. end;
  1474. procedure gen_save_used_regs(list:TAAsmoutput);
  1475. begin
  1476. { Pure assembler routines need to save the registers themselves }
  1477. if (po_assembler in current_procinfo.procdef.procoptions) then
  1478. exit;
  1479. { for the save all registers we can simply use a pusha,popa which
  1480. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1481. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1482. cg.g_save_all_registers(list)
  1483. else
  1484. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1485. cg.g_save_standard_registers(list);
  1486. end;
  1487. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tparalocation);
  1488. begin
  1489. { Pure assembler routines need to save the registers themselves }
  1490. if (po_assembler in current_procinfo.procdef.procoptions) then
  1491. exit;
  1492. { for the save all registers we can simply use a pusha,popa which
  1493. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1494. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1495. cg.g_restore_all_registers(list,funcretparaloc)
  1496. else
  1497. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1498. cg.g_restore_standard_registers(list);
  1499. end;
  1500. {****************************************************************************
  1501. Inlining
  1502. ****************************************************************************}
  1503. (*
  1504. procedure load_inlined_return_value(list:TAAsmoutput);
  1505. var
  1506. ressym: tvarsym;
  1507. resloc: tlocation;
  1508. r,r2 : tregister;
  1509. begin
  1510. if not is_void(current_procinfo.procdef.rettype.def) then
  1511. begin
  1512. ressym := tvarsym(current_procinfo.procdef.funcretsym);
  1513. if ressym.reg.enum <> R_NO then
  1514. begin
  1515. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1516. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  1517. else
  1518. if ressym.vartype.def.deftype = floatdef then
  1519. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procinfo.procdef.rettype.def))
  1520. else
  1521. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  1522. resloc.register := ressym.reg;
  1523. end
  1524. else
  1525. begin
  1526. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  1527. reference_reset_base(resloc.reference,current_procinfo.framepointer,tvarsym(current_procinfo.procdef.funcretsym).adjusted_address);
  1528. end;
  1529. { Here, we return the function result. In most architectures, the value is
  1530. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1531. function returns in a register and the caller receives it in an other one }
  1532. case current_procinfo.procdef.rettype.def.deftype of
  1533. orddef,
  1534. enumdef :
  1535. begin
  1536. {$ifndef cpu64bit}
  1537. if resloc.size in [OS_64,OS_S64] then
  1538. begin
  1539. r:=cg.getregisterint(list,OS_INT);
  1540. r2:=cg.getregisterint(list,OS_INT);
  1541. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2));
  1542. end
  1543. else
  1544. {$endif cpu64bit}
  1545. begin
  1546. r:=cg.getregisterint(list,resloc.size);
  1547. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1548. end;
  1549. end;
  1550. floatdef :
  1551. begin
  1552. {$ifdef cpufpemu}
  1553. if cs_fp_emulation in aktmoduleswitches then
  1554. r.enum := FUNCTION_RETURN_REG
  1555. else
  1556. {$endif cpufpemu}
  1557. r.enum:=FPU_RESULT_REG;
  1558. cg.a_loadfpu_loc_reg(list,resloc,r);
  1559. end;
  1560. else
  1561. begin
  1562. if not paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1563. begin
  1564. {$ifndef cpu64bit}
  1565. { Win32 can return records in EAX:EDX }
  1566. if resloc.size in [OS_64,OS_S64] then
  1567. begin
  1568. r:=cg.getregisterint(list,OS_INT);
  1569. r2:=cg.getregisterint(list,OS_INT);
  1570. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2));
  1571. end
  1572. else
  1573. {$endif cpu64bit}
  1574. begin
  1575. r:=cg.getregisterint(list,resloc.size);
  1576. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1577. end;
  1578. end
  1579. end;
  1580. end;
  1581. end;
  1582. end;
  1583. procedure geninlineentrycode(list:TAAsmoutput;stackframe:longint);
  1584. begin
  1585. { initialize return value }
  1586. initretvalue(list);
  1587. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1588. { initialisizes temp. ansi/wide string data }
  1589. inittempvariables(list);
  1590. { initialize ansi/widesstring para's }
  1591. if assigned(current_procinfo.procdef.parast) then
  1592. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1593. { generate copies of call by value parameters }
  1594. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1595. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1596. load_regvars(list,nil);
  1597. end;
  1598. procedure geninlineexitcode(list:TAAsmoutput;inlined:boolean);
  1599. var
  1600. usesacc,
  1601. usesacchi,
  1602. usesfpu : boolean;
  1603. begin
  1604. if aktexitlabel.is_used then
  1605. cg.a_label(list,aktexitlabel);
  1606. cleanup_regvars(list);
  1607. { finalize temporary data }
  1608. finalizetempvariables(list);
  1609. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1610. { finalize paras data }
  1611. if assigned(current_procinfo.procdef.parast) then
  1612. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1613. { handle return value, this is not done for assembler routines when
  1614. they didn't reference the result variable }
  1615. if not(po_assembler in current_procinfo.procdef.procoptions) or
  1616. (assigned(current_procinfo.procdef.funcretsym) and
  1617. (tvarsym(current_procinfo.procdef.funcretsym).refcount>1)) then
  1618. begin
  1619. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1620. internalerror(200305263);
  1621. // load_inlined_return_value(list);
  1622. load_return_value(list,usesacc,usesacchi,usesfpu)
  1623. end;
  1624. cleanup_regvars(list);
  1625. end;
  1626. *)
  1627. {****************************************************************************
  1628. Const Data
  1629. ****************************************************************************}
  1630. procedure insertconstdata(sym : ttypedconstsym);
  1631. { this does not affect the local stack space, since all
  1632. typed constansts and initialized variables are always
  1633. put in the .data / .rodata section
  1634. }
  1635. var
  1636. storefilepos : tfileposinfo;
  1637. curconstsegment : taasmoutput;
  1638. l : longint;
  1639. stabstr:Pchar;
  1640. begin
  1641. storefilepos:=aktfilepos;
  1642. aktfilepos:=sym.fileinfo;
  1643. if sym.is_writable then
  1644. curconstsegment:=datasegment
  1645. else
  1646. curconstsegment:=consts;
  1647. l:=sym.getsize;
  1648. { insert cut for smartlinking or alignment }
  1649. if (cs_create_smart in aktmoduleswitches) then
  1650. curconstSegment.concat(Tai_cut.Create);
  1651. curconstSegment.concat(Tai_align.create(const_align(l)));
  1652. if (sym.owner.symtabletype=globalsymtable) or
  1653. (cs_create_smart in aktmoduleswitches) or
  1654. (assigned(current_procinfo) and
  1655. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1656. DLLSource then
  1657. curconstSegment.concat(Tai_symbol.Createname_global(sym.mangledname,AT_DATA,l))
  1658. else
  1659. curconstSegment.concat(Tai_symbol.Createname(sym.mangledname,AT_DATA,l));
  1660. aktfilepos:=storefilepos;
  1661. end;
  1662. procedure insertbssdata(sym : tvarsym);
  1663. var
  1664. l,varalign : longint;
  1665. storefilepos : tfileposinfo;
  1666. stabstr:Pchar;
  1667. begin
  1668. storefilepos:=aktfilepos;
  1669. aktfilepos:=sym.fileinfo;
  1670. l:=sym.getvaluesize;
  1671. if (vo_is_thread_var in sym.varoptions) then
  1672. inc(l,pointer_size);
  1673. varalign:=var_align(l);
  1674. {
  1675. sym.address:=align(datasize,varalign);
  1676. datasize:=tvarsym(sym).address+l;
  1677. }
  1678. { insert cut for smartlinking or alignment }
  1679. if (cs_create_smart in aktmoduleswitches) then
  1680. bssSegment.concat(Tai_cut.Create);
  1681. bssSegment.concat(Tai_align.create(varalign));
  1682. if (sym.owner.symtabletype=globalsymtable) or
  1683. (cs_create_smart in aktmoduleswitches) or
  1684. DLLSource or
  1685. (assigned(current_procinfo) and
  1686. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1687. (vo_is_exported in sym.varoptions) or
  1688. (vo_is_C_var in sym.varoptions) then
  1689. bssSegment.concat(Tai_datablock.Create_global(sym.mangledname,l))
  1690. else
  1691. bssSegment.concat(Tai_datablock.Create(sym.mangledname,l));
  1692. aktfilepos:=storefilepos;
  1693. end;
  1694. procedure gen_alloc_localst(list:TAAsmoutput;st:tlocalsymtable);
  1695. var
  1696. sym : tsym;
  1697. begin
  1698. sym:=tsym(st.symindex.first);
  1699. while assigned(sym) do
  1700. begin
  1701. { Only allocate space for referenced locals }
  1702. if (sym.typ=varsym) and
  1703. (tvarsym(sym).refs>0) then
  1704. begin
  1705. with tvarsym(sym) do
  1706. begin
  1707. {$warning TODO Add support for register variables}
  1708. localloc.loc:=LOC_REFERENCE;
  1709. tg.GetLocal(list,getvaluesize,vartype.def,localloc.reference);
  1710. if cs_asm_source in aktglobalswitches then
  1711. list.concat(Tai_comment.Create(strpnew('Local '+realname+' located at '+
  1712. std_regname(localloc.reference.index)+tostr_with_plus(localloc.reference.offset))));
  1713. end;
  1714. end;
  1715. sym:=tsym(sym.indexnext);
  1716. end;
  1717. end;
  1718. procedure gen_free_localst(list:TAAsmoutput;st:tlocalsymtable);
  1719. var
  1720. sym : tsym;
  1721. begin
  1722. sym:=tsym(st.symindex.first);
  1723. while assigned(sym) do
  1724. begin
  1725. if (sym.typ=varsym) and
  1726. (tvarsym(sym).refs>0) then
  1727. begin
  1728. with tvarsym(sym) do
  1729. begin
  1730. { Note: We need to keep the data available in memory
  1731. for the sub procedures that can access local data
  1732. in the parent procedures }
  1733. case localloc.loc of
  1734. LOC_REFERENCE :
  1735. tg.Ungetlocal(list,localloc.reference);
  1736. LOC_REGISTER :
  1737. begin
  1738. {$ifndef cpu64bit}
  1739. if localloc.size in [OS_64,OS_S64] then
  1740. begin
  1741. cg.ungetregister(list,localloc.registerlow);
  1742. cg.ungetregister(list,localloc.registerhigh);
  1743. end
  1744. else
  1745. {$endif cpu64bit}
  1746. cg.ungetregister(list,localloc.register);
  1747. end;
  1748. end;
  1749. end;
  1750. end;
  1751. sym:=tsym(sym.indexnext);
  1752. end;
  1753. end;
  1754. procedure gen_alloc_parast(list:TAAsmoutput;st:tparasymtable);
  1755. var
  1756. sym : tsym;
  1757. begin
  1758. sym:=tsym(st.symindex.first);
  1759. while assigned(sym) do
  1760. begin
  1761. if sym.typ=varsym then
  1762. begin
  1763. with tvarsym(sym) do
  1764. begin
  1765. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1766. begin
  1767. case paraitem.paraloc[calleeside].loc of
  1768. LOC_MMREGISTER,
  1769. LOC_FPUREGISTER,
  1770. LOC_REGISTER:
  1771. begin
  1772. (*
  1773. if paraitem.paraloc[calleeside].register=NR_NO then
  1774. begin
  1775. paraitem.paraloc[calleeside].loc:=LOC_REGISTER;
  1776. paraitem.paraloc[calleeside].size:=paraitem.paraloc[calleeside].size;
  1777. {$ifndef cpu64bit}
  1778. if paraitem.paraloc[calleeside].size in [OS_64,OS_S64] then
  1779. begin
  1780. paraitem.paraloc[calleeside].registerlow:=cg.getregisterint(list,OS_32);
  1781. paraitem.paraloc[calleeside].registerhigh:=cg.getregisterint(list,OS_32);
  1782. end
  1783. else
  1784. {$endif cpu64bit}
  1785. paraitem.paraloc[calleeside].register:=cg.getregisterint(list,localloc.size);
  1786. end;
  1787. *)
  1788. (*
  1789. {$warning TODO Allocate register paras}
  1790. localloc.loc:=LOC_REGISTER;
  1791. localloc.size:=paraitem.paraloc[calleeside].size;
  1792. {$ifndef cpu64bit}
  1793. if localloc.size in [OS_64,OS_S64] then
  1794. begin
  1795. localloc.registerlow:=cg.getregisterint(list,OS_32);
  1796. localloc.registerhigh:=cg.getregisterint(list,OS_32);
  1797. end
  1798. else
  1799. {$endif cpu64bit}
  1800. localloc.register:=cg.getregisterint(list,localloc.size);
  1801. *)
  1802. localloc.loc:=LOC_REFERENCE;
  1803. localloc.size:=paraitem.paraloc[calleeside].size;
  1804. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1805. end
  1806. else
  1807. localloc:=paraitem.paraloc[calleeside];
  1808. end;
  1809. end
  1810. else
  1811. localloc:=paraitem.paraloc[calleeside];
  1812. if cs_asm_source in aktglobalswitches then
  1813. begin
  1814. case localloc.loc of
  1815. LOC_REFERENCE :
  1816. begin
  1817. list.concat(Tai_comment.Create(strpnew('Para '+realname+' located at '+
  1818. std_regname(localloc.reference.index)+tostr_with_plus(localloc.reference.offset))));
  1819. {$ifdef powerpc}
  1820. localloc.size:=paraitem.paraloc[calleeside].size;
  1821. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1822. {$endif powerpc}
  1823. end;
  1824. end;
  1825. end;
  1826. end;
  1827. end;
  1828. sym:=tsym(sym.indexnext);
  1829. end;
  1830. end;
  1831. procedure gen_alloc_inline_parast(list:TAAsmoutput;st:tparasymtable);
  1832. var
  1833. sym : tsym;
  1834. begin
  1835. sym:=tsym(st.symindex.first);
  1836. while assigned(sym) do
  1837. begin
  1838. if sym.typ=varsym then
  1839. begin
  1840. with tvarsym(sym) do
  1841. begin
  1842. {$warning TODO Allocate register paras}
  1843. localloc.loc:=LOC_REFERENCE;
  1844. localloc.size:=int_cgsize(paramanager.push_size(vs_value,vartype.def,pocall_inline));
  1845. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1846. if cs_asm_source in aktglobalswitches then
  1847. begin
  1848. case localloc.loc of
  1849. LOC_REFERENCE :
  1850. list.concat(Tai_comment.Create(strpnew('Para '+realname+' allocated at '+
  1851. std_regname(localloc.reference.index)+tostr_with_plus(localloc.reference.offset))));
  1852. end;
  1853. end;
  1854. paraitem.paraloc[callerside]:=localloc;
  1855. paraitem.paraloc[calleeside]:=localloc;
  1856. end;
  1857. end;
  1858. sym:=tsym(sym.indexnext);
  1859. end;
  1860. end;
  1861. procedure gen_free_parast(list:TAAsmoutput;st:tparasymtable);
  1862. var
  1863. sym : tsym;
  1864. begin
  1865. sym:=tsym(st.symindex.first);
  1866. while assigned(sym) do
  1867. begin
  1868. if sym.typ=varsym then
  1869. begin
  1870. with tvarsym(sym) do
  1871. begin
  1872. { Note: We need to keep the data available in memory
  1873. for the sub procedures that can access local data
  1874. in the parent procedures }
  1875. case localloc.loc of
  1876. LOC_REFERENCE :
  1877. tg.UngetLocal(list,localloc.reference);
  1878. LOC_REGISTER :
  1879. begin
  1880. if localloc.register<>paraitem.paraloc[calleeside].register then
  1881. begin
  1882. {$ifndef cpu64bit}
  1883. if localloc.size in [OS_64,OS_S64] then
  1884. begin
  1885. cg.ungetregister(list,localloc.registerlow);
  1886. cg.ungetregister(list,localloc.registerhigh);
  1887. end
  1888. else
  1889. {$endif cpu64bit}
  1890. cg.ungetregister(list,localloc.register);
  1891. end;
  1892. end;
  1893. end;
  1894. end;
  1895. end;
  1896. sym:=tsym(sym.indexnext);
  1897. end;
  1898. end;
  1899. { persistent rtti generation }
  1900. procedure generate_rtti(p:Ttypesym);
  1901. var
  1902. rsym : trttisym;
  1903. def : tstoreddef;
  1904. begin
  1905. { rtti can only be generated for classes that are always typesyms }
  1906. def:=tstoreddef(ttypesym(p).restype.def);
  1907. { there is an error, skip rtti info }
  1908. if def.deftype=errordef then
  1909. exit;
  1910. { only create rtti once for each definition }
  1911. if not(df_has_rttitable in def.defoptions) then
  1912. begin
  1913. { definition should be in the same symtable as the symbol }
  1914. if p.owner<>def.owner then
  1915. internalerror(200108262);
  1916. { create rttisym }
  1917. rsym:=trttisym.create(p.name,fullrtti);
  1918. p.owner.insert(rsym);
  1919. { register rttisym in definition }
  1920. include(def.defoptions,df_has_rttitable);
  1921. def.rttitablesym:=rsym;
  1922. { write rtti data }
  1923. def.write_child_rtti_data(fullrtti);
  1924. if (cs_create_smart in aktmoduleswitches) then
  1925. rttiList.concat(Tai_cut.Create);
  1926. rttilist.concat(tai_align.create(const_align(pointer_size)));
  1927. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  1928. def.write_rtti_data(fullrtti);
  1929. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  1930. end;
  1931. end;
  1932. { persistent init table generation }
  1933. procedure generate_inittable(p:tsym);
  1934. var
  1935. rsym : trttisym;
  1936. def : tstoreddef;
  1937. begin
  1938. { anonymous types are also allowed for records that can be varsym }
  1939. case p.typ of
  1940. typesym :
  1941. def:=tstoreddef(ttypesym(p).restype.def);
  1942. varsym :
  1943. def:=tstoreddef(tvarsym(p).vartype.def);
  1944. else
  1945. internalerror(200108263);
  1946. end;
  1947. { only create inittable once for each definition }
  1948. if not(df_has_inittable in def.defoptions) then
  1949. begin
  1950. { definition should be in the same symtable as the symbol }
  1951. if p.owner<>def.owner then
  1952. internalerror(200108264);
  1953. { create rttisym }
  1954. rsym:=trttisym.create(p.name,initrtti);
  1955. p.owner.insert(rsym);
  1956. { register rttisym in definition }
  1957. include(def.defoptions,df_has_inittable);
  1958. def.inittablesym:=rsym;
  1959. { write inittable data }
  1960. def.write_child_rtti_data(initrtti);
  1961. if (cs_create_smart in aktmoduleswitches) then
  1962. rttiList.concat(Tai_cut.Create);
  1963. rttilist.concat(tai_align.create(const_align(pointer_size)));
  1964. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  1965. def.write_rtti_data(initrtti);
  1966. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  1967. end;
  1968. end;
  1969. end.
  1970. {
  1971. $Log$
  1972. Revision 1.202 2004-05-23 15:23:30 peter
  1973. * fixed qword(longint) that removed sign from the number
  1974. * removed code in the compiler that relied on wrong qword(longint)
  1975. code generation
  1976. Revision 1.201 2004/05/23 15:06:21 peter
  1977. * implicit_finally flag must be set in pass1
  1978. * add check whether the implicit frame is generated when expected
  1979. Revision 1.200 2004/05/22 23:34:28 peter
  1980. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1981. Revision 1.199 2004/05/19 21:16:12 peter
  1982. * add DEBUGINFO symbol to reference the .o file that includes the
  1983. stabs info for types and global/static variables
  1984. * debuginfo flag added to ppu to indicate whether debuginfo is
  1985. generated or not
  1986. Revision 1.198 2004/05/02 17:26:19 peter
  1987. * fix stabs for globals
  1988. Revision 1.197 2004/03/29 14:43:47 peter
  1989. * cleaner temp get/unget for exceptions
  1990. Revision 1.196 2004/03/03 22:02:52 peter
  1991. * use loadnode and finalize_data_node for init/final code to support
  1992. threadvars correctly
  1993. Revision 1.195 2004/03/02 00:36:33 olle
  1994. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1995. Revision 1.194 2004/02/27 10:21:05 florian
  1996. * top_symbol killed
  1997. + refaddr to treference added
  1998. + refsymbol to treference added
  1999. * top_local stuff moved to an extra record to save memory
  2000. + aint introduced
  2001. * tppufile.get/putint64/aint implemented
  2002. Revision 1.193 2004/02/22 18:27:21 florian
  2003. * fixed exception reason size for 64 bit systems
  2004. Revision 1.192 2004/02/08 17:48:59 jonas
  2005. * fixed regvars
  2006. Revision 1.191 2004/02/05 19:35:27 florian
  2007. * more x86-64 fixes
  2008. Revision 1.190 2004/02/05 01:24:08 florian
  2009. * several fixes to compile x86-64 system
  2010. Revision 1.189 2004/02/04 22:15:15 daniel
  2011. * Rtti generation moved to ncgutil
  2012. * Assmtai usage of symsym removed
  2013. * operator overloading cleanup up
  2014. Revision 1.188 2004/02/04 22:01:13 peter
  2015. * first try to get cpupara working for x86_64
  2016. Revision 1.187 2004/02/03 22:32:54 peter
  2017. * renamed xNNbittype to xNNinttype
  2018. * renamed registers32 to registersint
  2019. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  2020. Revision 1.186 2004/01/31 18:40:15 daniel
  2021. * Last steps before removal of aasmtai dependency in symsym can be
  2022. accomplished.
  2023. Revision 1.185 2004/01/31 17:45:17 peter
  2024. * Change several $ifdef i386 to x86
  2025. * Change several OS_32 to OS_INT/OS_ADDR
  2026. Revision 1.184 2004/01/21 21:01:34 peter
  2027. * fixed stackchecking for register calling
  2028. Revision 1.183 2004/01/17 15:55:10 jonas
  2029. * fixed allocation of parameters passed by reference for powerpc in
  2030. callee
  2031. Revision 1.182 2004/01/13 18:08:58 florian
  2032. * x86-64 compilation fixed
  2033. Revision 1.181 2004/01/12 22:11:38 peter
  2034. * use localalign info for alignment for locals and temps
  2035. * sparc fpu flags branching added
  2036. * moved powerpc copy_valye_openarray to generic
  2037. Revision 1.180 2003/12/28 21:57:43 jonas
  2038. * fixed procedures declared as "interrupt" for non-x86
  2039. Revision 1.179 2003/12/26 13:19:16 florian
  2040. * rtl and compiler compile with -Cfsse2
  2041. Revision 1.178 2003/12/26 00:32:21 florian
  2042. + fpu<->mm register conversion
  2043. Revision 1.177 2003/12/24 00:10:02 florian
  2044. - delete parameter in cg64 methods removed
  2045. Revision 1.176 2003/12/23 14:38:07 florian
  2046. + second_floataddsse implemented
  2047. Revision 1.175 2003/12/22 19:00:17 florian
  2048. * fixed some x86-64 issues
  2049. Revision 1.174 2003/12/07 16:28:30 jonas
  2050. * fixed typo found by Charlie
  2051. Revision 1.173 2003/12/06 01:15:22 florian
  2052. * reverted Peter's alloctemp patch; hopefully properly
  2053. Revision 1.172 2003/12/03 23:13:20 peter
  2054. * delayed paraloc allocation, a_param_*() gets extra parameter
  2055. if it needs to allocate temp or real paralocation
  2056. * optimized/simplified int-real loading
  2057. Revision 1.171 2003/11/30 19:35:29 florian
  2058. * fixed several arm related problems
  2059. Revision 1.170 2003/11/29 20:13:25 florian
  2060. * fixed several pi_do_call problems
  2061. Revision 1.169 2003/11/23 17:05:15 peter
  2062. * register calling is left-right
  2063. * parameter ordering
  2064. * left-right calling inserts result parameter last
  2065. Revision 1.168 2003/11/22 00:31:25 jonas
  2066. + extra allocations of function result regs for the optimiser
  2067. Revision 1.167 2003/11/11 21:10:12 peter
  2068. * remove temporary stdcall hack
  2069. Revision 1.166 2003/11/10 22:02:52 peter
  2070. * cross unit inlining fixed
  2071. Revision 1.165 2003/11/07 15:58:32 florian
  2072. * Florian's culmutative nr. 1; contains:
  2073. - invalid calling conventions for a certain cpu are rejected
  2074. - arm softfloat calling conventions
  2075. - -Sp for cpu dependend code generation
  2076. - several arm fixes
  2077. - remaining code for value open array paras on heap
  2078. Revision 1.164 2003/11/04 19:03:50 peter
  2079. * fixes for temp type patch
  2080. Revision 1.163 2003/11/04 15:35:13 peter
  2081. * fix for referencecounted temps
  2082. Revision 1.162 2003/10/25 11:34:02 florian
  2083. * fixed compilation of ppc system unit
  2084. Revision 1.161 2003/10/19 01:34:30 florian
  2085. * some ppc stuff fixed
  2086. * memory leak fixed
  2087. Revision 1.160 2003/10/17 15:08:34 peter
  2088. * commented out more obsolete constants
  2089. Revision 1.159 2003/10/17 14:38:32 peter
  2090. * 64k registers supported
  2091. * fixed some memory leaks
  2092. Revision 1.158 2003/10/10 17:48:13 peter
  2093. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  2094. * tregisteralloctor renamed to trgobj
  2095. * removed rgobj from a lot of units
  2096. * moved location_* and reference_* to cgobj
  2097. * first things for mmx register allocation
  2098. Revision 1.157 2003/10/09 21:31:37 daniel
  2099. * Register allocator splitted, ans abstract now
  2100. Revision 1.156 2003/10/07 18:18:16 peter
  2101. * fix register calling for assembler procedures
  2102. * fix result loading for assembler procedures
  2103. Revision 1.155 2003/10/07 15:17:07 peter
  2104. * inline supported again, LOC_REFERENCEs are used to pass the
  2105. parameters
  2106. * inlineparasymtable,inlinelocalsymtable removed
  2107. * exitlabel inserting fixed
  2108. Revision 1.154 2003/10/01 20:34:48 peter
  2109. * procinfo unit contains tprocinfo
  2110. * cginfo renamed to cgbase
  2111. * moved cgmessage to verbose
  2112. * fixed ppc and sparc compiles
  2113. Revision 1.153 2003/09/30 21:02:37 peter
  2114. * updates for inlining
  2115. Revision 1.152 2003/09/29 20:58:56 peter
  2116. * optimized releasing of registers
  2117. Revision 1.151 2003/09/28 21:47:18 peter
  2118. * register paras and local copies updates
  2119. Revision 1.150 2003/09/28 17:55:03 peter
  2120. * parent framepointer changed to hidden parameter
  2121. * tloadparentfpnode added
  2122. Revision 1.149 2003/09/28 13:39:38 peter
  2123. * optimized releasing of registers
  2124. Revision 1.148 2003/09/25 21:28:00 peter
  2125. * parameter fixes
  2126. Revision 1.147 2003/09/23 21:03:59 peter
  2127. * check for refs>0 in init/final local data
  2128. Revision 1.146 2003/09/23 17:56:05 peter
  2129. * locals and paras are allocated in the code generation
  2130. * tvarsym.localloc contains the location of para/local when
  2131. generating code for the current procedure
  2132. Revision 1.145 2003/09/16 16:17:01 peter
  2133. * varspez in calls to push_addr_param
  2134. Revision 1.144 2003/09/14 21:33:37 peter
  2135. * location_force_reg gives IE when size=OS_NO
  2136. Revision 1.143 2003/09/14 19:18:10 peter
  2137. * remove obsolete code already in comments
  2138. Revision 1.142 2003/09/11 11:54:59 florian
  2139. * improved arm code generation
  2140. * move some protected and private field around
  2141. * the temp. register for register parameters/arguments are now released
  2142. before the move to the parameter register is done. This improves
  2143. the code in a lot of cases.
  2144. Revision 1.141 2003/09/10 08:31:47 marco
  2145. * Patch from Peter for paraloc
  2146. Revision 1.140 2003/09/07 22:09:35 peter
  2147. * preparations for different default calling conventions
  2148. * various RA fixes
  2149. Revision 1.139 2003/09/03 15:55:01 peter
  2150. * NEWRA branch merged
  2151. Revision 1.138 2003/09/03 11:18:37 florian
  2152. * fixed arm concatcopy
  2153. + arm support in the common compiler sources added
  2154. * moved some generic cg code around
  2155. + tfputype added
  2156. * ...
  2157. Revision 1.137.2.4 2003/08/31 15:46:26 peter
  2158. * more updates for tregister
  2159. Revision 1.137.2.3 2003/08/29 17:28:59 peter
  2160. * next batch of updates
  2161. Revision 1.137.2.2 2003/08/28 18:35:08 peter
  2162. * tregister changed to cardinal
  2163. Revision 1.137.2.1 2003/08/27 19:55:54 peter
  2164. * first tregister patch
  2165. Revision 1.137 2003/08/20 20:29:06 daniel
  2166. * Some more R_NO changes
  2167. * Preventive code to loadref added
  2168. Revision 1.136 2003/08/20 17:48:49 peter
  2169. * fixed stackalloc to not allocate localst.datasize twice
  2170. * order of stackalloc code fixed for implicit init/final
  2171. Revision 1.135 2003/08/17 16:59:20 jonas
  2172. * fixed regvars so they work with newra (at least for ppc)
  2173. * fixed some volatile register bugs
  2174. + -dnotranslation option for -dnewra, which causes the registers not to
  2175. be translated from virtual to normal registers. Requires support in
  2176. the assembler writer as well, which is only implemented in aggas/
  2177. agppcgas currently
  2178. Revision 1.134 2003/08/11 21:18:20 peter
  2179. * start of sparc support for newra
  2180. Revision 1.133 2003/08/09 18:56:54 daniel
  2181. * cs_regalloc renamed to cs_regvars to avoid confusion with register
  2182. allocator
  2183. * Some preventive changes to i386 spillinh code
  2184. Revision 1.132 2003/08/03 14:09:50 daniel
  2185. * Fixed a register allocator bug
  2186. * Figured out why -dnewra generates superfluous "mov reg1,reg2"
  2187. statements: changes in location_force. These moves are now no longer
  2188. constrained so they are optimized away.
  2189. Revision 1.131 2003/07/23 11:04:15 jonas
  2190. * split en_exit_code into a part that may allocate a register and a part
  2191. that doesn't, so the former can be done before the register colouring
  2192. has been performed
  2193. Revision 1.130 2003/07/06 17:58:22 peter
  2194. * framepointer fixes for sparc
  2195. * parent framepointer code more generic
  2196. Revision 1.129 2003/07/06 15:31:20 daniel
  2197. * Fixed register allocator. *Lots* of fixes.
  2198. Revision 1.128 2003/07/02 22:18:04 peter
  2199. * paraloc splitted in callerparaloc,calleeparaloc
  2200. * sparc calling convention updates
  2201. Revision 1.127 2003/06/17 18:13:51 jonas
  2202. * fixed -dnewra compilation problems
  2203. Revision 1.126 2003/06/17 16:32:44 peter
  2204. * alloc register for function result
  2205. Revision 1.125 2003/06/13 21:19:30 peter
  2206. * current_procdef removed, use current_procinfo.procdef instead
  2207. Revision 1.124 2003/06/09 12:23:30 peter
  2208. * init/final of procedure data splitted from genentrycode
  2209. * use asmnode getposition to insert final at the correct position
  2210. als for the implicit try...finally
  2211. Revision 1.123 2003/06/07 18:57:04 jonas
  2212. + added freeintparaloc
  2213. * ppc get/freeintparaloc now check whether the parameter regs are
  2214. properly allocated/deallocated (and get an extra list para)
  2215. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  2216. * fixed lot of missing pi_do_call's
  2217. Revision 1.122 2003/06/06 14:43:02 peter
  2218. * g_copyopenarrayvalue gets length reference
  2219. * don't copy open arrays for cdecl
  2220. Revision 1.121 2003/06/03 21:11:09 peter
  2221. * cg.a_load_* get a from and to size specifier
  2222. * makeregsize only accepts newregister
  2223. * i386 uses generic tcgnotnode,tcgunaryminus
  2224. Revision 1.120 2003/06/03 15:49:49 jonas
  2225. * fixed ref/loc problems
  2226. Revision 1.119 2003/06/03 15:06:37 daniel
  2227. * fixed conflict marks
  2228. Revision 1.118 2003/06/03 13:01:59 daniel
  2229. * Register allocator finished
  2230. Revision 1.117 2003/06/02 21:42:05 jonas
  2231. * function results can now also be regvars
  2232. - removed tprocinfo.return_offset, never use it again since it's invalid
  2233. if the result is a regvar
  2234. Revision 1.116 2003/06/01 21:38:06 peter
  2235. * getregisterfpu size parameter added
  2236. * op_const_reg size parameter added
  2237. * sparc updates
  2238. Revision 1.115 2003/05/31 20:28:17 jonas
  2239. * changed copyvalueparas so it also supports register parameters
  2240. (except for copy_value_openarray, but that one is seriously broken
  2241. anyway, since it expects that the high parameter will always be in
  2242. memory right after the pointer to the array, while it could just as
  2243. will be in a register)
  2244. Revision 1.114 2003/05/31 15:05:28 peter
  2245. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  2246. Revision 1.113 2003/05/31 00:48:15 jonas
  2247. * fixed my previous commit
  2248. Revision 1.112 2003/05/30 23:57:08 peter
  2249. * more sparc cleanup
  2250. * accumulator removed, splitted in function_return_reg (called) and
  2251. function_result_reg (caller)
  2252. Revision 1.111 2003/05/30 23:49:18 jonas
  2253. * a_load_loc_reg now has an extra size parameter for the destination
  2254. register (properly fixes what I worked around in revision 1.106 of
  2255. ncgutil.pas)
  2256. Revision 1.110 2003/05/30 18:52:10 jonas
  2257. * fixed bug with intregvars
  2258. * locapara.loc can also be LOC_CFPUREGISTER -> also fixed
  2259. rcgppc.a_param_ref, which previously got bogus size values
  2260. Revision 1.109 2003/05/27 21:19:08 jonas
  2261. * fixed ppc cycle
  2262. Revision 1.108 2003/05/27 14:28:14 jonas
  2263. * patch from Peter for nested procedures
  2264. Revision 1.107 2003/05/26 21:17:17 peter
  2265. * procinlinenode removed
  2266. * aktexit2label removed, fast exit removed
  2267. + tcallnode.inlined_pass_2 added
  2268. Revision 1.106 2003/05/24 11:59:42 jonas
  2269. * fixed integer typeconversion problems
  2270. Revision 1.105 2003/05/23 14:27:35 peter
  2271. * remove some unit dependencies
  2272. * current_procinfo changes to store more info
  2273. Revision 1.104 2003/05/15 18:58:53 peter
  2274. * removed selfpointer_offset, vmtpointer_offset
  2275. * tvarsym.adjusted_address
  2276. * address in localsymtable is now in the real direction
  2277. * removed some obsolete globals
  2278. Revision 1.103 2003/05/14 19:37:25 jonas
  2279. * patch from Peter for int64 function results
  2280. Revision 1.102 2003/05/13 19:14:41 peter
  2281. * failn removed
  2282. * inherited result code check moven to pexpr
  2283. Revision 1.101 2003/05/13 15:16:13 peter
  2284. * removed ret_in_acc, it's the reverse of ret_in_param
  2285. * fixed ret_in_param for win32 cdecl array
  2286. Revision 1.100 2003/05/12 08:08:27 jonas
  2287. * fixed several initialization and finalization related bugs (missing
  2288. tg.direction's, wrong paralocation for decreasing refcount of
  2289. everything but ansistrings)
  2290. Revision 1.99 2003/05/11 21:37:03 peter
  2291. * moved implicit exception frame from ncgutil to psub
  2292. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2293. Revision 1.98 2003/05/11 14:45:12 peter
  2294. * tloadnode does not support objectsymtable,withsymtable anymore
  2295. * withnode cleanup
  2296. * direct with rewritten to use temprefnode
  2297. Revision 1.97 2003/05/10 13:20:23 jonas
  2298. * moved storing of register parameters to memory even earlier in the
  2299. entry code to fix problems with constructors
  2300. Revision 1.96 2003/05/09 17:47:02 peter
  2301. * self moved to hidden parameter
  2302. * removed hdisposen,hnewn,selfn
  2303. Revision 1.95 2003/04/29 07:28:52 michael
  2304. + Patch from peter to fix wrong pushing of ansistring function results in open array
  2305. Revision 1.94 2003/04/28 21:17:38 peter
  2306. * do not finalize function results
  2307. Revision 1.93 2003/04/27 16:30:34 jonas
  2308. * store register para's to memory before copying the valuepara's, because
  2309. that one requires them to be there already (and it calls subroutines ->
  2310. could overwrite those registers)
  2311. Revision 1.92 2003/04/27 11:21:33 peter
  2312. * aktprocdef renamed to current_procinfo.procdef
  2313. * procinfo renamed to current_procinfo
  2314. * procinfo will now be stored in current_module so it can be
  2315. cleaned up properly
  2316. * gen_main_procsym changed to create_main_proc and release_main_proc
  2317. to also generate a tprocinfo structure
  2318. * fixed unit implicit initfinal
  2319. Revision 1.91 2003/04/27 07:29:50 peter
  2320. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  2321. a new procdef declaration
  2322. * aktprocsym removed
  2323. * lexlevel removed, use symtable.symtablelevel instead
  2324. * implicit init/final code uses the normal genentry/genexit
  2325. * funcret state checking updated for new funcret handling
  2326. Revision 1.90 2003/04/26 17:21:08 florian
  2327. * fixed passing of fpu values by fpu register
  2328. Revision 1.89 2003/04/25 20:59:33 peter
  2329. * removed funcretn,funcretsym, function result is now in varsym
  2330. and aliases for result and function name are added using absolutesym
  2331. * vs_hidden parameter for funcret passed in parameter
  2332. * vs_hidden fixes
  2333. * writenode changed to printnode and released from extdebug
  2334. * -vp option added to generate a tree.log with the nodetree
  2335. * nicer printnode for statements, callnode
  2336. Revision 1.88 2003/04/23 12:35:34 florian
  2337. * fixed several issues with powerpc
  2338. + applied a patch from Jonas for nested function calls (PowerPC only)
  2339. * ...
  2340. Revision 1.87 2003/04/22 14:33:38 peter
  2341. * removed some notes/hints
  2342. Revision 1.86 2003/04/22 13:47:08 peter
  2343. * fixed C style array of const
  2344. * fixed C array passing
  2345. * fixed left to right with high parameters
  2346. Revision 1.85 2003/04/22 10:09:35 daniel
  2347. + Implemented the actual register allocator
  2348. + Scratch registers unavailable when new register allocator used
  2349. + maybe_save/maybe_restore unavailable when new register allocator used
  2350. Revision 1.84 2003/04/16 09:26:55 jonas
  2351. * assembler procedures now again get a stackframe if they have local
  2352. variables. No space is reserved for a function result however.
  2353. Also, the register parameters aren't automatically saved on the stack
  2354. anymore in assembler procedures.
  2355. Revision 1.83 2003/04/06 21:11:23 olle
  2356. * changed newasmsymbol to newasmsymboldata for data symbols
  2357. Revision 1.82 2003/03/30 20:59:07 peter
  2358. * fix classmethod from classmethod call
  2359. * move BeforeDestruction/AfterConstruction calls to
  2360. genentrycode/genexitcode instead of generating them on the fly
  2361. after a call to a constructor
  2362. Revision 1.81 2003/03/28 19:16:56 peter
  2363. * generic constructor working for i386
  2364. * remove fixed self register
  2365. * esi added as address register for i386
  2366. Revision 1.80 2003/03/17 15:52:20 peter
  2367. * fix range error
  2368. Revision 1.79 2003/03/11 21:46:24 jonas
  2369. * lots of new regallocator fixes, both in generic and ppc-specific code
  2370. (ppc compiler still can't compile the linux system unit though)
  2371. Revision 1.78 2003/02/26 21:15:43 daniel
  2372. * Fixed the optimizer
  2373. Revision 1.77 2003/02/19 22:00:14 daniel
  2374. * Code generator converted to new register notation
  2375. - Horribily outdated todo.txt removed
  2376. Revision 1.76 2003/02/15 22:17:38 carl
  2377. * bugfix of FPU emulation code
  2378. Revision 1.75 2003/01/09 22:00:53 florian
  2379. * fixed some PowerPC issues
  2380. Revision 1.74 2003/01/09 20:41:10 florian
  2381. * fixed broken PowerPC compiler
  2382. Revision 1.73 2003/01/08 18:43:56 daniel
  2383. * Tregister changed into a record
  2384. Revision 1.72 2002/12/29 23:51:43 florian
  2385. * web bug 2214 fixed: ie 10 in const array constructors
  2386. Revision 1.71 2002/12/24 15:56:50 peter
  2387. * stackpointer_alloc added for adjusting ESP. Win32 needs
  2388. this for the pageprotection
  2389. Revision 1.70 2002/12/05 14:39:21 florian
  2390. * added missing then, Carl did you really a make fullcycle :) ?
  2391. Revision 1.69 2002/12/03 22:13:39 carl
  2392. * bugfix of problems with profile code which clobbers some registers
  2393. Revision 1.68 2002/12/01 22:06:59 carl
  2394. * warning of portabilitiy problems with parasize / localsize
  2395. Revision 1.67 2002/11/30 18:44:57 carl
  2396. + profiling support for Win32
  2397. Revision 1.66 2002/11/30 14:39:15 carl
  2398. * try to fix profiling for win32
  2399. Revision 1.65 2002/11/28 23:28:14 florian
  2400. * push_value_para didn't release floatdef locations, fixes tw2045
  2401. Revision 1.64 2002/11/27 02:33:19 peter
  2402. * copy_value_on_stack method added for cdecl record passing
  2403. Revision 1.63 2002/11/25 17:43:18 peter
  2404. * splitted defbase in defutil,symutil,defcmp
  2405. * merged isconvertable and is_equal into compare_defs(_ext)
  2406. * made operator search faster by walking the list only once
  2407. Revision 1.62 2002/11/18 17:31:55 peter
  2408. * pass proccalloption to ret_in_xxx and push_xxx functions
  2409. Revision 1.61 2002/11/17 17:49:08 mazen
  2410. + return_result_reg and FUNCTION_RESULT_REG are now used, in all plateforms, to pass functions result between called function and its caller. See the explanation of each one
  2411. Revision 1.60 2002/11/17 16:31:56 carl
  2412. * memory optimization (3-4%) : cleanup of tai fields,
  2413. cleanup of tdef and tsym fields.
  2414. * make it work for m68k
  2415. Revision 1.59 2002/11/15 01:58:51 peter
  2416. * merged changes from 1.0.7 up to 04-11
  2417. - -V option for generating bug report tracing
  2418. - more tracing for option parsing
  2419. - errors for cdecl and high()
  2420. - win32 import stabs
  2421. - win32 records<=8 are returned in eax:edx (turned off by default)
  2422. - heaptrc update
  2423. - more info for temp management in .s file with EXTDEBUG
  2424. Revision 1.58 2002/11/10 19:07:45 mazen
  2425. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  2426. Revision 1.57 2002/11/03 20:22:40 mazen
  2427. * parameter handling updated
  2428. Revision 1.56 2002/10/16 19:01:43 peter
  2429. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  2430. implicit exception frames for procedures with initialized variables
  2431. and for constructors. The default is on for compatibility
  2432. Revision 1.55 2002/10/14 19:42:33 peter
  2433. * only use init tables for threadvars
  2434. Revision 1.54 2002/10/06 19:41:30 peter
  2435. * Add finalization of typed consts
  2436. * Finalization of globals in the main program
  2437. Revision 1.53 2002/10/05 15:18:42 carl
  2438. * fix heap leaks
  2439. Revision 1.52 2002/09/30 07:00:46 florian
  2440. * fixes to common code to get the alpha compiler compiled applied
  2441. Revision 1.51 2002/09/22 14:02:35 carl
  2442. * stack checking cannot be called before system unit is initialized
  2443. * MC68020 define
  2444. Revision 1.50 2002/09/17 18:54:03 jonas
  2445. * a_load_reg_reg() now has two size parameters: source and dest. This
  2446. allows some optimizations on architectures that don't encode the
  2447. register size in the register name.
  2448. Revision 1.49 2002/09/10 21:48:30 florian
  2449. * improved handling of procedures with register calling conventions
  2450. Revision 1.48 2002/09/07 15:25:03 peter
  2451. * old logs removed and tabs fixed
  2452. Revision 1.47 2002/09/02 18:44:48 peter
  2453. * fixed (not) pushing of empty parameters
  2454. * fixed implicit initialization/finalization generation
  2455. * fixed/optimized local copy of value arguments init/final
  2456. Revision 1.46 2002/09/01 19:27:34 peter
  2457. * use index register when available for generating a reference with
  2458. only a signle register. Using the base register could possibly
  2459. destroy the framepointer
  2460. Revision 1.45 2002/09/01 18:50:20 peter
  2461. * fixed maybe_save that did not support a reference with only
  2462. a index register. It now also updates the location with the new
  2463. base register only
  2464. Revision 1.44 2002/09/01 14:42:41 peter
  2465. * removevaluepara added to fix the stackpointer so restoring of
  2466. saved registers works
  2467. Revision 1.43 2002/08/25 19:25:18 peter
  2468. * sym.insert_in_data removed
  2469. * symtable.insertvardata/insertconstdata added
  2470. * removed insert_in_data call from symtable.insert, it needs to be
  2471. called separatly. This allows to deref the address calculation
  2472. * procedures now calculate the parast addresses after the procedure
  2473. directives are parsed. This fixes the cdecl parast problem
  2474. * push_addr_param has an extra argument that specifies if cdecl is used
  2475. or not
  2476. Revision 1.42 2002/08/24 18:38:26 peter
  2477. * really use tt_noreuse for exception frame buffers
  2478. Revision 1.41 2002/08/23 16:14:49 peter
  2479. * tempgen cleanup
  2480. * tt_noreuse temp type added that will be used in genentrycode
  2481. Revision 1.40 2002/08/18 10:42:37 florian
  2482. * remaining assembler writer bugs fixed, the errors in the
  2483. system unit are inline assembler problems
  2484. Revision 1.39 2002/08/17 09:23:36 florian
  2485. * first part of procinfo rewrite
  2486. Revision 1.38 2002/08/16 14:24:57 carl
  2487. * issameref() to test if two references are the same (then emit no opcodes)
  2488. + ret_in_reg to replace ret_in_acc
  2489. (fix some register allocation bugs at the same time)
  2490. + save_std_register now has an extra parameter which is the
  2491. usedinproc registers
  2492. Revision 1.37 2002/08/15 15:15:55 carl
  2493. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  2494. * more generic nodes for maths
  2495. * several fixes for better m68k support
  2496. Revision 1.36 2002/08/14 19:25:09 carl
  2497. * fix Florian's last commit for m68k compilation
  2498. Revision 1.35 2002/08/13 21:40:56 florian
  2499. * more fixes for ppc calling conventions
  2500. Revision 1.34 2002/08/12 15:08:39 carl
  2501. + stab register indexes for powerpc (moved from gdb to cpubase)
  2502. + tprocessor enumeration moved to cpuinfo
  2503. + linker in target_info is now a class
  2504. * many many updates for m68k (will soon start to compile)
  2505. - removed some ifdef or correct them for correct cpu
  2506. Revision 1.33 2002/08/11 14:32:27 peter
  2507. * renamed current_library to objectlibrary
  2508. Revision 1.32 2002/08/11 13:24:12 peter
  2509. * saving of asmsymbols in ppu supported
  2510. * asmsymbollist global is removed and moved into a new class
  2511. tasmlibrarydata that will hold the info of a .a file which
  2512. corresponds with a single module. Added librarydata to tmodule
  2513. to keep the library info stored for the module. In the future the
  2514. objectfiles will also be stored to the tasmlibrarydata class
  2515. * all getlabel/newasmsymbol and friends are moved to the new class
  2516. Revision 1.31 2002/08/09 19:16:57 carl
  2517. * stack allocation is now done separately (at the end) of genentrycode
  2518. so temps. can be allocated before.
  2519. * fix generic exception handling
  2520. Revision 1.30 2002/08/06 20:55:21 florian
  2521. * first part of ppc calling conventions fix
  2522. Revision 1.29 2002/08/04 19:09:22 carl
  2523. + added generic exception support (still does not work!)
  2524. + more documentation
  2525. Revision 1.28 2002/07/29 21:23:42 florian
  2526. * more fixes for the ppc
  2527. + wrappers for the tcnvnode.first_* stuff introduced
  2528. }