ncgutil.pas 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311
  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_REGISTER :
  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. case hsym.localloc.loc of
  663. LOC_REFERENCE :
  664. begin
  665. { this code is only executed before the code for the body and the entry/exit code is generated
  666. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  667. }
  668. include(current_procinfo.flags,pi_do_call);
  669. cg.g_copyvaluepara_openarray(list,href1,hsym.localloc.reference,tarraydef(tvarsym(p).vartype.def).elesize)
  670. end
  671. else
  672. internalerror(200309182);
  673. end;
  674. end;
  675. end
  676. else
  677. begin
  678. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  679. internalerror(200309183);
  680. { Allocate space for the local copy }
  681. l:=tvarsym(p).getvaluesize;
  682. localcopyloc.loc:=LOC_REFERENCE;
  683. localcopyloc.size:=int_cgsize(l);
  684. tg.GetLocal(list,l,tvarsym(p).vartype.def,localcopyloc.reference);
  685. { Copy data }
  686. if is_shortstring(tvarsym(p).vartype.def) then
  687. begin
  688. { this code is only executed before the code for the body and the entry/exit code is generated
  689. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  690. }
  691. include(current_procinfo.flags,pi_do_call);
  692. cg.g_copyshortstring(list,href1,localcopyloc.reference,tstringdef(tvarsym(p).vartype.def).len,loadref)
  693. end
  694. else
  695. cg.g_concatcopy(list,href1,localcopyloc.reference,tvarsym(p).vartype.def.size,loadref);
  696. { update localloc of varsym }
  697. tg.Ungetlocal(list,tvarsym(p).localloc.reference);
  698. tvarsym(p).localloc:=localcopyloc;
  699. end;
  700. end;
  701. end;
  702. { generates the code for initialisation of local data }
  703. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  704. var
  705. oldexprasmlist : TAAsmoutput;
  706. hp : tnode;
  707. begin
  708. if (tsym(p).typ=varsym) and
  709. (tvarsym(p).refs>0) and
  710. not(is_class(tvarsym(p).vartype.def)) and
  711. tvarsym(p).vartype.def.needs_inittable then
  712. begin
  713. oldexprasmlist:=exprasmlist;
  714. exprasmlist:=taasmoutput(arg);
  715. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  716. firstpass(hp);
  717. secondpass(hp);
  718. hp.free;
  719. exprasmlist:=oldexprasmlist;
  720. end;
  721. end;
  722. procedure finalize_sym(asmlist:taasmoutput;sym:tsym);
  723. var
  724. hp : tnode;
  725. oldexprasmlist : TAAsmoutput;
  726. begin
  727. include(current_procinfo.flags,pi_needs_implicit_finally);
  728. oldexprasmlist:=exprasmlist;
  729. exprasmlist:=asmlist;
  730. hp:=finalize_data_node(cloadnode.create(sym,sym.owner));
  731. firstpass(hp);
  732. secondpass(hp);
  733. hp.free;
  734. exprasmlist:=oldexprasmlist;
  735. end;
  736. { generates the code for finalisation of local variables }
  737. procedure finalize_local_vars(p : tnamedindexitem;arg:pointer);
  738. begin
  739. case tsym(p).typ of
  740. varsym :
  741. begin
  742. if (tvarsym(p).refs>0) and
  743. not(vo_is_funcret in tvarsym(p).varoptions) and
  744. not(is_class(tvarsym(p).vartype.def)) and
  745. tvarsym(p).vartype.def.needs_inittable then
  746. finalize_sym(taasmoutput(arg),tsym(p));
  747. end;
  748. end;
  749. end;
  750. { generates the code for finalisation of local typedconsts }
  751. procedure finalize_local_typedconst(p : tnamedindexitem;arg:pointer);
  752. var
  753. i : longint;
  754. pd : tprocdef;
  755. begin
  756. case tsym(p).typ of
  757. typedconstsym :
  758. begin
  759. if ttypedconstsym(p).is_writable and
  760. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  761. finalize_sym(taasmoutput(arg),tsym(p));
  762. end;
  763. procsym :
  764. begin
  765. for i:=1 to tprocsym(p).procdef_count do
  766. begin
  767. pd:=tprocsym(p).procdef[i];
  768. if assigned(pd.localst) and
  769. (pd.procsym=tprocsym(p)) and
  770. (pd.localst.symtabletype<>staticsymtable) then
  771. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  772. end;
  773. end;
  774. end;
  775. end;
  776. { generates the code for finalization of static symtable and
  777. all local (static) typedconsts }
  778. procedure finalize_static_data(p : tnamedindexitem;arg:pointer);
  779. var
  780. i : longint;
  781. pd : tprocdef;
  782. begin
  783. case tsym(p).typ of
  784. varsym :
  785. begin
  786. if (tvarsym(p).refs>0) and
  787. not(vo_is_funcret in tvarsym(p).varoptions) and
  788. not(is_class(tvarsym(p).vartype.def)) and
  789. tvarsym(p).vartype.def.needs_inittable then
  790. finalize_sym(taasmoutput(arg),tsym(p));
  791. end;
  792. typedconstsym :
  793. begin
  794. if ttypedconstsym(p).is_writable and
  795. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  796. finalize_sym(taasmoutput(arg),tsym(p));
  797. end;
  798. procsym :
  799. begin
  800. for i:=1 to tprocsym(p).procdef_count do
  801. begin
  802. pd:=tprocsym(p).procdef[i];
  803. if assigned(pd.localst) and
  804. (pd.procsym=tprocsym(p)) and
  805. (pd.localst.symtabletype<>staticsymtable) then
  806. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  807. end;
  808. end;
  809. end;
  810. end;
  811. { generates the code for incrementing the reference count of parameters and
  812. initialize out parameters }
  813. procedure init_paras(p : tnamedindexitem;arg:pointer);
  814. var
  815. href : treference;
  816. tmpreg : tregister;
  817. list:TAAsmoutput;
  818. begin
  819. list:=taasmoutput(arg);
  820. if (tsym(p).typ=varsym) and
  821. not is_class(tvarsym(p).vartype.def) and
  822. tvarsym(p).vartype.def.needs_inittable then
  823. begin
  824. case tvarsym(p).varspez of
  825. vs_value :
  826. begin
  827. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  828. internalerror(200309187);
  829. cg.g_incrrefcount(list,tvarsym(p).vartype.def,tvarsym(p).localloc.reference,is_open_array(tvarsym(p).vartype.def));
  830. end;
  831. vs_out :
  832. begin
  833. case tvarsym(p).localloc.loc of
  834. LOC_REFERENCE :
  835. href:=tvarsym(p).localloc.reference;
  836. else
  837. internalerror(2003091810);
  838. end;
  839. tmpreg:=cg.getaddressregister(list);
  840. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,tmpreg);
  841. reference_reset_base(href,tmpreg,0);
  842. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  843. end;
  844. end;
  845. end;
  846. end;
  847. { generates the code for decrementing the reference count of parameters }
  848. procedure final_paras(p : tnamedindexitem;arg:pointer);
  849. var
  850. list:TAAsmoutput;
  851. begin
  852. list:=taasmoutput(arg);
  853. if (tsym(p).typ=varsym) and
  854. not is_class(tvarsym(p).vartype.def) and
  855. tvarsym(p).vartype.def.needs_inittable then
  856. begin
  857. if (tvarsym(p).varspez=vs_value) then
  858. begin
  859. include(current_procinfo.flags,pi_needs_implicit_finally);
  860. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  861. internalerror(200309188);
  862. cg.g_decrrefcount(list,tvarsym(p).vartype.def,tvarsym(p).localloc.reference,is_open_array(tvarsym(p).vartype.def));
  863. end;
  864. end
  865. else if (tsym(p).typ=varsym) and
  866. (tvarsym(p).varspez=vs_value) and
  867. (is_open_array(tvarsym(p).vartype.def) or
  868. is_array_of_const(tvarsym(p).vartype.def)) then
  869. begin
  870. { cdecl functions don't have a high pointer so it is not possible to generate
  871. a local copy }
  872. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  873. cg.g_releasevaluepara_openarray(list,tvarsym(p).localloc.reference);
  874. end;
  875. end;
  876. { Initialize temp ansi/widestrings,interfaces }
  877. procedure inittempvariables(list:taasmoutput);
  878. var
  879. hp : ptemprecord;
  880. href : treference;
  881. begin
  882. hp:=tg.templist;
  883. while assigned(hp) do
  884. begin
  885. if assigned(hp^.def) and
  886. hp^.def.needs_inittable then
  887. begin
  888. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  889. cg.g_initialize(list,hp^.def,href,false);
  890. end;
  891. hp:=hp^.next;
  892. end;
  893. end;
  894. procedure finalizetempvariables(list:taasmoutput);
  895. var
  896. hp : ptemprecord;
  897. href : treference;
  898. begin
  899. hp:=tg.templist;
  900. while assigned(hp) do
  901. begin
  902. if assigned(hp^.def) and
  903. hp^.def.needs_inittable then
  904. begin
  905. include(current_procinfo.flags,pi_needs_implicit_finally);
  906. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  907. cg.g_finalize(list,hp^.def,href,false);
  908. end;
  909. hp:=hp^.next;
  910. end;
  911. end;
  912. procedure gen_load_return_value(list:TAAsmoutput);
  913. var
  914. {$ifndef cpu64bit}
  915. href : treference;
  916. {$endif cpu64bit}
  917. ressym : tvarsym;
  918. resloc,
  919. restmploc : tlocation;
  920. hreg : tregister;
  921. funcretloc : pcgparalocation;
  922. begin
  923. { Is the loading needed? }
  924. if is_void(current_procinfo.procdef.rettype.def) or
  925. (
  926. (po_assembler in current_procinfo.procdef.procoptions) and
  927. (not(assigned(current_procinfo.procdef.funcretsym)) or
  928. (tvarsym(current_procinfo.procdef.funcretsym).refs=0))
  929. ) then
  930. exit;
  931. funcretloc:=current_procinfo.procdef.funcret_paraloc[calleeside].location;
  932. if not assigned(funcretloc) then
  933. internalerror(200408202);
  934. { constructors return self }
  935. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  936. ressym:=tvarsym(current_procinfo.procdef.parast.search('self'))
  937. else
  938. ressym:=tvarsym(current_procinfo.procdef.funcretsym);
  939. if (ressym.refs>0) then
  940. begin
  941. {$ifdef OLDREGVARS}
  942. case ressym.localloc.loc of
  943. LOC_CFPUREGISTER,
  944. LOC_FPUREGISTER:
  945. begin
  946. location_reset(restmploc,LOC_CFPUREGISTER,funcretloc^.size);
  947. restmploc.register:=ressym.localloc.register;
  948. end;
  949. LOC_CREGISTER,
  950. LOC_REGISTER:
  951. begin
  952. location_reset(restmploc,LOC_CREGISTER,funcretloc^.size);
  953. restmploc.register:=ressym.localloc.register;
  954. end;
  955. LOC_MMREGISTER:
  956. begin
  957. location_reset(restmploc,LOC_CMMREGISTER,funcretloc^.size);
  958. restmploc.register:=ressym.localloc.register;
  959. end;
  960. LOC_REFERENCE:
  961. begin
  962. location_reset(restmploc,LOC_REFERENCE,funcretloc^.size);
  963. restmploc.reference:=ressym.localloc.reference;
  964. end;
  965. else
  966. internalerror(200309184);
  967. end;
  968. {$else}
  969. restmploc:=ressym.localloc;
  970. {$endif}
  971. { Here, we return the function result. In most architectures, the value is
  972. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  973. function returns in a register and the caller receives it in an other one }
  974. case funcretloc^.loc of
  975. LOC_REGISTER:
  976. begin
  977. {$ifndef cpu64bit}
  978. if current_procinfo.procdef.funcret_paraloc[calleeside].size in [OS_64,OS_S64] then
  979. begin
  980. current_procinfo.procdef.funcret_paraloc[calleeside].get_location(resloc);
  981. if resloc.loc<>LOC_REGISTER then
  982. internalerror(200409141);
  983. { Load low and high register separate to generate better register
  984. allocation info }
  985. if getsupreg(resloc.registerlow)<first_int_imreg then
  986. begin
  987. cg.getcpuregister(list,resloc.registerlow);
  988. cg.ungetcpuregister(list,resloc.registerlow);
  989. { for the optimizer }
  990. cg.a_reg_alloc(list,resloc.registerlow);
  991. end;
  992. case restmploc.loc of
  993. LOC_REFERENCE :
  994. begin
  995. href:=restmploc.reference;
  996. if target_info.endian=ENDIAN_BIG then
  997. inc(href.offset,4);
  998. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.registerlow);
  999. end;
  1000. LOC_CREGISTER :
  1001. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.registerlow,resloc.registerlow);
  1002. else
  1003. internalerror(200409203);
  1004. end;
  1005. if getsupreg(resloc.registerhigh)<first_int_imreg then
  1006. begin
  1007. cg.getcpuregister(list,resloc.registerhigh);
  1008. cg.ungetcpuregister(list,resloc.registerhigh);
  1009. { for the optimizer }
  1010. cg.a_reg_alloc(list,resloc.registerhigh);
  1011. end;
  1012. case restmploc.loc of
  1013. LOC_REFERENCE :
  1014. begin
  1015. href:=restmploc.reference;
  1016. if target_info.endian=ENDIAN_LITTLE then
  1017. inc(href.offset,4);
  1018. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.registerhigh);
  1019. end;
  1020. LOC_CREGISTER :
  1021. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.registerhigh,resloc.registerhigh);
  1022. else
  1023. internalerror(200409204);
  1024. end;
  1025. end
  1026. else
  1027. {$endif cpu64bit}
  1028. begin
  1029. hreg:=cg.makeregsize(list,funcretloc^.register,restmploc.size);
  1030. if getsupreg(funcretloc^.register)<first_int_imreg then
  1031. begin
  1032. cg.getcpuregister(list,funcretloc^.register);
  1033. cg.ungetcpuregister(list,hreg);
  1034. { for the optimizer }
  1035. cg.a_reg_alloc(list,funcretloc^.register);
  1036. end;
  1037. cg.a_load_loc_reg(list,restmploc.size,restmploc,hreg);
  1038. end;
  1039. end;
  1040. LOC_FPUREGISTER:
  1041. begin
  1042. if getsupreg(funcretloc^.register)<first_fpu_imreg then
  1043. begin
  1044. cg.getcpuregister(list,funcretloc^.register);
  1045. cg.ungetcpuregister(list,funcretloc^.register);
  1046. end;
  1047. cg.a_loadfpu_loc_reg(list,restmploc,funcretloc^.register);
  1048. end;
  1049. LOC_MMREGISTER:
  1050. begin
  1051. if getsupreg(funcretloc^.register)<first_mm_imreg then
  1052. begin
  1053. cg.getcpuregister(list,funcretloc^.register);
  1054. cg.ungetcpuregister(list,funcretloc^.register);
  1055. end;
  1056. cg.a_loadmm_loc_reg(list,restmploc.size,restmploc,funcretloc^.register,mms_movescalar);
  1057. end;
  1058. LOC_INVALID,
  1059. LOC_REFERENCE:
  1060. ;
  1061. else
  1062. internalerror(200405025);
  1063. end;
  1064. end;
  1065. end;
  1066. procedure gen_load_para_value(list:TAAsmoutput);
  1067. procedure get_para(const paraloc:TCGParaLocation);
  1068. begin
  1069. case paraloc.loc of
  1070. LOC_REGISTER :
  1071. begin
  1072. if getsupreg(paraloc.register)<first_int_imreg then
  1073. cg.getcpuregister(list,paraloc.register);
  1074. end;
  1075. LOC_MMREGISTER :
  1076. begin
  1077. if getsupreg(paraloc.register)<first_mm_imreg then
  1078. cg.getcpuregister(list,paraloc.register);
  1079. end;
  1080. LOC_FPUREGISTER :
  1081. begin
  1082. if getsupreg(paraloc.register)<first_fpu_imreg then
  1083. cg.getcpuregister(list,paraloc.register);
  1084. end;
  1085. end;
  1086. end;
  1087. procedure unget_para(const paraloc:TCGParaLocation);
  1088. begin
  1089. case paraloc.loc of
  1090. LOC_REGISTER :
  1091. begin
  1092. if getsupreg(paraloc.register)<first_int_imreg then
  1093. cg.ungetcpuregister(list,paraloc.register);
  1094. end;
  1095. LOC_MMREGISTER :
  1096. begin
  1097. if getsupreg(paraloc.register)<first_mm_imreg then
  1098. cg.ungetcpuregister(list,paraloc.register);
  1099. end;
  1100. LOC_FPUREGISTER :
  1101. begin
  1102. if getsupreg(paraloc.register)<first_fpu_imreg then
  1103. cg.ungetcpuregister(list,paraloc.register);
  1104. end;
  1105. end;
  1106. end;
  1107. procedure gen_load_ref(const paraloc:TCGParaLocation;const ref:treference);
  1108. var
  1109. href : treference;
  1110. begin
  1111. case paraloc.loc of
  1112. LOC_REGISTER :
  1113. cg.a_load_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  1114. LOC_MMREGISTER :
  1115. cg.a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,mms_movescalar);
  1116. LOC_FPUREGISTER :
  1117. cg.a_loadfpu_reg_ref(list,paraloc.size,paraloc.register,ref);
  1118. LOC_REFERENCE :
  1119. begin
  1120. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1121. { use concatcopy, because it can also be a float which fails when
  1122. load_ref_ref is used. Don't copy data when the references are equal }
  1123. if not((href.base=ref.base) and (href.offset=ref.offset)) then
  1124. cg.g_concatcopy(list,href,ref,tcgsize2size[paraloc.size],false);
  1125. end;
  1126. else
  1127. internalerror(2002081302);
  1128. end;
  1129. end;
  1130. procedure gen_load_reg(const paraloc:TCGParaLocation;reg:tregister);
  1131. var
  1132. href : treference;
  1133. begin
  1134. case paraloc.loc of
  1135. LOC_REGISTER :
  1136. cg.a_load_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg);
  1137. LOC_MMREGISTER :
  1138. cg.a_loadmm_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg,mms_movescalar);
  1139. LOC_FPUREGISTER :
  1140. cg.a_loadfpu_reg_reg(list,paraloc.size,paraloc.register,reg);
  1141. LOC_REFERENCE :
  1142. begin
  1143. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1144. case getregtype(reg) of
  1145. R_INTREGISTER :
  1146. cg.a_load_ref_reg(list,paraloc.size,paraloc.size,href,reg);
  1147. R_FPUREGISTER :
  1148. cg.a_loadfpu_ref_reg(list,paraloc.size,href,reg);
  1149. R_MMREGISTER :
  1150. cg.a_loadmm_ref_reg(list,paraloc.size,paraloc.size,href,reg,mms_movescalar);
  1151. else
  1152. internalerror(2004101012);
  1153. end;
  1154. end;
  1155. else
  1156. internalerror(2002081302);
  1157. end;
  1158. end;
  1159. var
  1160. hp : tparaitem;
  1161. paraloc : pcgparalocation;
  1162. tempref,
  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. {$ifdef OLDREGVARS}
  1290. load_regvars(list,nil);
  1291. {$endif OLDREGVARS}
  1292. end;
  1293. procedure gen_finalize_code(list:TAAsmoutput);
  1294. begin
  1295. {$ifdef OLDREGVARS}
  1296. cleanup_regvars(list);
  1297. {$endif OLDREGVARS}
  1298. { finalize temporary data }
  1299. finalizetempvariables(list);
  1300. { finalize local data like ansistrings}
  1301. case current_procinfo.procdef.proctypeoption of
  1302. potype_unitfinalize:
  1303. begin
  1304. { this is also used for initialization of variables in a
  1305. program which does not have a globalsymtable }
  1306. if assigned(current_module.globalsymtable) then
  1307. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1308. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1309. end;
  1310. { units/progs have separate code for initialization and finalization }
  1311. potype_unitinit: ;
  1312. { program init/final is generated in separate procedure }
  1313. potype_proginit: ;
  1314. else
  1315. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_local_vars,list);
  1316. end;
  1317. { finalize paras data }
  1318. if assigned(current_procinfo.procdef.parast) then
  1319. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1320. end;
  1321. procedure gen_entry_code(list:TAAsmoutput);
  1322. var
  1323. href : treference;
  1324. paraloc1,
  1325. paraloc2 : tcgpara;
  1326. hp : tused_unit;
  1327. begin
  1328. paraloc1.init;
  1329. paraloc2.init;
  1330. { the actual profile code can clobber some registers,
  1331. therefore if the context must be saved, do it before
  1332. the actual call to the profile code
  1333. }
  1334. if (cs_profile in aktmoduleswitches) and
  1335. not(po_assembler in current_procinfo.procdef.procoptions) then
  1336. begin
  1337. { non-win32 can call mcout even in main }
  1338. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) or
  1339. not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1340. begin
  1341. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1342. cg.g_profilecode(list);
  1343. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1344. end;
  1345. end;
  1346. { call startup helpers from main program }
  1347. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1348. begin
  1349. { initialize profiling for win32 }
  1350. if (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1351. (cs_profile in aktmoduleswitches) then
  1352. begin
  1353. reference_reset_symbol(href,objectlibrary.newasmsymbol('etext',AB_EXTERNAL,AT_DATA),0);
  1354. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1355. paramanager.getintparaloc(pocall_default,2,paraloc2);
  1356. paramanager.allocparaloc(list,paraloc2);
  1357. cg.a_paramaddr_ref(list,href,paraloc2);
  1358. reference_reset_symbol(href,objectlibrary.newasmsymbol('__image_base__',AB_EXTERNAL,AT_DATA),0);
  1359. paramanager.allocparaloc(list,paraloc1);
  1360. cg.a_paramaddr_ref(list,href,paraloc1);
  1361. paramanager.freeparaloc(list,paraloc2);
  1362. paramanager.freeparaloc(list,paraloc1);
  1363. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1364. cg.a_call_name(list,'_monstartup');
  1365. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1366. end;
  1367. { initialize units }
  1368. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1369. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1370. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1371. {$ifdef GDB}
  1372. if (cs_debuginfo in aktmoduleswitches) then
  1373. if target_info.system <> system_powerpc_macos then
  1374. begin
  1375. { include reference to all debuginfo sections of used units }
  1376. hp:=tused_unit(usedunits.first);
  1377. while assigned(hp) do
  1378. begin
  1379. If (hp.u.flags and uf_has_debuginfo)=uf_has_debuginfo then
  1380. current_procinfo.aktlocaldata.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',hp.u.globalsymtable,''),AT_DATA,0));
  1381. hp:=tused_unit(hp.next);
  1382. end;
  1383. { include reference to debuginfo for this program }
  1384. current_procinfo.aktlocaldata.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
  1385. end;
  1386. {$endif GDB}
  1387. end;
  1388. {$ifdef GDB}
  1389. if (cs_debuginfo in aktmoduleswitches) then
  1390. list.concat(Tai_force_line.Create);
  1391. {$endif GDB}
  1392. {$ifdef OLDREGVARS}
  1393. load_regvars(list,nil);
  1394. {$endif OLDREGVARS}
  1395. paraloc1.done;
  1396. paraloc2.done;
  1397. end;
  1398. procedure gen_exit_code(list:TAAsmoutput);
  1399. begin
  1400. { call __EXIT for main program }
  1401. if (not DLLsource) and
  1402. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1403. cg.a_call_name(list,'FPC_DO_EXIT');
  1404. end;
  1405. {****************************************************************************
  1406. Entry/Exit
  1407. ****************************************************************************}
  1408. procedure gen_proc_symbol(list:Taasmoutput);
  1409. var
  1410. hs : string;
  1411. begin
  1412. { add symbol entry point as well as debug information }
  1413. { will be inserted in front of the rest of this list. }
  1414. { Insert alignment and assembler names }
  1415. { Align, gprof uses 16 byte granularity }
  1416. if (cs_profile in aktmoduleswitches) then
  1417. list.concat(Tai_align.create(16))
  1418. else
  1419. list.concat(Tai_align.create(aktalignment.procalign));
  1420. {$ifdef GDB}
  1421. if (cs_debuginfo in aktmoduleswitches) then
  1422. begin
  1423. if (po_public in current_procinfo.procdef.procoptions) then
  1424. Tprocsym(current_procinfo.procdef.procsym).is_global:=true;
  1425. current_procinfo.procdef.concatstabto(list);
  1426. Tprocsym(current_procinfo.procdef.procsym).isstabwritten:=true;
  1427. end;
  1428. {$endif GDB}
  1429. repeat
  1430. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1431. if hs='' then
  1432. break;
  1433. {$ifdef GDB}
  1434. if (cs_debuginfo in aktmoduleswitches) and
  1435. target_info.use_function_relative_addresses then
  1436. list.concat(Tai_stab_function_name.create(strpnew(hs)));
  1437. {$endif GDB}
  1438. if (cs_profile in aktmoduleswitches) or
  1439. (po_public in current_procinfo.procdef.procoptions) then
  1440. list.concat(Tai_symbol.createname_global(hs,AT_FUNCTION,0))
  1441. else
  1442. list.concat(Tai_symbol.createname(hs,AT_FUNCTION,0));
  1443. until false;
  1444. end;
  1445. procedure gen_proc_symbol_end(list:Taasmoutput);
  1446. {$ifdef GDB}
  1447. var
  1448. stabsendlabel : tasmlabel;
  1449. mangled_length : longint;
  1450. p : pchar;
  1451. {$endif GDB}
  1452. begin
  1453. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1454. {$ifdef GDB}
  1455. if (cs_debuginfo in aktmoduleswitches) then
  1456. begin
  1457. objectlibrary.getlabel(stabsendlabel);
  1458. cg.a_label(list,stabsendlabel);
  1459. { define calling EBP as pseudo local var PM }
  1460. { this enables test if the function is a local one !! }
  1461. {if assigned(current_procinfo.parent) and
  1462. (current_procinfo.procdef.parast.symtablelevel>normal_function_level) then
  1463. list.concat(Tai_stabs.Create(strpnew(
  1464. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1465. tostr(N_LSYM)+',0,0,'+tostr(current_procinfo.parent_framepointer_offset)))); }
  1466. if assigned(current_procinfo.procdef.funcretsym) and
  1467. (tvarsym(current_procinfo.procdef.funcretsym).refs>0) then
  1468. begin
  1469. if tvarsym(current_procinfo.procdef.funcretsym).localloc.loc=LOC_REFERENCE then
  1470. begin
  1471. {$warning Need to add gdb support for ret in param register calling}
  1472. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1473. begin
  1474. list.concat(Tai_stabs.Create(strpnew(
  1475. '"'+current_procinfo.procdef.procsym.name+':X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1476. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1477. if (m_result in aktmodeswitches) then
  1478. list.concat(Tai_stabs.Create(strpnew(
  1479. '"RESULT:X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1480. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))))
  1481. end
  1482. else
  1483. begin
  1484. list.concat(Tai_stabs.Create(strpnew(
  1485. '"'+current_procinfo.procdef.procsym.name+':X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1486. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1487. if (m_result in aktmodeswitches) then
  1488. list.concat(Tai_stabs.Create(strpnew(
  1489. '"RESULT:X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1490. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1491. end;
  1492. end;
  1493. end;
  1494. mangled_length:=length(current_procinfo.procdef.mangledname);
  1495. getmem(p,2*mangled_length+50);
  1496. strpcopy(p,'192,0,0,');
  1497. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1498. if (target_info.use_function_relative_addresses) then
  1499. begin
  1500. strpcopy(strend(p),'-');
  1501. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1502. end;
  1503. list.concat(Tai_stabn.Create(strnew(p)));
  1504. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1505. +current_procinfo.procdef.mangledname))));
  1506. p[0]:='2';p[1]:='2';p[2]:='4';
  1507. strpcopy(strend(p),'_end');}
  1508. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1509. if (target_info.use_function_relative_addresses) then
  1510. begin
  1511. strpcopy(strend(p),'-');
  1512. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1513. end;
  1514. list.concatlist(withdebuglist);
  1515. list.concat(Tai_stabn.Create(strnew(p)));
  1516. { strpnew('224,0,0,'
  1517. +current_procinfo.procdef.mangledname+'_end'))));}
  1518. freemem(p,2*mangled_length+50);
  1519. end;
  1520. {$endif GDB}
  1521. end;
  1522. procedure gen_proc_entry_code(list:Taasmoutput);
  1523. var
  1524. hitemp,
  1525. lotemp,
  1526. stackframe : longint;
  1527. check : boolean;
  1528. paraloc1 : tcgpara;
  1529. href : treference;
  1530. begin
  1531. paraloc1.init;
  1532. { generate call frame marker for dwarf call frame info }
  1533. dwarfcfi.start_frame(list);
  1534. { allocate temp for saving the argument used when
  1535. stack checking uses a register for pushing the stackframe size }
  1536. check:=(cs_check_stack in aktlocalswitches) and (current_procinfo.procdef.proctypeoption<>potype_proginit);
  1537. if check then
  1538. begin
  1539. { Allocate tempspace to store register parameter than
  1540. is destroyed when calling stackchecking code }
  1541. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1542. if paraloc1.location^.loc=LOC_REGISTER then
  1543. tg.GetTemp(list,sizeof(aint),tt_normal,href);
  1544. end;
  1545. { Calculate size of stackframe }
  1546. stackframe:=current_procinfo.calc_stackframe_size;
  1547. { All temps are know, write offsets used for information }
  1548. if (cs_asm_source in aktglobalswitches) then
  1549. begin
  1550. if tg.direction>0 then
  1551. begin
  1552. lotemp:=current_procinfo.tempstart;
  1553. hitemp:=tg.lasttemp;
  1554. end
  1555. else
  1556. begin
  1557. lotemp:=tg.lasttemp;
  1558. hitemp:=current_procinfo.tempstart;
  1559. end;
  1560. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1561. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1562. end;
  1563. { generate target specific proc entry code }
  1564. cg.g_proc_entry(list,stackframe,(po_nostackframe in current_procinfo.procdef.procoptions));
  1565. { Add stack checking code? }
  1566. if check then
  1567. begin
  1568. { The tempspace to store original register is already
  1569. allocated above before the stackframe size is calculated. }
  1570. if paraloc1.location^.loc=LOC_REGISTER then
  1571. cg.a_load_reg_ref(list,OS_INT,OS_INT,paraloc1.location^.register,href);
  1572. paramanager.allocparaloc(list,paraloc1);
  1573. cg.a_param_const(list,OS_INT,stackframe,paraloc1);
  1574. paramanager.freeparaloc(list,paraloc1);
  1575. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1576. cg.a_call_name(list,'FPC_STACKCHECK');
  1577. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1578. if paraloc1.location^.loc=LOC_REGISTER then
  1579. begin
  1580. cg.a_load_ref_reg(list,OS_INT,OS_INT,href,paraloc1.location^.register);
  1581. tg.UnGetTemp(list,href);
  1582. end;
  1583. end;
  1584. paraloc1.done;
  1585. end;
  1586. procedure gen_proc_exit_code(list:Taasmoutput);
  1587. var
  1588. parasize : longint;
  1589. begin
  1590. { c style clearstack does not need to remove parameters from the stack, only the
  1591. return value when it was pushed by arguments }
  1592. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1593. begin
  1594. parasize:=0;
  1595. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1596. inc(parasize,sizeof(aint));
  1597. end
  1598. else
  1599. parasize:=current_procinfo.para_stack_size;
  1600. { generate target specific proc exit code }
  1601. cg.g_proc_exit(list,parasize,(po_nostackframe in current_procinfo.procdef.procoptions));
  1602. { release return registers, needed for optimizer }
  1603. paramanager.freeparaloc(list,current_procinfo.procdef.funcret_paraloc[calleeside]);
  1604. { end of frame marker for call frame info }
  1605. dwarfcfi.end_frame(list);
  1606. end;
  1607. procedure gen_save_used_regs(list:TAAsmoutput);
  1608. begin
  1609. { Pure assembler routines need to save the registers themselves }
  1610. if (po_assembler in current_procinfo.procdef.procoptions) then
  1611. exit;
  1612. { for the save all registers we can simply use a pusha,popa which
  1613. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1614. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1615. cg.g_save_all_registers(list)
  1616. else
  1617. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1618. cg.g_save_standard_registers(list);
  1619. end;
  1620. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tcgpara);
  1621. begin
  1622. { Pure assembler routines need to save the registers themselves }
  1623. if (po_assembler in current_procinfo.procdef.procoptions) then
  1624. exit;
  1625. { for the save all registers we can simply use a pusha,popa which
  1626. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1627. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1628. cg.g_restore_all_registers(list,funcretparaloc)
  1629. else
  1630. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1631. cg.g_restore_standard_registers(list);
  1632. end;
  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. begin
  1646. storefilepos:=aktfilepos;
  1647. aktfilepos:=sym.fileinfo;
  1648. if sym.is_writable then
  1649. curconstsegment:=datasegment
  1650. else
  1651. curconstsegment:=consts;
  1652. l:=sym.getsize;
  1653. { insert cut for smartlinking or alignment }
  1654. maybe_new_object_file(curconstSegment);
  1655. new_section(curconstSegment,sec_rodata,lower(sym.mangledname),const_align(l));
  1656. if (sym.owner.symtabletype=globalsymtable) or
  1657. maybe_smartlink_symbol or
  1658. (assigned(current_procinfo) and
  1659. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1660. DLLSource then
  1661. curconstSegment.concat(Tai_symbol.Createname_global(sym.mangledname,AT_DATA,l))
  1662. else
  1663. curconstSegment.concat(Tai_symbol.Createname(sym.mangledname,AT_DATA,l));
  1664. aktfilepos:=storefilepos;
  1665. end;
  1666. procedure insertbssdata(sym : tvarsym);
  1667. var
  1668. l,varalign : longint;
  1669. storefilepos : tfileposinfo;
  1670. begin
  1671. storefilepos:=aktfilepos;
  1672. aktfilepos:=sym.fileinfo;
  1673. l:=sym.getvaluesize;
  1674. if (vo_is_thread_var in sym.varoptions) then
  1675. inc(l,sizeof(aint));
  1676. varalign:=var_align(l);
  1677. maybe_new_object_file(bssSegment);
  1678. new_section(bssSegment,sec_bss,lower(sym.mangledname),varalign);
  1679. if (sym.owner.symtabletype=globalsymtable) or
  1680. maybe_smartlink_symbol or
  1681. DLLSource or
  1682. (assigned(current_procinfo) and
  1683. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1684. (vo_is_exported in sym.varoptions) or
  1685. (vo_is_C_var in sym.varoptions) then
  1686. bssSegment.concat(Tai_datablock.Create_global(sym.mangledname,l))
  1687. else
  1688. bssSegment.concat(Tai_datablock.Create(sym.mangledname,l));
  1689. aktfilepos:=storefilepos;
  1690. end;
  1691. procedure gen_alloc_symtable(list:TAAsmoutput;st:tsymtable);
  1692. var
  1693. sym : tsym;
  1694. isaddr : boolean;
  1695. cgsize : tcgsize;
  1696. begin
  1697. sym:=tsym(st.symindex.first);
  1698. while assigned(sym) do
  1699. begin
  1700. if (sym.typ=varsym) then
  1701. begin
  1702. with tvarsym(sym) do
  1703. begin
  1704. { Parameters passed to assembler procedures need to be kept
  1705. in the original location }
  1706. if (st.symtabletype=parasymtable) and
  1707. (po_assembler in current_procinfo.procdef.procoptions) then
  1708. begin
  1709. paraitem.paraloc[calleeside].get_location(localloc);
  1710. end
  1711. else
  1712. begin
  1713. isaddr:=(st.symtabletype=parasymtable) and
  1714. paramanager.push_addr_param(varspez,vartype.def,current_procinfo.procdef.proccalloption);
  1715. if isaddr then
  1716. cgsize:=OS_ADDR
  1717. else
  1718. cgsize:=def_cgsize(vartype.def);
  1719. {$ifndef OLDREGVARS}
  1720. { When there is assembler code we can't use regvars }
  1721. if (cs_regvars in aktglobalswitches) and
  1722. not(pi_has_assembler_block in current_procinfo.flags) and
  1723. not(pi_uses_exceptions in current_procinfo.flags) and
  1724. (varregable<>vr_none) 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,getvaluesize,vartype.def,localloc.reference);
  1775. end;
  1776. end;
  1777. localsymtable,
  1778. stt_exceptsymtable :
  1779. begin
  1780. tg.GetLocal(list,getvaluesize,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.225 2004-10-10 21:08:55 peter
  2050. * parameter regvar fixes
  2051. Revision 1.224 2004/10/10 20:51:46 peter
  2052. * fixed sparc compile
  2053. * fixed float regvar loading
  2054. Revision 1.223 2004/10/10 20:22:53 peter
  2055. * symtable allocation rewritten
  2056. * loading of parameters to local temps/regs cleanup
  2057. * regvar support for parameters
  2058. * regvar support for staticsymtable (main body)
  2059. Revision 1.222 2004/10/09 10:51:13 olle
  2060. * Refs to DEBUGINFO_<x> is now not inserted for target MacOS
  2061. Revision 1.221 2004/10/08 20:52:07 florian
  2062. * fixed storage of parameters passed by ref.
  2063. Revision 1.220 2004/10/08 17:09:43 peter
  2064. * tvarsym.varregable added, split vo_regable from varoptions
  2065. Revision 1.219 2004/09/27 15:14:08 peter
  2066. * fix compile for oldregvars
  2067. Revision 1.218 2004/09/26 17:45:30 peter
  2068. * simple regvar support, not yet finished
  2069. Revision 1.217 2004/09/25 14:23:54 peter
  2070. * ungetregister is now only used for cpuregisters, renamed to
  2071. ungetcpuregister
  2072. * renamed (get|unget)explicitregister(s) to ..cpuregister
  2073. * removed location-release/reference_release
  2074. Revision 1.216 2004/09/21 17:25:12 peter
  2075. * paraloc branch merged
  2076. Revision 1.215 2004/09/14 16:33:46 peter
  2077. * release localsymtables when module is compiled
  2078. Revision 1.214 2004/09/13 20:30:05 peter
  2079. * finalize all (also procedure local) typedconst at unit finalization
  2080. Revision 1.213.4.3 2004/09/20 20:46:34 peter
  2081. * register allocation optimized for 64bit loading of parameters
  2082. and return values
  2083. Revision 1.213.4.2 2004/09/17 17:19:26 peter
  2084. * fixed 64 bit unaryminus for sparc
  2085. * fixed 64 bit inlining
  2086. * signness of not operation
  2087. Revision 1.213.4.1 2004/08/31 20:43:06 peter
  2088. * paraloc patch
  2089. Revision 1.213 2004/08/23 11:00:06 michael
  2090. + Patch from Peter to fix debuginfo in constructor.
  2091. Revision 1.212 2004/07/17 13:14:17 jonas
  2092. * don't finalize typed consts (fixes bug3212, but causes memory leak;
  2093. they should be finalized at the end of the module)
  2094. Revision 1.211 2004/07/09 23:41:04 jonas
  2095. * support register parameters for inlined procedures + some inline
  2096. cleanups
  2097. Revision 1.210 2004/07/04 12:24:59 jonas
  2098. * fixed one regvar problem, but regvars are still broken since the dwarf
  2099. merge...
  2100. Revision 1.209 2004/06/29 20:57:21 peter
  2101. * fixed size of exceptbuf
  2102. Revision 1.208 2004/06/20 08:55:29 florian
  2103. * logs truncated
  2104. Revision 1.207 2004/06/16 20:07:08 florian
  2105. * dwarf branch merged
  2106. Revision 1.206 2004/06/01 20:39:33 jonas
  2107. * fixed bug regarding parameters on the ppc (they were allocated twice
  2108. under some circumstances and not at all in others)
  2109. Revision 1.205 2004/05/30 21:41:15 jonas
  2110. * more regvar optimizations in location_force_reg
  2111. Revision 1.204 2004/05/30 21:18:22 jonas
  2112. * some optimizations and associated fixes for better regvar code
  2113. Revision 1.203 2004/05/28 21:14:13 peter
  2114. * first load para's to temps before calling entry code (profile
  2115. }