ncgcal.pas 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate assembler for call nodes
  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 ncgcal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. globtype,
  24. symdef,node,ncal;
  25. type
  26. tcgcallparanode = class(tcallparanode)
  27. private
  28. tempparaloc : tparalocation;
  29. procedure allocate_tempparaloc;
  30. procedure push_addr_para;
  31. procedure push_value_para;
  32. public
  33. procedure secondcallparan;override;
  34. end;
  35. tcgcallnode = class(tcallnode)
  36. private
  37. procedure release_para_temps;
  38. procedure normal_pass_2;
  39. procedure inlined_pass_2;
  40. protected
  41. { save the size of pushed parameter, needed po_clearstack
  42. and alignment }
  43. pushedparasize : longint;
  44. framepointer_paraloc : tparalocation;
  45. refcountedtemp : treference;
  46. procedure handle_return_value;
  47. {# This routine is used to push the current frame pointer
  48. on the stack. This is used in nested routines where the
  49. value of the frame pointer is always pushed as an extra
  50. parameter.
  51. The default handling is the standard handling used on
  52. most stack based machines, where the frame pointer is
  53. the first invisible parameter.
  54. }
  55. function align_parasize:longint;virtual;
  56. procedure pop_parasize(pop_size:longint);virtual;
  57. procedure extra_interrupt_code;virtual;
  58. public
  59. procedure pass_2;override;
  60. end;
  61. implementation
  62. uses
  63. systems,
  64. cutils,verbose,globals,
  65. symconst,symsym,symtable,defutil,paramgr,
  66. {$ifdef GDB}
  67. {$ifdef delphi}
  68. sysutils,
  69. {$else}
  70. strings,
  71. {$endif}
  72. gdb,
  73. {$endif GDB}
  74. cgbase,pass_2,
  75. cpuinfo,aasmbase,aasmtai,
  76. nbas,nmem,nld,ncnv,
  77. {$ifdef x86}
  78. cga,cgx86,
  79. {$endif x86}
  80. ncgutil,cgobj,tgobj,
  81. procinfo;
  82. {*****************************************************************************
  83. TCGCALLPARANODE
  84. *****************************************************************************}
  85. procedure tcgcallparanode.allocate_tempparaloc;
  86. begin
  87. { Allocate (temporary) paralocation }
  88. tempparaloc:=paraitem.paraloc[callerside];
  89. if tempparaloc.loc=LOC_REGISTER then
  90. paramanager.alloctempregs(exprasmlist,tempparaloc)
  91. else
  92. paramanager.allocparaloc(exprasmlist,tempparaloc);
  93. end;
  94. procedure tcgcallparanode.push_addr_para;
  95. begin
  96. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  97. internalerror(200304235);
  98. location_release(exprasmlist,left.location);
  99. allocate_tempparaloc;
  100. cg.a_paramaddr_ref(exprasmlist,left.location.reference,tempparaloc);
  101. inc(tcgcallnode(aktcallnode).pushedparasize,POINTER_SIZE);
  102. end;
  103. procedure tcgcallparanode.push_value_para;
  104. var
  105. href : treference;
  106. size : longint;
  107. cgsize : tcgsize;
  108. begin
  109. { we've nothing to push when the size of the parameter is 0 }
  110. if left.resulttype.def.size=0 then
  111. exit;
  112. { Move flags and jump in register to make it less complex }
  113. if left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  114. location_force_reg(exprasmlist,left.location,def_cgsize(left.resulttype.def),false);
  115. { Handle Floating point types differently }
  116. if left.resulttype.def.deftype=floatdef then
  117. begin
  118. location_release(exprasmlist,left.location);
  119. allocate_tempparaloc;
  120. {$ifdef i386}
  121. if tempparaloc.loc<>LOC_REFERENCE then
  122. internalerror(200309291);
  123. case left.location.loc of
  124. LOC_FPUREGISTER,
  125. LOC_CFPUREGISTER:
  126. begin
  127. size:=align(tfloatdef(left.resulttype.def).size,tempparaloc.alignment);
  128. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  129. if tempparaloc.reference.index=NR_STACK_POINTER_REG then
  130. begin
  131. cg.g_stackpointer_alloc(exprasmlist,size);
  132. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  133. end
  134. else
  135. reference_reset_base(href,tempparaloc.reference.index,tempparaloc.reference.offset);
  136. cg.a_loadfpu_reg_ref(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,href);
  137. end;
  138. LOC_REFERENCE,
  139. LOC_CREFERENCE :
  140. begin
  141. size:=align(left.resulttype.def.size,tempparaloc.alignment);
  142. if tempparaloc.reference.index=NR_STACK_POINTER_REG then
  143. begin
  144. href:=left.location.reference;
  145. inc(href.offset,size);
  146. while (size>0) do
  147. begin
  148. if (size>=4) or (tempparaloc.alignment>=4) then
  149. begin
  150. cgsize:=OS_32;
  151. inc(tcgcallnode(aktcallnode).pushedparasize,4);
  152. dec(href.offset,4);
  153. dec(size,4);
  154. end
  155. else
  156. begin
  157. cgsize:=OS_16;
  158. inc(tcgcallnode(aktcallnode).pushedparasize,2);
  159. dec(href.offset,2);
  160. dec(size,2);
  161. end;
  162. cg.a_param_ref(exprasmlist,cgsize,href,tempparaloc);
  163. end;
  164. end
  165. else
  166. begin
  167. reference_reset_base(href,tempparaloc.reference.index,tempparaloc.reference.offset);
  168. cg.g_concatcopy(exprasmlist,left.location.reference,href,size,false,false);
  169. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  170. end;
  171. end;
  172. else
  173. internalerror(200204243);
  174. end;
  175. {$else i386}
  176. case left.location.loc of
  177. LOC_FPUREGISTER,
  178. LOC_CFPUREGISTER:
  179. cg.a_paramfpu_reg(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,tempparaloc);
  180. LOC_REFERENCE,
  181. LOC_CREFERENCE :
  182. cg.a_paramfpu_ref(exprasmlist,def_cgsize(left.resulttype.def),left.location.reference,tempparaloc)
  183. else
  184. internalerror(200204243);
  185. end;
  186. {$endif i386}
  187. end
  188. else
  189. begin
  190. { copy the value on the stack or use normal parameter push?
  191. Check for varargs first because that has no paraitem }
  192. if not(nf_varargs_para in flags) and
  193. paramanager.copy_value_on_stack(paraitem.paratyp,left.resulttype.def,
  194. aktcallnode.procdefinition.proccalloption) then
  195. begin
  196. location_release(exprasmlist,left.location);
  197. allocate_tempparaloc;
  198. {$ifdef i386}
  199. if tempparaloc.loc<>LOC_REFERENCE then
  200. internalerror(200309292);
  201. if not (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  202. internalerror(200204241);
  203. { push on stack }
  204. size:=align(left.resulttype.def.size,tempparaloc.alignment);
  205. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  206. if tempparaloc.reference.index=NR_STACK_POINTER_REG then
  207. begin
  208. cg.g_stackpointer_alloc(exprasmlist,size);
  209. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  210. end
  211. else
  212. reference_reset_base(href,tempparaloc.reference.index,tempparaloc.reference.offset);
  213. cg.g_concatcopy(exprasmlist,left.location.reference,href,size,false,false);
  214. {$else i386}
  215. cg.a_param_copy_ref(exprasmlist,left.resulttype.def.size,left.location.reference,tempparaloc);
  216. {$endif i386}
  217. end
  218. else
  219. begin
  220. case left.location.loc of
  221. LOC_CONSTANT,
  222. LOC_REGISTER,
  223. LOC_CREGISTER,
  224. LOC_REFERENCE,
  225. LOC_CREFERENCE :
  226. begin
  227. cgsize:=def_cgsize(left.resulttype.def);
  228. if cgsize in [OS_64,OS_S64] then
  229. begin
  230. inc(tcgcallnode(aktcallnode).pushedparasize,8);
  231. allocate_tempparaloc;
  232. cg64.a_param64_loc(exprasmlist,left.location,tempparaloc);
  233. location_release(exprasmlist,left.location);
  234. end
  235. else
  236. begin
  237. location_release(exprasmlist,left.location);
  238. allocate_tempparaloc;
  239. inc(tcgcallnode(aktcallnode).pushedparasize,align(tcgsize2size[tempparaloc.size],tempparaloc.alignment));
  240. cg.a_param_loc(exprasmlist,left.location,tempparaloc);
  241. end;
  242. end;
  243. {$ifdef SUPPORT_MMX}
  244. LOC_MMXREGISTER,
  245. LOC_CMMXREGISTER:
  246. begin
  247. location_release(exprasmlist,left.location);
  248. allocate_tempparaloc;
  249. inc(tcgcallnode(aktcallnode).pushedparasize,8);
  250. cg.a_parammm_reg(exprasmlist,left.location.register);
  251. end;
  252. {$endif SUPPORT_MMX}
  253. else
  254. internalerror(200204241);
  255. end;
  256. end;
  257. end;
  258. end;
  259. procedure tcgcallparanode.secondcallparan;
  260. var
  261. otlabel,
  262. oflabel : tasmlabel;
  263. begin
  264. if not(assigned(paraitem)) or
  265. not(assigned(paraitem.paratype.def)) or
  266. not(assigned(paraitem.parasym) or
  267. (nf_varargs_para in flags)) then
  268. internalerror(200304242);
  269. { push from left to right if specified }
  270. if assigned(right) and
  271. (aktcallnode.procdefinition.proccalloption in pushleftright_pocalls) then
  272. tcallparanode(right).secondcallparan;
  273. { Skip nothingn nodes which are used after disabling
  274. a parameter }
  275. if (left.nodetype<>nothingn) then
  276. begin
  277. otlabel:=truelabel;
  278. oflabel:=falselabel;
  279. objectlibrary.getlabel(truelabel);
  280. objectlibrary.getlabel(falselabel);
  281. secondpass(left);
  282. { handle varargs first, because paraitem.parasym is not valid }
  283. if (nf_varargs_para in flags) then
  284. begin
  285. if paramanager.push_addr_param(vs_value,left.resulttype.def,
  286. aktcallnode.procdefinition.proccalloption) then
  287. push_addr_para
  288. else
  289. push_value_para;
  290. end
  291. { hidden parameters }
  292. else if paraitem.is_hidden then
  293. begin
  294. { don't push a node that already generated a pointer type
  295. by address for implicit hidden parameters }
  296. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  297. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  298. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  299. aktcallnode.procdefinition.proccalloption)) then
  300. push_addr_para
  301. else
  302. push_value_para;
  303. end
  304. { filter array of const c styled args }
  305. else if is_array_of_const(left.resulttype.def) and (nf_cargs in left.flags) then
  306. begin
  307. { nothing, everything is already pushed }
  308. end
  309. { formal def }
  310. else if (paraitem.paratype.def.deftype=formaldef) then
  311. begin
  312. { allow passing of a constant to a const formaldef }
  313. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  314. (left.location.loc=LOC_CONSTANT) then
  315. location_force_mem(exprasmlist,left.location);
  316. { allow @var }
  317. if (left.nodetype=addrn) and
  318. (not(nf_procvarload in left.flags)) then
  319. begin
  320. inc(tcgcallnode(aktcallnode).pushedparasize,POINTER_SIZE);
  321. location_release(exprasmlist,left.location);
  322. allocate_tempparaloc;
  323. cg.a_param_loc(exprasmlist,left.location,tempparaloc);
  324. end
  325. else
  326. push_addr_para;
  327. end
  328. { Normal parameter }
  329. else
  330. begin
  331. { don't push a node that already generated a pointer type
  332. by address for implicit hidden parameters }
  333. if (not(
  334. paraitem.is_hidden and
  335. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  336. ) and
  337. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  338. aktcallnode.procdefinition.proccalloption)) then
  339. begin
  340. { Check for passing a constant to var,out parameter }
  341. if (paraitem.paratyp in [vs_var,vs_out]) and
  342. (left.location.loc<>LOC_REFERENCE) then
  343. begin
  344. { passing self to a var parameter is allowed in
  345. TP and delphi }
  346. if not((left.location.loc=LOC_CREFERENCE) and
  347. is_self_node(left)) then
  348. internalerror(200106041);
  349. end;
  350. { Force to be in memory }
  351. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  352. location_force_mem(exprasmlist,left.location);
  353. push_addr_para;
  354. end
  355. else
  356. push_value_para;
  357. end;
  358. truelabel:=otlabel;
  359. falselabel:=oflabel;
  360. { update return location in callnode when this is the function
  361. result }
  362. if assigned(paraitem.parasym) and
  363. (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  364. location_copy(aktcallnode.location,left.location);
  365. end;
  366. { push from right to left }
  367. if assigned(right) and
  368. not(aktcallnode.procdefinition.proccalloption in pushleftright_pocalls) then
  369. tcallparanode(right).secondcallparan;
  370. end;
  371. {*****************************************************************************
  372. TCGCALLNODE
  373. *****************************************************************************}
  374. procedure tcgcallnode.extra_interrupt_code;
  375. begin
  376. end;
  377. function tcgcallnode.align_parasize:longint;
  378. begin
  379. result:=0;
  380. end;
  381. procedure tcgcallnode.pop_parasize(pop_size:longint);
  382. begin
  383. end;
  384. procedure tcgcallnode.handle_return_value;
  385. var
  386. cgsize : tcgsize;
  387. hregister : tregister;
  388. tempnode: tnode;
  389. begin
  390. { structured results are easy to handle.... }
  391. { needed also when result_no_used !! }
  392. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  393. begin
  394. { Location should be setup by the funcret para }
  395. if location.loc<>LOC_REFERENCE then
  396. internalerror(200304241);
  397. end
  398. else
  399. { ansi/widestrings must be registered, so we can dispose them }
  400. if is_ansistring(resulttype.def) or
  401. is_widestring(resulttype.def) then
  402. begin
  403. { the FUNCTION_RESULT_REG is already allocated }
  404. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  405. if not assigned(funcretnode) then
  406. begin
  407. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  408. location.reference:=refcountedtemp;
  409. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,location.reference);
  410. end
  411. else
  412. begin
  413. hregister := cg.getaddressregister(exprasmlist);
  414. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,hregister);
  415. { in case of a regular funcretnode with ret_in_param, the }
  416. { original funcretnode isn't touched -> make sure it's }
  417. { the same here (not sure if it's necessary) }
  418. tempnode := funcretnode.getcopy;
  419. tempnode.pass_2;
  420. location := tempnode.location;
  421. tempnode.free;
  422. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference, false);
  423. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  424. cg.ungetregister(exprasmlist,hregister);
  425. end;
  426. end
  427. else
  428. { we have only to handle the result if it is used }
  429. if (nf_return_value_used in flags) then
  430. begin
  431. if (resulttype.def.deftype=floatdef) then
  432. begin
  433. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  434. {$ifdef cpufpemu}
  435. if cs_fp_emulation in aktmoduleswitches then
  436. location.register:=NR_FUNCTION_RESULT_REG
  437. else
  438. {$endif cpufpemu}
  439. location.register:=NR_FPU_RESULT_REG;
  440. {$ifdef x86}
  441. tcgx86(cg).inc_fpu_stack;
  442. {$else x86}
  443. hregister := cg.getfpuregister(exprasmlist,location.size);
  444. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  445. location.register := hregister;
  446. {$endif x86}
  447. end
  448. else
  449. begin
  450. cgsize:=def_cgsize(resulttype.def);
  451. if cgsize<>OS_NO then
  452. begin
  453. location_reset(location,LOC_REGISTER,cgsize);
  454. {$ifndef cpu64bit}
  455. if cgsize in [OS_64,OS_S64] then
  456. begin
  457. { Move the function result to free registers, preferably the
  458. FUNCTION_RESULT_REG/FUNCTION_RESULTHIGH_REG, so no move is necessary.}
  459. { the FUNCTION_RESULT_LOW_REG/FUNCTION_RESULT_HIGH_REG
  460. are already allocated }
  461. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG);
  462. location.registerlow:=cg.getintregister(exprasmlist,OS_INT);
  463. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,NR_FUNCTION_RESULT64_LOW_REG,location.registerlow);
  464. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG);
  465. location.registerhigh:=cg.getintregister(exprasmlist,OS_INT);
  466. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,NR_FUNCTION_RESULT64_HIGH_REG,location.registerhigh);
  467. end
  468. else
  469. {$endif cpu64bit}
  470. begin
  471. {Move the function result to a free register, preferably the
  472. FUNCTION_RESULT_REG, so no move is necessary.}
  473. { the FUNCTION_RESULT_REG is already allocated }
  474. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  475. { change register size after the unget because the
  476. getregister was done for the full register }
  477. location.register:=cg.getintregister(exprasmlist,cgsize);
  478. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,cg.makeregsize(NR_FUNCTION_RESULT_REG,cgsize),location.register);
  479. end;
  480. end
  481. else
  482. begin
  483. if resulttype.def.size>0 then
  484. internalerror(200305131);
  485. end;
  486. end;
  487. end
  488. else
  489. begin
  490. cgsize:=def_cgsize(resulttype.def);
  491. { an object constructor is a function with pointer result }
  492. if (procdefinition.proctypeoption=potype_constructor) then
  493. cgsize:=OS_ADDR;
  494. if cgsize<>OS_NO then
  495. {$ifndef cpu64bit}
  496. if cgsize in [OS_64,OS_S64] then
  497. begin
  498. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG);
  499. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG);
  500. end
  501. else
  502. {$endif cpu64bit}
  503. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  504. location_reset(location,LOC_VOID,OS_NO);
  505. end;
  506. end;
  507. procedure tcgcallnode.release_para_temps;
  508. var
  509. hp : tnode;
  510. ppn : tcallparanode;
  511. begin
  512. { Release temps from parameters }
  513. ppn:=tcallparanode(left);
  514. while assigned(ppn) do
  515. begin
  516. if assigned(ppn.left) then
  517. begin
  518. { don't release the funcret temp }
  519. if not(assigned(ppn.paraitem.parasym)) or
  520. not(vo_is_funcret in tvarsym(ppn.paraitem.parasym).varoptions) then
  521. location_freetemp(exprasmlist,ppn.left.location);
  522. { process also all nodes of an array of const }
  523. if ppn.left.nodetype=arrayconstructorn then
  524. begin
  525. if assigned(tarrayconstructornode(ppn.left).left) then
  526. begin
  527. hp:=ppn.left;
  528. while assigned(hp) do
  529. begin
  530. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  531. hp:=tarrayconstructornode(hp).right;
  532. end;
  533. end;
  534. end;
  535. end;
  536. ppn:=tcallparanode(ppn.right);
  537. end;
  538. end;
  539. procedure tcgcallnode.normal_pass_2;
  540. var
  541. regs_to_push_fpu,
  542. regs_to_alloc,
  543. regs_to_free : Tcpuregisterset;
  544. oldpushedparasize : longint;
  545. { adress returned from an I/O-error }
  546. { help reference pointer }
  547. href : treference;
  548. pop_size : longint;
  549. pvreg,
  550. vmtreg : tregister;
  551. oldaktcallnode : tcallnode;
  552. procedure pushparas;
  553. var
  554. ppn : tcgcallparanode;
  555. begin
  556. { copy all resources to the allocated registers }
  557. ppn:=tcgcallparanode(left);
  558. while assigned(ppn) do
  559. begin
  560. if ppn.tempparaloc.loc=LOC_REGISTER then
  561. begin
  562. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  563. paramanager.allocparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  564. {$ifdef sparc}
  565. case ppn.tempparaloc.size of
  566. OS_F32 :
  567. ppn.tempparaloc.size:=OS_32;
  568. OS_F64 :
  569. ppn.tempparaloc.size:=OS_64;
  570. end;
  571. {$endif sparc}
  572. {$ifndef cpu64bit}
  573. if ppn.tempparaloc.size in [OS_64,OS_S64] then
  574. begin
  575. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerlow,
  576. ppn.paraitem.paraloc[callerside].registerlow);
  577. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerhigh,
  578. ppn.paraitem.paraloc[callerside].registerhigh);
  579. end
  580. else
  581. {$endif cpu64bit}
  582. cg.a_load_reg_reg(exprasmlist,ppn.tempparaloc.size,ppn.tempparaloc.size,
  583. ppn.tempparaloc.register,ppn.paraitem.paraloc[callerside].register);
  584. end;
  585. ppn:=tcgcallparanode(ppn.right);
  586. end;
  587. end;
  588. procedure freeparas;
  589. var
  590. ppn : tcgcallparanode;
  591. begin
  592. { free the resources allocated for the parameters }
  593. ppn:=tcgcallparanode(left);
  594. while assigned(ppn) do
  595. begin
  596. if ppn.tempparaloc.loc=LOC_REGISTER then
  597. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  598. paramanager.freeparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  599. ppn:=tcgcallparanode(ppn.right);
  600. end;
  601. end;
  602. begin
  603. if not assigned(procdefinition) then
  604. internalerror(200305264);
  605. { calculate the parameter info for the procdef }
  606. if not procdefinition.has_paraloc_info then
  607. begin
  608. paramanager.create_paraloc_info(procdefinition,callerside);
  609. procdefinition.has_paraloc_info:=true;
  610. end;
  611. { calculate the parameter info for varargs }
  612. if assigned(varargsparas) then
  613. paramanager.create_varargs_paraloc_info(procdefinition,varargsparas);
  614. if not assigned(funcretnode) then
  615. begin
  616. { if we allocate the temp. location for ansi- or widestrings }
  617. { already here, we avoid later a push/pop }
  618. if is_widestring(resulttype.def) then
  619. begin
  620. tg.gettemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  621. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  622. end
  623. else if is_ansistring(resulttype.def) then
  624. begin
  625. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  626. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  627. end;
  628. end;
  629. regs_to_alloc:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  630. regs_to_push_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  631. { Include Function result registers }
  632. if (not is_void(resulttype.def)) then
  633. begin
  634. case procdefinition.funcret_paraloc[callerside].loc of
  635. LOC_REGISTER,LOC_CREGISTER:
  636. begin
  637. {$ifndef cpu64bit}
  638. if procdefinition.funcret_paraloc[callerside].size in [OS_S64,OS_64] then
  639. begin
  640. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].registerlow));
  641. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].registerhigh));
  642. end
  643. else
  644. {$endif cpu64bit}
  645. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  646. end;
  647. end;
  648. end;
  649. { Save registers destroyed by the call }
  650. {$warning fime saveusedotherregisters.}
  651. { cg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);}
  652. { Initialize for pushing the parameters }
  653. oldpushedparasize:=pushedparasize;
  654. pushedparasize:=0;
  655. { Process parameters, register parameters will be loaded
  656. in imaginary registers. The actual load to the correct
  657. register is done just before the call }
  658. oldaktcallnode:=aktcallnode;
  659. aktcallnode:=self;
  660. if assigned(left) then
  661. tcallparanode(left).secondcallparan;
  662. aktcallnode:=oldaktcallnode;
  663. { Align stack if required }
  664. pop_size:=align_parasize;
  665. { procedure variable or normal function call ? }
  666. if (right=nil) then
  667. begin
  668. if (po_virtualmethod in procdefinition.procoptions) and
  669. assigned(methodpointer) then
  670. begin
  671. secondpass(methodpointer);
  672. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  673. { virtual methods require an index }
  674. if tprocdef(procdefinition).extnumber=-1 then
  675. internalerror(200304021);
  676. { VMT should already be loaded in a register }
  677. if methodpointer.location.register=NR_NO then
  678. internalerror(200304022);
  679. { test validity of VMT }
  680. if not(is_interface(tprocdef(procdefinition)._class)) and
  681. not(is_cppclass(tprocdef(procdefinition)._class)) then
  682. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  683. end;
  684. {$warning fixme regvars}
  685. { rg.saveotherregvars(exprasmlist,regs_to_push_other);}
  686. if (po_virtualmethod in procdefinition.procoptions) and
  687. assigned(methodpointer) then
  688. begin
  689. vmtreg:=methodpointer.location.register;
  690. { release self }
  691. cg.ungetregister(exprasmlist,vmtreg);
  692. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  693. reference_reset_base(href,vmtreg,
  694. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  695. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,pvreg);
  696. { Load parameters that are in temporary registers in the
  697. correct parameter register }
  698. if assigned(left) then
  699. pushparas;
  700. { free the resources allocated for the parameters }
  701. freeparas;
  702. { Release register containing procvar }
  703. cg.ungetregister(exprasmlist,pvreg);
  704. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  705. cg.allocexplicitregisters(exprasmlist,R_SSEREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  706. { call method }
  707. cg.a_call_reg(exprasmlist,pvreg);
  708. end
  709. else
  710. begin
  711. { Load parameters that are in temporary registers in the
  712. correct parameter register }
  713. if assigned(left) then
  714. pushparas;
  715. { free the resources allocated for the parameters }
  716. freeparas;
  717. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  718. cg.allocexplicitregisters(exprasmlist,R_SSEREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  719. { Calling interrupt from the same code requires some
  720. extra code }
  721. if (po_interrupt in procdefinition.procoptions) then
  722. extra_interrupt_code;
  723. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  724. end;
  725. end
  726. else
  727. { now procedure variable case }
  728. begin
  729. secondpass(right);
  730. location_release(exprasmlist,right.location);
  731. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  732. { Only load OS_ADDR from the reference }
  733. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  734. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,right.location.reference,pvreg)
  735. else
  736. cg.a_load_loc_reg(exprasmlist,OS_ADDR,right.location,pvreg);
  737. location_freetemp(exprasmlist,right.location);
  738. { Load parameters that are in temporary registers in the
  739. correct parameter register }
  740. if assigned(left) then
  741. pushparas;
  742. { free the resources allocated for the parameters }
  743. freeparas;
  744. { Release register containing procvar }
  745. cg.ungetregister(exprasmlist,pvreg);
  746. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  747. cg.allocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  748. { Calling interrupt from the same code requires some
  749. extra code }
  750. if (po_interrupt in procdefinition.procoptions) then
  751. extra_interrupt_code;
  752. {$warning fixme regvars.}
  753. { rg.saveotherregvars(exprasmlist,ALL_OTHERREGISTERS);}
  754. cg.a_call_reg(exprasmlist,pvreg);
  755. end;
  756. { Need to remove the parameters from the stack? }
  757. if (procdefinition.proccalloption in clearstack_pocalls) then
  758. begin
  759. { the old pop_size was already included in pushedparasize }
  760. pop_size:=pushedparasize;
  761. { for Cdecl functions we don't need to pop the funcret when it
  762. was pushed by para }
  763. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  764. dec(pop_size,POINTER_SIZE);
  765. end;
  766. { Remove parameters/alignment from the stack }
  767. if pop_size>0 then
  768. pop_parasize(pop_size);
  769. { Reserve space for storing parameters that will be pushed }
  770. current_procinfo.allocate_push_parasize(pushedparasize);
  771. { Restore }
  772. pushedparasize:=oldpushedparasize;
  773. { Release registers, but not the registers that contain the
  774. function result }
  775. regs_to_free:=regs_to_alloc;
  776. if (not is_void(resulttype.def)) then
  777. begin
  778. case procdefinition.funcret_paraloc[callerside].loc of
  779. LOC_REGISTER,LOC_CREGISTER:
  780. begin
  781. {$ifndef cpu64bit}
  782. if procdefinition.funcret_paraloc[callerside].size in [OS_S64,OS_64] then
  783. begin
  784. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].registerlow));
  785. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].registerhigh));
  786. end
  787. else
  788. {$endif cpu64bit}
  789. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  790. end;
  791. end;
  792. end;
  793. cg.deallocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  794. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_free);
  795. { handle function results }
  796. if (not is_void(resulttype.def)) then
  797. handle_return_value
  798. else
  799. location_reset(location,LOC_VOID,OS_NO);
  800. { perhaps i/o check ? }
  801. if (cs_check_io in aktlocalswitches) and
  802. (po_iocheck in procdefinition.procoptions) and
  803. not(po_iocheck in current_procinfo.procdef.procoptions) and
  804. { no IO check for methods and procedure variables }
  805. (right=nil) and
  806. not(po_virtualmethod in procdefinition.procoptions) then
  807. begin
  808. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  809. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  810. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  811. end;
  812. { restore registers }
  813. {$warning fixme restoreusedotherregisters}
  814. { rg.restoreusedotherregisters(exprasmlist,pushedother);}
  815. { release temps of paras }
  816. release_para_temps;
  817. { if return value is not used }
  818. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  819. begin
  820. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  821. begin
  822. { data which must be finalized ? }
  823. if (resulttype.def.needs_inittable) then
  824. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  825. { release unused temp }
  826. tg.ungetiftemp(exprasmlist,location.reference)
  827. end
  828. else if location.loc=LOC_FPUREGISTER then
  829. begin
  830. {$ifdef x86}
  831. { release FPU stack }
  832. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  833. {$endif x86}
  834. end;
  835. end;
  836. end;
  837. procedure tcgcallnode.inlined_pass_2;
  838. var
  839. oldaktcallnode : tcallnode;
  840. oldprocinfo : tprocinfo;
  841. oldinlining_procedure : boolean;
  842. inlineentrycode,inlineexitcode : TAAsmoutput;
  843. usesacc,usesacchi,usesfpu : boolean;
  844. {$ifdef GDB}
  845. startlabel,endlabel : tasmlabel;
  846. pp : pchar;
  847. mangled_length : longint;
  848. {$endif GDB}
  849. begin
  850. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  851. internalerror(200305262);
  852. oldinlining_procedure:=inlining_procedure;
  853. oldprocinfo:=current_procinfo;
  854. { we're inlining a procedure }
  855. inlining_procedure:=true;
  856. { calculate registers to pass the parameters }
  857. paramanager.create_inline_paraloc_info(procdefinition);
  858. { create temp procinfo }
  859. current_procinfo:=cprocinfo.create(nil);
  860. current_procinfo.procdef:=tprocdef(procdefinition);
  861. { Add inling start }
  862. exprasmList.concat(Tai_Marker.Create(InlineStart));
  863. {$ifdef extdebug}
  864. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  865. {$endif extdebug}
  866. { Allocate parameters and locals }
  867. gen_alloc_inline_parast(exprasmlist,tparasymtable(current_procinfo.procdef.parast));
  868. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  869. gen_alloc_localst(exprasmlist,tlocalsymtable(current_procinfo.procdef.localst));
  870. {$ifdef GDB}
  871. if (cs_debuginfo in aktmoduleswitches) then
  872. begin
  873. objectlibrary.getaddrlabel(startlabel);
  874. objectlibrary.getaddrlabel(endlabel);
  875. cg.a_label(exprasmlist,startlabel);
  876. { Here we must include the para and local symtable info }
  877. procdefinition.concatstabto(withdebuglist);
  878. mangled_length:=length(oldprocinfo.procdef.mangledname);
  879. getmem(pp,mangled_length+50);
  880. strpcopy(pp,'192,0,0,'+startlabel.name);
  881. if (target_info.use_function_relative_addresses) then
  882. begin
  883. strpcopy(strend(pp),'-');
  884. strpcopy(strend(pp),oldprocinfo.procdef.mangledname);
  885. end;
  886. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  887. end;
  888. {$endif GDB}
  889. { if we allocate the temp. location for ansi- or widestrings }
  890. { already here, we avoid later a push/pop }
  891. if is_widestring(resulttype.def) then
  892. begin
  893. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  894. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  895. end
  896. else if is_ansistring(resulttype.def) then
  897. begin
  898. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  899. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  900. end;
  901. { Push parameters }
  902. oldaktcallnode:=aktcallnode;
  903. aktcallnode:=self;
  904. if assigned(left) then
  905. tcallparanode(left).secondcallparan;
  906. aktcallnode:=oldaktcallnode;
  907. { takes care of local data initialization }
  908. inlineentrycode:=TAAsmoutput.Create;
  909. inlineexitcode:=TAAsmoutput.Create;
  910. gen_load_para_value(inlineentrycode);
  911. gen_initialize_code(inlineentrycode,true);
  912. if po_assembler in current_procinfo.procdef.procoptions then
  913. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  914. exprasmList.concatlist(inlineentrycode);
  915. { process the inline code }
  916. secondpass(inlinecode);
  917. gen_finalize_code(inlineexitcode,true);
  918. gen_load_return_value(inlineexitcode,usesacc,usesacchi,usesfpu);
  919. if po_assembler in current_procinfo.procdef.procoptions then
  920. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  921. exprasmlist.concatlist(inlineexitcode);
  922. inlineentrycode.free;
  923. inlineexitcode.free;
  924. {$ifdef extdebug}
  925. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  926. {$endif extdebug}
  927. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  928. { handle function results }
  929. if (not is_void(resulttype.def)) then
  930. handle_return_value
  931. else
  932. location_reset(location,LOC_VOID,OS_NO);
  933. { perhaps i/o check ? }
  934. if (cs_check_io in aktlocalswitches) and
  935. (po_iocheck in procdefinition.procoptions) and
  936. not(po_iocheck in current_procinfo.procdef.procoptions) and
  937. { no IO check for methods and procedure variables }
  938. (right=nil) and
  939. not(po_virtualmethod in procdefinition.procoptions) then
  940. begin
  941. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  942. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  943. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  944. end;
  945. { release temps of paras }
  946. release_para_temps;
  947. { if return value is not used }
  948. if (not is_void(resulttype.def)) and
  949. (not(nf_return_value_used in flags)) then
  950. begin
  951. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  952. begin
  953. { data which must be finalized ? }
  954. if (resulttype.def.needs_inittable) then
  955. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  956. { release unused temp }
  957. tg.ungetiftemp(exprasmlist,location.reference)
  958. end
  959. else if location.loc=LOC_FPUREGISTER then
  960. begin
  961. {$ifdef x86}
  962. { release FPU stack }
  963. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  964. {$endif x86}
  965. end;
  966. end;
  967. { Release parameters and locals }
  968. gen_free_parast(exprasmlist,tparasymtable(current_procinfo.procdef.parast));
  969. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  970. gen_free_localst(exprasmlist,tlocalsymtable(current_procinfo.procdef.localst));
  971. { release procinfo }
  972. current_procinfo.free;
  973. current_procinfo:=oldprocinfo;
  974. {$ifdef GDB}
  975. if (cs_debuginfo in aktmoduleswitches) then
  976. begin
  977. cg.a_label(exprasmlist,endlabel);
  978. strpcopy(pp,'224,0,0,'+endlabel.name);
  979. if (target_info.use_function_relative_addresses) then
  980. begin
  981. strpcopy(strend(pp),'-');
  982. strpcopy(strend(pp),oldprocinfo.procdef.mangledname);
  983. end;
  984. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  985. freemem(pp,mangled_length+50);
  986. end;
  987. {$endif GDB}
  988. { restore }
  989. current_procinfo:=oldprocinfo;
  990. inlining_procedure:=oldinlining_procedure;
  991. end;
  992. procedure tcgcallnode.pass_2;
  993. begin
  994. if assigned(inlinecode) then
  995. inlined_pass_2
  996. else
  997. normal_pass_2;
  998. end;
  999. begin
  1000. ccallparanode:=tcgcallparanode;
  1001. ccallnode:=tcgcallnode;
  1002. end.
  1003. {
  1004. $Log$
  1005. Revision 1.133 2003-10-20 19:28:17 peter
  1006. * fixed inlining float parameters for i386
  1007. Revision 1.132 2003/10/17 14:38:32 peter
  1008. * 64k registers supported
  1009. * fixed some memory leaks
  1010. Revision 1.131 2003/10/17 01:22:08 florian
  1011. * compilation of the powerpc compiler fixed
  1012. Revision 1.130 2003/10/11 16:06:42 florian
  1013. * fixed some MMX<->SSE
  1014. * started to fix ppc, needs an overhaul
  1015. + stabs info improve for spilling, not sure if it works correctly/completly
  1016. - MMX_SUPPORT removed from Makefile.fpc
  1017. Revision 1.129 2003/10/10 17:48:13 peter
  1018. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1019. * tregisteralloctor renamed to trgobj
  1020. * removed rgobj from a lot of units
  1021. * moved location_* and reference_* to cgobj
  1022. * first things for mmx register allocation
  1023. Revision 1.128 2003/10/10 09:21:53 marco
  1024. * typo fix from Wiktor
  1025. Revision 1.127 2003/10/09 21:31:37 daniel
  1026. * Register allocator splitted, ans abstract now
  1027. Revision 1.126 2003/10/07 15:17:07 peter
  1028. * inline supported again, LOC_REFERENCEs are used to pass the
  1029. parameters
  1030. * inlineparasymtable,inlinelocalsymtable removed
  1031. * exitlabel inserting fixed
  1032. Revision 1.125 2003/10/05 21:21:52 peter
  1033. * c style array of const generates callparanodes
  1034. * varargs paraloc fixes
  1035. Revision 1.124 2003/10/03 22:00:33 peter
  1036. * parameter alignment fixes
  1037. Revision 1.123 2003/10/01 20:34:48 peter
  1038. * procinfo unit contains tprocinfo
  1039. * cginfo renamed to cgbase
  1040. * moved cgmessage to verbose
  1041. * fixed ppc and sparc compiles
  1042. Revision 1.122 2003/09/30 21:02:37 peter
  1043. * updates for inlining
  1044. Revision 1.121 2003/09/30 19:55:19 peter
  1045. * remove abt reg for vmtreg
  1046. Revision 1.120 2003/09/29 20:58:55 peter
  1047. * optimized releasing of registers
  1048. Revision 1.119 2003/09/28 17:55:03 peter
  1049. * parent framepointer changed to hidden parameter
  1050. * tloadparentfpnode added
  1051. Revision 1.118 2003/09/28 13:54:43 peter
  1052. * removed a_call_ref
  1053. Revision 1.117 2003/09/25 21:28:00 peter
  1054. * parameter fixes
  1055. Revision 1.116 2003/09/23 17:56:05 peter
  1056. * locals and paras are allocated in the code generation
  1057. * tvarsym.localloc contains the location of para/local when
  1058. generating code for the current procedure
  1059. Revision 1.115 2003/09/16 16:17:01 peter
  1060. * varspez in calls to push_addr_param
  1061. Revision 1.114 2003/09/14 19:17:39 peter
  1062. * don't use a_call_ref because it can use a parameter register
  1063. as temp
  1064. Revision 1.113 2003/09/11 11:54:59 florian
  1065. * improved arm code generation
  1066. * move some protected and private field around
  1067. * the temp. register for register parameters/arguments are now released
  1068. before the move to the parameter register is done. This improves
  1069. the code in a lot of cases.
  1070. Revision 1.112 2003/09/10 08:31:47 marco
  1071. * Patch from Peter for paraloc
  1072. Revision 1.111 2003/09/07 22:09:35 peter
  1073. * preparations for different default calling conventions
  1074. * various RA fixes
  1075. Revision 1.110 2003/09/04 15:39:58 peter
  1076. * released useparatemp
  1077. Revision 1.109 2003/09/03 15:55:00 peter
  1078. * NEWRA branch merged
  1079. Revision 1.108.2.4 2003/09/01 21:02:55 peter
  1080. * sparc updates for new tregister
  1081. Revision 1.108.2.3 2003/08/31 21:07:44 daniel
  1082. * callparatemp ripped
  1083. Revision 1.108.2.2 2003/08/29 17:28:59 peter
  1084. * next batch of updates
  1085. Revision 1.108.2.1 2003/08/27 20:23:55 peter
  1086. * remove old ra code
  1087. Revision 1.108 2003/08/21 22:14:16 olle
  1088. - removed parameter from fpc_iocheck
  1089. Revision 1.107 2003/08/17 16:59:20 jonas
  1090. * fixed regvars so they work with newra (at least for ppc)
  1091. * fixed some volatile register bugs
  1092. + -dnotranslation option for -dnewra, which causes the registers not to
  1093. be translated from virtual to normal registers. Requires support in
  1094. the assembler writer as well, which is only implemented in aggas/
  1095. agppcgas currently
  1096. Revision 1.106 2003/08/16 18:56:40 marco
  1097. * fix from Jonas.
  1098. Revision 1.105 2003/08/11 21:18:20 peter
  1099. * start of sparc support for newra
  1100. Revision 1.104 2003/08/11 14:22:06 mazen
  1101. - dupplicated code removed
  1102. Revision 1.103 2003/07/23 11:01:14 jonas
  1103. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  1104. pairs round calls to helpers
  1105. Revision 1.102 2003/07/21 13:51:50 jonas
  1106. * fixed 64bit int results with -dnewra (you can't free both registers and
  1107. then allocate two new ones, because then the registers could be reversed
  1108. afterwards -> you get something like "movl %eax, %edx; movl %edx,%eax")
  1109. Revision 1.101 2003/07/08 21:24:59 peter
  1110. * sparc fixes
  1111. Revision 1.100 2003/07/06 21:50:33 jonas
  1112. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  1113. so that it doesn't include ebp and esp anymore
  1114. Revision 1.99 2003/07/06 17:58:22 peter
  1115. * framepointer fixes for sparc
  1116. * parent framepointer code more generic
  1117. Revision 1.98 2003/07/06 15:31:20 daniel
  1118. * Fixed register allocator. *Lots* of fixes.
  1119. Revision 1.97 2003/07/05 20:21:26 jonas
  1120. * create_paraloc_info() is now called separately for the caller and
  1121. callee info
  1122. * fixed ppc cycle
  1123. Revision 1.96 2003/07/02 22:18:04 peter
  1124. * paraloc splitted in paraloc[callerside],calleeparaloc
  1125. * sparc calling convention updates
  1126. Revision 1.95 2003/06/17 16:34:44 jonas
  1127. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1128. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  1129. processor dependent
  1130. Revision 1.94 2003/06/15 16:52:02 jonas
  1131. * release function result registers if the functino result isn't used
  1132. * don't allocate function result register with -dnewra if there is none
  1133. * some optimizations for non-x86 processor (don't save any registers
  1134. before a call)
  1135. Revision 1.93 2003/06/13 21:19:30 peter
  1136. * current_procdef removed, use current_procinfo.procdef instead
  1137. Revision 1.92 2003/06/12 21:10:50 peter
  1138. * newra fixes
  1139. Revision 1.91 2003/06/12 18:38:45 jonas
  1140. * deallocate parameter registers in time for newra
  1141. * for non-i386, procvars and methodpointers always have to be processed
  1142. in advance, whether or not newra is defined
  1143. Revision 1.90 2003/06/09 14:54:26 jonas
  1144. * (de)allocation of registers for parameters is now performed properly
  1145. (and checked on the ppc)
  1146. - removed obsolete allocation of all parameter registers at the start
  1147. of a procedure (and deallocation at the end)
  1148. Revision 1.89 2003/06/09 12:23:29 peter
  1149. * init/final of procedure data splitted from genentrycode
  1150. * use asmnode getposition to insert final at the correct position
  1151. als for the implicit try...finally
  1152. Revision 1.88 2003/06/08 20:01:53 jonas
  1153. * optimized assignments with on the right side a function that returns
  1154. an ansi- or widestring
  1155. Revision 1.87 2003/06/08 18:21:47 jonas
  1156. * fixed weird error in the copyleft statement :)
  1157. Revision 1.86 2003/06/07 18:57:04 jonas
  1158. + added freeintparaloc
  1159. * ppc get/freeintparaloc now check whether the parameter regs are
  1160. properly allocated/deallocated (and get an extra list para)
  1161. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1162. * fixed lot of missing pi_do_call's
  1163. Revision 1.85 2003/06/04 06:43:36 jonas
  1164. * fixed double secondpassing of procvar loads
  1165. Revision 1.84 2003/06/03 21:11:09 peter
  1166. * cg.a_load_* get a from and to size specifier
  1167. * makeregsize only accepts newregister
  1168. * i386 uses generic tcgnotnode,tcgunaryminus
  1169. Revision 1.83 2003/06/03 20:27:02 daniel
  1170. * Restored original methodpointer code for non newra case
  1171. Revision 1.82 2003/06/03 13:01:59 daniel
  1172. * Register allocator finished
  1173. Revision 1.81 2003/06/01 21:38:06 peter
  1174. * getregisterfpu size parameter added
  1175. * op_const_reg size parameter added
  1176. * sparc updates
  1177. Revision 1.80 2003/05/31 15:05:28 peter
  1178. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1179. Revision 1.79 2003/05/31 00:59:44 peter
  1180. * typo in FUNCTION_RESULT_REG
  1181. Revision 1.78 2003/05/30 23:57:08 peter
  1182. * more sparc cleanup
  1183. * accumulator removed, splitted in function_return_reg (called) and
  1184. function_result_reg (caller)
  1185. Revision 1.77 2003/05/29 10:05:40 jonas
  1186. * free callparatemps created for call-by-reference parameters
  1187. Revision 1.76 2003/05/28 23:58:18 jonas
  1188. * added missing initialization of rg.usedintin,byproc
  1189. * ppc now also saves/restores used fpu registers
  1190. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1191. i386
  1192. Revision 1.75 2003/05/26 21:17:17 peter
  1193. * procinlinenode removed
  1194. * aktexit2label removed, fast exit removed
  1195. + tcallnode.inlined_pass_2 added
  1196. Revision 1.74 2003/05/25 11:34:17 peter
  1197. * methodpointer self pushing fixed
  1198. Revision 1.73 2003/05/25 08:59:16 peter
  1199. * inline fixes
  1200. Revision 1.72 2003/05/24 13:36:54 jonas
  1201. * save fpu results in a normal fpu register on non-x86 processors
  1202. Revision 1.71 2003/05/23 19:35:50 jonas
  1203. - undid previous commit, it was wrong
  1204. Revision 1.70 2003/05/23 19:11:58 jonas
  1205. * fixed tests for whether a certain int register is unused
  1206. Revision 1.69 2003/05/23 18:01:56 jonas
  1207. * fixed ppc compiler
  1208. Revision 1.68 2003/05/23 14:27:35 peter
  1209. * remove some unit dependencies
  1210. * current_procinfo changes to store more info
  1211. Revision 1.67 2003/05/17 13:30:08 jonas
  1212. * changed tt_persistant to tt_persistent :)
  1213. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1214. temps, but a ttemptype, so you can also create ansistring temps etc
  1215. Revision 1.66 2003/05/16 14:33:31 peter
  1216. * regvar fixes
  1217. Revision 1.65 2003/05/15 18:58:53 peter
  1218. * removed selfpointer_offset, vmtpointer_offset
  1219. * tvarsym.adjusted_address
  1220. * address in localsymtable is now in the real direction
  1221. * removed some obsolete globals
  1222. Revision 1.64 2003/05/14 19:36:54 jonas
  1223. * patch from Peter for int64 function results
  1224. Revision 1.63 2003/05/13 19:14:41 peter
  1225. * failn removed
  1226. * inherited result code check moven to pexpr
  1227. Revision 1.62 2003/05/13 15:18:18 peter
  1228. * generate code for procvar first before pushing parameters. Made
  1229. the already existing code for powerpc available for all platforms
  1230. Revision 1.61 2003/05/12 18:17:55 jonas
  1231. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1232. already-loaded parameter registers
  1233. Revision 1.60 2003/05/11 21:48:38 jonas
  1234. * fixed procvar bug on the ppc (load procvar before loading para's,
  1235. because the procvar may otherwise destroy the already loaded paras)
  1236. Revision 1.59 2003/05/09 17:47:02 peter
  1237. * self moved to hidden parameter
  1238. * removed hdisposen,hnewn,selfn
  1239. Revision 1.58 2003/05/05 14:53:16 peter
  1240. * vs_hidden replaced by is_hidden boolean
  1241. Revision 1.57 2003/04/30 20:53:32 florian
  1242. * error when address of an abstract method is taken
  1243. * fixed some x86-64 problems
  1244. * merged some more x86-64 and i386 code
  1245. Revision 1.56 2003/04/29 07:28:52 michael
  1246. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1247. Revision 1.55 2003/04/27 11:21:33 peter
  1248. * aktprocdef renamed to current_procinfo.procdef
  1249. * procinfo renamed to current_procinfo
  1250. * procinfo will now be stored in current_module so it can be
  1251. cleaned up properly
  1252. * gen_main_procsym changed to create_main_proc and release_main_proc
  1253. to also generate a tprocinfo structure
  1254. * fixed unit implicit initfinal
  1255. Revision 1.54 2003/04/27 07:29:50 peter
  1256. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  1257. a new procdef declaration
  1258. * aktprocsym removed
  1259. * lexlevel removed, use symtable.symtablelevel instead
  1260. * implicit init/final code uses the normal genentry/genexit
  1261. * funcret state checking updated for new funcret handling
  1262. Revision 1.53 2003/04/25 20:59:33 peter
  1263. * removed funcretn,funcretsym, function result is now in varsym
  1264. and aliases for result and function name are added using absolutesym
  1265. * vs_hidden parameter for funcret passed in parameter
  1266. * vs_hidden fixes
  1267. * writenode changed to printnode and released from extdebug
  1268. * -vp option added to generate a tree.log with the nodetree
  1269. * nicer printnode for statements, callnode
  1270. Revision 1.52 2003/04/25 08:25:26 daniel
  1271. * Ifdefs around a lot of calls to cleartempgen
  1272. * Fixed registers that are allocated but not freed in several nodes
  1273. * Tweak to register allocator to cause less spills
  1274. * 8-bit registers now interfere with esi,edi and ebp
  1275. Compiler can now compile rtl successfully when using new register
  1276. allocator
  1277. Revision 1.51 2003/04/22 23:50:22 peter
  1278. * firstpass uses expectloc
  1279. * checks if there are differences between the expectloc and
  1280. location.loc from secondpass in EXTDEBUG
  1281. Revision 1.50 2003/04/22 14:33:38 peter
  1282. * removed some notes/hints
  1283. Revision 1.49 2003/04/22 13:47:08 peter
  1284. * fixed C style array of const
  1285. * fixed C array passing
  1286. * fixed left to right with high parameters
  1287. Revision 1.48 2003/04/22 10:09:34 daniel
  1288. + Implemented the actual register allocator
  1289. + Scratch registers unavailable when new register allocator used
  1290. + maybe_save/maybe_restore unavailable when new register allocator used
  1291. Revision 1.47 2003/04/22 09:49:44 peter
  1292. * do not load self when calling a non-inherited class constructor
  1293. Revision 1.46 2003/04/21 20:03:32 peter
  1294. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1295. Revision 1.45 2003/04/21 13:53:16 jonas
  1296. - removed copying of all paras when secondpassing a callnode (this used
  1297. to be necessary for inlinign support, but currently the whole inlined
  1298. procedure is already copied in advance). Note that the compiler crashes
  1299. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1300. syntax errors), but that was also the case before this change.
  1301. Revision 1.44 2003/04/10 17:57:52 peter
  1302. * vs_hidden released
  1303. Revision 1.43 2003/04/06 21:11:23 olle
  1304. * changed newasmsymbol to newasmsymboldata for data symbols
  1305. Revision 1.42 2003/04/04 15:38:56 peter
  1306. * moved generic code from n386cal to ncgcal, i386 now also
  1307. uses the generic ncgcal
  1308. Revision 1.41 2003/03/28 19:16:56 peter
  1309. * generic constructor working for i386
  1310. * remove fixed self register
  1311. * esi added as address register for i386
  1312. Revision 1.40 2003/03/06 11:35:50 daniel
  1313. * Fixed internalerror 7843 issue
  1314. Revision 1.39 2003/02/19 22:00:14 daniel
  1315. * Code generator converted to new register notation
  1316. - Horribily outdated todo.txt removed
  1317. Revision 1.38 2003/02/15 22:17:38 carl
  1318. * bugfix of FPU emulation code
  1319. Revision 1.37 2003/02/12 22:10:07 carl
  1320. * load_frame_pointer is now generic
  1321. * change fpu emulation routine names
  1322. Revision 1.36 2003/01/30 21:46:57 peter
  1323. * self fixes for static methods (merged)
  1324. Revision 1.35 2003/01/22 20:45:15 mazen
  1325. * making math code in RTL compiling.
  1326. *NB : This does NOT mean necessary that it will generate correct code!
  1327. Revision 1.34 2003/01/17 12:03:45 daniel
  1328. * Optalign conditional code adapted to record Tregister
  1329. Revision 1.33 2003/01/08 18:43:56 daniel
  1330. * Tregister changed into a record
  1331. Revision 1.32 2002/12/15 22:50:00 florian
  1332. + some stuff for the new hidden parameter handling added
  1333. Revision 1.31 2002/12/15 21:30:12 florian
  1334. * tcallnode.paraitem introduced, all references to defcoll removed
  1335. Revision 1.30 2002/11/27 20:04:39 peter
  1336. * cdecl array of const fixes
  1337. Revision 1.29 2002/11/25 17:43:17 peter
  1338. * splitted defbase in defutil,symutil,defcmp
  1339. * merged isconvertable and is_equal into compare_defs(_ext)
  1340. * made operator search faster by walking the list only once
  1341. Revision 1.28 2002/11/18 17:31:54 peter
  1342. * pass proccalloption to ret_in_xxx and push_xxx functions
  1343. Revision 1.27 2002/11/16 15:34:30 florian
  1344. * generic location for float results
  1345. Revision 1.26 2002/11/15 01:58:51 peter
  1346. * merged changes from 1.0.7 up to 04-11
  1347. - -V option for generating bug report tracing
  1348. - more tracing for option parsing
  1349. - errors for cdecl and high()
  1350. - win32 import stabs
  1351. - win32 records<=8 are returned in eax:edx (turned off by default)
  1352. - heaptrc update
  1353. - more info for temp management in .s file with EXTDEBUG
  1354. Revision 1.25 2002/10/05 12:43:25 carl
  1355. * fixes for Delphi 6 compilation
  1356. (warning : Some features do not work under Delphi)
  1357. Revision 1.24 2002/09/30 07:00:45 florian
  1358. * fixes to common code to get the alpha compiler compiled applied
  1359. Revision 1.23 2002/09/17 18:54:02 jonas
  1360. * a_load_reg_reg() now has two size parameters: source and dest. This
  1361. allows some optimizations on architectures that don't encode the
  1362. register size in the register name.
  1363. Revision 1.22 2002/09/07 15:25:02 peter
  1364. * old logs removed and tabs fixed
  1365. Revision 1.21 2002/09/07 11:50:02 jonas
  1366. * fixed small regalloction info bug
  1367. Revision 1.20 2002/09/02 11:25:20 florian
  1368. * fixed generic procedure variable calling
  1369. Revision 1.19 2002/09/01 21:04:48 florian
  1370. * several powerpc related stuff fixed
  1371. Revision 1.18 2002/09/01 18:43:27 peter
  1372. * include FUNCTION_RETURN_REG in regs_to_push list
  1373. Revision 1.17 2002/09/01 12:13:00 peter
  1374. * use a_call_reg
  1375. * ungetiftemp for procvar of object temp
  1376. Revision 1.16 2002/08/25 19:25:18 peter
  1377. * sym.insert_in_data removed
  1378. * symtable.insertvardata/insertconstdata added
  1379. * removed insert_in_data call from symtable.insert, it needs to be
  1380. called separatly. This allows to deref the address calculation
  1381. * procedures now calculate the parast addresses after the procedure
  1382. directives are parsed. This fixes the cdecl parast problem
  1383. * push_addr_param has an extra argument that specifies if cdecl is used
  1384. or not
  1385. Revision 1.15 2002/08/23 16:14:48 peter
  1386. * tempgen cleanup
  1387. * tt_noreuse temp type added that will be used in genentrycode
  1388. Revision 1.14 2002/08/20 16:55:38 peter
  1389. * don't write (stabs)line info when inlining a procedure
  1390. Revision 1.13 2002/08/19 19:36:42 peter
  1391. * More fixes for cross unit inlining, all tnodes are now implemented
  1392. * Moved pocall_internconst to po_internconst because it is not a
  1393. calling type at all and it conflicted when inlining of these small
  1394. functions was requested
  1395. Revision 1.12 2002/08/18 20:06:23 peter
  1396. * inlining is now also allowed in interface
  1397. * renamed write/load to ppuwrite/ppuload
  1398. * tnode storing in ppu
  1399. * nld,ncon,nbas are already updated for storing in ppu
  1400. Revision 1.11 2002/08/17 22:09:44 florian
  1401. * result type handling in tcgcal.pass_2 overhauled
  1402. * better tnode.dowrite
  1403. * some ppc stuff fixed
  1404. Revision 1.10 2002/08/17 09:23:35 florian
  1405. * first part of procinfo rewrite
  1406. Revision 1.9 2002/08/13 21:40:55 florian
  1407. * more fixes for ppc calling conventions
  1408. Revision 1.8 2002/08/13 18:01:51 carl
  1409. * rename swatoperands to swapoperands
  1410. + m68k first compilable version (still needs a lot of testing):
  1411. assembler generator, system information , inline
  1412. assembler reader.
  1413. Revision 1.7 2002/08/12 15:08:39 carl
  1414. + stab register indexes for powerpc (moved from gdb to cpubase)
  1415. + tprocessor enumeration moved to cpuinfo
  1416. + linker in target_info is now a class
  1417. * many many updates for m68k (will soon start to compile)
  1418. - removed some ifdef or correct them for correct cpu
  1419. Revision 1.6 2002/08/11 14:32:26 peter
  1420. * renamed current_library to objectlibrary
  1421. Revision 1.5 2002/08/11 13:24:11 peter
  1422. * saving of asmsymbols in ppu supported
  1423. * asmsymbollist global is removed and moved into a new class
  1424. tasmlibrarydata that will hold the info of a .a file which
  1425. corresponds with a single module. Added librarydata to tmodule
  1426. to keep the library info stored for the module. In the future the
  1427. objectfiles will also be stored to the tasmlibrarydata class
  1428. * all getlabel/newasmsymbol and friends are moved to the new class
  1429. Revision 1.4 2002/08/06 20:55:20 florian
  1430. * first part of ppc calling conventions fix
  1431. Revision 1.3 2002/07/20 11:57:53 florian
  1432. * types.pas renamed to defbase.pas because D6 contains a types
  1433. unit so this would conflicts if D6 programms are compiled
  1434. + Willamette/SSE2 instructions to assembler added
  1435. Revision 1.2 2002/07/13 19:38:43 florian
  1436. * some more generic calling stuff fixed
  1437. }