ncgutil.pas 95 KB

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