ncgutil.pas 111 KB

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