ncgutil.pas 90 KB

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