ncgutil.pas 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  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 cpu64bitalu}
  27. ,cg64f32
  28. {$endif not cpu64bitalu}
  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_fpureg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  50. procedure location_force_mmreg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  51. procedure location_allocate_register(list:TAsmList;out l: tlocation;def: tdef;constant: boolean);
  52. { loads a cgpara into a tlocation; assumes that loc.loc is already
  53. initialised }
  54. procedure gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);
  55. { allocate registers for a tlocation; assumes that loc.loc is already
  56. set to LOC_CREGISTER/LOC_CFPUREGISTER/... }
  57. procedure gen_alloc_regloc(list:TAsmList;var loc: tlocation);
  58. procedure register_maybe_adjust_setbase(list: TAsmList; var l: tlocation; setbase: aint);
  59. function has_alias_name(pd:tprocdef;const s:string):boolean;
  60. procedure alloc_proc_symbol(pd: tprocdef);
  61. procedure gen_proc_symbol(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_load_para_value(list:TAsmList);
  69. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  70. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  71. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  72. { adds the regvars used in n and its children to rv.allregvars,
  73. those which were already in rv.allregvars to rv.commonregvars and
  74. uses rv.myregvars as scratch (so that two uses of the same regvar
  75. in a single tree to make it appear in commonregvars). Useful to
  76. find out which regvars are used in two different node trees
  77. (e.g. in the "else" and "then" path, or in various case blocks }
  78. // procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  79. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  80. { if the result of n is a LOC_C(..)REGISTER, try to find the corresponding
  81. loadn and change its location to a new register (= SSA). In case reload
  82. is true, transfer the old to the new register }
  83. procedure maybechangeloadnodereg(list: TAsmList; var n: tnode; reload: boolean);
  84. { Allocate the buffers for exception management and setjmp environment.
  85. Return a pointer to these buffers, send them to the utility routine
  86. so they are registered, and then call setjmp.
  87. Then compare the result of setjmp with 0, and if not equal
  88. to zero, then jump to exceptlabel.
  89. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  90. It is to note that this routine may be called *after* the stackframe of a
  91. routine has been called, therefore on machines where the stack cannot
  92. be modified, all temps should be allocated on the heap instead of the
  93. stack. }
  94. const
  95. EXCEPT_BUF_SIZE = 3*sizeof(pint);
  96. type
  97. texceptiontemps=record
  98. jmpbuf,
  99. envbuf,
  100. reasonbuf : treference;
  101. end;
  102. procedure get_exception_temps(list:TAsmList;var t:texceptiontemps);
  103. procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  104. procedure new_exception(list:TAsmList;const t:texceptiontemps;exceptlabel:tasmlabel);
  105. procedure free_exception(list:TAsmList;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  106. procedure gen_alloc_symtable(list:TAsmList;pd:tprocdef;st:TSymtable);
  107. procedure gen_free_symtable(list:TAsmList;st:TSymtable);
  108. procedure location_free(list: TAsmList; const location : TLocation);
  109. function getprocalign : shortint;
  110. procedure gen_fpc_dummy(list : TAsmList);
  111. implementation
  112. uses
  113. version,
  114. cutils,cclasses,
  115. globals,systems,verbose,export,
  116. ppu,defutil,
  117. procinfo,paramgr,fmodule,
  118. regvars,dbgbase,
  119. pass_1,pass_2,
  120. nbas,ncon,nld,nmem,nutils,ngenutil,
  121. tgobj,cgobj,cgcpu,hlcgobj,hlcgcpu
  122. {$ifdef powerpc}
  123. , cpupi
  124. {$endif}
  125. {$ifdef powerpc64}
  126. , cpupi
  127. {$endif}
  128. {$ifdef SUPPORT_MMX}
  129. , cgx86
  130. {$endif SUPPORT_MMX}
  131. ;
  132. {*****************************************************************************
  133. Misc Helpers
  134. *****************************************************************************}
  135. {$if first_mm_imreg = 0}
  136. {$WARN 4044 OFF} { Comparison might be always false ... }
  137. {$endif}
  138. procedure location_free(list: TAsmList; const location : TLocation);
  139. begin
  140. case location.loc of
  141. LOC_VOID:
  142. ;
  143. LOC_REGISTER,
  144. LOC_CREGISTER:
  145. begin
  146. {$ifdef cpu64bitalu}
  147. { x86-64 system v abi:
  148. structs with up to 16 bytes are returned in registers }
  149. if location.size in [OS_128,OS_S128] then
  150. begin
  151. if getsupreg(location.register)<first_int_imreg then
  152. cg.ungetcpuregister(list,location.register);
  153. if getsupreg(location.registerhi)<first_int_imreg then
  154. cg.ungetcpuregister(list,location.registerhi);
  155. end
  156. {$else cpu64bitalu}
  157. if location.size in [OS_64,OS_S64] then
  158. begin
  159. if getsupreg(location.register64.reglo)<first_int_imreg then
  160. cg.ungetcpuregister(list,location.register64.reglo);
  161. if getsupreg(location.register64.reghi)<first_int_imreg then
  162. cg.ungetcpuregister(list,location.register64.reghi);
  163. end
  164. {$endif cpu64bitalu}
  165. else
  166. if getsupreg(location.register)<first_int_imreg then
  167. cg.ungetcpuregister(list,location.register);
  168. end;
  169. LOC_FPUREGISTER,
  170. LOC_CFPUREGISTER:
  171. begin
  172. if getsupreg(location.register)<first_fpu_imreg then
  173. cg.ungetcpuregister(list,location.register);
  174. end;
  175. LOC_MMREGISTER,
  176. LOC_CMMREGISTER :
  177. begin
  178. if getsupreg(location.register)<first_mm_imreg then
  179. cg.ungetcpuregister(list,location.register);
  180. end;
  181. LOC_REFERENCE,
  182. LOC_CREFERENCE :
  183. begin
  184. if paramanager.use_fixed_stack then
  185. location_freetemp(list,location);
  186. end;
  187. else
  188. internalerror(2004110211);
  189. end;
  190. end;
  191. procedure firstcomplex(p : tbinarynode);
  192. var
  193. fcl, fcr: longint;
  194. ncl, ncr: longint;
  195. begin
  196. { always calculate boolean AND and OR from left to right }
  197. if (p.nodetype in [orn,andn]) and
  198. is_boolean(p.left.resultdef) then
  199. begin
  200. if nf_swapped in p.flags then
  201. internalerror(200709253);
  202. end
  203. else
  204. begin
  205. fcl:=node_resources_fpu(p.left);
  206. fcr:=node_resources_fpu(p.right);
  207. ncl:=node_complexity(p.left);
  208. ncr:=node_complexity(p.right);
  209. { We swap left and right if
  210. a) right needs more floating point registers than left, and
  211. left needs more than 0 floating point registers (if it
  212. doesn't need any, swapping won't change the floating
  213. point register pressure)
  214. b) both left and right need an equal amount of floating
  215. point registers or right needs no floating point registers,
  216. and in addition right has a higher complexity than left
  217. (+- needs more integer registers, but not necessarily)
  218. }
  219. if ((fcr>fcl) and
  220. (fcl>0)) or
  221. (((fcr=fcl) or
  222. (fcr=0)) and
  223. (ncr>ncl)) then
  224. p.swapleftright
  225. end;
  226. end;
  227. procedure maketojumpbool(list:TAsmList; p : tnode; loadregvars: tloadregvars);
  228. {
  229. produces jumps to true respectively false labels using boolean expressions
  230. depending on whether the loading of regvars is currently being
  231. synchronized manually (such as in an if-node) or automatically (most of
  232. the other cases where this procedure is called), loadregvars can be
  233. "lr_load_regvars" or "lr_dont_load_regvars"
  234. }
  235. var
  236. opsize : tcgsize;
  237. storepos : tfileposinfo;
  238. tmpreg : tregister;
  239. begin
  240. if nf_error in p.flags then
  241. exit;
  242. storepos:=current_filepos;
  243. current_filepos:=p.fileinfo;
  244. if is_boolean(p.resultdef) then
  245. begin
  246. {$ifdef OLDREGVARS}
  247. if loadregvars = lr_load_regvars then
  248. load_all_regvars(list);
  249. {$endif OLDREGVARS}
  250. if is_constboolnode(p) then
  251. begin
  252. if Tordconstnode(p).value.uvalue<>0 then
  253. cg.a_jmp_always(list,current_procinfo.CurrTrueLabel)
  254. else
  255. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel)
  256. end
  257. else
  258. begin
  259. opsize:=def_cgsize(p.resultdef);
  260. case p.location.loc of
  261. LOC_SUBSETREG,LOC_CSUBSETREG,
  262. LOC_SUBSETREF,LOC_CSUBSETREF:
  263. begin
  264. tmpreg := cg.getintregister(list,OS_INT);
  265. hlcg.a_load_loc_reg(list,p.resultdef,osuinttype,p.location,tmpreg);
  266. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,tmpreg,current_procinfo.CurrTrueLabel);
  267. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  268. end;
  269. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  270. begin
  271. {$ifdef cpu64bitalu}
  272. if opsize in [OS_128,OS_S128] then
  273. begin
  274. hlcg.location_force_reg(list,p.location,p.resultdef,cgsize_orddef(opsize),true);
  275. tmpreg:=cg.getintregister(list,OS_64);
  276. cg.a_op_reg_reg_reg(list,OP_OR,OS_64,p.location.register128.reglo,p.location.register128.reghi,tmpreg);
  277. location_reset(p.location,LOC_REGISTER,OS_64);
  278. p.location.register:=tmpreg;
  279. opsize:=OS_64;
  280. end;
  281. {$else cpu64bitalu}
  282. if opsize in [OS_64,OS_S64] then
  283. begin
  284. hlcg.location_force_reg(list,p.location,p.resultdef,cgsize_orddef(opsize),true);
  285. tmpreg:=cg.getintregister(list,OS_32);
  286. cg.a_op_reg_reg_reg(list,OP_OR,OS_32,p.location.register64.reglo,p.location.register64.reghi,tmpreg);
  287. location_reset(p.location,LOC_REGISTER,OS_32);
  288. p.location.register:=tmpreg;
  289. opsize:=OS_32;
  290. end;
  291. {$endif cpu64bitalu}
  292. cg.a_cmp_const_loc_label(list,opsize,OC_NE,0,p.location,current_procinfo.CurrTrueLabel);
  293. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  294. end;
  295. LOC_JUMP:
  296. ;
  297. {$ifdef cpuflags}
  298. LOC_FLAGS :
  299. begin
  300. cg.a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
  301. cg.a_reg_dealloc(list,NR_DEFAULTFLAGS);
  302. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  303. end;
  304. {$endif cpuflags}
  305. else
  306. begin
  307. printnode(output,p);
  308. internalerror(200308241);
  309. end;
  310. end;
  311. end;
  312. end
  313. else
  314. internalerror(200112305);
  315. current_filepos:=storepos;
  316. end;
  317. (*
  318. This code needs fixing. It is not safe to use rgint; on the m68000 it
  319. would be rgaddr.
  320. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  321. begin
  322. case t.loc of
  323. LOC_REGISTER:
  324. begin
  325. { can't be a regvar, since it would be LOC_CREGISTER then }
  326. exclude(regs,getsupreg(t.register));
  327. if t.register64.reghi<>NR_NO then
  328. exclude(regs,getsupreg(t.register64.reghi));
  329. end;
  330. LOC_CREFERENCE,LOC_REFERENCE:
  331. begin
  332. if not(cs_opt_regvar in current_settings.optimizerswitches) or
  333. (getsupreg(t.reference.base) in cg.rgint.usableregs) then
  334. exclude(regs,getsupreg(t.reference.base));
  335. if not(cs_opt_regvar in current_settings.optimizerswitches) or
  336. (getsupreg(t.reference.index) in cg.rgint.usableregs) then
  337. exclude(regs,getsupreg(t.reference.index));
  338. end;
  339. end;
  340. end;
  341. *)
  342. {*****************************************************************************
  343. EXCEPTION MANAGEMENT
  344. *****************************************************************************}
  345. procedure get_exception_temps(list:TAsmList;var t:texceptiontemps);
  346. begin
  347. get_jumpbuf_size;
  348. tg.GetTemp(list,EXCEPT_BUF_SIZE,sizeof(pint),tt_persistent,t.envbuf);
  349. tg.GetTemp(list,jmp_buf_size,jmp_buf_align,tt_persistent,t.jmpbuf);
  350. tg.GetTemp(list,sizeof(pint),sizeof(pint),tt_persistent,t.reasonbuf);
  351. end;
  352. procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  353. begin
  354. tg.Ungettemp(list,t.jmpbuf);
  355. tg.ungettemp(list,t.envbuf);
  356. tg.ungettemp(list,t.reasonbuf);
  357. end;
  358. procedure new_exception(list:TAsmList;const t:texceptiontemps;exceptlabel:tasmlabel);
  359. const
  360. {$ifdef cpu16bitaddr}
  361. pushexceptaddr_frametype_cgsize = OS_S16;
  362. setjmp_result_cgsize = OS_S16;
  363. {$else cpu16bitaddr}
  364. pushexceptaddr_frametype_cgsize = OS_S32;
  365. setjmp_result_cgsize = OS_S32;
  366. {$endif cpu16bitaddr}
  367. var
  368. paraloc1,paraloc2,paraloc3 : tcgpara;
  369. pd: tprocdef;
  370. begin
  371. pd:=search_system_proc('fpc_pushexceptaddr');
  372. paraloc1.init;
  373. paraloc2.init;
  374. paraloc3.init;
  375. paramanager.getintparaloc(pd,1,paraloc1);
  376. paramanager.getintparaloc(pd,2,paraloc2);
  377. paramanager.getintparaloc(pd,3,paraloc3);
  378. if pd.is_pushleftright then
  379. begin
  380. { push type of exceptionframe }
  381. cg.a_load_const_cgpara(list,pushexceptaddr_frametype_cgsize,1,paraloc1);
  382. cg.a_loadaddr_ref_cgpara(list,t.jmpbuf,paraloc2);
  383. cg.a_loadaddr_ref_cgpara(list,t.envbuf,paraloc3);
  384. end
  385. else
  386. begin
  387. cg.a_loadaddr_ref_cgpara(list,t.envbuf,paraloc3);
  388. cg.a_loadaddr_ref_cgpara(list,t.jmpbuf,paraloc2);
  389. { push type of exceptionframe }
  390. cg.a_load_const_cgpara(list,pushexceptaddr_frametype_cgsize,1,paraloc1);
  391. end;
  392. paramanager.freecgpara(list,paraloc3);
  393. paramanager.freecgpara(list,paraloc2);
  394. paramanager.freecgpara(list,paraloc1);
  395. cg.allocallcpuregisters(list);
  396. cg.a_call_name(list,'FPC_PUSHEXCEPTADDR',false);
  397. cg.deallocallcpuregisters(list);
  398. pd:=search_system_proc('fpc_setjmp');
  399. paramanager.getintparaloc(pd,1,paraloc1);
  400. cg.a_load_reg_cgpara(list,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  401. paramanager.freecgpara(list,paraloc1);
  402. cg.allocallcpuregisters(list);
  403. cg.a_call_name(list,'FPC_SETJMP',false);
  404. cg.deallocallcpuregisters(list);
  405. cg.alloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  406. cg.g_exception_reason_save(list, t.reasonbuf);
  407. cg.a_cmp_const_reg_label(list,setjmp_result_cgsize,OC_NE,0,cg.makeregsize(list,NR_FUNCTION_RESULT_REG,setjmp_result_cgsize),exceptlabel);
  408. cg.dealloccpuregisters(list,R_INTREGISTER,[RS_FUNCTION_RESULT_REG]);
  409. paraloc1.done;
  410. paraloc2.done;
  411. paraloc3.done;
  412. end;
  413. procedure free_exception(list:TAsmList;const t:texceptiontemps;a:aint;endexceptlabel:tasmlabel;onlyfree:boolean);
  414. begin
  415. cg.allocallcpuregisters(list);
  416. cg.a_call_name(list,'FPC_POPADDRSTACK',false);
  417. cg.deallocallcpuregisters(list);
  418. if not onlyfree then
  419. begin
  420. { g_exception_reason_load already allocates NR_FUNCTION_RESULT_REG }
  421. cg.g_exception_reason_load(list, t.reasonbuf);
  422. cg.a_cmp_const_reg_label(list,OS_INT,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
  423. cg.a_reg_dealloc(list,NR_FUNCTION_RESULT_REG);
  424. end;
  425. end;
  426. {*****************************************************************************
  427. TLocation
  428. *****************************************************************************}
  429. procedure location_force_fpureg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  430. var
  431. reg : tregister;
  432. href : treference;
  433. begin
  434. if (l.loc<>LOC_FPUREGISTER) and
  435. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  436. begin
  437. { if it's in an mm register, store to memory first }
  438. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  439. begin
  440. tg.GetTemp(list,tcgsize2size[l.size],tcgsize2size[l.size],tt_normal,href);
  441. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
  442. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  443. l.reference:=href;
  444. end;
  445. reg:=cg.getfpuregister(list,l.size);
  446. cg.a_loadfpu_loc_reg(list,l.size,l,reg);
  447. location_freetemp(list,l);
  448. location_reset(l,LOC_FPUREGISTER,l.size);
  449. l.register:=reg;
  450. end;
  451. end;
  452. procedure register_maybe_adjust_setbase(list: TAsmList; var l: tlocation; setbase: aint);
  453. var
  454. tmpreg: tregister;
  455. begin
  456. if (setbase<>0) then
  457. begin
  458. if not(l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  459. internalerror(2007091502);
  460. { subtract the setbase }
  461. case l.loc of
  462. LOC_CREGISTER:
  463. begin
  464. tmpreg := cg.getintregister(list,l.size);
  465. cg.a_op_const_reg_reg(list,OP_SUB,l.size,setbase,l.register,tmpreg);
  466. l.loc:=LOC_REGISTER;
  467. l.register:=tmpreg;
  468. end;
  469. LOC_REGISTER:
  470. begin
  471. cg.a_op_const_reg(list,OP_SUB,l.size,setbase,l.register);
  472. end;
  473. end;
  474. end;
  475. end;
  476. procedure location_force_mmreg(list:TAsmList;var l: tlocation;maybeconst:boolean);
  477. var
  478. reg : tregister;
  479. begin
  480. if (l.loc<>LOC_MMREGISTER) and
  481. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  482. begin
  483. reg:=cg.getmmregister(list,OS_VECTOR);
  484. cg.a_loadmm_loc_reg(list,OS_VECTOR,l,reg,nil);
  485. location_freetemp(list,l);
  486. location_reset(l,LOC_MMREGISTER,OS_VECTOR);
  487. l.register:=reg;
  488. end;
  489. end;
  490. procedure location_allocate_register(list: TAsmList;out l: tlocation;def: tdef;constant: boolean);
  491. begin
  492. l.size:=def_cgsize(def);
  493. if (def.typ=floatdef) and
  494. not(cs_fp_emulation in current_settings.moduleswitches) then
  495. begin
  496. if use_vectorfpu(def) then
  497. begin
  498. if constant then
  499. location_reset(l,LOC_CMMREGISTER,l.size)
  500. else
  501. location_reset(l,LOC_MMREGISTER,l.size);
  502. l.register:=cg.getmmregister(list,l.size);
  503. end
  504. else
  505. begin
  506. if constant then
  507. location_reset(l,LOC_CFPUREGISTER,l.size)
  508. else
  509. location_reset(l,LOC_FPUREGISTER,l.size);
  510. l.register:=cg.getfpuregister(list,l.size);
  511. end;
  512. end
  513. else
  514. begin
  515. if constant then
  516. location_reset(l,LOC_CREGISTER,l.size)
  517. else
  518. location_reset(l,LOC_REGISTER,l.size);
  519. {$ifdef cpu64bitalu}
  520. if l.size in [OS_128,OS_S128,OS_F128] then
  521. begin
  522. l.register128.reglo:=cg.getintregister(list,OS_64);
  523. l.register128.reghi:=cg.getintregister(list,OS_64);
  524. end
  525. else
  526. {$else cpu64bitalu}
  527. if l.size in [OS_64,OS_S64,OS_F64] then
  528. begin
  529. l.register64.reglo:=cg.getintregister(list,OS_32);
  530. l.register64.reghi:=cg.getintregister(list,OS_32);
  531. end
  532. else
  533. {$endif cpu64bitalu}
  534. { Note: for withs of records (and maybe objects, classes, etc.) an
  535. address register could be set here, but that is later
  536. changed to an intregister neverthless when in the
  537. tcgassignmentnode maybechangeloadnodereg is called for the
  538. temporary node; so the workaround for now is to fix the
  539. symptoms... }
  540. l.register:=cg.getintregister(list,l.size);
  541. end;
  542. end;
  543. {****************************************************************************
  544. Init/Finalize Code
  545. ****************************************************************************}
  546. procedure copyvalueparas(p:TObject;arg:pointer);
  547. var
  548. href : treference;
  549. hreg : tregister;
  550. list : TAsmList;
  551. hsym : tparavarsym;
  552. l : longint;
  553. localcopyloc : tlocation;
  554. sizedef : tdef;
  555. begin
  556. list:=TAsmList(arg);
  557. if (tsym(p).typ=paravarsym) and
  558. (tparavarsym(p).varspez=vs_value) and
  559. (paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption)) then
  560. begin
  561. { we have no idea about the alignment at the caller side }
  562. hlcg.location_get_data_ref(list,tparavarsym(p).vardef,tparavarsym(p).initialloc,href,true,1);
  563. if is_open_array(tparavarsym(p).vardef) or
  564. is_array_of_const(tparavarsym(p).vardef) then
  565. begin
  566. { cdecl functions don't have a high pointer so it is not possible to generate
  567. a local copy }
  568. if not(current_procinfo.procdef.proccalloption in cdecl_pocalls) then
  569. begin
  570. hsym:=tparavarsym(get_high_value_sym(tparavarsym(p)));
  571. if not assigned(hsym) then
  572. internalerror(200306061);
  573. hreg:=cg.getaddressregister(list);
  574. if not is_packed_array(tparavarsym(p).vardef) then
  575. hlcg.g_copyvaluepara_openarray(list,href,hsym.initialloc,tarraydef(tparavarsym(p).vardef),hreg)
  576. else
  577. internalerror(2006080401);
  578. // cg.g_copyvaluepara_packedopenarray(list,href,hsym.intialloc,tarraydef(tparavarsym(p).vardef).elepackedbitsize,hreg);
  579. sizedef:=getpointerdef(tparavarsym(p).vardef);
  580. hlcg.a_load_reg_loc(list,sizedef,sizedef,hreg,tparavarsym(p).initialloc);
  581. end;
  582. end
  583. else
  584. begin
  585. { Allocate space for the local copy }
  586. l:=tparavarsym(p).getsize;
  587. localcopyloc.loc:=LOC_REFERENCE;
  588. localcopyloc.size:=int_cgsize(l);
  589. tg.GetLocal(list,l,tparavarsym(p).vardef,localcopyloc.reference);
  590. { Copy data }
  591. if is_shortstring(tparavarsym(p).vardef) then
  592. begin
  593. { this code is only executed before the code for the body and the entry/exit code is generated
  594. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  595. }
  596. include(current_procinfo.flags,pi_do_call);
  597. hlcg.g_copyshortstring(list,href,localcopyloc.reference,tstringdef(tparavarsym(p).vardef));
  598. end
  599. else if tparavarsym(p).vardef.typ = variantdef then
  600. begin
  601. { this code is only executed before the code for the body and the entry/exit code is generated
  602. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  603. }
  604. include(current_procinfo.flags,pi_do_call);
  605. hlcg.g_copyvariant(list,href,localcopyloc.reference,tvariantdef(tparavarsym(p).vardef))
  606. end
  607. else
  608. begin
  609. { pass proper alignment info }
  610. localcopyloc.reference.alignment:=tparavarsym(p).vardef.alignment;
  611. cg.g_concatcopy(list,href,localcopyloc.reference,tparavarsym(p).vardef.size);
  612. end;
  613. { update localloc of varsym }
  614. tg.Ungetlocal(list,tparavarsym(p).localloc.reference);
  615. tparavarsym(p).localloc:=localcopyloc;
  616. tparavarsym(p).initialloc:=localcopyloc;
  617. end;
  618. end;
  619. end;
  620. { generates the code for incrementing the reference count of parameters and
  621. initialize out parameters }
  622. procedure init_paras(p:TObject;arg:pointer);
  623. var
  624. href : treference;
  625. hsym : tparavarsym;
  626. eldef : tdef;
  627. list : TAsmList;
  628. needs_inittable : boolean;
  629. begin
  630. list:=TAsmList(arg);
  631. if (tsym(p).typ=paravarsym) then
  632. begin
  633. needs_inittable:=is_managed_type(tparavarsym(p).vardef);
  634. if not needs_inittable then
  635. exit;
  636. case tparavarsym(p).varspez of
  637. vs_value :
  638. begin
  639. { variants are already handled by the call to fpc_variant_copy_overwrite if
  640. they are passed by reference }
  641. if not((tparavarsym(p).vardef.typ=variantdef) and
  642. paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption)) then
  643. begin
  644. hlcg.location_get_data_ref(list,tparavarsym(p).vardef,tparavarsym(p).initialloc,href,is_open_array(tparavarsym(p).vardef),sizeof(pint));
  645. if is_open_array(tparavarsym(p).vardef) then
  646. begin
  647. { open arrays do not contain correct element count in their rtti,
  648. the actual count must be passed separately. }
  649. hsym:=tparavarsym(get_high_value_sym(tparavarsym(p)));
  650. eldef:=tarraydef(tparavarsym(p).vardef).elementdef;
  651. if not assigned(hsym) then
  652. internalerror(201003031);
  653. hlcg.g_array_rtti_helper(list,eldef,href,hsym.initialloc,'fpc_addref_array');
  654. end
  655. else
  656. hlcg.g_incrrefcount(list,tparavarsym(p).vardef,href);
  657. end;
  658. end;
  659. vs_out :
  660. begin
  661. { we have no idea about the alignment at the callee side,
  662. and the user also cannot specify "unaligned" here, so
  663. assume worst case }
  664. hlcg.location_get_data_ref(list,tparavarsym(p).vardef,tparavarsym(p).initialloc,href,true,1);
  665. if is_open_array(tparavarsym(p).vardef) then
  666. begin
  667. hsym:=tparavarsym(get_high_value_sym(tparavarsym(p)));
  668. eldef:=tarraydef(tparavarsym(p).vardef).elementdef;
  669. if not assigned(hsym) then
  670. internalerror(201103033);
  671. hlcg.g_array_rtti_helper(list,eldef,href,hsym.initialloc,'fpc_initialize_array');
  672. end
  673. else
  674. hlcg.g_initialize(list,tparavarsym(p).vardef,href);
  675. end;
  676. end;
  677. end;
  678. end;
  679. procedure gen_alloc_regloc(list:TAsmList;var loc: tlocation);
  680. begin
  681. case loc.loc of
  682. LOC_CREGISTER:
  683. begin
  684. {$ifdef cpu64bitalu}
  685. if loc.size in [OS_128,OS_S128] then
  686. begin
  687. loc.register128.reglo:=cg.getintregister(list,OS_64);
  688. loc.register128.reghi:=cg.getintregister(list,OS_64);
  689. end
  690. else
  691. {$else cpu64bitalu}
  692. if loc.size in [OS_64,OS_S64] then
  693. begin
  694. loc.register64.reglo:=cg.getintregister(list,OS_32);
  695. loc.register64.reghi:=cg.getintregister(list,OS_32);
  696. end
  697. else
  698. {$endif cpu64bitalu}
  699. loc.register:=cg.getintregister(list,loc.size);
  700. end;
  701. LOC_CFPUREGISTER:
  702. begin
  703. loc.register:=cg.getfpuregister(list,loc.size);
  704. end;
  705. LOC_CMMREGISTER:
  706. begin
  707. loc.register:=cg.getmmregister(list,loc.size);
  708. end;
  709. end;
  710. end;
  711. procedure gen_alloc_regvar(list:TAsmList;sym: tabstractnormalvarsym; allocreg: boolean);
  712. begin
  713. if allocreg then
  714. gen_alloc_regloc(list,sym.initialloc);
  715. if (pi_has_label in current_procinfo.flags) then
  716. begin
  717. { Allocate register already, to prevent first allocation to be
  718. inside a loop }
  719. {$ifdef cpu64bitalu}
  720. if sym.initialloc.size in [OS_128,OS_S128] then
  721. begin
  722. cg.a_reg_sync(list,sym.initialloc.register128.reglo);
  723. cg.a_reg_sync(list,sym.initialloc.register128.reghi);
  724. end
  725. else
  726. {$else cpu64bitalu}
  727. if sym.initialloc.size in [OS_64,OS_S64] then
  728. begin
  729. cg.a_reg_sync(list,sym.initialloc.register64.reglo);
  730. cg.a_reg_sync(list,sym.initialloc.register64.reghi);
  731. end
  732. else
  733. {$endif cpu64bitalu}
  734. cg.a_reg_sync(list,sym.initialloc.register);
  735. end;
  736. sym.localloc:=sym.initialloc;
  737. end;
  738. procedure gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);
  739. procedure unget_para(const paraloc:TCGParaLocation);
  740. begin
  741. case paraloc.loc of
  742. LOC_REGISTER :
  743. begin
  744. if getsupreg(paraloc.register)<first_int_imreg then
  745. cg.ungetcpuregister(list,paraloc.register);
  746. end;
  747. LOC_MMREGISTER :
  748. begin
  749. if getsupreg(paraloc.register)<first_mm_imreg then
  750. cg.ungetcpuregister(list,paraloc.register);
  751. end;
  752. LOC_FPUREGISTER :
  753. begin
  754. if getsupreg(paraloc.register)<first_fpu_imreg then
  755. cg.ungetcpuregister(list,paraloc.register);
  756. end;
  757. end;
  758. end;
  759. var
  760. paraloc : pcgparalocation;
  761. href : treference;
  762. sizeleft : aint;
  763. {$if defined(sparc) or defined(arm) or defined(mips)}
  764. tempref : treference;
  765. {$endif defined(sparc) or defined(arm) or defined(mips)}
  766. {$ifdef mips}
  767. tmpreg : tregister;
  768. {$endif mips}
  769. {$ifndef cpu64bitalu}
  770. tempreg : tregister;
  771. reg64 : tregister64;
  772. {$endif not cpu64bitalu}
  773. begin
  774. paraloc:=para.location;
  775. if not assigned(paraloc) then
  776. internalerror(200408203);
  777. { skip e.g. empty records }
  778. if (paraloc^.loc = LOC_VOID) then
  779. exit;
  780. case destloc.loc of
  781. LOC_REFERENCE :
  782. begin
  783. { If the parameter location is reused we don't need to copy
  784. anything }
  785. if not reusepara then
  786. begin
  787. href:=destloc.reference;
  788. sizeleft:=para.intsize;
  789. while assigned(paraloc) do
  790. begin
  791. if (paraloc^.size=OS_NO) then
  792. begin
  793. { Can only be a reference that contains the rest
  794. of the parameter }
  795. if (paraloc^.loc<>LOC_REFERENCE) or
  796. assigned(paraloc^.next) then
  797. internalerror(2005013010);
  798. cg.a_load_cgparaloc_ref(list,paraloc^,href,sizeleft,destloc.reference.alignment);
  799. inc(href.offset,sizeleft);
  800. sizeleft:=0;
  801. end
  802. else
  803. begin
  804. cg.a_load_cgparaloc_ref(list,paraloc^,href,tcgsize2size[paraloc^.size],destloc.reference.alignment);
  805. inc(href.offset,TCGSize2Size[paraloc^.size]);
  806. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  807. end;
  808. unget_para(paraloc^);
  809. paraloc:=paraloc^.next;
  810. end;
  811. end;
  812. end;
  813. LOC_REGISTER,
  814. LOC_CREGISTER :
  815. begin
  816. {$ifdef cpu64bitalu}
  817. if (para.size in [OS_128,OS_S128,OS_F128]) and
  818. ({ in case of fpu emulation, or abi's that pass fpu values
  819. via integer registers }
  820. (vardef.typ=floatdef) or
  821. is_methodpointer(vardef) or
  822. is_record(vardef)) then
  823. begin
  824. case paraloc^.loc of
  825. LOC_REGISTER:
  826. begin
  827. if not assigned(paraloc^.next) then
  828. internalerror(200410104);
  829. if (target_info.endian=ENDIAN_BIG) then
  830. begin
  831. { paraloc^ -> high
  832. paraloc^.next -> low }
  833. unget_para(paraloc^);
  834. gen_alloc_regloc(list,destloc);
  835. { reg->reg, alignment is irrelevant }
  836. cg.a_load_cgparaloc_anyreg(list,OS_64,paraloc^,destloc.register128.reghi,8);
  837. unget_para(paraloc^.next^);
  838. cg.a_load_cgparaloc_anyreg(list,OS_64,paraloc^.next^,destloc.register128.reglo,8);
  839. end
  840. else
  841. begin
  842. { paraloc^ -> low
  843. paraloc^.next -> high }
  844. unget_para(paraloc^);
  845. gen_alloc_regloc(list,destloc);
  846. cg.a_load_cgparaloc_anyreg(list,OS_64,paraloc^,destloc.register128.reglo,8);
  847. unget_para(paraloc^.next^);
  848. cg.a_load_cgparaloc_anyreg(list,OS_64,paraloc^.next^,destloc.register128.reghi,8);
  849. end;
  850. end;
  851. LOC_REFERENCE:
  852. begin
  853. gen_alloc_regloc(list,destloc);
  854. reference_reset_base(href,paraloc^.reference.index,paraloc^.reference.offset,para.alignment);
  855. cg128.a_load128_ref_reg(list,href,destloc.register128);
  856. unget_para(paraloc^);
  857. end;
  858. else
  859. internalerror(2012090607);
  860. end
  861. end
  862. else
  863. {$else cpu64bitalu}
  864. if (para.size in [OS_64,OS_S64,OS_F64]) and
  865. (is_64bit(vardef) or
  866. { in case of fpu emulation, or abi's that pass fpu values
  867. via integer registers }
  868. (vardef.typ=floatdef) or
  869. is_methodpointer(vardef) or
  870. is_record(vardef)) then
  871. begin
  872. case paraloc^.loc of
  873. LOC_REGISTER:
  874. begin
  875. case para.locations_count of
  876. {$ifdef cpu16bitalu}
  877. { 4 paralocs? }
  878. 4:
  879. if (target_info.endian=ENDIAN_BIG) then
  880. begin
  881. { paraloc^ -> high
  882. paraloc^.next^.next -> low }
  883. unget_para(paraloc^);
  884. gen_alloc_regloc(list,destloc);
  885. { reg->reg, alignment is irrelevant }
  886. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^,GetNextReg(destloc.register64.reghi),2);
  887. unget_para(paraloc^.next^);
  888. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^.next^,destloc.register64.reghi,2);
  889. unget_para(paraloc^.next^.next^);
  890. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^.next^.next^,GetNextReg(destloc.register64.reglo),2);
  891. unget_para(paraloc^.next^.next^.next^);
  892. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^.next^.next^.next^,destloc.register64.reglo,2);
  893. end
  894. else
  895. begin
  896. { paraloc^ -> low
  897. paraloc^.next^.next -> high }
  898. unget_para(paraloc^);
  899. gen_alloc_regloc(list,destloc);
  900. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^,destloc.register64.reglo,2);
  901. unget_para(paraloc^.next^);
  902. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^.next^,GetNextReg(destloc.register64.reglo),2);
  903. unget_para(paraloc^.next^.next^);
  904. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^.next^.next^,destloc.register64.reghi,2);
  905. unget_para(paraloc^.next^.next^.next^);
  906. cg.a_load_cgparaloc_anyreg(list,OS_16,paraloc^.next^.next^.next^,GetNextReg(destloc.register64.reghi),2);
  907. end;
  908. {$endif cpu16bitalu}
  909. 2:
  910. if (target_info.endian=ENDIAN_BIG) then
  911. begin
  912. { paraloc^ -> high
  913. paraloc^.next -> low }
  914. unget_para(paraloc^);
  915. gen_alloc_regloc(list,destloc);
  916. { reg->reg, alignment is irrelevant }
  917. cg.a_load_cgparaloc_anyreg(list,OS_32,paraloc^,destloc.register64.reghi,4);
  918. unget_para(paraloc^.next^);
  919. cg.a_load_cgparaloc_anyreg(list,OS_32,paraloc^.next^,destloc.register64.reglo,4);
  920. end
  921. else
  922. begin
  923. { paraloc^ -> low
  924. paraloc^.next -> high }
  925. unget_para(paraloc^);
  926. gen_alloc_regloc(list,destloc);
  927. cg.a_load_cgparaloc_anyreg(list,OS_32,paraloc^,destloc.register64.reglo,4);
  928. unget_para(paraloc^.next^);
  929. cg.a_load_cgparaloc_anyreg(list,OS_32,paraloc^.next^,destloc.register64.reghi,4);
  930. end;
  931. else
  932. { unexpected number of paralocs }
  933. internalerror(200410104);
  934. end;
  935. end;
  936. LOC_REFERENCE:
  937. begin
  938. gen_alloc_regloc(list,destloc);
  939. reference_reset_base(href,paraloc^.reference.index,paraloc^.reference.offset,para.alignment);
  940. cg64.a_load64_ref_reg(list,href,destloc.register64);
  941. unget_para(paraloc^);
  942. end;
  943. else
  944. internalerror(2005101501);
  945. end
  946. end
  947. else
  948. {$endif cpu64bitalu}
  949. begin
  950. if assigned(paraloc^.next) then
  951. begin
  952. if (destloc.size in [OS_PAIR,OS_SPAIR]) and
  953. (para.Size in [OS_PAIR,OS_SPAIR]) then
  954. begin
  955. unget_para(paraloc^);
  956. gen_alloc_regloc(list,destloc);
  957. cg.a_load_cgparaloc_anyreg(list,OS_INT,paraloc^,destloc.register,sizeof(aint));
  958. unget_para(paraloc^.Next^);
  959. gen_alloc_regloc(list,destloc);
  960. {$if defined(cpu16bitalu) or defined(cpu8bitalu)}
  961. cg.a_load_cgparaloc_anyreg(list,OS_INT,paraloc^.Next^,GetNextReg(destloc.register),sizeof(aint));
  962. {$else}
  963. cg.a_load_cgparaloc_anyreg(list,OS_INT,paraloc^.Next^,destloc.registerhi,sizeof(aint));
  964. {$endif}
  965. end
  966. else
  967. internalerror(200410105);
  968. end
  969. else
  970. begin
  971. unget_para(paraloc^);
  972. gen_alloc_regloc(list,destloc);
  973. cg.a_load_cgparaloc_anyreg(list,destloc.size,paraloc^,destloc.register,sizeof(aint));
  974. end;
  975. end;
  976. end;
  977. LOC_FPUREGISTER,
  978. LOC_CFPUREGISTER :
  979. begin
  980. {$ifdef mips}
  981. if (destloc.size = paraloc^.Size) and
  982. (paraloc^.Loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER,LOC_REFERENCE,LOC_CREFERENCE]) then
  983. begin
  984. unget_para(paraloc^);
  985. gen_alloc_regloc(list,destloc);
  986. cg.a_load_cgparaloc_anyreg(list,destloc.size,paraloc^,destloc.register,para.alignment);
  987. end
  988. else if (destloc.size = OS_F32) and
  989. (paraloc^.Loc in [LOC_REGISTER,LOC_CREGISTER]) then
  990. begin
  991. gen_alloc_regloc(list,destloc);
  992. unget_para(paraloc^);
  993. list.Concat(taicpu.op_reg_reg(A_MTC1,paraloc^.register,destloc.register));
  994. end
  995. { TODO: Produces invalid code, needs fixing together with regalloc setup. }
  996. {
  997. else if (destloc.size = OS_F64) and
  998. (paraloc^.Loc in [LOC_REGISTER,LOC_CREGISTER]) and
  999. (paraloc^.next^.Loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1000. begin
  1001. gen_alloc_regloc(list,destloc);
  1002. tmpreg:=destloc.register;
  1003. unget_para(paraloc^);
  1004. list.Concat(taicpu.op_reg_reg(A_MTC1,paraloc^.register,tmpreg));
  1005. setsupreg(tmpreg,getsupreg(tmpreg)+1);
  1006. unget_para(paraloc^.next^);
  1007. list.Concat(taicpu.op_reg_reg(A_MTC1,paraloc^.Next^.register,tmpreg));
  1008. end
  1009. }
  1010. else
  1011. begin
  1012. sizeleft := TCGSize2Size[destloc.size];
  1013. tg.GetTemp(list,sizeleft,sizeleft,tt_normal,tempref);
  1014. href:=tempref;
  1015. while assigned(paraloc) do
  1016. begin
  1017. unget_para(paraloc^);
  1018. cg.a_load_cgparaloc_ref(list,paraloc^,href,sizeleft,destloc.reference.alignment);
  1019. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1020. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1021. paraloc:=paraloc^.next;
  1022. end;
  1023. gen_alloc_regloc(list,destloc);
  1024. cg.a_loadfpu_ref_reg(list,destloc.size,destloc.size,tempref,destloc.register);
  1025. tg.UnGetTemp(list,tempref);
  1026. end;
  1027. {$else mips}
  1028. {$if defined(sparc) or defined(arm)}
  1029. { Arm and Sparc passes floats in int registers, when loading to fpu register
  1030. we need a temp }
  1031. sizeleft := TCGSize2Size[destloc.size];
  1032. tg.GetTemp(list,sizeleft,sizeleft,tt_normal,tempref);
  1033. href:=tempref;
  1034. while assigned(paraloc) do
  1035. begin
  1036. unget_para(paraloc^);
  1037. cg.a_load_cgparaloc_ref(list,paraloc^,href,sizeleft,destloc.reference.alignment);
  1038. inc(href.offset,TCGSize2Size[paraloc^.size]);
  1039. dec(sizeleft,TCGSize2Size[paraloc^.size]);
  1040. paraloc:=paraloc^.next;
  1041. end;
  1042. gen_alloc_regloc(list,destloc);
  1043. cg.a_loadfpu_ref_reg(list,destloc.size,destloc.size,tempref,destloc.register);
  1044. tg.UnGetTemp(list,tempref);
  1045. {$else defined(sparc) or defined(arm)}
  1046. unget_para(paraloc^);
  1047. gen_alloc_regloc(list,destloc);
  1048. { from register to register -> alignment is irrelevant }
  1049. cg.a_load_cgparaloc_anyreg(list,destloc.size,paraloc^,destloc.register,0);
  1050. if assigned(paraloc^.next) then
  1051. internalerror(200410109);
  1052. {$endif defined(sparc) or defined(arm)}
  1053. {$endif mips}
  1054. end;
  1055. LOC_MMREGISTER,
  1056. LOC_CMMREGISTER :
  1057. begin
  1058. {$ifndef cpu64bitalu}
  1059. { ARM vfp floats are passed in integer registers }
  1060. if (para.size=OS_F64) and
  1061. (paraloc^.size in [OS_32,OS_S32]) and
  1062. use_vectorfpu(vardef) then
  1063. begin
  1064. { we need 2x32bit reg }
  1065. if not assigned(paraloc^.next) or
  1066. assigned(paraloc^.next^.next) then
  1067. internalerror(2009112421);
  1068. unget_para(paraloc^.next^);
  1069. case paraloc^.next^.loc of
  1070. LOC_REGISTER:
  1071. tempreg:=paraloc^.next^.register;
  1072. LOC_REFERENCE:
  1073. begin
  1074. tempreg:=cg.getintregister(list,OS_32);
  1075. cg.a_load_cgparaloc_anyreg(list,OS_32,paraloc^.next^,tempreg,4);
  1076. end;
  1077. else
  1078. internalerror(2012051301);
  1079. end;
  1080. { don't free before the above, because then the getintregister
  1081. could reallocate this register and overwrite it }
  1082. unget_para(paraloc^);
  1083. gen_alloc_regloc(list,destloc);
  1084. if (target_info.endian=endian_big) then
  1085. { paraloc^ -> high
  1086. paraloc^.next -> low }
  1087. reg64:=joinreg64(tempreg,paraloc^.register)
  1088. else
  1089. reg64:=joinreg64(paraloc^.register,tempreg);
  1090. cg64.a_loadmm_intreg64_reg(list,OS_F64,reg64,destloc.register);
  1091. end
  1092. else
  1093. {$endif not cpu64bitalu}
  1094. begin
  1095. unget_para(paraloc^);
  1096. gen_alloc_regloc(list,destloc);
  1097. { from register to register -> alignment is irrelevant }
  1098. cg.a_load_cgparaloc_anyreg(list,destloc.size,paraloc^,destloc.register,0);
  1099. { data could come in two memory locations, for now
  1100. we simply ignore the sanity check (FK)
  1101. if assigned(paraloc^.next) then
  1102. internalerror(200410108);
  1103. }
  1104. end;
  1105. end;
  1106. else
  1107. internalerror(2010052903);
  1108. end;
  1109. end;
  1110. procedure gen_load_para_value(list:TAsmList);
  1111. procedure get_para(const paraloc:TCGParaLocation);
  1112. begin
  1113. case paraloc.loc of
  1114. LOC_REGISTER :
  1115. begin
  1116. if getsupreg(paraloc.register)<first_int_imreg then
  1117. cg.getcpuregister(list,paraloc.register);
  1118. end;
  1119. LOC_MMREGISTER :
  1120. begin
  1121. if getsupreg(paraloc.register)<first_mm_imreg then
  1122. cg.getcpuregister(list,paraloc.register);
  1123. end;
  1124. LOC_FPUREGISTER :
  1125. begin
  1126. if getsupreg(paraloc.register)<first_fpu_imreg then
  1127. cg.getcpuregister(list,paraloc.register);
  1128. end;
  1129. end;
  1130. end;
  1131. var
  1132. i : longint;
  1133. currpara : tparavarsym;
  1134. paraloc : pcgparalocation;
  1135. begin
  1136. if (po_assembler in current_procinfo.procdef.procoptions) or
  1137. { exceptfilters have a single hidden 'parentfp' parameter, which
  1138. is handled by tcg.g_proc_entry. }
  1139. (current_procinfo.procdef.proctypeoption=potype_exceptfilter) then
  1140. exit;
  1141. { Allocate registers used by parameters }
  1142. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1143. begin
  1144. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1145. paraloc:=currpara.paraloc[calleeside].location;
  1146. while assigned(paraloc) do
  1147. begin
  1148. if paraloc^.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER] then
  1149. get_para(paraloc^);
  1150. paraloc:=paraloc^.next;
  1151. end;
  1152. end;
  1153. { Copy parameters to local references/registers }
  1154. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1155. begin
  1156. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1157. gen_load_cgpara_loc(list,currpara.vardef,currpara.paraloc[calleeside],currpara.initialloc,paramanager.param_use_paraloc(currpara.paraloc[calleeside]));
  1158. { gen_load_cgpara_loc() already allocated the initialloc
  1159. -> don't allocate again }
  1160. if currpara.initialloc.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMREGISTER] then
  1161. gen_alloc_regvar(list,currpara,false);
  1162. end;
  1163. { generate copies of call by value parameters, must be done before
  1164. the initialization and body is parsed because the refcounts are
  1165. incremented using the local copies }
  1166. current_procinfo.procdef.parast.SymList.ForEachCall(@copyvalueparas,list);
  1167. {$ifdef powerpc}
  1168. { unget the register that contains the stack pointer before the procedure entry, }
  1169. { which is used to access the parameters in their original callee-side location }
  1170. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1171. cg.a_reg_dealloc(list,NR_R12);
  1172. {$endif powerpc}
  1173. {$ifdef powerpc64}
  1174. { unget the register that contains the stack pointer before the procedure entry, }
  1175. { which is used to access the parameters in their original callee-side location }
  1176. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  1177. cg.a_reg_dealloc(list, NR_OLD_STACK_POINTER_REG);
  1178. {$endif powerpc64}
  1179. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1180. begin
  1181. { initialize refcounted paras, and trash others. Needed here
  1182. instead of in gen_initialize_code, because when a reference is
  1183. intialised or trashed while the pointer to that reference is kept
  1184. in a regvar, we add a register move and that one again has to
  1185. come after the parameter loading code as far as the register
  1186. allocator is concerned }
  1187. current_procinfo.procdef.parast.SymList.ForEachCall(@init_paras,list);
  1188. end;
  1189. end;
  1190. {****************************************************************************
  1191. Entry/Exit
  1192. ****************************************************************************}
  1193. function has_alias_name(pd:tprocdef;const s:string):boolean;
  1194. var
  1195. item : TCmdStrListItem;
  1196. begin
  1197. result:=true;
  1198. if pd.mangledname=s then
  1199. exit;
  1200. item := TCmdStrListItem(pd.aliasnames.first);
  1201. while assigned(item) do
  1202. begin
  1203. if item.str=s then
  1204. exit;
  1205. item := TCmdStrListItem(item.next);
  1206. end;
  1207. result:=false;
  1208. end;
  1209. procedure alloc_proc_symbol(pd: tprocdef);
  1210. var
  1211. item : TCmdStrListItem;
  1212. begin
  1213. item := TCmdStrListItem(pd.aliasnames.first);
  1214. while assigned(item) do
  1215. begin
  1216. current_asmdata.DefineAsmSymbol(item.str,AB_GLOBAL,AT_FUNCTION);
  1217. item := TCmdStrListItem(item.next);
  1218. end;
  1219. end;
  1220. procedure gen_proc_symbol(list:TAsmList);
  1221. var
  1222. item,
  1223. previtem : TCmdStrListItem;
  1224. begin
  1225. previtem:=nil;
  1226. item := TCmdStrListItem(current_procinfo.procdef.aliasnames.first);
  1227. while assigned(item) do
  1228. begin
  1229. {$ifdef arm}
  1230. if current_settings.cputype in cpu_thumb2+cpu_thumb then
  1231. list.concat(tai_thumb_func.create);
  1232. {$endif arm}
  1233. { "double link" all procedure entry symbols via .reference }
  1234. { directives on darwin, because otherwise the linker }
  1235. { sometimes strips the procedure if only on of the symbols }
  1236. { is referenced }
  1237. if assigned(previtem) and
  1238. (target_info.system in systems_darwin) then
  1239. list.concat(tai_directive.create(asd_reference,item.str));
  1240. if (cs_profile in current_settings.moduleswitches) or
  1241. (po_global in current_procinfo.procdef.procoptions) then
  1242. list.concat(Tai_symbol.createname_global(item.str,AT_FUNCTION,0))
  1243. else
  1244. list.concat(Tai_symbol.createname(item.str,AT_FUNCTION,0));
  1245. if assigned(previtem) and
  1246. (target_info.system in systems_darwin) then
  1247. list.concat(tai_directive.create(asd_reference,previtem.str));
  1248. if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  1249. list.concat(Tai_function_name.create(item.str));
  1250. previtem:=item;
  1251. item := TCmdStrListItem(item.next);
  1252. end;
  1253. current_procinfo.procdef.procstarttai:=tai(list.last);
  1254. end;
  1255. procedure gen_proc_entry_code(list:TAsmList);
  1256. var
  1257. hitemp,
  1258. lotemp, stack_frame_size : longint;
  1259. begin
  1260. { generate call frame marker for dwarf call frame info }
  1261. current_asmdata.asmcfi.start_frame(list);
  1262. { All temps are know, write offsets used for information }
  1263. if (cs_asm_source in current_settings.globalswitches) then
  1264. begin
  1265. if tg.direction>0 then
  1266. begin
  1267. lotemp:=current_procinfo.tempstart;
  1268. hitemp:=tg.lasttemp;
  1269. end
  1270. else
  1271. begin
  1272. lotemp:=tg.lasttemp;
  1273. hitemp:=current_procinfo.tempstart;
  1274. end;
  1275. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1276. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1277. end;
  1278. { generate target specific proc entry code }
  1279. stack_frame_size := current_procinfo.calc_stackframe_size;
  1280. if (stack_frame_size <> 0) and
  1281. (po_nostackframe in current_procinfo.procdef.procoptions) then
  1282. message1(parser_e_nostackframe_with_locals,tostr(stack_frame_size));
  1283. hlcg.g_proc_entry(list,stack_frame_size,(po_nostackframe in current_procinfo.procdef.procoptions));
  1284. end;
  1285. procedure gen_proc_exit_code(list:TAsmList);
  1286. var
  1287. parasize : longint;
  1288. begin
  1289. { c style clearstack does not need to remove parameters from the stack, only the
  1290. return value when it was pushed by arguments }
  1291. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1292. begin
  1293. parasize:=0;
  1294. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef) then
  1295. inc(parasize,sizeof(pint));
  1296. end
  1297. else
  1298. begin
  1299. parasize:=current_procinfo.para_stack_size;
  1300. { the parent frame pointer para has to be removed by the caller in
  1301. case of Delphi-style parent frame pointer passing }
  1302. if not paramanager.use_fixed_stack and
  1303. (po_delphi_nested_cc in current_procinfo.procdef.procoptions) then
  1304. dec(parasize,sizeof(pint));
  1305. end;
  1306. { generate target specific proc exit code }
  1307. hlcg.g_proc_exit(list,parasize,(po_nostackframe in current_procinfo.procdef.procoptions));
  1308. { release return registers, needed for optimizer }
  1309. if not is_void(current_procinfo.procdef.returndef) then
  1310. paramanager.freecgpara(list,current_procinfo.procdef.funcretloc[calleeside]);
  1311. { end of frame marker for call frame info }
  1312. current_asmdata.asmcfi.end_frame(list);
  1313. end;
  1314. procedure gen_stack_check_size_para(list:TAsmList);
  1315. var
  1316. paraloc1 : tcgpara;
  1317. pd : tprocdef;
  1318. begin
  1319. pd:=search_system_proc('fpc_stackcheck');
  1320. paraloc1.init;
  1321. paramanager.getintparaloc(pd,1,paraloc1);
  1322. cg.a_load_const_cgpara(list,OS_INT,current_procinfo.calc_stackframe_size,paraloc1);
  1323. paramanager.freecgpara(list,paraloc1);
  1324. paraloc1.done;
  1325. end;
  1326. procedure gen_stack_check_call(list:TAsmList);
  1327. var
  1328. paraloc1 : tcgpara;
  1329. pd : tprocdef;
  1330. begin
  1331. pd:=search_system_proc('fpc_stackcheck');
  1332. paraloc1.init;
  1333. { Also alloc the register needed for the parameter }
  1334. paramanager.getintparaloc(pd,1,paraloc1);
  1335. paramanager.freecgpara(list,paraloc1);
  1336. { Call the helper }
  1337. cg.allocallcpuregisters(list);
  1338. cg.a_call_name(list,'FPC_STACKCHECK',false);
  1339. cg.deallocallcpuregisters(list);
  1340. paraloc1.done;
  1341. end;
  1342. procedure gen_save_used_regs(list:TAsmList);
  1343. begin
  1344. { Pure assembler routines need to save the registers themselves }
  1345. if (po_assembler in current_procinfo.procdef.procoptions) then
  1346. exit;
  1347. { oldfpccall expects all registers to be destroyed }
  1348. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1349. cg.g_save_registers(list);
  1350. end;
  1351. procedure gen_restore_used_regs(list:TAsmList);
  1352. begin
  1353. { Pure assembler routines need to save the registers themselves }
  1354. if (po_assembler in current_procinfo.procdef.procoptions) then
  1355. exit;
  1356. { oldfpccall expects all registers to be destroyed }
  1357. if current_procinfo.procdef.proccalloption<>pocall_oldfpccall then
  1358. cg.g_restore_registers(list);
  1359. end;
  1360. {****************************************************************************
  1361. External handling
  1362. ****************************************************************************}
  1363. procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
  1364. begin
  1365. create_hlcodegen;
  1366. { add the procedure to the al_procedures }
  1367. maybe_new_object_file(list);
  1368. new_section(list,sec_code,lower(pd.mangledname),current_settings.alignment.procalign);
  1369. list.concat(Tai_align.create(current_settings.alignment.procalign));
  1370. if (po_global in pd.procoptions) then
  1371. list.concat(Tai_symbol.createname_global(pd.mangledname,AT_FUNCTION,0))
  1372. else
  1373. list.concat(Tai_symbol.createname(pd.mangledname,AT_FUNCTION,0));
  1374. cg.g_external_wrapper(list,pd,externalname);
  1375. destroy_hlcodegen;
  1376. end;
  1377. {****************************************************************************
  1378. Const Data
  1379. ****************************************************************************}
  1380. procedure gen_alloc_symtable(list:TAsmList;pd:tprocdef;st:TSymtable);
  1381. procedure setlocalloc(vs:tabstractnormalvarsym);
  1382. begin
  1383. if cs_asm_source in current_settings.globalswitches then
  1384. begin
  1385. case vs.initialloc.loc of
  1386. LOC_REFERENCE :
  1387. begin
  1388. if not assigned(vs.initialloc.reference.symbol) then
  1389. list.concat(Tai_comment.Create(strpnew('Var '+vs.realname+' located at '+
  1390. std_regname(vs.initialloc.reference.base)+tostr_with_plus(vs.initialloc.reference.offset))));
  1391. end;
  1392. end;
  1393. end;
  1394. vs.localloc:=vs.initialloc;
  1395. FillChar(vs.currentregloc,sizeof(vs.currentregloc),0);
  1396. end;
  1397. var
  1398. i : longint;
  1399. sym : tsym;
  1400. vs : tabstractnormalvarsym;
  1401. isaddr : boolean;
  1402. begin
  1403. for i:=0 to st.SymList.Count-1 do
  1404. begin
  1405. sym:=tsym(st.SymList[i]);
  1406. case sym.typ of
  1407. staticvarsym :
  1408. begin
  1409. vs:=tabstractnormalvarsym(sym);
  1410. { The code in loadnode.pass_generatecode will create the
  1411. LOC_REFERENCE instead for all none register variables. This is
  1412. required because we can't store an asmsymbol in the localloc because
  1413. the asmsymbol is invalid after an unit is compiled. This gives
  1414. problems when this procedure is inlined in another unit (PFV) }
  1415. if vs.is_regvar(false) then
  1416. begin
  1417. vs.initialloc.loc:=tvarregable2tcgloc[vs.varregable];
  1418. vs.initialloc.size:=def_cgsize(vs.vardef);
  1419. gen_alloc_regvar(list,vs,true);
  1420. setlocalloc(vs);
  1421. end;
  1422. end;
  1423. paravarsym :
  1424. begin
  1425. vs:=tabstractnormalvarsym(sym);
  1426. { Parameters passed to assembler procedures need to be kept
  1427. in the original location }
  1428. if (po_assembler in current_procinfo.procdef.procoptions) then
  1429. tparavarsym(vs).paraloc[calleeside].get_location(vs.initialloc)
  1430. { exception filters receive their frame pointer as a parameter }
  1431. else if (current_procinfo.procdef.proctypeoption=potype_exceptfilter) and
  1432. (vo_is_parentfp in vs.varoptions) then
  1433. begin
  1434. location_reset(vs.initialloc,LOC_REGISTER,OS_ADDR);
  1435. vs.initialloc.register:=NR_FRAME_POINTER_REG;
  1436. end
  1437. else
  1438. begin
  1439. isaddr:=paramanager.push_addr_param(vs.varspez,vs.vardef,current_procinfo.procdef.proccalloption);
  1440. if isaddr then
  1441. vs.initialloc.size:=OS_ADDR
  1442. else
  1443. vs.initialloc.size:=def_cgsize(vs.vardef);
  1444. if vs.is_regvar(isaddr) then
  1445. vs.initialloc.loc:=tvarregable2tcgloc[vs.varregable]
  1446. else
  1447. begin
  1448. vs.initialloc.loc:=LOC_REFERENCE;
  1449. { Reuse the parameter location for values to are at a single location on the stack }
  1450. if paramanager.param_use_paraloc(tparavarsym(sym).paraloc[calleeside]) then
  1451. begin
  1452. reference_reset_base(vs.initialloc.reference,tparavarsym(sym).paraloc[calleeside].location^.reference.index,
  1453. tparavarsym(sym).paraloc[calleeside].location^.reference.offset,tparavarsym(sym).paraloc[calleeside].alignment);
  1454. end
  1455. else
  1456. begin
  1457. if isaddr then
  1458. tg.GetLocal(list,sizeof(pint),voidpointertype,vs.initialloc.reference)
  1459. else
  1460. tg.GetLocal(list,vs.getsize,tparavarsym(sym).paraloc[calleeside].alignment,vs.vardef,vs.initialloc.reference);
  1461. end;
  1462. end;
  1463. end;
  1464. setlocalloc(vs);
  1465. end;
  1466. localvarsym :
  1467. begin
  1468. vs:=tabstractnormalvarsym(sym);
  1469. vs.initialloc.size:=def_cgsize(vs.vardef);
  1470. if ([po_assembler,po_nostackframe] * current_procinfo.procdef.procoptions = [po_assembler,po_nostackframe]) and
  1471. (vo_is_funcret in vs.varoptions) then
  1472. begin
  1473. paramanager.create_funcretloc_info(pd,calleeside);
  1474. if assigned(pd.funcretloc[calleeside].location^.next) then
  1475. begin
  1476. { can't replace references to "result" with a complex
  1477. location expression inside assembler code }
  1478. location_reset(vs.initialloc,LOC_INVALID,OS_NO);
  1479. end
  1480. else
  1481. pd.funcretloc[calleeside].get_location(vs.initialloc);
  1482. end
  1483. else if (m_delphi in current_settings.modeswitches) and
  1484. (po_assembler in current_procinfo.procdef.procoptions) and
  1485. (vo_is_funcret in vs.varoptions) and
  1486. (vs.refs=0) then
  1487. begin
  1488. { not referenced, so don't allocate. Use dummy to }
  1489. { avoid ie's later on because of LOC_INVALID }
  1490. vs.initialloc.loc:=LOC_REGISTER;
  1491. vs.initialloc.size:=OS_INT;
  1492. vs.initialloc.register:=NR_FUNCTION_RESULT_REG;
  1493. end
  1494. else if vs.is_regvar(false) then
  1495. begin
  1496. vs.initialloc.loc:=tvarregable2tcgloc[vs.varregable];
  1497. gen_alloc_regvar(list,vs,true);
  1498. end
  1499. else
  1500. begin
  1501. vs.initialloc.loc:=LOC_REFERENCE;
  1502. tg.GetLocal(list,vs.getsize,vs.vardef,vs.initialloc.reference);
  1503. end;
  1504. setlocalloc(vs);
  1505. end;
  1506. end;
  1507. end;
  1508. end;
  1509. procedure add_regvars(var rv: tusedregvars; const location: tlocation);
  1510. begin
  1511. case location.loc of
  1512. LOC_CREGISTER:
  1513. {$ifdef cpu64bitalu}
  1514. if location.size in [OS_128,OS_S128] then
  1515. begin
  1516. rv.intregvars.addnodup(getsupreg(location.register128.reglo));
  1517. rv.intregvars.addnodup(getsupreg(location.register128.reghi));
  1518. end
  1519. else
  1520. {$else cpu64bitalu}
  1521. if location.size in [OS_64,OS_S64] then
  1522. begin
  1523. rv.intregvars.addnodup(getsupreg(location.register64.reglo));
  1524. rv.intregvars.addnodup(getsupreg(location.register64.reghi));
  1525. end
  1526. else
  1527. {$endif cpu64bitalu}
  1528. rv.intregvars.addnodup(getsupreg(location.register));
  1529. LOC_CFPUREGISTER:
  1530. rv.fpuregvars.addnodup(getsupreg(location.register));
  1531. LOC_CMMREGISTER:
  1532. rv.mmregvars.addnodup(getsupreg(location.register));
  1533. end;
  1534. end;
  1535. function do_get_used_regvars(var n: tnode; arg: pointer): foreachnoderesult;
  1536. var
  1537. rv: pusedregvars absolute arg;
  1538. begin
  1539. case (n.nodetype) of
  1540. temprefn:
  1541. { We only have to synchronise a tempnode before a loop if it is }
  1542. { not created inside the loop, and only synchronise after the }
  1543. { loop if it's not destroyed inside the loop. If it's created }
  1544. { before the loop and not yet destroyed, then before the loop }
  1545. { is secondpassed tempinfo^.valid will be true, and we get the }
  1546. { correct registers. If it's not destroyed inside the loop, }
  1547. { then after the loop has been secondpassed tempinfo^.valid }
  1548. { be true and we also get the right registers. In other cases, }
  1549. { tempinfo^.valid will be false and so we do not add }
  1550. { unnecessary registers. This way, we don't have to look at }
  1551. { tempcreate and tempdestroy nodes to get this info (JM) }
  1552. if (ti_valid in ttemprefnode(n).tempinfo^.flags) then
  1553. add_regvars(rv^,ttemprefnode(n).tempinfo^.location);
  1554. loadn:
  1555. if (tloadnode(n).symtableentry.typ in [staticvarsym,localvarsym,paravarsym]) then
  1556. add_regvars(rv^,tabstractnormalvarsym(tloadnode(n).symtableentry).localloc);
  1557. vecn:
  1558. { range checks sometimes need the high parameter }
  1559. if (cs_check_range in current_settings.localswitches) and
  1560. (is_open_array(tvecnode(n).left.resultdef) or
  1561. is_array_of_const(tvecnode(n).left.resultdef)) and
  1562. not(current_procinfo.procdef.proccalloption in cdecl_pocalls) then
  1563. add_regvars(rv^,tabstractnormalvarsym(get_high_value_sym(tparavarsym(tloadnode(tvecnode(n).left).symtableentry))).localloc)
  1564. end;
  1565. result := fen_true;
  1566. end;
  1567. procedure get_used_regvars(n: tnode; var rv: tusedregvars);
  1568. begin
  1569. foreachnodestatic(n,@do_get_used_regvars,@rv);
  1570. end;
  1571. (*
  1572. See comments at declaration of pusedregvarscommon
  1573. function do_get_used_regvars_common(var n: tnode; arg: pointer): foreachnoderesult;
  1574. var
  1575. rv: pusedregvarscommon absolute arg;
  1576. begin
  1577. if (n.nodetype = loadn) and
  1578. (tloadnode(n).symtableentry.typ in [staticvarsym,localvarsym,paravarsym]) then
  1579. with tabstractnormalvarsym(tloadnode(n).symtableentry).localloc do
  1580. case loc of
  1581. LOC_CREGISTER:
  1582. { if not yet encountered in this node tree }
  1583. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  1584. { but nevertheless already encountered somewhere }
  1585. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  1586. { then it's a regvar used in two or more node trees }
  1587. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  1588. LOC_CFPUREGISTER:
  1589. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  1590. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  1591. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  1592. LOC_CMMREGISTER:
  1593. if (rv^.myregvars.intregvars.addnodup(getsupreg(register))) and
  1594. not(rv^.allregvars.intregvars.addnodup(getsupreg(register))) then
  1595. rv^.commonregvars.intregvars.addnodup(getsupreg(register));
  1596. end;
  1597. result := fen_true;
  1598. end;
  1599. procedure get_used_regvars_common(n: tnode; var rv: tusedregvarscommon);
  1600. begin
  1601. rv.myregvars.intregvars.clear;
  1602. rv.myregvars.fpuregvars.clear;
  1603. rv.myregvars.mmregvars.clear;
  1604. foreachnodestatic(n,@do_get_used_regvars_common,@rv);
  1605. end;
  1606. *)
  1607. procedure gen_sync_regvars(list:TAsmList; var rv: tusedregvars);
  1608. var
  1609. count: longint;
  1610. begin
  1611. for count := 1 to rv.intregvars.length do
  1612. cg.a_reg_sync(list,newreg(R_INTREGISTER,rv.intregvars.readidx(count-1),R_SUBWHOLE));
  1613. for count := 1 to rv.fpuregvars.length do
  1614. cg.a_reg_sync(list,newreg(R_FPUREGISTER,rv.fpuregvars.readidx(count-1),R_SUBWHOLE));
  1615. for count := 1 to rv.mmregvars.length do
  1616. cg.a_reg_sync(list,newreg(R_MMREGISTER,rv.mmregvars.readidx(count-1),R_SUBWHOLE));
  1617. end;
  1618. {*****************************************************************************
  1619. SSA support
  1620. *****************************************************************************}
  1621. type
  1622. preplaceregrec = ^treplaceregrec;
  1623. treplaceregrec = record
  1624. old, new: tregister;
  1625. oldhi, newhi: tregister;
  1626. ressym: tsym;
  1627. { moved sym }
  1628. sym : tabstractnormalvarsym;
  1629. end;
  1630. function doreplace(var n: tnode; para: pointer): foreachnoderesult;
  1631. var
  1632. rr: preplaceregrec absolute para;
  1633. begin
  1634. result := fen_false;
  1635. if (nf_is_funcret in n.flags) and (fc_exit in flowcontrol) then
  1636. exit;
  1637. case n.nodetype of
  1638. loadn:
  1639. begin
  1640. if (tloadnode(n).symtableentry.typ in [localvarsym,paravarsym,staticvarsym]) and
  1641. (tabstractvarsym(tloadnode(n).symtableentry).varoptions * [vo_is_dll_var, vo_is_thread_var] = []) and
  1642. not assigned(tloadnode(n).left) and
  1643. ((tloadnode(n).symtableentry <> rr^.ressym) or
  1644. not(fc_exit in flowcontrol)
  1645. ) and
  1646. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  1647. (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register = rr^.old) then
  1648. begin
  1649. {$ifdef cpu64bitalu}
  1650. { it's possible a 128 bit location was shifted and/xor typecasted }
  1651. { in a 64 bit value, so only 1 register was left in the location }
  1652. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.size in [OS_128,OS_S128]) then
  1653. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register128.reghi = rr^.oldhi) then
  1654. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register128.reghi := rr^.newhi
  1655. else
  1656. exit;
  1657. {$else cpu64bitalu}
  1658. { it's possible a 64 bit location was shifted and/xor typecasted }
  1659. { in a 32 bit value, so only 1 register was left in the location }
  1660. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.size in [OS_64,OS_S64]) then
  1661. if (tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi = rr^.oldhi) then
  1662. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register64.reghi := rr^.newhi
  1663. else
  1664. exit;
  1665. {$endif cpu64bitalu}
  1666. tabstractnormalvarsym(tloadnode(n).symtableentry).localloc.register := rr^.new;
  1667. rr^.sym := tabstractnormalvarsym(tloadnode(n).symtableentry);
  1668. result := fen_norecurse_true;
  1669. end;
  1670. end;
  1671. temprefn:
  1672. begin
  1673. if (ti_valid in ttemprefnode(n).tempinfo^.flags) and
  1674. (ttemprefnode(n).tempinfo^.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) and
  1675. (ttemprefnode(n).tempinfo^.location.register = rr^.old) then
  1676. begin
  1677. {$ifdef cpu64bitalu}
  1678. { it's possible a 128 bit location was shifted and/xor typecasted }
  1679. { in a 64 bit value, so only 1 register was left in the location }
  1680. if (ttemprefnode(n).tempinfo^.location.size in [OS_128,OS_S128]) then
  1681. if (ttemprefnode(n).tempinfo^.location.register128.reghi = rr^.oldhi) then
  1682. ttemprefnode(n).tempinfo^.location.register128.reghi := rr^.newhi
  1683. else
  1684. exit;
  1685. {$else cpu64bitalu}
  1686. { it's possible a 64 bit location was shifted and/xor typecasted }
  1687. { in a 32 bit value, so only 1 register was left in the location }
  1688. if (ttemprefnode(n).tempinfo^.location.size in [OS_64,OS_S64]) then
  1689. if (ttemprefnode(n).tempinfo^.location.register64.reghi = rr^.oldhi) then
  1690. ttemprefnode(n).tempinfo^.location.register64.reghi := rr^.newhi
  1691. else
  1692. exit;
  1693. {$endif cpu64bitalu}
  1694. ttemprefnode(n).tempinfo^.location.register := rr^.new;
  1695. result := fen_norecurse_true;
  1696. end;
  1697. end;
  1698. { optimize the searching a bit }
  1699. derefn,addrn,
  1700. calln,inlinen,casen,
  1701. addn,subn,muln,
  1702. andn,orn,xorn,
  1703. ltn,lten,gtn,gten,equaln,unequaln,
  1704. slashn,divn,shrn,shln,notn,
  1705. inn,
  1706. asn,isn:
  1707. result := fen_norecurse_false;
  1708. end;
  1709. end;
  1710. procedure maybechangeloadnodereg(list: TAsmList; var n: tnode; reload: boolean);
  1711. var
  1712. rr: treplaceregrec;
  1713. varloc : tai_varloc;
  1714. begin
  1715. {$ifdef jvm}
  1716. exit;
  1717. {$endif}
  1718. if not (n.location.loc in [LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMXREGISTER,LOC_CMMREGISTER]) or
  1719. ([fc_inflowcontrol,fc_gotolabel,fc_lefthandled] * flowcontrol <> []) then
  1720. exit;
  1721. rr.old := n.location.register;
  1722. rr.ressym := nil;
  1723. rr.sym := nil;
  1724. rr.oldhi := NR_NO;
  1725. case n.location.loc of
  1726. LOC_CREGISTER:
  1727. begin
  1728. {$ifdef cpu64bitalu}
  1729. if (n.location.size in [OS_128,OS_S128]) then
  1730. begin
  1731. rr.oldhi := n.location.register128.reghi;
  1732. rr.new := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  1733. rr.newhi := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  1734. end
  1735. else
  1736. {$else cpu64bitalu}
  1737. if (n.location.size in [OS_64,OS_S64]) then
  1738. begin
  1739. rr.oldhi := n.location.register64.reghi;
  1740. rr.new := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  1741. rr.newhi := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  1742. end
  1743. else
  1744. {$endif cpu64bitalu}
  1745. rr.new := cg.getintregister(current_asmdata.CurrAsmList,n.location.size);
  1746. end;
  1747. LOC_CFPUREGISTER:
  1748. rr.new := cg.getfpuregister(current_asmdata.CurrAsmList,n.location.size);
  1749. {$ifdef SUPPORT_MMX}
  1750. LOC_CMMXREGISTER:
  1751. rr.new := tcgx86(cg).getmmxregister(current_asmdata.CurrAsmList);
  1752. {$endif SUPPORT_MMX}
  1753. LOC_CMMREGISTER:
  1754. rr.new := cg.getmmregister(current_asmdata.CurrAsmList,n.location.size);
  1755. else
  1756. exit;
  1757. end;
  1758. if not is_void(current_procinfo.procdef.returndef) and
  1759. assigned(current_procinfo.procdef.funcretsym) and
  1760. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs <> 0) then
  1761. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1762. rr.ressym:=tsym(current_procinfo.procdef.parast.Find('self'))
  1763. else
  1764. rr.ressym:=current_procinfo.procdef.funcretsym;
  1765. if not foreachnodestatic(n,@doreplace,@rr) then
  1766. exit;
  1767. if reload then
  1768. case n.location.loc of
  1769. LOC_CREGISTER:
  1770. begin
  1771. {$ifdef cpu64bitalu}
  1772. if (n.location.size in [OS_128,OS_S128]) then
  1773. cg128.a_load128_reg_reg(list,n.location.register128,joinreg128(rr.new,rr.newhi))
  1774. else
  1775. {$else cpu64bitalu}
  1776. if (n.location.size in [OS_64,OS_S64]) then
  1777. cg64.a_load64_reg_reg(list,n.location.register64,joinreg64(rr.new,rr.newhi))
  1778. else
  1779. {$endif cpu64bitalu}
  1780. cg.a_load_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new);
  1781. end;
  1782. LOC_CFPUREGISTER:
  1783. cg.a_loadfpu_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new);
  1784. {$ifdef SUPPORT_MMX}
  1785. LOC_CMMXREGISTER:
  1786. cg.a_loadmm_reg_reg(list,OS_M64,OS_M64,n.location.register,rr.new,nil);
  1787. {$endif SUPPORT_MMX}
  1788. LOC_CMMREGISTER:
  1789. cg.a_loadmm_reg_reg(list,n.location.size,n.location.size,n.location.register,rr.new,nil);
  1790. else
  1791. internalerror(2006090920);
  1792. end;
  1793. { now that we've change the loadn/temp, also change the node result location }
  1794. {$ifdef cpu64bitalu}
  1795. if (n.location.size in [OS_128,OS_S128]) then
  1796. begin
  1797. n.location.register128.reglo := rr.new;
  1798. n.location.register128.reghi := rr.newhi;
  1799. if assigned(rr.sym) and
  1800. ((rr.sym.currentregloc.register<>rr.new) or
  1801. (rr.sym.currentregloc.registerhi<>rr.newhi)) then
  1802. begin
  1803. varloc:=tai_varloc.create128(rr.sym,rr.new,rr.newhi);
  1804. varloc.oldlocation:=rr.sym.currentregloc.register;
  1805. varloc.oldlocationhi:=rr.sym.currentregloc.registerhi;
  1806. rr.sym.currentregloc.register:=rr.new;
  1807. rr.sym.currentregloc.registerHI:=rr.newhi;
  1808. list.concat(varloc);
  1809. end;
  1810. end
  1811. else
  1812. {$else cpu64bitalu}
  1813. if (n.location.size in [OS_64,OS_S64]) then
  1814. begin
  1815. n.location.register64.reglo := rr.new;
  1816. n.location.register64.reghi := rr.newhi;
  1817. if assigned(rr.sym) and
  1818. ((rr.sym.currentregloc.register<>rr.new) or
  1819. (rr.sym.currentregloc.registerhi<>rr.newhi)) then
  1820. begin
  1821. varloc:=tai_varloc.create64(rr.sym,rr.new,rr.newhi);
  1822. varloc.oldlocation:=rr.sym.currentregloc.register;
  1823. varloc.oldlocationhi:=rr.sym.currentregloc.registerhi;
  1824. rr.sym.currentregloc.register:=rr.new;
  1825. rr.sym.currentregloc.registerHI:=rr.newhi;
  1826. list.concat(varloc);
  1827. end;
  1828. end
  1829. else
  1830. {$endif cpu64bitalu}
  1831. begin
  1832. n.location.register := rr.new;
  1833. if assigned(rr.sym) and (rr.sym.currentregloc.register<>rr.new) then
  1834. begin
  1835. varloc:=tai_varloc.create(rr.sym,rr.new);
  1836. varloc.oldlocation:=rr.sym.currentregloc.register;
  1837. rr.sym.currentregloc.register:=rr.new;
  1838. list.concat(varloc);
  1839. end;
  1840. end;
  1841. end;
  1842. procedure gen_free_symtable(list:TAsmList;st:TSymtable);
  1843. var
  1844. i : longint;
  1845. sym : tsym;
  1846. begin
  1847. for i:=0 to st.SymList.Count-1 do
  1848. begin
  1849. sym:=tsym(st.SymList[i]);
  1850. if (sym.typ in [staticvarsym,localvarsym,paravarsym]) then
  1851. begin
  1852. with tabstractnormalvarsym(sym) do
  1853. begin
  1854. { Note: We need to keep the data available in memory
  1855. for the sub procedures that can access local data
  1856. in the parent procedures }
  1857. case localloc.loc of
  1858. LOC_CREGISTER :
  1859. if (pi_has_label in current_procinfo.flags) then
  1860. {$ifdef cpu64bitalu}
  1861. if def_cgsize(vardef) in [OS_128,OS_S128] then
  1862. begin
  1863. cg.a_reg_sync(list,localloc.register128.reglo);
  1864. cg.a_reg_sync(list,localloc.register128.reghi);
  1865. end
  1866. else
  1867. {$else cpu64bitalu}
  1868. if def_cgsize(vardef) in [OS_64,OS_S64] then
  1869. begin
  1870. cg.a_reg_sync(list,localloc.register64.reglo);
  1871. cg.a_reg_sync(list,localloc.register64.reghi);
  1872. end
  1873. else
  1874. {$endif cpu64bitalu}
  1875. cg.a_reg_sync(list,localloc.register);
  1876. LOC_CFPUREGISTER,
  1877. LOC_CMMREGISTER:
  1878. if (pi_has_label in current_procinfo.flags) then
  1879. cg.a_reg_sync(list,localloc.register);
  1880. LOC_REFERENCE :
  1881. begin
  1882. if typ in [localvarsym,paravarsym] then
  1883. tg.Ungetlocal(list,localloc.reference);
  1884. end;
  1885. end;
  1886. end;
  1887. end;
  1888. end;
  1889. end;
  1890. procedure gen_load_vmt_register(list:TAsmList;objdef:tobjectdef;selfloc:tlocation;var vmtreg:tregister);
  1891. var
  1892. href : treference;
  1893. selfdef: tdef;
  1894. begin
  1895. if is_object(objdef) then
  1896. begin
  1897. case selfloc.loc of
  1898. LOC_CREFERENCE,
  1899. LOC_REFERENCE:
  1900. begin
  1901. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset,sizeof(pint));
  1902. cg.a_loadaddr_ref_reg(list,selfloc.reference,href.base);
  1903. selfdef:=getpointerdef(objdef);
  1904. end;
  1905. else
  1906. internalerror(200305056);
  1907. end;
  1908. end
  1909. else
  1910. { This is also valid for Objective-C classes: vmt_offset is 0 there,
  1911. and the first "field" of an Objective-C class instance is a pointer
  1912. to its "meta-class". }
  1913. begin
  1914. selfdef:=objdef;
  1915. case selfloc.loc of
  1916. LOC_REGISTER:
  1917. begin
  1918. {$ifdef cpu_uses_separate_address_registers}
  1919. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  1920. begin
  1921. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset,sizeof(pint));
  1922. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,selfloc.register,href.base);
  1923. end
  1924. else
  1925. {$endif cpu_uses_separate_address_registers}
  1926. reference_reset_base(href,selfloc.register,objdef.vmt_offset,sizeof(pint));
  1927. end;
  1928. LOC_CONSTANT,
  1929. LOC_CREGISTER,
  1930. LOC_CREFERENCE,
  1931. LOC_REFERENCE,
  1932. LOC_CSUBSETREG,
  1933. LOC_SUBSETREG,
  1934. LOC_CSUBSETREF,
  1935. LOC_SUBSETREF:
  1936. begin
  1937. reference_reset_base(href,cg.getaddressregister(list),objdef.vmt_offset,sizeof(pint));
  1938. { todo: pass actual vmt pointer type to hlcg }
  1939. hlcg.a_load_loc_reg(list,voidpointertype,voidpointertype,selfloc,href.base);
  1940. end;
  1941. else
  1942. internalerror(200305057);
  1943. end;
  1944. end;
  1945. vmtreg:=cg.getaddressregister(list);
  1946. hlcg.g_maybe_testself(list,selfdef,href.base);
  1947. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,vmtreg);
  1948. { test validity of VMT }
  1949. if not(is_interface(objdef)) and
  1950. not(is_cppclass(objdef)) and
  1951. not(is_objc_class_or_protocol(objdef)) then
  1952. cg.g_maybe_testvmt(list,vmtreg,objdef);
  1953. end;
  1954. function getprocalign : shortint;
  1955. begin
  1956. { gprof uses 16 byte granularity }
  1957. if (cs_profile in current_settings.moduleswitches) then
  1958. result:=16
  1959. else
  1960. result:=current_settings.alignment.procalign;
  1961. end;
  1962. procedure gen_fpc_dummy(list : TAsmList);
  1963. begin
  1964. {$ifdef i386}
  1965. { fix me! }
  1966. list.concat(Taicpu.Op_const_reg(A_MOV,S_L,1,NR_EAX));
  1967. list.concat(Taicpu.Op_const(A_RET,S_W,12));
  1968. {$endif i386}
  1969. end;
  1970. end.