ncgutil.pas 107 KB

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