ncgutil.pas 90 KB

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