ncgutil.pas 88 KB

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