ncgutil.pas 68 KB

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