ncgutil.pas 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Helper routines for all code generators
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncgutil;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,
  23. cpubase,cpupara,
  24. aasmbase,aasmtai,aasmcpu,
  25. cginfo,
  26. rgobj;
  27. type
  28. tloadregvars = (lr_dont_load_regvars, lr_load_regvars);
  29. tmaybesave = record
  30. saved : boolean;
  31. ref : treference;
  32. end;
  33. procedure firstcomplex(p : tbinarynode);
  34. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  35. procedure remove_non_regvars_from_loc(const t: tlocation; var regs: tregisterset);
  36. procedure location_force_reg(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  37. procedure location_force_mem(list: TAAsmoutput;var l:tlocation);
  38. procedure maybe_save(list:taasmoutput;needed:integer;var l:tlocation;var s:tmaybesave);
  39. procedure maybe_restore(list:taasmoutput;var l:tlocation;const s:tmaybesave);
  40. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  41. procedure push_value_para(p:tnode;inlined,is_cdecl:boolean;
  42. para_offset:longint;alignment : longint;
  43. const locpara : tparalocation);
  44. procedure genentrycode(list : TAAsmoutput;
  45. make_global:boolean;
  46. stackframe:longint;
  47. var parasize:longint;var nostackframe:boolean;
  48. inlined : boolean);
  49. procedure genexitcode(list : TAAsmoutput;parasize:longint;nostackframe,inlined:boolean);
  50. procedure genimplicitunitinit(list : TAAsmoutput);
  51. procedure genimplicitunitfinal(list : TAAsmoutput);
  52. implementation
  53. uses
  54. {$ifdef Delphi}
  55. Sysutils,
  56. {$else}
  57. strings,
  58. {$endif}
  59. cutils,cclasses,globtype,globals,systems,verbose,
  60. symbase,symconst,symtype,symsym,symdef,symtable,types,
  61. fmodule,
  62. cgbase,regvars,
  63. {$ifdef GDB}
  64. gdb,
  65. {$endif GDB}
  66. ncon,
  67. tgobj,cpuinfo,cgobj,cgcpu,cg64f32;
  68. {*****************************************************************************
  69. Misc Helpers
  70. *****************************************************************************}
  71. { DO NOT RELY on the fact that the tnode is not yet swaped
  72. because of inlining code PM }
  73. procedure firstcomplex(p : tbinarynode);
  74. var
  75. hp : tnode;
  76. begin
  77. { always calculate boolean AND and OR from left to right }
  78. if (p.nodetype in [orn,andn]) and
  79. (p.left.resulttype.def.deftype=orddef) and
  80. (torddef(p.left.resulttype.def).typ in [bool8bit,bool16bit,bool32bit]) then
  81. begin
  82. { p.swaped:=false}
  83. if nf_swaped in p.flags then
  84. internalerror(234234);
  85. end
  86. else
  87. if (((p.location.loc=LOC_FPUREGISTER) and
  88. (p.right.registersfpu > p.left.registersfpu)) or
  89. ((((p.left.registersfpu = 0) and
  90. (p.right.registersfpu = 0)) or
  91. (p.location.loc<>LOC_FPUREGISTER)) and
  92. (p.left.registers32<p.right.registers32))) and
  93. { the following check is appropriate, because all }
  94. { 4 registers are rarely used and it is thereby }
  95. { achieved that the extra code is being dropped }
  96. { by exchanging not commutative operators }
  97. (p.right.registers32<=c_countusableregsint) then
  98. begin
  99. hp:=p.left;
  100. p.left:=p.right;
  101. p.right:=hp;
  102. if nf_swaped in p.flags then
  103. exclude(p.flags,nf_swaped)
  104. else
  105. include(p.flags,nf_swaped);
  106. end;
  107. end;
  108. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  109. {
  110. produces jumps to true respectively false labels using boolean expressions
  111. depending on whether the loading of regvars is currently being
  112. synchronized manually (such as in an if-node) or automatically (most of
  113. the other cases where this procedure is called), loadregvars can be
  114. "lr_load_regvars" or "lr_dont_load_regvars"
  115. }
  116. var
  117. opsize : tcgsize;
  118. storepos : tfileposinfo;
  119. begin
  120. if nf_error in p.flags then
  121. exit;
  122. storepos:=aktfilepos;
  123. aktfilepos:=p.fileinfo;
  124. if is_boolean(p.resulttype.def) then
  125. begin
  126. if loadregvars = lr_load_regvars then
  127. load_all_regvars(list);
  128. if is_constboolnode(p) then
  129. begin
  130. if tordconstnode(p).value<>0 then
  131. cg.a_jmp_always(list,truelabel)
  132. else
  133. cg.a_jmp_always(list,falselabel)
  134. end
  135. else
  136. begin
  137. opsize:=def_cgsize(p.resulttype.def);
  138. case p.location.loc of
  139. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  140. begin
  141. if (p.location.loc = LOC_CREGISTER) then
  142. load_regvar_reg(list,p.location.register);
  143. cg.a_cmp_const_loc_label(list,opsize,OC_NE,
  144. 0,p.location,truelabel);
  145. { !!! should happen right after cmp (JM) }
  146. location_release(list,p.location);
  147. cg.a_jmp_always(list,falselabel);
  148. end;
  149. LOC_FLAGS :
  150. begin
  151. cg.a_jmp_flags(list,p.location.resflags,
  152. truelabel);
  153. cg.a_jmp_always(list,falselabel);
  154. end;
  155. end;
  156. end;
  157. end
  158. else
  159. internalerror(200112305);
  160. aktfilepos:=storepos;
  161. end;
  162. procedure remove_non_regvars_from_loc(const t: tlocation; var regs: tregisterset);
  163. begin
  164. case t.loc of
  165. LOC_REGISTER:
  166. begin
  167. { can't be a regvar, since it would be LOC_CREGISTER then }
  168. exclude(regs,t.register);
  169. if t.registerhigh <> R_NO then
  170. exclude(regs,t.registerhigh);
  171. end;
  172. LOC_CREFERENCE,LOC_REFERENCE:
  173. begin
  174. if not(cs_regalloc in aktglobalswitches) or
  175. (t.reference.base in rg.usableregsint) then
  176. exclude(regs,t.reference.base);
  177. if not(cs_regalloc in aktglobalswitches) or
  178. (t.reference.index in rg.usableregsint) then
  179. exclude(regs,t.reference.index);
  180. end;
  181. end;
  182. end;
  183. {*****************************************************************************
  184. TLocation
  185. *****************************************************************************}
  186. { 32-bit version }
  187. procedure location_force_reg32(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  188. var
  189. hregister,
  190. hregisterhi : tregister;
  191. hreg64 : tregister64;
  192. hl : tasmlabel;
  193. begin
  194. { handle transformations to 64bit separate }
  195. if dst_size in [OS_64,OS_S64] then
  196. begin
  197. if not (l.size in [OS_64,OS_S64]) then
  198. begin
  199. { load a smaller size to OS_64 }
  200. if l.loc=LOC_REGISTER then
  201. hregister:=rg.makeregsize(l.registerlow,OS_INT)
  202. else
  203. hregister:=rg.getregisterint(list);
  204. { load value in low register }
  205. case l.loc of
  206. LOC_FLAGS :
  207. cg.g_flags2reg(list,l.resflags,hregister);
  208. LOC_JUMP :
  209. begin
  210. cg.a_label(list,truelabel);
  211. cg.a_load_const_reg(list,OS_INT,1,hregister);
  212. getlabel(hl);
  213. cg.a_jmp_always(list,hl);
  214. cg.a_label(list,falselabel);
  215. cg.a_load_const_reg(list,OS_INT,0,hregister);
  216. cg.a_label(list,hl);
  217. end;
  218. else
  219. cg.a_load_loc_reg(list,l,hregister);
  220. end;
  221. { reset hi part, take care of the signed bit of the current value }
  222. hregisterhi:=rg.getregisterint(list);
  223. if (dst_size=OS_S64) and
  224. (l.size in [OS_S8,OS_S16,OS_S32]) then
  225. begin
  226. if l.loc=LOC_CONSTANT then
  227. begin
  228. if (longint(l.value)<0) then
  229. cg.a_load_const_reg(list,OS_32,$ffffffff,hregisterhi)
  230. else
  231. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  232. end
  233. else
  234. begin
  235. cg.a_load_reg_reg(list,OS_32,hregister,hregisterhi);
  236. cg.a_op_const_reg(list,OP_SAR,31,hregisterhi);
  237. end;
  238. end
  239. else
  240. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  241. location_reset(l,LOC_REGISTER,dst_size);
  242. l.registerlow:=hregister;
  243. l.registerhigh:=hregisterhi;
  244. end
  245. else
  246. begin
  247. { 64bit to 64bit }
  248. if (l.loc=LOC_REGISTER) or
  249. ((l.loc=LOC_CREGISTER) and maybeconst) then
  250. begin
  251. hregister:=l.registerlow;
  252. hregisterhi:=l.registerhigh;
  253. end
  254. else
  255. begin
  256. hregister:=rg.getregisterint(list);
  257. hregisterhi:=rg.getregisterint(list);
  258. end;
  259. hreg64.reglo:=hregister;
  260. hreg64.reghi:=hregisterhi;
  261. { load value in new register }
  262. cg64.a_load64_loc_reg(list,l,hreg64);
  263. location_reset(l,LOC_REGISTER,dst_size);
  264. l.registerlow:=hregister;
  265. l.registerhigh:=hregisterhi;
  266. end;
  267. end
  268. else
  269. begin
  270. { transformations to 32bit or smaller }
  271. if l.loc=LOC_REGISTER then
  272. begin
  273. { if the previous was 64bit release the high register }
  274. if l.size in [OS_64,OS_S64] then
  275. begin
  276. rg.ungetregisterint(list,l.registerhigh);
  277. l.registerhigh:=R_NO;
  278. end;
  279. hregister:=l.register;
  280. end
  281. else
  282. begin
  283. { get new register }
  284. if (l.loc=LOC_CREGISTER) and
  285. maybeconst and
  286. (TCGSize2Size[dst_size]=TCGSize2Size[l.size]) then
  287. hregister:=l.register
  288. else
  289. hregister:=rg.getregisterint(list);
  290. end;
  291. hregister:=rg.makeregsize(hregister,dst_size);
  292. { load value in new register }
  293. case l.loc of
  294. LOC_FLAGS :
  295. cg.g_flags2reg(list,l.resflags,hregister);
  296. LOC_JUMP :
  297. begin
  298. cg.a_label(list,truelabel);
  299. cg.a_load_const_reg(list,dst_size,1,hregister);
  300. getlabel(hl);
  301. cg.a_jmp_always(list,hl);
  302. cg.a_label(list,falselabel);
  303. cg.a_load_const_reg(list,dst_size,0,hregister);
  304. cg.a_label(list,hl);
  305. end;
  306. else
  307. begin
  308. { load_loc_reg can only handle size >= l.size, when the
  309. new size is smaller then we need to adjust the size
  310. of the orignal and maybe recalculate l.register for i386 }
  311. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  312. begin
  313. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  314. l.register:=rg.makeregsize(l.register,dst_size);
  315. { 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. 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. (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,getintparaloc(2));
  768. reference_reset_symbol(href,newasmsymbol(tvarsym(p).mangledname),0);
  769. cg.a_paramaddr_ref(list,href,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,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,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,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 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 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,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,getintparaloc(2));
  1258. cg.a_param_reg(list,OS_ADDR,self_pointer_reg,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,getintparaloc(2));
  1263. reference_reset_symbol(href,newasmsymbol(procinfo^._class.vmt_mangledname),0);
  1264. cg.a_paramaddr_ref(list,href,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,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 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 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.21 2002-07-11 07:33:25 jonas
  1506. * big-endian fixes for location_force_reg*()
  1507. Revision 1.20 2002/07/07 09:52:32 florian
  1508. * powerpc target fixed, very simple units can be compiled
  1509. * some basic stuff for better callparanode handling, far from being finished
  1510. Revision 1.19 2002/07/01 18:46:23 peter
  1511. * internal linker
  1512. * reorganized aasm layer
  1513. Revision 1.18 2002/07/01 16:23:53 peter
  1514. * cg64 patch
  1515. * basics for currency
  1516. * asnode updates for class and interface (not finished)
  1517. Revision 1.17 2002/05/20 13:30:40 carl
  1518. * bugfix of hdisponen (base must be set, not index)
  1519. * more portability fixes
  1520. Revision 1.16 2002/05/18 13:34:09 peter
  1521. * readded missing revisions
  1522. Revision 1.15 2002/05/16 19:46:37 carl
  1523. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1524. + try to fix temp allocation (still in ifdef)
  1525. + generic constructor calls
  1526. + start of tassembler / tmodulebase class cleanup
  1527. Revision 1.13 2002/05/13 19:54:37 peter
  1528. * removed n386ld and n386util units
  1529. * maybe_save/maybe_restore added instead of the old maybe_push
  1530. Revision 1.12 2002/05/12 19:58:36 carl
  1531. * some small portability fixes
  1532. Revision 1.11 2002/05/12 16:53:07 peter
  1533. * moved entry and exitcode to ncgutil and cgobj
  1534. * foreach gets extra argument for passing local data to the
  1535. iterator function
  1536. * -CR checks also class typecasts at runtime by changing them
  1537. into as
  1538. * fixed compiler to cycle with the -CR option
  1539. * fixed stabs with elf writer, finally the global variables can
  1540. be watched
  1541. * removed a lot of routines from cga unit and replaced them by
  1542. calls to cgobj
  1543. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1544. u32bit then the other is typecasted also to u32bit without giving
  1545. a rangecheck warning/error.
  1546. * fixed pascal calling method with reversing also the high tree in
  1547. the parast, detected by tcalcst3 test
  1548. Revision 1.10 2002/04/21 19:02:03 peter
  1549. * removed newn and disposen nodes, the code is now directly
  1550. inlined from pexpr
  1551. * -an option that will write the secondpass nodes to the .s file, this
  1552. requires EXTDEBUG define to actually write the info
  1553. * fixed various internal errors and crashes due recent code changes
  1554. Revision 1.9 2002/04/21 15:24:38 carl
  1555. + a_jmp_cond -> a_jmp_always (a_jmp_cond is NOT portable)
  1556. + changeregsize -> rg.makeregsize
  1557. Revision 1.8 2002/04/19 15:39:34 peter
  1558. * removed some more routines from cga
  1559. * moved location_force_reg/mem to ncgutil
  1560. * moved arrayconstructnode secondpass to ncgld
  1561. Revision 1.7 2002/04/15 18:58:47 carl
  1562. + target_info.size_of_pointer -> pointer_Size
  1563. Revision 1.6 2002/04/06 18:10:42 jonas
  1564. * several powerpc-related additions and fixes
  1565. Revision 1.5 2002/04/04 19:05:57 peter
  1566. * removed unused units
  1567. * use tlocation.size in cg.a_*loc*() routines
  1568. Revision 1.4 2002/04/02 17:11:28 peter
  1569. * tlocation,treference update
  1570. * LOC_CONSTANT added for better constant handling
  1571. * secondadd splitted in multiple routines
  1572. * location_force_reg added for loading a location to a register
  1573. of a specified size
  1574. * secondassignment parses now first the right and then the left node
  1575. (this is compatible with Kylix). This saves a lot of push/pop especially
  1576. with string operations
  1577. * adapted some routines to use the new cg methods
  1578. Revision 1.3 2002/03/31 20:26:34 jonas
  1579. + a_loadfpu_* and a_loadmm_* methods in tcg
  1580. * register allocation is now handled by a class and is mostly processor
  1581. independent (+rgobj.pas and i386/rgcpu.pas)
  1582. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1583. * some small improvements and fixes to the optimizer
  1584. * some register allocation fixes
  1585. * some fpuvaroffset fixes in the unary minus node
  1586. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1587. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1588. also better optimizable)
  1589. * fixed and optimized register saving/restoring for new/dispose nodes
  1590. * LOC_FPU locations now also require their "register" field to be set to
  1591. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1592. - list field removed of the tnode class because it's not used currently
  1593. and can cause hard-to-find bugs
  1594. Revision 1.2 2002/03/04 19:10:11 peter
  1595. * removed compiler warnings
  1596. }