ncgutil.pas 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324
  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. { Retrieve the location of the data pointed to in location l, when the location is
  41. a register it is expected to contain the address of the data }
  42. procedure location_get_data_ref(list:TAAsmoutput;const l:tlocation;var ref:treference;loadref:boolean);
  43. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  44. procedure gen_proc_symbol(list:Taasmoutput);
  45. procedure gen_proc_symbol_end(list:Taasmoutput);
  46. procedure gen_proc_entry_code(list:Taasmoutput);
  47. procedure gen_proc_exit_code(list:Taasmoutput);
  48. procedure gen_stack_check_code(list:Taasmoutput);
  49. procedure gen_save_used_regs(list:TAAsmoutput);
  50. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tcgpara);
  51. procedure gen_initialize_code(list:TAAsmoutput);
  52. procedure gen_finalize_code(list:TAAsmoutput);
  53. procedure gen_entry_code(list:TAAsmoutput);
  54. procedure gen_exit_code(list:TAAsmoutput);
  55. procedure gen_load_para_value(list:TAAsmoutput);
  56. procedure gen_load_return_value(list:TAAsmoutput);
  57. {#
  58. Allocate the buffers for exception management and setjmp environment.
  59. Return a pointer to these buffers, send them to the utility routine
  60. so they are registered, and then call setjmp.
  61. Then compare the result of setjmp with 0, and if not equal
  62. to zero, then jump to exceptlabel.
  63. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  64. It is to note that this routine may be called *after* the stackframe of a
  65. routine has been called, therefore on machines where the stack cannot
  66. be modified, all temps should be allocated on the heap instead of the
  67. stack.
  68. }
  69. const
  70. EXCEPT_BUF_SIZE = 3*sizeof(aint);
  71. type
  72. texceptiontemps=record
  73. jmpbuf,
  74. envbuf,
  75. reasonbuf : treference;
  76. end;
  77. procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
  78. procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
  79. procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;exceptlabel:tasmlabel);
  80. procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  81. procedure insertconstdata(sym : ttypedconstsym);
  82. procedure insertbssdata(sym : tvarsym);
  83. procedure gen_alloc_symtable(list:TAAsmoutput;st:tsymtable);
  84. procedure gen_free_symtable(list:TAAsmoutput;st:tsymtable);
  85. procedure gen_alloc_inline_parast(list:TAAsmoutput;pd:tprocdef);
  86. procedure gen_alloc_inline_funcret(list:TAAsmoutput;pd:tprocdef);
  87. { rtti and init/final }
  88. procedure generate_rtti(p:Ttypesym);
  89. procedure generate_inittable(p:tsym);
  90. implementation
  91. uses
  92. strings,
  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;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. procedure location_get_data_ref(list:TAAsmoutput;const l:tlocation;var ref:treference;loadref:boolean);
  606. begin
  607. case l.loc of
  608. LOC_REGISTER,
  609. LOC_CREGISTER :
  610. begin
  611. if not loadref then
  612. internalerror(200410231);
  613. reference_reset_base(ref,l.register,0);
  614. end;
  615. LOC_REFERENCE,
  616. LOC_CREFERENCE :
  617. begin
  618. if loadref then
  619. begin
  620. reference_reset_base(ref,cg.getaddressregister(list),0);
  621. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,l.reference,ref.base);
  622. end
  623. else
  624. ref:=l.reference;
  625. end;
  626. else
  627. internalerror(200309181);
  628. end;
  629. end;
  630. {*****************************************************************************
  631. Maybe_Save
  632. *****************************************************************************}
  633. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  634. begin
  635. {$ifdef i386}
  636. if (needed>=maxfpuregs) and
  637. (l.loc = LOC_FPUREGISTER) then
  638. begin
  639. location_force_mem(list,l);
  640. maybe_pushfpu:=true;
  641. end
  642. else
  643. maybe_pushfpu:=false;
  644. {$else i386}
  645. maybe_pushfpu:=false;
  646. {$endif i386}
  647. end;
  648. {****************************************************************************
  649. Init/Finalize Code
  650. ****************************************************************************}
  651. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  652. var
  653. href : treference;
  654. hreg : tregister;
  655. list : TAAsmoutput;
  656. hsym : tvarsym;
  657. l : longint;
  658. localcopyloc : tlocation;
  659. begin
  660. list:=taasmoutput(arg);
  661. if (tsym(p).typ=varsym) and
  662. (tvarsym(p).varspez=vs_value) and
  663. (paramanager.push_addr_param(tvarsym(p).varspez,tvarsym(p).vartype.def,current_procinfo.procdef.proccalloption)) then
  664. begin
  665. location_get_data_ref(list,tvarsym(p).localloc,href,true);
  666. if is_open_array(tvarsym(p).vartype.def) or
  667. is_array_of_const(tvarsym(p).vartype.def) then
  668. begin
  669. { cdecl functions don't have a high pointer so it is not possible to generate
  670. a local copy }
  671. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  672. begin
  673. hsym:=tvarsym(tsym(p).owner.search('high'+p.name));
  674. if not assigned(hsym) then
  675. internalerror(200306061);
  676. hreg:=cg.getaddressregister(list);
  677. cg.g_copyvaluepara_openarray(list,href,hsym.localloc,tarraydef(tvarsym(p).vartype.def).elesize,hreg);
  678. cg.a_load_reg_loc(list,OS_ADDR,hreg,tvarsym(p).localloc);
  679. end;
  680. end
  681. else
  682. begin
  683. { Allocate space for the local copy }
  684. l:=tvarsym(p).getsize;
  685. localcopyloc.loc:=LOC_REFERENCE;
  686. localcopyloc.size:=int_cgsize(l);
  687. tg.GetLocal(list,l,tvarsym(p).vartype.def,localcopyloc.reference);
  688. { Copy data }
  689. if is_shortstring(tvarsym(p).vartype.def) then
  690. begin
  691. { this code is only executed before the code for the body and the entry/exit code is generated
  692. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  693. }
  694. include(current_procinfo.flags,pi_do_call);
  695. cg.g_copyshortstring(list,href,localcopyloc.reference,tstringdef(tvarsym(p).vartype.def).len)
  696. end
  697. else
  698. cg.g_concatcopy(list,href,localcopyloc.reference,tvarsym(p).vartype.def.size);
  699. { update localloc of varsym }
  700. tg.Ungetlocal(list,tvarsym(p).localloc.reference);
  701. tvarsym(p).localloc:=localcopyloc;
  702. end;
  703. end;
  704. end;
  705. { initializes the regvars from staticsymtable with 0 }
  706. procedure initialize_regvars(p : tnamedindexitem;arg:pointer);
  707. begin
  708. if (tsym(p).typ=varsym) then
  709. begin
  710. case tvarsym(p).localloc.loc of
  711. LOC_CREGISTER :
  712. cg.a_load_const_reg(taasmoutput(arg),reg_cgsize(tvarsym(p).localloc.register),0,tvarsym(p).localloc.register);
  713. LOC_REFERENCE : ;
  714. else
  715. internalerror(200410124);
  716. end;
  717. end;
  718. end;
  719. { generates the code for initialisation of local data }
  720. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  721. var
  722. oldexprasmlist : TAAsmoutput;
  723. hp : tnode;
  724. begin
  725. if (tsym(p).typ=varsym) and
  726. (tvarsym(p).refs>0) and
  727. not(is_class(tvarsym(p).vartype.def)) and
  728. tvarsym(p).vartype.def.needs_inittable then
  729. begin
  730. oldexprasmlist:=exprasmlist;
  731. exprasmlist:=taasmoutput(arg);
  732. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  733. firstpass(hp);
  734. secondpass(hp);
  735. hp.free;
  736. exprasmlist:=oldexprasmlist;
  737. end;
  738. end;
  739. procedure finalize_sym(asmlist:taasmoutput;sym:tsym);
  740. var
  741. hp : tnode;
  742. oldexprasmlist : TAAsmoutput;
  743. begin
  744. include(current_procinfo.flags,pi_needs_implicit_finally);
  745. oldexprasmlist:=exprasmlist;
  746. exprasmlist:=asmlist;
  747. hp:=finalize_data_node(cloadnode.create(sym,sym.owner));
  748. firstpass(hp);
  749. secondpass(hp);
  750. hp.free;
  751. exprasmlist:=oldexprasmlist;
  752. end;
  753. { generates the code for finalisation of local variables }
  754. procedure finalize_local_vars(p : tnamedindexitem;arg:pointer);
  755. begin
  756. case tsym(p).typ of
  757. varsym :
  758. begin
  759. if (tvarsym(p).refs>0) and
  760. not(vo_is_funcret in tvarsym(p).varoptions) and
  761. not(is_class(tvarsym(p).vartype.def)) and
  762. tvarsym(p).vartype.def.needs_inittable then
  763. finalize_sym(taasmoutput(arg),tsym(p));
  764. end;
  765. end;
  766. end;
  767. { generates the code for finalisation of local typedconsts }
  768. procedure finalize_local_typedconst(p : tnamedindexitem;arg:pointer);
  769. var
  770. i : longint;
  771. pd : tprocdef;
  772. begin
  773. case tsym(p).typ of
  774. typedconstsym :
  775. begin
  776. if ttypedconstsym(p).is_writable and
  777. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  778. finalize_sym(taasmoutput(arg),tsym(p));
  779. end;
  780. procsym :
  781. begin
  782. for i:=1 to tprocsym(p).procdef_count do
  783. begin
  784. pd:=tprocsym(p).procdef[i];
  785. if assigned(pd.localst) and
  786. (pd.procsym=tprocsym(p)) and
  787. (pd.localst.symtabletype<>staticsymtable) then
  788. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  789. end;
  790. end;
  791. end;
  792. end;
  793. { generates the code for finalization of static symtable and
  794. all local (static) typedconsts }
  795. procedure finalize_static_data(p : tnamedindexitem;arg:pointer);
  796. var
  797. i : longint;
  798. pd : tprocdef;
  799. begin
  800. case tsym(p).typ of
  801. varsym :
  802. begin
  803. if (tvarsym(p).refs>0) and
  804. not(vo_is_funcret in tvarsym(p).varoptions) and
  805. not(is_class(tvarsym(p).vartype.def)) and
  806. tvarsym(p).vartype.def.needs_inittable then
  807. finalize_sym(taasmoutput(arg),tsym(p));
  808. end;
  809. typedconstsym :
  810. begin
  811. if ttypedconstsym(p).is_writable and
  812. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  813. finalize_sym(taasmoutput(arg),tsym(p));
  814. end;
  815. procsym :
  816. begin
  817. for i:=1 to tprocsym(p).procdef_count do
  818. begin
  819. pd:=tprocsym(p).procdef[i];
  820. if assigned(pd.localst) and
  821. (pd.procsym=tprocsym(p)) and
  822. (pd.localst.symtabletype<>staticsymtable) then
  823. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  824. end;
  825. end;
  826. end;
  827. end;
  828. { generates the code for incrementing the reference count of parameters and
  829. initialize out parameters }
  830. procedure init_paras(p : tnamedindexitem;arg:pointer);
  831. var
  832. href : treference;
  833. tmpreg : tregister;
  834. list : TAAsmoutput;
  835. begin
  836. list:=taasmoutput(arg);
  837. if (tsym(p).typ=varsym) and
  838. not is_class_or_interface(tvarsym(p).vartype.def) and
  839. tvarsym(p).vartype.def.needs_inittable then
  840. begin
  841. case tvarsym(p).varspez of
  842. vs_value :
  843. begin
  844. location_get_data_ref(list,tvarsym(p).localloc,href,is_open_array(tvarsym(p).vartype.def));
  845. cg.g_incrrefcount(list,tvarsym(p).vartype.def,href);
  846. end;
  847. vs_out :
  848. begin
  849. tmpreg:=cg.getaddressregister(list);
  850. cg.a_load_loc_reg(list,OS_ADDR,tvarsym(p).localloc,tmpreg);
  851. reference_reset_base(href,tmpreg,0);
  852. cg.g_initialize(list,tvarsym(p).vartype.def,href);
  853. end;
  854. end;
  855. end;
  856. end;
  857. { generates the code for decrementing the reference count of parameters }
  858. procedure final_paras(p : tnamedindexitem;arg:pointer);
  859. var
  860. list : TAAsmoutput;
  861. href : treference;
  862. begin
  863. list:=taasmoutput(arg);
  864. if (tsym(p).typ=varsym) and
  865. not is_class_or_interface(tvarsym(p).vartype.def) and
  866. tvarsym(p).vartype.def.needs_inittable then
  867. begin
  868. location_get_data_ref(list,tvarsym(p).localloc,href,is_open_array(tvarsym(p).vartype.def));
  869. if (tvarsym(p).varspez=vs_value) then
  870. begin
  871. include(current_procinfo.flags,pi_needs_implicit_finally);
  872. location_get_data_ref(list,tvarsym(p).localloc,href,is_open_array(tvarsym(p).vartype.def));
  873. cg.g_decrrefcount(list,tvarsym(p).vartype.def,href);
  874. end;
  875. end
  876. else if (tsym(p).typ=varsym) and
  877. (tvarsym(p).varspez=vs_value) and
  878. (is_open_array(tvarsym(p).vartype.def) or
  879. is_array_of_const(tvarsym(p).vartype.def)) then
  880. begin
  881. { cdecl functions don't have a high pointer so it is not possible to generate
  882. a local copy }
  883. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  884. cg.g_releasevaluepara_openarray(list,tvarsym(p).localloc.reference);
  885. end;
  886. end;
  887. { Initialize temp ansi/widestrings,interfaces }
  888. procedure inittempvariables(list:taasmoutput);
  889. var
  890. hp : ptemprecord;
  891. href : treference;
  892. begin
  893. hp:=tg.templist;
  894. while assigned(hp) do
  895. begin
  896. if assigned(hp^.def) and
  897. hp^.def.needs_inittable then
  898. begin
  899. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  900. cg.g_initialize(list,hp^.def,href);
  901. end;
  902. hp:=hp^.next;
  903. end;
  904. end;
  905. procedure finalizetempvariables(list:taasmoutput);
  906. var
  907. hp : ptemprecord;
  908. href : treference;
  909. begin
  910. hp:=tg.templist;
  911. while assigned(hp) do
  912. begin
  913. if assigned(hp^.def) and
  914. hp^.def.needs_inittable then
  915. begin
  916. include(current_procinfo.flags,pi_needs_implicit_finally);
  917. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  918. cg.g_finalize(list,hp^.def,href);
  919. end;
  920. hp:=hp^.next;
  921. end;
  922. end;
  923. procedure gen_load_return_value(list:TAAsmoutput);
  924. var
  925. {$ifndef cpu64bit}
  926. href : treference;
  927. {$endif cpu64bit}
  928. ressym : tvarsym;
  929. resloc,
  930. restmploc : tlocation;
  931. hreg : tregister;
  932. funcretloc : pcgparalocation;
  933. begin
  934. { Is the loading needed? }
  935. if is_void(current_procinfo.procdef.rettype.def) or
  936. (
  937. (po_assembler in current_procinfo.procdef.procoptions) and
  938. (not(assigned(current_procinfo.procdef.funcretsym)) or
  939. (tvarsym(current_procinfo.procdef.funcretsym).refs=0))
  940. ) then
  941. exit;
  942. funcretloc:=current_procinfo.procdef.funcret_paraloc[calleeside].location;
  943. if not assigned(funcretloc) then
  944. internalerror(200408202);
  945. { constructors return self }
  946. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  947. ressym:=tvarsym(current_procinfo.procdef.parast.search('self'))
  948. else
  949. ressym:=tvarsym(current_procinfo.procdef.funcretsym);
  950. if (ressym.refs>0) then
  951. begin
  952. {$ifdef OLDREGVARS}
  953. case ressym.localloc.loc of
  954. LOC_CFPUREGISTER,
  955. LOC_FPUREGISTER:
  956. begin
  957. location_reset(restmploc,LOC_CFPUREGISTER,funcretloc^.size);
  958. restmploc.register:=ressym.localloc.register;
  959. end;
  960. LOC_CREGISTER,
  961. LOC_REGISTER:
  962. begin
  963. location_reset(restmploc,LOC_CREGISTER,funcretloc^.size);
  964. restmploc.register:=ressym.localloc.register;
  965. end;
  966. LOC_MMREGISTER:
  967. begin
  968. location_reset(restmploc,LOC_CMMREGISTER,funcretloc^.size);
  969. restmploc.register:=ressym.localloc.register;
  970. end;
  971. LOC_REFERENCE:
  972. begin
  973. location_reset(restmploc,LOC_REFERENCE,funcretloc^.size);
  974. restmploc.reference:=ressym.localloc.reference;
  975. end;
  976. else
  977. internalerror(200309184);
  978. end;
  979. {$else}
  980. restmploc:=ressym.localloc;
  981. {$endif}
  982. { Here, we return the function result. In most architectures, the value is
  983. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  984. function returns in a register and the caller receives it in an other one }
  985. case funcretloc^.loc of
  986. LOC_REGISTER:
  987. begin
  988. {$ifndef cpu64bit}
  989. if current_procinfo.procdef.funcret_paraloc[calleeside].size in [OS_64,OS_S64] then
  990. begin
  991. current_procinfo.procdef.funcret_paraloc[calleeside].get_location(resloc);
  992. if resloc.loc<>LOC_REGISTER then
  993. internalerror(200409141);
  994. { Load low and high register separate to generate better register
  995. allocation info }
  996. if getsupreg(resloc.registerlow)<first_int_imreg then
  997. begin
  998. cg.getcpuregister(list,resloc.registerlow);
  999. cg.ungetcpuregister(list,resloc.registerlow);
  1000. { for the optimizer }
  1001. cg.a_reg_alloc(list,resloc.registerlow);
  1002. end;
  1003. case restmploc.loc of
  1004. LOC_REFERENCE :
  1005. begin
  1006. href:=restmploc.reference;
  1007. if target_info.endian=ENDIAN_BIG then
  1008. inc(href.offset,4);
  1009. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.registerlow);
  1010. end;
  1011. LOC_CREGISTER :
  1012. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.registerlow,resloc.registerlow);
  1013. else
  1014. internalerror(200409203);
  1015. end;
  1016. if getsupreg(resloc.registerhigh)<first_int_imreg then
  1017. begin
  1018. cg.getcpuregister(list,resloc.registerhigh);
  1019. cg.ungetcpuregister(list,resloc.registerhigh);
  1020. { for the optimizer }
  1021. cg.a_reg_alloc(list,resloc.registerhigh);
  1022. end;
  1023. case restmploc.loc of
  1024. LOC_REFERENCE :
  1025. begin
  1026. href:=restmploc.reference;
  1027. if target_info.endian=ENDIAN_LITTLE then
  1028. inc(href.offset,4);
  1029. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.registerhigh);
  1030. end;
  1031. LOC_CREGISTER :
  1032. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.registerhigh,resloc.registerhigh);
  1033. else
  1034. internalerror(200409204);
  1035. end;
  1036. end
  1037. else
  1038. {$endif cpu64bit}
  1039. begin
  1040. hreg:=cg.makeregsize(list,funcretloc^.register,restmploc.size);
  1041. if getsupreg(funcretloc^.register)<first_int_imreg then
  1042. begin
  1043. cg.getcpuregister(list,funcretloc^.register);
  1044. cg.ungetcpuregister(list,hreg);
  1045. { for the optimizer }
  1046. cg.a_reg_alloc(list,funcretloc^.register);
  1047. end;
  1048. cg.a_load_loc_reg(list,restmploc.size,restmploc,hreg);
  1049. end;
  1050. end;
  1051. LOC_FPUREGISTER:
  1052. begin
  1053. if getsupreg(funcretloc^.register)<first_fpu_imreg then
  1054. begin
  1055. cg.getcpuregister(list,funcretloc^.register);
  1056. cg.ungetcpuregister(list,funcretloc^.register);
  1057. end;
  1058. cg.a_loadfpu_loc_reg(list,restmploc,funcretloc^.register);
  1059. end;
  1060. LOC_MMREGISTER:
  1061. begin
  1062. if getsupreg(funcretloc^.register)<first_mm_imreg then
  1063. begin
  1064. cg.getcpuregister(list,funcretloc^.register);
  1065. cg.ungetcpuregister(list,funcretloc^.register);
  1066. end;
  1067. cg.a_loadmm_loc_reg(list,restmploc.size,restmploc,funcretloc^.register,mms_movescalar);
  1068. end;
  1069. LOC_INVALID,
  1070. LOC_REFERENCE:
  1071. ;
  1072. else
  1073. internalerror(200405025);
  1074. end;
  1075. end;
  1076. end;
  1077. procedure gen_load_para_value(list:TAAsmoutput);
  1078. procedure get_para(const paraloc:TCGParaLocation);
  1079. begin
  1080. case paraloc.loc of
  1081. LOC_REGISTER :
  1082. begin
  1083. if getsupreg(paraloc.register)<first_int_imreg then
  1084. cg.getcpuregister(list,paraloc.register);
  1085. end;
  1086. LOC_MMREGISTER :
  1087. begin
  1088. if getsupreg(paraloc.register)<first_mm_imreg then
  1089. cg.getcpuregister(list,paraloc.register);
  1090. end;
  1091. LOC_FPUREGISTER :
  1092. begin
  1093. if getsupreg(paraloc.register)<first_fpu_imreg then
  1094. cg.getcpuregister(list,paraloc.register);
  1095. end;
  1096. end;
  1097. end;
  1098. procedure unget_para(const paraloc:TCGParaLocation);
  1099. begin
  1100. case paraloc.loc of
  1101. LOC_REGISTER :
  1102. begin
  1103. if getsupreg(paraloc.register)<first_int_imreg then
  1104. cg.ungetcpuregister(list,paraloc.register);
  1105. end;
  1106. LOC_MMREGISTER :
  1107. begin
  1108. if getsupreg(paraloc.register)<first_mm_imreg then
  1109. cg.ungetcpuregister(list,paraloc.register);
  1110. end;
  1111. LOC_FPUREGISTER :
  1112. begin
  1113. if getsupreg(paraloc.register)<first_fpu_imreg then
  1114. cg.ungetcpuregister(list,paraloc.register);
  1115. end;
  1116. end;
  1117. end;
  1118. procedure gen_load_ref(const paraloc:TCGParaLocation;const ref:treference);
  1119. var
  1120. href : treference;
  1121. begin
  1122. case paraloc.loc of
  1123. LOC_REGISTER :
  1124. cg.a_load_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  1125. LOC_MMREGISTER :
  1126. cg.a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,mms_movescalar);
  1127. LOC_FPUREGISTER :
  1128. cg.a_loadfpu_reg_ref(list,paraloc.size,paraloc.register,ref);
  1129. LOC_REFERENCE :
  1130. begin
  1131. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1132. { use concatcopy, because it can also be a float which fails when
  1133. load_ref_ref is used. Don't copy data when the references are equal }
  1134. if not((href.base=ref.base) and (href.offset=ref.offset)) then
  1135. cg.g_concatcopy(list,href,ref,tcgsize2size[paraloc.size]);
  1136. end;
  1137. else
  1138. internalerror(2002081302);
  1139. end;
  1140. end;
  1141. procedure gen_load_reg(const paraloc:TCGParaLocation;reg:tregister);
  1142. var
  1143. href : treference;
  1144. begin
  1145. case paraloc.loc of
  1146. LOC_REGISTER :
  1147. cg.a_load_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg);
  1148. LOC_MMREGISTER :
  1149. cg.a_loadmm_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg,mms_movescalar);
  1150. LOC_FPUREGISTER :
  1151. cg.a_loadfpu_reg_reg(list,paraloc.size,paraloc.register,reg);
  1152. LOC_REFERENCE :
  1153. begin
  1154. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1155. case getregtype(reg) of
  1156. R_INTREGISTER :
  1157. cg.a_load_ref_reg(list,paraloc.size,paraloc.size,href,reg);
  1158. R_FPUREGISTER :
  1159. cg.a_loadfpu_ref_reg(list,paraloc.size,href,reg);
  1160. R_MMREGISTER :
  1161. cg.a_loadmm_ref_reg(list,paraloc.size,paraloc.size,href,reg,mms_movescalar);
  1162. else
  1163. internalerror(2004101012);
  1164. end;
  1165. end;
  1166. else
  1167. internalerror(2002081302);
  1168. end;
  1169. end;
  1170. var
  1171. hp : tparaitem;
  1172. paraloc : pcgparalocation;
  1173. {$ifdef sparc}
  1174. tempref,
  1175. {$endif sparc}
  1176. href : treference;
  1177. begin
  1178. if (po_assembler in current_procinfo.procdef.procoptions) then
  1179. exit;
  1180. { Allocate registers used by parameters }
  1181. hp:=tparaitem(current_procinfo.procdef.para.first);
  1182. while assigned(hp) do
  1183. begin
  1184. paraloc:=hp.paraloc[calleeside].location;
  1185. while assigned(paraloc) do
  1186. begin
  1187. if paraloc^.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER] then
  1188. get_para(paraloc^);
  1189. paraloc:=paraloc^.next;
  1190. end;
  1191. hp:=tparaitem(hp.next);
  1192. end;
  1193. { Copy parameters to local references/registers }
  1194. hp:=tparaitem(current_procinfo.procdef.para.first);
  1195. while assigned(hp) do
  1196. begin
  1197. paraloc:=hp.paraloc[calleeside].location;
  1198. if not assigned(paraloc) then
  1199. internalerror(200408203);
  1200. case tvarsym(hp.parasym).localloc.loc of
  1201. LOC_REFERENCE :
  1202. begin
  1203. href:=tvarsym(hp.parasym).localloc.reference;
  1204. while assigned(paraloc) do
  1205. begin
  1206. unget_para(paraloc^);
  1207. gen_load_ref(paraloc^,href);
  1208. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1209. paraloc:=paraloc^.next;
  1210. end;
  1211. end;
  1212. LOC_CREGISTER :
  1213. begin
  1214. {$ifndef cpu64bit}
  1215. if tvarsym(hp.parasym).localloc.size in [OS_64,OS_S64] then
  1216. begin
  1217. { First 32bits }
  1218. unget_para(paraloc^);
  1219. if (target_info.endian=ENDIAN_BIG) then
  1220. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerhigh)
  1221. else
  1222. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerlow);
  1223. { Second 32bits }
  1224. if not assigned(paraloc^.next) then
  1225. internalerror(200410104);
  1226. unget_para(paraloc^);
  1227. if (target_info.endian=ENDIAN_BIG) then
  1228. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerlow)
  1229. else
  1230. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.registerhigh);
  1231. end
  1232. else
  1233. {$endif cpu64bit}
  1234. begin
  1235. unget_para(paraloc^);
  1236. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.register);
  1237. if assigned(paraloc^.next) then
  1238. internalerror(200410105);
  1239. end;
  1240. end;
  1241. LOC_CFPUREGISTER :
  1242. begin
  1243. {$ifdef sparc}
  1244. { Sparc passes floats in int registers, when loading to fpu register
  1245. we need a temp }
  1246. tg.GetTemp(list,TCGSize2Size[tvarsym(hp.parasym).localloc.size],tt_normal,tempref);
  1247. href:=tempref;
  1248. while assigned(paraloc) do
  1249. begin
  1250. unget_para(paraloc^);
  1251. gen_load_ref(paraloc^,href);
  1252. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1253. paraloc:=paraloc^.next;
  1254. end;
  1255. cg.a_loadfpu_ref_reg(list,tvarsym(hp.parasym).localloc.size,tempref,tvarsym(hp.parasym).localloc.register);
  1256. tg.UnGetTemp(list,tempref);
  1257. {$else sparc}
  1258. unget_para(paraloc^);
  1259. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.register);
  1260. if assigned(paraloc^.next) then
  1261. internalerror(200410109);
  1262. {$endif sparc}
  1263. end;
  1264. LOC_CMMREGISTER :
  1265. begin
  1266. unget_para(paraloc^);
  1267. gen_load_reg(paraloc^,tvarsym(hp.parasym).localloc.register);
  1268. if assigned(paraloc^.next) then
  1269. internalerror(200410108);
  1270. end;
  1271. end;
  1272. hp:=tparaitem(hp.next);
  1273. end;
  1274. { generate copies of call by value parameters, must be done before
  1275. the initialization and body is parsed because the refcounts are
  1276. incremented using the local copies }
  1277. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1278. end;
  1279. procedure gen_initialize_code(list:TAAsmoutput);
  1280. begin
  1281. { initialize local data like ansistrings }
  1282. case current_procinfo.procdef.proctypeoption of
  1283. potype_unitinit:
  1284. begin
  1285. { this is also used for initialization of variables in a
  1286. program which does not have a globalsymtable }
  1287. if assigned(current_module.globalsymtable) then
  1288. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1289. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1290. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_regvars,list);
  1291. end;
  1292. { units have seperate code for initilization and finalization }
  1293. potype_unitfinalize: ;
  1294. { program init/final is generated in separate procedure }
  1295. potype_proginit:
  1296. begin
  1297. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_regvars,list);
  1298. end;
  1299. else
  1300. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1301. end;
  1302. { initialisizes temp. ansi/wide string data }
  1303. inittempvariables(list);
  1304. { initialize ansi/widesstring para's }
  1305. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1306. {$ifdef OLDREGVARS}
  1307. load_regvars(list,nil);
  1308. {$endif OLDREGVARS}
  1309. end;
  1310. procedure gen_finalize_code(list:TAAsmoutput);
  1311. begin
  1312. {$ifdef OLDREGVARS}
  1313. cleanup_regvars(list);
  1314. {$endif OLDREGVARS}
  1315. { finalize temporary data }
  1316. finalizetempvariables(list);
  1317. { finalize local data like ansistrings}
  1318. case current_procinfo.procdef.proctypeoption of
  1319. potype_unitfinalize:
  1320. begin
  1321. { this is also used for initialization of variables in a
  1322. program which does not have a globalsymtable }
  1323. if assigned(current_module.globalsymtable) then
  1324. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1325. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1326. end;
  1327. { units/progs have separate code for initialization and finalization }
  1328. potype_unitinit: ;
  1329. { program init/final is generated in separate procedure }
  1330. potype_proginit: ;
  1331. else
  1332. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_local_vars,list);
  1333. end;
  1334. { finalize paras data }
  1335. if assigned(current_procinfo.procdef.parast) then
  1336. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1337. end;
  1338. procedure gen_entry_code(list:TAAsmoutput);
  1339. var
  1340. href : treference;
  1341. paraloc1,
  1342. paraloc2 : tcgpara;
  1343. hp : tused_unit;
  1344. begin
  1345. paraloc1.init;
  1346. paraloc2.init;
  1347. { the actual profile code can clobber some registers,
  1348. therefore if the context must be saved, do it before
  1349. the actual call to the profile code
  1350. }
  1351. if (cs_profile in aktmoduleswitches) and
  1352. not(po_assembler in current_procinfo.procdef.procoptions) then
  1353. begin
  1354. { non-win32 can call mcout even in main }
  1355. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) or
  1356. not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1357. begin
  1358. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1359. cg.g_profilecode(list);
  1360. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1361. end;
  1362. end;
  1363. { call startup helpers from main program }
  1364. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1365. begin
  1366. { initialize profiling for win32 }
  1367. if (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1368. (cs_profile in aktmoduleswitches) then
  1369. begin
  1370. reference_reset_symbol(href,objectlibrary.newasmsymbol('etext',AB_EXTERNAL,AT_DATA),0);
  1371. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1372. paramanager.getintparaloc(pocall_default,2,paraloc2);
  1373. paramanager.allocparaloc(list,paraloc2);
  1374. cg.a_paramaddr_ref(list,href,paraloc2);
  1375. reference_reset_symbol(href,objectlibrary.newasmsymbol('__image_base__',AB_EXTERNAL,AT_DATA),0);
  1376. paramanager.allocparaloc(list,paraloc1);
  1377. cg.a_paramaddr_ref(list,href,paraloc1);
  1378. paramanager.freeparaloc(list,paraloc2);
  1379. paramanager.freeparaloc(list,paraloc1);
  1380. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1381. cg.a_call_name(list,'_monstartup');
  1382. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1383. end;
  1384. { initialize units }
  1385. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1386. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1387. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1388. {$ifdef GDB}
  1389. if (cs_debuginfo in aktmoduleswitches) then
  1390. if target_info.system <> system_powerpc_macos then
  1391. begin
  1392. { include reference to all debuginfo sections of used units }
  1393. hp:=tused_unit(usedunits.first);
  1394. while assigned(hp) do
  1395. begin
  1396. If (hp.u.flags and uf_has_debuginfo)=uf_has_debuginfo then
  1397. current_procinfo.aktlocaldata.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',hp.u.globalsymtable,''),AT_DATA,0));
  1398. hp:=tused_unit(hp.next);
  1399. end;
  1400. { include reference to debuginfo for this program }
  1401. current_procinfo.aktlocaldata.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
  1402. end;
  1403. {$endif GDB}
  1404. end;
  1405. {$ifdef GDB}
  1406. if (cs_debuginfo in aktmoduleswitches) then
  1407. list.concat(Tai_force_line.Create);
  1408. {$endif GDB}
  1409. {$ifdef OLDREGVARS}
  1410. load_regvars(list,nil);
  1411. {$endif OLDREGVARS}
  1412. paraloc1.done;
  1413. paraloc2.done;
  1414. end;
  1415. procedure gen_exit_code(list:TAAsmoutput);
  1416. begin
  1417. { call __EXIT for main program }
  1418. if (not DLLsource) and
  1419. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1420. cg.a_call_name(list,'FPC_DO_EXIT');
  1421. end;
  1422. {****************************************************************************
  1423. Entry/Exit
  1424. ****************************************************************************}
  1425. procedure gen_proc_symbol(list:Taasmoutput);
  1426. var
  1427. hs : string;
  1428. begin
  1429. { add symbol entry point as well as debug information }
  1430. { will be inserted in front of the rest of this list. }
  1431. { Insert alignment and assembler names }
  1432. { Align, gprof uses 16 byte granularity }
  1433. if (cs_profile in aktmoduleswitches) then
  1434. list.concat(Tai_align.create(16))
  1435. else
  1436. list.concat(Tai_align.create(aktalignment.procalign));
  1437. {$ifdef GDB}
  1438. if (cs_debuginfo in aktmoduleswitches) then
  1439. begin
  1440. if (po_public in current_procinfo.procdef.procoptions) then
  1441. Tprocsym(current_procinfo.procdef.procsym).is_global:=true;
  1442. current_procinfo.procdef.concatstabto(list);
  1443. Tprocsym(current_procinfo.procdef.procsym).isstabwritten:=true;
  1444. end;
  1445. {$endif GDB}
  1446. repeat
  1447. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1448. if hs='' then
  1449. break;
  1450. {$ifdef GDB}
  1451. if (cs_debuginfo in aktmoduleswitches) and
  1452. target_info.use_function_relative_addresses then
  1453. list.concat(Tai_stab_function_name.create(strpnew(hs)));
  1454. {$endif GDB}
  1455. if (cs_profile in aktmoduleswitches) or
  1456. (po_public in current_procinfo.procdef.procoptions) then
  1457. list.concat(Tai_symbol.createname_global(hs,AT_FUNCTION,0))
  1458. else
  1459. list.concat(Tai_symbol.createname(hs,AT_FUNCTION,0));
  1460. until false;
  1461. end;
  1462. procedure gen_proc_symbol_end(list:Taasmoutput);
  1463. {$ifdef GDB}
  1464. var
  1465. stabsendlabel : tasmlabel;
  1466. mangled_length : longint;
  1467. p : pchar;
  1468. {$endif GDB}
  1469. begin
  1470. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1471. {$ifdef GDB}
  1472. if (cs_debuginfo in aktmoduleswitches) then
  1473. begin
  1474. objectlibrary.getlabel(stabsendlabel);
  1475. cg.a_label(list,stabsendlabel);
  1476. { define calling EBP as pseudo local var PM }
  1477. { this enables test if the function is a local one !! }
  1478. {if assigned(current_procinfo.parent) and
  1479. (current_procinfo.procdef.parast.symtablelevel>normal_function_level) then
  1480. list.concat(Tai_stabs.Create(strpnew(
  1481. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1482. tostr(N_LSYM)+',0,0,'+tostr(current_procinfo.parent_framepointer_offset)))); }
  1483. if assigned(current_procinfo.procdef.funcretsym) and
  1484. (tvarsym(current_procinfo.procdef.funcretsym).refs>0) then
  1485. begin
  1486. if tvarsym(current_procinfo.procdef.funcretsym).localloc.loc=LOC_REFERENCE then
  1487. begin
  1488. {$warning Need to add gdb support for ret in param register calling}
  1489. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1490. begin
  1491. list.concat(Tai_stabs.Create(strpnew(
  1492. '"'+current_procinfo.procdef.procsym.name+':X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1493. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1494. if (m_result in aktmodeswitches) then
  1495. list.concat(Tai_stabs.Create(strpnew(
  1496. '"RESULT:X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1497. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))))
  1498. end
  1499. else
  1500. begin
  1501. list.concat(Tai_stabs.Create(strpnew(
  1502. '"'+current_procinfo.procdef.procsym.name+':X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1503. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1504. if (m_result in aktmodeswitches) then
  1505. list.concat(Tai_stabs.Create(strpnew(
  1506. '"RESULT:X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1507. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1508. end;
  1509. end;
  1510. end;
  1511. mangled_length:=length(current_procinfo.procdef.mangledname);
  1512. getmem(p,2*mangled_length+50);
  1513. strpcopy(p,'192,0,0,');
  1514. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1515. if (target_info.use_function_relative_addresses) then
  1516. begin
  1517. strpcopy(strend(p),'-');
  1518. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1519. end;
  1520. list.concat(Tai_stabn.Create(strnew(p)));
  1521. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1522. +current_procinfo.procdef.mangledname))));
  1523. p[0]:='2';p[1]:='2';p[2]:='4';
  1524. strpcopy(strend(p),'_end');}
  1525. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1526. if (target_info.use_function_relative_addresses) then
  1527. begin
  1528. strpcopy(strend(p),'-');
  1529. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1530. end;
  1531. list.concatlist(withdebuglist);
  1532. list.concat(Tai_stabn.Create(strnew(p)));
  1533. { strpnew('224,0,0,'
  1534. +current_procinfo.procdef.mangledname+'_end'))));}
  1535. freemem(p,2*mangled_length+50);
  1536. end;
  1537. {$endif GDB}
  1538. end;
  1539. procedure gen_proc_entry_code(list:Taasmoutput);
  1540. var
  1541. hitemp,
  1542. lotemp : longint;
  1543. begin
  1544. { generate call frame marker for dwarf call frame info }
  1545. dwarfcfi.start_frame(list);
  1546. { All temps are know, write offsets used for information }
  1547. if (cs_asm_source in aktglobalswitches) then
  1548. begin
  1549. if tg.direction>0 then
  1550. begin
  1551. lotemp:=current_procinfo.tempstart;
  1552. hitemp:=tg.lasttemp;
  1553. end
  1554. else
  1555. begin
  1556. lotemp:=tg.lasttemp;
  1557. hitemp:=current_procinfo.tempstart;
  1558. end;
  1559. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1560. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1561. end;
  1562. { generate target specific proc entry code }
  1563. cg.g_proc_entry(list,current_procinfo.calc_stackframe_size,(po_nostackframe in current_procinfo.procdef.procoptions));
  1564. end;
  1565. procedure gen_proc_exit_code(list:Taasmoutput);
  1566. var
  1567. parasize : longint;
  1568. begin
  1569. { c style clearstack does not need to remove parameters from the stack, only the
  1570. return value when it was pushed by arguments }
  1571. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1572. begin
  1573. parasize:=0;
  1574. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1575. inc(parasize,sizeof(aint));
  1576. end
  1577. else
  1578. parasize:=current_procinfo.para_stack_size;
  1579. { generate target specific proc exit code }
  1580. cg.g_proc_exit(list,parasize,(po_nostackframe in current_procinfo.procdef.procoptions));
  1581. { release return registers, needed for optimizer }
  1582. paramanager.freeparaloc(list,current_procinfo.procdef.funcret_paraloc[calleeside]);
  1583. { end of frame marker for call frame info }
  1584. dwarfcfi.end_frame(list);
  1585. end;
  1586. procedure gen_stack_check_code(list:Taasmoutput);
  1587. var
  1588. paraloc1 : tcgpara;
  1589. begin
  1590. paraloc1.init;
  1591. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1592. paramanager.allocparaloc(list,paraloc1);
  1593. cg.a_param_const(list,OS_INT,current_procinfo.calc_stackframe_size,paraloc1);
  1594. paramanager.freeparaloc(list,paraloc1);
  1595. cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1596. cg.a_call_name(list,'FPC_STACKCHECK');
  1597. cg.dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1598. paraloc1.done;
  1599. end;
  1600. procedure gen_save_used_regs(list:TAAsmoutput);
  1601. begin
  1602. { Pure assembler routines need to save the registers themselves }
  1603. if (po_assembler in current_procinfo.procdef.procoptions) then
  1604. exit;
  1605. { oldfpccall expects all registers to be destroyed }
  1606. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1607. cg.g_save_standard_registers(list);
  1608. end;
  1609. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tcgpara);
  1610. begin
  1611. { Pure assembler routines need to save the registers themselves }
  1612. if (po_assembler in current_procinfo.procdef.procoptions) then
  1613. exit;
  1614. { oldfpccall expects all registers to be destroyed }
  1615. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1616. cg.g_restore_standard_registers(list);
  1617. end;
  1618. {****************************************************************************
  1619. Const Data
  1620. ****************************************************************************}
  1621. procedure insertconstdata(sym : ttypedconstsym);
  1622. { this does not affect the local stack space, since all
  1623. typed constansts and initialized variables are always
  1624. put in the .data / .rodata section
  1625. }
  1626. var
  1627. storefilepos : tfileposinfo;
  1628. curconstsegment : taasmoutput;
  1629. l : longint;
  1630. begin
  1631. storefilepos:=aktfilepos;
  1632. aktfilepos:=sym.fileinfo;
  1633. if sym.is_writable then
  1634. curconstsegment:=datasegment
  1635. else
  1636. curconstsegment:=consts;
  1637. l:=sym.getsize;
  1638. { insert cut for smartlinking or alignment }
  1639. maybe_new_object_file(curconstSegment);
  1640. new_section(curconstSegment,sec_rodata,lower(sym.mangledname),const_align(l));
  1641. if (sym.owner.symtabletype=globalsymtable) or
  1642. maybe_smartlink_symbol or
  1643. (assigned(current_procinfo) and
  1644. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1645. DLLSource then
  1646. curconstSegment.concat(Tai_symbol.Createname_global(sym.mangledname,AT_DATA,l))
  1647. else
  1648. curconstSegment.concat(Tai_symbol.Createname(sym.mangledname,AT_DATA,l));
  1649. aktfilepos:=storefilepos;
  1650. end;
  1651. procedure insertbssdata(sym : tvarsym);
  1652. var
  1653. l,varalign : longint;
  1654. storefilepos : tfileposinfo;
  1655. begin
  1656. storefilepos:=aktfilepos;
  1657. aktfilepos:=sym.fileinfo;
  1658. l:=sym.getsize;
  1659. if (vo_is_thread_var in sym.varoptions) then
  1660. inc(l,sizeof(aint));
  1661. varalign:=var_align(l);
  1662. maybe_new_object_file(bssSegment);
  1663. new_section(bssSegment,sec_bss,lower(sym.mangledname),varalign);
  1664. if (sym.owner.symtabletype=globalsymtable) or
  1665. maybe_smartlink_symbol or
  1666. DLLSource or
  1667. (assigned(current_procinfo) and
  1668. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1669. (vo_is_exported in sym.varoptions) or
  1670. (vo_is_C_var in sym.varoptions) then
  1671. bssSegment.concat(Tai_datablock.Create_global(sym.mangledname,l))
  1672. else
  1673. bssSegment.concat(Tai_datablock.Create(sym.mangledname,l));
  1674. aktfilepos:=storefilepos;
  1675. end;
  1676. procedure gen_alloc_symtable(list:TAAsmoutput;st:tsymtable);
  1677. var
  1678. sym : tsym;
  1679. isaddr : boolean;
  1680. cgsize : tcgsize;
  1681. begin
  1682. sym:=tsym(st.symindex.first);
  1683. while assigned(sym) do
  1684. begin
  1685. if (sym.typ=varsym) then
  1686. begin
  1687. with tvarsym(sym) do
  1688. begin
  1689. { Parameters passed to assembler procedures need to be kept
  1690. in the original location }
  1691. if (st.symtabletype=parasymtable) and
  1692. (po_assembler in current_procinfo.procdef.procoptions) then
  1693. begin
  1694. paraitem.paraloc[calleeside].get_location(localloc);
  1695. end
  1696. else
  1697. begin
  1698. isaddr:=(st.symtabletype=parasymtable) and
  1699. paramanager.push_addr_param(varspez,vartype.def,current_procinfo.procdef.proccalloption);
  1700. if isaddr then
  1701. cgsize:=OS_ADDR
  1702. else
  1703. cgsize:=def_cgsize(vartype.def);
  1704. {$ifndef OLDREGVARS}
  1705. { When there is assembler code we can't use regvars }
  1706. if is_regvar then
  1707. begin
  1708. localloc.size:=cgsize;
  1709. case varregable of
  1710. vr_intreg :
  1711. begin
  1712. localloc.loc:=LOC_CREGISTER;
  1713. {$ifndef cpu64bit}
  1714. if cgsize in [OS_64,OS_S64] then
  1715. begin
  1716. localloc.registerlow:=cg.getintregister(list,OS_32);
  1717. localloc.registerhigh:=cg.getintregister(list,OS_32);
  1718. end
  1719. else
  1720. {$endif cpu64bit}
  1721. localloc.register:=cg.getintregister(list,cgsize);
  1722. end;
  1723. vr_fpureg :
  1724. begin
  1725. localloc.loc:=LOC_CFPUREGISTER;
  1726. localloc.register:=cg.getfpuregister(list,cgsize);
  1727. end;
  1728. vr_mmreg :
  1729. begin
  1730. localloc.loc:=LOC_CMMREGISTER;
  1731. localloc.register:=cg.getmmregister(list,cgsize);
  1732. end;
  1733. else
  1734. internalerror(2004101010);
  1735. end;
  1736. { Allocate register already, to prevent first allocation to be
  1737. inside a loop }
  1738. cg.a_reg_sync(list,localloc.register);
  1739. end
  1740. else
  1741. {$endif NOT OLDREGVARS}
  1742. begin
  1743. localloc.loc:=LOC_REFERENCE;
  1744. localloc.size:=cgsize;
  1745. case st.symtabletype of
  1746. parasymtable :
  1747. begin
  1748. { Reuse the parameter location for values to are at a single location on the stack }
  1749. if (paraitem.paraloc[calleeside].is_simple_reference) then
  1750. begin
  1751. reference_reset_base(localloc.reference,paraitem.paraloc[calleeside].location^.reference.index,
  1752. paraitem.paraloc[calleeside].location^.reference.offset);
  1753. end
  1754. else
  1755. begin
  1756. if isaddr then
  1757. tg.GetLocal(list,sizeof(aint),voidpointertype.def,localloc.reference)
  1758. else
  1759. tg.GetLocal(list,getsize,vartype.def,localloc.reference);
  1760. end;
  1761. end;
  1762. localsymtable,
  1763. stt_exceptsymtable :
  1764. begin
  1765. tg.GetLocal(list,getsize,vartype.def,localloc.reference);
  1766. end;
  1767. staticsymtable :
  1768. begin
  1769. { PIC, DLL and Threadvar need extra code and are handled in ncgld }
  1770. if not(cs_create_pic in aktmoduleswitches) and
  1771. not(vo_is_dll_var in varoptions) and
  1772. not(vo_is_thread_var in varoptions) then
  1773. reference_reset_symbol(localloc.reference,objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_NONE),0);
  1774. end;
  1775. else
  1776. internalerror(200410103);
  1777. end;
  1778. end;
  1779. end;
  1780. if cs_asm_source in aktglobalswitches then
  1781. begin
  1782. case localloc.loc of
  1783. LOC_REGISTER,
  1784. LOC_CREGISTER :
  1785. begin
  1786. if (cs_no_regalloc in aktglobalswitches) then
  1787. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located in register '+
  1788. std_regname(localloc.register))))
  1789. else
  1790. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located in register')));
  1791. end;
  1792. LOC_REFERENCE :
  1793. begin
  1794. if not assigned(localloc.reference.symbol) then
  1795. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located at '+
  1796. std_regname(localloc.reference.base)+tostr_with_plus(localloc.reference.offset))));
  1797. end;
  1798. end;
  1799. end;
  1800. end;
  1801. end;
  1802. sym:=tsym(sym.indexnext);
  1803. end;
  1804. end;
  1805. procedure gen_free_symtable(list:TAAsmoutput;st:tsymtable);
  1806. var
  1807. sym : tsym;
  1808. begin
  1809. sym:=tsym(st.symindex.first);
  1810. while assigned(sym) do
  1811. begin
  1812. if (sym.typ=varsym) then
  1813. begin
  1814. with tvarsym(sym) do
  1815. begin
  1816. { Note: We need to keep the data available in memory
  1817. for the sub procedures that can access local data
  1818. in the parent procedures }
  1819. case localloc.loc of
  1820. LOC_CREGISTER :
  1821. cg.a_reg_sync(list,localloc.register);
  1822. LOC_REFERENCE :
  1823. begin
  1824. case st.symtabletype of
  1825. localsymtable,
  1826. parasymtable,
  1827. stt_exceptsymtable :
  1828. tg.Ungetlocal(list,localloc.reference);
  1829. end;
  1830. end;
  1831. end;
  1832. end;
  1833. end;
  1834. sym:=tsym(sym.indexnext);
  1835. end;
  1836. end;
  1837. procedure gen_alloc_inline_parast(list:TAAsmoutput;pd:tprocdef);
  1838. var
  1839. sym : tsym;
  1840. calleeparaloc,
  1841. callerparaloc : pcgparalocation;
  1842. begin
  1843. if (po_assembler in pd.procoptions) then
  1844. exit;
  1845. sym:=tsym(pd.parast.symindex.first);
  1846. while assigned(sym) do
  1847. begin
  1848. if sym.typ=varsym then
  1849. begin
  1850. with tvarsym(sym) do
  1851. begin
  1852. { for localloc <> LOC_REFERENCE, we need regvar support inside inlined procedures }
  1853. localloc.loc:=LOC_REFERENCE;
  1854. localloc.size:=int_cgsize(paramanager.push_size(varspez,vartype.def,pocall_inline));
  1855. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1856. calleeparaloc:=paraitem.paraloc[calleeside].location;
  1857. callerparaloc:=paraitem.paraloc[callerside].location;
  1858. while assigned(calleeparaloc) do
  1859. begin
  1860. if not assigned(callerparaloc) then
  1861. internalerror(200408281);
  1862. if calleeparaloc^.loc<>callerparaloc^.loc then
  1863. internalerror(200408282);
  1864. case calleeparaloc^.loc of
  1865. LOC_FPUREGISTER:
  1866. begin
  1867. calleeparaloc^.register:=cg.getfpuregister(list,calleeparaloc^.size);
  1868. callerparaloc^.register:=calleeparaloc^.register;
  1869. end;
  1870. LOC_REGISTER:
  1871. begin
  1872. calleeparaloc^.register:=cg.getintregister(list,calleeparaloc^.size);
  1873. callerparaloc^.register:=calleeparaloc^.register;
  1874. end;
  1875. LOC_MMREGISTER:
  1876. begin
  1877. calleeparaloc^.register:=cg.getmmregister(list,calleeparaloc^.size);
  1878. callerparaloc^.register:=calleeparaloc^.register;
  1879. end;
  1880. LOC_REFERENCE:
  1881. begin
  1882. calleeparaloc^.reference.offset := localloc.reference.offset;
  1883. calleeparaloc^.reference.index := localloc.reference.base;
  1884. callerparaloc^.reference.offset := localloc.reference.offset;
  1885. callerparaloc^.reference.index := localloc.reference.base;
  1886. end;
  1887. end;
  1888. calleeparaloc:=calleeparaloc^.next;
  1889. callerparaloc:=callerparaloc^.next;
  1890. end;
  1891. if cs_asm_source in aktglobalswitches then
  1892. begin
  1893. case localloc.loc of
  1894. LOC_REFERENCE :
  1895. list.concat(Tai_comment.Create(strpnew('Para '+realname+' allocated at '+
  1896. std_regname(localloc.reference.base)+tostr_with_plus(localloc.reference.offset))));
  1897. end;
  1898. end;
  1899. end;
  1900. end;
  1901. sym:=tsym(sym.indexnext);
  1902. end;
  1903. end;
  1904. procedure gen_alloc_inline_funcret(list:TAAsmoutput;pd:tprocdef);
  1905. var
  1906. calleeparaloc,
  1907. callerparaloc : pcgparalocation;
  1908. begin
  1909. if not assigned(pd.funcretsym) or
  1910. (po_assembler in pd.procoptions) then
  1911. exit;
  1912. { for localloc <> LOC_REFERENCE, we need regvar support inside inlined procedures }
  1913. with tvarsym(pd.funcretsym) do
  1914. begin
  1915. localloc.loc:=LOC_REFERENCE;
  1916. localloc.size:=int_cgsize(paramanager.push_size(varspez,vartype.def,pocall_inline));
  1917. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1918. calleeparaloc:=pd.funcret_paraloc[calleeside].location;
  1919. callerparaloc:=pd.funcret_paraloc[callerside].location;
  1920. while assigned(calleeparaloc) do
  1921. begin
  1922. if not assigned(callerparaloc) then
  1923. internalerror(200408281);
  1924. if calleeparaloc^.loc<>callerparaloc^.loc then
  1925. internalerror(200408282);
  1926. case calleeparaloc^.loc of
  1927. LOC_FPUREGISTER:
  1928. begin
  1929. calleeparaloc^.register:=cg.getfpuregister(list,calleeparaloc^.size);
  1930. callerparaloc^.register:=calleeparaloc^.register;
  1931. end;
  1932. LOC_REGISTER:
  1933. begin
  1934. calleeparaloc^.register:=cg.getintregister(list,calleeparaloc^.size);
  1935. callerparaloc^.register:=calleeparaloc^.register;
  1936. end;
  1937. LOC_MMREGISTER:
  1938. begin
  1939. calleeparaloc^.register:=cg.getmmregister(list,calleeparaloc^.size);
  1940. callerparaloc^.register:=calleeparaloc^.register;
  1941. end;
  1942. LOC_REFERENCE:
  1943. begin
  1944. calleeparaloc^.reference.offset := localloc.reference.offset;
  1945. calleeparaloc^.reference.index := localloc.reference.base;
  1946. callerparaloc^.reference.offset := localloc.reference.offset;
  1947. callerparaloc^.reference.index := localloc.reference.base;
  1948. end;
  1949. end;
  1950. calleeparaloc:=calleeparaloc^.next;
  1951. callerparaloc:=callerparaloc^.next;
  1952. end;
  1953. if cs_asm_source in aktglobalswitches then
  1954. begin
  1955. case localloc.loc of
  1956. LOC_REFERENCE :
  1957. list.concat(Tai_comment.Create(strpnew('Funcret '+realname+' allocated at '+
  1958. std_regname(localloc.reference.base)+tostr_with_plus(localloc.reference.offset))));
  1959. end;
  1960. end;
  1961. end;
  1962. end;
  1963. { persistent rtti generation }
  1964. procedure generate_rtti(p:Ttypesym);
  1965. var
  1966. rsym : trttisym;
  1967. def : tstoreddef;
  1968. begin
  1969. { rtti can only be generated for classes that are always typesyms }
  1970. def:=tstoreddef(ttypesym(p).restype.def);
  1971. { there is an error, skip rtti info }
  1972. if (def.deftype=errordef) or (Errorcount>0) then
  1973. exit;
  1974. { only create rtti once for each definition }
  1975. if not(df_has_rttitable in def.defoptions) then
  1976. begin
  1977. { definition should be in the same symtable as the symbol }
  1978. if p.owner<>def.owner then
  1979. internalerror(200108262);
  1980. { create rttisym }
  1981. rsym:=trttisym.create(p.name,fullrtti);
  1982. p.owner.insert(rsym);
  1983. { register rttisym in definition }
  1984. include(def.defoptions,df_has_rttitable);
  1985. def.rttitablesym:=rsym;
  1986. { write rtti data }
  1987. def.write_child_rtti_data(fullrtti);
  1988. maybe_new_object_file(rttilist);
  1989. new_section(rttilist,sec_rodata,rsym.get_label.name,const_align(sizeof(aint)));
  1990. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  1991. def.write_rtti_data(fullrtti);
  1992. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  1993. end;
  1994. end;
  1995. { persistent init table generation }
  1996. procedure generate_inittable(p:tsym);
  1997. var
  1998. rsym : trttisym;
  1999. def : tstoreddef;
  2000. begin
  2001. { anonymous types are also allowed for records that can be varsym }
  2002. case p.typ of
  2003. typesym :
  2004. def:=tstoreddef(ttypesym(p).restype.def);
  2005. varsym :
  2006. def:=tstoreddef(tvarsym(p).vartype.def);
  2007. else
  2008. internalerror(200108263);
  2009. end;
  2010. { only create inittable once for each definition }
  2011. if not(df_has_inittable in def.defoptions) then
  2012. begin
  2013. { definition should be in the same symtable as the symbol }
  2014. if p.owner<>def.owner then
  2015. internalerror(200108264);
  2016. { create rttisym }
  2017. rsym:=trttisym.create(p.name,initrtti);
  2018. p.owner.insert(rsym);
  2019. { register rttisym in definition }
  2020. include(def.defoptions,df_has_inittable);
  2021. def.inittablesym:=rsym;
  2022. { write inittable data }
  2023. def.write_child_rtti_data(initrtti);
  2024. maybe_new_object_file(rttilist);
  2025. new_section(rttilist,sec_rodata,rsym.get_label.name,const_align(sizeof(aint)));
  2026. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  2027. def.write_rtti_data(initrtti);
  2028. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2029. end;
  2030. end;
  2031. end.
  2032. {
  2033. $Log$
  2034. Revision 1.232 2004-10-26 15:03:31 peter
  2035. * localloc of staticsymtable needs a AT_NONE since it is a reference
  2036. Revision 1.231 2004/10/24 20:01:08 peter
  2037. * remove saveregister calling convention
  2038. Revision 1.230 2004/10/24 11:44:28 peter
  2039. * small regvar fixes
  2040. * loadref parameter removed from concatcopy,incrrefcount,etc
  2041. Revision 1.229 2004/10/15 09:14:17 mazen
  2042. - remove $IFDEF DELPHI and related code
  2043. - remove $IFDEF FPCPROCVAR and related code
  2044. Revision 1.228 2004/10/14 17:54:06 peter
  2045. * add reg_sync when regvars are allocated to fix first use in
  2046. loop
  2047. Revision 1.227 2004/10/13 21:12:51 peter
  2048. * -Or fixes for open array
  2049. Revision 1.226 2004/10/11 15:48:15 peter
  2050. * small regvar for para fixes
  2051. * function tvarsym.is_regvar added
  2052. * tvarsym.getvaluesize removed, use getsize instead
  2053. Revision 1.225 2004/10/10 21:08:55 peter
  2054. * parameter regvar fixes
  2055. Revision 1.224 2004/10/10 20:51:46 peter
  2056. * fixed sparc compile
  2057. * fixed float regvar loading
  2058. Revision 1.223 2004/10/10 20:22:53 peter
  2059. * symtable allocation rewritten
  2060. * loading of parameters to local temps/regs cleanup
  2061. * regvar support for parameters
  2062. * regvar support for staticsymtable (main body)
  2063. Revision 1.222 2004/10/09 10:51:13 olle
  2064. * Refs to DEBUGINFO_<x> is now not inserted for target MacOS
  2065. Revision 1.221 2004/10/08 20:52:07 florian
  2066. * fixed storage of parameters passed by ref.
  2067. Revision 1.220 2004/10/08 17:09:43 peter
  2068. * tvarsym.varregable added, split vo_regable from varoptions
  2069. Revision 1.219 2004/09/27 15:14:08 peter
  2070. * fix compile for oldregvars
  2071. Revision 1.218 2004/09/26 17:45:30 peter
  2072. * simple regvar support, not yet finished
  2073. Revision 1.217 2004/09/25 14:23:54 peter
  2074. * ungetregister is now only used for cpuregisters, renamed to
  2075. ungetcpuregister
  2076. * renamed (get|unget)explicitregister(s) to ..cpuregister
  2077. * removed location-release/reference_release
  2078. Revision 1.216 2004/09/21 17:25:12 peter
  2079. * paraloc branch merged
  2080. Revision 1.215 2004/09/14 16:33:46 peter
  2081. * release localsymtables when module is compiled
  2082. Revision 1.214 2004/09/13 20:30:05 peter
  2083. * finalize all (also procedure local) typedconst at unit finalization
  2084. Revision 1.213.4.3 2004/09/20 20:46:34 peter
  2085. * register allocation optimized for 64bit loading of parameters
  2086. and return values
  2087. Revision 1.213.4.2 2004/09/17 17:19:26 peter
  2088. * fixed 64 bit unaryminus for sparc
  2089. * fixed 64 bit inlining
  2090. * signness of not operation
  2091. Revision 1.213.4.1 2004/08/31 20:43:06 peter
  2092. * paraloc patch
  2093. Revision 1.213 2004/08/23 11:00:06 michael
  2094. + Patch from Peter to fix debuginfo in constructor.
  2095. Revision 1.212 2004/07/17 13:14:17 jonas
  2096. * don't finalize typed consts (fixes bug3212, but causes memory leak;
  2097. they should be finalized at the end of the module)
  2098. Revision 1.211 2004/07/09 23:41:04 jonas
  2099. * support register parameters for inlined procedures + some inline
  2100. cleanups
  2101. Revision 1.210 2004/07/04 12:24:59 jonas
  2102. * fixed one regvar problem, but regvars are still broken since the dwarf
  2103. merge...
  2104. Revision 1.209 2004/06/29 20:57:21 peter
  2105. * fixed size of exceptbuf
  2106. Revision 1.208 2004/06/20 08:55:29 florian
  2107. * logs truncated
  2108. Revision 1.207 2004/06/16 20:07:08 florian
  2109. * dwarf branch merged
  2110. Revision 1.206 2004/06/01 20:39:33 jonas
  2111. * fixed bug regarding parameters on the ppc (they were allocated twice
  2112. under some circumstances and not at all in others)
  2113. Revision 1.205 2004/05/30 21:41:15 jonas
  2114. * more regvar optimizations in location_force_reg
  2115. Revision 1.204 2004/05/30 21:18:22 jonas
  2116. * some optimizations and associated fixes for better regvar code
  2117. Revision 1.203 2004/05/28 21:14:13 peter
  2118. * first load para's to temps before calling entry code (profile
  2119. }