ncgutil.pas 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Helper routines for all code generators
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncgutil;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,
  23. cpubase,cpupara,
  24. aasmbase,aasmtai,aasmcpu,
  25. cginfo,
  26. rgobj;
  27. type
  28. tloadregvars = (lr_dont_load_regvars, lr_load_regvars);
  29. tmaybesave = record
  30. saved : boolean;
  31. ref : treference;
  32. end;
  33. procedure firstcomplex(p : tbinarynode);
  34. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  35. procedure remove_non_regvars_from_loc(const t: tlocation; var regs: tregisterset);
  36. procedure location_force_reg(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  37. procedure location_force_mem(list: TAAsmoutput;var l:tlocation);
  38. procedure maybe_save(list:taasmoutput;needed:integer;var l:tlocation;var s:tmaybesave);
  39. procedure maybe_restore(list:taasmoutput;var l:tlocation;const s:tmaybesave);
  40. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  41. procedure push_value_para(p:tnode;inlined,is_cdecl:boolean;
  42. para_offset:longint;alignment : longint;
  43. const locpara : tparalocation);
  44. procedure genentrycode(list : TAAsmoutput;
  45. make_global:boolean;
  46. stackframe:longint;
  47. var parasize:longint;var nostackframe:boolean;
  48. inlined : boolean);
  49. procedure genexitcode(list : TAAsmoutput;parasize:longint;nostackframe,inlined:boolean);
  50. procedure genimplicitunitinit(list : TAAsmoutput);
  51. procedure genimplicitunitfinal(list : TAAsmoutput);
  52. implementation
  53. uses
  54. {$ifdef Delphi}
  55. Sysutils,
  56. {$else}
  57. strings,
  58. {$endif}
  59. cutils,cclasses,globtype,globals,systems,verbose,
  60. symbase,symconst,symtype,symsym,symdef,symtable,types,
  61. fmodule,
  62. cgbase,regvars,
  63. {$ifdef GDB}
  64. gdb,
  65. {$endif GDB}
  66. ncon,
  67. tgobj,cpuinfo,cgobj,cgcpu,cg64f32;
  68. {*****************************************************************************
  69. Misc Helpers
  70. *****************************************************************************}
  71. { DO NOT RELY on the fact that the tnode is not yet swaped
  72. because of inlining code PM }
  73. procedure firstcomplex(p : tbinarynode);
  74. var
  75. hp : tnode;
  76. begin
  77. { always calculate boolean AND and OR from left to right }
  78. if (p.nodetype in [orn,andn]) and
  79. (p.left.resulttype.def.deftype=orddef) and
  80. (torddef(p.left.resulttype.def).typ in [bool8bit,bool16bit,bool32bit]) then
  81. begin
  82. { p.swaped:=false}
  83. if nf_swaped in p.flags then
  84. internalerror(234234);
  85. end
  86. else
  87. if (((p.location.loc=LOC_FPUREGISTER) and
  88. (p.right.registersfpu > p.left.registersfpu)) or
  89. ((((p.left.registersfpu = 0) and
  90. (p.right.registersfpu = 0)) or
  91. (p.location.loc<>LOC_FPUREGISTER)) and
  92. (p.left.registers32<p.right.registers32))) and
  93. { the following check is appropriate, because all }
  94. { 4 registers are rarely used and it is thereby }
  95. { achieved that the extra code is being dropped }
  96. { by exchanging not commutative operators }
  97. (p.right.registers32<=c_countusableregsint) then
  98. begin
  99. hp:=p.left;
  100. p.left:=p.right;
  101. p.right:=hp;
  102. if nf_swaped in p.flags then
  103. exclude(p.flags,nf_swaped)
  104. else
  105. include(p.flags,nf_swaped);
  106. end;
  107. end;
  108. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  109. {
  110. produces jumps to true respectively false labels using boolean expressions
  111. depending on whether the loading of regvars is currently being
  112. synchronized manually (such as in an if-node) or automatically (most of
  113. the other cases where this procedure is called), loadregvars can be
  114. "lr_load_regvars" or "lr_dont_load_regvars"
  115. }
  116. var
  117. opsize : tcgsize;
  118. storepos : tfileposinfo;
  119. begin
  120. if nf_error in p.flags then
  121. exit;
  122. storepos:=aktfilepos;
  123. aktfilepos:=p.fileinfo;
  124. if is_boolean(p.resulttype.def) then
  125. begin
  126. if loadregvars = lr_load_regvars then
  127. load_all_regvars(list);
  128. if is_constboolnode(p) then
  129. begin
  130. if tordconstnode(p).value<>0 then
  131. cg.a_jmp_always(list,truelabel)
  132. else
  133. cg.a_jmp_always(list,falselabel)
  134. end
  135. else
  136. begin
  137. opsize:=def_cgsize(p.resulttype.def);
  138. case p.location.loc of
  139. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  140. begin
  141. if (p.location.loc = LOC_CREGISTER) then
  142. load_regvar_reg(list,p.location.register);
  143. cg.a_cmp_const_loc_label(list,opsize,OC_NE,
  144. 0,p.location,truelabel);
  145. { !!! should happen right after cmp (JM) }
  146. location_release(list,p.location);
  147. cg.a_jmp_always(list,falselabel);
  148. end;
  149. LOC_FLAGS :
  150. begin
  151. cg.a_jmp_flags(list,p.location.resflags,
  152. truelabel);
  153. cg.a_jmp_always(list,falselabel);
  154. end;
  155. end;
  156. end;
  157. end
  158. else
  159. internalerror(200112305);
  160. aktfilepos:=storepos;
  161. end;
  162. procedure remove_non_regvars_from_loc(const t: tlocation; var regs: tregisterset);
  163. begin
  164. case t.loc of
  165. LOC_REGISTER:
  166. begin
  167. { can't be a regvar, since it would be LOC_CREGISTER then }
  168. exclude(regs,t.register);
  169. if t.registerhigh <> R_NO then
  170. exclude(regs,t.registerhigh);
  171. end;
  172. LOC_CREFERENCE,LOC_REFERENCE:
  173. begin
  174. if not(cs_regalloc in aktglobalswitches) or
  175. (t.reference.base in rg.usableregsint) then
  176. exclude(regs,t.reference.base);
  177. if not(cs_regalloc in aktglobalswitches) or
  178. (t.reference.index in rg.usableregsint) then
  179. exclude(regs,t.reference.index);
  180. end;
  181. end;
  182. end;
  183. {*****************************************************************************
  184. TLocation
  185. *****************************************************************************}
  186. { 32-bit version }
  187. procedure location_force_reg32(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  188. var
  189. hregister,
  190. hregisterhi : tregister;
  191. hreg64 : tregister64;
  192. hl : tasmlabel;
  193. begin
  194. { handle transformations to 64bit separate }
  195. if dst_size in [OS_64,OS_S64] then
  196. begin
  197. if not (l.size in [OS_64,OS_S64]) then
  198. begin
  199. { load a smaller size to OS_64 }
  200. if l.loc=LOC_REGISTER then
  201. hregister:=rg.makeregsize(l.registerlow,OS_INT)
  202. else
  203. hregister:=rg.getregisterint(list);
  204. { load value in low register }
  205. case l.loc of
  206. LOC_FLAGS :
  207. cg.g_flags2reg(list,l.resflags,hregister);
  208. LOC_JUMP :
  209. begin
  210. cg.a_label(list,truelabel);
  211. cg.a_load_const_reg(list,OS_INT,1,hregister);
  212. getlabel(hl);
  213. cg.a_jmp_always(list,hl);
  214. cg.a_label(list,falselabel);
  215. cg.a_load_const_reg(list,OS_INT,0,hregister);
  216. cg.a_label(list,hl);
  217. end;
  218. else
  219. cg.a_load_loc_reg(list,l,hregister);
  220. end;
  221. { reset hi part, take care of the signed bit of the current value }
  222. hregisterhi:=rg.getregisterint(list);
  223. if (dst_size=OS_S64) and
  224. (l.size in [OS_S8,OS_S16,OS_S32]) then
  225. begin
  226. if l.loc=LOC_CONSTANT then
  227. begin
  228. if (longint(l.value)<0) then
  229. cg.a_load_const_reg(list,OS_32,$ffffffff,hregisterhi)
  230. else
  231. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  232. end
  233. else
  234. begin
  235. cg.a_load_reg_reg(list,OS_32,hregister,hregisterhi);
  236. cg.a_op_const_reg(list,OP_SAR,31,hregisterhi);
  237. end;
  238. end
  239. else
  240. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  241. location_reset(l,LOC_REGISTER,dst_size);
  242. l.registerlow:=hregister;
  243. l.registerhigh:=hregisterhi;
  244. end
  245. else
  246. begin
  247. { 64bit to 64bit }
  248. if (l.loc=LOC_REGISTER) or
  249. ((l.loc=LOC_CREGISTER) and maybeconst) then
  250. begin
  251. hregister:=l.registerlow;
  252. hregisterhi:=l.registerhigh;
  253. end
  254. else
  255. begin
  256. hregister:=rg.getregisterint(list);
  257. hregisterhi:=rg.getregisterint(list);
  258. end;
  259. hreg64.reglo:=hregister;
  260. hreg64.reghi:=hregisterhi;
  261. { load value in new register }
  262. cg64.a_load64_loc_reg(list,l,hreg64);
  263. location_reset(l,LOC_REGISTER,dst_size);
  264. l.registerlow:=hregister;
  265. l.registerhigh:=hregisterhi;
  266. end;
  267. end
  268. else
  269. begin
  270. { transformations to 32bit or smaller }
  271. if l.loc=LOC_REGISTER then
  272. begin
  273. { if the previous was 64bit release the high register }
  274. if l.size in [OS_64,OS_S64] then
  275. begin
  276. rg.ungetregisterint(list,l.registerhigh);
  277. l.registerhigh:=R_NO;
  278. end;
  279. hregister:=l.register;
  280. end
  281. else
  282. begin
  283. { get new register }
  284. if (l.loc=LOC_CREGISTER) and
  285. maybeconst and
  286. (TCGSize2Size[dst_size]=TCGSize2Size[l.size]) then
  287. hregister:=l.register
  288. else
  289. hregister:=rg.getregisterint(list);
  290. end;
  291. hregister:=rg.makeregsize(hregister,dst_size);
  292. { load value in new register }
  293. case l.loc of
  294. LOC_FLAGS :
  295. cg.g_flags2reg(list,l.resflags,hregister);
  296. LOC_JUMP :
  297. begin
  298. cg.a_label(list,truelabel);
  299. cg.a_load_const_reg(list,dst_size,1,hregister);
  300. getlabel(hl);
  301. cg.a_jmp_always(list,hl);
  302. cg.a_label(list,falselabel);
  303. cg.a_load_const_reg(list,dst_size,0,hregister);
  304. cg.a_label(list,hl);
  305. end;
  306. else
  307. begin
  308. { load_loc_reg can only handle size >= l.size, when the
  309. new size is smaller then we need to adjust the size
  310. of the orignal and maybe recalculate l.register for i386 }
  311. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  312. begin
  313. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  314. l.register:=rg.makeregsize(l.register,dst_size);
  315. l.size:=dst_size;
  316. end;
  317. cg.a_load_loc_reg(list,l,hregister);
  318. end;
  319. end;
  320. location_reset(l,LOC_REGISTER,dst_size);
  321. l.register:=hregister;
  322. end;
  323. end;
  324. { 64-bit version }
  325. procedure location_force_reg64(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  326. var
  327. hregister : tregister;
  328. hl : tasmlabel;
  329. begin
  330. { handle transformations to 64bit separate }
  331. if dst_size in [OS_64,OS_S64] then
  332. begin
  333. { load a smaller size to OS_64 }
  334. if l.loc=LOC_REGISTER then
  335. hregister:=rg.makeregsize(l.register,OS_INT)
  336. else
  337. hregister:=rg.getregisterint(list);
  338. { load value in low register }
  339. case l.loc of
  340. LOC_FLAGS :
  341. cg.g_flags2reg(list,l.resflags,hregister);
  342. LOC_JUMP :
  343. begin
  344. cg.a_label(list,truelabel);
  345. cg.a_load_const_reg(list,OS_INT,1,hregister);
  346. getlabel(hl);
  347. cg.a_jmp_always(list,hl);
  348. cg.a_label(list,falselabel);
  349. cg.a_load_const_reg(list,OS_INT,0,hregister);
  350. cg.a_label(list,hl);
  351. end;
  352. else
  353. cg.a_load_loc_reg(list,l,hregister);
  354. end;
  355. location_reset(l,LOC_REGISTER,dst_size);
  356. l.register:=hregister;
  357. end
  358. else
  359. begin
  360. { transformations to 32bit or smaller }
  361. if l.loc=LOC_REGISTER then
  362. begin
  363. hregister:=l.register;
  364. end
  365. else
  366. begin
  367. { get new register }
  368. if (l.loc=LOC_CREGISTER) and
  369. maybeconst and
  370. (TCGSize2Size[dst_size]=TCGSize2Size[l.size]) then
  371. hregister:=l.register
  372. else
  373. hregister:=rg.getregisterint(list);
  374. end;
  375. hregister:=rg.makeregsize(hregister,dst_size);
  376. { load value in new register }
  377. case l.loc of
  378. LOC_FLAGS :
  379. cg.g_flags2reg(list,l.resflags,hregister);
  380. LOC_JUMP :
  381. begin
  382. cg.a_label(list,truelabel);
  383. cg.a_load_const_reg(list,dst_size,1,hregister);
  384. getlabel(hl);
  385. cg.a_jmp_always(list,hl);
  386. cg.a_label(list,falselabel);
  387. cg.a_load_const_reg(list,dst_size,0,hregister);
  388. cg.a_label(list,hl);
  389. end;
  390. else
  391. begin
  392. { load_loc_reg can only handle size >= l.size, when the
  393. new size is smaller then we need to adjust the size
  394. of the orignal and maybe recalculate l.register for i386 }
  395. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  396. begin
  397. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  398. l.register:=rg.makeregsize(l.register,dst_size);
  399. l.size:=dst_size;
  400. end;
  401. cg.a_load_loc_reg(list,l,hregister);
  402. end;
  403. end;
  404. location_reset(l,LOC_REGISTER,dst_size);
  405. l.register:=hregister;
  406. end;
  407. end;
  408. procedure location_force_reg(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  409. begin
  410. { release previous location before demanding a new register }
  411. if (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  412. begin
  413. location_freetemp(list,l);
  414. location_release(list,l);
  415. end;
  416. if sizeof(aword) < 8 then
  417. location_force_reg32(list, l, dst_size, maybeconst)
  418. else
  419. location_force_reg64(list, l, dst_size, maybeconst);
  420. end;
  421. procedure location_force_mem(list: TAAsmoutput;var l:tlocation);
  422. var
  423. r : treference;
  424. begin
  425. case l.loc of
  426. LOC_FPUREGISTER,
  427. LOC_CFPUREGISTER :
  428. begin
  429. tg.gettempofsizereference(list,TCGSize2Size[l.size],r);
  430. cg.a_loadfpu_reg_ref(list,l.size,l.register,r);
  431. location_reset(l,LOC_REFERENCE,l.size);
  432. l.reference:=r;
  433. end;
  434. LOC_CONSTANT,
  435. LOC_REGISTER,
  436. LOC_CREGISTER :
  437. begin
  438. tg.gettempofsizereference(list,TCGSize2Size[l.size],r);
  439. if l.size in [OS_64,OS_S64] then
  440. cg64.a_load64_loc_ref(list,l,r)
  441. else
  442. cg.a_load_loc_ref(list,l,r);
  443. location_reset(l,LOC_REFERENCE,l.size);
  444. l.reference:=r;
  445. end;
  446. LOC_CREFERENCE,
  447. LOC_REFERENCE : ;
  448. else
  449. internalerror(200203219);
  450. end;
  451. end;
  452. {*****************************************************************************
  453. Maybe_Save
  454. *****************************************************************************}
  455. procedure maybe_save(list:taasmoutput;needed:integer;var l:tlocation;var s:tmaybesave);
  456. begin
  457. s.saved:=false;
  458. if l.loc=LOC_CREGISTER then
  459. begin
  460. s.saved:=true;
  461. exit;
  462. end;
  463. if needed>rg.countunusedregsint then
  464. begin
  465. case l.loc of
  466. LOC_REGISTER :
  467. begin
  468. if l.size in [OS_64,OS_S64] then
  469. begin
  470. tg.gettempofsizereference(exprasmlist,8,s.ref);
  471. cg64.a_load64_reg_ref(exprasmlist,joinreg64(l.registerlow,l.registerhigh),s.ref);
  472. end
  473. else
  474. begin
  475. tg.gettempofsizereference(exprasmlist,TCGSize2Size[l.size],s.ref);
  476. cg.a_load_reg_ref(exprasmlist,l.size,l.register,s.ref);
  477. end;
  478. location_release(exprasmlist,l);
  479. s.saved:=true;
  480. end;
  481. LOC_REFERENCE,
  482. LOC_CREFERENCE :
  483. begin
  484. if ((l.reference.base<>R_NO) or
  485. (l.reference.index<>R_NO)) then
  486. begin
  487. { load address into a single base register }
  488. cg.a_loadaddr_ref_reg(list,l.reference,l.reference.base);
  489. { save base register }
  490. tg.gettempofsizereference(exprasmlist,TCGSize2Size[OS_ADDR],s.ref);
  491. cg.a_load_reg_ref(exprasmlist,OS_ADDR,l.reference.base,s.ref);
  492. { release }
  493. location_release(exprasmlist,l);
  494. s.saved:=true;
  495. end;
  496. end;
  497. end;
  498. end;
  499. end;
  500. procedure maybe_restore(list:taasmoutput;var l:tlocation;const s:tmaybesave);
  501. begin
  502. if not s.saved then
  503. exit;
  504. if l.loc=LOC_CREGISTER then
  505. begin
  506. load_regvar_reg(list,l.register);
  507. exit;
  508. end;
  509. case l.loc of
  510. LOC_REGISTER :
  511. begin
  512. if l.size in [OS_64,OS_S64] then
  513. begin
  514. l.registerlow:=rg.getregisterint(exprasmlist);
  515. l.registerhigh:=rg.getregisterint(exprasmlist);
  516. cg64.a_load64_ref_reg(exprasmlist,s.ref,joinreg64(l.registerlow,l.registerhigh));
  517. end
  518. else
  519. begin
  520. l.register:=rg.getregisterint(exprasmlist);
  521. cg.a_load_ref_reg(exprasmlist,OS_INT,s.ref,l.register);
  522. end;
  523. end;
  524. LOC_CREFERENCE,
  525. LOC_REFERENCE :
  526. begin
  527. reference_reset(l.reference);
  528. l.reference.base:=rg.getaddressregister(exprasmlist);
  529. cg.a_load_ref_reg(exprasmlist,OS_ADDR,s.ref,l.reference.base);
  530. end;
  531. end;
  532. tg.ungetiftemp(exprasmlist,s.ref);
  533. end;
  534. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  535. begin
  536. if needed>=maxfpuregs then
  537. begin
  538. if l.loc = LOC_FPUREGISTER then
  539. begin
  540. location_force_mem(list,l);
  541. maybe_pushfpu:=true;
  542. end
  543. else
  544. maybe_pushfpu:=false;
  545. end
  546. else
  547. maybe_pushfpu:=false;
  548. end;
  549. {*****************************************************************************
  550. Push Value Para
  551. *****************************************************************************}
  552. procedure push_value_para(p:tnode;inlined,is_cdecl:boolean;
  553. para_offset:longint;alignment : longint;
  554. const locpara : tparalocation);
  555. var
  556. tempreference : treference;
  557. href : treference;
  558. hreg : tregister;
  559. sizetopush,
  560. size : longint;
  561. cgsize : tcgsize;
  562. begin
  563. { Move flags and jump in register to make it less complex }
  564. if p.location.loc in [LOC_FLAGS,LOC_JUMP] then
  565. location_force_reg(exprasmlist,p.location,def_cgsize(p.resulttype.def),false);
  566. { Handle Floating point types differently }
  567. if p.resulttype.def.deftype=floatdef then
  568. begin
  569. case p.location.loc of
  570. LOC_FPUREGISTER,
  571. LOC_CFPUREGISTER:
  572. begin
  573. size:=align(tfloatdef(p.resulttype.def).size,alignment);
  574. inc(pushedparasize,size);
  575. if not inlined then
  576. cg.a_op_const_reg(exprasmlist,OP_SUB,size,STACK_POINTER_REG);
  577. {$ifdef GDB}
  578. if (cs_debuginfo in aktmoduleswitches) and
  579. (exprasmList.first=exprasmList.last) then
  580. exprasmList.concat(Tai_force_line.Create);
  581. {$endif GDB}
  582. { this is the easiest case for inlined !! }
  583. if inlined then
  584. reference_reset_base(href,procinfo^.framepointer,para_offset-pushedparasize)
  585. else
  586. reference_reset_base(href,stack_pointer_reg,0);
  587. cg.a_loadfpu_reg_ref(exprasmlist,
  588. def_cgsize(p.resulttype.def),p.location.register,href);
  589. end;
  590. LOC_REFERENCE,
  591. LOC_CREFERENCE :
  592. begin
  593. sizetopush:=align(p.resulttype.def.size,alignment);
  594. tempreference:=p.location.reference;
  595. inc(tempreference.offset,sizetopush);
  596. while (sizetopush>0) do
  597. begin
  598. if sizetopush>=4 then
  599. begin
  600. cgsize:=OS_32;
  601. inc(pushedparasize,4);
  602. dec(tempreference.offset,4);
  603. dec(sizetopush,4);
  604. end
  605. else
  606. begin
  607. cgsize:=OS_16;
  608. inc(pushedparasize,2);
  609. dec(tempreference.offset,2);
  610. dec(sizetopush,2);
  611. end;
  612. if inlined then
  613. begin
  614. reference_reset_base(href,procinfo^.framepointer,para_offset-pushedparasize);
  615. cg.a_load_ref_ref(exprasmlist,cgsize,tempreference,href);
  616. end
  617. else
  618. cg.a_param_ref(exprasmlist,cgsize,tempreference,locpara);
  619. end;
  620. end;
  621. else
  622. internalerror(200204243);
  623. end;
  624. end
  625. else
  626. begin
  627. { call by value open array ? }
  628. if is_cdecl and
  629. push_addr_param(p.resulttype.def) then
  630. begin
  631. if not (p.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  632. internalerror(200204241);
  633. { push on stack }
  634. size:=align(p.resulttype.def.size,alignment);
  635. inc(pushedparasize,size);
  636. cg.a_op_const_reg(exprasmlist,OP_SUB,size,STACK_POINTER_REG);
  637. reference_reset_base(href,STACK_POINTER_REG,0);
  638. cg.g_concatcopy(exprasmlist,p.location.reference,href,size,false,false);
  639. end
  640. else
  641. begin
  642. case p.location.loc of
  643. LOC_CONSTANT,
  644. LOC_REGISTER,
  645. LOC_CREGISTER,
  646. LOC_REFERENCE,
  647. LOC_CREFERENCE :
  648. begin
  649. cgsize:=def_cgsize(p.resulttype.def);
  650. if cgsize in [OS_64,OS_S64] then
  651. begin
  652. inc(pushedparasize,8);
  653. if inlined then
  654. begin
  655. reference_reset_base(href,procinfo^.framepointer,para_offset-pushedparasize);
  656. cg64.a_load64_loc_ref(exprasmlist,p.location,href);
  657. end
  658. else
  659. cg64.a_param64_loc(exprasmlist,p.location,locpara);
  660. end
  661. else
  662. begin
  663. case cgsize of
  664. OS_8,OS_S8 :
  665. begin
  666. if alignment=4 then
  667. cgsize:=OS_32
  668. else
  669. cgsize:=OS_16;
  670. end;
  671. OS_16,OS_S16 :
  672. begin
  673. if alignment=4 then
  674. cgsize:=OS_32;
  675. end;
  676. end;
  677. { update register to use to match alignment }
  678. if p.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  679. begin
  680. hreg:=p.location.register;
  681. p.location.register:=rg.makeregsize(p.location.register,cgsize);
  682. end;
  683. inc(pushedparasize,alignment);
  684. if inlined then
  685. begin
  686. reference_reset_base(href,procinfo^.framepointer,para_offset-pushedparasize);
  687. cg.a_load_loc_ref(exprasmlist,p.location,href);
  688. end
  689. else
  690. cg.a_param_loc(exprasmlist,p.location,locpara);
  691. { restore old register }
  692. if p.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  693. p.location.register:=hreg;
  694. end;
  695. location_release(exprasmlist,p.location);
  696. end;
  697. {$ifdef SUPPORT_MMX}
  698. LOC_MMXREGISTER,
  699. LOC_CMMXREGISTER:
  700. begin
  701. inc(pushedparasize,8);
  702. if inlined then
  703. begin
  704. reference_reset_base(href,procinfo^.framepointer,para_offset-pushedparasize);
  705. cg.a_loadmm_reg_ref(exprasmlist,p.location.register,href);
  706. end
  707. else
  708. cg.a_parammm_reg(exprasmlist,p.location.register);
  709. end;
  710. {$endif SUPPORT_MMX}
  711. else
  712. internalerror(200204241);
  713. end;
  714. end;
  715. end;
  716. end;
  717. {****************************************************************************
  718. Entry/Exit Code
  719. ****************************************************************************}
  720. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  721. var
  722. href1,href2 : treference;
  723. list : taasmoutput;
  724. begin
  725. list:=taasmoutput(arg);
  726. if (tsym(p).typ=varsym) and
  727. (tvarsym(p).varspez=vs_value) and
  728. (push_addr_param(tvarsym(p).vartype.def)) then
  729. begin
  730. reference_reset_base(href1,procinfo^.framepointer,tvarsym(p).address+procinfo^.para_offset);
  731. if is_open_array(tvarsym(p).vartype.def) or
  732. is_array_of_const(tvarsym(p).vartype.def) then
  733. cg.g_copyvaluepara_openarray(list,href1,tarraydef(tvarsym(p).vartype.def).elesize)
  734. else
  735. begin
  736. reference_reset_base(href2,procinfo^.framepointer,-tvarsym(p).localvarsym.address+tvarsym(p).localvarsym.owner.address_fixup);
  737. if is_shortstring(tvarsym(p).vartype.def) then
  738. cg.g_copyshortstring(list,href1,href2,tstringdef(tvarsym(p).vartype.def).len,false,true)
  739. else
  740. cg.g_concatcopy(list,href1,href2,tvarsym(p).vartype.def.size,true,true);
  741. end;
  742. end;
  743. end;
  744. procedure initialize_threadvar(p : tnamedindexitem;arg:pointer);
  745. var
  746. href : treference;
  747. list : taasmoutput;
  748. begin
  749. list:=taasmoutput(arg);
  750. if (tsym(p).typ=varsym) and
  751. (vo_is_thread_var in tvarsym(p).varoptions) then
  752. begin
  753. cg.a_param_const(list,OS_INT,tvarsym(p).getsize,getintparaloc(2));
  754. reference_reset_symbol(href,newasmsymbol(tvarsym(p).mangledname),0);
  755. cg.a_paramaddr_ref(list,href,getintparaloc(1));
  756. rg.saveregvars(list,all_registers);
  757. cg.a_call_name(list,'FPC_INIT_THREADVAR');
  758. end;
  759. end;
  760. { generates the code for initialisation of local data }
  761. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  762. var
  763. href : treference;
  764. list : taasmoutput;
  765. begin
  766. list:=taasmoutput(arg);
  767. if (tsym(p).typ=varsym) and
  768. assigned(tvarsym(p).vartype.def) and
  769. not(is_class(tvarsym(p).vartype.def)) and
  770. tvarsym(p).vartype.def.needs_inittable then
  771. begin
  772. if assigned(procinfo) then
  773. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  774. if tsym(p).owner.symtabletype in [localsymtable,inlinelocalsymtable] then
  775. reference_reset_base(href,procinfo^.framepointer,-tvarsym(p).address+tvarsym(p).owner.address_fixup)
  776. else
  777. reference_reset_symbol(href,newasmsymbol(tvarsym(p).mangledname),0);
  778. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  779. end;
  780. end;
  781. { generates the code for finalisation of local data }
  782. procedure finalize_data(p : tnamedindexitem;arg:pointer);
  783. var
  784. href : treference;
  785. list : taasmoutput;
  786. begin
  787. list:=taasmoutput(arg);
  788. if (tsym(p).typ=varsym) and
  789. assigned(tvarsym(p).vartype.def) and
  790. not(is_class(tvarsym(p).vartype.def)) and
  791. tvarsym(p).vartype.def.needs_inittable then
  792. begin
  793. if tsym(p).owner.symtabletype in [localsymtable,inlinelocalsymtable] then
  794. reference_reset_base(href,procinfo^.framepointer,-tvarsym(p).address+tvarsym(p).owner.address_fixup)
  795. else
  796. reference_reset_symbol(href,newasmsymbol(tvarsym(p).mangledname),0);
  797. cg.g_finalize(list,tvarsym(p).vartype.def,href,false);
  798. end;
  799. end;
  800. { generates the code for incrementing the reference count of parameters and
  801. initialize out parameters }
  802. procedure init_paras(p : tnamedindexitem;arg:pointer);
  803. var
  804. href : treference;
  805. tmpreg : tregister;
  806. list : taasmoutput;
  807. begin
  808. list:=taasmoutput(arg);
  809. if (tsym(p).typ=varsym) and
  810. not is_class(tvarsym(p).vartype.def) and
  811. tvarsym(p).vartype.def.needs_inittable then
  812. begin
  813. case tvarsym(p).varspez of
  814. vs_value :
  815. begin
  816. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  817. if assigned(tvarsym(p).localvarsym) then
  818. reference_reset_base(href,procinfo^.framepointer,
  819. -tvarsym(p).localvarsym.address+tvarsym(p).localvarsym.owner.address_fixup)
  820. else
  821. reference_reset_base(href,procinfo^.framepointer,tvarsym(p).address+procinfo^.para_offset);
  822. cg.g_incrrefcount(list,tvarsym(p).vartype.def,href);
  823. end;
  824. vs_out :
  825. begin
  826. reference_reset_base(href,procinfo^.framepointer,tvarsym(p).address+procinfo^.para_offset);
  827. tmpreg:=cg.get_scratch_reg_address(list);
  828. cg.a_load_ref_reg(list,OS_ADDR,href,tmpreg);
  829. reference_reset_base(href,tmpreg,0);
  830. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  831. cg.free_scratch_reg(list,tmpreg);
  832. end;
  833. end;
  834. end;
  835. end;
  836. { generates the code for decrementing the reference count of parameters }
  837. procedure final_paras(p : tnamedindexitem;arg:pointer);
  838. var
  839. href : treference;
  840. list : taasmoutput;
  841. begin
  842. list:=taasmoutput(arg);
  843. if (tsym(p).typ=varsym) and
  844. not is_class(tvarsym(p).vartype.def) and
  845. tvarsym(p).vartype.def.needs_inittable then
  846. begin
  847. if (tvarsym(p).varspez=vs_value) then
  848. begin
  849. if assigned(tvarsym(p).localvarsym) then
  850. reference_reset_base(href,procinfo^.framepointer,
  851. -tvarsym(p).localvarsym.address+tvarsym(p).localvarsym.owner.address_fixup)
  852. else
  853. reference_reset_base(href,procinfo^.framepointer,tvarsym(p).address+procinfo^.para_offset);
  854. cg.g_decrrefcount(list,tvarsym(p).vartype.def,href);
  855. end;
  856. end;
  857. end;
  858. { Initialize temp ansi/widestrings,interfaces }
  859. procedure inittempvariables(list:taasmoutput);
  860. var
  861. hp : ptemprecord;
  862. href : treference;
  863. begin
  864. hp:=tg.templist;
  865. while assigned(hp) do
  866. begin
  867. if hp^.temptype in [tt_ansistring,tt_freeansistring,
  868. tt_widestring,tt_freewidestring,
  869. tt_interfacecom] then
  870. begin
  871. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  872. reference_reset_base(href,procinfo^.framepointer,hp^.pos);
  873. cg.a_load_const_ref(list,OS_ADDR,0,href);
  874. end;
  875. hp:=hp^.next;
  876. end;
  877. end;
  878. procedure finalizetempvariables(list:taasmoutput);
  879. var
  880. hp : ptemprecord;
  881. href : treference;
  882. begin
  883. hp:=tg.templist;
  884. while assigned(hp) do
  885. begin
  886. case hp^.temptype of
  887. tt_ansistring,
  888. tt_freeansistring :
  889. begin
  890. reference_reset_base(href,procinfo^.framepointer,hp^.pos);
  891. cg.a_paramaddr_ref(list,href,getintparaloc(1));
  892. cg.a_call_name(list,'FPC_ANSISTR_DECR_REF');
  893. end;
  894. tt_widestring,
  895. tt_freewidestring :
  896. begin
  897. reference_reset_base(href,procinfo^.framepointer,hp^.pos);
  898. cg.a_paramaddr_ref(list,href,getintparaloc(2));
  899. cg.a_call_name(list,'FPC_WIDESTR_DECR_REF');
  900. end;
  901. tt_interfacecom :
  902. begin
  903. reference_reset_base(href,procinfo^.framepointer,hp^.pos);
  904. cg.a_paramaddr_ref(list,href,getintparaloc(2));
  905. cg.a_call_name(list,'FPC_INTF_DECR_REF');
  906. end;
  907. end;
  908. hp:=hp^.next;
  909. end;
  910. end;
  911. procedure handle_return_value(list:TAAsmoutput; inlined : boolean;var uses_acc,uses_acchi : boolean);
  912. var
  913. href : treference;
  914. hreg : tregister;
  915. cgsize : TCGSize;
  916. begin
  917. if not is_void(aktprocdef.rettype.def) then
  918. begin
  919. if (tfuncretsym(aktprocdef.funcretsym).funcretstate<>vs_assigned) and
  920. (not inlined) then
  921. CGMessage(sym_w_function_result_not_set);
  922. reference_reset_base(href,procinfo^.framepointer,procinfo^.return_offset);
  923. cgsize:=def_cgsize(aktprocdef.rettype.def);
  924. case aktprocdef.rettype.def.deftype of
  925. orddef,
  926. enumdef :
  927. begin
  928. uses_acc:=true;
  929. cg.a_reg_alloc(list,accumulator);
  930. if cgsize in [OS_64,OS_S64] then
  931. begin
  932. uses_acchi:=true;
  933. cg.a_reg_alloc(list,accumulatorhigh);
  934. cg64.a_load64_ref_reg(list,href,joinreg64(accumulator,accumulatorhigh));
  935. end
  936. else
  937. begin
  938. hreg:=rg.makeregsize(accumulator,cgsize);
  939. cg.a_load_ref_reg(list,cgsize,href,hreg);
  940. end;
  941. end;
  942. floatdef :
  943. begin
  944. cg.a_loadfpu_ref_reg(list,cgsize,href,fpuresultreg);
  945. end;
  946. else
  947. begin
  948. if ret_in_acc(aktprocdef.rettype.def) then
  949. begin
  950. uses_acc:=true;
  951. cg.a_reg_alloc(list,accumulator);
  952. cg.a_load_ref_reg(list,cgsize,href,accumulator);
  953. end
  954. end;
  955. end;
  956. end;
  957. end;
  958. procedure handle_fast_exit_return_value(list:TAAsmoutput);
  959. var
  960. href : treference;
  961. hreg : tregister;
  962. cgsize : TCGSize;
  963. begin
  964. if not is_void(aktprocdef.rettype.def) then
  965. begin
  966. reference_reset_base(href,procinfo^.framepointer,procinfo^.return_offset);
  967. cgsize:=def_cgsize(aktprocdef.rettype.def);
  968. case aktprocdef.rettype.def.deftype of
  969. orddef,
  970. enumdef :
  971. begin
  972. if cgsize in [OS_64,OS_S64] then
  973. cg64.a_load64_reg_ref(list,joinreg64(accumulator,accumulatorhigh),href)
  974. else
  975. begin
  976. hreg:=rg.makeregsize(accumulator,cgsize);
  977. cg.a_load_reg_ref(list,cgsize,hreg,href);
  978. end;
  979. end;
  980. floatdef :
  981. begin
  982. cg.a_loadfpu_reg_ref(list,cgsize,fpuresultreg,href);
  983. end;
  984. else
  985. begin
  986. if ret_in_acc(aktprocdef.rettype.def) then
  987. cg.a_load_reg_ref(list,cgsize,accumulator,href);
  988. end;
  989. end;
  990. end;
  991. end;
  992. procedure genentrycode(list : TAAsmoutput;
  993. make_global:boolean;
  994. stackframe:longint;
  995. var parasize:longint;var nostackframe:boolean;
  996. inlined : boolean);
  997. var
  998. hs : string;
  999. href : treference;
  1000. p : tsymtable;
  1001. tempbuf : treference;
  1002. tmpreg : tregister;
  1003. begin
  1004. { Insert alignment and assembler names }
  1005. if not inlined then
  1006. begin
  1007. { Align, gprof uses 16 byte granularity }
  1008. if (cs_profile in aktmoduleswitches) then
  1009. list.concat(Tai_align.Create_op(16,$90))
  1010. else
  1011. list.concat(Tai_align.Create(aktalignment.procalign));
  1012. if (cs_profile in aktmoduleswitches) or
  1013. (aktprocdef.owner.symtabletype=globalsymtable) or
  1014. (assigned(procinfo^._class) and (procinfo^._class.owner.symtabletype=globalsymtable)) then
  1015. make_global:=true;
  1016. if make_global or ((procinfo^.flags and pi_is_global) <> 0) then
  1017. aktprocsym.is_global := True;
  1018. {$ifdef GDB}
  1019. if (cs_debuginfo in aktmoduleswitches) then
  1020. begin
  1021. aktprocdef.concatstabto(list);
  1022. aktprocsym.isstabwritten:=true;
  1023. end;
  1024. {$endif GDB}
  1025. repeat
  1026. hs:=aktprocdef.aliasnames.getfirst;
  1027. if hs='' then
  1028. break;
  1029. {$ifdef GDB}
  1030. if (cs_debuginfo in aktmoduleswitches) and
  1031. target_info.use_function_relative_addresses then
  1032. list.concat(Tai_stab_function_name.Create(strpnew(hs)));
  1033. {$endif GDB}
  1034. if make_global then
  1035. list.concat(Tai_symbol.Createname_global(hs,0))
  1036. else
  1037. list.concat(Tai_symbol.Createname(hs,0));
  1038. until false;
  1039. { omit stack frame ? }
  1040. if (procinfo^.framepointer=STACK_POINTER_REG) then
  1041. begin
  1042. CGMessage(cg_d_stackframe_omited);
  1043. nostackframe:=true;
  1044. if (aktprocdef.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  1045. parasize:=0
  1046. else
  1047. parasize:=aktprocdef.parast.datasize+procinfo^.para_offset-4;
  1048. if stackframe<>0 then
  1049. cg.a_op_const_reg(list,OP_SUB,stackframe,procinfo^.framepointer);
  1050. end
  1051. else
  1052. begin
  1053. nostackframe:=false;
  1054. if (aktprocdef.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  1055. parasize:=0
  1056. else
  1057. parasize:=aktprocdef.parast.datasize+procinfo^.para_offset-target_info.first_parm_offset;
  1058. if (po_interrupt in aktprocdef.procoptions) then
  1059. cg.g_interrupt_stackframe_entry(list);
  1060. cg.g_stackframe_entry(list,stackframe);
  1061. if (cs_check_stack in aktlocalswitches) then
  1062. cg.g_stackcheck(list,stackframe);
  1063. end;
  1064. if (cs_profile in aktmoduleswitches) and
  1065. not(po_assembler in aktprocdef.procoptions) then
  1066. cg.g_profilecode(list);
  1067. end;
  1068. { for the save all registers we can simply use a pusha,popa which
  1069. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1070. if (po_saveregisters in aktprocdef.procoptions) then
  1071. cg.g_save_all_registers(list)
  1072. else
  1073. { should we save edi,esi,ebx like C ? }
  1074. if (po_savestdregs in aktprocdef.procoptions) then
  1075. cg.g_save_standard_registers(list);
  1076. { a constructor needs a help procedure }
  1077. if (aktprocdef.proctypeoption=potype_constructor) then
  1078. cg.g_call_constructor_helper(list);
  1079. { don't load ESI, does the caller }
  1080. { we must do it for local function }
  1081. { that can be called from a foreach_static }
  1082. { of another object than self !! PM }
  1083. if assigned(procinfo^._class) and { !!!!! shouldn't we load ESI always? }
  1084. (lexlevel>normal_function_level) then
  1085. cg.g_maybe_loadself(list);
  1086. { When message method contains self as a parameter,
  1087. we must load it into ESI }
  1088. If (po_containsself in aktprocdef.procoptions) then
  1089. begin
  1090. list.concat(tai_regalloc.Alloc(self_pointer_reg));
  1091. reference_reset_base(href,procinfo^.framepointer,procinfo^.selfpointer_offset);
  1092. cg.a_load_ref_reg(list,OS_ADDR,href,self_pointer_reg);
  1093. end;
  1094. { initialize return value }
  1095. if (not is_void(aktprocdef.rettype.def)) and
  1096. (aktprocdef.rettype.def.needs_inittable) then
  1097. begin
  1098. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  1099. reference_reset_base(href,procinfo^.framepointer,procinfo^.return_offset);
  1100. cg.g_initialize(list,aktprocdef.rettype.def,href,ret_in_param(aktprocdef.rettype.def));
  1101. end;
  1102. { initialisize local data like ansistrings }
  1103. case aktprocdef.proctypeoption of
  1104. potype_unitinit:
  1105. begin
  1106. { using current_module.globalsymtable is hopefully }
  1107. { more robust than symtablestack and symtablestack.next }
  1108. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1109. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1110. end;
  1111. { units have seperate code for initilization and finalization }
  1112. potype_unitfinalize: ;
  1113. else
  1114. aktprocdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1115. end;
  1116. { initialisizes temp. ansi/wide string data }
  1117. inittempvariables(list);
  1118. { generate copies of call by value parameters }
  1119. if not(po_assembler in aktprocdef.procoptions) and
  1120. not(aktprocdef.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_palmossyscall,pocall_system]) then
  1121. aktprocdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1122. if assigned( aktprocdef.parast) then
  1123. aktprocdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1124. if (not inlined) then
  1125. begin
  1126. { call startup helpers from main program }
  1127. if (aktprocdef.proctypeoption=potype_proginit) then
  1128. begin
  1129. { initialize profiling for win32 }
  1130. if (target_info.target in [target_I386_WIN32,target_I386_wdosx]) and
  1131. (cs_profile in aktmoduleswitches) then
  1132. cg.a_call_name(list,'__monstartup');
  1133. { add local threadvars in units (only if needed because not all platforms
  1134. have threadvar support) }
  1135. if have_local_threadvars then
  1136. cg.a_call_name(list,'FPC_INITIALIZELOCALTHREADVARS');
  1137. { add global threadvars }
  1138. p:=symtablestack;
  1139. while assigned(p) do
  1140. begin
  1141. p.foreach_static({$ifndef TP}@{$endif}initialize_threadvar,list);
  1142. p:=p.next;
  1143. end;
  1144. { initialize units }
  1145. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1146. end;
  1147. { do we need an exception frame because of ansi/widestrings/interfaces ? }
  1148. if ((procinfo^.flags and pi_needs_implicit_finally)<>0) and
  1149. { but it's useless in init/final code of units }
  1150. not(aktprocdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) then
  1151. begin
  1152. include(rg.usedinproc,accumulator);
  1153. { allocate exception frame buffer }
  1154. cg.a_op_const_reg(list,OP_SUB,36,STACK_POINTER_REG);
  1155. tmpreg:=rg.getaddressregister(list);
  1156. cg.a_load_reg_reg(list,OS_ADDR,STACK_POINTER_REG,tmpreg);
  1157. reference_reset_base(tempbuf,tmpreg,0);
  1158. cg.g_push_exception(list,tempbuf,1,aktexitlabel);
  1159. reference_release(list,tempbuf);
  1160. { probably we've to reload self here }
  1161. cg.g_maybe_loadself(list);
  1162. end;
  1163. {$ifdef GDB}
  1164. if (cs_debuginfo in aktmoduleswitches) then
  1165. list.concat(Tai_force_line.Create);
  1166. {$endif GDB}
  1167. end;
  1168. if inlined then
  1169. load_regvars(list,nil);
  1170. end;
  1171. procedure genexitcode(list : TAAsmoutput;parasize:longint;nostackframe,inlined:boolean);
  1172. var
  1173. {$ifdef GDB}
  1174. stabsendlabel : tasmlabel;
  1175. mangled_length : longint;
  1176. p : pchar;
  1177. st : string[2];
  1178. {$endif GDB}
  1179. okexitlabel,
  1180. noreraiselabel,nodestroycall : tasmlabel;
  1181. tmpreg : tregister;
  1182. href : treference;
  1183. usesacc,
  1184. usesacchi,
  1185. usesself : boolean;
  1186. pd : tprocdef;
  1187. begin
  1188. if aktexit2label.is_used and
  1189. ((procinfo^.flags and (pi_needs_implicit_finally or pi_uses_exceptions)) <> 0) then
  1190. begin
  1191. cg.a_jmp_always(list,aktexitlabel);
  1192. cg.a_label(list,aktexit2label);
  1193. handle_fast_exit_return_value(list);
  1194. end;
  1195. if aktexitlabel.is_used then
  1196. list.concat(Tai_label.Create(aktexitlabel));
  1197. cleanup_regvars(list);
  1198. { call the destructor help procedure }
  1199. if (aktprocdef.proctypeoption=potype_destructor) and
  1200. assigned(procinfo^._class) then
  1201. cg.g_call_destructor_helper(list);
  1202. { finalize temporary data }
  1203. finalizetempvariables(list);
  1204. { finalize local data like ansistrings}
  1205. case aktprocdef.proctypeoption of
  1206. potype_unitfinalize:
  1207. begin
  1208. { using current_module.globalsymtable is hopefully }
  1209. { more robust than symtablestack and symtablestack.next }
  1210. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1211. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1212. end;
  1213. { units have seperate code for initialization and finalization }
  1214. potype_unitinit: ;
  1215. else
  1216. aktprocdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1217. end;
  1218. { finalize paras data }
  1219. if assigned(aktprocdef.parast) then
  1220. aktprocdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1221. { do we need to handle exceptions because of ansi/widestrings ? }
  1222. if not inlined and
  1223. ((procinfo^.flags and pi_needs_implicit_finally)<>0) and
  1224. { but it's useless in init/final code of units }
  1225. not(aktprocdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) then
  1226. begin
  1227. { the exception helper routines modify all registers }
  1228. aktprocdef.usedregisters:=all_registers;
  1229. getlabel(noreraiselabel);
  1230. cg.g_pop_exception(list,noreraiselabel);
  1231. if (aktprocdef.proctypeoption=potype_constructor) then
  1232. begin
  1233. if assigned(procinfo^._class) then
  1234. begin
  1235. pd:=procinfo^._class.searchdestructor;
  1236. if assigned(pd) then
  1237. begin
  1238. getlabel(nodestroycall);
  1239. reference_reset_base(href,procinfo^.framepointer,procinfo^.selfpointer_offset);
  1240. cg.a_cmp_const_ref_label(list,OS_ADDR,OC_EQ,0,href,nodestroycall);
  1241. if is_class(procinfo^._class) then
  1242. begin
  1243. cg.a_param_const(list,OS_INT,1,getintparaloc(2));
  1244. cg.a_param_reg(list,OS_ADDR,self_pointer_reg,getintparaloc(1));
  1245. end
  1246. else if is_object(procinfo^._class) then
  1247. begin
  1248. cg.a_param_reg(list,OS_ADDR,self_pointer_reg,getintparaloc(2));
  1249. reference_reset_symbol(href,newasmsymbol(procinfo^._class.vmt_mangledname),0);
  1250. cg.a_paramaddr_ref(list,href,getintparaloc(1));
  1251. end
  1252. else
  1253. Internalerror(200006164);
  1254. if (po_virtualmethod in pd.procoptions) then
  1255. begin
  1256. reference_reset_base(href,self_pointer_reg,0);
  1257. tmpreg:=cg.get_scratch_reg_address(list);
  1258. cg.a_load_ref_reg(list,OS_ADDR,href,tmpreg);
  1259. reference_reset_base(href,tmpreg,procinfo^._class.vmtmethodoffset(pd.extnumber));
  1260. cg.free_scratch_reg(list,tmpreg);
  1261. cg.a_call_ref(list,href);
  1262. end
  1263. else
  1264. cg.a_call_name(list,pd.mangledname);
  1265. { not necessary because the result is never assigned in the
  1266. case of an exception (FK) }
  1267. cg.a_label(list,nodestroycall);
  1268. end;
  1269. end
  1270. end
  1271. else
  1272. begin
  1273. { no constructor }
  1274. { must be the return value finalized before reraising the exception? }
  1275. if (not is_void(aktprocdef.rettype.def)) and
  1276. (aktprocdef.rettype.def.needs_inittable) and
  1277. ((aktprocdef.rettype.def.deftype<>objectdef) or
  1278. not is_class(aktprocdef.rettype.def)) then
  1279. begin
  1280. reference_reset_base(href,procinfo^.framepointer,procinfo^.return_offset);
  1281. cg.g_finalize(list,aktprocdef.rettype.def,href,ret_in_param(aktprocdef.rettype.def));
  1282. end;
  1283. end;
  1284. cg.a_call_name(list,'FPC_RERAISE');
  1285. cg.a_label(list,noreraiselabel);
  1286. end;
  1287. { call __EXIT for main program }
  1288. if (not DLLsource) and
  1289. (not inlined) and
  1290. (aktprocdef.proctypeoption=potype_proginit) then
  1291. cg.a_call_name(list,'FPC_DO_EXIT');
  1292. { handle return value, this is not done for assembler routines when
  1293. they didn't reference the result variable }
  1294. usesacc:=false;
  1295. usesacchi:=false;
  1296. usesself:=false;
  1297. if not(po_assembler in aktprocdef.procoptions) or
  1298. (assigned(aktprocdef.funcretsym) and
  1299. (tfuncretsym(aktprocdef.funcretsym).refcount>1)) then
  1300. begin
  1301. if (aktprocdef.proctypeoption<>potype_constructor) then
  1302. handle_return_value(list,inlined,usesacc,usesacchi)
  1303. else
  1304. begin
  1305. { successful constructor deletes the zero flag }
  1306. { and returns self in eax }
  1307. { eax must be set to zero if the allocation failed !!! }
  1308. getlabel(okexitlabel);
  1309. cg.a_jmp_always(list,okexitlabel);
  1310. cg.a_label(list,faillabel);
  1311. cg.g_call_fail_helper(list);
  1312. cg.a_label(list,okexitlabel);
  1313. { for classes this is done after the call to }
  1314. { AfterConstruction }
  1315. if is_object(procinfo^._class) then
  1316. begin
  1317. cg.a_reg_alloc(list,accumulator);
  1318. cg.a_load_reg_reg(list,OS_ADDR,self_pointer_reg,accumulator);
  1319. usesacc:=true;
  1320. end;
  1321. {$ifdef i386}
  1322. list.concat(taicpu.op_reg_reg(A_TEST,S_L,R_ESI,R_ESI));
  1323. {$else}
  1324. {$warning constructor returns in flags for i386}
  1325. {$endif i386}
  1326. usesself:=true;
  1327. end;
  1328. end;
  1329. if aktexit2label.is_used and not aktexit2label.is_set then
  1330. cg.a_label(list,aktexit2label);
  1331. {$ifdef GDB}
  1332. if ((cs_debuginfo in aktmoduleswitches) and not inlined) then
  1333. begin
  1334. getlabel(stabsendlabel);
  1335. cg.a_label(list,stabsendlabel);
  1336. end;
  1337. {$endif GDB}
  1338. { for the save all registers we can simply use a pusha,popa which
  1339. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1340. if (po_saveregisters in aktprocdef.procoptions) then
  1341. cg.g_restore_all_registers(list,usesself,usesacc,usesacchi)
  1342. else
  1343. { should we restore edi ? }
  1344. if (po_savestdregs in aktprocdef.procoptions) then
  1345. cg.g_restore_standard_registers(list);
  1346. { remove stackframe }
  1347. if not inlined then
  1348. begin
  1349. if (not nostackframe) then
  1350. cg.g_restore_frame_pointer(list)
  1351. else
  1352. if (tg.gettempsize<>0) then
  1353. cg.a_op_const_reg(list,OP_ADD,tg.gettempsize,STACK_POINTER_REG);
  1354. end;
  1355. { at last, the return is generated }
  1356. if not inlined then
  1357. begin
  1358. if (po_interrupt in aktprocdef.procoptions) then
  1359. cg.g_interrupt_stackframe_exit(list,usesself,usesacc,usesacchi)
  1360. else
  1361. cg.g_return_from_proc(list,parasize);
  1362. end;
  1363. if not inlined then
  1364. list.concat(Tai_symbol_end.Createname(aktprocdef.mangledname));
  1365. {$ifdef GDB}
  1366. if (cs_debuginfo in aktmoduleswitches) and not inlined then
  1367. begin
  1368. if assigned(procinfo^._class) then
  1369. if (not assigned(procinfo^.parent) or
  1370. not assigned(procinfo^.parent^._class)) then
  1371. begin
  1372. if (po_classmethod in aktprocdef.procoptions) or
  1373. ((po_virtualmethod in aktprocdef.procoptions) and
  1374. (potype_constructor=aktprocdef.proctypeoption)) or
  1375. (po_staticmethod in aktprocdef.procoptions) then
  1376. begin
  1377. list.concat(Tai_stabs.Create(strpnew(
  1378. '"pvmt:p'+tstoreddef(pvmttype.def).numberstring+'",'+
  1379. tostr(N_tsym)+',0,0,'+tostr(procinfo^.selfpointer_offset))));
  1380. end
  1381. else
  1382. begin
  1383. if not(is_class(procinfo^._class)) then
  1384. st:='v'
  1385. else
  1386. st:='p';
  1387. list.concat(Tai_stabs.Create(strpnew(
  1388. '"$t:'+st+procinfo^._class.numberstring+'",'+
  1389. tostr(N_tsym)+',0,0,'+tostr(procinfo^.selfpointer_offset))));
  1390. end;
  1391. end
  1392. else
  1393. begin
  1394. if not is_class(procinfo^._class) then
  1395. st:='*'
  1396. else
  1397. st:='';
  1398. list.concat(Tai_stabs.Create(strpnew(
  1399. '"$t:r'+st+procinfo^._class.numberstring+'",'+
  1400. tostr(N_RSYM)+',0,0,'+tostr(GDB_i386index[SELF_POINTER_REG]))));
  1401. end;
  1402. { define calling EBP as pseudo local var PM }
  1403. { this enables test if the function is a local one !! }
  1404. if assigned(procinfo^.parent) and (lexlevel>normal_function_level) then
  1405. list.concat(Tai_stabs.Create(strpnew(
  1406. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1407. tostr(N_LSYM)+',0,0,'+tostr(procinfo^.framepointer_offset))));
  1408. if (not is_void(aktprocdef.rettype.def)) then
  1409. begin
  1410. if ret_in_param(aktprocdef.rettype.def) then
  1411. list.concat(Tai_stabs.Create(strpnew(
  1412. '"'+aktprocsym.name+':X*'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1413. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))))
  1414. else
  1415. list.concat(Tai_stabs.Create(strpnew(
  1416. '"'+aktprocsym.name+':X'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1417. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))));
  1418. if (m_result in aktmodeswitches) then
  1419. if ret_in_param(aktprocdef.rettype.def) then
  1420. list.concat(Tai_stabs.Create(strpnew(
  1421. '"RESULT:X*'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1422. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))))
  1423. else
  1424. list.concat(Tai_stabs.Create(strpnew(
  1425. '"RESULT:X'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1426. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))));
  1427. end;
  1428. mangled_length:=length(aktprocdef.mangledname);
  1429. getmem(p,2*mangled_length+50);
  1430. strpcopy(p,'192,0,0,');
  1431. strpcopy(strend(p),aktprocdef.mangledname);
  1432. if (target_info.use_function_relative_addresses) then
  1433. begin
  1434. strpcopy(strend(p),'-');
  1435. strpcopy(strend(p),aktprocdef.mangledname);
  1436. end;
  1437. list.concat(Tai_stabn.Create(strnew(p)));
  1438. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1439. +aktprocdef.mangledname))));
  1440. p[0]:='2';p[1]:='2';p[2]:='4';
  1441. strpcopy(strend(p),'_end');}
  1442. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1443. if (target_info.use_function_relative_addresses) then
  1444. begin
  1445. strpcopy(strend(p),'-');
  1446. strpcopy(strend(p),aktprocdef.mangledname);
  1447. end;
  1448. list.concatlist(withdebuglist);
  1449. list.concat(Tai_stabn.Create(strnew(p)));
  1450. { strpnew('224,0,0,'
  1451. +aktprocdef.mangledname+'_end'))));}
  1452. freemem(p,2*mangled_length+50);
  1453. end;
  1454. {$endif GDB}
  1455. if inlined then
  1456. cleanup_regvars(list);
  1457. end;
  1458. procedure genimplicitunitinit(list : TAAsmoutput);
  1459. begin
  1460. { using current_module.globalsymtable is hopefully }
  1461. { more robust than symtablestack and symtablestack.next }
  1462. tsymtable(current_module.globalsymtable).foreach_static({$ifdef FPCPROCVAR}@{$endif}finalize_data,list);
  1463. tsymtable(current_module.localsymtable).foreach_static({$ifdef FPCPROCVAR}@{$endif}finalize_data,list);
  1464. list.insert(Tai_symbol.Createname_global('INIT$$'+current_module.modulename^,0));
  1465. list.insert(Tai_symbol.Createname_global(target_info.cprefix+current_module.modulename^+'_init',0));
  1466. {$ifdef GDB}
  1467. if (cs_debuginfo in aktmoduleswitches) and
  1468. target_info.use_function_relative_addresses then
  1469. list.insert(Tai_stab_function_name.Create(strpnew('INIT$$'+current_module.modulename^)));
  1470. {$endif GDB}
  1471. cg.g_return_from_proc(list,0);
  1472. end;
  1473. procedure genimplicitunitfinal(list : TAAsmoutput);
  1474. begin
  1475. { using current_module.globalsymtable is hopefully }
  1476. { more robust than symtablestack and symtablestack.next }
  1477. tsymtable(current_module.globalsymtable).foreach_static({$ifdef FPCPROCVAR}@{$endif}finalize_data,list);
  1478. tsymtable(current_module.localsymtable).foreach_static({$ifdef FPCPROCVAR}@{$endif}finalize_data,list);
  1479. list.insert(Tai_symbol.Createname_global('FINALIZE$$'+current_module.modulename^,0));
  1480. list.insert(Tai_symbol.Createname_global(target_info.cprefix+current_module.modulename^+'_finalize',0));
  1481. {$ifdef GDB}
  1482. if (cs_debuginfo in aktmoduleswitches) and
  1483. target_info.use_function_relative_addresses then
  1484. list.insert(Tai_stab_function_name.Create(strpnew('FINALIZE$$'+current_module.modulename^)));
  1485. {$endif GDB}
  1486. cg.g_return_from_proc(list,0);
  1487. end;
  1488. end.
  1489. {
  1490. $Log$
  1491. Revision 1.20 2002-07-07 09:52:32 florian
  1492. * powerpc target fixed, very simple units can be compiled
  1493. * some basic stuff for better callparanode handling, far from being finished
  1494. Revision 1.19 2002/07/01 18:46:23 peter
  1495. * internal linker
  1496. * reorganized aasm layer
  1497. Revision 1.18 2002/07/01 16:23:53 peter
  1498. * cg64 patch
  1499. * basics for currency
  1500. * asnode updates for class and interface (not finished)
  1501. Revision 1.17 2002/05/20 13:30:40 carl
  1502. * bugfix of hdisponen (base must be set, not index)
  1503. * more portability fixes
  1504. Revision 1.16 2002/05/18 13:34:09 peter
  1505. * readded missing revisions
  1506. Revision 1.15 2002/05/16 19:46:37 carl
  1507. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1508. + try to fix temp allocation (still in ifdef)
  1509. + generic constructor calls
  1510. + start of tassembler / tmodulebase class cleanup
  1511. Revision 1.13 2002/05/13 19:54:37 peter
  1512. * removed n386ld and n386util units
  1513. * maybe_save/maybe_restore added instead of the old maybe_push
  1514. Revision 1.12 2002/05/12 19:58:36 carl
  1515. * some small portability fixes
  1516. Revision 1.11 2002/05/12 16:53:07 peter
  1517. * moved entry and exitcode to ncgutil and cgobj
  1518. * foreach gets extra argument for passing local data to the
  1519. iterator function
  1520. * -CR checks also class typecasts at runtime by changing them
  1521. into as
  1522. * fixed compiler to cycle with the -CR option
  1523. * fixed stabs with elf writer, finally the global variables can
  1524. be watched
  1525. * removed a lot of routines from cga unit and replaced them by
  1526. calls to cgobj
  1527. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1528. u32bit then the other is typecasted also to u32bit without giving
  1529. a rangecheck warning/error.
  1530. * fixed pascal calling method with reversing also the high tree in
  1531. the parast, detected by tcalcst3 test
  1532. Revision 1.10 2002/04/21 19:02:03 peter
  1533. * removed newn and disposen nodes, the code is now directly
  1534. inlined from pexpr
  1535. * -an option that will write the secondpass nodes to the .s file, this
  1536. requires EXTDEBUG define to actually write the info
  1537. * fixed various internal errors and crashes due recent code changes
  1538. Revision 1.9 2002/04/21 15:24:38 carl
  1539. + a_jmp_cond -> a_jmp_always (a_jmp_cond is NOT portable)
  1540. + changeregsize -> rg.makeregsize
  1541. Revision 1.8 2002/04/19 15:39:34 peter
  1542. * removed some more routines from cga
  1543. * moved location_force_reg/mem to ncgutil
  1544. * moved arrayconstructnode secondpass to ncgld
  1545. Revision 1.7 2002/04/15 18:58:47 carl
  1546. + target_info.size_of_pointer -> pointer_Size
  1547. Revision 1.6 2002/04/06 18:10:42 jonas
  1548. * several powerpc-related additions and fixes
  1549. Revision 1.5 2002/04/04 19:05:57 peter
  1550. * removed unused units
  1551. * use tlocation.size in cg.a_*loc*() routines
  1552. Revision 1.4 2002/04/02 17:11:28 peter
  1553. * tlocation,treference update
  1554. * LOC_CONSTANT added for better constant handling
  1555. * secondadd splitted in multiple routines
  1556. * location_force_reg added for loading a location to a register
  1557. of a specified size
  1558. * secondassignment parses now first the right and then the left node
  1559. (this is compatible with Kylix). This saves a lot of push/pop especially
  1560. with string operations
  1561. * adapted some routines to use the new cg methods
  1562. Revision 1.3 2002/03/31 20:26:34 jonas
  1563. + a_loadfpu_* and a_loadmm_* methods in tcg
  1564. * register allocation is now handled by a class and is mostly processor
  1565. independent (+rgobj.pas and i386/rgcpu.pas)
  1566. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1567. * some small improvements and fixes to the optimizer
  1568. * some register allocation fixes
  1569. * some fpuvaroffset fixes in the unary minus node
  1570. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1571. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1572. also better optimizable)
  1573. * fixed and optimized register saving/restoring for new/dispose nodes
  1574. * LOC_FPU locations now also require their "register" field to be set to
  1575. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1576. - list field removed of the tnode class because it's not used currently
  1577. and can cause hard-to-find bugs
  1578. Revision 1.2 2002/03/04 19:10:11 peter
  1579. * removed compiler warnings
  1580. }