ncgutil.pas 111 KB

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