ncgutil.pas 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322
  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,parabase,
  25. aasmbase,aasmtai,aasmcpu,
  26. symconst,symbase,symdef,symsym,symtype,symtable
  27. {$ifndef cpu64bit}
  28. ,cg64f32
  29. {$endif cpu64bit}
  30. ;
  31. type
  32. tloadregvars = (lr_dont_load_regvars, lr_load_regvars);
  33. procedure firstcomplex(p : tbinarynode);
  34. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  35. // procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  36. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  37. procedure location_force_fpureg(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  38. procedure location_force_mem(list:TAAsmoutput;var l:tlocation);
  39. procedure location_force_mmregscalar(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  40. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  41. procedure gen_proc_symbol(list:Taasmoutput);
  42. procedure gen_proc_symbol_end(list:Taasmoutput);
  43. procedure gen_proc_entry_code(list:Taasmoutput);
  44. procedure gen_proc_exit_code(list:Taasmoutput);
  45. procedure gen_save_used_regs(list:TAAsmoutput);
  46. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tcgpara);
  47. procedure gen_initialize_code(list:TAAsmoutput);
  48. procedure gen_finalize_code(list:TAAsmoutput);
  49. procedure gen_entry_code(list:TAAsmoutput);
  50. procedure gen_exit_code(list:TAAsmoutput);
  51. procedure gen_load_para_value(list:TAAsmoutput);
  52. procedure gen_load_return_value(list:TAAsmoutput);
  53. {#
  54. Allocate the buffers for exception management and setjmp environment.
  55. Return a pointer to these buffers, send them to the utility routine
  56. so they are registered, and then call setjmp.
  57. Then compare the result of setjmp with 0, and if not equal
  58. to zero, then jump to exceptlabel.
  59. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  60. It is to note that this routine may be called *after* the stackframe of a
  61. routine has been called, therefore on machines where the stack cannot
  62. be modified, all temps should be allocated on the heap instead of the
  63. stack.
  64. }
  65. const
  66. EXCEPT_BUF_SIZE = 3*sizeof(aint);
  67. type
  68. texceptiontemps=record
  69. jmpbuf,
  70. envbuf,
  71. reasonbuf : treference;
  72. end;
  73. procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
  74. procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
  75. procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aint;exceptlabel:tasmlabel);
  76. procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  77. procedure insertconstdata(sym : ttypedconstsym);
  78. procedure insertbssdata(sym : tvarsym);
  79. procedure gen_alloc_symtable(list:TAAsmoutput;st:tsymtable);
  80. procedure gen_free_symtable(list:TAAsmoutput;st:tsymtable);
  81. procedure gen_alloc_inline_parast(list:TAAsmoutput;pd:tprocdef);
  82. procedure gen_alloc_inline_funcret(list:TAAsmoutput;pd:tprocdef);
  83. { rtti and init/final }
  84. procedure generate_rtti(p:Ttypesym);
  85. procedure generate_inittable(p:tsym);
  86. implementation
  87. uses
  88. {$ifdef Delphi}
  89. Sysutils,
  90. {$else}
  91. strings,
  92. {$endif}
  93. cutils,cclasses,
  94. globals,systems,verbose,
  95. ppu,defutil,
  96. procinfo,paramgr,fmodule,
  97. regvars,dwarf,
  98. {$ifdef GDB}
  99. gdb,
  100. {$endif GDB}
  101. pass_1,pass_2,
  102. ncon,nld,nutils,
  103. tgobj,cgutils,cgobj;
  104. {*****************************************************************************
  105. Misc Helpers
  106. *****************************************************************************}
  107. { DO NOT RELY on the fact that the tnode is not yet swaped
  108. because of inlining code PM }
  109. procedure firstcomplex(p : tbinarynode);
  110. var
  111. hp : tnode;
  112. begin
  113. { always calculate boolean AND and OR from left to right }
  114. if (p.nodetype in [orn,andn]) and
  115. is_boolean(p.left.resulttype.def) then
  116. begin
  117. if nf_swaped in p.flags then
  118. internalerror(234234);
  119. end
  120. else
  121. if (
  122. (p.location.loc=LOC_FPUREGISTER) and
  123. (p.right.registersfpu > p.left.registersfpu)
  124. ) or
  125. (
  126. (
  127. (
  128. ((p.left.registersfpu = 0) and (p.right.registersfpu = 0)) or
  129. (p.location.loc<>LOC_FPUREGISTER)
  130. ) and
  131. (p.left.registersint<p.right.registersint)
  132. )
  133. ) then
  134. begin
  135. hp:=p.left;
  136. p.left:=p.right;
  137. p.right:=hp;
  138. if nf_swaped in p.flags then
  139. exclude(p.flags,nf_swaped)
  140. else
  141. include(p.flags,nf_swaped);
  142. end;
  143. end;
  144. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  145. {
  146. produces jumps to true respectively false labels using boolean expressions
  147. depending on whether the loading of regvars is currently being
  148. synchronized manually (such as in an if-node) or automatically (most of
  149. the other cases where this procedure is called), loadregvars can be
  150. "lr_load_regvars" or "lr_dont_load_regvars"
  151. }
  152. var
  153. opsize : tcgsize;
  154. storepos : tfileposinfo;
  155. begin
  156. if nf_error in p.flags then
  157. exit;
  158. storepos:=aktfilepos;
  159. aktfilepos:=p.fileinfo;
  160. if is_boolean(p.resulttype.def) then
  161. begin
  162. {$ifdef OLDREGVARS}
  163. if loadregvars = lr_load_regvars then
  164. load_all_regvars(list);
  165. {$endif OLDREGVARS}
  166. if is_constboolnode(p) then
  167. begin
  168. if tordconstnode(p).value<>0 then
  169. cg.a_jmp_always(list,truelabel)
  170. else
  171. cg.a_jmp_always(list,falselabel)
  172. end
  173. else
  174. begin
  175. opsize:=def_cgsize(p.resulttype.def);
  176. case p.location.loc of
  177. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  178. begin
  179. {$ifdef OLDREGVARS}
  180. if (p.location.loc = LOC_CREGISTER) then
  181. load_regvar_reg(list,p.location.register);
  182. {$endif OLDREGVARS}
  183. cg.a_cmp_const_loc_label(list,opsize,OC_NE,0,p.location,truelabel);
  184. cg.a_jmp_always(list,falselabel);
  185. end;
  186. LOC_JUMP:
  187. ;
  188. {$ifdef cpuflags}
  189. LOC_FLAGS :
  190. begin
  191. cg.a_jmp_flags(list,p.location.resflags,truelabel);
  192. cg.a_jmp_always(list,falselabel);
  193. end;
  194. {$endif cpuflags}
  195. else
  196. begin
  197. printnode(output,p);
  198. internalerror(200308241);
  199. end;
  200. end;
  201. end;
  202. end
  203. else
  204. internalerror(200112305);
  205. aktfilepos:=storepos;
  206. end;
  207. (*
  208. This code needs fixing. It is not safe to use rgint; on the m68000 it
  209. would be rgaddr.
  210. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  211. begin
  212. case t.loc of
  213. LOC_REGISTER:
  214. begin
  215. { can't be a regvar, since it would be LOC_CREGISTER then }
  216. exclude(regs,getsupreg(t.register));
  217. if t.registerhigh<>NR_NO then
  218. exclude(regs,getsupreg(t.registerhigh));
  219. end;
  220. LOC_CREFERENCE,LOC_REFERENCE:
  221. begin
  222. if not(cs_regvars in aktglobalswitches) or
  223. (getsupreg(t.reference.base) in cg.rgint.usableregs) then
  224. exclude(regs,getsupreg(t.reference.base));
  225. if not(cs_regvars in aktglobalswitches) or
  226. (getsupreg(t.reference.index) in cg.rgint.usableregs) then
  227. exclude(regs,getsupreg(t.reference.index));
  228. end;
  229. end;
  230. end;
  231. *)
  232. {*****************************************************************************
  233. EXCEPTION MANAGEMENT
  234. *****************************************************************************}
  235. procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
  236. begin
  237. tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,t.envbuf);
  238. tg.GetTemp(list,JMP_BUF_SIZE,tt_persistent,t.jmpbuf);
  239. tg.GetTemp(list,sizeof(aint),tt_persistent,t.reasonbuf);
  240. end;
  241. procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
  242. begin
  243. tg.Ungettemp(list,t.jmpbuf);
  244. tg.ungettemp(list,t.envbuf);
  245. tg.ungettemp(list,t.reasonbuf);
  246. end;
  247. procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aint;exceptlabel:tasmlabel);
  248. var
  249. paraloc1,paraloc2,paraloc3 : tcgpara;
  250. begin
  251. paraloc1.init;
  252. paraloc2.init;
  253. paraloc3.init;
  254. paramanager.getintparaloc(pocall_default,1,paraloc1);
  255. paramanager.getintparaloc(pocall_default,2,paraloc2);
  256. paramanager.getintparaloc(pocall_default,3,paraloc3);
  257. paramanager.allocparaloc(list,paraloc3);
  258. cg.a_paramaddr_ref(list,t.envbuf,paraloc3);
  259. paramanager.allocparaloc(list,paraloc2);
  260. cg.a_paramaddr_ref(list,t.jmpbuf,paraloc2);
  261. { push type of exceptionframe }
  262. paramanager.allocparaloc(list,paraloc1);
  263. cg.a_param_const(list,OS_S32,1,paraloc1);
  264. paramanager.freeparaloc(list,paraloc3);
  265. paramanager.freeparaloc(list,paraloc2);
  266. paramanager.freeparaloc(list,paraloc1);
  267. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  268. cg.a_call_name(list,'FPC_PUSHEXCEPTADDR');
  269. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  270. paramanager.getintparaloc(pocall_default,1,paraloc1);
  271. paramanager.allocparaloc(list,paraloc1);
  272. cg.a_param_reg(list,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  273. paramanager.freeparaloc(list,paraloc1);
  274. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  275. cg.a_call_name(list,'FPC_SETJMP');
  276. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  277. cg.g_exception_reason_save(list, t.reasonbuf);
  278. cg.a_cmp_const_reg_label(list,OS_S32,OC_NE,0,cg.makeregsize(list,NR_FUNCTION_RESULT_REG,OS_S32),exceptlabel);
  279. paraloc1.done;
  280. paraloc2.done;
  281. paraloc3.done;
  282. end;
  283. procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  284. begin
  285. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  286. cg.a_call_name(list,'FPC_POPADDRSTACK');
  287. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  288. if not onlyfree then
  289. begin
  290. cg.g_exception_reason_load(list, t.reasonbuf);
  291. cg.a_cmp_const_reg_label(list,OS_INT,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
  292. end;
  293. end;
  294. {*****************************************************************************
  295. TLocation
  296. *****************************************************************************}
  297. {$ifndef cpu64bit}
  298. { 32-bit version }
  299. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  300. var
  301. hregister,
  302. hregisterhi : tregister;
  303. hreg64 : tregister64;
  304. hl : tasmlabel;
  305. oldloc : tlocation;
  306. const_location: boolean;
  307. begin
  308. oldloc:=l;
  309. if dst_size=OS_NO then
  310. internalerror(200309144);
  311. { handle transformations to 64bit separate }
  312. if dst_size in [OS_64,OS_S64] then
  313. begin
  314. if not (l.size in [OS_64,OS_S64]) then
  315. begin
  316. { load a smaller size to OS_64 }
  317. if l.loc=LOC_REGISTER then
  318. begin
  319. hregister:=cg.makeregsize(list,l.registerlow,OS_32);
  320. cg.a_load_reg_reg(list,l.size,OS_32,l.registerlow,hregister);
  321. end
  322. else
  323. hregister:=cg.getintregister(list,OS_INT);
  324. { load value in low register }
  325. case l.loc of
  326. LOC_FLAGS :
  327. cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
  328. LOC_JUMP :
  329. begin
  330. cg.a_label(list,truelabel);
  331. cg.a_load_const_reg(list,OS_INT,1,hregister);
  332. objectlibrary.getlabel(hl);
  333. cg.a_jmp_always(list,hl);
  334. cg.a_label(list,falselabel);
  335. cg.a_load_const_reg(list,OS_INT,0,hregister);
  336. cg.a_label(list,hl);
  337. end;
  338. else
  339. cg.a_load_loc_reg(list,OS_INT,l,hregister);
  340. end;
  341. { reset hi part, take care of the signed bit of the current value }
  342. hregisterhi:=cg.getintregister(list,OS_INT);
  343. if (l.size in [OS_S8,OS_S16,OS_S32]) then
  344. begin
  345. if l.loc=LOC_CONSTANT then
  346. begin
  347. if (longint(l.value)<0) then
  348. cg.a_load_const_reg(list,OS_32,aint($ffffffff),hregisterhi)
  349. else
  350. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  351. end
  352. else
  353. begin
  354. cg.a_op_const_reg_reg(list,OP_SAR,OS_32,31,hregister,
  355. hregisterhi);
  356. end;
  357. end
  358. else
  359. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  360. location_reset(l,LOC_REGISTER,dst_size);
  361. l.registerlow:=hregister;
  362. l.registerhigh:=hregisterhi;
  363. end
  364. else
  365. begin
  366. { 64bit to 64bit }
  367. if (l.loc=LOC_REGISTER) or
  368. ((l.loc=LOC_CREGISTER) and maybeconst) then
  369. begin
  370. hregister:=l.registerlow;
  371. hregisterhi:=l.registerhigh;
  372. end
  373. else
  374. begin
  375. hregister:=cg.getintregister(list,OS_INT);
  376. hregisterhi:=cg.getintregister(list,OS_INT);
  377. end;
  378. hreg64.reglo:=hregister;
  379. hreg64.reghi:=hregisterhi;
  380. { load value in new register }
  381. cg64.a_load64_loc_reg(list,l,hreg64);
  382. location_reset(l,LOC_REGISTER,dst_size);
  383. l.registerlow:=hregister;
  384. l.registerhigh:=hregisterhi;
  385. end;
  386. end
  387. else
  388. begin
  389. {Do not bother to recycle the existing register. The register
  390. allocator eliminates unnecessary moves, so it's not needed
  391. and trying to recycle registers can cause problems because
  392. the registers changes size and may need aditional constraints.
  393. Not if it's about LOC_CREGISTER's (JM)
  394. }
  395. const_location :=
  396. (maybeconst) and
  397. (l.loc = LOC_CREGISTER) and
  398. (TCGSize2Size[l.size] = TCGSize2Size[dst_size]) and
  399. ((l.size = dst_size) or
  400. (TCGSize2Size[l.size] = TCGSize2Size[OS_INT]));
  401. if not const_location then
  402. hregister:=cg.getintregister(list,dst_size)
  403. else
  404. hregister := l.register;
  405. { load value in new register }
  406. case l.loc of
  407. LOC_FLAGS :
  408. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  409. LOC_JUMP :
  410. begin
  411. cg.a_label(list,truelabel);
  412. cg.a_load_const_reg(list,dst_size,1,hregister);
  413. objectlibrary.getlabel(hl);
  414. cg.a_jmp_always(list,hl);
  415. cg.a_label(list,falselabel);
  416. cg.a_load_const_reg(list,dst_size,0,hregister);
  417. cg.a_label(list,hl);
  418. end;
  419. else
  420. begin
  421. { load_loc_reg can only handle size >= l.size, when the
  422. new size is smaller then we need to adjust the size
  423. of the orignal and maybe recalculate l.register for i386 }
  424. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  425. begin
  426. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  427. l.register:=cg.makeregsize(list,l.register,dst_size);
  428. { for big endian systems, the reference's offset must }
  429. { be increased in this case, since they have the }
  430. { MSB first in memory and e.g. byte(word_var) should }
  431. { return the second byte in this case (JM) }
  432. if (target_info.endian = ENDIAN_BIG) and
  433. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  434. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  435. {$ifdef x86}
  436. l.size:=dst_size;
  437. {$endif x86}
  438. end;
  439. cg.a_load_loc_reg(list,dst_size,l,hregister);
  440. {$ifndef x86}
  441. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  442. l.size:=dst_size;
  443. {$endif not x86}
  444. end;
  445. end;
  446. if not const_location then
  447. location_reset(l,LOC_REGISTER,dst_size)
  448. else
  449. location_reset(l,LOC_CREGISTER,dst_size);
  450. l.register:=hregister;
  451. end;
  452. { Release temp when it was a reference }
  453. if oldloc.loc=LOC_REFERENCE then
  454. location_freetemp(list,oldloc);
  455. end;
  456. {$else cpu64bit}
  457. { 64-bit version }
  458. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  459. var
  460. hregister : tregister;
  461. hl : tasmlabel;
  462. oldloc : tlocation;
  463. begin
  464. oldloc:=l;
  465. hregister:=cg.getintregister(list,dst_size);
  466. { load value in new register }
  467. case l.loc of
  468. LOC_FLAGS :
  469. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  470. LOC_JUMP :
  471. begin
  472. cg.a_label(list,truelabel);
  473. cg.a_load_const_reg(list,dst_size,1,hregister);
  474. objectlibrary.getlabel(hl);
  475. cg.a_jmp_always(list,hl);
  476. cg.a_label(list,falselabel);
  477. cg.a_load_const_reg(list,dst_size,0,hregister);
  478. cg.a_label(list,hl);
  479. end;
  480. else
  481. begin
  482. { load_loc_reg can only handle size >= l.size, when the
  483. new size is smaller then we need to adjust the size
  484. of the orignal and maybe recalculate l.register for i386 }
  485. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  486. begin
  487. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  488. l.register:=cg.makeregsize(list,l.register,dst_size);
  489. { for big endian systems, the reference's offset must }
  490. { be increased in this case, since they have the }
  491. { MSB first in memory and e.g. byte(word_var) should }
  492. { return the second byte in this case (JM) }
  493. if (target_info.endian = ENDIAN_BIG) and
  494. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  495. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  496. {$ifdef x86}
  497. l.size:=dst_size;
  498. {$endif x86}
  499. end;
  500. cg.a_load_loc_reg(list,dst_size,l,hregister);
  501. {$ifndef x86}
  502. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  503. l.size:=dst_size;
  504. {$endif not x86}
  505. end;
  506. end;
  507. if (l.loc <> LOC_CREGISTER) or
  508. not maybeconst then
  509. location_reset(l,LOC_REGISTER,dst_size)
  510. else
  511. location_reset(l,LOC_CREGISTER,dst_size);
  512. l.register:=hregister;
  513. { Release temp when it was a reference }
  514. if oldloc.loc=LOC_REFERENCE then
  515. location_freetemp(list,oldloc);
  516. end;
  517. {$endif cpu64bit}
  518. procedure location_force_fpureg(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  519. var
  520. reg : tregister;
  521. href : treference;
  522. begin
  523. if (l.loc<>LOC_FPUREGISTER) and
  524. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  525. begin
  526. { if it's in an mm register, store to memory first }
  527. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  528. begin
  529. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  530. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
  531. location_reset(l,LOC_REFERENCE,l.size);
  532. l.reference:=href;
  533. end;
  534. reg:=cg.getfpuregister(list,l.size);
  535. cg.a_loadfpu_loc_reg(list,l,reg);
  536. location_freetemp(list,l);
  537. location_reset(l,LOC_FPUREGISTER,l.size);
  538. l.register:=reg;
  539. end;
  540. end;
  541. procedure location_force_mmregscalar(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  542. var
  543. reg : tregister;
  544. href : treference;
  545. begin
  546. if (l.loc<>LOC_MMREGISTER) and
  547. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  548. begin
  549. { if it's in an fpu register, store to memory first }
  550. if (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  551. begin
  552. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  553. cg.a_loadfpu_reg_ref(list,l.size,l.register,href);
  554. location_reset(l,LOC_REFERENCE,l.size);
  555. l.reference:=href;
  556. end;
  557. reg:=cg.getmmregister(list,l.size);
  558. cg.a_loadmm_loc_reg(list,l.size,l,reg,mms_movescalar);
  559. location_freetemp(list,l);
  560. location_reset(l,LOC_MMREGISTER,l.size);
  561. l.register:=reg;
  562. end;
  563. end;
  564. procedure location_force_mem(list:TAAsmoutput;var l:tlocation);
  565. var
  566. r : treference;
  567. begin
  568. case l.loc of
  569. LOC_FPUREGISTER,
  570. LOC_CFPUREGISTER :
  571. begin
  572. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  573. cg.a_loadfpu_reg_ref(list,l.size,l.register,r);
  574. location_reset(l,LOC_REFERENCE,l.size);
  575. l.reference:=r;
  576. end;
  577. LOC_MMREGISTER,
  578. LOC_CMMREGISTER:
  579. begin
  580. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  581. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  582. location_reset(l,LOC_REFERENCE,l.size);
  583. l.reference:=r;
  584. end;
  585. LOC_CONSTANT,
  586. LOC_REGISTER,
  587. LOC_CREGISTER :
  588. begin
  589. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  590. {$ifndef cpu64bit}
  591. if l.size in [OS_64,OS_S64] then
  592. cg64.a_load64_loc_ref(list,l,r)
  593. else
  594. {$endif cpu64bit}
  595. cg.a_load_loc_ref(list,l.size,l,r);
  596. location_reset(l,LOC_REFERENCE,l.size);
  597. l.reference:=r;
  598. end;
  599. LOC_CREFERENCE,
  600. LOC_REFERENCE : ;
  601. else
  602. internalerror(200203219);
  603. end;
  604. end;
  605. {*****************************************************************************
  606. Maybe_Save
  607. *****************************************************************************}
  608. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  609. begin
  610. {$ifdef i386}
  611. if (needed>=maxfpuregs) and
  612. (l.loc = LOC_FPUREGISTER) then
  613. begin
  614. location_force_mem(list,l);
  615. maybe_pushfpu:=true;
  616. end
  617. else
  618. maybe_pushfpu:=false;
  619. {$else i386}
  620. maybe_pushfpu:=false;
  621. {$endif i386}
  622. end;
  623. {****************************************************************************
  624. Init/Finalize Code
  625. ****************************************************************************}
  626. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  627. var
  628. href1 : treference;
  629. list:TAAsmoutput;
  630. hsym : tvarsym;
  631. l : longint;
  632. loadref : boolean;
  633. localcopyloc : tlocation;
  634. begin
  635. list:=taasmoutput(arg);
  636. if (tsym(p).typ=varsym) and
  637. (tvarsym(p).varspez=vs_value) and
  638. (paramanager.push_addr_param(tvarsym(p).varspez,tvarsym(p).vartype.def,current_procinfo.procdef.proccalloption)) then
  639. begin
  640. loadref:=true;
  641. case tvarsym(p).localloc.loc of
  642. LOC_CREGISTER :
  643. begin
  644. reference_reset_base(href1,tvarsym(p).localloc.register,0);
  645. loadref:=false;
  646. end;
  647. LOC_REFERENCE :
  648. href1:=tvarsym(p).localloc.reference;
  649. else
  650. internalerror(200309181);
  651. end;
  652. if is_open_array(tvarsym(p).vartype.def) or
  653. is_array_of_const(tvarsym(p).vartype.def) then
  654. begin
  655. { cdecl functions don't have a high pointer so it is not possible to generate
  656. a local copy }
  657. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  658. begin
  659. hsym:=tvarsym(tsym(p).owner.search('high'+p.name));
  660. if not assigned(hsym) then
  661. internalerror(200306061);
  662. cg.g_copyvaluepara_openarray(list,href1,hsym.localloc,tarraydef(tvarsym(p).vartype.def).elesize,loadref);
  663. end;
  664. end
  665. else
  666. begin
  667. { Allocate space for the local copy }
  668. l:=tvarsym(p).getsize;
  669. localcopyloc.loc:=LOC_REFERENCE;
  670. localcopyloc.size:=int_cgsize(l);
  671. tg.GetLocal(list,l,tvarsym(p).vartype.def,localcopyloc.reference);
  672. { Copy data }
  673. if is_shortstring(tvarsym(p).vartype.def) then
  674. begin
  675. { this code is only executed before the code for the body and the entry/exit code is generated
  676. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  677. }
  678. include(current_procinfo.flags,pi_do_call);
  679. cg.g_copyshortstring(list,href1,localcopyloc.reference,tstringdef(tvarsym(p).vartype.def).len,loadref)
  680. end
  681. else
  682. cg.g_concatcopy(list,href1,localcopyloc.reference,tvarsym(p).vartype.def.size,loadref);
  683. { update localloc of varsym }
  684. tg.Ungetlocal(list,tvarsym(p).localloc.reference);
  685. tvarsym(p).localloc:=localcopyloc;
  686. end;
  687. end;
  688. end;
  689. { initializes the regvars from staticsymtable with 0 }
  690. procedure initialize_regvars(p : tnamedindexitem;arg:pointer);
  691. var
  692. oldexprasmlist : TAAsmoutput;
  693. hp : tnode;
  694. begin
  695. if (tsym(p).typ=varsym) then
  696. begin
  697. case tvarsym(p).localloc.loc of
  698. LOC_CREGISTER :
  699. cg.a_load_const_reg(taasmoutput(arg),reg_cgsize(tvarsym(p).localloc.register),0,tvarsym(p).localloc.register);
  700. LOC_REFERENCE : ;
  701. else
  702. internalerror(200410124);
  703. end;
  704. end;
  705. end;
  706. { generates the code for initialisation of local data }
  707. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  708. var
  709. oldexprasmlist : TAAsmoutput;
  710. hp : tnode;
  711. begin
  712. if (tsym(p).typ=varsym) and
  713. (tvarsym(p).refs>0) and
  714. not(is_class(tvarsym(p).vartype.def)) and
  715. tvarsym(p).vartype.def.needs_inittable then
  716. begin
  717. oldexprasmlist:=exprasmlist;
  718. exprasmlist:=taasmoutput(arg);
  719. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  720. firstpass(hp);
  721. secondpass(hp);
  722. hp.free;
  723. exprasmlist:=oldexprasmlist;
  724. end;
  725. end;
  726. procedure finalize_sym(asmlist:taasmoutput;sym:tsym);
  727. var
  728. hp : tnode;
  729. oldexprasmlist : TAAsmoutput;
  730. begin
  731. include(current_procinfo.flags,pi_needs_implicit_finally);
  732. oldexprasmlist:=exprasmlist;
  733. exprasmlist:=asmlist;
  734. hp:=finalize_data_node(cloadnode.create(sym,sym.owner));
  735. firstpass(hp);
  736. secondpass(hp);
  737. hp.free;
  738. exprasmlist:=oldexprasmlist;
  739. end;
  740. { generates the code for finalisation of local variables }
  741. procedure finalize_local_vars(p : tnamedindexitem;arg:pointer);
  742. begin
  743. case tsym(p).typ of
  744. varsym :
  745. begin
  746. if (tvarsym(p).refs>0) and
  747. not(vo_is_funcret in tvarsym(p).varoptions) and
  748. not(is_class(tvarsym(p).vartype.def)) and
  749. tvarsym(p).vartype.def.needs_inittable then
  750. finalize_sym(taasmoutput(arg),tsym(p));
  751. end;
  752. end;
  753. end;
  754. { generates the code for finalisation of local typedconsts }
  755. procedure finalize_local_typedconst(p : tnamedindexitem;arg:pointer);
  756. var
  757. i : longint;
  758. pd : tprocdef;
  759. begin
  760. case tsym(p).typ of
  761. typedconstsym :
  762. begin
  763. if ttypedconstsym(p).is_writable and
  764. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  765. finalize_sym(taasmoutput(arg),tsym(p));
  766. end;
  767. procsym :
  768. begin
  769. for i:=1 to tprocsym(p).procdef_count do
  770. begin
  771. pd:=tprocsym(p).procdef[i];
  772. if assigned(pd.localst) and
  773. (pd.procsym=tprocsym(p)) and
  774. (pd.localst.symtabletype<>staticsymtable) then
  775. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  776. end;
  777. end;
  778. end;
  779. end;
  780. { generates the code for finalization of static symtable and
  781. all local (static) typedconsts }
  782. procedure finalize_static_data(p : tnamedindexitem;arg:pointer);
  783. var
  784. i : longint;
  785. pd : tprocdef;
  786. begin
  787. case tsym(p).typ of
  788. varsym :
  789. begin
  790. if (tvarsym(p).refs>0) and
  791. not(vo_is_funcret in tvarsym(p).varoptions) and
  792. not(is_class(tvarsym(p).vartype.def)) and
  793. tvarsym(p).vartype.def.needs_inittable then
  794. finalize_sym(taasmoutput(arg),tsym(p));
  795. end;
  796. typedconstsym :
  797. begin
  798. if ttypedconstsym(p).is_writable and
  799. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  800. finalize_sym(taasmoutput(arg),tsym(p));
  801. end;
  802. procsym :
  803. begin
  804. for i:=1 to tprocsym(p).procdef_count do
  805. begin
  806. pd:=tprocsym(p).procdef[i];
  807. if assigned(pd.localst) and
  808. (pd.procsym=tprocsym(p)) and
  809. (pd.localst.symtabletype<>staticsymtable) then
  810. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  811. end;
  812. end;
  813. end;
  814. end;
  815. { generates the code for incrementing the reference count of parameters and
  816. initialize out parameters }
  817. procedure init_paras(p : tnamedindexitem;arg:pointer);
  818. var
  819. href : treference;
  820. tmpreg : tregister;
  821. list:TAAsmoutput;
  822. begin
  823. list:=taasmoutput(arg);
  824. if (tsym(p).typ=varsym) and
  825. not is_class_or_interface(tvarsym(p).vartype.def) and
  826. tvarsym(p).vartype.def.needs_inittable then
  827. begin
  828. case tvarsym(p).varspez of
  829. vs_value :
  830. begin
  831. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  832. internalerror(200309187);
  833. cg.g_incrrefcount(list,tvarsym(p).vartype.def,tvarsym(p).localloc.reference,is_open_array(tvarsym(p).vartype.def));
  834. end;
  835. vs_out :
  836. begin
  837. tmpreg:=cg.getaddressregister(list);
  838. cg.a_load_loc_reg(list,OS_ADDR,tvarsym(p).localloc,tmpreg);
  839. reference_reset_base(href,tmpreg,0);
  840. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  841. end;
  842. end;
  843. end;
  844. end;
  845. { generates the code for decrementing the reference count of parameters }
  846. procedure final_paras(p : tnamedindexitem;arg:pointer);
  847. var
  848. list:TAAsmoutput;
  849. begin
  850. list:=taasmoutput(arg);
  851. if (tsym(p).typ=varsym) and
  852. not is_class_or_interface(tvarsym(p).vartype.def) and
  853. tvarsym(p).vartype.def.needs_inittable then
  854. begin
  855. if (tvarsym(p).varspez=vs_value) then
  856. begin
  857. include(current_procinfo.flags,pi_needs_implicit_finally);
  858. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  859. internalerror(200309188);
  860. cg.g_decrrefcount(list,tvarsym(p).vartype.def,tvarsym(p).localloc.reference,is_open_array(tvarsym(p).vartype.def));
  861. end;
  862. end
  863. else if (tsym(p).typ=varsym) and
  864. (tvarsym(p).varspez=vs_value) and
  865. (is_open_array(tvarsym(p).vartype.def) or
  866. is_array_of_const(tvarsym(p).vartype.def)) then
  867. begin
  868. { cdecl functions don't have a high pointer so it is not possible to generate
  869. a local copy }
  870. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  871. cg.g_releasevaluepara_openarray(list,tvarsym(p).localloc.reference);
  872. end;
  873. end;
  874. { Initialize temp ansi/widestrings,interfaces }
  875. procedure inittempvariables(list:taasmoutput);
  876. var
  877. hp : ptemprecord;
  878. href : treference;
  879. begin
  880. hp:=tg.templist;
  881. while assigned(hp) do
  882. begin
  883. if assigned(hp^.def) and
  884. hp^.def.needs_inittable then
  885. begin
  886. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  887. cg.g_initialize(list,hp^.def,href,false);
  888. end;
  889. hp:=hp^.next;
  890. end;
  891. end;
  892. procedure finalizetempvariables(list:taasmoutput);
  893. var
  894. hp : ptemprecord;
  895. href : treference;
  896. begin
  897. hp:=tg.templist;
  898. while assigned(hp) do
  899. begin
  900. if assigned(hp^.def) and
  901. hp^.def.needs_inittable then
  902. begin
  903. include(current_procinfo.flags,pi_needs_implicit_finally);
  904. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  905. cg.g_finalize(list,hp^.def,href,false);
  906. end;
  907. hp:=hp^.next;
  908. end;
  909. end;
  910. procedure gen_load_return_value(list:TAAsmoutput);
  911. var
  912. {$ifndef cpu64bit}
  913. href : treference;
  914. {$endif cpu64bit}
  915. ressym : tvarsym;
  916. resloc,
  917. restmploc : tlocation;
  918. hreg : tregister;
  919. funcretloc : pcgparalocation;
  920. begin
  921. { Is the loading needed? }
  922. if is_void(current_procinfo.procdef.rettype.def) or
  923. (
  924. (po_assembler in current_procinfo.procdef.procoptions) and
  925. (not(assigned(current_procinfo.procdef.funcretsym)) or
  926. (tvarsym(current_procinfo.procdef.funcretsym).refs=0))
  927. ) then
  928. exit;
  929. funcretloc:=current_procinfo.procdef.funcret_paraloc[calleeside].location;
  930. if not assigned(funcretloc) then
  931. internalerror(200408202);
  932. { constructors return self }
  933. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  934. ressym:=tvarsym(current_procinfo.procdef.parast.search('self'))
  935. else
  936. ressym:=tvarsym(current_procinfo.procdef.funcretsym);
  937. if (ressym.refs>0) then
  938. begin
  939. {$ifdef OLDREGVARS}
  940. case ressym.localloc.loc of
  941. LOC_CFPUREGISTER,
  942. LOC_FPUREGISTER:
  943. begin
  944. location_reset(restmploc,LOC_CFPUREGISTER,funcretloc^.size);
  945. restmploc.register:=ressym.localloc.register;
  946. end;
  947. LOC_CREGISTER,
  948. LOC_REGISTER:
  949. begin
  950. location_reset(restmploc,LOC_CREGISTER,funcretloc^.size);
  951. restmploc.register:=ressym.localloc.register;
  952. end;
  953. LOC_MMREGISTER:
  954. begin
  955. location_reset(restmploc,LOC_CMMREGISTER,funcretloc^.size);
  956. restmploc.register:=ressym.localloc.register;
  957. end;
  958. LOC_REFERENCE:
  959. begin
  960. location_reset(restmploc,LOC_REFERENCE,funcretloc^.size);
  961. restmploc.reference:=ressym.localloc.reference;
  962. end;
  963. else
  964. internalerror(200309184);
  965. end;
  966. {$else}
  967. restmploc:=ressym.localloc;
  968. {$endif}
  969. { Here, we return the function result. In most architectures, the value is
  970. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  971. function returns in a register and the caller receives it in an other one }
  972. case funcretloc^.loc of
  973. LOC_REGISTER:
  974. begin
  975. {$ifndef cpu64bit}
  976. if current_procinfo.procdef.funcret_paraloc[calleeside].size in [OS_64,OS_S64] then
  977. begin
  978. current_procinfo.procdef.funcret_paraloc[calleeside].get_location(resloc);
  979. if resloc.loc<>LOC_REGISTER then
  980. internalerror(200409141);
  981. { Load low and high register separate to generate better register
  982. allocation info }
  983. if getsupreg(resloc.registerlow)<first_int_imreg then
  984. begin
  985. cg.getcpuregister(list,resloc.registerlow);
  986. cg.ungetcpuregister(list,resloc.registerlow);
  987. { for the optimizer }
  988. cg.a_reg_alloc(list,resloc.registerlow);
  989. end;
  990. case restmploc.loc of
  991. LOC_REFERENCE :
  992. begin
  993. href:=restmploc.reference;
  994. if target_info.endian=ENDIAN_BIG then
  995. inc(href.offset,4);
  996. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.registerlow);
  997. end;
  998. LOC_CREGISTER :
  999. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.registerlow,resloc.registerlow);
  1000. else
  1001. internalerror(200409203);
  1002. end;
  1003. if getsupreg(resloc.registerhigh)<first_int_imreg then
  1004. begin
  1005. cg.getcpuregister(list,resloc.registerhigh);
  1006. cg.ungetcpuregister(list,resloc.registerhigh);
  1007. { for the optimizer }
  1008. cg.a_reg_alloc(list,resloc.registerhigh);
  1009. end;
  1010. case restmploc.loc of
  1011. LOC_REFERENCE :
  1012. begin
  1013. href:=restmploc.reference;
  1014. if target_info.endian=ENDIAN_LITTLE then
  1015. inc(href.offset,4);
  1016. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.registerhigh);
  1017. end;
  1018. LOC_CREGISTER :
  1019. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.registerhigh,resloc.registerhigh);
  1020. else
  1021. internalerror(200409204);
  1022. end;
  1023. end
  1024. else
  1025. {$endif cpu64bit}
  1026. begin
  1027. hreg:=cg.makeregsize(list,funcretloc^.register,restmploc.size);
  1028. if getsupreg(funcretloc^.register)<first_int_imreg then
  1029. begin
  1030. cg.getcpuregister(list,funcretloc^.register);
  1031. cg.ungetcpuregister(list,hreg);
  1032. { for the optimizer }
  1033. cg.a_reg_alloc(list,funcretloc^.register);
  1034. end;
  1035. cg.a_load_loc_reg(list,restmploc.size,restmploc,hreg);
  1036. end;
  1037. end;
  1038. LOC_FPUREGISTER:
  1039. begin
  1040. if getsupreg(funcretloc^.register)<first_fpu_imreg then
  1041. begin
  1042. cg.getcpuregister(list,funcretloc^.register);
  1043. cg.ungetcpuregister(list,funcretloc^.register);
  1044. end;
  1045. cg.a_loadfpu_loc_reg(list,restmploc,funcretloc^.register);
  1046. end;
  1047. LOC_MMREGISTER:
  1048. begin
  1049. if getsupreg(funcretloc^.register)<first_mm_imreg then
  1050. begin
  1051. cg.getcpuregister(list,funcretloc^.register);
  1052. cg.ungetcpuregister(list,funcretloc^.register);
  1053. end;
  1054. cg.a_loadmm_loc_reg(list,restmploc.size,restmploc,funcretloc^.register,mms_movescalar);
  1055. end;
  1056. LOC_INVALID,
  1057. LOC_REFERENCE:
  1058. ;
  1059. else
  1060. internalerror(200405025);
  1061. end;
  1062. end;
  1063. end;
  1064. procedure gen_load_para_value(list:TAAsmoutput);
  1065. procedure get_para(const paraloc:TCGParaLocation);
  1066. begin
  1067. case paraloc.loc of
  1068. LOC_REGISTER :
  1069. begin
  1070. if getsupreg(paraloc.register)<first_int_imreg then
  1071. cg.getcpuregister(list,paraloc.register);
  1072. end;
  1073. LOC_MMREGISTER :
  1074. begin
  1075. if getsupreg(paraloc.register)<first_mm_imreg then
  1076. cg.getcpuregister(list,paraloc.register);
  1077. end;
  1078. LOC_FPUREGISTER :
  1079. begin
  1080. if getsupreg(paraloc.register)<first_fpu_imreg then
  1081. cg.getcpuregister(list,paraloc.register);
  1082. end;
  1083. end;
  1084. end;
  1085. procedure unget_para(const paraloc:TCGParaLocation);
  1086. begin
  1087. case paraloc.loc of
  1088. LOC_REGISTER :
  1089. begin
  1090. if getsupreg(paraloc.register)<first_int_imreg then
  1091. cg.ungetcpuregister(list,paraloc.register);
  1092. end;
  1093. LOC_MMREGISTER :
  1094. begin
  1095. if getsupreg(paraloc.register)<first_mm_imreg then
  1096. cg.ungetcpuregister(list,paraloc.register);
  1097. end;
  1098. LOC_FPUREGISTER :
  1099. begin
  1100. if getsupreg(paraloc.register)<first_fpu_imreg then
  1101. cg.ungetcpuregister(list,paraloc.register);
  1102. end;
  1103. end;
  1104. end;
  1105. procedure gen_load_ref(const paraloc:TCGParaLocation;const ref:treference);
  1106. var
  1107. href : treference;
  1108. begin
  1109. case paraloc.loc of
  1110. LOC_REGISTER :
  1111. cg.a_load_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  1112. LOC_MMREGISTER :
  1113. cg.a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,mms_movescalar);
  1114. LOC_FPUREGISTER :
  1115. cg.a_loadfpu_reg_ref(list,paraloc.size,paraloc.register,ref);
  1116. LOC_REFERENCE :
  1117. begin
  1118. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1119. { use concatcopy, because it can also be a float which fails when
  1120. load_ref_ref is used. Don't copy data when the references are equal }
  1121. if not((href.base=ref.base) and (href.offset=ref.offset)) then
  1122. cg.g_concatcopy(list,href,ref,tcgsize2size[paraloc.size],false);
  1123. end;
  1124. else
  1125. internalerror(2002081302);
  1126. end;
  1127. end;
  1128. procedure gen_load_reg(const paraloc:TCGParaLocation;reg:tregister);
  1129. var
  1130. href : treference;
  1131. begin
  1132. case paraloc.loc of
  1133. LOC_REGISTER :
  1134. cg.a_load_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg);
  1135. LOC_MMREGISTER :
  1136. cg.a_loadmm_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg,mms_movescalar);
  1137. LOC_FPUREGISTER :
  1138. cg.a_loadfpu_reg_reg(list,paraloc.size,paraloc.register,reg);
  1139. LOC_REFERENCE :
  1140. begin
  1141. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1142. case getregtype(reg) of
  1143. R_INTREGISTER :
  1144. cg.a_load_ref_reg(list,paraloc.size,paraloc.size,href,reg);
  1145. R_FPUREGISTER :
  1146. cg.a_loadfpu_ref_reg(list,paraloc.size,href,reg);
  1147. R_MMREGISTER :
  1148. cg.a_loadmm_ref_reg(list,paraloc.size,paraloc.size,href,reg,mms_movescalar);
  1149. else
  1150. internalerror(2004101012);
  1151. end;
  1152. end;
  1153. else
  1154. internalerror(2002081302);
  1155. end;
  1156. end;
  1157. var
  1158. hp : tparaitem;
  1159. paraloc : pcgparalocation;
  1160. {$ifdef sparc}
  1161. tempref,
  1162. {$endif sparc}
  1163. href : treference;
  1164. begin
  1165. if (po_assembler in current_procinfo.procdef.procoptions) then
  1166. exit;
  1167. { Allocate registers used by parameters }
  1168. hp:=tparaitem(current_procinfo.procdef.para.first);
  1169. while assigned(hp) do
  1170. begin
  1171. paraloc:=hp.paraloc[calleeside].location;
  1172. while assigned(paraloc) do
  1173. begin
  1174. if paraloc^.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER] then
  1175. get_para(paraloc^);
  1176. paraloc:=paraloc^.next;
  1177. end;
  1178. hp:=tparaitem(hp.next);
  1179. end;
  1180. { Copy parameters to local references/registers }
  1181. hp:=tparaitem(current_procinfo.procdef.para.first);
  1182. while assigned(hp) do
  1183. begin
  1184. paraloc:=hp.paraloc[calleeside].location;
  1185. if not assigned(paraloc) then
  1186. internalerror(200408203);
  1187. case tvarsym(hp.parasym).localloc.loc of
  1188. LOC_REFERENCE :
  1189. begin
  1190. href:=tvarsym(hp.parasym).localloc.reference;
  1191. while assigned(paraloc) do
  1192. begin
  1193. unget_para(paraloc^);
  1194. gen_load_ref(paraloc^,href);
  1195. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1196. paraloc:=paraloc^.next;
  1197. end;
  1198. end;
  1199. LOC_CREGISTER :
  1200. begin
  1201. {$ifndef cpu64bit}
  1202. if tvarsym(hp.parasym).localloc.size in [OS_64,OS_S64] then
  1203. begin
  1204. { First 32bits }
  1205. unget_para(paraloc^);
  1206. if (target_info.endian=ENDIAN_BIG) then
  1207. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerhigh)
  1208. else
  1209. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerlow);
  1210. { Second 32bits }
  1211. if not assigned(paraloc^.next) then
  1212. internalerror(200410104);
  1213. unget_para(paraloc^);
  1214. if (target_info.endian=ENDIAN_BIG) then
  1215. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerlow)
  1216. else
  1217. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerhigh);
  1218. end
  1219. else
  1220. {$endif cpu64bit}
  1221. begin
  1222. unget_para(paraloc^);
  1223. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.register);
  1224. if assigned(paraloc^.next) then
  1225. internalerror(200410105);
  1226. end;
  1227. end;
  1228. LOC_CFPUREGISTER :
  1229. begin
  1230. {$ifdef sparc}
  1231. { Sparc passes floats in int registers, when loading to fpu register
  1232. we need a temp }
  1233. tg.GetTemp(list,TCGSize2Size[tvarsym(hp.parasym).localloc.size],tt_normal,tempref);
  1234. href:=tempref;
  1235. while assigned(paraloc) do
  1236. begin
  1237. unget_para(paraloc^);
  1238. gen_load_ref(paraloc^,href);
  1239. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1240. paraloc:=paraloc^.next;
  1241. end;
  1242. cg.a_loadfpu_ref_reg(list,tvarsym(hp.parasym).localloc.size,tempref,tvarsym(hp.parasym).localloc.register);
  1243. tg.UnGetTemp(list,tempref);
  1244. {$else sparc}
  1245. unget_para(paraloc^);
  1246. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.register);
  1247. if assigned(paraloc^.next) then
  1248. internalerror(200410109);
  1249. {$endif sparc}
  1250. end;
  1251. LOC_CMMREGISTER :
  1252. begin
  1253. unget_para(paraloc^);
  1254. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.register);
  1255. if assigned(paraloc^.next) then
  1256. internalerror(200410108);
  1257. end;
  1258. end;
  1259. hp:=tparaitem(hp.next);
  1260. end;
  1261. { generate copies of call by value parameters, must be done before
  1262. the initialization and body is parsed because the refcounts are
  1263. incremented using the local copies }
  1264. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1265. end;
  1266. procedure gen_initialize_code(list:TAAsmoutput);
  1267. begin
  1268. { initialize local data like ansistrings }
  1269. case current_procinfo.procdef.proctypeoption of
  1270. potype_unitinit:
  1271. begin
  1272. { this is also used for initialization of variables in a
  1273. program which does not have a globalsymtable }
  1274. if assigned(current_module.globalsymtable) then
  1275. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1276. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1277. end;
  1278. { units have seperate code for initilization and finalization }
  1279. potype_unitfinalize: ;
  1280. { program init/final is generated in separate procedure }
  1281. potype_proginit: ;
  1282. else
  1283. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1284. end;
  1285. { initialisizes temp. ansi/wide string data }
  1286. inittempvariables(list);
  1287. { initialize ansi/widesstring para's }
  1288. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1289. { initialize regvars in staticsymtable with 0, like .bss }
  1290. if current_procinfo.procdef.localst.symtabletype=staticsymtable then
  1291. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_regvars,list);
  1292. {$ifdef OLDREGVARS}
  1293. load_regvars(list,nil);
  1294. {$endif OLDREGVARS}
  1295. end;
  1296. procedure gen_finalize_code(list:TAAsmoutput);
  1297. begin
  1298. {$ifdef OLDREGVARS}
  1299. cleanup_regvars(list);
  1300. {$endif OLDREGVARS}
  1301. { finalize temporary data }
  1302. finalizetempvariables(list);
  1303. { finalize local data like ansistrings}
  1304. case current_procinfo.procdef.proctypeoption of
  1305. potype_unitfinalize:
  1306. begin
  1307. { this is also used for initialization of variables in a
  1308. program which does not have a globalsymtable }
  1309. if assigned(current_module.globalsymtable) then
  1310. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1311. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1312. end;
  1313. { units/progs have separate code for initialization and finalization }
  1314. potype_unitinit: ;
  1315. { program init/final is generated in separate procedure }
  1316. potype_proginit: ;
  1317. else
  1318. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_local_vars,list);
  1319. end;
  1320. { finalize paras data }
  1321. if assigned(current_procinfo.procdef.parast) then
  1322. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1323. end;
  1324. procedure gen_entry_code(list:TAAsmoutput);
  1325. var
  1326. href : treference;
  1327. paraloc1,
  1328. paraloc2 : tcgpara;
  1329. hp : tused_unit;
  1330. begin
  1331. paraloc1.init;
  1332. paraloc2.init;
  1333. { the actual profile code can clobber some registers,
  1334. therefore if the context must be saved, do it before
  1335. the actual call to the profile code
  1336. }
  1337. if (cs_profile in aktmoduleswitches) and
  1338. not(po_assembler in current_procinfo.procdef.procoptions) then
  1339. begin
  1340. { non-win32 can call mcout even in main }
  1341. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) or
  1342. not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1343. begin
  1344. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1345. cg.g_profilecode(list);
  1346. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1347. end;
  1348. end;
  1349. { call startup helpers from main program }
  1350. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1351. begin
  1352. { initialize profiling for win32 }
  1353. if (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1354. (cs_profile in aktmoduleswitches) then
  1355. begin
  1356. reference_reset_symbol(href,objectlibrary.newasmsymbol('etext',AB_EXTERNAL,AT_DATA),0);
  1357. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1358. paramanager.getintparaloc(pocall_default,2,paraloc2);
  1359. paramanager.allocparaloc(list,paraloc2);
  1360. cg.a_paramaddr_ref(list,href,paraloc2);
  1361. reference_reset_symbol(href,objectlibrary.newasmsymbol('__image_base__',AB_EXTERNAL,AT_DATA),0);
  1362. paramanager.allocparaloc(list,paraloc1);
  1363. cg.a_paramaddr_ref(list,href,paraloc1);
  1364. paramanager.freeparaloc(list,paraloc2);
  1365. paramanager.freeparaloc(list,paraloc1);
  1366. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1367. cg.a_call_name(list,'_monstartup');
  1368. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1369. end;
  1370. { initialize units }
  1371. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1372. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1373. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1374. {$ifdef GDB}
  1375. if (cs_debuginfo in aktmoduleswitches) then
  1376. if target_info.system <> system_powerpc_macos then
  1377. begin
  1378. { include reference to all debuginfo sections of used units }
  1379. hp:=tused_unit(usedunits.first);
  1380. while assigned(hp) do
  1381. begin
  1382. If (hp.u.flags and uf_has_debuginfo)=uf_has_debuginfo then
  1383. current_procinfo.aktlocaldata.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',hp.u.globalsymtable,''),AT_DATA,0));
  1384. hp:=tused_unit(hp.next);
  1385. end;
  1386. { include reference to debuginfo for this program }
  1387. current_procinfo.aktlocaldata.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
  1388. end;
  1389. {$endif GDB}
  1390. end;
  1391. {$ifdef GDB}
  1392. if (cs_debuginfo in aktmoduleswitches) then
  1393. list.concat(Tai_force_line.Create);
  1394. {$endif GDB}
  1395. {$ifdef OLDREGVARS}
  1396. load_regvars(list,nil);
  1397. {$endif OLDREGVARS}
  1398. paraloc1.done;
  1399. paraloc2.done;
  1400. end;
  1401. procedure gen_exit_code(list:TAAsmoutput);
  1402. begin
  1403. { call __EXIT for main program }
  1404. if (not DLLsource) and
  1405. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1406. cg.a_call_name(list,'FPC_DO_EXIT');
  1407. end;
  1408. {****************************************************************************
  1409. Entry/Exit
  1410. ****************************************************************************}
  1411. procedure gen_proc_symbol(list:Taasmoutput);
  1412. var
  1413. hs : string;
  1414. begin
  1415. { add symbol entry point as well as debug information }
  1416. { will be inserted in front of the rest of this list. }
  1417. { Insert alignment and assembler names }
  1418. { Align, gprof uses 16 byte granularity }
  1419. if (cs_profile in aktmoduleswitches) then
  1420. list.concat(Tai_align.create(16))
  1421. else
  1422. list.concat(Tai_align.create(aktalignment.procalign));
  1423. {$ifdef GDB}
  1424. if (cs_debuginfo in aktmoduleswitches) then
  1425. begin
  1426. if (po_public in current_procinfo.procdef.procoptions) then
  1427. Tprocsym(current_procinfo.procdef.procsym).is_global:=true;
  1428. current_procinfo.procdef.concatstabto(list);
  1429. Tprocsym(current_procinfo.procdef.procsym).isstabwritten:=true;
  1430. end;
  1431. {$endif GDB}
  1432. repeat
  1433. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1434. if hs='' then
  1435. break;
  1436. {$ifdef GDB}
  1437. if (cs_debuginfo in aktmoduleswitches) and
  1438. target_info.use_function_relative_addresses then
  1439. list.concat(Tai_stab_function_name.create(strpnew(hs)));
  1440. {$endif GDB}
  1441. if (cs_profile in aktmoduleswitches) or
  1442. (po_public in current_procinfo.procdef.procoptions) then
  1443. list.concat(Tai_symbol.createname_global(hs,AT_FUNCTION,0))
  1444. else
  1445. list.concat(Tai_symbol.createname(hs,AT_FUNCTION,0));
  1446. until false;
  1447. end;
  1448. procedure gen_proc_symbol_end(list:Taasmoutput);
  1449. {$ifdef GDB}
  1450. var
  1451. stabsendlabel : tasmlabel;
  1452. mangled_length : longint;
  1453. p : pchar;
  1454. {$endif GDB}
  1455. begin
  1456. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1457. {$ifdef GDB}
  1458. if (cs_debuginfo in aktmoduleswitches) then
  1459. begin
  1460. objectlibrary.getlabel(stabsendlabel);
  1461. cg.a_label(list,stabsendlabel);
  1462. { define calling EBP as pseudo local var PM }
  1463. { this enables test if the function is a local one !! }
  1464. {if assigned(current_procinfo.parent) and
  1465. (current_procinfo.procdef.parast.symtablelevel>normal_function_level) then
  1466. list.concat(Tai_stabs.Create(strpnew(
  1467. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1468. tostr(N_LSYM)+',0,0,'+tostr(current_procinfo.parent_framepointer_offset)))); }
  1469. if assigned(current_procinfo.procdef.funcretsym) and
  1470. (tvarsym(current_procinfo.procdef.funcretsym).refs>0) then
  1471. begin
  1472. if tvarsym(current_procinfo.procdef.funcretsym).localloc.loc=LOC_REFERENCE then
  1473. begin
  1474. {$warning Need to add gdb support for ret in param register calling}
  1475. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1476. begin
  1477. list.concat(Tai_stabs.Create(strpnew(
  1478. '"'+current_procinfo.procdef.procsym.name+':X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1479. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1480. if (m_result in aktmodeswitches) then
  1481. list.concat(Tai_stabs.Create(strpnew(
  1482. '"RESULT:X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1483. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))))
  1484. end
  1485. else
  1486. begin
  1487. list.concat(Tai_stabs.Create(strpnew(
  1488. '"'+current_procinfo.procdef.procsym.name+':X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1489. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1490. if (m_result in aktmodeswitches) then
  1491. list.concat(Tai_stabs.Create(strpnew(
  1492. '"RESULT:X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1493. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1494. end;
  1495. end;
  1496. end;
  1497. mangled_length:=length(current_procinfo.procdef.mangledname);
  1498. getmem(p,2*mangled_length+50);
  1499. strpcopy(p,'192,0,0,');
  1500. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1501. if (target_info.use_function_relative_addresses) then
  1502. begin
  1503. strpcopy(strend(p),'-');
  1504. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1505. end;
  1506. list.concat(Tai_stabn.Create(strnew(p)));
  1507. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1508. +current_procinfo.procdef.mangledname))));
  1509. p[0]:='2';p[1]:='2';p[2]:='4';
  1510. strpcopy(strend(p),'_end');}
  1511. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1512. if (target_info.use_function_relative_addresses) then
  1513. begin
  1514. strpcopy(strend(p),'-');
  1515. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1516. end;
  1517. list.concatlist(withdebuglist);
  1518. list.concat(Tai_stabn.Create(strnew(p)));
  1519. { strpnew('224,0,0,'
  1520. +current_procinfo.procdef.mangledname+'_end'))));}
  1521. freemem(p,2*mangled_length+50);
  1522. end;
  1523. {$endif GDB}
  1524. end;
  1525. procedure gen_proc_entry_code(list:Taasmoutput);
  1526. var
  1527. hitemp,
  1528. lotemp,
  1529. stackframe : longint;
  1530. check : boolean;
  1531. paraloc1 : tcgpara;
  1532. href : treference;
  1533. begin
  1534. paraloc1.init;
  1535. { generate call frame marker for dwarf call frame info }
  1536. dwarfcfi.start_frame(list);
  1537. { allocate temp for saving the argument used when
  1538. stack checking uses a register for pushing the stackframe size }
  1539. check:=(cs_check_stack in aktlocalswitches) and (current_procinfo.procdef.proctypeoption<>potype_proginit);
  1540. if check then
  1541. begin
  1542. { Allocate tempspace to store register parameter than
  1543. is destroyed when calling stackchecking code }
  1544. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1545. if paraloc1.location^.loc=LOC_REGISTER then
  1546. tg.GetTemp(list,sizeof(aint),tt_normal,href);
  1547. end;
  1548. { Calculate size of stackframe }
  1549. stackframe:=current_procinfo.calc_stackframe_size;
  1550. { All temps are know, write offsets used for information }
  1551. if (cs_asm_source in aktglobalswitches) then
  1552. begin
  1553. if tg.direction>0 then
  1554. begin
  1555. lotemp:=current_procinfo.tempstart;
  1556. hitemp:=tg.lasttemp;
  1557. end
  1558. else
  1559. begin
  1560. lotemp:=tg.lasttemp;
  1561. hitemp:=current_procinfo.tempstart;
  1562. end;
  1563. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1564. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1565. end;
  1566. { generate target specific proc entry code }
  1567. cg.g_proc_entry(list,stackframe,(po_nostackframe in current_procinfo.procdef.procoptions));
  1568. { Add stack checking code? }
  1569. if check then
  1570. begin
  1571. { The tempspace to store original register is already
  1572. allocated above before the stackframe size is calculated. }
  1573. if paraloc1.location^.loc=LOC_REGISTER then
  1574. cg.a_load_reg_ref(list,OS_INT,OS_INT,paraloc1.location^.register,href);
  1575. paramanager.allocparaloc(list,paraloc1);
  1576. cg.a_param_const(list,OS_INT,stackframe,paraloc1);
  1577. paramanager.freeparaloc(list,paraloc1);
  1578. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1579. cg.a_call_name(list,'FPC_STACKCHECK');
  1580. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1581. if paraloc1.location^.loc=LOC_REGISTER then
  1582. begin
  1583. cg.a_load_ref_reg(list,OS_INT,OS_INT,href,paraloc1.location^.register);
  1584. tg.UnGetTemp(list,href);
  1585. end;
  1586. end;
  1587. paraloc1.done;
  1588. end;
  1589. procedure gen_proc_exit_code(list:Taasmoutput);
  1590. var
  1591. parasize : longint;
  1592. begin
  1593. { c style clearstack does not need to remove parameters from the stack, only the
  1594. return value when it was pushed by arguments }
  1595. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1596. begin
  1597. parasize:=0;
  1598. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1599. inc(parasize,sizeof(aint));
  1600. end
  1601. else
  1602. parasize:=current_procinfo.para_stack_size;
  1603. { generate target specific proc exit code }
  1604. cg.g_proc_exit(list,parasize,(po_nostackframe in current_procinfo.procdef.procoptions));
  1605. { release return registers, needed for optimizer }
  1606. paramanager.freeparaloc(list,current_procinfo.procdef.funcret_paraloc[calleeside]);
  1607. { end of frame marker for call frame info }
  1608. dwarfcfi.end_frame(list);
  1609. end;
  1610. procedure gen_save_used_regs(list:TAAsmoutput);
  1611. begin
  1612. { Pure assembler routines need to save the registers themselves }
  1613. if (po_assembler in current_procinfo.procdef.procoptions) then
  1614. exit;
  1615. { for the save all registers we can simply use a pusha,popa which
  1616. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1617. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1618. cg.g_save_all_registers(list)
  1619. else
  1620. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1621. cg.g_save_standard_registers(list);
  1622. end;
  1623. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tcgpara);
  1624. begin
  1625. { Pure assembler routines need to save the registers themselves }
  1626. if (po_assembler in current_procinfo.procdef.procoptions) then
  1627. exit;
  1628. { for the save all registers we can simply use a pusha,popa which
  1629. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1630. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1631. cg.g_restore_all_registers(list,funcretparaloc)
  1632. else
  1633. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1634. cg.g_restore_standard_registers(list);
  1635. end;
  1636. {****************************************************************************
  1637. Const Data
  1638. ****************************************************************************}
  1639. procedure insertconstdata(sym : ttypedconstsym);
  1640. { this does not affect the local stack space, since all
  1641. typed constansts and initialized variables are always
  1642. put in the .data / .rodata section
  1643. }
  1644. var
  1645. storefilepos : tfileposinfo;
  1646. curconstsegment : taasmoutput;
  1647. l : longint;
  1648. begin
  1649. storefilepos:=aktfilepos;
  1650. aktfilepos:=sym.fileinfo;
  1651. if sym.is_writable then
  1652. curconstsegment:=datasegment
  1653. else
  1654. curconstsegment:=consts;
  1655. l:=sym.getsize;
  1656. { insert cut for smartlinking or alignment }
  1657. maybe_new_object_file(curconstSegment);
  1658. new_section(curconstSegment,sec_rodata,lower(sym.mangledname),const_align(l));
  1659. if (sym.owner.symtabletype=globalsymtable) or
  1660. maybe_smartlink_symbol or
  1661. (assigned(current_procinfo) and
  1662. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1663. DLLSource then
  1664. curconstSegment.concat(Tai_symbol.Createname_global(sym.mangledname,AT_DATA,l))
  1665. else
  1666. curconstSegment.concat(Tai_symbol.Createname(sym.mangledname,AT_DATA,l));
  1667. aktfilepos:=storefilepos;
  1668. end;
  1669. procedure insertbssdata(sym : tvarsym);
  1670. var
  1671. l,varalign : longint;
  1672. storefilepos : tfileposinfo;
  1673. begin
  1674. storefilepos:=aktfilepos;
  1675. aktfilepos:=sym.fileinfo;
  1676. l:=sym.getsize;
  1677. if (vo_is_thread_var in sym.varoptions) then
  1678. inc(l,sizeof(aint));
  1679. varalign:=var_align(l);
  1680. maybe_new_object_file(bssSegment);
  1681. new_section(bssSegment,sec_bss,lower(sym.mangledname),varalign);
  1682. if (sym.owner.symtabletype=globalsymtable) or
  1683. maybe_smartlink_symbol or
  1684. DLLSource or
  1685. (assigned(current_procinfo) and
  1686. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1687. (vo_is_exported in sym.varoptions) or
  1688. (vo_is_C_var in sym.varoptions) then
  1689. bssSegment.concat(Tai_datablock.Create_global(sym.mangledname,l))
  1690. else
  1691. bssSegment.concat(Tai_datablock.Create(sym.mangledname,l));
  1692. aktfilepos:=storefilepos;
  1693. end;
  1694. procedure gen_alloc_symtable(list:TAAsmoutput;st:tsymtable);
  1695. var
  1696. sym : tsym;
  1697. isaddr : boolean;
  1698. cgsize : tcgsize;
  1699. begin
  1700. sym:=tsym(st.symindex.first);
  1701. while assigned(sym) do
  1702. begin
  1703. if (sym.typ=varsym) then
  1704. begin
  1705. with tvarsym(sym) do
  1706. begin
  1707. { Parameters passed to assembler procedures need to be kept
  1708. in the original location }
  1709. if (st.symtabletype=parasymtable) and
  1710. (po_assembler in current_procinfo.procdef.procoptions) then
  1711. begin
  1712. paraitem.paraloc[calleeside].get_location(localloc);
  1713. end
  1714. else
  1715. begin
  1716. isaddr:=(st.symtabletype=parasymtable) and
  1717. paramanager.push_addr_param(varspez,vartype.def,current_procinfo.procdef.proccalloption);
  1718. if isaddr then
  1719. cgsize:=OS_ADDR
  1720. else
  1721. cgsize:=def_cgsize(vartype.def);
  1722. {$ifndef OLDREGVARS}
  1723. { When there is assembler code we can't use regvars }
  1724. if is_regvar then
  1725. begin
  1726. localloc.size:=cgsize;
  1727. case varregable of
  1728. vr_intreg :
  1729. begin
  1730. localloc.loc:=LOC_CREGISTER;
  1731. {$ifndef cpu64bit}
  1732. if cgsize in [OS_64,OS_S64] then
  1733. begin
  1734. localloc.registerlow:=cg.getintregister(list,OS_32);
  1735. localloc.registerhigh:=cg.getintregister(list,OS_32);
  1736. end
  1737. else
  1738. {$endif cpu64bit}
  1739. localloc.register:=cg.getintregister(list,cgsize);
  1740. end;
  1741. vr_fpureg :
  1742. begin
  1743. localloc.loc:=LOC_CFPUREGISTER;
  1744. localloc.register:=cg.getfpuregister(list,cgsize);
  1745. end;
  1746. vr_mmreg :
  1747. begin
  1748. localloc.loc:=LOC_CMMREGISTER;
  1749. localloc.register:=cg.getmmregister(list,cgsize);
  1750. end;
  1751. else
  1752. internalerror(2004101010);
  1753. end;
  1754. end
  1755. else
  1756. {$endif NOT OLDREGVARS}
  1757. begin
  1758. localloc.loc:=LOC_REFERENCE;
  1759. localloc.size:=cgsize;
  1760. case st.symtabletype of
  1761. parasymtable :
  1762. begin
  1763. { Reuse the parameter location for values to are at a single location on the stack }
  1764. if (paraitem.paraloc[calleeside].is_simple_reference) then
  1765. begin
  1766. reference_reset_base(localloc.reference,paraitem.paraloc[calleeside].location^.reference.index,
  1767. paraitem.paraloc[calleeside].location^.reference.offset);
  1768. end
  1769. else
  1770. begin
  1771. if isaddr then
  1772. tg.GetLocal(list,sizeof(aint),voidpointertype.def,localloc.reference)
  1773. else
  1774. tg.GetLocal(list,getsize,vartype.def,localloc.reference);
  1775. end;
  1776. end;
  1777. localsymtable,
  1778. stt_exceptsymtable :
  1779. begin
  1780. tg.GetLocal(list,getsize,vartype.def,localloc.reference);
  1781. end;
  1782. staticsymtable :
  1783. begin
  1784. { PIC, DLL and Threadvar need extra code and are handled in ncgld }
  1785. if not(cs_create_pic in aktmoduleswitches) and
  1786. not(vo_is_dll_var in varoptions) and
  1787. not(vo_is_thread_var in varoptions) then
  1788. reference_reset_symbol(localloc.reference,objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA),0);
  1789. end;
  1790. else
  1791. internalerror(200410103);
  1792. end;
  1793. end;
  1794. end;
  1795. if cs_asm_source in aktglobalswitches then
  1796. begin
  1797. case localloc.loc of
  1798. LOC_REGISTER,
  1799. LOC_CREGISTER :
  1800. begin
  1801. if (cs_no_regalloc in aktglobalswitches) then
  1802. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located in register '+
  1803. std_regname(localloc.register))))
  1804. else
  1805. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located in register')));
  1806. end;
  1807. LOC_REFERENCE :
  1808. begin
  1809. if not assigned(localloc.reference.symbol) then
  1810. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located at '+
  1811. std_regname(localloc.reference.base)+tostr_with_plus(localloc.reference.offset))));
  1812. end;
  1813. end;
  1814. end;
  1815. end;
  1816. end;
  1817. sym:=tsym(sym.indexnext);
  1818. end;
  1819. end;
  1820. procedure gen_free_symtable(list:TAAsmoutput;st:tsymtable);
  1821. var
  1822. sym : tsym;
  1823. begin
  1824. sym:=tsym(st.symindex.first);
  1825. while assigned(sym) do
  1826. begin
  1827. if (sym.typ=varsym) then
  1828. begin
  1829. with tvarsym(sym) do
  1830. begin
  1831. { Note: We need to keep the data available in memory
  1832. for the sub procedures that can access local data
  1833. in the parent procedures }
  1834. case localloc.loc of
  1835. LOC_CREGISTER :
  1836. cg.a_reg_sync(list,localloc.register);
  1837. LOC_REFERENCE :
  1838. begin
  1839. case st.symtabletype of
  1840. localsymtable,
  1841. parasymtable,
  1842. stt_exceptsymtable :
  1843. tg.Ungetlocal(list,localloc.reference);
  1844. end;
  1845. end;
  1846. end;
  1847. end;
  1848. end;
  1849. sym:=tsym(sym.indexnext);
  1850. end;
  1851. end;
  1852. procedure gen_alloc_inline_parast(list:TAAsmoutput;pd:tprocdef);
  1853. var
  1854. sym : tsym;
  1855. calleeparaloc,
  1856. callerparaloc : pcgparalocation;
  1857. begin
  1858. if (po_assembler in pd.procoptions) then
  1859. exit;
  1860. sym:=tsym(pd.parast.symindex.first);
  1861. while assigned(sym) do
  1862. begin
  1863. if sym.typ=varsym then
  1864. begin
  1865. with tvarsym(sym) do
  1866. begin
  1867. { for localloc <> LOC_REFERENCE, we need regvar support inside inlined procedures }
  1868. localloc.loc:=LOC_REFERENCE;
  1869. localloc.size:=int_cgsize(paramanager.push_size(varspez,vartype.def,pocall_inline));
  1870. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1871. calleeparaloc:=paraitem.paraloc[calleeside].location;
  1872. callerparaloc:=paraitem.paraloc[callerside].location;
  1873. while assigned(calleeparaloc) do
  1874. begin
  1875. if not assigned(callerparaloc) then
  1876. internalerror(200408281);
  1877. if calleeparaloc^.loc<>callerparaloc^.loc then
  1878. internalerror(200408282);
  1879. case calleeparaloc^.loc of
  1880. LOC_FPUREGISTER:
  1881. begin
  1882. calleeparaloc^.register:=cg.getfpuregister(list,calleeparaloc^.size);
  1883. callerparaloc^.register:=calleeparaloc^.register;
  1884. end;
  1885. LOC_REGISTER:
  1886. begin
  1887. calleeparaloc^.register:=cg.getintregister(list,calleeparaloc^.size);
  1888. callerparaloc^.register:=calleeparaloc^.register;
  1889. end;
  1890. LOC_MMREGISTER:
  1891. begin
  1892. calleeparaloc^.register:=cg.getmmregister(list,calleeparaloc^.size);
  1893. callerparaloc^.register:=calleeparaloc^.register;
  1894. end;
  1895. LOC_REFERENCE:
  1896. begin
  1897. calleeparaloc^.reference.offset := localloc.reference.offset;
  1898. calleeparaloc^.reference.index := localloc.reference.base;
  1899. callerparaloc^.reference.offset := localloc.reference.offset;
  1900. callerparaloc^.reference.index := localloc.reference.base;
  1901. end;
  1902. end;
  1903. calleeparaloc:=calleeparaloc^.next;
  1904. callerparaloc:=callerparaloc^.next;
  1905. end;
  1906. if cs_asm_source in aktglobalswitches then
  1907. begin
  1908. case localloc.loc of
  1909. LOC_REFERENCE :
  1910. list.concat(Tai_comment.Create(strpnew('Para '+realname+' allocated at '+
  1911. std_regname(localloc.reference.base)+tostr_with_plus(localloc.reference.offset))));
  1912. end;
  1913. end;
  1914. end;
  1915. end;
  1916. sym:=tsym(sym.indexnext);
  1917. end;
  1918. end;
  1919. procedure gen_alloc_inline_funcret(list:TAAsmoutput;pd:tprocdef);
  1920. var
  1921. calleeparaloc,
  1922. callerparaloc : pcgparalocation;
  1923. begin
  1924. if not assigned(pd.funcretsym) or
  1925. (po_assembler in pd.procoptions) then
  1926. exit;
  1927. { for localloc <> LOC_REFERENCE, we need regvar support inside inlined procedures }
  1928. with tvarsym(pd.funcretsym) do
  1929. begin
  1930. localloc.loc:=LOC_REFERENCE;
  1931. localloc.size:=int_cgsize(paramanager.push_size(varspez,vartype.def,pocall_inline));
  1932. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1933. calleeparaloc:=pd.funcret_paraloc[calleeside].location;
  1934. callerparaloc:=pd.funcret_paraloc[callerside].location;
  1935. while assigned(calleeparaloc) do
  1936. begin
  1937. if not assigned(callerparaloc) then
  1938. internalerror(200408281);
  1939. if calleeparaloc^.loc<>callerparaloc^.loc then
  1940. internalerror(200408282);
  1941. case calleeparaloc^.loc of
  1942. LOC_FPUREGISTER:
  1943. begin
  1944. calleeparaloc^.register:=cg.getfpuregister(list,calleeparaloc^.size);
  1945. callerparaloc^.register:=calleeparaloc^.register;
  1946. end;
  1947. LOC_REGISTER:
  1948. begin
  1949. calleeparaloc^.register:=cg.getintregister(list,calleeparaloc^.size);
  1950. callerparaloc^.register:=calleeparaloc^.register;
  1951. end;
  1952. LOC_MMREGISTER:
  1953. begin
  1954. calleeparaloc^.register:=cg.getmmregister(list,calleeparaloc^.size);
  1955. callerparaloc^.register:=calleeparaloc^.register;
  1956. end;
  1957. LOC_REFERENCE:
  1958. begin
  1959. calleeparaloc^.reference.offset := localloc.reference.offset;
  1960. calleeparaloc^.reference.index := localloc.reference.base;
  1961. callerparaloc^.reference.offset := localloc.reference.offset;
  1962. callerparaloc^.reference.index := localloc.reference.base;
  1963. end;
  1964. end;
  1965. calleeparaloc:=calleeparaloc^.next;
  1966. callerparaloc:=callerparaloc^.next;
  1967. end;
  1968. if cs_asm_source in aktglobalswitches then
  1969. begin
  1970. case localloc.loc of
  1971. LOC_REFERENCE :
  1972. list.concat(Tai_comment.Create(strpnew('Funcret '+realname+' allocated at '+
  1973. std_regname(localloc.reference.base)+tostr_with_plus(localloc.reference.offset))));
  1974. end;
  1975. end;
  1976. end;
  1977. end;
  1978. { persistent rtti generation }
  1979. procedure generate_rtti(p:Ttypesym);
  1980. var
  1981. rsym : trttisym;
  1982. def : tstoreddef;
  1983. begin
  1984. { rtti can only be generated for classes that are always typesyms }
  1985. def:=tstoreddef(ttypesym(p).restype.def);
  1986. { there is an error, skip rtti info }
  1987. if (def.deftype=errordef) or (Errorcount>0) then
  1988. exit;
  1989. { only create rtti once for each definition }
  1990. if not(df_has_rttitable in def.defoptions) then
  1991. begin
  1992. { definition should be in the same symtable as the symbol }
  1993. if p.owner<>def.owner then
  1994. internalerror(200108262);
  1995. { create rttisym }
  1996. rsym:=trttisym.create(p.name,fullrtti);
  1997. p.owner.insert(rsym);
  1998. { register rttisym in definition }
  1999. include(def.defoptions,df_has_rttitable);
  2000. def.rttitablesym:=rsym;
  2001. { write rtti data }
  2002. def.write_child_rtti_data(fullrtti);
  2003. maybe_new_object_file(rttilist);
  2004. new_section(rttilist,sec_rodata,rsym.get_label.name,const_align(sizeof(aint)));
  2005. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  2006. def.write_rtti_data(fullrtti);
  2007. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2008. end;
  2009. end;
  2010. { persistent init table generation }
  2011. procedure generate_inittable(p:tsym);
  2012. var
  2013. rsym : trttisym;
  2014. def : tstoreddef;
  2015. begin
  2016. { anonymous types are also allowed for records that can be varsym }
  2017. case p.typ of
  2018. typesym :
  2019. def:=tstoreddef(ttypesym(p).restype.def);
  2020. varsym :
  2021. def:=tstoreddef(tvarsym(p).vartype.def);
  2022. else
  2023. internalerror(200108263);
  2024. end;
  2025. { only create inittable once for each definition }
  2026. if not(df_has_inittable in def.defoptions) then
  2027. begin
  2028. { definition should be in the same symtable as the symbol }
  2029. if p.owner<>def.owner then
  2030. internalerror(200108264);
  2031. { create rttisym }
  2032. rsym:=trttisym.create(p.name,initrtti);
  2033. p.owner.insert(rsym);
  2034. { register rttisym in definition }
  2035. include(def.defoptions,df_has_inittable);
  2036. def.inittablesym:=rsym;
  2037. { write inittable data }
  2038. def.write_child_rtti_data(initrtti);
  2039. maybe_new_object_file(rttilist);
  2040. new_section(rttilist,sec_rodata,rsym.get_label.name,const_align(sizeof(aint)));
  2041. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  2042. def.write_rtti_data(initrtti);
  2043. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2044. end;
  2045. end;
  2046. end.
  2047. {
  2048. $Log$
  2049. Revision 1.227 2004-10-13 21:12:51 peter
  2050. * -Or fixes for open array
  2051. Revision 1.226 2004/10/11 15:48:15 peter
  2052. * small regvar for para fixes
  2053. * function tvarsym.is_regvar added
  2054. * tvarsym.getvaluesize removed, use getsize instead
  2055. Revision 1.225 2004/10/10 21:08:55 peter
  2056. * parameter regvar fixes
  2057. Revision 1.224 2004/10/10 20:51:46 peter
  2058. * fixed sparc compile
  2059. * fixed float regvar loading
  2060. Revision 1.223 2004/10/10 20:22:53 peter
  2061. * symtable allocation rewritten
  2062. * loading of parameters to local temps/regs cleanup
  2063. * regvar support for parameters
  2064. * regvar support for staticsymtable (main body)
  2065. Revision 1.222 2004/10/09 10:51:13 olle
  2066. * Refs to DEBUGINFO_<x> is now not inserted for target MacOS
  2067. Revision 1.221 2004/10/08 20:52:07 florian
  2068. * fixed storage of parameters passed by ref.
  2069. Revision 1.220 2004/10/08 17:09:43 peter
  2070. * tvarsym.varregable added, split vo_regable from varoptions
  2071. Revision 1.219 2004/09/27 15:14:08 peter
  2072. * fix compile for oldregvars
  2073. Revision 1.218 2004/09/26 17:45:30 peter
  2074. * simple regvar support, not yet finished
  2075. Revision 1.217 2004/09/25 14:23:54 peter
  2076. * ungetregister is now only used for cpuregisters, renamed to
  2077. ungetcpuregister
  2078. * renamed (get|unget)explicitregister(s) to ..cpuregister
  2079. * removed location-release/reference_release
  2080. Revision 1.216 2004/09/21 17:25:12 peter
  2081. * paraloc branch merged
  2082. Revision 1.215 2004/09/14 16:33:46 peter
  2083. * release localsymtables when module is compiled
  2084. Revision 1.214 2004/09/13 20:30:05 peter
  2085. * finalize all (also procedure local) typedconst at unit finalization
  2086. Revision 1.213.4.3 2004/09/20 20:46:34 peter
  2087. * register allocation optimized for 64bit loading of parameters
  2088. and return values
  2089. Revision 1.213.4.2 2004/09/17 17:19:26 peter
  2090. * fixed 64 bit unaryminus for sparc
  2091. * fixed 64 bit inlining
  2092. * signness of not operation
  2093. Revision 1.213.4.1 2004/08/31 20:43:06 peter
  2094. * paraloc patch
  2095. Revision 1.213 2004/08/23 11:00:06 michael
  2096. + Patch from Peter to fix debuginfo in constructor.
  2097. Revision 1.212 2004/07/17 13:14:17 jonas
  2098. * don't finalize typed consts (fixes bug3212, but causes memory leak;
  2099. they should be finalized at the end of the module)
  2100. Revision 1.211 2004/07/09 23:41:04 jonas
  2101. * support register parameters for inlined procedures + some inline
  2102. cleanups
  2103. Revision 1.210 2004/07/04 12:24:59 jonas
  2104. * fixed one regvar problem, but regvars are still broken since the dwarf
  2105. merge...
  2106. Revision 1.209 2004/06/29 20:57:21 peter
  2107. * fixed size of exceptbuf
  2108. Revision 1.208 2004/06/20 08:55:29 florian
  2109. * logs truncated
  2110. Revision 1.207 2004/06/16 20:07:08 florian
  2111. * dwarf branch merged
  2112. Revision 1.206 2004/06/01 20:39:33 jonas
  2113. * fixed bug regarding parameters on the ppc (they were allocated twice
  2114. under some circumstances and not at all in others)
  2115. Revision 1.205 2004/05/30 21:41:15 jonas
  2116. * more regvar optimizations in location_force_reg
  2117. Revision 1.204 2004/05/30 21:18:22 jonas
  2118. * some optimizations and associated fixes for better regvar code
  2119. Revision 1.203 2004/05/28 21:14:13 peter
  2120. * first load para's to temps before calling entry code (profile
  2121. }