ncgutil.pas 110 KB

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