ncgutil.pas 69 KB

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