ncgutil.pas 112 KB

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