ncgutil.pas 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Helper routines for all code generators
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncgutil;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,cpuinfo,
  22. globtype,
  23. cpubase,cgbase,parabase,cgutils,
  24. aasmbase,aasmtai,aasmdata,aasmcpu,
  25. symconst,symbase,symdef,symsym,symtype,symtable
  26. {$ifndef cpu64bit}
  27. ,cg64f32
  28. {$endif cpu64bit}
  29. ;
  30. type
  31. tloadregvars = (lr_dont_load_regvars, lr_load_regvars);
  32. pusedregvars = ^tusedregvars;
  33. tusedregvars = record
  34. intregvars, fpuregvars, mmregvars: Tsuperregisterworklist;
  35. end;
  36. {
  37. Not used currently, implemented because I thought we had to
  38. synchronise around if/then/else as well, but not needed. May
  39. still be useful for SSA once we get around to implementing
  40. that (JM)
  41. pusedregvarscommon = ^tusedregvarscommon;
  42. tusedregvarscommon = record
  43. allregvars, commonregvars, myregvars: tusedregvars;
  44. end;
  45. }
  46. procedure firstcomplex(p : tbinarynode);
  47. procedure maketojumpbool(list:TAsmList; p : tnode; loadregvars: tloadregvars);
  48. // procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  49. procedure location_force_reg(list:TAsmList;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  50. procedure location_force_fpureg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  51. procedure location_force_mem(list:TAsmList;var l:tlocation);
  52. procedure location_force_mmregscalar(list:TAsmList;var l: tlocation;maybeconst:boolean);
  53. procedure location_force_mmreg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  54. procedure register_maybe_adjust_setbase(list: TAsmList; var l: tlocation; setbase: aint);
  55. { Retrieve the location of the data pointed to in location l, when the location is
  56. a register it is expected to contain the address of the data }
  57. procedure location_get_data_ref(list:TAsmList;const l:tlocation;var ref:treference;loadref:boolean);
  58. function has_alias_name(pd:tprocdef;const s:string):boolean;
  59. procedure alloc_proc_symbol(pd: tprocdef);
  60. procedure gen_proc_symbol(list:TAsmList);
  61. procedure gen_proc_symbol_end(list:TAsmList);
  62. procedure gen_proc_entry_code(list:TAsmList);
  63. procedure gen_proc_exit_code(list:TAsmList);
  64. procedure gen_stack_check_size_para(list:TAsmList);
  65. procedure gen_stack_check_call(list:TAsmList);
  66. procedure gen_save_used_regs(list:TAsmList);
  67. procedure gen_restore_used_regs(list:TAsmList);
  68. procedure gen_initialize_code(list:TAsmList);
  69. procedure gen_finalize_code(list:TAsmList);
  70. procedure gen_entry_code(list:TAsmList);
  71. procedure gen_exit_code(list:TAsmList);
  72. procedure gen_load_para_value(list:TAsmList);
  73. procedure gen_load_return_value(list:TAsmList);
  74. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  75. procedure gen_intf_wrappers(list:TAsmList;st:TSymtable);
  76. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  77. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  78. { adds the regvars used in n and its children to rv.allregvars,
  79. those which were already in rv.allregvars to rv.commonregvars and
  80. uses rv.myregvars as scratch (so that two uses of the same regvar
  81. in a single tree to make it appear in commonregvars). Useful to
  82. find out which regvars are used in two different node trees
  83. (e.g. in the "else" and "then" path, or in various case blocks }
  84. // procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  85. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  86. { if the result of n is a LOC_C(..)REGISTER, try to find the corresponding }
  87. { loadn and change its location to a new register (= SSA). In case reload }
  88. { is true, transfer the old to the new register }
  89. procedure maybechangeloadnodereg(list: TAsmList; var n: tnode; reload: boolean);
  90. {#
  91. Allocate the buffers for exception management and setjmp environment.
  92. Return a pointer to these buffers, send them to the utility routine
  93. so they are registered, and then call setjmp.
  94. Then compare the result of setjmp with 0, and if not equal
  95. to zero, then jump to exceptlabel.
  96. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  97. It is to note that this routine may be called *after* the stackframe of a
  98. routine has been called, therefore on machines where the stack cannot
  99. be modified, all temps should be allocated on the heap instead of the
  100. stack.
  101. }
  102. const
  103. EXCEPT_BUF_SIZE = 3*sizeof(aint);
  104. type
  105. texceptiontemps=record
  106. jmpbuf,
  107. envbuf,
  108. reasonbuf : treference;
  109. end;
  110. procedure get_exception_temps(list:TAsmList;var t:texceptiontemps);
  111. procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  112. procedure new_exception(list:TAsmList;const t:texceptiontemps;exceptlabel:tasmlabel);
  113. procedure free_exception(list:TAsmList;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  114. procedure insertbssdata(sym : tstaticvarsym);
  115. procedure gen_alloc_symtable(list:TAsmList;st:TSymtable);
  116. procedure gen_free_symtable(list:TAsmList;st:TSymtable);
  117. procedure location_free(list: TAsmList; const location : TLocation);
  118. function getprocalign : shortint;
  119. procedure gen_pic_helpers(list : TAsmList);
  120. implementation
  121. uses
  122. version,
  123. cutils,cclasses,
  124. globals,systems,verbose,
  125. ppu,defutil,
  126. procinfo,paramgr,fmodule,
  127. regvars,dbgbase,
  128. pass_1,pass_2,
  129. nbas,ncon,nld,nmem,nutils,
  130. tgobj,cgobj
  131. {$ifdef powerpc}
  132. , cpupi
  133. {$endif}
  134. {$ifdef powerpc64}
  135. , cpupi
  136. {$endif}
  137. {$ifdef SUPPORT_MMX}
  138. , cgx86
  139. {$endif SUPPORT_MMX}
  140. ;
  141. {*****************************************************************************
  142. Misc Helpers
  143. *****************************************************************************}
  144. procedure location_free(list: TAsmList; const location : TLocation);
  145. begin
  146. case location.loc of
  147. LOC_VOID:
  148. ;
  149. LOC_REGISTER,
  150. LOC_CREGISTER:
  151. begin
  152. if getsupreg(location.register)<first_int_imreg then
  153. cg.ungetcpuregister(list,location.register);
  154. end;
  155. LOC_FPUREGISTER,
  156. LOC_CFPUREGISTER:
  157. begin
  158. if getsupreg(location.register)<first_fpu_imreg then
  159. cg.ungetcpuregister(list,location.register);
  160. end;
  161. LOC_MMREGISTER,
  162. LOC_CMMREGISTER :
  163. begin
  164. if getsupreg(location.register)<first_mm_imreg then
  165. cg.ungetcpuregister(list,location.register);
  166. end;
  167. LOC_REFERENCE,
  168. LOC_CREFERENCE :
  169. begin
  170. if use_fixed_stack then
  171. location_freetemp(list,location);
  172. end;
  173. else
  174. internalerror(2004110211);
  175. end;
  176. end;
  177. procedure firstcomplex(p : tbinarynode);
  178. begin
  179. { always calculate boolean AND and OR from left to right }
  180. if (p.nodetype in [orn,andn]) and
  181. is_boolean(p.left.resultdef) then
  182. begin
  183. if nf_swapped in p.flags then
  184. internalerror(200709253);
  185. end
  186. else
  187. if node_resources_fpu(p.right)>node_resources_fpu(p.left) then
  188. p.swapleftright;
  189. end;
  190. procedure maketojumpbool(list:TAsmList; p : tnode; loadregvars: tloadregvars);
  191. {
  192. produces jumps to true respectively false labels using boolean expressions
  193. depending on whether the loading of regvars is currently being
  194. synchronized manually (such as in an if-node) or automatically (most of
  195. the other cases where this procedure is called), loadregvars can be
  196. "lr_load_regvars" or "lr_dont_load_regvars"
  197. }
  198. var
  199. opsize : tcgsize;
  200. storepos : tfileposinfo;
  201. tmpreg : tregister;
  202. begin
  203. if nf_error in p.flags then
  204. exit;
  205. storepos:=current_filepos;
  206. current_filepos:=p.fileinfo;
  207. if is_boolean(p.resultdef) then
  208. begin
  209. {$ifdef OLDREGVARS}
  210. if loadregvars = lr_load_regvars then
  211. load_all_regvars(list);
  212. {$endif OLDREGVARS}
  213. if is_constboolnode(p) then
  214. begin
  215. if Tordconstnode(p).value.uvalue<>0 then
  216. cg.a_jmp_always(list,current_procinfo.CurrTrueLabel)
  217. else
  218. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel)
  219. end
  220. else
  221. begin
  222. opsize:=def_cgsize(p.resultdef);
  223. case p.location.loc of
  224. LOC_SUBSETREG,LOC_CSUBSETREG,
  225. LOC_SUBSETREF,LOC_CSUBSETREF:
  226. begin
  227. tmpreg := cg.getintregister(list,OS_INT);
  228. cg.a_load_loc_reg(list,OS_INT,p.location,tmpreg);
  229. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,tmpreg,current_procinfo.CurrTrueLabel);
  230. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  231. end;
  232. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  233. begin
  234. cg.a_cmp_const_loc_label(list,opsize,OC_NE,0,p.location,current_procinfo.CurrTrueLabel);
  235. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  236. end;
  237. LOC_JUMP:
  238. ;
  239. {$ifdef cpuflags}
  240. LOC_FLAGS :
  241. begin
  242. cg.a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
  243. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  244. end;
  245. {$endif cpuflags}
  246. else
  247. begin
  248. printnode(output,p);
  249. internalerror(200308241);
  250. end;
  251. end;
  252. end;
  253. end
  254. else
  255. internalerror(200112305);
  256. current_filepos:=storepos;
  257. end;
  258. (*
  259. This code needs fixing. It is not safe to use rgint; on the m68000 it
  260. would be rgaddr.
  261. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  262. begin
  263. case t.loc of
  264. LOC_REGISTER:
  265. begin
  266. { can't be a regvar, since it would be LOC_CREGISTER then }
  267. exclude(regs,getsupreg(t.register));
  268. if t.register64.reghi<>NR_NO then
  269. exclude(regs,getsupreg(t.register64.reghi));
  270. end;
  271. LOC_CREFERENCE,LOC_REFERENCE:
  272. begin
  273. if not(cs_opt_regvar in current_settings.optimizerswitches) or
  274. (getsupreg(t.reference.base) in cg.rgint.usableregs) then
  275. exclude(regs,getsupreg(t.reference.base));
  276. if not(cs_opt_regvar in current_settings.optimizerswitches) or
  277. (getsupreg(t.reference.index) in cg.rgint.usableregs) then
  278. exclude(regs,getsupreg(t.reference.index));
  279. end;
  280. end;
  281. end;
  282. *)
  283. {*****************************************************************************
  284. EXCEPTION MANAGEMENT
  285. *****************************************************************************}
  286. procedure get_exception_temps(list:TAsmList;var t:texceptiontemps);
  287. var
  288. srsym : ttypesym;
  289. begin
  290. if jmp_buf_size=-1 then
  291. begin
  292. srsym:=search_system_type('JMP_BUF');
  293. jmp_buf_size:=srsym.typedef.size;
  294. end;
  295. tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,t.envbuf);
  296. tg.GetTemp(list,jmp_buf_size,tt_persistent,t.jmpbuf);
  297. tg.GetTemp(list,sizeof(aint),tt_persistent,t.reasonbuf);
  298. end;
  299. procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  300. begin
  301. tg.Ungettemp(list,t.jmpbuf);
  302. tg.ungettemp(list,t.envbuf);
  303. tg.ungettemp(list,t.reasonbuf);
  304. end;
  305. procedure new_exception(list:TAsmList;const t:texceptiontemps;exceptlabel:tasmlabel);
  306. var
  307. paraloc1,paraloc2,paraloc3 : tcgpara;
  308. begin
  309. paraloc1.init;
  310. paraloc2.init;
  311. paraloc3.init;
  312. paramanager.getintparaloc(pocall_default,1,paraloc1);
  313. paramanager.getintparaloc(pocall_default,2,paraloc2);
  314. paramanager.getintparaloc(pocall_default,3,paraloc3);
  315. paramanager.allocparaloc(list,paraloc3);
  316. cg.a_paramaddr_ref(list,t.envbuf,paraloc3);
  317. paramanager.allocparaloc(list,paraloc2);
  318. cg.a_paramaddr_ref(list,t.jmpbuf,paraloc2);
  319. { push type of exceptionframe }
  320. paramanager.allocparaloc(list,paraloc1);
  321. cg.a_param_const(list,OS_S32,1,paraloc1);
  322. paramanager.freeparaloc(list,paraloc3);
  323. paramanager.freeparaloc(list,paraloc2);
  324. paramanager.freeparaloc(list,paraloc1);
  325. cg.allocallcpuregisters(list);
  326. cg.a_call_name(list,'FPC_PUSHEXCEPTADDR');
  327. cg.deallocallcpuregisters(list);
  328. paramanager.getintparaloc(pocall_default,1,paraloc1);
  329. paramanager.allocparaloc(list,paraloc1);
  330. cg.a_param_reg(list,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  331. paramanager.freeparaloc(list,paraloc1);
  332. cg.allocallcpuregisters(list);
  333. cg.a_call_name(list,'FPC_SETJMP');
  334. cg.deallocallcpuregisters(list);
  335. cg.alloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  336. cg.g_exception_reason_save(list, t.reasonbuf);
  337. cg.a_cmp_const_reg_label(list,OS_S32,OC_NE,0,cg.makeregsize(list,NR_FUNCTION_RESULT_REG,OS_S32),exceptlabel);
  338. cg.dealloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  339. paraloc1.done;
  340. paraloc2.done;
  341. paraloc3.done;
  342. end;
  343. procedure free_exception(list:TAsmList;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  344. begin
  345. cg.allocallcpuregisters(list);
  346. cg.a_call_name(list,'FPC_POPADDRSTACK');
  347. cg.deallocallcpuregisters(list);
  348. if not onlyfree then
  349. begin
  350. cg.alloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  351. cg.g_exception_reason_load(list, t.reasonbuf);
  352. cg.a_cmp_const_reg_label(list,OS_INT,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
  353. cg.dealloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  354. end;
  355. end;
  356. {*****************************************************************************
  357. TLocation
  358. *****************************************************************************}
  359. {$ifndef cpu64bit}
  360. { 32-bit version }
  361. procedure location_force_reg(list:TAsmList;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  362. var
  363. hregister,
  364. hregisterhi : tregister;
  365. hreg64 : tregister64;
  366. hl : tasmlabel;
  367. oldloc : tlocation;
  368. const_location: boolean;
  369. begin
  370. oldloc:=l;
  371. if dst_size=OS_NO then
  372. internalerror(200309144);
  373. { handle transformations to 64bit separate }
  374. if dst_size in [OS_64,OS_S64] then
  375. begin
  376. if not (l.size in [OS_64,OS_S64]) then
  377. begin
  378. { load a smaller size to OS_64 }
  379. if l.loc=LOC_REGISTER then
  380. begin
  381. hregister:=cg.makeregsize(list,l.register64.reglo,OS_32);
  382. cg.a_load_reg_reg(list,l.size,OS_32,l.register64.reglo,hregister);
  383. end
  384. else
  385. hregister:=cg.getintregister(list,OS_INT);
  386. { load value in low register }
  387. case l.loc of
  388. LOC_FLAGS :
  389. cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
  390. LOC_JUMP :
  391. begin
  392. cg.a_label(list,current_procinfo.CurrTrueLabel);
  393. cg.a_load_const_reg(list,OS_INT,1,hregister);
  394. current_asmdata.getjumplabel(hl);
  395. cg.a_jmp_always(list,hl);
  396. cg.a_label(list,current_procinfo.CurrFalseLabel);
  397. cg.a_load_const_reg(list,OS_INT,0,hregister);
  398. cg.a_label(list,hl);
  399. end;
  400. else
  401. cg.a_load_loc_reg(list,OS_INT,l,hregister);
  402. end;
  403. { reset hi part, take care of the signed bit of the current value }
  404. hregisterhi:=cg.getintregister(list,OS_INT);
  405. if (l.size in [OS_S8,OS_S16,OS_S32]) then
  406. begin
  407. if l.loc=LOC_CONSTANT then
  408. begin
  409. if (longint(l.value)<0) then
  410. cg.a_load_const_reg(list,OS_32,aint($ffffffff),hregisterhi)
  411. else
  412. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  413. end
  414. else
  415. begin
  416. cg.a_op_const_reg_reg(list,OP_SAR,OS_32,31,hregister,
  417. hregisterhi);
  418. end;
  419. end
  420. else
  421. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  422. location_reset(l,LOC_REGISTER,dst_size);
  423. l.register64.reglo:=hregister;
  424. l.register64.reghi:=hregisterhi;
  425. end
  426. else
  427. begin
  428. { 64bit to 64bit }
  429. if ((l.loc=LOC_CREGISTER) and maybeconst) then
  430. begin
  431. hregister:=l.register64.reglo;
  432. hregisterhi:=l.register64.reghi;
  433. const_location := true;
  434. end
  435. else
  436. begin
  437. hregister:=cg.getintregister(list,OS_INT);
  438. hregisterhi:=cg.getintregister(list,OS_INT);
  439. const_location := false;
  440. end;
  441. hreg64.reglo:=hregister;
  442. hreg64.reghi:=hregisterhi;
  443. { load value in new register }
  444. cg64.a_load64_loc_reg(list,l,hreg64);
  445. if not const_location then
  446. location_reset(l,LOC_REGISTER,dst_size)
  447. else
  448. location_reset(l,LOC_CREGISTER,dst_size);
  449. l.register64.reglo:=hregister;
  450. l.register64.reghi:=hregisterhi;
  451. end;
  452. end
  453. else
  454. begin
  455. {Do not bother to recycle the existing register. The register
  456. allocator eliminates unnecessary moves, so it's not needed
  457. and trying to recycle registers can cause problems because
  458. the registers changes size and may need aditional constraints.
  459. Not if it's about LOC_CREGISTER's (JM)
  460. }
  461. const_location :=
  462. (maybeconst) and
  463. (l.loc = LOC_CREGISTER) and
  464. (TCGSize2Size[l.size] = TCGSize2Size[dst_size]) and
  465. ((l.size = dst_size) or
  466. (TCGSize2Size[l.size] = TCGSize2Size[OS_INT]));
  467. if not const_location then
  468. hregister:=cg.getintregister(list,dst_size)
  469. else
  470. hregister := l.register;
  471. { load value in new register }
  472. case l.loc of
  473. LOC_FLAGS :
  474. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  475. LOC_JUMP :
  476. begin
  477. cg.a_label(list,current_procinfo.CurrTrueLabel);
  478. cg.a_load_const_reg(list,dst_size,1,hregister);
  479. current_asmdata.getjumplabel(hl);
  480. cg.a_jmp_always(list,hl);
  481. cg.a_label(list,current_procinfo.CurrFalseLabel);
  482. cg.a_load_const_reg(list,dst_size,0,hregister);
  483. cg.a_label(list,hl);
  484. end;
  485. else
  486. begin
  487. { load_loc_reg can only handle size >= l.size, when the
  488. new size is smaller then we need to adjust the size
  489. of the orignal and maybe recalculate l.register for i386 }
  490. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  491. begin
  492. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  493. l.register:=cg.makeregsize(list,l.register,dst_size);
  494. { for big endian systems, the reference's offset must }
  495. { be increased in this case, since they have the }
  496. { MSB first in memory and e.g. byte(word_var) should }
  497. { return the second byte in this case (JM) }
  498. if (target_info.endian = ENDIAN_BIG) and
  499. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_SUBSETREF,LOC_CSUBSETREF]) then
  500. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  501. {$ifdef x86}
  502. if not (l.loc in [LOC_SUBSETREG,LOC_CSUBSETREG]) then
  503. l.size:=dst_size;
  504. {$endif x86}
  505. end;
  506. cg.a_load_loc_reg(list,dst_size,l,hregister);
  507. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size])
  508. {$ifdef x86}
  509. and (l.loc in [LOC_SUBSETREG,LOC_CSUBSETREG])
  510. {$endif x86}
  511. then
  512. l.size:=dst_size;
  513. end;
  514. end;
  515. if not const_location then
  516. location_reset(l,LOC_REGISTER,dst_size)
  517. else
  518. location_reset(l,LOC_CREGISTER,dst_size);
  519. l.register:=hregister;
  520. end;
  521. { Release temp when it was a reference }
  522. if oldloc.loc=LOC_REFERENCE then
  523. location_freetemp(list,oldloc);
  524. end;
  525. {$else cpu64bit}
  526. { 64-bit version }
  527. procedure location_force_reg(list:TAsmList;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  528. var
  529. hregister : tregister;
  530. hl : tasmlabel;
  531. oldloc : tlocation;
  532. begin
  533. oldloc:=l;
  534. hregister:=cg.getintregister(list,dst_size);
  535. { load value in new register }
  536. case l.loc of
  537. LOC_FLAGS :
  538. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  539. LOC_JUMP :
  540. begin
  541. cg.a_label(list,current_procinfo.CurrTrueLabel);
  542. cg.a_load_const_reg(list,dst_size,1,hregister);
  543. current_asmdata.getjumplabel(hl);
  544. cg.a_jmp_always(list,hl);
  545. cg.a_label(list,current_procinfo.CurrFalseLabel);
  546. cg.a_load_const_reg(list,dst_size,0,hregister);
  547. cg.a_label(list,hl);
  548. end;
  549. else
  550. begin
  551. { load_loc_reg can only handle size >= l.size, when the
  552. new size is smaller then we need to adjust the size
  553. of the orignal and maybe recalculate l.register for i386 }
  554. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  555. begin
  556. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  557. l.register:=cg.makeregsize(list,l.register,dst_size);
  558. { for big endian systems, the reference's offset must }
  559. { be increased in this case, since they have the }
  560. { MSB first in memory and e.g. byte(word_var) should }
  561. { return the second byte in this case (JM) }
  562. if (target_info.endian = ENDIAN_BIG) and
  563. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  564. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  565. {$ifdef x86}
  566. l.size:=dst_size;
  567. {$endif x86}
  568. end;
  569. cg.a_load_loc_reg(list,dst_size,l,hregister);
  570. {$ifndef x86}
  571. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  572. l.size:=dst_size;
  573. {$endif not x86}
  574. end;
  575. end;
  576. if (l.loc <> LOC_CREGISTER) or
  577. not maybeconst then
  578. location_reset(l,LOC_REGISTER,dst_size)
  579. else
  580. location_reset(l,LOC_CREGISTER,dst_size);
  581. l.register:=hregister;
  582. { Release temp when it was a reference }
  583. if oldloc.loc=LOC_REFERENCE then
  584. location_freetemp(list,oldloc);
  585. end;
  586. {$endif cpu64bit}
  587. procedure location_force_fpureg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  588. var
  589. reg : tregister;
  590. href : treference;
  591. begin
  592. if (l.loc<>LOC_FPUREGISTER) and
  593. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  594. begin
  595. { if it's in an mm register, store to memory first }
  596. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  597. begin
  598. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  599. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
  600. location_reset(l,LOC_REFERENCE,l.size);
  601. l.reference:=href;
  602. end;
  603. reg:=cg.getfpuregister(list,l.size);
  604. cg.a_loadfpu_loc_reg(list,l.size,l,reg);
  605. location_freetemp(list,l);
  606. location_reset(l,LOC_FPUREGISTER,l.size);
  607. l.register:=reg;
  608. end;
  609. end;
  610. procedure location_force_mmregscalar(list:TAsmList;var l: tlocation;maybeconst:boolean);
  611. var
  612. reg : tregister;
  613. href : treference;
  614. begin
  615. if (l.loc<>LOC_MMREGISTER) and
  616. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  617. begin
  618. { if it's in an fpu register, store to memory first }
  619. if (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  620. begin
  621. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  622. cg.a_loadfpu_reg_ref(list,l.size,l.size,l.register,href);
  623. location_reset(l,LOC_REFERENCE,l.size);
  624. l.reference:=href;
  625. end;
  626. reg:=cg.getmmregister(list,l.size);
  627. cg.a_loadmm_loc_reg(list,l.size,l,reg,mms_movescalar);
  628. location_freetemp(list,l);
  629. location_reset(l,LOC_MMREGISTER,l.size);
  630. l.register:=reg;
  631. end;
  632. end;
  633. procedure register_maybe_adjust_setbase(list: TAsmList; var l: tlocation; setbase: aint);
  634. var
  635. tmpreg: tregister;
  636. begin
  637. if (setbase<>0) then
  638. begin
  639. if not(l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  640. internalerror(2007091502);
  641. { subtract the setbase }
  642. case l.loc of
  643. LOC_CREGISTER:
  644. begin
  645. tmpreg := cg.getintregister(list,l.size);
  646. cg.a_op_const_reg_reg(list,OP_SUB,l.size,setbase,l.register,tmpreg);
  647. l.loc:=LOC_REGISTER;
  648. l.register:=tmpreg;
  649. end;
  650. LOC_REGISTER:
  651. begin
  652. cg.a_op_const_reg(list,OP_SUB,l.size,setbase,l.register);
  653. end;
  654. end;
  655. end;
  656. end;
  657. procedure location_force_mmreg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  658. var
  659. reg : tregister;
  660. begin
  661. if (l.loc<>LOC_MMREGISTER) and
  662. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  663. begin
  664. reg:=cg.getmmregister(list,OS_VECTOR);
  665. cg.a_loadmm_loc_reg(list,OS_VECTOR,l,reg,nil);
  666. location_freetemp(list,l);
  667. location_reset(l,LOC_MMREGISTER,OS_VECTOR);
  668. l.register:=reg;
  669. end;
  670. end;
  671. procedure location_force_mem(list:TAsmList;var l:tlocation);
  672. var
  673. r : treference;
  674. begin
  675. case l.loc of
  676. LOC_FPUREGISTER,
  677. LOC_CFPUREGISTER :
  678. begin
  679. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  680. cg.a_loadfpu_reg_ref(list,l.size,l.size,l.register,r);
  681. location_reset(l,LOC_REFERENCE,l.size);
  682. l.reference:=r;
  683. end;
  684. LOC_MMREGISTER,
  685. LOC_CMMREGISTER:
  686. begin
  687. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  688. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  689. location_reset(l,LOC_REFERENCE,l.size);
  690. l.reference:=r;
  691. end;
  692. LOC_CONSTANT,
  693. LOC_REGISTER,
  694. LOC_CREGISTER :
  695. begin
  696. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  697. {$ifndef cpu64bit}
  698. if l.size in [OS_64,OS_S64] then
  699. cg64.a_load64_loc_ref(list,l,r)
  700. else
  701. {$endif cpu64bit}
  702. cg.a_load_loc_ref(list,l.size,l,r);
  703. location_reset(l,LOC_REFERENCE,l.size);
  704. l.reference:=r;
  705. end;
  706. LOC_SUBSETREG,
  707. LOC_CSUBSETREG,
  708. LOC_SUBSETREF,
  709. LOC_CSUBSETREF:
  710. begin
  711. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  712. cg.a_load_loc_ref(list,l.size,l,r);
  713. location_reset(l,LOC_REFERENCE,l.size);
  714. l.reference:=r;
  715. end;
  716. LOC_CREFERENCE,
  717. LOC_REFERENCE : ;
  718. else
  719. internalerror(200203219);
  720. end;
  721. end;
  722. procedure location_get_data_ref(list:TAsmList;const l:tlocation;var ref:treference;loadref:boolean);
  723. begin
  724. case l.loc of
  725. LOC_REGISTER,
  726. LOC_CREGISTER :
  727. begin
  728. if not loadref then
  729. internalerror(200410231);
  730. reference_reset_base(ref,l.register,0);
  731. end;
  732. LOC_REFERENCE,
  733. LOC_CREFERENCE :
  734. begin
  735. if loadref then
  736. begin
  737. reference_reset_base(ref,cg.getaddressregister(list),0);
  738. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,l.reference,ref.base);
  739. end
  740. else
  741. ref:=l.reference;
  742. end;
  743. else
  744. internalerror(200309181);
  745. end;
  746. end;
  747. {****************************************************************************
  748. Init/Finalize Code
  749. ****************************************************************************}
  750. procedure copyvalueparas(p:TObject;arg:pointer);
  751. var
  752. href : treference;
  753. hreg : tregister;
  754. list : TAsmList;
  755. hsym : tparavarsym;
  756. l : longint;
  757. localcopyloc : tlocation;
  758. begin
  759. list:=TAsmList(arg);
  760. if (tsym(p).typ=paravarsym) and
  761. (tparavarsym(p).varspez=vs_value) and
  762. (paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption)) then
  763. begin
  764. location_get_data_ref(list,tparavarsym(p).initialloc,href,true);
  765. if is_open_array(tparavarsym(p).vardef) or
  766. is_array_of_const(tparavarsym(p).vardef) then
  767. begin
  768. { cdecl functions don't have a high pointer so it is not possible to generate
  769. a local copy }
  770. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  771. begin
  772. hsym:=tparavarsym(tsym(p).owner.Find('high'+tsym(p).name));
  773. if not assigned(hsym) then
  774. internalerror(200306061);
  775. hreg:=cg.getaddressregister(list);
  776. if not is_packed_array(tparavarsym(p).vardef) then
  777. cg.g_copyvaluepara_openarray(list,href,hsym.initialloc,tarraydef(tparavarsym(p).vardef).elesize,hreg)
  778. else
  779. internalerror(2006080401);
  780. // cg.g_copyvaluepara_packedopenarray(list,href,hsym.intialloc,tarraydef(tparavarsym(p).vardef).elepackedbitsize,hreg);
  781. cg.a_load_reg_loc(list,OS_ADDR,hreg,tparavarsym(p).initialloc);
  782. end;
  783. end
  784. else
  785. begin
  786. { Allocate space for the local copy }
  787. l:=tparavarsym(p).getsize;
  788. localcopyloc.loc:=LOC_REFERENCE;
  789. localcopyloc.size:=int_cgsize(l);
  790. tg.GetLocal(list,l,tparavarsym(p).vardef,localcopyloc.reference);
  791. { Copy data }
  792. if is_shortstring(tparavarsym(p).vardef) then
  793. begin
  794. { this code is only executed before the code for the body and the entry/exit code is generated
  795. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  796. }
  797. include(current_procinfo.flags,pi_do_call);
  798. cg.g_copyshortstring(list,href,localcopyloc.reference,tstringdef(tparavarsym(p).vardef).len)
  799. end
  800. else if tparavarsym(p).vardef.typ = variantdef then
  801. begin
  802. { this code is only executed before the code for the body and the entry/exit code is generated
  803. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  804. }
  805. include(current_procinfo.flags,pi_do_call);
  806. cg.g_copyvariant(list,href,localcopyloc.reference)
  807. end
  808. else
  809. begin
  810. { pass proper alignment info }
  811. localcopyloc.reference.alignment:=tparavarsym(p).vardef.alignment;
  812. cg.g_concatcopy(list,href,localcopyloc.reference,tparavarsym(p).vardef.size);
  813. end;
  814. { update localloc of varsym }
  815. tg.Ungetlocal(list,tparavarsym(p).localloc.reference);
  816. tparavarsym(p).localloc:=localcopyloc;
  817. tparavarsym(p).initialloc:=localcopyloc;
  818. end;
  819. end;
  820. end;
  821. const
  822. {$ifdef cpu64bit}
  823. trashintvalues: array[0..nroftrashvalues-1] of aint = ($5555555555555555,aint($AAAAAAAAAAAAAAAA),aint($EFEFEFEFEFEFEFEF),0);
  824. {$else cpu64bit}
  825. trashintvalues: array[0..nroftrashvalues-1] of aint = ($55555555,aint($AAAAAAAA),aint($EFEFEFEF),0);
  826. {$endif cpu64bit}
  827. procedure trash_reference(list: TAsmList; const ref: treference; size: aint);
  828. var
  829. countreg, valuereg: tregister;
  830. hl: tasmlabel;
  831. trashintval: aint;
  832. tmpref: treference;
  833. begin
  834. trashintval := trashintvalues[localvartrashing];
  835. case size of
  836. 0: ; { empty record }
  837. 1: cg.a_load_const_ref(list,OS_8,byte(trashintval),ref);
  838. 2: cg.a_load_const_ref(list,OS_16,word(trashintval),ref);
  839. 4: cg.a_load_const_ref(list,OS_32,longint(trashintval),ref);
  840. {$ifdef cpu64bit}
  841. 8: cg.a_load_const_ref(list,OS_64,int64(trashintval),ref);
  842. {$endif cpu64bit}
  843. else
  844. begin
  845. countreg := cg.getintregister(list,OS_ADDR);
  846. valuereg := cg.getintregister(list,OS_8);
  847. cg.a_load_const_reg(list,OS_INT,size,countreg);
  848. cg.a_load_const_reg(list,OS_8,byte(trashintval),valuereg);
  849. current_asmdata.getjumplabel(hl);
  850. tmpref := ref;
  851. if (tmpref.index <> NR_NO) then
  852. internalerror(200607201);
  853. tmpref.index := countreg;
  854. dec(tmpref.offset);
  855. cg.a_label(list,hl);
  856. cg.a_load_reg_ref(list,OS_8,OS_8,valuereg,tmpref);
  857. cg.a_op_const_reg(list,OP_SUB,OS_INT,1,countreg);
  858. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,countreg,hl);
  859. cg.a_reg_sync(list,tmpref.base);
  860. cg.a_reg_sync(list,valuereg);
  861. end;
  862. end;
  863. end;
  864. { trash contents of local variables or parameters (function result) }
  865. procedure trash_variable(p:TObject;arg:pointer);
  866. var
  867. trashintval: aint;
  868. list: TAsmList absolute arg;
  869. begin
  870. if ((tsym(p).typ=localvarsym) or
  871. ((tsym(p).typ=paravarsym) and
  872. (vo_is_funcret in tparavarsym(p).varoptions))) and
  873. not(tabstractnormalvarsym(p).vardef.needs_inittable) and
  874. not(assigned(tabstractnormalvarsym(p).defaultconstsym)) then
  875. begin
  876. trashintval := trashintvalues[localvartrashing];
  877. case tabstractnormalvarsym(p).initialloc.loc of
  878. LOC_CREGISTER :
  879. {$ifopt q+}
  880. {$define overflowon}
  881. {$q-}
  882. {$endif}
  883. cg.a_load_const_reg(list,reg_cgsize(tabstractnormalvarsym(p).initialloc.register),
  884. trashintval and (aword(1) shl (tcgsize2size[reg_cgsize(tabstractnormalvarsym(p).initialloc.register)] * 8) - 1),
  885. tabstractnormalvarsym(p).initialloc.register);
  886. {$ifdef overflowon}
  887. {$undef overflowon}
  888. {$q+}
  889. {$endif}
  890. LOC_REFERENCE :
  891. begin
  892. if ((tsym(p).typ=localvarsym) and
  893. not(vo_is_funcret in tabstractvarsym(p).varoptions)) or
  894. not is_shortstring(tabstractnormalvarsym(p).vardef) then
  895. trash_reference(list,tabstractnormalvarsym(p).initialloc.reference,
  896. tlocalvarsym(p).getsize)
  897. else
  898. { may be an open string, even if is_open_string() returns }
  899. { false for some helpers in the system unit }
  900. { an open string has at least size 2 }
  901. trash_reference(list,tabstractnormalvarsym(p).initialloc.reference,
  902. 2);
  903. end;
  904. LOC_CMMREGISTER :
  905. ;
  906. LOC_CFPUREGISTER :
  907. ;
  908. else
  909. internalerror(200410124);
  910. end;
  911. end;
  912. end;
  913. { initializes the regvars from staticsymtable with 0 }
  914. procedure initialize_regvars(p:TObject;arg:pointer);
  915. var
  916. href : treference;
  917. begin
  918. if (tsym(p).typ=staticvarsym) then
  919. begin
  920. { Static variables can have the initialloc only set to LOC_CxREGISTER
  921. or LOC_INVALID, for explaination see gen_alloc_symtable (PFV) }
  922. case tstaticvarsym(p).initialloc.loc of
  923. LOC_CREGISTER :
  924. begin
  925. {$ifndef cpu64bit}
  926. if (tstaticvarsym(p).initialloc.size in [OS_64,OS_S64]) then
  927. cg64.a_load64_const_reg(TAsmList(arg),0,tstaticvarsym(p).initialloc.register64)
  928. else
  929. {$endif not cpu64bit}
  930. cg.a_load_const_reg(TAsmList(arg),reg_cgsize(tstaticvarsym(p).initialloc.register),0,
  931. tstaticvarsym(p).initialloc.register);
  932. end;
  933. LOC_CMMREGISTER :
  934. { clear the whole register }
  935. cg.a_opmm_reg_reg(TAsmList(arg),OP_XOR,reg_cgsize(tstaticvarsym(p).initialloc.register),
  936. tstaticvarsym(p).initialloc.register,
  937. tstaticvarsym(p).initialloc.register,
  938. nil);
  939. LOC_CFPUREGISTER :
  940. begin
  941. { initialize fpu regvar by loading from memory }
  942. reference_reset_symbol(href,
  943. current_asmdata.RefAsmSymbol(tstaticvarsym(p).mangledname), 0);
  944. cg.a_loadfpu_ref_reg(TAsmList(arg), tstaticvarsym(p).initialloc.size,
  945. tstaticvarsym(p).initialloc.size, href, tstaticvarsym(p).initialloc.register);
  946. end;
  947. LOC_INVALID :
  948. ;
  949. else
  950. internalerror(200410124);
  951. end;
  952. end;
  953. end;
  954. { generates the code for initialisation of local data }
  955. procedure initialize_data(p:TObject;arg:pointer);
  956. var
  957. OldAsmList : TAsmList;
  958. hp : tnode;
  959. begin
  960. if (tsym(p).typ in [staticvarsym,localvarsym]) and
  961. ((tabstractvarsym(p).refs>0) or
  962. { managed return symbols must be inited }
  963. ((tsym(p).typ=localvarsym) and (vo_is_funcret in tlocalvarsym(p).varoptions))
  964. ) and
  965. not(vo_is_typed_const in tabstractvarsym(p).varoptions) and
  966. not(vo_is_external in tabstractvarsym(p).varoptions) and
  967. not(is_class(tabstractvarsym(p).vardef)) and
  968. tabstractvarsym(p).vardef.needs_inittable then
  969. begin
  970. OldAsmList:=current_asmdata.CurrAsmList;
  971. current_asmdata.CurrAsmList:=TAsmList(arg);
  972. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  973. firstpass(hp);
  974. secondpass(hp);
  975. hp.free;
  976. current_asmdata.CurrAsmList:=OldAsmList;
  977. end;
  978. end;
  979. procedure finalize_sym(asmlist:TAsmList;sym:tsym);
  980. var
  981. hp : tnode;
  982. OldAsmList : TAsmList;
  983. begin
  984. include(current_procinfo.flags,pi_needs_implicit_finally);
  985. OldAsmList:=current_asmdata.CurrAsmList;
  986. current_asmdata.CurrAsmList:=asmlist;
  987. hp:=finalize_data_node(cloadnode.create(sym,sym.owner));
  988. firstpass(hp);
  989. secondpass(hp);
  990. hp.free;
  991. current_asmdata.CurrAsmList:=OldAsmList;
  992. end;
  993. { generates the code for finalisation of local variables }
  994. procedure finalize_local_vars(p:TObject;arg:pointer);
  995. begin
  996. if (tsym(p).typ=localvarsym) and
  997. (tlocalvarsym(p).refs>0) and
  998. not(vo_is_external in tlocalvarsym(p).varoptions) and
  999. not(vo_is_funcret in tlocalvarsym(p).varoptions) and
  1000. not(is_class(tlocalvarsym(p).vardef)) and
  1001. tlocalvarsym(p).vardef.needs_inittable then
  1002. finalize_sym(TAsmList(arg),tsym(p));
  1003. end;
  1004. { generates the code for finalization of static symtable and
  1005. all local (static) typed consts }
  1006. procedure finalize_static_data(p:TObject;arg:pointer);
  1007. var
  1008. i : longint;
  1009. pd : tprocdef;
  1010. begin
  1011. case tsym(p).typ of
  1012. staticvarsym :
  1013. begin
  1014. if (tstaticvarsym(p).refs>0) and
  1015. (tstaticvarsym(p).varspez<>vs_const) and
  1016. not(vo_is_funcret in tstaticvarsym(p).varoptions) and
  1017. not(vo_is_external in tstaticvarsym(p).varoptions) and
  1018. not(is_class(tstaticvarsym(p).vardef)) and
  1019. tstaticvarsym(p).vardef.needs_inittable then
  1020. finalize_sym(TAsmList(arg),tsym(p));
  1021. end;
  1022. procsym :
  1023. begin
  1024. for i:=0 to tprocsym(p).ProcdefList.Count-1 do
  1025. begin
  1026. pd:=tprocdef(tprocsym(p).ProcdefList[i]);
  1027. if assigned(pd.localst) and
  1028. (pd.procsym=tprocsym(p)) and
  1029. (pd.localst.symtabletype<>staticsymtable) then
  1030. pd.localst.SymList.ForEachCall(@finalize_static_data,arg);
  1031. end;
  1032. end;
  1033. end;
  1034. end;
  1035. { generates the code for incrementing the reference count of parameters and
  1036. initialize out parameters }
  1037. procedure init_paras(p:TObject;arg:pointer);
  1038. var
  1039. href : treference;
  1040. tmpreg : tregister;
  1041. list : TAsmList;
  1042. needs_inittable,
  1043. do_trashing : boolean;
  1044. begin
  1045. list:=TAsmList(arg);
  1046. if (tsym(p).typ=paravarsym) then
  1047. begin
  1048. needs_inittable :=
  1049. not is_class_or_interface(tparavarsym(p).vardef) and
  1050. tparavarsym(p).vardef.needs_inittable;
  1051. do_trashing :=
  1052. (localvartrashing <> -1) and
  1053. (not assigned(tparavarsym(p).defaultconstsym)) and
  1054. (not tparavarsym(p).vardef.needs_inittable or
  1055. is_class(tparavarsym(p).vardef));
  1056. case tparavarsym(p).varspez of
  1057. vs_value :
  1058. if needs_inittable then
  1059. begin
  1060. { variants are already handled by the call to fpc_variant_copy_overwrite }
  1061. if tparavarsym(p).vardef.typ <> variantdef then begin
  1062. location_get_data_ref(list,tparavarsym(p).initialloc,href,is_open_array(tparavarsym(p).vardef));
  1063. cg.g_incrrefcount(list,tparavarsym(p).vardef,href);
  1064. end;
  1065. end;
  1066. vs_out :
  1067. begin
  1068. if needs_inittable or
  1069. do_trashing then
  1070. begin
  1071. tmpreg:=cg.getaddressregister(list);
  1072. cg.a_load_loc_reg(list,OS_ADDR,tparavarsym(p).initialloc,tmpreg);
  1073. reference_reset_base(href,tmpreg,0);
  1074. if do_trashing and
  1075. { needs separate implementation to trash open arrays }
  1076. { since their size is only known at run time }
  1077. not is_special_array(tparavarsym(p).vardef) then
  1078. trash_reference(list,href,tparavarsym(p).vardef.size);
  1079. if needs_inittable then
  1080. cg.g_initialize(list,tparavarsym(p).vardef,href);
  1081. end;
  1082. end;
  1083. else if do_trashing and
  1084. ([vo_is_funcret,vo_is_hidden_para] * tparavarsym(p).varoptions = [vo_is_funcret,vo_is_hidden_para]) then
  1085. begin
  1086. tmpreg:=cg.getaddressregister(list);
  1087. cg.a_load_loc_reg(list,OS_ADDR,tparavarsym(p).initialloc,tmpreg);
  1088. reference_reset_base(href,tmpreg,0);
  1089. { may be an open string, even if is_open_string() returns }
  1090. { false for some helpers in the system unit }
  1091. if not is_shortstring(tparavarsym(p).vardef) then
  1092. trash_reference(list,href,tparavarsym(p).vardef.size)
  1093. else
  1094. { an open string has at least size 2 }
  1095. trash_reference(list,href,2);
  1096. end
  1097. end;
  1098. end;
  1099. end;
  1100. { generates the code for decrementing the reference count of parameters }
  1101. procedure final_paras(p:TObject;arg:pointer);
  1102. var
  1103. list : TAsmList;
  1104. href : treference;
  1105. begin
  1106. if not(tsym(p).typ=paravarsym) then
  1107. exit;
  1108. list:=TAsmList(arg);
  1109. if not is_class_or_interface(tparavarsym(p).vardef) and
  1110. tparavarsym(p).vardef.needs_inittable then
  1111. begin
  1112. if (tparavarsym(p).varspez=vs_value) then
  1113. begin
  1114. include(current_procinfo.flags,pi_needs_implicit_finally);
  1115. location_get_data_ref(list,tparavarsym(p).localloc,href,is_open_array(tparavarsym(p).vardef));
  1116. cg.g_decrrefcount(list,tparavarsym(p).vardef,href);
  1117. end;
  1118. end;
  1119. { open arrays can contain elements requiring init/final code, so the else has been removed here }
  1120. if (tparavarsym(p).varspez=vs_value) and
  1121. (is_open_array(tparavarsym(p).vardef) or
  1122. is_array_of_const(tparavarsym(p).vardef)) then
  1123. begin
  1124. { cdecl functions don't have a high pointer so it is not possible to generate
  1125. a local copy }
  1126. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1127. cg.g_releasevaluepara_openarray(list,tparavarsym(p).localloc);
  1128. end;
  1129. end;
  1130. { Initialize temp ansi/widestrings,interfaces }
  1131. procedure inittempvariables(list:TAsmList);
  1132. var
  1133. hp : ptemprecord;
  1134. href : treference;
  1135. begin
  1136. hp:=tg.templist;
  1137. while assigned(hp) do
  1138. begin
  1139. if assigned(hp^.def) and
  1140. hp^.def.needs_inittable then
  1141. begin
  1142. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1143. cg.g_initialize(list,hp^.def,href);
  1144. end;
  1145. hp:=hp^.next;
  1146. end;
  1147. end;
  1148. procedure finalizetempvariables(list:TAsmList);
  1149. var
  1150. hp : ptemprecord;
  1151. href : treference;
  1152. begin
  1153. hp:=tg.templist;
  1154. while assigned(hp) do
  1155. begin
  1156. if assigned(hp^.def) and
  1157. hp^.def.needs_inittable then
  1158. begin
  1159. include(current_procinfo.flags,pi_needs_implicit_finally);
  1160. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1161. cg.g_finalize(list,hp^.def,href);
  1162. end;
  1163. hp:=hp^.next;
  1164. end;
  1165. end;
  1166. procedure gen_load_return_value(list:TAsmList);
  1167. var
  1168. {$ifndef cpu64bit}
  1169. href : treference;
  1170. {$endif cpu64bit}
  1171. ressym : tabstractnormalvarsym;
  1172. resloc,
  1173. restmploc : tlocation;
  1174. hreg : tregister;
  1175. funcretloc : tlocation;
  1176. begin
  1177. { Is the loading needed? }
  1178. if (current_procinfo.procdef.funcretloc[calleeside].loc=LOC_VOID) or
  1179. (
  1180. (po_assembler in current_procinfo.procdef.procoptions) and
  1181. (not(assigned(current_procinfo.procdef.funcretsym)) or
  1182. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs=0))
  1183. ) then
  1184. exit;
  1185. funcretloc:=current_procinfo.procdef.funcretloc[calleeside];
  1186. { constructors return self }
  1187. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1188. ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.Find('self'))
  1189. else
  1190. ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
  1191. if (ressym.refs>0) or (ressym.vardef.needs_inittable) then
  1192. begin
  1193. {$ifdef OLDREGVARS}
  1194. case ressym.localloc.loc of
  1195. LOC_CFPUREGISTER,
  1196. LOC_FPUREGISTER:
  1197. begin
  1198. location_reset(restmploc,LOC_CFPUREGISTER,funcretloc^.size);
  1199. restmploc.register:=ressym.localloc.register;
  1200. end;
  1201. LOC_CREGISTER,
  1202. LOC_REGISTER:
  1203. begin
  1204. location_reset(restmploc,LOC_CREGISTER,funcretloc^.size);
  1205. restmploc.register:=ressym.localloc.register;
  1206. end;
  1207. LOC_MMREGISTER:
  1208. begin
  1209. location_reset(restmploc,LOC_CMMREGISTER,funcretloc^.size);
  1210. restmploc.register:=ressym.localloc.register;
  1211. end;
  1212. LOC_REFERENCE:
  1213. begin
  1214. location_reset(restmploc,LOC_REFERENCE,funcretloc^.size);
  1215. restmploc.reference:=ressym.localloc.reference;
  1216. end;
  1217. else
  1218. internalerror(200309184);
  1219. end;
  1220. {$else}
  1221. restmploc:=ressym.localloc;
  1222. {$endif}
  1223. { Here, we return the function result. In most architectures, the value is
  1224. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1225. function returns in a register and the caller receives it in an other one }
  1226. case funcretloc.loc of
  1227. LOC_REGISTER:
  1228. begin
  1229. {$ifndef cpu64bit}
  1230. if current_procinfo.procdef.funcretloc[calleeside].size in [OS_64,OS_S64] then
  1231. begin
  1232. resloc:=current_procinfo.procdef.funcretloc[calleeside];
  1233. if resloc.loc<>LOC_REGISTER then
  1234. internalerror(200409141);
  1235. { Load low and high register separate to generate better register
  1236. allocation info }
  1237. if getsupreg(resloc.register64.reglo)<first_int_imreg then
  1238. begin
  1239. cg.getcpuregister(list,resloc.register64.reglo);
  1240. end;
  1241. case restmploc.loc of
  1242. LOC_REFERENCE :
  1243. begin
  1244. href:=restmploc.reference;
  1245. if target_info.endian=ENDIAN_BIG then
  1246. inc(href.offset,4);
  1247. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.register64.reglo);
  1248. end;
  1249. LOC_CREGISTER :
  1250. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.register64.reglo,resloc.register64.reglo);
  1251. else
  1252. internalerror(200409203);
  1253. end;
  1254. if getsupreg(resloc.register64.reghi)<first_int_imreg then
  1255. begin
  1256. cg.getcpuregister(list,resloc.register64.reghi);
  1257. end;
  1258. case restmploc.loc of
  1259. LOC_REFERENCE :
  1260. begin
  1261. href:=restmploc.reference;
  1262. if target_info.endian=ENDIAN_LITTLE then
  1263. inc(href.offset,4);
  1264. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.register64.reghi);
  1265. end;
  1266. LOC_CREGISTER :
  1267. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.register64.reghi,resloc.register64.reghi);
  1268. else
  1269. internalerror(200409204);
  1270. end;
  1271. end
  1272. else
  1273. {$endif cpu64bit}
  1274. begin
  1275. hreg:=cg.makeregsize(list,funcretloc.register,funcretloc.size);
  1276. if getsupreg(funcretloc.register)<first_int_imreg then
  1277. begin
  1278. cg.getcpuregister(list,funcretloc.register);
  1279. end;
  1280. { it could be that a structure is passed in memory but the function is expected to
  1281. return a pointer to this memory }
  1282. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1283. cg.a_load_loc_reg(list,OS_ADDR,restmploc,hreg)
  1284. else
  1285. cg.a_load_loc_reg(list,restmploc.size,restmploc,hreg);
  1286. end;
  1287. end;
  1288. LOC_FPUREGISTER:
  1289. begin
  1290. if getsupreg(funcretloc.register)<first_fpu_imreg then
  1291. begin
  1292. cg.getcpuregister(list,funcretloc.register);
  1293. end;
  1294. { we can't do direct moves between fpu and mm registers }
  1295. if restmploc.loc in [LOC_MMREGISTER,LOC_CMMREGISTER] then
  1296. location_force_fpureg(list,restmploc,false);
  1297. cg.a_loadfpu_loc_reg(list,funcretloc.size,restmploc,funcretloc.register);
  1298. end;
  1299. LOC_MMREGISTER:
  1300. begin
  1301. if getsupreg(funcretloc.register)<first_mm_imreg then
  1302. begin
  1303. cg.getcpuregister(list,funcretloc.register);
  1304. end;
  1305. cg.a_loadmm_loc_reg(list,restmploc.size,restmploc,funcretloc.register,mms_movescalar);
  1306. end;
  1307. LOC_INVALID,
  1308. LOC_REFERENCE:
  1309. ;
  1310. else
  1311. internalerror(200405025);
  1312. end;
  1313. end
  1314. {$ifdef x86}
  1315. else
  1316. begin
  1317. { the caller will pop a value off the cpu stack }
  1318. if (funcretloc.loc = LOC_FPUREGISTER) then
  1319. list.concat(taicpu.op_none(A_FLDZ));
  1320. end;
  1321. {$endif x86}
  1322. end;
  1323. procedure gen_alloc_regvar(list:TAsmList;sym: tabstractnormalvarsym);
  1324. begin
  1325. case sym.initialloc.loc of
  1326. LOC_CREGISTER:
  1327. begin
  1328. {$ifndef cpu64bit}
  1329. if sym.initialloc.size in [OS_64,OS_S64] then
  1330. begin
  1331. sym.initialloc.register64.reglo:=cg.getintregister(list,OS_32);
  1332. sym.initialloc.register64.reghi:=cg.getintregister(list,OS_32);
  1333. end
  1334. else
  1335. {$endif cpu64bit}
  1336. sym.initialloc.register:=cg.getintregister(list,sym.initialloc.size);
  1337. end;
  1338. LOC_CFPUREGISTER:
  1339. begin
  1340. sym.initialloc.register:=cg.getfpuregister(list,sym.initialloc.size);
  1341. end;
  1342. LOC_CMMREGISTER:
  1343. begin
  1344. sym.initialloc.register:=cg.getmmregister(list,sym.initialloc.size);
  1345. end;
  1346. end;
  1347. if (pi_has_goto in current_procinfo.flags) then
  1348. begin
  1349. { Allocate register already, to prevent first allocation to be
  1350. inside a loop }
  1351. {$ifndef cpu64bit}
  1352. if sym.initialloc.size in [OS_64,OS_S64] then
  1353. begin
  1354. cg.a_reg_sync(list,sym.initialloc.register64.reglo);
  1355. cg.a_reg_sync(list,sym.initialloc.register64.reghi);
  1356. end
  1357. else
  1358. {$endif cpu64bit}
  1359. cg.a_reg_sync(list,sym.initialloc.register);
  1360. end;
  1361. sym.localloc:=sym.initialloc;
  1362. end;
  1363. procedure gen_load_para_value(list:TAsmList);
  1364. procedure get_para(const paraloc:TCGParaLocation);
  1365. begin
  1366. case paraloc.loc of
  1367. LOC_REGISTER :
  1368. begin
  1369. if getsupreg(paraloc.register)<first_int_imreg then
  1370. cg.getcpuregister(list,paraloc.register);
  1371. end;
  1372. LOC_MMREGISTER :
  1373. begin
  1374. if getsupreg(paraloc.register)<first_mm_imreg then
  1375. cg.getcpuregister(list,paraloc.register);
  1376. end;
  1377. LOC_FPUREGISTER :
  1378. begin
  1379. if getsupreg(paraloc.register)<first_fpu_imreg then
  1380. cg.getcpuregister(list,paraloc.register);
  1381. end;
  1382. end;
  1383. end;
  1384. procedure unget_para(const paraloc:TCGParaLocation);
  1385. begin
  1386. case paraloc.loc of
  1387. LOC_REGISTER :
  1388. begin
  1389. if getsupreg(paraloc.register)<first_int_imreg then
  1390. cg.ungetcpuregister(list,paraloc.register);
  1391. end;
  1392. LOC_MMREGISTER :
  1393. begin
  1394. if getsupreg(paraloc.register)<first_mm_imreg then
  1395. cg.ungetcpuregister(list,paraloc.register);
  1396. end;
  1397. LOC_FPUREGISTER :
  1398. begin
  1399. if getsupreg(paraloc.register)<first_fpu_imreg then
  1400. cg.ungetcpuregister(list,paraloc.register);
  1401. end;
  1402. end;
  1403. end;
  1404. procedure gen_load_ref(const paraloc:TCGParaLocation;const ref:treference;sizeleft:aint);
  1405. var
  1406. href : treference;
  1407. begin
  1408. case paraloc.loc of
  1409. LOC_REGISTER :
  1410. begin
  1411. {$IFDEF POWERPC64}
  1412. if (paraloc.shiftval <> 0) then
  1413. cg.a_op_const_reg_reg(list, OP_SHL, OS_INT, paraloc.shiftval, paraloc.register, paraloc.register);
  1414. {$ENDIF POWERPC64}
  1415. cg.a_load_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  1416. end;
  1417. LOC_MMREGISTER :
  1418. cg.a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,mms_movescalar);
  1419. LOC_FPUREGISTER :
  1420. cg.a_loadfpu_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  1421. LOC_REFERENCE :
  1422. begin
  1423. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1424. { use concatcopy, because it can also be a float which fails when
  1425. load_ref_ref is used. Don't copy data when the references are equal }
  1426. if not((href.base=ref.base) and (href.offset=ref.offset)) then
  1427. cg.g_concatcopy(list,href,ref,sizeleft);
  1428. end;
  1429. else
  1430. internalerror(2002081302);
  1431. end;
  1432. end;
  1433. procedure gen_load_reg(const paraloc:TCGParaLocation;reg:tregister);
  1434. var
  1435. href : treference;
  1436. begin
  1437. case paraloc.loc of
  1438. LOC_REGISTER :
  1439. cg.a_load_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg);
  1440. LOC_MMREGISTER :
  1441. cg.a_loadmm_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg,mms_movescalar);
  1442. LOC_FPUREGISTER :
  1443. cg.a_loadfpu_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg);
  1444. LOC_REFERENCE :
  1445. begin
  1446. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1447. case getregtype(reg) of
  1448. R_INTREGISTER :
  1449. cg.a_load_ref_reg(list,paraloc.size,paraloc.size,href,reg);
  1450. R_FPUREGISTER :
  1451. cg.a_loadfpu_ref_reg(list,paraloc.size,paraloc.size,href,reg);
  1452. R_MMREGISTER :
  1453. cg.a_loadmm_ref_reg(list,paraloc.size,paraloc.size,href,reg,mms_movescalar);
  1454. else
  1455. internalerror(2004101012);
  1456. end;
  1457. end;
  1458. else
  1459. internalerror(2002081302);
  1460. end;
  1461. end;
  1462. var
  1463. i : longint;
  1464. currpara : tparavarsym;
  1465. paraloc : pcgparalocation;
  1466. href : treference;
  1467. sizeleft : aint;
  1468. {$if defined(sparc) or defined(arm)}
  1469. tempref : treference;
  1470. {$endif sparc}
  1471. begin
  1472. if (po_assembler in current_procinfo.procdef.procoptions) then
  1473. exit;
  1474. { Allocate registers used by parameters }
  1475. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1476. begin
  1477. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1478. paraloc:=currpara.paraloc[calleeside].location;
  1479. while assigned(paraloc) do
  1480. begin
  1481. if paraloc^.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER] then
  1482. get_para(paraloc^);
  1483. paraloc:=paraloc^.next;
  1484. end;
  1485. end;
  1486. { Copy parameters to local references/registers }
  1487. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1488. begin
  1489. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1490. paraloc:=currpara.paraloc[calleeside].location;
  1491. { skip e.g. empty records }
  1492. if not assigned(paraloc) then
  1493. internalerror(200408203);
  1494. if (paraloc^.loc = LOC_VOID) then
  1495. continue;
  1496. case currpara.initialloc.loc of
  1497. LOC_REFERENCE :
  1498. begin
  1499. { If the parameter location is reused we don't need to copy
  1500. anything }
  1501. if not paramanager.param_use_paraloc(currpara.paraloc[calleeside]) then
  1502. begin
  1503. href:=currpara.initialloc.reference;
  1504. sizeleft:=currpara.paraloc[calleeside].intsize;
  1505. while assigned(paraloc) do
  1506. begin
  1507. if (paraloc^.size=OS_NO) then
  1508. begin
  1509. { Can only be a reference that contains the rest
  1510. of the parameter }
  1511. if (paraloc^.loc<>LOC_REFERENCE) or
  1512. assigned(paraloc^.next) then
  1513. internalerror(2005013010);
  1514. gen_load_ref(paraloc^,href,sizeleft);
  1515. inc(href.offset,sizeleft);
  1516. sizeleft:=0;
  1517. end
  1518. else
  1519. begin
  1520. gen_load_ref(paraloc^,href,tcgsize2size[paraloc^.size]);
  1521. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1522. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1523. end;
  1524. unget_para(paraloc^);
  1525. paraloc:=paraloc^.next;
  1526. end;
  1527. end;
  1528. end;
  1529. LOC_CREGISTER :
  1530. begin
  1531. {$ifndef cpu64bit}
  1532. if (currpara.paraloc[calleeside].size in [OS_64,OS_S64]) and
  1533. is_64bit(currpara.vardef) then
  1534. begin
  1535. case paraloc^.loc of
  1536. LOC_REGISTER:
  1537. begin
  1538. if not assigned(paraloc^.next) then
  1539. internalerror(200410104);
  1540. if (target_info.endian=ENDIAN_BIG) then
  1541. begin
  1542. { paraloc^ -> high
  1543. paraloc^.next -> low }
  1544. unget_para(paraloc^);
  1545. gen_alloc_regvar(list,currpara);
  1546. gen_load_reg(paraloc^,currpara.initialloc.register64.reghi);
  1547. unget_para(paraloc^.next^);
  1548. gen_load_reg(paraloc^.next^,currpara.initialloc.register64.reglo);
  1549. end
  1550. else
  1551. begin
  1552. { paraloc^ -> low
  1553. paraloc^.next -> high }
  1554. unget_para(paraloc^);
  1555. gen_alloc_regvar(list,currpara);
  1556. gen_load_reg(paraloc^,currpara.initialloc.register64.reglo);
  1557. unget_para(paraloc^.next^);
  1558. gen_load_reg(paraloc^.next^,currpara.initialloc.register64.reghi);
  1559. end;
  1560. end;
  1561. LOC_REFERENCE:
  1562. begin
  1563. gen_alloc_regvar(list,currpara);
  1564. reference_reset_base(href,paraloc^.reference.index,paraloc^.reference.offset);
  1565. cg64.a_load64_ref_reg(list,href,currpara.initialloc.register64);
  1566. unget_para(paraloc^);
  1567. end;
  1568. else
  1569. internalerror(2005101501);
  1570. end
  1571. end
  1572. else
  1573. {$endif cpu64bit}
  1574. begin
  1575. if assigned(paraloc^.next) then
  1576. internalerror(200410105);
  1577. unget_para(paraloc^);
  1578. gen_alloc_regvar(list,currpara);
  1579. gen_load_reg(paraloc^,currpara.initialloc.register);
  1580. end;
  1581. end;
  1582. LOC_CFPUREGISTER :
  1583. begin
  1584. {$if defined(sparc) or defined(arm)}
  1585. { Arm and Sparc passes floats in int registers, when loading to fpu register
  1586. we need a temp }
  1587. sizeleft := TCGSize2Size[currpara.initialloc.size];
  1588. tg.GetTemp(list,sizeleft,tt_normal,tempref);
  1589. href:=tempref;
  1590. while assigned(paraloc) do
  1591. begin
  1592. unget_para(paraloc^);
  1593. gen_load_ref(paraloc^,href,sizeleft);
  1594. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1595. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1596. paraloc:=paraloc^.next;
  1597. end;
  1598. gen_alloc_regvar(list,currpara);
  1599. cg.a_loadfpu_ref_reg(list,currpara.initialloc.size,currpara.initialloc.size,tempref,currpara.initialloc.register);
  1600. tg.UnGetTemp(list,tempref);
  1601. {$else sparc}
  1602. unget_para(paraloc^);
  1603. gen_alloc_regvar(list,currpara);
  1604. gen_load_reg(paraloc^,currpara.initialloc.register);
  1605. if assigned(paraloc^.next) then
  1606. internalerror(200410109);
  1607. {$endif sparc}
  1608. end;
  1609. LOC_CMMREGISTER :
  1610. begin
  1611. unget_para(paraloc^);
  1612. gen_alloc_regvar(list,currpara);
  1613. gen_load_reg(paraloc^,currpara.initialloc.register);
  1614. { data could come in two memory locations, for now
  1615. we simply ignore the sanity check (FK)
  1616. if assigned(paraloc^.next) then
  1617. internalerror(200410108);
  1618. }
  1619. end;
  1620. end;
  1621. end;
  1622. { generate copies of call by value parameters, must be done before
  1623. the initialization and body is parsed because the refcounts are
  1624. incremented using the local copies }
  1625. current_procinfo.procdef.parast.SymList.ForEachCall(@copyvalueparas,list);
  1626. {$ifdef powerpc}
  1627. { unget the register that contains the stack pointer before the procedure entry, }
  1628. { which is used to access the parameters in their original callee-side location }
  1629. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1630. cg.a_reg_dealloc(list,NR_R12);
  1631. {$endif powerpc}
  1632. {$ifdef powerpc64}
  1633. { unget the register that contains the stack pointer before the procedure entry, }
  1634. { which is used to access the parameters in their original callee-side location }
  1635. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1636. cg.a_reg_dealloc(list, NR_OLD_STACK_POINTER_REG);
  1637. {$endif powerpc64}
  1638. end;
  1639. procedure gen_initialize_code(list:TAsmList);
  1640. begin
  1641. { initialize local data like ansistrings }
  1642. case current_procinfo.procdef.proctypeoption of
  1643. potype_unitinit:
  1644. begin
  1645. { this is also used for initialization of variables in a
  1646. program which does not have a globalsymtable }
  1647. if assigned(current_module.globalsymtable) then
  1648. TSymtable(current_module.globalsymtable).SymList.ForEachCall(@initialize_data,list);
  1649. TSymtable(current_module.localsymtable).SymList.ForEachCall(@initialize_data,list);
  1650. TSymtable(current_module.localsymtable).SymList.ForEachCall(@initialize_regvars,list);
  1651. end;
  1652. { units have seperate code for initilization and finalization }
  1653. potype_unitfinalize: ;
  1654. { program init/final is generated in separate procedure }
  1655. potype_proginit:
  1656. begin
  1657. TSymtable(current_module.localsymtable).SymList.ForEachCall(@initialize_regvars,list);
  1658. end;
  1659. else
  1660. begin
  1661. if (localvartrashing <> -1) and
  1662. not(po_assembler in current_procinfo.procdef.procoptions) then
  1663. current_procinfo.procdef.localst.SymList.ForEachCall(@trash_variable,list);
  1664. current_procinfo.procdef.localst.SymList.ForEachCall(@initialize_data,list);
  1665. end;
  1666. end;
  1667. { initialisizes temp. ansi/wide string data }
  1668. inittempvariables(list);
  1669. { initialize ansi/widesstring para's }
  1670. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1671. current_procinfo.procdef.parast.SymList.ForEachCall(@init_paras,list);
  1672. {$ifdef OLDREGVARS}
  1673. load_regvars(list,nil);
  1674. {$endif OLDREGVARS}
  1675. end;
  1676. procedure gen_finalize_code(list:TAsmList);
  1677. begin
  1678. {$ifdef OLDREGVARS}
  1679. cleanup_regvars(list);
  1680. {$endif OLDREGVARS}
  1681. { finalize temporary data }
  1682. finalizetempvariables(list);
  1683. { finalize local data like ansistrings}
  1684. case current_procinfo.procdef.proctypeoption of
  1685. potype_unitfinalize:
  1686. begin
  1687. { this is also used for initialization of variables in a
  1688. program which does not have a globalsymtable }
  1689. if assigned(current_module.globalsymtable) then
  1690. TSymtable(current_module.globalsymtable).SymList.ForEachCall(@finalize_static_data,list);
  1691. TSymtable(current_module.localsymtable).SymList.ForEachCall(@finalize_static_data,list);
  1692. end;
  1693. { units/progs have separate code for initialization and finalization }
  1694. potype_unitinit: ;
  1695. { program init/final is generated in separate procedure }
  1696. potype_proginit: ;
  1697. else
  1698. current_procinfo.procdef.localst.SymList.ForEachCall(@finalize_local_vars,list);
  1699. end;
  1700. { finalize paras data }
  1701. if assigned(current_procinfo.procdef.parast) and
  1702. not(po_assembler in current_procinfo.procdef.procoptions) then
  1703. current_procinfo.procdef.parast.SymList.ForEachCall(@final_paras,list);
  1704. end;
  1705. procedure gen_entry_code(list:TAsmList);
  1706. var
  1707. paraloc1,
  1708. paraloc2 : tcgpara;
  1709. begin
  1710. paraloc1.init;
  1711. paraloc2.init;
  1712. { the actual profile code can clobber some registers,
  1713. therefore if the context must be saved, do it before
  1714. the actual call to the profile code
  1715. }
  1716. if (cs_profile in current_settings.moduleswitches) and
  1717. not(po_assembler in current_procinfo.procdef.procoptions) then
  1718. begin
  1719. { non-win32 can call mcout even in main }
  1720. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) or
  1721. not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1722. begin
  1723. cg.g_profilecode(list);
  1724. end;
  1725. end;
  1726. { call startup helpers from main program }
  1727. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1728. begin
  1729. { initialize units }
  1730. cg.allocallcpuregisters(list);
  1731. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1732. cg.deallocallcpuregisters(list);
  1733. end;
  1734. list.concat(Tai_force_line.Create);
  1735. {$ifdef OLDREGVARS}
  1736. load_regvars(list,nil);
  1737. {$endif OLDREGVARS}
  1738. paraloc1.done;
  1739. paraloc2.done;
  1740. end;
  1741. procedure gen_exit_code(list:TAsmList);
  1742. begin
  1743. { call __EXIT for main program }
  1744. if (not DLLsource) and
  1745. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1746. cg.a_call_name(list,'FPC_DO_EXIT');
  1747. end;
  1748. {****************************************************************************
  1749. Entry/Exit
  1750. ****************************************************************************}
  1751. function has_alias_name(pd:tprocdef;const s:string):boolean;
  1752. var
  1753. item : TCmdStrListItem;
  1754. begin
  1755. result:=true;
  1756. if pd.mangledname=s then
  1757. exit;
  1758. item := TCmdStrListItem(pd.aliasnames.first);
  1759. while assigned(item) do
  1760. begin
  1761. if item.str=s then
  1762. exit;
  1763. item := TCmdStrListItem(item.next);
  1764. end;
  1765. result:=false;
  1766. end;
  1767. procedure alloc_proc_symbol(pd: tprocdef);
  1768. var
  1769. item : TCmdStrListItem;
  1770. begin
  1771. item := TCmdStrListItem(pd.aliasnames.first);
  1772. while assigned(item) do
  1773. begin
  1774. current_asmdata.DefineAsmSymbol(item.str,AB_GLOBAL,AT_FUNCTION);
  1775. item := TCmdStrListItem(item.next);
  1776. end;
  1777. end;
  1778. procedure gen_proc_symbol(list:TAsmList);
  1779. var
  1780. item,
  1781. previtem : TCmdStrListItem;
  1782. begin
  1783. previtem:=nil;
  1784. item := TCmdStrListItem(current_procinfo.procdef.aliasnames.first);
  1785. while assigned(item) do
  1786. begin
  1787. { "double link" all procedure entry symbols via .reference }
  1788. { directives on darwin, because otherwise the linker }
  1789. { sometimes strips the procedure if only on of the symbols }
  1790. { is referenced }
  1791. if assigned(previtem) and
  1792. (target_info.system in systems_darwin) then
  1793. list.concat(tai_directive.create(asd_reference,item.str));
  1794. if (cs_profile in current_settings.moduleswitches) or
  1795. (po_global in current_procinfo.procdef.procoptions) then
  1796. list.concat(Tai_symbol.createname_global(item.str,AT_FUNCTION,0))
  1797. else
  1798. list.concat(Tai_symbol.createname(item.str,AT_FUNCTION,0));
  1799. if assigned(previtem) and
  1800. (target_info.system in systems_darwin) then
  1801. list.concat(tai_directive.create(asd_reference,previtem.str));
  1802. if tf_use_function_relative_addresses in target_info.flags then
  1803. list.concat(Tai_function_name.create(item.str));
  1804. previtem:=item;
  1805. item := TCmdStrListItem(item.next);
  1806. end;
  1807. current_procinfo.procdef.procstarttai:=tai(list.last);
  1808. end;
  1809. procedure gen_proc_symbol_end(list:TAsmList);
  1810. begin
  1811. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1812. current_procinfo.procdef.procendtai:=tai(list.last);
  1813. { finalisation marker for Mac OS X }
  1814. if (target_info.system in systems_darwin) and
  1815. (current_module.islibrary) and
  1816. (((current_module.flags and uf_finalize)<>0) or
  1817. (current_procinfo.procdef.proctypeoption = potype_proginit)) then
  1818. begin
  1819. if (current_procinfo.procdef.proctypeoption = potype_proginit) then
  1820. list.concat(tai_directive.create(asd_mod_init_func,''))
  1821. else
  1822. list.concat(tai_directive.create(asd_mod_term_func,''));
  1823. list.concat(tai_align.create(4));
  1824. list.concat(Tai_const.Createname(current_procinfo.procdef.mangledname,0));
  1825. end;
  1826. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1827. begin
  1828. if (target_info.system in (systems_darwin+[system_powerpc_macos])) and
  1829. not(current_module.islibrary) then
  1830. begin
  1831. list.concat(tai_section.create(sec_code,'',4));
  1832. list.concat(tai_symbol.createname_global(
  1833. target_info.cprefix+mainaliasname,AT_FUNCTION,0));
  1834. { keep argc, argv and envp properly on the stack }
  1835. cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
  1836. end;
  1837. end;
  1838. end;
  1839. procedure gen_proc_entry_code(list:TAsmList);
  1840. var
  1841. hitemp,
  1842. lotemp : longint;
  1843. begin
  1844. { generate call frame marker for dwarf call frame info }
  1845. current_asmdata.asmcfi.start_frame(list);
  1846. { All temps are know, write offsets used for information }
  1847. if (cs_asm_source in current_settings.globalswitches) then
  1848. begin
  1849. if tg.direction>0 then
  1850. begin
  1851. lotemp:=current_procinfo.tempstart;
  1852. hitemp:=tg.lasttemp;
  1853. end
  1854. else
  1855. begin
  1856. lotemp:=tg.lasttemp;
  1857. hitemp:=current_procinfo.tempstart;
  1858. end;
  1859. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1860. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1861. end;
  1862. { generate target specific proc entry code }
  1863. cg.g_proc_entry(list,current_procinfo.calc_stackframe_size,(po_nostackframe in current_procinfo.procdef.procoptions));
  1864. end;
  1865. procedure gen_proc_exit_code(list:TAsmList);
  1866. var
  1867. parasize : longint;
  1868. begin
  1869. { c style clearstack does not need to remove parameters from the stack, only the
  1870. return value when it was pushed by arguments }
  1871. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1872. begin
  1873. parasize:=0;
  1874. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  1875. inc(parasize,sizeof(aint));
  1876. end
  1877. else
  1878. parasize:=current_procinfo.para_stack_size;
  1879. { generate target specific proc exit code }
  1880. cg.g_proc_exit(list,parasize,(po_nostackframe in current_procinfo.procdef.procoptions));
  1881. { release return registers, needed for optimizer }
  1882. if not is_void(current_procinfo.procdef.returndef) then
  1883. location_free(list,current_procinfo.procdef.funcretloc[calleeside]);
  1884. { end of frame marker for call frame info }
  1885. current_asmdata.asmcfi.end_frame(list);
  1886. end;
  1887. procedure gen_stack_check_size_para(list:TAsmList);
  1888. var
  1889. paraloc1 : tcgpara;
  1890. begin
  1891. paraloc1.init;
  1892. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1893. paramanager.allocparaloc(list,paraloc1);
  1894. cg.a_param_const(list,OS_INT,current_procinfo.calc_stackframe_size,paraloc1);
  1895. paramanager.freeparaloc(list,paraloc1);
  1896. paraloc1.done;
  1897. end;
  1898. procedure gen_stack_check_call(list:TAsmList);
  1899. var
  1900. paraloc1 : tcgpara;
  1901. begin
  1902. paraloc1.init;
  1903. { Also alloc the register needed for the parameter }
  1904. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1905. paramanager.allocparaloc(list,paraloc1);
  1906. paramanager.freeparaloc(list,paraloc1);
  1907. { Call the helper }
  1908. cg.allocallcpuregisters(list);
  1909. cg.a_call_name(list,'FPC_STACKCHECK');
  1910. cg.deallocallcpuregisters(list);
  1911. paraloc1.done;
  1912. end;
  1913. procedure gen_save_used_regs(list:TAsmList);
  1914. begin
  1915. { Pure assembler routines need to save the registers themselves }
  1916. if (po_assembler in current_procinfo.procdef.procoptions) then
  1917. exit;
  1918. { oldfpccall expects all registers to be destroyed }
  1919. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1920. cg.g_save_registers(list);
  1921. end;
  1922. procedure gen_restore_used_regs(list:TAsmList);
  1923. begin
  1924. { Pure assembler routines need to save the registers themselves }
  1925. if (po_assembler in current_procinfo.procdef.procoptions) then
  1926. exit;
  1927. { oldfpccall expects all registers to be destroyed }
  1928. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1929. cg.g_restore_registers(list);
  1930. end;
  1931. {****************************************************************************
  1932. External handling
  1933. ****************************************************************************}
  1934. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  1935. begin
  1936. { add the procedure to the al_procedures }
  1937. maybe_new_object_file(list);
  1938. new_section(list,sec_code,lower(pd.mangledname),current_settings.alignment.procalign);
  1939. list.concat(Tai_align.create(current_settings.alignment.procalign));
  1940. if (po_global in pd.procoptions) then
  1941. list.concat(Tai_symbol.createname_global(pd.mangledname,AT_FUNCTION,0))
  1942. else
  1943. list.concat(Tai_symbol.createname(pd.mangledname,AT_FUNCTION,0));
  1944. cg.g_external_wrapper(list,pd,externalname);
  1945. end;
  1946. {****************************************************************************
  1947. Const Data
  1948. ****************************************************************************}
  1949. procedure insertbssdata(sym : tstaticvarsym);
  1950. var
  1951. l : aint;
  1952. varalign : shortint;
  1953. storefilepos : tfileposinfo;
  1954. list : TAsmList;
  1955. sectype : TAsmSectiontype;
  1956. begin
  1957. storefilepos:=current_filepos;
  1958. current_filepos:=sym.fileinfo;
  1959. l:=sym.getsize;
  1960. varalign:=sym.vardef.alignment;
  1961. if (varalign=0) then
  1962. varalign:=l;
  1963. if tf_section_threadvars in target_info.flags then
  1964. begin
  1965. if (vo_is_thread_var in sym.varoptions) then
  1966. begin
  1967. list:=current_asmdata.asmlists[al_threadvars];
  1968. sectype:=sec_threadvar;
  1969. end
  1970. else
  1971. begin
  1972. list:=current_asmdata.asmlists[al_globals];
  1973. sectype:=sec_bss;
  1974. end;
  1975. end
  1976. else
  1977. begin
  1978. if (vo_is_thread_var in sym.varoptions) then
  1979. begin
  1980. inc(l,sizeof(aint));
  1981. { it doesn't help to set a higher alignment, as }
  1982. { the first sizeof(aint) bytes field will offset }
  1983. { everything anyway }
  1984. varalign:=sizeof(aint);
  1985. end;
  1986. list:=current_asmdata.asmlists[al_globals];
  1987. sectype:=sec_bss;
  1988. end;
  1989. varalign:=var_align(varalign);
  1990. maybe_new_object_file(list);
  1991. new_section(list,sectype,lower(sym.mangledname),varalign);
  1992. if (sym.owner.symtabletype=globalsymtable) or
  1993. create_smartlink or
  1994. DLLSource or
  1995. (assigned(current_procinfo) and
  1996. (po_inline in current_procinfo.procdef.procoptions)) or
  1997. (vo_is_public in sym.varoptions) then
  1998. list.concat(Tai_datablock.create_global(sym.mangledname,l))
  1999. else
  2000. list.concat(Tai_datablock.create(sym.mangledname,l));
  2001. current_filepos:=storefilepos;
  2002. end;
  2003. procedure gen_alloc_symtable(list:TAsmList;st:TSymtable);
  2004. procedure setlocalloc(vs:tabstractnormalvarsym);
  2005. begin
  2006. if cs_asm_source in current_settings.globalswitches then
  2007. begin
  2008. case vs.initialloc.loc of
  2009. LOC_REFERENCE :
  2010. begin
  2011. if not assigned(vs.initialloc.reference.symbol) then
  2012. list.concat(Tai_comment.Create(strpnew('Var '+vs.realname+' located at '+
  2013. std_regname(vs.initialloc.reference.base)+tostr_with_plus(vs.initialloc.reference.offset))));
  2014. end;
  2015. end;
  2016. end;
  2017. vs.localloc:=vs.initialloc;
  2018. end;
  2019. var
  2020. i : longint;
  2021. sym : tsym;
  2022. vs : tabstractnormalvarsym;
  2023. isaddr : boolean;
  2024. begin
  2025. for i:=0 to st.SymList.Count-1 do
  2026. begin
  2027. sym:=tsym(st.SymList[i]);
  2028. case sym.typ of
  2029. staticvarsym :
  2030. begin
  2031. vs:=tabstractnormalvarsym(sym);
  2032. { The code in laodnode.pass_generatecode will create the
  2033. LOC_REFERENCE instead for all none register variables. This is
  2034. required because we can't store an asmsymbol in the localloc because
  2035. the asmsymbol is invalid after an unit is compiled. This gives
  2036. problems when this procedure is inlined in an other unit (PFV) }
  2037. if vs.is_regvar(false) then
  2038. begin
  2039. vs.initialloc.loc:=tvarregable2tcgloc[vs.varregable];
  2040. vs.initialloc.size:=def_cgsize(vs.vardef);
  2041. gen_alloc_regvar(list,vs);
  2042. setlocalloc(vs);
  2043. end;
  2044. end;
  2045. paravarsym :
  2046. begin
  2047. vs:=tabstractnormalvarsym(sym);
  2048. { Parameters passed to assembler procedures need to be kept
  2049. in the original location }
  2050. if (po_assembler in current_procinfo.procdef.procoptions) then
  2051. tparavarsym(vs).paraloc[calleeside].get_location(vs.initialloc)
  2052. else
  2053. begin
  2054. isaddr:=paramanager.push_addr_param(vs.varspez,vs.vardef,current_procinfo.procdef.proccalloption);
  2055. if isaddr then
  2056. vs.initialloc.size:=OS_ADDR
  2057. else
  2058. vs.initialloc.size:=def_cgsize(vs.vardef);
  2059. if vs.is_regvar(isaddr) then
  2060. vs.initialloc.loc:=tvarregable2tcgloc[vs.varregable]
  2061. else
  2062. begin
  2063. vs.initialloc.loc:=LOC_REFERENCE;
  2064. { Reuse the parameter location for values to are at a single location on the stack }
  2065. if paramanager.param_use_paraloc(tparavarsym(sym).paraloc[calleeside]) then
  2066. begin
  2067. reference_reset_base(vs.initialloc.reference,tparavarsym(sym).paraloc[calleeside].location^.reference.index,
  2068. tparavarsym(sym).paraloc[calleeside].location^.reference.offset);
  2069. end
  2070. else
  2071. begin
  2072. if isaddr then
  2073. tg.GetLocal(list,sizeof(aint),voidpointertype,vs.initialloc.reference)
  2074. else
  2075. tg.GetLocal(list,vs.getsize,tparavarsym(sym).paraloc[calleeside].alignment,vs.vardef,vs.initialloc.reference);
  2076. end;
  2077. end;
  2078. end;
  2079. setlocalloc(vs);
  2080. end;
  2081. localvarsym :
  2082. begin
  2083. vs:=tabstractnormalvarsym(sym);
  2084. vs.initialloc.size:=def_cgsize(vs.vardef);
  2085. if (m_delphi in current_settings.modeswitches) and
  2086. (po_assembler in current_procinfo.procdef.procoptions) and
  2087. (vo_is_funcret in vs.varoptions) and
  2088. (vs.refs=0) then
  2089. begin
  2090. { not referenced, so don't allocate. Use dummy to }
  2091. { avoid ie's later on because of LOC_INVALID }
  2092. vs.initialloc.loc:=LOC_REGISTER;
  2093. vs.initialloc.size:=OS_INT;
  2094. vs.initialloc.register:=NR_FUNCTION_RESULT_REG;
  2095. end
  2096. else if vs.is_regvar(false) then
  2097. begin
  2098. vs.initialloc.loc:=tvarregable2tcgloc[vs.varregable];
  2099. gen_alloc_regvar(list,vs);
  2100. end
  2101. else
  2102. begin
  2103. vs.initialloc.loc:=LOC_REFERENCE;
  2104. tg.GetLocal(list,vs.getsize,vs.vardef,vs.initialloc.reference);
  2105. end;
  2106. setlocalloc(vs);
  2107. end;
  2108. end;
  2109. end;
  2110. end;
  2111. procedure add_regvars(var rv: tusedregvars; const location: tlocation);
  2112. begin
  2113. case location.loc of
  2114. LOC_CREGISTER:
  2115. {$ifndef cpu64bit}
  2116. if location.size in [OS_64,OS_S64] then
  2117. begin
  2118. rv.intregvars.addnodup(getsupreg(location.register64.reglo));
  2119. rv.intregvars.addnodup(getsupreg(location.register64.reghi));
  2120. end
  2121. else
  2122. {$endif cpu64bit}
  2123. rv.intregvars.addnodup(getsupreg(location.register));
  2124. LOC_CFPUREGISTER:
  2125. rv.fpuregvars.addnodup(getsupreg(location.register));
  2126. LOC_CMMREGISTER:
  2127. rv.mmregvars.addnodup(getsupreg(location.register));
  2128. end;
  2129. end;
  2130. function do_get_used_regvars(var n: tnode; arg: pointer): foreachnoderesult;
  2131. var
  2132. rv: pusedregvars absolute arg;
  2133. begin
  2134. case (n.nodetype) of
  2135. temprefn:
  2136. { We only have to synchronise a tempnode before a loop if it is }
  2137. { not created inside the loop, and only synchronise after the }
  2138. { loop if it's not destroyed inside the loop. If it's created }
  2139. { before the loop and not yet destroyed, then before the loop }
  2140. { is secondpassed tempinfo^.valid will be true, and we get the }
  2141. { correct registers. If it's not destroyed inside the loop, }
  2142. { then after the loop has been secondpassed tempinfo^.valid }
  2143. { be true and we also get the right registers. In other cases, }
  2144. { tempinfo^.valid will be false and so we do not add }
  2145. { unnecessary registers. This way, we don't have to look at }
  2146. { tempcreate and tempdestroy nodes to get this info (JM) }
  2147. if (ti_valid in ttemprefnode(n).tempinfo^.flags) then
  2148. add_regvars(rv^,ttemprefnode(n).tempinfo^.location);
  2149. loadn:
  2150. if (tloadnode(n).symtableentry.typ in [staticvarsym,localvarsym,paravarsym]) then
  2151. add_regvars(rv^,tabstractnormalvarsym(tloadnode(n).symtableentry).localloc);
  2152. vecn:
  2153. { range checks sometimes need the high parameter }
  2154. if (cs_check_range in current_settings.localswitches) and
  2155. (is_open_array(tvecnode(n).left.resultdef) or
  2156. is_array_of_const(tvecnode(n).left.resultdef)) and
  2157. not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2158. add_regvars(rv^,tabstractnormalvarsym(get_high_value_sym(tparavarsym(tloadnode(tvecnode(n).left).symtableentry))).localloc)
  2159. end;
  2160. result := fen_true;
  2161. end;
  2162. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  2163. begin
  2164. foreachnodestatic(n,@do_get_used_regvars,@rv);
  2165. end;
  2166. (*
  2167. See comments at declaration of pusedregvarscommon
  2168. function do_get_used_regvars_common(var n: tnode; arg: pointer): foreachnoderesult;
  2169. var
  2170. rv: pusedregvarscommon absolute arg;
  2171. begin
  2172. if (n.nodetype = loadn) and
  2173. (tloadnode(n).symtableentry.typ in [staticvarsym,localvarsym,paravarsym]) then
  2174. with tabstractnormalvarsym(tloadnode(n).symtableentry).localloc do
  2175. case loc of
  2176. LOC_CREGISTER:
  2177. { if not yet encountered in this node tree }
  2178. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2179. { but nevertheless already encountered somewhere }
  2180. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2181. { then it's a regvar used in two or more node trees }
  2182. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2183. LOC_CFPUREGISTER:
  2184. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2185. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2186. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2187. LOC_CMMREGISTER:
  2188. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2189. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2190. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2191. end;
  2192. result := fen_true;
  2193. end;
  2194. procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  2195. begin
  2196. rv.myregvars.intregvars.clear;
  2197. rv.myregvars.fpuregvars.clear;
  2198. rv.myregvars.mmregvars.clear;
  2199. foreachnodestatic(n,@do_get_used_regvars_common,@rv);
  2200. end;
  2201. *)
  2202. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  2203. var
  2204. count: longint;
  2205. begin
  2206. for count := 1 to rv.intregvars.length do
  2207. cg.a_reg_sync(list,newreg(R_INTREGISTER,rv.intregvars.readidx(count-1),R_SUBWHOLE));
  2208. for count := 1 to rv.fpuregvars.length do
  2209. cg.a_reg_sync(list,newreg(R_FPUREGISTER,rv.fpuregvars.readidx(count-1),R_SUBWHOLE));
  2210. for count := 1 to rv.mmregvars.length do
  2211. cg.a_reg_sync(list,newreg(R_MMREGISTER,rv.mmregvars.readidx(count-1),R_SUBWHOLE));
  2212. end;
  2213. {*****************************************************************************
  2214. SSA support
  2215. *****************************************************************************}
  2216. type
  2217. preplaceregrec = ^treplaceregrec;
  2218. treplaceregrec = record
  2219. old, new: tregister;
  2220. {$ifndef cpu64bit}
  2221. oldhi, newhi: tregister;
  2222. {$endif cpu64bit}
  2223. ressym: tsym;
  2224. end;
  2225. function doreplace(var n: tnode; para: pointer): foreachnoderesult;
  2226. var
  2227. rr: preplaceregrec absolute para;
  2228. begin
  2229. result := fen_false;
  2230. if (nf_is_funcret in n.flags) and (fc_exit in flowcontrol) then
  2231. exit;
  2232. case n.nodetype of
  2233. loadn:
  2234. begin
  2235. if (tabstractvarsym(tloadnode(n).symtableentry).varoptions * [vo_is_dll_var, vo_is_thread_var] = []) and
  2236. not assigned(tloadnode(n).left) and
  2237. (tloadnode(n).symtableentry <> rr^.ressym) and
  2238. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  2239. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register = rr^.old) then
  2240. begin
  2241. {$ifndef cpu64bit}
  2242. { it's possible a 64 bit location was shifted and/xor typecasted }
  2243. { in a 32 bit value, so only 1 register was left in the location }
  2244. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.size in [OS_64,OS_S64]) then
  2245. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi = rr^.oldhi) then
  2246. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi := rr^.newhi
  2247. else
  2248. exit;
  2249. {$endif cpu64bit}
  2250. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register := rr^.new;
  2251. result := fen_norecurse_true;
  2252. end;
  2253. end;
  2254. temprefn:
  2255. begin
  2256. if (ti_valid in ttemprefnode(n).tempinfo^.flags) and
  2257. (ttemprefnode(n).tempinfo^.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  2258. (ttemprefnode(n).tempinfo^.location.register = rr^.old) then
  2259. begin
  2260. {$ifndef cpu64bit}
  2261. { it's possible a 64 bit location was shifted and/xor typecasted }
  2262. { in a 32 bit value, so only 1 register was left in the location }
  2263. if (ttemprefnode(n).tempinfo^.location.size in [OS_64,OS_S64]) then
  2264. if (ttemprefnode(n).tempinfo^.location.register64.reghi = rr^.oldhi) then
  2265. ttemprefnode(n).tempinfo^.location.register64.reghi := rr^.newhi
  2266. else
  2267. exit;
  2268. {$endif cpu64bit}
  2269. ttemprefnode(n).tempinfo^.location.register := rr^.new;
  2270. result := fen_norecurse_true;
  2271. end;
  2272. end;
  2273. { optimize the searching a bit }
  2274. derefn,addrn,
  2275. calln,inlinen,casen,
  2276. addn,subn,muln,
  2277. andn,orn,xorn,
  2278. ltn,lten,gtn,gten,equaln,unequaln,
  2279. slashn,divn,shrn,shln,notn,
  2280. inn,
  2281. asn,isn:
  2282. result := fen_norecurse_false;
  2283. end;
  2284. end;
  2285. procedure maybechangeloadnodereg(list: TAsmList; var n: tnode; reload: boolean);
  2286. var
  2287. rr: treplaceregrec;
  2288. begin
  2289. if not (n.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) or
  2290. ([fc_inflowcontrol,fc_gotolabel] * flowcontrol <> []) then
  2291. exit;
  2292. rr.old := n.location.register;
  2293. rr.ressym := nil;
  2294. {$ifndef cpu64bit}
  2295. rr.oldhi := NR_NO;
  2296. {$endif cpu64bit}
  2297. case n.location.loc of
  2298. LOC_CREGISTER:
  2299. begin
  2300. {$ifndef cpu64bit}
  2301. if (n.location.size in [OS_64,OS_S64]) then
  2302. begin
  2303. rr.oldhi := n.location.register64.reghi;
  2304. rr.new := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  2305. rr.newhi := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  2306. end
  2307. else
  2308. {$endif cpu64bit}
  2309. rr.new := cg.getintregister(current_asmdata.CurrAsmList,n.location.size);
  2310. end;
  2311. LOC_CFPUREGISTER:
  2312. rr.new := cg.getfpuregister(current_asmdata.CurrAsmList,n.location.size);
  2313. {$ifdef SUPPORT_MMX}
  2314. LOC_CMMXREGISTER:
  2315. rr.new := tcgx86(cg).getmmxregister(current_asmdata.CurrAsmList);
  2316. {$endif SUPPORT_MMX}
  2317. LOC_CMMREGISTER:
  2318. rr.new := cg.getmmregister(current_asmdata.CurrAsmList,n.location.size);
  2319. else
  2320. exit;
  2321. end;
  2322. if (current_procinfo.procdef.funcretloc[calleeside].loc<>LOC_VOID) and
  2323. assigned(current_procinfo.procdef.funcretsym) and
  2324. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs <> 0) then
  2325. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  2326. rr.ressym:=tsym(current_procinfo.procdef.parast.Find('self'))
  2327. else
  2328. rr.ressym:=current_procinfo.procdef.funcretsym;
  2329. if not foreachnodestatic(n,@doreplace,@rr) then
  2330. exit;
  2331. if reload then
  2332. case n.location.loc of
  2333. LOC_CREGISTER:
  2334. begin
  2335. {$ifndef cpu64bit}
  2336. if (n.location.size in [OS_64,OS_S64]) then
  2337. cg64.a_load64_reg_reg(list,n.location.register64,joinreg64(rr.new,rr.newhi))
  2338. else
  2339. {$endif cpu64bit}
  2340. cg.a_load_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new);
  2341. end;
  2342. LOC_CFPUREGISTER:
  2343. cg.a_loadfpu_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new);
  2344. {$ifdef SUPPORT_MMX}
  2345. LOC_CMMXREGISTER:
  2346. cg.a_loadmm_reg_reg(list,OS_M64,OS_M64,n.location.register,rr.new,nil);
  2347. {$endif SUPPORT_MMX}
  2348. LOC_CMMREGISTER:
  2349. cg.a_loadmm_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new,nil);
  2350. else
  2351. internalerror(2006090920);
  2352. end;
  2353. { now that we've change the loadn/temp, also change the node result location }
  2354. {$ifndef cpu64bit}
  2355. if (n.location.size in [OS_64,OS_S64]) then
  2356. begin
  2357. n.location.register64.reglo := rr.new;
  2358. n.location.register64.reghi := rr.newhi;
  2359. end
  2360. else
  2361. {$endif cpu64bit}
  2362. n.location.register := rr.new;
  2363. end;
  2364. procedure gen_free_symtable(list:TAsmList;st:TSymtable);
  2365. var
  2366. i : longint;
  2367. sym : tsym;
  2368. begin
  2369. for i:=0 to st.SymList.Count-1 do
  2370. begin
  2371. sym:=tsym(st.SymList[i]);
  2372. if (sym.typ in [staticvarsym,localvarsym,paravarsym]) then
  2373. begin
  2374. with tabstractnormalvarsym(sym) do
  2375. begin
  2376. { Note: We need to keep the data available in memory
  2377. for the sub procedures that can access local data
  2378. in the parent procedures }
  2379. case localloc.loc of
  2380. LOC_CREGISTER :
  2381. if (pi_has_goto in current_procinfo.flags) then
  2382. {$ifndef cpu64bit}
  2383. if def_cgsize(vardef) in [OS_64,OS_S64] then
  2384. begin
  2385. cg.a_reg_sync(list,localloc.register64.reglo);
  2386. cg.a_reg_sync(list,localloc.register64.reghi);
  2387. end
  2388. else
  2389. {$endif cpu64bit}
  2390. cg.a_reg_sync(list,localloc.register);
  2391. LOC_CFPUREGISTER,
  2392. LOC_CMMREGISTER:
  2393. if (pi_has_goto in current_procinfo.flags) then
  2394. cg.a_reg_sync(list,localloc.register);
  2395. LOC_REFERENCE :
  2396. begin
  2397. if typ in [localvarsym,paravarsym] then
  2398. tg.Ungetlocal(list,localloc.reference);
  2399. end;
  2400. end;
  2401. end;
  2402. end;
  2403. end;
  2404. end;
  2405. procedure gen_intf_wrapper(list:TAsmList;_class:tobjectdef);
  2406. var
  2407. i,j : longint;
  2408. tmps : string;
  2409. pd : TProcdef;
  2410. ImplIntf : TImplementedInterface;
  2411. begin
  2412. for i:=0 to _class.ImplementedInterfaces.count-1 do
  2413. begin
  2414. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  2415. if (ImplIntf=ImplIntf.VtblImplIntf) and
  2416. assigned(ImplIntf.ProcDefs) then
  2417. begin
  2418. for j:=0 to ImplIntf.ProcDefs.Count-1 do
  2419. begin
  2420. pd:=TProcdef(ImplIntf.ProcDefs[j]);
  2421. tmps:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+
  2422. ImplIntf.IntfDef.objname^+'_$_'+tostr(j)+'_$_'+pd.mangledname);
  2423. { create wrapper code }
  2424. new_section(list,sec_code,tmps,0);
  2425. cg.init_register_allocators;
  2426. cg.g_intf_wrapper(list,pd,tmps,ImplIntf.ioffset);
  2427. cg.done_register_allocators;
  2428. end;
  2429. end;
  2430. end;
  2431. end;
  2432. procedure gen_intf_wrappers(list:TAsmList;st:TSymtable);
  2433. var
  2434. i : longint;
  2435. def : tdef;
  2436. begin
  2437. for i:=0 to st.DefList.Count-1 do
  2438. begin
  2439. def:=tdef(st.DefList[i]);
  2440. if is_class(def) then
  2441. gen_intf_wrapper(list,tobjectdef(def));
  2442. end;
  2443. end;
  2444. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  2445. var
  2446. href : treference;
  2447. begin
  2448. if is_object(objdef) then
  2449. begin
  2450. case selfloc.loc of
  2451. LOC_CREFERENCE,
  2452. LOC_REFERENCE:
  2453. begin
  2454. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2455. cg.a_loadaddr_ref_reg(list,selfloc.reference,href.base);
  2456. end;
  2457. else
  2458. internalerror(200305056);
  2459. end;
  2460. end
  2461. else
  2462. begin
  2463. case selfloc.loc of
  2464. LOC_REGISTER:
  2465. begin
  2466. {$ifdef cpu_uses_separate_address_registers}
  2467. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  2468. begin
  2469. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2470. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,selfloc.register,href.base);
  2471. end
  2472. else
  2473. {$endif cpu_uses_separate_address_registers}
  2474. reference_reset_base(href,selfloc.register,objdef.vmt_offset);
  2475. end;
  2476. LOC_CREGISTER,
  2477. LOC_CREFERENCE,
  2478. LOC_REFERENCE:
  2479. begin
  2480. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2481. cg.a_load_loc_reg(list,OS_ADDR,selfloc,href.base);
  2482. end;
  2483. else
  2484. internalerror(200305057);
  2485. end;
  2486. end;
  2487. vmtreg:=cg.getaddressregister(list);
  2488. cg.g_maybe_testself(list,href.base);
  2489. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,vmtreg);
  2490. { test validity of VMT }
  2491. if not(is_interface(objdef)) and
  2492. not(is_cppclass(objdef)) then
  2493. cg.g_maybe_testvmt(list,vmtreg,objdef);
  2494. end;
  2495. function getprocalign : shortint;
  2496. begin
  2497. { gprof uses 16 byte granularity }
  2498. if (cs_profile in current_settings.moduleswitches) then
  2499. result:=16
  2500. else
  2501. result:=current_settings.alignment.procalign;
  2502. end;
  2503. procedure gen_pic_helpers(list : TAsmList);
  2504. {$ifdef i386}
  2505. var
  2506. href : treference;
  2507. {$endif i386}
  2508. begin
  2509. { if other cpus require such helpers as well, it can be solved more cleanly }
  2510. {$ifdef i386}
  2511. if current_module.requires_ebx_pic_helper then
  2512. begin
  2513. new_section(list,sec_code,'fpc_geteipasebx',0);
  2514. list.concat(tai_symbol.Createname('fpc_geteipasebx',AT_FUNCTION,getprocalign));
  2515. reference_reset(href);
  2516. href.base:=NR_ESP;
  2517. list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,NR_EBX));
  2518. list.concat(taicpu.op_none(A_RET,S_NO));
  2519. end;
  2520. if current_module.requires_ecx_pic_helper then
  2521. begin
  2522. new_section(list,sec_code,'fpc_geteipasecx',0);
  2523. list.concat(tai_symbol.Createname('fpc_geteipasecx',AT_FUNCTION,getprocalign));
  2524. reference_reset(href);
  2525. href.base:=NR_ESP;
  2526. list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,NR_ECX));
  2527. list.concat(taicpu.op_none(A_RET,S_NO));
  2528. end;
  2529. {$endif i386}
  2530. end;
  2531. end.