ncgutil.pas 91 KB

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