ncgutil.pas 92 KB

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