ncgutil.pas 98 KB

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