ncgutil.pas 107 KB

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