ncgutil.pas 89 KB

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