ncgutil.pas 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  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 genentrycode(list : TAAsmoutput;
  1006. make_global:boolean;
  1007. stackframe:longint;
  1008. var parasize:longint;var nostackframe:boolean;
  1009. inlined : boolean);
  1010. var
  1011. hs : string;
  1012. href : treference;
  1013. p : tsymtable;
  1014. tmpreg : tregister;
  1015. begin
  1016. { Insert alignment and assembler names }
  1017. if not inlined then
  1018. begin
  1019. { Align, gprof uses 16 byte granularity }
  1020. if (cs_profile in aktmoduleswitches) then
  1021. list.concat(Tai_align.Create_op(16,$90))
  1022. else
  1023. list.concat(Tai_align.Create(aktalignment.procalign));
  1024. if (cs_profile in aktmoduleswitches) or
  1025. (aktprocdef.owner.symtabletype=globalsymtable) or
  1026. (assigned(procinfo^._class) and (procinfo^._class.owner.symtabletype=globalsymtable)) then
  1027. make_global:=true;
  1028. if make_global or ((procinfo^.flags and pi_is_global) <> 0) then
  1029. aktprocsym.is_global := True;
  1030. {$ifdef GDB}
  1031. if (cs_debuginfo in aktmoduleswitches) then
  1032. begin
  1033. aktprocdef.concatstabto(list);
  1034. aktprocsym.isstabwritten:=true;
  1035. end;
  1036. {$endif GDB}
  1037. repeat
  1038. hs:=aktprocdef.aliasnames.getfirst;
  1039. if hs='' then
  1040. break;
  1041. {$ifdef GDB}
  1042. if (cs_debuginfo in aktmoduleswitches) and
  1043. target_info.use_function_relative_addresses then
  1044. list.concat(Tai_stab_function_name.Create(strpnew(hs)));
  1045. {$endif GDB}
  1046. if make_global then
  1047. list.concat(Tai_symbol.Createname_global(hs,0))
  1048. else
  1049. list.concat(Tai_symbol.Createname(hs,0));
  1050. until false;
  1051. {$ifdef i386}
  1052. { at least for the ppc this applies always, so this code isn't usable (FK) }
  1053. { omit stack frame ? }
  1054. if (procinfo^.framepointer=STACK_POINTER_REG) then
  1055. begin
  1056. CGMessage(cg_d_stackframe_omited);
  1057. nostackframe:=true;
  1058. if (aktprocdef.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  1059. parasize:=0
  1060. else
  1061. parasize:=aktprocdef.parast.datasize+procinfo^.para_offset-4;
  1062. if stackframe<>0 then
  1063. cg.a_op_const_reg(list,OP_SUB,stackframe,procinfo^.framepointer);
  1064. end
  1065. else
  1066. {$endif i386}
  1067. begin
  1068. nostackframe:=false;
  1069. if (aktprocdef.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  1070. parasize:=0
  1071. else
  1072. parasize:=aktprocdef.parast.datasize+procinfo^.para_offset-target_info.first_parm_offset;
  1073. if (po_interrupt in aktprocdef.procoptions) then
  1074. cg.g_interrupt_stackframe_entry(list);
  1075. cg.g_stackframe_entry(list,stackframe);
  1076. if (cs_check_stack in aktlocalswitches) then
  1077. cg.g_stackcheck(list,stackframe);
  1078. end;
  1079. if (cs_profile in aktmoduleswitches) and
  1080. not(po_assembler in aktprocdef.procoptions) then
  1081. cg.g_profilecode(list);
  1082. end;
  1083. { for the save all registers we can simply use a pusha,popa which
  1084. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1085. if (po_saveregisters in aktprocdef.procoptions) then
  1086. cg.g_save_all_registers(list)
  1087. else
  1088. { should we save edi,esi,ebx like C ? }
  1089. if (po_savestdregs in aktprocdef.procoptions) then
  1090. cg.g_save_standard_registers(list);
  1091. { a constructor needs a help procedure }
  1092. if (aktprocdef.proctypeoption=potype_constructor) then
  1093. cg.g_call_constructor_helper(list);
  1094. { don't load ESI, does the caller }
  1095. { we must do it for local function }
  1096. { that can be called from a foreach_static }
  1097. { of another object than self !! PM }
  1098. if assigned(procinfo^._class) and { !!!!! shouldn't we load ESI always? }
  1099. (lexlevel>normal_function_level) then
  1100. cg.g_maybe_loadself(list);
  1101. { When message method contains self as a parameter,
  1102. we must load it into ESI }
  1103. If (po_containsself in aktprocdef.procoptions) then
  1104. begin
  1105. list.concat(tai_regalloc.Alloc(self_pointer_reg));
  1106. reference_reset_base(href,procinfo^.framepointer,procinfo^.selfpointer_offset);
  1107. cg.a_load_ref_reg(list,OS_ADDR,href,self_pointer_reg);
  1108. end;
  1109. { initialize return value }
  1110. if (not is_void(aktprocdef.rettype.def)) and
  1111. (aktprocdef.rettype.def.needs_inittable) then
  1112. begin
  1113. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  1114. reference_reset_base(href,procinfo^.framepointer,procinfo^.return_offset);
  1115. cg.g_initialize(list,aktprocdef.rettype.def,href,paramanager.ret_in_param(aktprocdef.rettype.def));
  1116. end;
  1117. { initialisize local data like ansistrings }
  1118. case aktprocdef.proctypeoption of
  1119. potype_unitinit:
  1120. begin
  1121. { using current_module.globalsymtable is hopefully }
  1122. { more robust than symtablestack and symtablestack.next }
  1123. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1124. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1125. end;
  1126. { units have seperate code for initilization and finalization }
  1127. potype_unitfinalize: ;
  1128. else
  1129. aktprocdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1130. end;
  1131. { initialisizes temp. ansi/wide string data }
  1132. inittempvariables(list);
  1133. { generate copies of call by value parameters }
  1134. if not(po_assembler in aktprocdef.procoptions) and
  1135. not(aktprocdef.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_palmossyscall,pocall_system]) then
  1136. aktprocdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1137. if assigned( aktprocdef.parast) then
  1138. aktprocdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1139. if (not inlined) then
  1140. begin
  1141. { call startup helpers from main program }
  1142. if (aktprocdef.proctypeoption=potype_proginit) then
  1143. begin
  1144. { initialize profiling for win32 }
  1145. if (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1146. (cs_profile in aktmoduleswitches) then
  1147. cg.a_call_name(list,'__monstartup');
  1148. { add local threadvars in units (only if needed because not all platforms
  1149. have threadvar support) }
  1150. if have_local_threadvars then
  1151. cg.a_call_name(list,'FPC_INITIALIZELOCALTHREADVARS');
  1152. { add global threadvars }
  1153. p:=symtablestack;
  1154. while assigned(p) do
  1155. begin
  1156. p.foreach_static({$ifndef TP}@{$endif}initialize_threadvar,list);
  1157. p:=p.next;
  1158. end;
  1159. { initialize units }
  1160. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1161. end;
  1162. { do we need an exception frame because of ansi/widestrings/interfaces ? }
  1163. if ((procinfo^.flags and pi_needs_implicit_finally)<>0) and
  1164. { but it's useless in init/final code of units }
  1165. not(aktprocdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) then
  1166. begin
  1167. include(rg.usedinproc,accumulator);
  1168. cg.g_new_exception(list,procinfo^.exception_jmp_ref,
  1169. procinfo^.exception_env_ref,
  1170. procinfo^.exception_result_ref,1,aktexitlabel);
  1171. { probably we've to reload self here }
  1172. cg.g_maybe_loadself(list);
  1173. end;
  1174. {$ifdef GDB}
  1175. if (cs_debuginfo in aktmoduleswitches) then
  1176. list.concat(Tai_force_line.Create);
  1177. {$endif GDB}
  1178. end;
  1179. if inlined then
  1180. load_regvars(list,nil);
  1181. end;
  1182. procedure genexitcode(list : TAAsmoutput;parasize:longint;nostackframe,inlined:boolean);
  1183. var
  1184. {$ifdef GDB}
  1185. stabsendlabel : tasmlabel;
  1186. mangled_length : longint;
  1187. p : pchar;
  1188. st : string[2];
  1189. {$endif GDB}
  1190. okexitlabel,
  1191. noreraiselabel,nodestroycall : tasmlabel;
  1192. tmpreg : tregister;
  1193. href : treference;
  1194. usesacc,
  1195. usesacchi,
  1196. usesself : boolean;
  1197. pd : tprocdef;
  1198. begin
  1199. if aktexit2label.is_used and
  1200. ((procinfo^.flags and (pi_needs_implicit_finally or pi_uses_exceptions)) <> 0) then
  1201. begin
  1202. cg.a_jmp_always(list,aktexitlabel);
  1203. cg.a_label(list,aktexit2label);
  1204. handle_fast_exit_return_value(list);
  1205. end;
  1206. if aktexitlabel.is_used then
  1207. list.concat(Tai_label.Create(aktexitlabel));
  1208. cleanup_regvars(list);
  1209. { call the destructor help procedure }
  1210. if (aktprocdef.proctypeoption=potype_destructor) and
  1211. assigned(procinfo^._class) then
  1212. cg.g_call_destructor_helper(list);
  1213. { finalize temporary data }
  1214. finalizetempvariables(list);
  1215. { finalize local data like ansistrings}
  1216. case aktprocdef.proctypeoption of
  1217. potype_unitfinalize:
  1218. begin
  1219. { using current_module.globalsymtable is hopefully }
  1220. { more robust than symtablestack and symtablestack.next }
  1221. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1222. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1223. end;
  1224. { units have seperate code for initialization and finalization }
  1225. potype_unitinit: ;
  1226. else
  1227. aktprocdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1228. end;
  1229. { finalize paras data }
  1230. if assigned(aktprocdef.parast) then
  1231. aktprocdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1232. { do we need to handle exceptions because of ansi/widestrings ? }
  1233. if not inlined and
  1234. ((procinfo^.flags and pi_needs_implicit_finally)<>0) and
  1235. { but it's useless in init/final code of units }
  1236. not(aktprocdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) then
  1237. begin
  1238. { the exception helper routines modify all registers }
  1239. aktprocdef.usedregisters:=all_registers;
  1240. getlabel(noreraiselabel);
  1241. cg.g_free_exception(list,
  1242. procinfo^.exception_jmp_ref,
  1243. procinfo^.exception_env_ref,
  1244. procinfo^.exception_result_ref,0
  1245. ,noreraiselabel,false);
  1246. if (aktprocdef.proctypeoption=potype_constructor) then
  1247. begin
  1248. if assigned(procinfo^._class) then
  1249. begin
  1250. pd:=procinfo^._class.searchdestructor;
  1251. if assigned(pd) then
  1252. begin
  1253. getlabel(nodestroycall);
  1254. reference_reset_base(href,procinfo^.framepointer,procinfo^.selfpointer_offset);
  1255. cg.a_cmp_const_ref_label(list,OS_ADDR,OC_EQ,0,href,nodestroycall);
  1256. if is_class(procinfo^._class) then
  1257. begin
  1258. cg.a_param_const(list,OS_INT,1,paramanager.getintparaloc(2));
  1259. cg.a_param_reg(list,OS_ADDR,self_pointer_reg,paramanager.getintparaloc(1));
  1260. end
  1261. else if is_object(procinfo^._class) then
  1262. begin
  1263. cg.a_param_reg(list,OS_ADDR,self_pointer_reg,paramanager.getintparaloc(2));
  1264. reference_reset_symbol(href,newasmsymbol(procinfo^._class.vmt_mangledname),0);
  1265. cg.a_paramaddr_ref(list,href,paramanager.getintparaloc(1));
  1266. end
  1267. else
  1268. Internalerror(200006164);
  1269. if (po_virtualmethod in pd.procoptions) then
  1270. begin
  1271. reference_reset_base(href,self_pointer_reg,0);
  1272. tmpreg:=cg.get_scratch_reg_address(list);
  1273. cg.a_load_ref_reg(list,OS_ADDR,href,tmpreg);
  1274. reference_reset_base(href,tmpreg,procinfo^._class.vmtmethodoffset(pd.extnumber));
  1275. cg.free_scratch_reg(list,tmpreg);
  1276. cg.a_call_ref(list,href);
  1277. end
  1278. else
  1279. cg.a_call_name(list,pd.mangledname);
  1280. { not necessary because the result is never assigned in the
  1281. case of an exception (FK) }
  1282. cg.a_label(list,nodestroycall);
  1283. end;
  1284. end
  1285. end
  1286. else
  1287. begin
  1288. { no constructor }
  1289. { must be the return value finalized before reraising the exception? }
  1290. if (not is_void(aktprocdef.rettype.def)) and
  1291. (aktprocdef.rettype.def.needs_inittable) and
  1292. ((aktprocdef.rettype.def.deftype<>objectdef) or
  1293. not is_class(aktprocdef.rettype.def)) then
  1294. begin
  1295. reference_reset_base(href,procinfo^.framepointer,procinfo^.return_offset);
  1296. cg.g_finalize(list,aktprocdef.rettype.def,href,paramanager.ret_in_param(aktprocdef.rettype.def));
  1297. end;
  1298. end;
  1299. cg.a_call_name(list,'FPC_RERAISE');
  1300. cg.a_label(list,noreraiselabel);
  1301. end;
  1302. { call __EXIT for main program }
  1303. if (not DLLsource) and
  1304. (not inlined) and
  1305. (aktprocdef.proctypeoption=potype_proginit) then
  1306. cg.a_call_name(list,'FPC_DO_EXIT');
  1307. { handle return value, this is not done for assembler routines when
  1308. they didn't reference the result variable }
  1309. usesacc:=false;
  1310. usesacchi:=false;
  1311. usesself:=false;
  1312. if not(po_assembler in aktprocdef.procoptions) or
  1313. (assigned(aktprocdef.funcretsym) and
  1314. (tfuncretsym(aktprocdef.funcretsym).refcount>1)) then
  1315. begin
  1316. if (aktprocdef.proctypeoption<>potype_constructor) then
  1317. handle_return_value(list,inlined,usesacc,usesacchi)
  1318. else
  1319. begin
  1320. { successful constructor deletes the zero flag }
  1321. { and returns self in eax }
  1322. { eax must be set to zero if the allocation failed !!! }
  1323. getlabel(okexitlabel);
  1324. cg.a_jmp_always(list,okexitlabel);
  1325. cg.a_label(list,faillabel);
  1326. cg.g_call_fail_helper(list);
  1327. cg.a_label(list,okexitlabel);
  1328. { for classes this is done after the call to }
  1329. { AfterConstruction }
  1330. if is_object(procinfo^._class) then
  1331. begin
  1332. cg.a_reg_alloc(list,accumulator);
  1333. cg.a_load_reg_reg(list,OS_ADDR,self_pointer_reg,accumulator);
  1334. usesacc:=true;
  1335. end;
  1336. {$ifdef i386}
  1337. list.concat(taicpu.op_reg_reg(A_TEST,S_L,R_ESI,R_ESI));
  1338. {$else}
  1339. {$warning constructor returns in flags for i386}
  1340. {$endif i386}
  1341. usesself:=true;
  1342. end;
  1343. end;
  1344. if aktexit2label.is_used and not aktexit2label.is_set then
  1345. cg.a_label(list,aktexit2label);
  1346. {$ifdef GDB}
  1347. if ((cs_debuginfo in aktmoduleswitches) and not inlined) then
  1348. begin
  1349. getlabel(stabsendlabel);
  1350. cg.a_label(list,stabsendlabel);
  1351. end;
  1352. {$endif GDB}
  1353. { for the save all registers we can simply use a pusha,popa which
  1354. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1355. if (po_saveregisters in aktprocdef.procoptions) then
  1356. cg.g_restore_all_registers(list,usesself,usesacc,usesacchi)
  1357. else
  1358. { should we restore edi ? }
  1359. if (po_savestdregs in aktprocdef.procoptions) then
  1360. cg.g_restore_standard_registers(list);
  1361. { remove stackframe }
  1362. if not inlined then
  1363. begin
  1364. if (not nostackframe) then
  1365. cg.g_restore_frame_pointer(list)
  1366. else
  1367. if (tg.gettempsize<>0) then
  1368. cg.a_op_const_reg(list,OP_ADD,tg.gettempsize,STACK_POINTER_REG);
  1369. end;
  1370. { at last, the return is generated }
  1371. if not inlined then
  1372. begin
  1373. if (po_interrupt in aktprocdef.procoptions) then
  1374. cg.g_interrupt_stackframe_exit(list,usesself,usesacc,usesacchi)
  1375. else
  1376. cg.g_return_from_proc(list,parasize);
  1377. end;
  1378. if not inlined then
  1379. list.concat(Tai_symbol_end.Createname(aktprocdef.mangledname));
  1380. {$ifdef GDB}
  1381. if (cs_debuginfo in aktmoduleswitches) and not inlined then
  1382. begin
  1383. if assigned(procinfo^._class) then
  1384. if (not assigned(procinfo^.parent) or
  1385. not assigned(procinfo^.parent^._class)) then
  1386. begin
  1387. if (po_classmethod in aktprocdef.procoptions) or
  1388. ((po_virtualmethod in aktprocdef.procoptions) and
  1389. (potype_constructor=aktprocdef.proctypeoption)) or
  1390. (po_staticmethod in aktprocdef.procoptions) then
  1391. begin
  1392. list.concat(Tai_stabs.Create(strpnew(
  1393. '"pvmt:p'+tstoreddef(pvmttype.def).numberstring+'",'+
  1394. tostr(N_tsym)+',0,0,'+tostr(procinfo^.selfpointer_offset))));
  1395. end
  1396. else
  1397. begin
  1398. if not(is_class(procinfo^._class)) then
  1399. st:='v'
  1400. else
  1401. st:='p';
  1402. list.concat(Tai_stabs.Create(strpnew(
  1403. '"$t:'+st+procinfo^._class.numberstring+'",'+
  1404. tostr(N_tsym)+',0,0,'+tostr(procinfo^.selfpointer_offset))));
  1405. end;
  1406. end
  1407. else
  1408. begin
  1409. if not is_class(procinfo^._class) then
  1410. st:='*'
  1411. else
  1412. st:='';
  1413. list.concat(Tai_stabs.Create(strpnew(
  1414. '"$t:r'+st+procinfo^._class.numberstring+'",'+
  1415. tostr(N_RSYM)+',0,0,'+tostr(GDB_i386index[SELF_POINTER_REG]))));
  1416. end;
  1417. { define calling EBP as pseudo local var PM }
  1418. { this enables test if the function is a local one !! }
  1419. if assigned(procinfo^.parent) and (lexlevel>normal_function_level) then
  1420. list.concat(Tai_stabs.Create(strpnew(
  1421. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1422. tostr(N_LSYM)+',0,0,'+tostr(procinfo^.framepointer_offset))));
  1423. if (not is_void(aktprocdef.rettype.def)) then
  1424. begin
  1425. if paramanager.ret_in_param(aktprocdef.rettype.def) then
  1426. list.concat(Tai_stabs.Create(strpnew(
  1427. '"'+aktprocsym.name+':X*'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1428. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))))
  1429. else
  1430. list.concat(Tai_stabs.Create(strpnew(
  1431. '"'+aktprocsym.name+':X'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1432. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))));
  1433. if (m_result in aktmodeswitches) then
  1434. if paramanager.ret_in_param(aktprocdef.rettype.def) then
  1435. list.concat(Tai_stabs.Create(strpnew(
  1436. '"RESULT:X*'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1437. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))))
  1438. else
  1439. list.concat(Tai_stabs.Create(strpnew(
  1440. '"RESULT:X'+tstoreddef(aktprocdef.rettype.def).numberstring+'",'+
  1441. tostr(N_tsym)+',0,0,'+tostr(procinfo^.return_offset))));
  1442. end;
  1443. mangled_length:=length(aktprocdef.mangledname);
  1444. getmem(p,2*mangled_length+50);
  1445. strpcopy(p,'192,0,0,');
  1446. strpcopy(strend(p),aktprocdef.mangledname);
  1447. if (target_info.use_function_relative_addresses) then
  1448. begin
  1449. strpcopy(strend(p),'-');
  1450. strpcopy(strend(p),aktprocdef.mangledname);
  1451. end;
  1452. list.concat(Tai_stabn.Create(strnew(p)));
  1453. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1454. +aktprocdef.mangledname))));
  1455. p[0]:='2';p[1]:='2';p[2]:='4';
  1456. strpcopy(strend(p),'_end');}
  1457. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1458. if (target_info.use_function_relative_addresses) then
  1459. begin
  1460. strpcopy(strend(p),'-');
  1461. strpcopy(strend(p),aktprocdef.mangledname);
  1462. end;
  1463. list.concatlist(withdebuglist);
  1464. list.concat(Tai_stabn.Create(strnew(p)));
  1465. { strpnew('224,0,0,'
  1466. +aktprocdef.mangledname+'_end'))));}
  1467. freemem(p,2*mangled_length+50);
  1468. end;
  1469. {$endif GDB}
  1470. if inlined then
  1471. cleanup_regvars(list);
  1472. end;
  1473. procedure genimplicitunitinit(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('INIT$$'+current_module.modulename^,0));
  1480. list.insert(Tai_symbol.Createname_global(target_info.cprefix+current_module.modulename^+'_init',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('INIT$$'+current_module.modulename^)));
  1485. {$endif GDB}
  1486. cg.g_return_from_proc(list,0);
  1487. end;
  1488. procedure genimplicitunitfinal(list : TAAsmoutput);
  1489. begin
  1490. { using current_module.globalsymtable is hopefully }
  1491. { more robust than symtablestack and symtablestack.next }
  1492. tsymtable(current_module.globalsymtable).foreach_static({$ifdef FPCPROCVAR}@{$endif}finalize_data,list);
  1493. tsymtable(current_module.localsymtable).foreach_static({$ifdef FPCPROCVAR}@{$endif}finalize_data,list);
  1494. list.insert(Tai_symbol.Createname_global('FINALIZE$$'+current_module.modulename^,0));
  1495. list.insert(Tai_symbol.Createname_global(target_info.cprefix+current_module.modulename^+'_finalize',0));
  1496. {$ifdef GDB}
  1497. if (cs_debuginfo in aktmoduleswitches) and
  1498. target_info.use_function_relative_addresses then
  1499. list.insert(Tai_stab_function_name.Create(strpnew('FINALIZE$$'+current_module.modulename^)));
  1500. {$endif GDB}
  1501. cg.g_return_from_proc(list,0);
  1502. end;
  1503. end.
  1504. {
  1505. $Log$
  1506. Revision 1.30 2002-08-06 20:55:21 florian
  1507. * first part of ppc calling conventions fix
  1508. Revision 1.29 2002/08/04 19:09:22 carl
  1509. + added generic exception support (still does not work!)
  1510. + more documentation
  1511. Revision 1.28 2002/07/29 21:23:42 florian
  1512. * more fixes for the ppc
  1513. + wrappers for the tcnvnode.first_* stuff introduced
  1514. Revision 1.27 2002/07/28 15:59:57 jonas
  1515. * fixed bug in location_force_reg32() when converting smaller values to
  1516. 64 bit locations
  1517. * use cg.op_const_reg_reg() instead of a move and then cg.op_const_reg()
  1518. in location_force_reg32()
  1519. Revision 1.26 2002/07/27 19:53:51 jonas
  1520. + generic implementation of tcg.g_flags2ref()
  1521. * tcg.flags2xxx() now also needs a size parameter
  1522. Revision 1.25 2002/07/26 21:15:38 florian
  1523. * rewrote the system handling
  1524. Revision 1.24 2002/07/25 17:58:24 carl
  1525. + FPURESULTREG -> FPU_RESULT_REG
  1526. Revision 1.23 2002/07/20 11:57:54 florian
  1527. * types.pas renamed to defbase.pas because D6 contains a types
  1528. unit so this would conflicts if D6 programms are compiled
  1529. + Willamette/SSE2 instructions to assembler added
  1530. Revision 1.22 2002/07/11 14:41:28 florian
  1531. * start of the new generic parameter handling
  1532. Revision 1.21 2002/07/11 07:33:25 jonas
  1533. * big-endian fixes for location_force_reg*()
  1534. Revision 1.20 2002/07/07 09:52:32 florian
  1535. * powerpc target fixed, very simple units can be compiled
  1536. * some basic stuff for better callparanode handling, far from being finished
  1537. Revision 1.19 2002/07/01 18:46:23 peter
  1538. * internal linker
  1539. * reorganized aasm layer
  1540. Revision 1.18 2002/07/01 16:23:53 peter
  1541. * cg64 patch
  1542. * basics for currency
  1543. * asnode updates for class and interface (not finished)
  1544. Revision 1.17 2002/05/20 13:30:40 carl
  1545. * bugfix of hdisponen (base must be set, not index)
  1546. * more portability fixes
  1547. Revision 1.16 2002/05/18 13:34:09 peter
  1548. * readded missing revisions
  1549. Revision 1.15 2002/05/16 19:46:37 carl
  1550. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1551. + try to fix temp allocation (still in ifdef)
  1552. + generic constructor calls
  1553. + start of tassembler / tmodulebase class cleanup
  1554. Revision 1.13 2002/05/13 19:54:37 peter
  1555. * removed n386ld and n386util units
  1556. * maybe_save/maybe_restore added instead of the old maybe_push
  1557. Revision 1.12 2002/05/12 19:58:36 carl
  1558. * some small portability fixes
  1559. Revision 1.11 2002/05/12 16:53:07 peter
  1560. * moved entry and exitcode to ncgutil and cgobj
  1561. * foreach gets extra argument for passing local data to the
  1562. iterator function
  1563. * -CR checks also class typecasts at runtime by changing them
  1564. into as
  1565. * fixed compiler to cycle with the -CR option
  1566. * fixed stabs with elf writer, finally the global variables can
  1567. be watched
  1568. * removed a lot of routines from cga unit and replaced them by
  1569. calls to cgobj
  1570. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1571. u32bit then the other is typecasted also to u32bit without giving
  1572. a rangecheck warning/error.
  1573. * fixed pascal calling method with reversing also the high tree in
  1574. the parast, detected by tcalcst3 test
  1575. Revision 1.10 2002/04/21 19:02:03 peter
  1576. * removed newn and disposen nodes, the code is now directly
  1577. inlined from pexpr
  1578. * -an option that will write the secondpass nodes to the .s file, this
  1579. requires EXTDEBUG define to actually write the info
  1580. * fixed various internal errors and crashes due recent code changes
  1581. Revision 1.9 2002/04/21 15:24:38 carl
  1582. + a_jmp_cond -> a_jmp_always (a_jmp_cond is NOT portable)
  1583. + changeregsize -> rg.makeregsize
  1584. Revision 1.8 2002/04/19 15:39:34 peter
  1585. * removed some more routines from cga
  1586. * moved location_force_reg/mem to ncgutil
  1587. * moved arrayconstructnode secondpass to ncgld
  1588. Revision 1.7 2002/04/15 18:58:47 carl
  1589. + target_info.size_of_pointer -> pointer_Size
  1590. Revision 1.6 2002/04/06 18:10:42 jonas
  1591. * several powerpc-related additions and fixes
  1592. Revision 1.5 2002/04/04 19:05:57 peter
  1593. * removed unused units
  1594. * use tlocation.size in cg.a_*loc*() routines
  1595. Revision 1.4 2002/04/02 17:11:28 peter
  1596. * tlocation,treference update
  1597. * LOC_CONSTANT added for better constant handling
  1598. * secondadd splitted in multiple routines
  1599. * location_force_reg added for loading a location to a register
  1600. of a specified size
  1601. * secondassignment parses now first the right and then the left node
  1602. (this is compatible with Kylix). This saves a lot of push/pop especially
  1603. with string operations
  1604. * adapted some routines to use the new cg methods
  1605. Revision 1.3 2002/03/31 20:26:34 jonas
  1606. + a_loadfpu_* and a_loadmm_* methods in tcg
  1607. * register allocation is now handled by a class and is mostly processor
  1608. independent (+rgobj.pas and i386/rgcpu.pas)
  1609. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1610. * some small improvements and fixes to the optimizer
  1611. * some register allocation fixes
  1612. * some fpuvaroffset fixes in the unary minus node
  1613. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1614. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1615. also better optimizable)
  1616. * fixed and optimized register saving/restoring for new/dispose nodes
  1617. * LOC_FPU locations now also require their "register" field to be set to
  1618. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1619. - list field removed of the tnode class because it's not used currently
  1620. and can cause hard-to-find bugs
  1621. Revision 1.2 2002/03/04 19:10:11 peter
  1622. * removed compiler warnings
  1623. }