ncgutil.pas 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791
  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. { Retrieve the location of the data pointed to in location l, when the location is
  54. a register it is expected to contain the address of the data }
  55. procedure location_get_data_ref(list:TAsmList;const l:tlocation;var ref:treference;loadref:boolean);
  56. function maybe_pushfpu(list:TAsmList;needed : byte;var l:tlocation) : boolean;
  57. procedure alloc_proc_symbol(pd: tprocdef);
  58. procedure gen_proc_symbol(list:TAsmList);
  59. procedure gen_proc_symbol_end(list:TAsmList);
  60. procedure gen_proc_entry_code(list:TAsmList);
  61. procedure gen_proc_exit_code(list:TAsmList);
  62. procedure gen_stack_check_size_para(list:TAsmList);
  63. procedure gen_stack_check_call(list:TAsmList);
  64. procedure gen_save_used_regs(list:TAsmList);
  65. procedure gen_restore_used_regs(list:TAsmList);
  66. procedure gen_initialize_code(list:TAsmList);
  67. procedure gen_finalize_code(list:TAsmList);
  68. procedure gen_entry_code(list:TAsmList);
  69. procedure gen_exit_code(list:TAsmList);
  70. procedure gen_load_para_value(list:TAsmList);
  71. procedure gen_load_return_value(list:TAsmList);
  72. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  73. procedure gen_intf_wrappers(list:TAsmList;st:tsymtable);
  74. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  75. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  76. { adds the regvars used in n and its children to rv.allregvars,
  77. those which were already in rv.allregvars to rv.commonregvars and
  78. uses rv.myregvars as scratch (so that two uses of the same regvar
  79. in a single tree to make it appear in commonregvars). Useful to
  80. find out which regvars are used in two different node trees
  81. (e.g. in the "else" and "then" path, or in various case blocks }
  82. // procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  83. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  84. { if the result of n is a LOC_C(..)REGISTER, try to find the corresponding }
  85. { loadn and change its location to a new register (= SSA) }
  86. procedure maybechangeloadnodereg(var n: tnode);
  87. {#
  88. Allocate the buffers for exception management and setjmp environment.
  89. Return a pointer to these buffers, send them to the utility routine
  90. so they are registered, and then call setjmp.
  91. Then compare the result of setjmp with 0, and if not equal
  92. to zero, then jump to exceptlabel.
  93. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  94. It is to note that this routine may be called *after* the stackframe of a
  95. routine has been called, therefore on machines where the stack cannot
  96. be modified, all temps should be allocated on the heap instead of the
  97. stack.
  98. }
  99. const
  100. EXCEPT_BUF_SIZE = 3*sizeof(aint);
  101. type
  102. texceptiontemps=record
  103. jmpbuf,
  104. envbuf,
  105. reasonbuf : treference;
  106. end;
  107. procedure get_exception_temps(list:TAsmList;var t:texceptiontemps);
  108. procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  109. procedure new_exception(list:TAsmList;const t:texceptiontemps;exceptlabel:tasmlabel);
  110. procedure free_exception(list:TAsmList;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  111. procedure insertbssdata(sym : tglobalvarsym);
  112. procedure gen_alloc_symtable(list:TAsmList;st:tsymtable);
  113. procedure gen_free_symtable(list:TAsmList;st:tsymtable);
  114. { rtti and init/final }
  115. procedure generate_rtti(p:Ttypesym);
  116. procedure generate_inittable(p:tsym);
  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.resulttype.def) then
  187. begin
  188. if nf_swaped 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_swaped in p.flags then
  210. exclude(p.flags,nf_swaped)
  211. else
  212. include(p.flags,nf_swaped);
  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:=aktfilepos;
  231. aktfilepos:=p.fileinfo;
  232. if is_boolean(p.resulttype.def) 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.resulttype.def);
  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. aktfilepos:=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 aktoptimizerswitches) 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 aktoptimizerswitches) 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.restype.def.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,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.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_mem(list:TAsmList;var l:tlocation);
  659. var
  660. r : treference;
  661. begin
  662. case l.loc of
  663. LOC_FPUREGISTER,
  664. LOC_CFPUREGISTER :
  665. begin
  666. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  667. cg.a_loadfpu_reg_ref(list,l.size,l.register,r);
  668. location_reset(l,LOC_REFERENCE,l.size);
  669. l.reference:=r;
  670. end;
  671. LOC_MMREGISTER,
  672. LOC_CMMREGISTER:
  673. begin
  674. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  675. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  676. location_reset(l,LOC_REFERENCE,l.size);
  677. l.reference:=r;
  678. end;
  679. LOC_CONSTANT,
  680. LOC_REGISTER,
  681. LOC_CREGISTER :
  682. begin
  683. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  684. {$ifndef cpu64bit}
  685. if l.size in [OS_64,OS_S64] then
  686. cg64.a_load64_loc_ref(list,l,r)
  687. else
  688. {$endif cpu64bit}
  689. cg.a_load_loc_ref(list,l.size,l,r);
  690. location_reset(l,LOC_REFERENCE,l.size);
  691. l.reference:=r;
  692. end;
  693. LOC_SUBSETREG,
  694. LOC_CSUBSETREG,
  695. LOC_SUBSETREF,
  696. LOC_CSUBSETREF:
  697. begin
  698. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  699. cg.a_load_loc_ref(list,l.size,l,r);
  700. location_reset(l,LOC_REFERENCE,l.size);
  701. l.reference:=r;
  702. end;
  703. LOC_CREFERENCE,
  704. LOC_REFERENCE : ;
  705. else
  706. internalerror(200203219);
  707. end;
  708. end;
  709. procedure location_get_data_ref(list:TAsmList;const l:tlocation;var ref:treference;loadref:boolean);
  710. begin
  711. case l.loc of
  712. LOC_REGISTER,
  713. LOC_CREGISTER :
  714. begin
  715. if not loadref then
  716. internalerror(200410231);
  717. reference_reset_base(ref,l.register,0);
  718. end;
  719. LOC_REFERENCE,
  720. LOC_CREFERENCE :
  721. begin
  722. if loadref then
  723. begin
  724. reference_reset_base(ref,cg.getaddressregister(list),0);
  725. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,l.reference,ref.base);
  726. end
  727. else
  728. ref:=l.reference;
  729. end;
  730. else
  731. internalerror(200309181);
  732. end;
  733. end;
  734. {*****************************************************************************
  735. Maybe_Save
  736. *****************************************************************************}
  737. function maybe_pushfpu(list:TAsmList;needed : byte;var l:tlocation) : boolean;
  738. begin
  739. {$ifdef i386}
  740. if (needed>=maxfpuregs) and
  741. (l.loc = LOC_FPUREGISTER) then
  742. begin
  743. location_force_mem(list,l);
  744. maybe_pushfpu:=true;
  745. end
  746. else
  747. maybe_pushfpu:=false;
  748. {$else i386}
  749. maybe_pushfpu:=false;
  750. {$endif i386}
  751. end;
  752. {****************************************************************************
  753. Init/Finalize Code
  754. ****************************************************************************}
  755. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  756. var
  757. href : treference;
  758. hreg : tregister;
  759. list : TAsmList;
  760. hsym : tparavarsym;
  761. l : longint;
  762. localcopyloc : tlocation;
  763. begin
  764. list:=TAsmList(arg);
  765. if (tsym(p).typ=paravarsym) and
  766. (tparavarsym(p).varspez=vs_value) and
  767. (paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vartype.def,current_procinfo.procdef.proccalloption)) then
  768. begin
  769. location_get_data_ref(list,tparavarsym(p).localloc,href,true);
  770. if is_open_array(tparavarsym(p).vartype.def) or
  771. is_array_of_const(tparavarsym(p).vartype.def) then
  772. begin
  773. { cdecl functions don't have a high pointer so it is not possible to generate
  774. a local copy }
  775. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  776. begin
  777. hsym:=tparavarsym(tsym(p).owner.search('high'+p.name));
  778. if not assigned(hsym) then
  779. internalerror(200306061);
  780. hreg:=cg.getaddressregister(list);
  781. if not is_packed_array(tparavarsym(p).vartype.def) then
  782. cg.g_copyvaluepara_openarray(list,href,hsym.localloc,tarraydef(tparavarsym(p).vartype.def).elesize,hreg)
  783. else
  784. internalerror(2006080401);
  785. // cg.g_copyvaluepara_packedopenarray(list,href,hsym.localloc,tarraydef(tparavarsym(p).vartype.def).elepackedbitsize,hreg);
  786. cg.a_load_reg_loc(list,OS_ADDR,hreg,tparavarsym(p).localloc);
  787. end;
  788. end
  789. else
  790. begin
  791. { Allocate space for the local copy }
  792. l:=tparavarsym(p).getsize;
  793. localcopyloc.loc:=LOC_REFERENCE;
  794. localcopyloc.size:=int_cgsize(l);
  795. tg.GetLocal(list,l,tparavarsym(p).vartype.def,localcopyloc.reference);
  796. { Copy data }
  797. if is_shortstring(tparavarsym(p).vartype.def) then
  798. begin
  799. { this code is only executed before the code for the body and the entry/exit code is generated
  800. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  801. }
  802. include(current_procinfo.flags,pi_do_call);
  803. cg.g_copyshortstring(list,href,localcopyloc.reference,tstringdef(tparavarsym(p).vartype.def).len)
  804. end
  805. else
  806. begin
  807. { pass proper alignment info }
  808. localcopyloc.reference.alignment:=tparavarsym(p).vartype.def.alignment;
  809. cg.g_concatcopy(list,href,localcopyloc.reference,tparavarsym(p).vartype.def.size);
  810. end;
  811. { update localloc of varsym }
  812. tg.Ungetlocal(list,tparavarsym(p).localloc.reference);
  813. tparavarsym(p).localloc:=localcopyloc;
  814. end;
  815. end;
  816. end;
  817. const
  818. {$ifdef cpu64bit}
  819. trashintvalues: array[0..nroftrashvalues-1] of aint = ($5555555555555555,aint($AAAAAAAAAAAAAAAA),aint($EFEFEFEFEFEFEFEF),0);
  820. {$else cpu64bit}
  821. trashintvalues: array[0..nroftrashvalues-1] of aint = ($55555555,aint($AAAAAAAA),aint($EFEFEFEF),0);
  822. {$endif cpu64bit}
  823. procedure trash_reference(list: TAsmList; const ref: treference; size: aint);
  824. var
  825. countreg, valuereg: tregister;
  826. hl: tasmlabel;
  827. trashintval: aint;
  828. tmpref: treference;
  829. begin
  830. trashintval := trashintvalues[localvartrashing];
  831. case size of
  832. 0: ; { empty record }
  833. 1: cg.a_load_const_ref(list,OS_8,byte(trashintval),ref);
  834. 2: cg.a_load_const_ref(list,OS_16,word(trashintval),ref);
  835. 4: cg.a_load_const_ref(list,OS_32,longint(trashintval),ref);
  836. {$ifdef cpu64bit}
  837. 8: cg.a_load_const_ref(list,OS_64,int64(trashintval),ref);
  838. {$endif cpu64bit}
  839. else
  840. begin
  841. countreg := cg.getintregister(list,OS_ADDR);
  842. valuereg := cg.getintregister(list,OS_8);
  843. cg.a_load_const_reg(list,OS_INT,size,countreg);
  844. cg.a_load_const_reg(list,OS_8,byte(trashintval),valuereg);
  845. current_asmdata.getjumplabel(hl);
  846. tmpref := ref;
  847. if (tmpref.index <> NR_NO) then
  848. internalerror(200607201);
  849. tmpref.index := countreg;
  850. dec(tmpref.offset);
  851. cg.a_label(list,hl);
  852. cg.a_load_reg_ref(list,OS_8,OS_8,valuereg,tmpref);
  853. cg.a_op_const_reg(list,OP_SUB,OS_INT,1,countreg);
  854. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,countreg,hl);
  855. cg.a_reg_sync(list,tmpref.base);
  856. cg.a_reg_sync(list,valuereg);
  857. end;
  858. end;
  859. end;
  860. { trash contents of local variables or parameters (function result) }
  861. procedure trash_variable(p : tnamedindexitem;arg:pointer);
  862. var
  863. trashintval: aint;
  864. list: TAsmList absolute arg;
  865. begin
  866. if (tsym(p).typ=localvarsym) or
  867. ((tsym(p).typ=paravarsym) and
  868. (vo_is_funcret in tparavarsym(p).varoptions)) then
  869. begin
  870. trashintval := trashintvalues[localvartrashing];
  871. case tabstractnormalvarsym(p).localloc.loc of
  872. LOC_CREGISTER :
  873. {$ifopt q+}
  874. {$define overflowon}
  875. {$q-}
  876. {$endif}
  877. cg.a_load_const_reg(list,reg_cgsize(tabstractnormalvarsym(p).localloc.register),
  878. trashintval and (aint(1) shl (tcgsize2size[reg_cgsize(tabstractnormalvarsym(p).localloc.register)] * 8) - 1),
  879. tabstractnormalvarsym(p).localloc.register);
  880. {$ifdef overflowon}
  881. {$undef overflowon}
  882. {$q+}
  883. {$endif}
  884. LOC_REFERENCE :
  885. begin
  886. trash_reference(list,tabstractnormalvarsym(p).localloc.reference,
  887. tlocalvarsym(p).getsize);
  888. end;
  889. LOC_CMMREGISTER :
  890. ;
  891. LOC_CFPUREGISTER :
  892. ;
  893. else
  894. internalerror(200410124);
  895. end;
  896. end;
  897. end;
  898. { initializes the regvars from staticsymtable with 0 }
  899. procedure initialize_regvars(p : tnamedindexitem;arg:pointer);
  900. begin
  901. if (tsym(p).typ=globalvarsym) then
  902. begin
  903. case tglobalvarsym(p).localloc.loc of
  904. LOC_CREGISTER :
  905. cg.a_load_const_reg(TAsmList(arg),reg_cgsize(tglobalvarsym(p).localloc.register),0,
  906. tglobalvarsym(p).localloc.register);
  907. LOC_REFERENCE : ;
  908. LOC_CMMREGISTER :
  909. { clear the whole register }
  910. cg.a_opmm_reg_reg(TAsmList(arg),OP_XOR,reg_cgsize(tglobalvarsym(p).localloc.register),
  911. tglobalvarsym(p).localloc.register,
  912. tglobalvarsym(p).localloc.register,
  913. nil);
  914. LOC_CFPUREGISTER :
  915. ;
  916. else
  917. internalerror(200410124);
  918. end;
  919. end;
  920. end;
  921. { generates the code for initialisation of local data }
  922. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  923. var
  924. OldAsmList : TAsmList;
  925. hp : tnode;
  926. begin
  927. if (tsym(p).typ in [globalvarsym,localvarsym]) and
  928. (tabstractvarsym(p).refs>0) and
  929. not(vo_is_external in tabstractvarsym(p).varoptions) and
  930. not(is_class(tabstractvarsym(p).vartype.def)) and
  931. tabstractvarsym(p).vartype.def.needs_inittable then
  932. begin
  933. OldAsmList:=current_asmdata.CurrAsmList;
  934. current_asmdata.CurrAsmList:=TAsmList(arg);
  935. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  936. firstpass(hp);
  937. secondpass(hp);
  938. hp.free;
  939. current_asmdata.CurrAsmList:=OldAsmList;
  940. end;
  941. end;
  942. procedure finalize_sym(asmlist:TAsmList;sym:tsym);
  943. var
  944. hp : tnode;
  945. OldAsmList : TAsmList;
  946. begin
  947. include(current_procinfo.flags,pi_needs_implicit_finally);
  948. OldAsmList:=current_asmdata.CurrAsmList;
  949. current_asmdata.CurrAsmList:=asmlist;
  950. hp:=finalize_data_node(cloadnode.create(sym,sym.owner));
  951. firstpass(hp);
  952. secondpass(hp);
  953. hp.free;
  954. current_asmdata.CurrAsmList:=OldAsmList;
  955. end;
  956. { generates the code for finalisation of local variables }
  957. procedure finalize_local_vars(p : tnamedindexitem;arg:pointer);
  958. begin
  959. if (tsym(p).typ=localvarsym) and
  960. (tlocalvarsym(p).refs>0) and
  961. not(vo_is_external in tlocalvarsym(p).varoptions) and
  962. not(vo_is_funcret in tlocalvarsym(p).varoptions) and
  963. not(is_class(tlocalvarsym(p).vartype.def)) and
  964. tlocalvarsym(p).vartype.def.needs_inittable then
  965. finalize_sym(TAsmList(arg),tsym(p));
  966. end;
  967. { generates the code for finalisation of local typedconsts }
  968. procedure finalize_local_typedconst(p : tnamedindexitem;arg:pointer);
  969. var
  970. i : longint;
  971. pd : tprocdef;
  972. begin
  973. case tsym(p).typ of
  974. typedconstsym :
  975. begin
  976. if ttypedconstsym(p).is_writable and
  977. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  978. finalize_sym(TAsmList(arg),tsym(p));
  979. end;
  980. procsym :
  981. begin
  982. for i:=1 to tprocsym(p).procdef_count do
  983. begin
  984. pd:=tprocsym(p).procdef[i];
  985. if assigned(pd.localst) and
  986. (pd.procsym=tprocsym(p)) and
  987. (pd.localst.symtabletype<>staticsymtable) then
  988. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  989. end;
  990. end;
  991. end;
  992. end;
  993. { generates the code for finalization of static symtable and
  994. all local (static) typedconsts }
  995. procedure finalize_static_data(p : tnamedindexitem;arg:pointer);
  996. var
  997. i : longint;
  998. pd : tprocdef;
  999. begin
  1000. case tsym(p).typ of
  1001. globalvarsym :
  1002. begin
  1003. if (tglobalvarsym(p).refs>0) and
  1004. not(vo_is_funcret in tglobalvarsym(p).varoptions) and
  1005. not(vo_is_external in tglobalvarsym(p).varoptions) and
  1006. not(is_class(tglobalvarsym(p).vartype.def)) and
  1007. tglobalvarsym(p).vartype.def.needs_inittable then
  1008. finalize_sym(TAsmList(arg),tsym(p));
  1009. end;
  1010. typedconstsym :
  1011. begin
  1012. if ttypedconstsym(p).is_writable and
  1013. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  1014. finalize_sym(TAsmList(arg),tsym(p));
  1015. end;
  1016. procsym :
  1017. begin
  1018. for i:=1 to tprocsym(p).procdef_count do
  1019. begin
  1020. pd:=tprocsym(p).procdef[i];
  1021. if assigned(pd.localst) and
  1022. (pd.procsym=tprocsym(p)) and
  1023. (pd.localst.symtabletype<>staticsymtable) then
  1024. pd.localst.foreach_static(@finalize_local_typedconst,arg);
  1025. end;
  1026. end;
  1027. end;
  1028. end;
  1029. { generates the code for incrementing the reference count of parameters and
  1030. initialize out parameters }
  1031. procedure init_paras(p : tnamedindexitem;arg:pointer);
  1032. var
  1033. href : treference;
  1034. tmpreg : tregister;
  1035. list : TAsmList;
  1036. needs_inittable: boolean;
  1037. begin
  1038. list:=TAsmList(arg);
  1039. if (tsym(p).typ=paravarsym) then
  1040. begin
  1041. needs_inittable :=
  1042. not is_class_or_interface(tparavarsym(p).vartype.def) and
  1043. tparavarsym(p).vartype.def.needs_inittable;
  1044. case tparavarsym(p).varspez of
  1045. vs_value :
  1046. if needs_inittable then
  1047. begin
  1048. location_get_data_ref(list,tparavarsym(p).localloc,href,is_open_array(tparavarsym(p).vartype.def));
  1049. cg.g_incrrefcount(list,tparavarsym(p).vartype.def,href);
  1050. end;
  1051. vs_out :
  1052. begin
  1053. if (needs_inittable) or
  1054. (localvartrashing <> -1) then
  1055. begin
  1056. tmpreg:=cg.getaddressregister(list);
  1057. cg.a_load_loc_reg(list,OS_ADDR,tparavarsym(p).localloc,tmpreg);
  1058. reference_reset_base(href,tmpreg,0);
  1059. if (localvartrashing <> -1) and
  1060. { needs separate implementation to trash open arrays }
  1061. { since their size is only known at run time }
  1062. not is_special_array(tparavarsym(p).vartype.def) then
  1063. trash_reference(list,href,tparavarsym(p).vartype.def.size);
  1064. if needs_inittable then
  1065. cg.g_initialize(list,tparavarsym(p).vartype.def,href);
  1066. end;
  1067. end;
  1068. else if (localvartrashing <> -1) and
  1069. ([vo_is_funcret,vo_is_hidden_para] * tparavarsym(p).varoptions = [vo_is_funcret,vo_is_hidden_para]) then
  1070. begin
  1071. tmpreg:=cg.getaddressregister(list);
  1072. cg.a_load_loc_reg(list,OS_ADDR,tparavarsym(p).localloc,tmpreg);
  1073. reference_reset_base(href,tmpreg,0);
  1074. trash_reference(list,href,tparavarsym(p).vartype.def.size);
  1075. end
  1076. end;
  1077. end;
  1078. end;
  1079. { generates the code for decrementing the reference count of parameters }
  1080. procedure final_paras(p : tnamedindexitem;arg:pointer);
  1081. var
  1082. list : TAsmList;
  1083. href : treference;
  1084. begin
  1085. if not(tsym(p).typ=paravarsym) then
  1086. exit;
  1087. list:=TAsmList(arg);
  1088. if not is_class_or_interface(tparavarsym(p).vartype.def) and
  1089. tparavarsym(p).vartype.def.needs_inittable then
  1090. begin
  1091. if (tparavarsym(p).varspez=vs_value) then
  1092. begin
  1093. include(current_procinfo.flags,pi_needs_implicit_finally);
  1094. location_get_data_ref(list,tparavarsym(p).localloc,href,is_open_array(tparavarsym(p).vartype.def));
  1095. cg.g_decrrefcount(list,tparavarsym(p).vartype.def,href);
  1096. end;
  1097. end
  1098. else
  1099. if (tparavarsym(p).varspez=vs_value) and
  1100. (is_open_array(tparavarsym(p).vartype.def) or
  1101. is_array_of_const(tparavarsym(p).vartype.def)) then
  1102. begin
  1103. { cdecl functions don't have a high pointer so it is not possible to generate
  1104. a local copy }
  1105. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1106. cg.g_releasevaluepara_openarray(list,tparavarsym(p).localloc);
  1107. end;
  1108. end;
  1109. { Initialize temp ansi/widestrings,interfaces }
  1110. procedure inittempvariables(list:TAsmList);
  1111. var
  1112. hp : ptemprecord;
  1113. href : treference;
  1114. begin
  1115. hp:=tg.templist;
  1116. while assigned(hp) do
  1117. begin
  1118. if assigned(hp^.def) and
  1119. hp^.def.needs_inittable then
  1120. begin
  1121. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1122. cg.g_initialize(list,hp^.def,href);
  1123. end;
  1124. hp:=hp^.next;
  1125. end;
  1126. end;
  1127. procedure finalizetempvariables(list:TAsmList);
  1128. var
  1129. hp : ptemprecord;
  1130. href : treference;
  1131. begin
  1132. hp:=tg.templist;
  1133. while assigned(hp) do
  1134. begin
  1135. if assigned(hp^.def) and
  1136. hp^.def.needs_inittable then
  1137. begin
  1138. include(current_procinfo.flags,pi_needs_implicit_finally);
  1139. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1140. cg.g_finalize(list,hp^.def,href);
  1141. end;
  1142. hp:=hp^.next;
  1143. end;
  1144. end;
  1145. procedure gen_load_return_value(list:TAsmList);
  1146. var
  1147. {$ifndef cpu64bit}
  1148. href : treference;
  1149. {$endif cpu64bit}
  1150. ressym : tabstractnormalvarsym;
  1151. resloc,
  1152. restmploc : tlocation;
  1153. hreg : tregister;
  1154. funcretloc : tlocation;
  1155. begin
  1156. { Is the loading needed? }
  1157. if (current_procinfo.procdef.funcretloc[calleeside].loc=LOC_VOID) or
  1158. (
  1159. (po_assembler in current_procinfo.procdef.procoptions) and
  1160. (not(assigned(current_procinfo.procdef.funcretsym)) or
  1161. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs=0))
  1162. ) then
  1163. exit;
  1164. funcretloc:=current_procinfo.procdef.funcretloc[calleeside];
  1165. { constructors return self }
  1166. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1167. ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.search('self'))
  1168. else
  1169. ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
  1170. if (ressym.refs>0) then
  1171. begin
  1172. {$ifdef OLDREGVARS}
  1173. case ressym.localloc.loc of
  1174. LOC_CFPUREGISTER,
  1175. LOC_FPUREGISTER:
  1176. begin
  1177. location_reset(restmploc,LOC_CFPUREGISTER,funcretloc^.size);
  1178. restmploc.register:=ressym.localloc.register;
  1179. end;
  1180. LOC_CREGISTER,
  1181. LOC_REGISTER:
  1182. begin
  1183. location_reset(restmploc,LOC_CREGISTER,funcretloc^.size);
  1184. restmploc.register:=ressym.localloc.register;
  1185. end;
  1186. LOC_MMREGISTER:
  1187. begin
  1188. location_reset(restmploc,LOC_CMMREGISTER,funcretloc^.size);
  1189. restmploc.register:=ressym.localloc.register;
  1190. end;
  1191. LOC_REFERENCE:
  1192. begin
  1193. location_reset(restmploc,LOC_REFERENCE,funcretloc^.size);
  1194. restmploc.reference:=ressym.localloc.reference;
  1195. end;
  1196. else
  1197. internalerror(200309184);
  1198. end;
  1199. {$else}
  1200. restmploc:=ressym.localloc;
  1201. {$endif}
  1202. { Here, we return the function result. In most architectures, the value is
  1203. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1204. function returns in a register and the caller receives it in an other one }
  1205. case funcretloc.loc of
  1206. LOC_REGISTER:
  1207. begin
  1208. {$ifndef cpu64bit}
  1209. if current_procinfo.procdef.funcretloc[calleeside].size in [OS_64,OS_S64] then
  1210. begin
  1211. resloc:=current_procinfo.procdef.funcretloc[calleeside];
  1212. if resloc.loc<>LOC_REGISTER then
  1213. internalerror(200409141);
  1214. { Load low and high register separate to generate better register
  1215. allocation info }
  1216. if getsupreg(resloc.register64.reglo)<first_int_imreg then
  1217. begin
  1218. cg.getcpuregister(list,resloc.register64.reglo);
  1219. end;
  1220. case restmploc.loc of
  1221. LOC_REFERENCE :
  1222. begin
  1223. href:=restmploc.reference;
  1224. if target_info.endian=ENDIAN_BIG then
  1225. inc(href.offset,4);
  1226. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.register64.reglo);
  1227. end;
  1228. LOC_CREGISTER :
  1229. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.register64.reglo,resloc.register64.reglo);
  1230. else
  1231. internalerror(200409203);
  1232. end;
  1233. if getsupreg(resloc.register64.reghi)<first_int_imreg then
  1234. begin
  1235. cg.getcpuregister(list,resloc.register64.reghi);
  1236. end;
  1237. case restmploc.loc of
  1238. LOC_REFERENCE :
  1239. begin
  1240. href:=restmploc.reference;
  1241. if target_info.endian=ENDIAN_LITTLE then
  1242. inc(href.offset,4);
  1243. cg.a_load_ref_reg(list,OS_32,OS_32,href,resloc.register64.reghi);
  1244. end;
  1245. LOC_CREGISTER :
  1246. cg.a_load_reg_reg(list,OS_32,OS_32,restmploc.register64.reghi,resloc.register64.reghi);
  1247. else
  1248. internalerror(200409204);
  1249. end;
  1250. end
  1251. else
  1252. {$endif cpu64bit}
  1253. begin
  1254. hreg:=cg.makeregsize(list,funcretloc.register,funcretloc.size);
  1255. if getsupreg(funcretloc.register)<first_int_imreg then
  1256. begin
  1257. cg.getcpuregister(list,funcretloc.register);
  1258. end;
  1259. { it could be that a structure is passed in memory but the function is expected to
  1260. return a pointer to this memory }
  1261. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1262. cg.a_load_loc_reg(list,OS_ADDR,restmploc,hreg)
  1263. else
  1264. cg.a_load_loc_reg(list,restmploc.size,restmploc,hreg);
  1265. end;
  1266. end;
  1267. LOC_FPUREGISTER:
  1268. begin
  1269. if getsupreg(funcretloc.register)<first_fpu_imreg then
  1270. begin
  1271. cg.getcpuregister(list,funcretloc.register);
  1272. end;
  1273. { we can't do direct moves between fpu and mm registers }
  1274. if restmploc.loc in [LOC_MMREGISTER,LOC_CMMREGISTER] then
  1275. location_force_fpureg(list,restmploc,false);
  1276. cg.a_loadfpu_loc_reg(list,restmploc,funcretloc.register);
  1277. end;
  1278. LOC_MMREGISTER:
  1279. begin
  1280. if getsupreg(funcretloc.register)<first_mm_imreg then
  1281. begin
  1282. cg.getcpuregister(list,funcretloc.register);
  1283. end;
  1284. cg.a_loadmm_loc_reg(list,restmploc.size,restmploc,funcretloc.register,mms_movescalar);
  1285. end;
  1286. LOC_INVALID,
  1287. LOC_REFERENCE:
  1288. ;
  1289. else
  1290. internalerror(200405025);
  1291. end;
  1292. end
  1293. {$ifdef x86}
  1294. else
  1295. begin
  1296. { the caller will pop a value off the cpu stack }
  1297. if (funcretloc.loc = LOC_FPUREGISTER) then
  1298. list.concat(taicpu.op_none(A_FLDZ));
  1299. end;
  1300. {$endif x86}
  1301. end;
  1302. procedure gen_alloc_regvar(list:TAsmList;sym: tabstractnormalvarsym);
  1303. begin
  1304. case sym.localloc.loc of
  1305. LOC_CREGISTER:
  1306. begin
  1307. {$ifndef cpu64bit}
  1308. if sym.localloc.size in [OS_64,OS_S64] then
  1309. begin
  1310. sym.localloc.register64.reglo:=cg.getintregister(list,OS_32);
  1311. sym.localloc.register64.reghi:=cg.getintregister(list,OS_32);
  1312. end
  1313. else
  1314. {$endif cpu64bit}
  1315. sym.localloc.register:=cg.getintregister(list,sym.localloc.size);
  1316. end;
  1317. LOC_CFPUREGISTER:
  1318. begin
  1319. sym.localloc.register:=cg.getfpuregister(list,sym.localloc.size);
  1320. end;
  1321. LOC_CMMREGISTER:
  1322. begin
  1323. sym. localloc.register:=cg.getmmregister(list,sym.localloc.size);
  1324. end;
  1325. end;
  1326. if (pi_has_goto in current_procinfo.flags) then
  1327. begin
  1328. { Allocate register already, to prevent first allocation to be
  1329. inside a loop }
  1330. {$ifndef cpu64bit}
  1331. if sym.localloc.size in [OS_64,OS_S64] then
  1332. begin
  1333. cg.a_reg_sync(list,sym.localloc.register64.reglo);
  1334. cg.a_reg_sync(list,sym.localloc.register64.reghi);
  1335. end
  1336. else
  1337. {$endif cpu64bit}
  1338. cg.a_reg_sync(list,sym.localloc.register);
  1339. end;
  1340. end;
  1341. procedure gen_load_para_value(list:TAsmList);
  1342. procedure get_para(const paraloc:TCGParaLocation);
  1343. begin
  1344. case paraloc.loc of
  1345. LOC_REGISTER :
  1346. begin
  1347. if getsupreg(paraloc.register)<first_int_imreg then
  1348. cg.getcpuregister(list,paraloc.register);
  1349. end;
  1350. LOC_MMREGISTER :
  1351. begin
  1352. if getsupreg(paraloc.register)<first_mm_imreg then
  1353. cg.getcpuregister(list,paraloc.register);
  1354. end;
  1355. LOC_FPUREGISTER :
  1356. begin
  1357. if getsupreg(paraloc.register)<first_fpu_imreg then
  1358. cg.getcpuregister(list,paraloc.register);
  1359. end;
  1360. end;
  1361. end;
  1362. procedure unget_para(const paraloc:TCGParaLocation);
  1363. begin
  1364. case paraloc.loc of
  1365. LOC_REGISTER :
  1366. begin
  1367. if getsupreg(paraloc.register)<first_int_imreg then
  1368. cg.ungetcpuregister(list,paraloc.register);
  1369. end;
  1370. LOC_MMREGISTER :
  1371. begin
  1372. if getsupreg(paraloc.register)<first_mm_imreg then
  1373. cg.ungetcpuregister(list,paraloc.register);
  1374. end;
  1375. LOC_FPUREGISTER :
  1376. begin
  1377. if getsupreg(paraloc.register)<first_fpu_imreg then
  1378. cg.ungetcpuregister(list,paraloc.register);
  1379. end;
  1380. end;
  1381. end;
  1382. procedure gen_load_ref(const paraloc:TCGParaLocation;const ref:treference;sizeleft:aint);
  1383. var
  1384. href : treference;
  1385. begin
  1386. case paraloc.loc of
  1387. LOC_REGISTER :
  1388. begin
  1389. {$IFDEF POWERPC64}
  1390. if (paraloc.shiftval <> 0) then
  1391. cg.a_op_const_reg_reg(list, OP_SHL, OS_INT, paraloc.shiftval, paraloc.register, paraloc.register);
  1392. {$ENDIF POWERPC64}
  1393. cg.a_load_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  1394. end;
  1395. LOC_MMREGISTER :
  1396. cg.a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,mms_movescalar);
  1397. LOC_FPUREGISTER :
  1398. cg.a_loadfpu_reg_ref(list,paraloc.size,paraloc.register,ref);
  1399. LOC_REFERENCE :
  1400. begin
  1401. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1402. { use concatcopy, because it can also be a float which fails when
  1403. load_ref_ref is used. Don't copy data when the references are equal }
  1404. if not((href.base=ref.base) and (href.offset=ref.offset)) then
  1405. cg.g_concatcopy(list,href,ref,sizeleft);
  1406. end;
  1407. else
  1408. internalerror(2002081302);
  1409. end;
  1410. end;
  1411. procedure gen_load_reg(const paraloc:TCGParaLocation;reg:tregister);
  1412. var
  1413. href : treference;
  1414. begin
  1415. case paraloc.loc of
  1416. LOC_REGISTER :
  1417. cg.a_load_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg);
  1418. LOC_MMREGISTER :
  1419. cg.a_loadmm_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg,mms_movescalar);
  1420. LOC_FPUREGISTER :
  1421. cg.a_loadfpu_reg_reg(list,paraloc.size,paraloc.register,reg);
  1422. LOC_REFERENCE :
  1423. begin
  1424. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset);
  1425. case getregtype(reg) of
  1426. R_INTREGISTER :
  1427. cg.a_load_ref_reg(list,paraloc.size,paraloc.size,href,reg);
  1428. R_FPUREGISTER :
  1429. cg.a_loadfpu_ref_reg(list,paraloc.size,href,reg);
  1430. R_MMREGISTER :
  1431. cg.a_loadmm_ref_reg(list,paraloc.size,paraloc.size,href,reg,mms_movescalar);
  1432. else
  1433. internalerror(2004101012);
  1434. end;
  1435. end;
  1436. else
  1437. internalerror(2002081302);
  1438. end;
  1439. end;
  1440. var
  1441. i : longint;
  1442. currpara : tparavarsym;
  1443. paraloc : pcgparalocation;
  1444. href : treference;
  1445. sizeleft : aint;
  1446. {$ifdef sparc}
  1447. tempref : treference;
  1448. {$endif sparc}
  1449. begin
  1450. if (po_assembler in current_procinfo.procdef.procoptions) then
  1451. exit;
  1452. { Allocate registers used by parameters }
  1453. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1454. begin
  1455. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1456. paraloc:=currpara.paraloc[calleeside].location;
  1457. while assigned(paraloc) do
  1458. begin
  1459. if paraloc^.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER] then
  1460. get_para(paraloc^);
  1461. paraloc:=paraloc^.next;
  1462. end;
  1463. end;
  1464. { Copy parameters to local references/registers }
  1465. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1466. begin
  1467. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1468. paraloc:=currpara.paraloc[calleeside].location;
  1469. { skip e.g. empty records }
  1470. if not assigned(paraloc) then
  1471. internalerror(200408203);
  1472. if (paraloc^.loc = LOC_VOID) then
  1473. continue;
  1474. case currpara.localloc.loc of
  1475. LOC_REFERENCE :
  1476. begin
  1477. { If the parameter location is reused we don't need to copy
  1478. anything }
  1479. if not paramanager.param_use_paraloc(currpara.paraloc[calleeside]) then
  1480. begin
  1481. href:=currpara.localloc.reference;
  1482. sizeleft:=currpara.paraloc[calleeside].intsize;
  1483. while assigned(paraloc) do
  1484. begin
  1485. unget_para(paraloc^);
  1486. if (paraloc^.size=OS_NO) then
  1487. begin
  1488. { Can only be a reference that contains the rest
  1489. of the parameter }
  1490. if (paraloc^.loc<>LOC_REFERENCE) or
  1491. assigned(paraloc^.next) then
  1492. internalerror(2005013010);
  1493. gen_load_ref(paraloc^,href,sizeleft);
  1494. inc(href.offset,sizeleft);
  1495. sizeleft:=0;
  1496. end
  1497. else
  1498. begin
  1499. gen_load_ref(paraloc^,href,tcgsize2size[paraloc^.size]);
  1500. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1501. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1502. end;
  1503. paraloc:=paraloc^.next;
  1504. end;
  1505. end;
  1506. end;
  1507. LOC_CREGISTER :
  1508. begin
  1509. {$ifndef cpu64bit}
  1510. if (currpara.paraloc[calleeside].size in [OS_64,OS_S64]) and
  1511. is_64bit(currpara.vartype.def) then
  1512. begin
  1513. case paraloc^.loc of
  1514. LOC_REGISTER:
  1515. begin
  1516. if not assigned(paraloc^.next) then
  1517. internalerror(200410104);
  1518. if (target_info.endian=ENDIAN_BIG) then
  1519. begin
  1520. { paraloc^ -> high
  1521. paraloc^.next -> low }
  1522. unget_para(paraloc^);
  1523. gen_alloc_regvar(list,currpara);
  1524. gen_load_reg(paraloc^,currpara.localloc.register64.reghi);
  1525. unget_para(paraloc^.next^);
  1526. gen_load_reg(paraloc^.next^,currpara.localloc.register64.reglo);
  1527. end
  1528. else
  1529. begin
  1530. { paraloc^ -> low
  1531. paraloc^.next -> high }
  1532. unget_para(paraloc^);
  1533. gen_alloc_regvar(list,currpara);
  1534. gen_load_reg(paraloc^,currpara.localloc.register64.reglo);
  1535. unget_para(paraloc^.next^);
  1536. gen_load_reg(paraloc^.next^,currpara.localloc.register64.reghi);
  1537. end;
  1538. end;
  1539. LOC_REFERENCE:
  1540. begin
  1541. gen_alloc_regvar(list,currpara);
  1542. reference_reset_base(href,paraloc^.reference.index,paraloc^.reference.offset);
  1543. cg64.a_load64_ref_reg(list,href,currpara.localloc.register64);
  1544. unget_para(paraloc^);
  1545. end;
  1546. else
  1547. internalerror(2005101501);
  1548. end
  1549. end
  1550. else
  1551. {$endif cpu64bit}
  1552. begin
  1553. if assigned(paraloc^.next) then
  1554. internalerror(200410105);
  1555. unget_para(paraloc^);
  1556. gen_alloc_regvar(list,currpara);
  1557. gen_load_reg(paraloc^,currpara.localloc.register);
  1558. end;
  1559. end;
  1560. LOC_CFPUREGISTER :
  1561. begin
  1562. {$ifdef sparc}
  1563. { Sparc passes floats in int registers, when loading to fpu register
  1564. we need a temp }
  1565. sizeleft := TCGSize2Size[currpara.localloc.size];
  1566. tg.GetTemp(list,sizeleft,tt_normal,tempref);
  1567. href:=tempref;
  1568. while assigned(paraloc) do
  1569. begin
  1570. unget_para(paraloc^);
  1571. gen_load_ref(paraloc^,href,sizeleft);
  1572. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1573. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1574. paraloc:=paraloc^.next;
  1575. end;
  1576. gen_alloc_regvar(list,currpara);
  1577. cg.a_loadfpu_ref_reg(list,currpara.localloc.size,tempref,currpara.localloc.register);
  1578. tg.UnGetTemp(list,tempref);
  1579. {$else sparc}
  1580. unget_para(paraloc^);
  1581. gen_alloc_regvar(list,currpara);
  1582. gen_load_reg(paraloc^,currpara.localloc.register);
  1583. if assigned(paraloc^.next) then
  1584. internalerror(200410109);
  1585. {$endif sparc}
  1586. end;
  1587. LOC_CMMREGISTER :
  1588. begin
  1589. unget_para(paraloc^);
  1590. gen_alloc_regvar(list,currpara);
  1591. gen_load_reg(paraloc^,currpara.localloc.register);
  1592. { data could come in two memory locations, for now
  1593. we simply ignore the sanity check (FK)
  1594. if assigned(paraloc^.next) then
  1595. internalerror(200410108);
  1596. }
  1597. end;
  1598. end;
  1599. end;
  1600. { generate copies of call by value parameters, must be done before
  1601. the initialization and body is parsed because the refcounts are
  1602. incremented using the local copies }
  1603. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1604. {$ifdef powerpc}
  1605. { unget the register that contains the stack pointer before the procedure entry, }
  1606. { which is used to access the parameters in their original callee-side location }
  1607. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1608. cg.a_reg_dealloc(list,NR_R12);
  1609. {$endif powerpc}
  1610. {$ifdef powerpc64}
  1611. { unget the register that contains the stack pointer before the procedure entry, }
  1612. { which is used to access the parameters in their original callee-side location }
  1613. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1614. cg.a_reg_dealloc(list, NR_OLD_STACK_POINTER_REG);
  1615. {$endif powerpc64}
  1616. end;
  1617. procedure gen_initialize_code(list:TAsmList);
  1618. begin
  1619. { initialize local data like ansistrings }
  1620. case current_procinfo.procdef.proctypeoption of
  1621. potype_unitinit:
  1622. begin
  1623. { this is also used for initialization of variables in a
  1624. program which does not have a globalsymtable }
  1625. if assigned(current_module.globalsymtable) then
  1626. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1627. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1628. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_regvars,list);
  1629. end;
  1630. { units have seperate code for initilization and finalization }
  1631. potype_unitfinalize: ;
  1632. { program init/final is generated in separate procedure }
  1633. potype_proginit:
  1634. begin
  1635. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_regvars,list);
  1636. end;
  1637. else
  1638. begin
  1639. if (localvartrashing <> -1) and
  1640. not(po_assembler in current_procinfo.procdef.procoptions) then
  1641. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}trash_variable,list);
  1642. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1643. end;
  1644. end;
  1645. { initialisizes temp. ansi/wide string data }
  1646. inittempvariables(list);
  1647. { initialize ansi/widesstring para's }
  1648. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1649. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1650. {$ifdef OLDREGVARS}
  1651. load_regvars(list,nil);
  1652. {$endif OLDREGVARS}
  1653. end;
  1654. procedure gen_finalize_code(list:TAsmList);
  1655. begin
  1656. {$ifdef OLDREGVARS}
  1657. cleanup_regvars(list);
  1658. {$endif OLDREGVARS}
  1659. { finalize temporary data }
  1660. finalizetempvariables(list);
  1661. { finalize local data like ansistrings}
  1662. case current_procinfo.procdef.proctypeoption of
  1663. potype_unitfinalize:
  1664. begin
  1665. { this is also used for initialization of variables in a
  1666. program which does not have a globalsymtable }
  1667. if assigned(current_module.globalsymtable) then
  1668. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1669. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_static_data,list);
  1670. end;
  1671. { units/progs have separate code for initialization and finalization }
  1672. potype_unitinit: ;
  1673. { program init/final is generated in separate procedure }
  1674. potype_proginit: ;
  1675. else
  1676. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_local_vars,list);
  1677. end;
  1678. { finalize paras data }
  1679. if assigned(current_procinfo.procdef.parast) and
  1680. not(po_assembler in current_procinfo.procdef.procoptions) then
  1681. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1682. end;
  1683. procedure gen_entry_code(list:TAsmList);
  1684. var
  1685. paraloc1,
  1686. paraloc2 : tcgpara;
  1687. begin
  1688. paraloc1.init;
  1689. paraloc2.init;
  1690. { the actual profile code can clobber some registers,
  1691. therefore if the context must be saved, do it before
  1692. the actual call to the profile code
  1693. }
  1694. if (cs_profile in aktmoduleswitches) and
  1695. not(po_assembler in current_procinfo.procdef.procoptions) then
  1696. begin
  1697. { non-win32 can call mcout even in main }
  1698. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) or
  1699. not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1700. begin
  1701. cg.g_profilecode(list);
  1702. end;
  1703. end;
  1704. { call startup helpers from main program }
  1705. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1706. begin
  1707. { initialize units }
  1708. cg.allocallcpuregisters(list);
  1709. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1710. cg.deallocallcpuregisters(list);
  1711. end;
  1712. list.concat(Tai_force_line.Create);
  1713. {$ifdef OLDREGVARS}
  1714. load_regvars(list,nil);
  1715. {$endif OLDREGVARS}
  1716. paraloc1.done;
  1717. paraloc2.done;
  1718. end;
  1719. procedure gen_exit_code(list:TAsmList);
  1720. begin
  1721. { call __EXIT for main program }
  1722. if (not DLLsource) and
  1723. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1724. cg.a_call_name(list,'FPC_DO_EXIT');
  1725. end;
  1726. {****************************************************************************
  1727. Entry/Exit
  1728. ****************************************************************************}
  1729. procedure alloc_proc_symbol(pd: tprocdef);
  1730. var
  1731. item: tstringlistitem;
  1732. begin
  1733. item := tstringlistitem(pd.aliasnames.first);
  1734. while assigned(item) do
  1735. begin
  1736. current_asmdata.DefineAsmSymbol(item.str,AB_GLOBAL,AT_FUNCTION);
  1737. item := tstringlistitem(item.next);
  1738. end;
  1739. end;
  1740. procedure gen_proc_symbol(list:TAsmList);
  1741. var
  1742. hs : string;
  1743. begin
  1744. repeat
  1745. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1746. if hs='' then
  1747. break;
  1748. if (cs_profile in aktmoduleswitches) or
  1749. (po_global in current_procinfo.procdef.procoptions) then
  1750. list.concat(Tai_symbol.createname_global(hs,AT_FUNCTION,0))
  1751. else
  1752. list.concat(Tai_symbol.createname(hs,AT_FUNCTION,0));
  1753. if tf_use_function_relative_addresses in target_info.flags then
  1754. list.concat(Tai_function_name.create(hs));
  1755. until false;
  1756. current_procinfo.procdef.procstarttai:=tai(list.last);
  1757. end;
  1758. procedure gen_proc_symbol_end(list:TAsmList);
  1759. begin
  1760. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1761. current_procinfo.procdef.procendtai:=tai(list.last);
  1762. { finalisation marker for Mac OS X }
  1763. if (target_info.system in [system_powerpc_darwin,system_i386_darwin]) and
  1764. (current_module.islibrary) and
  1765. (((current_module.flags and uf_finalize)<>0) or
  1766. (current_procinfo.procdef.proctypeoption = potype_proginit)) then
  1767. begin
  1768. if (current_procinfo.procdef.proctypeoption = potype_proginit) then
  1769. list.concat(tai_directive.create(asd_mod_init_func,''))
  1770. else
  1771. list.concat(tai_directive.create(asd_mod_term_func,''));
  1772. list.concat(tai_align.create(4));
  1773. list.concat(Tai_const.Createname(current_procinfo.procdef.mangledname,0));
  1774. end;
  1775. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1776. begin
  1777. if (target_info.system in [system_powerpc_darwin,system_i386_darwin,system_powerpc_macos]) and
  1778. not(current_module.islibrary) then
  1779. begin
  1780. list.concat(tai_section.create(sec_code,'',4));
  1781. list.concat(tai_symbol.createname_global(
  1782. target_info.cprefix+mainaliasname,AT_FUNCTION,0));
  1783. { keep argc, argv and envp properly on the stack }
  1784. cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
  1785. end;
  1786. end;
  1787. end;
  1788. procedure gen_proc_entry_code(list:TAsmList);
  1789. var
  1790. hitemp,
  1791. lotemp : longint;
  1792. begin
  1793. { generate call frame marker for dwarf call frame info }
  1794. current_asmdata.asmcfi.start_frame(list);
  1795. { All temps are know, write offsets used for information }
  1796. if (cs_asm_source in aktglobalswitches) then
  1797. begin
  1798. if tg.direction>0 then
  1799. begin
  1800. lotemp:=current_procinfo.tempstart;
  1801. hitemp:=tg.lasttemp;
  1802. end
  1803. else
  1804. begin
  1805. lotemp:=tg.lasttemp;
  1806. hitemp:=current_procinfo.tempstart;
  1807. end;
  1808. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1809. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1810. end;
  1811. { generate target specific proc entry code }
  1812. cg.g_proc_entry(list,current_procinfo.calc_stackframe_size,(po_nostackframe in current_procinfo.procdef.procoptions));
  1813. end;
  1814. procedure gen_proc_exit_code(list:TAsmList);
  1815. var
  1816. parasize : longint;
  1817. begin
  1818. { c style clearstack does not need to remove parameters from the stack, only the
  1819. return value when it was pushed by arguments }
  1820. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1821. begin
  1822. parasize:=0;
  1823. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1824. inc(parasize,sizeof(aint));
  1825. end
  1826. else
  1827. parasize:=current_procinfo.para_stack_size;
  1828. { generate target specific proc exit code }
  1829. cg.g_proc_exit(list,parasize,(po_nostackframe in current_procinfo.procdef.procoptions));
  1830. { release return registers, needed for optimizer }
  1831. if not is_void(current_procinfo.procdef.rettype.def) then
  1832. location_free(list,current_procinfo.procdef.funcretloc[calleeside]);
  1833. { end of frame marker for call frame info }
  1834. current_asmdata.asmcfi.end_frame(list);
  1835. end;
  1836. procedure gen_stack_check_size_para(list:TAsmList);
  1837. var
  1838. paraloc1 : tcgpara;
  1839. begin
  1840. paraloc1.init;
  1841. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1842. paramanager.allocparaloc(list,paraloc1);
  1843. cg.a_param_const(list,OS_INT,current_procinfo.calc_stackframe_size,paraloc1);
  1844. paramanager.freeparaloc(list,paraloc1);
  1845. paraloc1.done;
  1846. end;
  1847. procedure gen_stack_check_call(list:TAsmList);
  1848. var
  1849. paraloc1 : tcgpara;
  1850. begin
  1851. paraloc1.init;
  1852. { Also alloc the register needed for the parameter }
  1853. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1854. paramanager.allocparaloc(list,paraloc1);
  1855. paramanager.freeparaloc(list,paraloc1);
  1856. { Call the helper }
  1857. cg.allocallcpuregisters(list);
  1858. cg.a_call_name(list,'FPC_STACKCHECK');
  1859. cg.deallocallcpuregisters(list);
  1860. paraloc1.done;
  1861. end;
  1862. procedure gen_save_used_regs(list:TAsmList);
  1863. begin
  1864. { Pure assembler routines need to save the registers themselves }
  1865. if (po_assembler in current_procinfo.procdef.procoptions) then
  1866. exit;
  1867. { oldfpccall expects all registers to be destroyed }
  1868. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1869. cg.g_save_standard_registers(list);
  1870. end;
  1871. procedure gen_restore_used_regs(list:TAsmList);
  1872. begin
  1873. { Pure assembler routines need to save the registers themselves }
  1874. if (po_assembler in current_procinfo.procdef.procoptions) then
  1875. exit;
  1876. { oldfpccall expects all registers to be destroyed }
  1877. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1878. cg.g_restore_standard_registers(list);
  1879. end;
  1880. procedure gen_got_load(list : TAsmList);
  1881. begin
  1882. { if loading got is necessary for more cpus, it can be moved
  1883. to the cg }
  1884. {$ifdef i386}
  1885. { allocate PIC register }
  1886. if (cs_create_pic in aktmoduleswitches) and
  1887. (tf_pic_uses_got in target_info.flags) and
  1888. (pi_needs_got in current_procinfo.flags) then
  1889. begin
  1890. current_module.requires_ebx_pic_helper:=true;
  1891. cg.a_call_name_static(list,'fpc_geteipasebx');
  1892. list.concat(taicpu.op_sym_ofs_reg(A_ADD,S_L,current_asmdata.RefAsmSymbol('_GLOBAL_OFFSET_TABLE_'),0,NR_PIC_OFFSET_REG));
  1893. list.concat(tai_regalloc.alloc(NR_PIC_OFFSET_REG,nil));
  1894. { ecx could be used in leave procedures }
  1895. current_procinfo.got:=NR_EBX;
  1896. end;
  1897. {$endif i386}
  1898. end;
  1899. {****************************************************************************
  1900. External handling
  1901. ****************************************************************************}
  1902. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  1903. var
  1904. ref : treference;
  1905. sym : tasmsymbol;
  1906. begin
  1907. { add the procedure to the al_procedures }
  1908. maybe_new_object_file(list);
  1909. new_section(list,sec_code,lower(pd.mangledname),aktalignment.procalign);
  1910. list.concat(Tai_align.create(aktalignment.procalign));
  1911. if (po_global in pd.procoptions) then
  1912. list.concat(Tai_symbol.createname_global(pd.mangledname,AT_FUNCTION,0))
  1913. else
  1914. list.concat(Tai_symbol.createname(pd.mangledname,AT_FUNCTION,0));
  1915. {$ifdef x86}
  1916. { fix this for other CPUs as well }
  1917. sym:=current_asmdata.RefAsmSymbol(externalname);
  1918. reference_reset_symbol(ref,sym,0);
  1919. { create pic'ed? }
  1920. if cs_create_pic in aktmoduleswitches then
  1921. begin
  1922. { it could be that we're called from a procedure not having the
  1923. got loaded
  1924. }
  1925. gen_got_load(list);
  1926. ref.refaddr:=addr_pic;
  1927. end
  1928. else
  1929. ref.refaddr:=addr_full;
  1930. list.concat(taicpu.op_ref(A_JMP,S_NO,ref));
  1931. {$else x86}
  1932. cg.a_jmp_name(list,externalname);
  1933. {$endif x86}
  1934. end;
  1935. {****************************************************************************
  1936. Const Data
  1937. ****************************************************************************}
  1938. procedure insertbssdata(sym : tglobalvarsym);
  1939. var
  1940. l : aint;
  1941. varalign : shortint;
  1942. storefilepos : tfileposinfo;
  1943. list : TAsmList;
  1944. sectype : TAsmSectiontype;
  1945. begin
  1946. storefilepos:=aktfilepos;
  1947. aktfilepos:=sym.fileinfo;
  1948. l:=sym.getsize;
  1949. if tf_section_threadvars in target_info.flags then
  1950. begin
  1951. if (vo_is_thread_var in sym.varoptions) then
  1952. begin
  1953. list:=current_asmdata.asmlists[al_threadvars];
  1954. sectype:=sec_threadvar;
  1955. end
  1956. else
  1957. begin
  1958. list:=current_asmdata.asmlists[al_globals];
  1959. sectype:=sec_bss;
  1960. end;
  1961. end
  1962. else
  1963. begin
  1964. if (vo_is_thread_var in sym.varoptions) then
  1965. inc(l,sizeof(aint));
  1966. list:=current_asmdata.asmlists[al_globals];
  1967. sectype:=sec_bss;
  1968. end;
  1969. varalign:=var_align(size_2_align(l));
  1970. maybe_new_object_file(list);
  1971. new_section(list,sectype,lower(sym.mangledname),varalign);
  1972. if (sym.owner.symtabletype=globalsymtable) or
  1973. maybe_smartlink_symbol or
  1974. DLLSource or
  1975. (assigned(current_procinfo) and
  1976. (po_inline in current_procinfo.procdef.procoptions)) or
  1977. (vo_is_exported in sym.varoptions) or
  1978. (vo_is_C_var in sym.varoptions) then
  1979. list.concat(Tai_datablock.create_global(sym.mangledname,l))
  1980. else
  1981. list.concat(Tai_datablock.create(sym.mangledname,l));
  1982. aktfilepos:=storefilepos;
  1983. end;
  1984. procedure init_regvar_loc(sym:tabstractnormalvarsym;cgsize:tcgsize);
  1985. begin
  1986. with sym do
  1987. begin
  1988. localloc.size:=cgsize;
  1989. case varregable of
  1990. vr_intreg,
  1991. vr_addr :
  1992. begin
  1993. localloc.loc:=LOC_CREGISTER;
  1994. end;
  1995. vr_fpureg :
  1996. begin
  1997. localloc.loc:=LOC_CFPUREGISTER;
  1998. end;
  1999. vr_mmreg :
  2000. begin
  2001. localloc.loc:=LOC_CMMREGISTER;
  2002. end;
  2003. else
  2004. internalerror(2004101010);
  2005. end;
  2006. end;
  2007. end;
  2008. procedure gen_alloc_symtable(list:TAsmList;st:tsymtable);
  2009. var
  2010. sym : tsym;
  2011. isaddr : boolean;
  2012. cgsize : tcgsize;
  2013. begin
  2014. sym:=tsym(st.symindex.first);
  2015. while assigned(sym) do
  2016. begin
  2017. if (sym.typ in [globalvarsym,localvarsym,paravarsym]) then
  2018. begin
  2019. with tabstractnormalvarsym(sym) do
  2020. begin
  2021. { Parameters passed to assembler procedures need to be kept
  2022. in the original location }
  2023. if (sym.typ=paravarsym) and
  2024. (po_assembler in current_procinfo.procdef.procoptions) then
  2025. begin
  2026. tparavarsym(sym).paraloc[calleeside].get_location(localloc);
  2027. end
  2028. else
  2029. begin
  2030. isaddr:=(st.symtabletype=parasymtable) and
  2031. paramanager.push_addr_param(varspez,vartype.def,current_procinfo.procdef.proccalloption);
  2032. if isaddr then
  2033. cgsize:=OS_ADDR
  2034. else
  2035. cgsize:=def_cgsize(vartype.def);
  2036. {$ifndef OLDREGVARS}
  2037. { When there is assembler code we can't use regvars }
  2038. if is_regvar(isaddr) then
  2039. begin
  2040. init_regvar_loc(tabstractnormalvarsym(sym),cgsize);
  2041. if (st.symtabletype <> parasymtable) then
  2042. gen_alloc_regvar(list,tabstractnormalvarsym(sym));
  2043. end
  2044. else
  2045. {$endif NOT OLDREGVARS}
  2046. begin
  2047. localloc.loc:=LOC_REFERENCE;
  2048. localloc.size:=cgsize;
  2049. case st.symtabletype of
  2050. parasymtable :
  2051. begin
  2052. { Reuse the parameter location for values to are at a single location on the stack }
  2053. if paramanager.param_use_paraloc(tparavarsym(sym).paraloc[calleeside]) then
  2054. begin
  2055. reference_reset_base(localloc.reference,tparavarsym(sym).paraloc[calleeside].location^.reference.index,
  2056. tparavarsym(sym).paraloc[calleeside].location^.reference.offset);
  2057. end
  2058. else
  2059. begin
  2060. if isaddr then
  2061. tg.GetLocal(list,sizeof(aint),voidpointertype.def,localloc.reference)
  2062. else
  2063. tg.GetLocal(list,getsize,tparavarsym(sym).paraloc[calleeside].alignment,vartype.def,localloc.reference);
  2064. end;
  2065. end;
  2066. localsymtable,
  2067. stt_exceptsymtable :
  2068. begin
  2069. tg.GetLocal(list,getsize,vartype.def,localloc.reference);
  2070. end;
  2071. staticsymtable :
  2072. begin
  2073. { PIC, DLL and Threadvar need extra code and are handled in ncgld }
  2074. if not(vo_is_dll_var in varoptions) and ((tf_section_threadvars in target_info.flags) or
  2075. not(vo_is_thread_var in varoptions)) then
  2076. reference_reset_symbol(localloc.reference,current_asmdata.RefAsmSymbol(mangledname),0);
  2077. end;
  2078. else
  2079. internalerror(200410103);
  2080. end;
  2081. end;
  2082. end;
  2083. if cs_asm_source in aktglobalswitches then
  2084. begin
  2085. case localloc.loc of
  2086. LOC_REFERENCE :
  2087. begin
  2088. if not assigned(localloc.reference.symbol) then
  2089. list.concat(Tai_comment.Create(strpnew('Var '+realname+' located at '+
  2090. std_regname(localloc.reference.base)+tostr_with_plus(localloc.reference.offset))));
  2091. end;
  2092. end;
  2093. end;
  2094. end;
  2095. end;
  2096. sym:=tsym(sym.indexnext);
  2097. end;
  2098. end;
  2099. procedure add_regvars(var rv: tusedregvars; const location: tlocation);
  2100. begin
  2101. case location.loc of
  2102. LOC_CREGISTER:
  2103. {$ifndef cpu64bit}
  2104. if location.size in [OS_64,OS_S64] then
  2105. begin
  2106. rv.intregvars.addnodup(getsupreg(location.register64.reglo));
  2107. rv.intregvars.addnodup(getsupreg(location.register64.reghi));
  2108. end
  2109. else
  2110. {$endif cpu64bit}
  2111. rv.intregvars.addnodup(getsupreg(location.register));
  2112. LOC_CFPUREGISTER:
  2113. rv.fpuregvars.addnodup(getsupreg(location.register));
  2114. LOC_CMMREGISTER:
  2115. rv.mmregvars.addnodup(getsupreg(location.register));
  2116. end;
  2117. end;
  2118. function do_get_used_regvars(var n: tnode; arg: pointer): foreachnoderesult;
  2119. var
  2120. rv: pusedregvars absolute arg;
  2121. begin
  2122. case (n.nodetype) of
  2123. temprefn:
  2124. { We only have to synchronise a tempnode before a loop if it is }
  2125. { not created inside the loop, and only synchronise after the }
  2126. { loop if it's not destroyed inside the loop. If it's created }
  2127. { before the loop and not yet destroyed, then before the loop }
  2128. { is secondpassed tempinfo^.valid will be true, and we get the }
  2129. { correct registers. If it's not destroyed inside the loop, }
  2130. { then after the loop has been secondpassed tempinfo^.valid }
  2131. { be true and we also get the right registers. In other cases, }
  2132. { tempinfo^.valid will be false and so we do not add }
  2133. { unnecessary registers. This way, we don't have to look at }
  2134. { tempcreate and tempdestroy nodes to get this info (JM) }
  2135. if (ttemprefnode(n).tempinfo^.valid) then
  2136. add_regvars(rv^,ttemprefnode(n).tempinfo^.location);
  2137. loadn:
  2138. if (tloadnode(n).symtableentry.typ in [globalvarsym,localvarsym,paravarsym]) then
  2139. add_regvars(rv^,tabstractnormalvarsym(tloadnode(n).symtableentry).localloc);
  2140. vecn:
  2141. { range checks sometimes need the high parameter }
  2142. if (cs_check_range in aktlocalswitches) and
  2143. (is_open_array(tvecnode(n).left.resulttype.def) or
  2144. is_array_of_const(tvecnode(n).left.resulttype.def)) and
  2145. not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2146. add_regvars(rv^,tabstractnormalvarsym(get_high_value_sym(tparavarsym(tloadnode(tvecnode(n).left).symtableentry))).localloc)
  2147. end;
  2148. result := fen_true;
  2149. end;
  2150. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  2151. begin
  2152. foreachnodestatic(n,@do_get_used_regvars,@rv);
  2153. end;
  2154. (*
  2155. See comments at declaration of pusedregvarscommon
  2156. function do_get_used_regvars_common(var n: tnode; arg: pointer): foreachnoderesult;
  2157. var
  2158. rv: pusedregvarscommon absolute arg;
  2159. begin
  2160. if (n.nodetype = loadn) and
  2161. (tloadnode(n).symtableentry.typ in [globalvarsym,localvarsym,paravarsym]) then
  2162. with tabstractnormalvarsym(tloadnode(n).symtableentry).localloc do
  2163. case loc of
  2164. LOC_CREGISTER:
  2165. { if not yet encountered in this node tree }
  2166. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2167. { but nevertheless already encountered somewhere }
  2168. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2169. { then it's a regvar used in two or more node trees }
  2170. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2171. LOC_CFPUREGISTER:
  2172. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2173. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2174. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2175. LOC_CMMREGISTER:
  2176. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  2177. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  2178. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  2179. end;
  2180. result := fen_true;
  2181. end;
  2182. procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  2183. begin
  2184. rv.myregvars.intregvars.clear;
  2185. rv.myregvars.fpuregvars.clear;
  2186. rv.myregvars.mmregvars.clear;
  2187. foreachnodestatic(n,@do_get_used_regvars_common,@rv);
  2188. end;
  2189. *)
  2190. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  2191. var
  2192. count: longint;
  2193. begin
  2194. for count := 1 to rv.intregvars.length do
  2195. cg.a_reg_sync(list,newreg(R_INTREGISTER,rv.intregvars.readidx(count-1),R_SUBWHOLE));
  2196. for count := 1 to rv.fpuregvars.length do
  2197. cg.a_reg_sync(list,newreg(R_FPUREGISTER,rv.fpuregvars.readidx(count-1),R_SUBWHOLE));
  2198. for count := 1 to rv.mmregvars.length do
  2199. cg.a_reg_sync(list,newreg(R_MMREGISTER,rv.mmregvars.readidx(count-1),R_SUBWHOLE));
  2200. end;
  2201. {*****************************************************************************
  2202. SSA support
  2203. *****************************************************************************}
  2204. type
  2205. preplaceregrec = ^treplaceregrec;
  2206. treplaceregrec = record
  2207. old, new: tregister;
  2208. {$ifndef cpu64bit}
  2209. oldhi, newhi: tregister;
  2210. {$endif cpu64bit}
  2211. ressym: tsym;
  2212. end;
  2213. function doreplace(var n: tnode; para: pointer): foreachnoderesult;
  2214. var
  2215. rr: preplaceregrec absolute para;
  2216. begin
  2217. result := fen_false;
  2218. case n.nodetype of
  2219. loadn:
  2220. begin
  2221. if (tabstractvarsym(tloadnode(n).symtableentry).varoptions * [vo_is_dll_var, vo_is_thread_var] = []) and
  2222. not assigned(tloadnode(n).left) and
  2223. (((tloadnode(n).symtableentry <> rr^.ressym) and
  2224. not(vo_is_funcret in tabstractvarsym(tloadnode(n).symtableentry).varoptions)) or
  2225. not(fc_exit in flowcontrol)) and
  2226. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  2227. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register = rr^.old) then
  2228. begin
  2229. {$ifndef cpu64bit}
  2230. { it's possible a 64 bit location was shifted and/xor typecasted }
  2231. { in a 32 bit value, so only 1 register was left in the location }
  2232. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.size in [OS_64,OS_S64]) then
  2233. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi = rr^.oldhi) then
  2234. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi := rr^.newhi
  2235. else
  2236. exit;
  2237. {$endif cpu64bit}
  2238. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register := rr^.new;
  2239. result := fen_norecurse_true;
  2240. end;
  2241. end;
  2242. temprefn:
  2243. begin
  2244. if (ttemprefnode(n).tempinfo^.valid) and
  2245. (ttemprefnode(n).tempinfo^.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  2246. (ttemprefnode(n).tempinfo^.location.register = rr^.old) then
  2247. begin
  2248. {$ifndef cpu64bit}
  2249. { it's possible a 64 bit location was shifted and/xor typecasted }
  2250. { in a 32 bit value, so only 1 register was left in the location }
  2251. if (ttemprefnode(n).tempinfo^.location.size in [OS_64,OS_S64]) then
  2252. if (ttemprefnode(n).tempinfo^.location.register64.reghi = rr^.oldhi) then
  2253. ttemprefnode(n).tempinfo^.location.register64.reghi := rr^.newhi
  2254. else
  2255. exit;
  2256. {$endif cpu64bit}
  2257. ttemprefnode(n).tempinfo^.location.register := rr^.new;
  2258. result := fen_norecurse_true;
  2259. end;
  2260. end;
  2261. end;
  2262. end;
  2263. procedure maybechangeloadnodereg(var n: tnode);
  2264. var
  2265. rr: treplaceregrec;
  2266. begin
  2267. if not (n.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) or
  2268. ([fc_inflowcontrol,fc_gotolabel] * flowcontrol <> []) then
  2269. exit;
  2270. rr.old := n.location.register;
  2271. rr.ressym := nil;
  2272. {$ifndef cpu64bit}
  2273. rr.oldhi := NR_NO;
  2274. {$endif cpu64bit}
  2275. case n.location.loc of
  2276. LOC_CREGISTER:
  2277. begin
  2278. {$ifndef cpu64bit}
  2279. if (n.location.size in [OS_64,OS_S64]) then
  2280. begin
  2281. rr.oldhi := n.location.register64.reghi;
  2282. rr.new := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  2283. rr.newhi := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  2284. end
  2285. else
  2286. {$endif cpu64bit}
  2287. rr.new := cg.getintregister(current_asmdata.CurrAsmList,n.location.size);
  2288. end;
  2289. LOC_CFPUREGISTER:
  2290. rr.new := cg.getfpuregister(current_asmdata.CurrAsmList,n.location.size);
  2291. {$ifdef SUPPORT_MMX}
  2292. LOC_CMMXREGISTER:
  2293. rr.new := tcgx86(cg).getmmxregister(current_asmdata.CurrAsmList);
  2294. {$endif SUPPORT_MMX}
  2295. LOC_CMMREGISTER:
  2296. rr.new := cg.getmmregister(current_asmdata.CurrAsmList,n.location.size);
  2297. else
  2298. exit;
  2299. end;
  2300. if (current_procinfo.procdef.funcretloc[calleeside].loc<>LOC_VOID) and
  2301. assigned(current_procinfo.procdef.funcretsym) and
  2302. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs <> 0) then
  2303. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  2304. rr.ressym:=tsym(current_procinfo.procdef.parast.search('self'))
  2305. else
  2306. rr.ressym:=current_procinfo.procdef.funcretsym;
  2307. if not foreachnodestatic(n,@doreplace,@rr) then
  2308. exit;
  2309. { now that we've change the loadn/temp, also change the node result location }
  2310. {$ifndef cpu64bit}
  2311. if (n.location.size in [OS_64,OS_S64]) then
  2312. begin
  2313. n.location.register64.reglo := rr.new;
  2314. n.location.register64.reghi := rr.newhi;
  2315. end
  2316. else
  2317. {$endif cpu64bit}
  2318. n.location.register := rr.new;
  2319. end;
  2320. procedure gen_free_symtable(list:TAsmList;st:tsymtable);
  2321. var
  2322. sym : tsym;
  2323. begin
  2324. sym:=tsym(st.symindex.first);
  2325. while assigned(sym) do
  2326. begin
  2327. if (sym.typ in [globalvarsym,localvarsym,paravarsym]) then
  2328. begin
  2329. with tabstractnormalvarsym(sym) do
  2330. begin
  2331. { Note: We need to keep the data available in memory
  2332. for the sub procedures that can access local data
  2333. in the parent procedures }
  2334. case localloc.loc of
  2335. LOC_CREGISTER :
  2336. {$ifndef cpu64bit}
  2337. if (pi_has_goto in current_procinfo.flags) then
  2338. if def_cgsize(vartype.def) in [OS_64,OS_S64] then
  2339. begin
  2340. cg.a_reg_sync(list,localloc.register64.reglo);
  2341. cg.a_reg_sync(list,localloc.register64.reghi);
  2342. end
  2343. else
  2344. {$endif cpu64bit}
  2345. cg.a_reg_sync(list,localloc.register);
  2346. LOC_CFPUREGISTER,
  2347. LOC_CMMREGISTER:
  2348. if (pi_has_goto in current_procinfo.flags) then
  2349. cg.a_reg_sync(list,localloc.register);
  2350. LOC_REFERENCE :
  2351. begin
  2352. case st.symtabletype of
  2353. localsymtable,
  2354. parasymtable,
  2355. stt_exceptsymtable :
  2356. tg.Ungetlocal(list,localloc.reference);
  2357. end;
  2358. end;
  2359. end;
  2360. end;
  2361. end;
  2362. sym:=tsym(sym.indexnext);
  2363. end;
  2364. end;
  2365. { persistent rtti generation }
  2366. procedure generate_rtti(p:Ttypesym);
  2367. var
  2368. rsym : trttisym;
  2369. def : tstoreddef;
  2370. begin
  2371. { rtti can only be generated for classes that are always typesyms }
  2372. def:=tstoreddef(ttypesym(p).restype.def);
  2373. { there is an error, skip rtti info }
  2374. if (def.deftype=errordef) or (Errorcount>0) then
  2375. exit;
  2376. { only create rtti once for each definition }
  2377. if not(df_has_rttitable in def.defoptions) then
  2378. begin
  2379. { definition should be in the same symtable as the symbol }
  2380. if p.owner<>def.owner then
  2381. internalerror(200108262);
  2382. { create rttisym }
  2383. rsym:=trttisym.create(p.name,fullrtti);
  2384. p.owner.insert(rsym);
  2385. { register rttisym in definition }
  2386. include(def.defoptions,df_has_rttitable);
  2387. def.rttitablesym:=rsym;
  2388. { write rtti data }
  2389. def.write_child_rtti_data(fullrtti);
  2390. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  2391. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,rsym.get_label.name,const_align(sizeof(aint)));
  2392. current_asmdata.asmlists[al_rtti].concat(Tai_symbol.Create_global(rsym.get_label,0));
  2393. def.write_rtti_data(fullrtti);
  2394. current_asmdata.asmlists[al_rtti].concat(Tai_symbol_end.Create(rsym.get_label));
  2395. end;
  2396. end;
  2397. { persistent init table generation }
  2398. procedure generate_inittable(p:tsym);
  2399. var
  2400. rsym : trttisym;
  2401. def : tstoreddef;
  2402. begin
  2403. { anonymous types are also allowed for records that can be varsym }
  2404. case p.typ of
  2405. typesym :
  2406. def:=tstoreddef(ttypesym(p).restype.def);
  2407. globalvarsym,
  2408. localvarsym,
  2409. paravarsym :
  2410. def:=tstoreddef(tabstractvarsym(p).vartype.def);
  2411. else
  2412. internalerror(200108263);
  2413. end;
  2414. { only create inittable once for each definition }
  2415. if not(df_has_inittable in def.defoptions) then
  2416. begin
  2417. { definition should be in the same symtable as the symbol }
  2418. if p.owner<>def.owner then
  2419. internalerror(200108264);
  2420. { create rttisym }
  2421. rsym:=trttisym.create(p.name,initrtti);
  2422. p.owner.insert(rsym);
  2423. { register rttisym in definition }
  2424. include(def.defoptions,df_has_inittable);
  2425. def.inittablesym:=rsym;
  2426. { write inittable data }
  2427. def.write_child_rtti_data(initrtti);
  2428. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  2429. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,rsym.get_label.name,const_align(sizeof(aint)));
  2430. current_asmdata.asmlists[al_rtti].concat(Tai_symbol.Create_global(rsym.get_label,0));
  2431. def.write_rtti_data(initrtti);
  2432. current_asmdata.asmlists[al_rtti].concat(Tai_symbol_end.Create(rsym.get_label));
  2433. end;
  2434. end;
  2435. procedure gen_intf_wrapper(list:TAsmList;_class:tobjectdef);
  2436. var
  2437. i,j,
  2438. proccount : longint;
  2439. tmps : string;
  2440. begin
  2441. for i:=1 to _class.implementedinterfaces.count do
  2442. begin
  2443. { only if implemented by this class }
  2444. if _class.implementedinterfaces.implindex(i)=i then
  2445. begin
  2446. proccount:=_class.implementedinterfaces.implproccount(i);
  2447. for j:=1 to proccount do
  2448. begin
  2449. tmps:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+
  2450. _class.implementedinterfaces.interfaces(i).objname^+'_$_'+
  2451. tostr(j)+'_$_'+_class.implementedinterfaces.implprocs(i,j).mangledname);
  2452. { create wrapper code }
  2453. new_section(list,sec_code,lower(tmps),0);
  2454. cg.init_register_allocators;
  2455. cg.g_intf_wrapper(list,_class.implementedinterfaces.implprocs(i,j),tmps,_class.implementedinterfaces.ioffsets(i));
  2456. cg.done_register_allocators;
  2457. end;
  2458. end;
  2459. end;
  2460. end;
  2461. procedure gen_intf_wrappers(list:TAsmList;st:tsymtable);
  2462. var
  2463. def : tstoreddef;
  2464. begin
  2465. def:=tstoreddef(st.defindex.first);
  2466. while assigned(def) do
  2467. begin
  2468. if is_class(def) then
  2469. gen_intf_wrapper(list,tobjectdef(def));
  2470. def:=tstoreddef(def.indexnext);
  2471. end;
  2472. end;
  2473. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  2474. var
  2475. href : treference;
  2476. begin
  2477. if is_object(objdef) then
  2478. begin
  2479. case selfloc.loc of
  2480. LOC_CREFERENCE,
  2481. LOC_REFERENCE:
  2482. begin
  2483. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2484. cg.a_loadaddr_ref_reg(list,selfloc.reference,href.base);
  2485. end;
  2486. else
  2487. internalerror(200305056);
  2488. end;
  2489. end
  2490. else
  2491. begin
  2492. case selfloc.loc of
  2493. LOC_REGISTER:
  2494. begin
  2495. {$ifdef cpu_uses_separate_address_registers}
  2496. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  2497. begin
  2498. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2499. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,selfloc.register,href.base);
  2500. end
  2501. else
  2502. {$endif cpu_uses_separate_address_registers}
  2503. reference_reset_base(href,selfloc.register,objdef.vmt_offset);
  2504. end;
  2505. LOC_CREGISTER,
  2506. LOC_CREFERENCE,
  2507. LOC_REFERENCE:
  2508. begin
  2509. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset);
  2510. cg.a_load_loc_reg(list,OS_ADDR,selfloc,href.base);
  2511. end;
  2512. else
  2513. internalerror(200305057);
  2514. end;
  2515. end;
  2516. vmtreg:=cg.getaddressregister(list);
  2517. cg.g_maybe_testself(list,href.base);
  2518. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,vmtreg);
  2519. { test validity of VMT }
  2520. if not(is_interface(objdef)) and
  2521. not(is_cppclass(objdef)) then
  2522. cg.g_maybe_testvmt(list,vmtreg,objdef);
  2523. end;
  2524. function getprocalign : shortint;
  2525. begin
  2526. { gprof uses 16 byte granularity }
  2527. if (cs_profile in aktmoduleswitches) then
  2528. result:=16
  2529. else
  2530. result:=aktalignment.procalign;
  2531. end;
  2532. procedure gen_pic_helpers(list : TAsmList);
  2533. var
  2534. href : treference;
  2535. begin
  2536. { if other cpus require such helpers as well, it can be solved more cleaner }
  2537. {$ifdef i386}
  2538. if current_module.requires_ebx_pic_helper then
  2539. begin
  2540. new_section(list,sec_code,'fpc_geteipasebx',0);
  2541. list.concat(tai_symbol.Createname('fpc_geteipasebx',AT_FUNCTION,getprocalign));
  2542. reference_reset(href);
  2543. href.base:=NR_ESP;
  2544. list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,NR_EBX));
  2545. list.concat(taicpu.op_none(A_RET,S_NO));
  2546. end;
  2547. if current_module.requires_ecx_pic_helper then
  2548. begin
  2549. new_section(list,sec_code,'fpc_geteipasecx',0);
  2550. list.concat(tai_symbol.Createname('fpc_geteipasecx',AT_FUNCTION,getprocalign));
  2551. reference_reset(href);
  2552. href.base:=NR_ESP;
  2553. list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,NR_ECX));
  2554. list.concat(taicpu.op_none(A_RET,S_NO));
  2555. end;
  2556. {$endif i386}
  2557. end;
  2558. end.