ncgutil.pas 93 KB

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