ncgutil.pas 68 KB

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