ncgcal.pas 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate i386 assembler for in 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. { $define AnsiStrRef}
  22. uses
  23. cpubase,
  24. globtype,
  25. symdef,node,ncal;
  26. type
  27. tcgcallparanode = class(tcallparanode)
  28. procedure secondcallparan(push_from_left_to_right:boolean;calloption:tproccalloption;
  29. para_alignment,para_offset : longint);override;
  30. end;
  31. tcgcallnode = class(tcallnode)
  32. private
  33. procedure release_para_temps;
  34. procedure normal_pass_2;
  35. procedure inlined_pass_2;
  36. protected
  37. refcountedtemp : treference;
  38. procedure handle_return_value;
  39. {# This routine is used to push the current frame pointer
  40. on the stack. This is used in nested routines where the
  41. value of the frame pointer is always pushed as an extra
  42. parameter.
  43. The default handling is the standard handling used on
  44. most stack based machines, where the frame pointer is
  45. the first invisible parameter.
  46. }
  47. function align_parasize:longint;virtual;
  48. procedure pop_parasize(pop_size:longint);virtual;
  49. procedure push_framepointer;virtual;
  50. procedure extra_interrupt_code;virtual;
  51. public
  52. procedure pass_2;override;
  53. end;
  54. implementation
  55. uses
  56. systems,
  57. cutils,verbose,globals,
  58. symconst,symbase,symsym,symtable,defutil,paramgr,
  59. {$ifdef GDB}
  60. {$ifdef delphi}
  61. sysutils,
  62. {$else}
  63. strings,
  64. {$endif}
  65. gdb,
  66. {$endif GDB}
  67. cginfo,cgbase,pass_2,
  68. cpuinfo,aasmbase,aasmtai,aasmcpu,
  69. nbas,nmem,nld,ncnv,
  70. {$ifdef x86}
  71. cga,
  72. {$endif x86}
  73. {$ifdef cpu64bit}
  74. cg64f64,
  75. {$else cpu64bit}
  76. cg64f32,
  77. {$endif cpu64bit}
  78. {$ifdef powerpc}
  79. cpupi,
  80. {$endif powerpc}
  81. ncgutil,cgobj,tgobj,regvars,rgobj,rgcpu;
  82. {*****************************************************************************
  83. TCGCALLPARANODE
  84. *****************************************************************************}
  85. procedure tcgcallparanode.secondcallparan(push_from_left_to_right:boolean;calloption:tproccalloption;para_alignment,para_offset : longint);
  86. var
  87. otlabel,
  88. oflabel : tasmlabel;
  89. tmpreg : tregister;
  90. href : treference;
  91. begin
  92. if not(assigned(paraitem.paratype.def) or
  93. assigned(paraitem.parasym)) then
  94. internalerror(200304242);
  95. { set default para_alignment to target_info.stackalignment }
  96. if para_alignment=0 then
  97. para_alignment:=aktalignment.paraalign;
  98. { push from left to right if specified }
  99. if push_from_left_to_right and assigned(right) then
  100. begin
  101. tcallparanode(right).secondcallparan(push_from_left_to_right,
  102. calloption,para_alignment,para_offset);
  103. end;
  104. otlabel:=truelabel;
  105. oflabel:=falselabel;
  106. objectlibrary.getlabel(truelabel);
  107. objectlibrary.getlabel(falselabel);
  108. secondpass(left);
  109. { allocate paraloc }
  110. paramanager.allocparaloc(exprasmlist,paraitem.callerparaloc);
  111. { handle varargs first, because defcoll is not valid }
  112. if (nf_varargs_para in flags) then
  113. begin
  114. if paramanager.push_addr_param(left.resulttype.def,calloption) then
  115. begin
  116. inc(pushedparasize,POINTER_SIZE);
  117. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  118. location_release(exprasmlist,left.location);
  119. end
  120. else
  121. push_value_para(exprasmlist,left,calloption,para_offset,para_alignment,paraitem.callerparaloc);
  122. end
  123. { hidden parameters }
  124. else if paraitem.is_hidden then
  125. begin
  126. { don't push a node that already generated a pointer type
  127. by address for implicit hidden parameters }
  128. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  129. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  130. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  131. begin
  132. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  133. internalerror(200305071);
  134. inc(pushedparasize,POINTER_SIZE);
  135. if calloption=pocall_inline then
  136. begin
  137. {$ifdef newra}
  138. tmpreg:=rg.getaddressregister(exprasmlist);
  139. {$else}
  140. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  141. {$endif}
  142. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  143. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  144. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  145. {$ifdef newra}
  146. rg.ungetregisterint(exprasmlist,tmpreg);
  147. {$else}
  148. cg.free_scratch_reg(exprasmlist,tmpreg);
  149. {$endif}
  150. end
  151. else
  152. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  153. location_release(exprasmlist,left.location);
  154. end
  155. else
  156. begin
  157. push_value_para(exprasmlist,left,calloption,
  158. para_offset,para_alignment,paraitem.callerparaloc);
  159. end;
  160. end
  161. { filter array of const c styled args }
  162. else if is_array_of_const(left.resulttype.def) and (nf_cargs in left.flags) then
  163. begin
  164. { nothing, everything is already pushed }
  165. end
  166. { in codegen.handleread.. paraitem.data is set to nil }
  167. else if assigned(paraitem.paratype.def) and
  168. (paraitem.paratype.def.deftype=formaldef) then
  169. begin
  170. { allow passing of a constant to a const formaldef }
  171. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  172. (left.location.loc=LOC_CONSTANT) then
  173. location_force_mem(exprasmlist,left.location);
  174. { allow @var }
  175. inc(pushedparasize,POINTER_SIZE);
  176. if (left.nodetype=addrn) and
  177. (not(nf_procvarload in left.flags)) then
  178. begin
  179. if calloption=pocall_inline then
  180. begin
  181. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  182. cg.a_load_loc_ref(exprasmlist,OS_ADDR,left.location,href);
  183. end
  184. else
  185. cg.a_param_loc(exprasmlist,left.location,paraitem.callerparaloc);
  186. location_release(exprasmlist,left.location);
  187. end
  188. else
  189. begin
  190. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  191. internalerror(200304235);
  192. if calloption=pocall_inline then
  193. begin
  194. {$ifdef newra}
  195. tmpreg:=rg.getaddressregister(exprasmlist);
  196. {$else}
  197. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  198. {$endif newra}
  199. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  200. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  201. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  202. {$ifdef newra}
  203. rg.ungetregisterint(exprasmlist,tmpreg);
  204. {$else}
  205. cg.free_scratch_reg(exprasmlist,tmpreg);
  206. {$endif}
  207. end
  208. else
  209. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  210. location_release(exprasmlist,left.location);
  211. end;
  212. end
  213. { handle call by reference parameter }
  214. else if (paraitem.paratyp in [vs_var,vs_out]) then
  215. begin
  216. if (left.location.loc<>LOC_REFERENCE) then
  217. begin
  218. { passing self to a var parameter is allowed in
  219. TP and delphi }
  220. if not((left.location.loc=LOC_CREFERENCE) and
  221. is_self_node(left)) then
  222. internalerror(200106041);
  223. end;
  224. if (paraitem.paratyp=vs_out) and
  225. assigned(paraitem.paratype.def) and
  226. not is_class(paraitem.paratype.def) and
  227. paraitem.paratype.def.needs_inittable then
  228. cg.g_finalize(exprasmlist,paraitem.paratype.def,left.location.reference,false);
  229. inc(pushedparasize,POINTER_SIZE);
  230. if calloption=pocall_inline then
  231. begin
  232. {$ifdef newra}
  233. tmpreg:=rg.getaddressregister(exprasmlist);
  234. {$else}
  235. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  236. {$endif}
  237. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  238. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  239. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  240. {$ifdef newra}
  241. rg.ungetregisterint(exprasmlist,tmpreg);
  242. {$else}
  243. cg.free_scratch_reg(exprasmlist,tmpreg);
  244. {$endif}
  245. end
  246. else
  247. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  248. location_release(exprasmlist,left.location);
  249. end
  250. else
  251. begin
  252. { don't push a node that already generated a pointer type
  253. by address for implicit hidden parameters }
  254. if (not(
  255. paraitem.is_hidden and
  256. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  257. ) and
  258. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  259. begin
  260. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  261. begin
  262. { allow passing nil to a procvardef (methodpointer) }
  263. if (left.nodetype=typeconvn) and
  264. (left.resulttype.def.deftype=procvardef) and
  265. (ttypeconvnode(left).left.nodetype=niln) then
  266. begin
  267. tg.GetTemp(exprasmlist,tcgsize2size[left.location.size],tt_normal,href);
  268. if not (left.location.size in [OS_64,OS_S64]) then
  269. cg.a_load_loc_ref(exprasmlist,left.location.size,left.location,href)
  270. else
  271. cg64.a_load64_loc_ref(exprasmlist,left.location,href);
  272. location_reset(left.location,LOC_REFERENCE,left.location.size);
  273. left.location.reference:=href;
  274. end
  275. else
  276. internalerror(200204011);
  277. end;
  278. inc(pushedparasize,POINTER_SIZE);
  279. if calloption=pocall_inline then
  280. begin
  281. {$ifdef newra}
  282. tmpreg:=rg.getaddressregister(exprasmlist);
  283. {$else}
  284. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  285. {$endif}
  286. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  287. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  288. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  289. {$ifdef newra}
  290. rg.ungetregisterint(exprasmlist,tmpreg);
  291. {$else}
  292. cg.free_scratch_reg(exprasmlist,tmpreg);
  293. {$endif}
  294. end
  295. else
  296. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  297. location_release(exprasmlist,left.location);
  298. end
  299. else
  300. begin
  301. push_value_para(exprasmlist,left,calloption,
  302. para_offset,para_alignment,paraitem.callerparaloc);
  303. end;
  304. end;
  305. truelabel:=otlabel;
  306. falselabel:=oflabel;
  307. { update return location in callnode when this is the function
  308. result }
  309. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  310. begin
  311. location_copy(aktcallnode.location,left.location);
  312. end;
  313. { push from right to left }
  314. if not push_from_left_to_right and assigned(right) then
  315. begin
  316. tcallparanode(right).secondcallparan(push_from_left_to_right,
  317. calloption,para_alignment,para_offset);
  318. end;
  319. end;
  320. {*****************************************************************************
  321. TCGCALLNODE
  322. *****************************************************************************}
  323. procedure tcgcallnode.extra_interrupt_code;
  324. begin
  325. end;
  326. function tcgcallnode.align_parasize:longint;
  327. begin
  328. result:=0;
  329. end;
  330. procedure tcgcallnode.pop_parasize(pop_size:longint);
  331. begin
  332. end;
  333. procedure tcgcallnode.push_framepointer;
  334. var
  335. href : treference;
  336. hregister : tregister;
  337. i : integer;
  338. begin
  339. { this routine is itself not nested }
  340. if current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel) then
  341. begin
  342. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  343. cg.a_param_ref(exprasmlist,OS_ADDR,href,paramanager.getintparaloc(exprasmlist,1));
  344. end
  345. { one nesting level }
  346. else if (current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  347. begin
  348. cg.a_param_reg(exprasmlist,OS_ADDR,current_procinfo.framepointer,paramanager.getintparaloc(exprasmlist,1));
  349. end
  350. { very complex nesting level ... }
  351. else if (current_procinfo.procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  352. begin
  353. hregister:=rg.getaddressregister(exprasmlist);
  354. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  355. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,hregister);
  356. i:=current_procinfo.procdef.parast.symtablelevel;
  357. while (i>tprocdef(procdefinition).parast.symtablelevel) do
  358. begin
  359. reference_reset_base(href,hregister,current_procinfo.framepointer_offset);
  360. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,hregister);
  361. dec(i);
  362. end;
  363. cg.a_param_reg(exprasmlist,OS_ADDR,hregister,paramanager.getintparaloc(exprasmlist,1));
  364. rg.ungetaddressregister(exprasmlist,hregister);
  365. end;
  366. end;
  367. procedure tcgcallnode.handle_return_value;
  368. var
  369. cgsize : tcgsize;
  370. r,hregister : tregister;
  371. href: treference;
  372. tempnode: tnode;
  373. begin
  374. { structured results are easy to handle.... }
  375. { needed also when result_no_used !! }
  376. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  377. begin
  378. { Location should be setup by the funcret para }
  379. if location.loc<>LOC_REFERENCE then
  380. internalerror(200304241);
  381. end
  382. else
  383. { ansi/widestrings must be registered, so we can dispose them }
  384. if is_ansistring(resulttype.def) or
  385. is_widestring(resulttype.def) then
  386. begin
  387. r.enum:=R_INTREGISTER;
  388. r.number:=NR_FUNCTION_RETURN_REG;
  389. {$ifdef newra}
  390. { the FUNCTION_RESULT_REG is already allocated }
  391. rg.ungetregisterint(exprasmlist,r);
  392. {$else}
  393. cg.a_reg_alloc(exprasmlist,r);
  394. {$endif}
  395. if not assigned(funcretnode) then
  396. begin
  397. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  398. location.reference:=refcountedtemp;
  399. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,r,location.reference);
  400. {$ifndef newra}
  401. cg.a_reg_dealloc(exprasmlist,r);
  402. {$endif newra}
  403. end
  404. else
  405. begin
  406. {$ifndef newra}
  407. tg.gettemp(exprasmlist,pointer_size,tt_normal,href);
  408. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,r,href);
  409. cg.a_reg_dealloc(exprasmlist,r);
  410. {$else newra}
  411. hregister := rg.getaddressregister(exprasmlist);
  412. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,r,hregister);
  413. {$endif newra}
  414. { in case of a regular funcretnode with ret_in_param, the }
  415. { original funcretnode isn't touched -> make sure it's }
  416. { the same here (not sure if it's necessary) }
  417. tempnode := funcretnode.getcopy;
  418. tempnode.pass_2;
  419. location := tempnode.location;
  420. tempnode.free;
  421. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference, false);
  422. {$ifndef newra}
  423. cg.a_load_ref_ref(exprasmlist,OS_ADDR,OS_ADDR,href,location.reference);
  424. { since we used a normal temp, it won't be finalized or }
  425. { decref'd later -> no need to zero it }
  426. tg.ungettemp(exprasmlist,href);
  427. {$else newra}
  428. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  429. rg.ungetregisterint(exprasmlist,hregister);
  430. {$endif newra}
  431. end;
  432. end
  433. else
  434. { we have only to handle the result if it is used }
  435. if (nf_return_value_used in flags) then
  436. begin
  437. if (resulttype.def.deftype=floatdef) then
  438. begin
  439. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  440. {$ifdef cpufpemu}
  441. if cs_fp_emulation in aktmoduleswitches then
  442. location.register.enum := FUNCTION_RESULT_REG
  443. else
  444. {$endif cpufpemu}
  445. location.register.enum:=FPU_RESULT_REG;
  446. {$ifdef x86}
  447. inc(trgcpu(rg).fpuvaroffset);
  448. {$else x86}
  449. hregister := rg.getregisterfpu(exprasmlist,location.size);
  450. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  451. location.register := hregister;
  452. {$endif x86}
  453. end
  454. else
  455. begin
  456. cgsize:=def_cgsize(resulttype.def);
  457. { an object constructor is a function with pointer result }
  458. if (procdefinition.proctypeoption=potype_constructor) then
  459. cgsize:=OS_ADDR;
  460. if cgsize<>OS_NO then
  461. begin
  462. location_reset(location,LOC_REGISTER,cgsize);
  463. {$ifndef cpu64bit}
  464. if cgsize in [OS_64,OS_S64] then
  465. begin
  466. { Move the function result to free registers, preferably the
  467. FUNCTION_RESULT_REG/FUNCTION_RESULTHIGH_REG, so no move is necessary.}
  468. r.enum:=R_INTREGISTER;
  469. r.number:=NR_FUNCTION_RESULT64_LOW_REG;
  470. hregister.enum:=R_INTREGISTER;
  471. hregister.number:=NR_FUNCTION_RESULT64_HIGH_REG;
  472. {$ifdef newra}
  473. { the FUNCTION_RESULT_LOW_REG/FUNCTION_RESULT_HIGH_REG
  474. are already allocated }
  475. rg.ungetregisterint(exprasmlist,r);
  476. rg.ungetregisterint(exprasmlist,hregister);
  477. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  478. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  479. {$else newra}
  480. if RS_FUNCTION_RESULT64_LOW_REG in rg.unusedregsint then
  481. location.registerlow:=rg.getexplicitregisterint(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG)
  482. else
  483. cg.a_reg_alloc(exprasmlist,r);
  484. if RS_FUNCTION_RESULT64_HIGH_REG in rg.unusedregsint then
  485. location.registerhigh:=rg.getexplicitregisterint(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG)
  486. else
  487. cg.a_reg_alloc(exprasmlist,hregister);
  488. { do this after both low,high are allocated, else it is possible that
  489. low will be loaded in the register that still contains high }
  490. if location.registerlow.number=NR_NO then
  491. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  492. if location.registerhigh.number=NR_NO then
  493. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  494. {$endif newra}
  495. cg64.a_load64_reg_reg(exprasmlist,joinreg64(r,hregister),
  496. location.register64{$ifdef newra},false{$endif});
  497. end
  498. else
  499. {$endif cpu64bit}
  500. begin
  501. {Move the function result to a free register, preferably the
  502. FUNCTION_RESULT_REG, so no move is necessary.}
  503. r.enum:=R_INTREGISTER;
  504. r.number:=NR_FUNCTION_RESULT_REG;
  505. {$ifdef newra}
  506. { the FUNCTION_RESULT_REG is already allocated }
  507. rg.ungetregisterint(exprasmlist,r);
  508. { change register size after the unget because the getregister
  509. was done for the full register }
  510. r:=rg.makeregsize(r,cgsize);
  511. location.register:=rg.getregisterint(exprasmlist,cgsize);
  512. {$else newra}
  513. r.enum:=R_INTREGISTER;
  514. r.number:=NR_FUNCTION_RESULT_REG;
  515. r:=rg.makeregsize(r,cgsize);
  516. cg.a_reg_alloc(exprasmlist,r);
  517. if RS_FUNCTION_RESULT_REG in rg.unusedregsint then
  518. begin
  519. location.register:=rg.makeregsize(rg.getexplicitregisterint(
  520. exprasmlist,NR_FUNCTION_RESULT_REG),cgsize);
  521. end
  522. else
  523. location.register:=rg.getregisterint(exprasmlist,cgsize);
  524. {$endif newra}
  525. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,r,location.register);
  526. end;
  527. end
  528. else
  529. begin
  530. if resulttype.def.size>0 then
  531. internalerror(200305131);
  532. end;
  533. end;
  534. end
  535. else
  536. begin
  537. {$ifdef newra}
  538. cgsize:=def_cgsize(resulttype.def);
  539. { an object constructor is a function with pointer result }
  540. if (procdefinition.proctypeoption=potype_constructor) then
  541. cgsize:=OS_ADDR;
  542. if cgsize<>OS_NO then
  543. {$ifndef cpu64bit}
  544. if cgsize in [OS_64,OS_S64] then
  545. begin
  546. r.enum:=R_INTREGISTER;
  547. r.number:=NR_FUNCTION_RESULT64_LOW_REG;
  548. hregister.enum:=R_INTREGISTER;
  549. hregister.number:=NR_FUNCTION_RESULT64_HIGH_REG;
  550. rg.ungetregisterint(exprasmlist,r);
  551. rg.ungetregisterint(exprasmlist,hregister);
  552. end
  553. else
  554. {$endif cpu64bit}
  555. begin
  556. r.enum:=R_INTREGISTER;
  557. r.number:=NR_FUNCTION_RESULT_REG;
  558. rg.ungetregisterint(exprasmlist,r);
  559. end;
  560. {$endif newra}
  561. location_reset(location,LOC_VOID,OS_NO);
  562. end;
  563. end;
  564. procedure tcgcallnode.release_para_temps;
  565. var
  566. hp : tnode;
  567. ppn : tcallparanode;
  568. begin
  569. { Release temps from parameters }
  570. ppn:=tcallparanode(left);
  571. while assigned(ppn) do
  572. begin
  573. if assigned(ppn.left) then
  574. begin
  575. { don't release the funcret temp }
  576. if not(vo_is_funcret in tvarsym(ppn.paraitem.parasym).varoptions) then
  577. begin
  578. {$ifdef callparatemp}
  579. { free call-by-reference temps }
  580. if (ppn.left.nodetype = typeconvn) and
  581. (ttypeconvnode(ppn.left).left.nodetype = derefn) and
  582. (tderefnode(ttypeconvnode(ppn.left).left).left.nodetype = temprefn) then
  583. location_freetemp(exprasmlist,tderefnode(ttypeconvnode(ppn.left).left).left.location)
  584. else
  585. {$endif callparatemp}
  586. location_freetemp(exprasmlist,ppn.left.location);
  587. end;
  588. { process also all nodes of an array of const }
  589. if ppn.left.nodetype=arrayconstructorn then
  590. begin
  591. if assigned(tarrayconstructornode(ppn.left).left) then
  592. begin
  593. hp:=ppn.left;
  594. while assigned(hp) do
  595. begin
  596. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  597. hp:=tarrayconstructornode(hp).right;
  598. end;
  599. end;
  600. end;
  601. end;
  602. ppn:=tcallparanode(ppn.right);
  603. end;
  604. end;
  605. procedure tcgcallnode.normal_pass_2;
  606. var
  607. regs_to_push_other : tregisterset;
  608. unusedstate: pointer;
  609. {$ifdef newra}
  610. i:Tsuperregister;
  611. regs_to_alloc,regs_to_free:Tsupregset;
  612. funcretloc: tparalocation;
  613. {$else}
  614. regs_to_push_int : Tsupregset;
  615. pushedint : tpushedsavedint;
  616. pushedregs : tmaybesave;
  617. {$endif}
  618. pushedother : tpushedsavedother;
  619. oldpushedparasize : longint;
  620. paraitem : tparaitem;
  621. { adress returned from an I/O-error }
  622. iolabel : tasmlabel;
  623. { help reference pointer }
  624. href,helpref : treference;
  625. para_alignment,
  626. pop_size : longint;
  627. r,
  628. {$ifdef x86}
  629. accreg,
  630. {$endif x86}
  631. vmtreg,vmtreg2 : tregister;
  632. oldaktcallnode : tcallnode;
  633. begin
  634. if not assigned(procdefinition) then
  635. internalerror(200305264);
  636. { calculate the parameter info for the procdef }
  637. if not procdefinition.has_paraloc_info then
  638. begin
  639. paramanager.create_paraloc_info(procdefinition);
  640. procdefinition.has_paraloc_info:=true;
  641. end;
  642. iolabel:=nil;
  643. rg.saveunusedstate(unusedstate);
  644. if not assigned(funcretnode) then
  645. begin
  646. { if we allocate the temp. location for ansi- or widestrings }
  647. { already here, we avoid later a push/pop }
  648. if is_widestring(resulttype.def) then
  649. begin
  650. tg.gettemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  651. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  652. end
  653. else if is_ansistring(resulttype.def) then
  654. begin
  655. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  656. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  657. end;
  658. end;
  659. if (procdefinition.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_stdcall]) then
  660. para_alignment:=4
  661. else
  662. para_alignment:=aktalignment.paraalign;
  663. { proc variables destroy all registers }
  664. if (right=nil) and
  665. { virtual methods too }
  666. not(po_virtualmethod in procdefinition.procoptions) then
  667. begin
  668. if (cs_check_io in aktlocalswitches) and
  669. (po_iocheck in procdefinition.procoptions) and
  670. not(po_iocheck in current_procinfo.procdef.procoptions) then
  671. begin
  672. objectlibrary.getaddrlabel(iolabel);
  673. cg.a_label(exprasmlist,iolabel);
  674. end
  675. else
  676. iolabel:=nil;
  677. {$ifdef newra}
  678. regs_to_alloc:=Tprocdef(procdefinition).usedintregisters;
  679. if (not is_void(resulttype.def)) and
  680. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  681. begin
  682. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  683. case funcretloc.loc of
  684. LOC_REGISTER,LOC_CREGISTER:
  685. begin
  686. {$ifndef cpu64bit}
  687. if funcretloc.size in [OS_S64,OS_64] then
  688. begin
  689. include(regs_to_alloc,funcretloc.registerlow.number shr 8);
  690. include(regs_to_alloc,funcretloc.registerhigh.number shr 8);
  691. end
  692. else
  693. {$endif cpu64bit}
  694. include(regs_to_alloc,funcretloc.register.number shr 8);
  695. end;
  696. end;
  697. end;
  698. {$else}
  699. { save all used registers and possible registers
  700. used for the return value }
  701. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  702. if (not is_void(resulttype.def)) and
  703. (not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  704. begin
  705. {$ifndef cpu64bit}
  706. if resulttype.def.size>sizeof(aword) then
  707. begin
  708. include(regs_to_push_int,RS_FUNCTION_RESULT64_LOW_REG);
  709. include(regs_to_push_int,RS_FUNCTION_RESULT64_HIGH_REG);
  710. end
  711. else
  712. {$endif cpu64bit}
  713. include(regs_to_push_int,RS_FUNCTION_RESULT_REG);
  714. end;
  715. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  716. {$endif}
  717. {$ifdef i386}
  718. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  719. {$else i386}
  720. regs_to_push_other := [];
  721. {$endif i386}
  722. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  723. { on the ppc, ever procedure saves the non-volatile registers it uses itself }
  724. { and must make sure it saves its volatile registers before doing a call }
  725. {$ifdef i386}
  726. { give used registers through }
  727. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  728. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  729. {$endif i386}
  730. end
  731. else
  732. begin
  733. {No procedure is allowed to destroy ebp.}
  734. {$ifdef newra}
  735. regs_to_alloc:=VOLATILE_INTREGISTERS-[RS_FRAME_POINTER_REG];
  736. if (not is_void(resulttype.def)) and
  737. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  738. begin
  739. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  740. case funcretloc.loc of
  741. LOC_REGISTER,LOC_CREGISTER:
  742. begin
  743. {$ifndef cpu64bit}
  744. if funcretloc.size in [OS_S64,OS_64] then
  745. begin
  746. include(regs_to_alloc,funcretloc.registerlow.number shr 8);
  747. include(regs_to_alloc,funcretloc.registerhigh.number shr 8);
  748. end
  749. else
  750. {$endif cpu64bit}
  751. include(regs_to_alloc,funcretloc.register.number shr 8);
  752. end;
  753. end;
  754. end;
  755. {$else}
  756. regs_to_push_int := VOLATILE_INTREGISTERS-[RS_FRAME_POINTER_REG];
  757. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  758. {$endif}
  759. {$ifdef i386}
  760. regs_to_push_other := all_registers;
  761. {$else i386}
  762. regs_to_push_other := [];
  763. {$endif i386}
  764. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  765. {$ifdef i386}
  766. rg.used_in_proc_other:=all_registers;
  767. {$endif i386}
  768. { no IO check for methods and procedure variables }
  769. iolabel:=nil;
  770. end;
  771. { Initialize for pushing the parameters }
  772. oldpushedparasize:=pushedparasize;
  773. pushedparasize:=0;
  774. { Align stack if required }
  775. pop_size:=align_parasize;
  776. { Push parameters }
  777. oldaktcallnode:=aktcallnode;
  778. aktcallnode:=self;
  779. {$ifndef i386}
  780. { process procvar. Done here already, because otherwise it may }
  781. { destroy registers containing a parameter for the actual }
  782. { function call (e.g. if it's a function, its result will }
  783. { overwrite r3, which contains the first parameter) (JM) }
  784. if assigned(right) then
  785. secondpass(right);
  786. if (po_virtualmethod in procdefinition.procoptions) and
  787. assigned(methodpointer) then
  788. begin
  789. secondpass(methodpointer);
  790. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  791. { virtual methods require an index }
  792. if tprocdef(procdefinition).extnumber=-1 then
  793. internalerror(200304021);
  794. { VMT should already be loaded in a register }
  795. if methodpointer.location.register.number=NR_NO then
  796. internalerror(200304022);
  797. { test validity of VMT }
  798. if not(is_interface(tprocdef(procdefinition)._class)) and
  799. not(is_cppclass(tprocdef(procdefinition)._class)) then
  800. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  801. end;
  802. {$endif not i386}
  803. if assigned(left) then
  804. begin
  805. {$ifndef newra}
  806. if assigned(right) then
  807. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  808. else
  809. if assigned(methodpointer) then
  810. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  811. {$endif}
  812. tcallparanode(left).secondcallparan(
  813. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  814. para_alignment,0);
  815. {$ifndef newra}
  816. if assigned(right) then
  817. maybe_restore(exprasmlist,right.location,pushedregs)
  818. else
  819. if assigned(methodpointer) then
  820. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  821. {$endif newra}
  822. end;
  823. aktcallnode:=oldaktcallnode;
  824. { procedure variable or normal function call ? }
  825. if (right=nil) then
  826. begin
  827. { push base pointer ?}
  828. if (current_procinfo.procdef.parast.symtablelevel>=normal_function_level) and
  829. assigned(tprocdef(procdefinition).parast) and
  830. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  831. push_framepointer;
  832. {$ifndef newra}
  833. rg.saveintregvars(exprasmlist,regs_to_push_int);
  834. {$endif}
  835. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  836. if (po_virtualmethod in procdefinition.procoptions) and
  837. assigned(methodpointer) then
  838. begin
  839. {$ifdef i386}
  840. secondpass(methodpointer);
  841. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  842. vmtreg:=methodpointer.location.register;
  843. { virtual methods require an index }
  844. if tprocdef(procdefinition).extnumber=-1 then
  845. internalerror(200304021);
  846. { VMT should already be loaded in a register }
  847. if vmtreg.number=NR_NO then
  848. internalerror(200304022);
  849. { test validity of VMT }
  850. if not(is_interface(tprocdef(procdefinition)._class)) and
  851. not(is_cppclass(tprocdef(procdefinition)._class)) then
  852. cg.g_maybe_testvmt(exprasmlist,vmtreg,tprocdef(procdefinition)._class);
  853. {$else}
  854. vmtreg:=methodpointer.location.register;
  855. {$endif}
  856. {$ifdef newra}
  857. { release self }
  858. rg.ungetaddressregister(exprasmlist,vmtreg);
  859. vmtreg2:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  860. rg.ungetregisterint(exprasmlist,vmtreg2);
  861. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,vmtreg,vmtreg2);
  862. {$endif newra}
  863. { free the resources allocated for the parameters }
  864. paraitem:=tparaitem(procdefinition.para.first);
  865. while assigned(paraitem) do
  866. begin
  867. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  868. paraitem:=tparaitem(paraitem.next);
  869. end;
  870. {$ifdef newra}
  871. for i:=first_supreg to last_supreg do
  872. if i in regs_to_alloc then
  873. begin
  874. r.number:=i shl 8 or R_SUBWHOLE;
  875. rg.getexplicitregisterint(exprasmlist,r.number);
  876. end;
  877. {$endif}
  878. { call method }
  879. reference_reset_base(href,{$ifdef newra}vmtreg2{$else}vmtreg{$endif},
  880. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  881. cg.a_call_ref(exprasmlist,href);
  882. {$ifndef newra}
  883. { release self }
  884. rg.ungetaddressregister(exprasmlist,vmtreg);
  885. {$endif}
  886. end
  887. else
  888. begin
  889. { free the resources allocated for the parameters }
  890. paraitem:=tparaitem(procdefinition.para.first);
  891. while assigned(paraitem) do
  892. begin
  893. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  894. paraitem:=tparaitem(paraitem.next);
  895. end;
  896. {$ifdef newra}
  897. for i:=first_supreg to last_supreg do
  898. if i in regs_to_alloc then
  899. begin
  900. r.number:=i shl 8 or R_SUBWHOLE;
  901. rg.getexplicitregisterint(exprasmlist,r.number);
  902. end;
  903. {$endif}
  904. { Calling interrupt from the same code requires some
  905. extra code }
  906. if (po_interrupt in procdefinition.procoptions) then
  907. extra_interrupt_code;
  908. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  909. end;
  910. end
  911. else
  912. { now procedure variable case }
  913. begin
  914. {$ifdef i386}
  915. secondpass(right);
  916. {$endif i386}
  917. {$ifdef newra}
  918. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  919. begin
  920. helpref:=right.location.reference;
  921. if helpref.index.number<>NR_NO then
  922. begin
  923. rg.ungetregisterint(exprasmlist,helpref.index);
  924. helpref.index:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  925. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,
  926. right.location.reference.index,helpref.index);
  927. end;
  928. if helpref.base.number<>NR_NO then
  929. begin
  930. rg.ungetregisterint(exprasmlist,helpref.base);
  931. helpref.base:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  932. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,
  933. right.location.reference.base,helpref.base);
  934. end;
  935. end
  936. else
  937. rg.ungetregisterint(exprasmlist,right.location.register);
  938. reference_release(exprasmlist,helpref);
  939. location_freetemp(exprasmlist,right.location);
  940. {$endif newra}
  941. { free the resources allocated for the parameters }
  942. paraitem:=tparaitem(procdefinition.para.first);
  943. while assigned(paraitem) do
  944. begin
  945. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  946. paraitem:=tparaitem(paraitem.next);
  947. end;
  948. {$ifdef newra}
  949. for i:=first_supreg to last_supreg do
  950. if i in regs_to_alloc then
  951. begin
  952. r.number:=i shl 8 or R_SUBWHOLE;
  953. rg.getexplicitregisterint(exprasmlist,r.number);
  954. end;
  955. {$endif}
  956. { Calling interrupt from the same code requires some
  957. extra code }
  958. if (po_interrupt in procdefinition.procoptions) then
  959. extra_interrupt_code;
  960. {$ifndef newra}
  961. helpref:=right.location.reference;
  962. rg.saveintregvars(exprasmlist,VOLATILE_INTREGISTERS);
  963. {$endif}
  964. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  965. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  966. cg.a_call_ref(exprasmlist,helpref)
  967. else
  968. cg.a_call_reg(exprasmlist,right.location.register);
  969. { cg.a_call_loc(exprasmlist,right.location);}
  970. {$ifndef newra}
  971. location_release(exprasmlist,right.location);
  972. location_freetemp(exprasmlist,right.location);
  973. {$endif newra}
  974. end;
  975. { Need to remove the parameters from the stack? }
  976. if (po_clearstack in procdefinition.procoptions) then
  977. begin
  978. { the old pop_size was already included in pushedparasize }
  979. pop_size:=pushedparasize;
  980. { for Cdecl functions we don't need to pop the funcret when it
  981. was pushed by para }
  982. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  983. dec(pop_size,POINTER_SIZE);
  984. end;
  985. { Remove parameters/alignment from the stack }
  986. if pop_size>0 then
  987. pop_parasize(pop_size);
  988. {$ifdef powerpc}
  989. { this calculation must be done in pass_1 anyway, so don't worry }
  990. if tppcprocinfo(current_procinfo).maxpushedparasize<pushedparasize then
  991. tppcprocinfo(current_procinfo).maxpushedparasize:=pushedparasize;
  992. {$endif powerpc}
  993. { Restore }
  994. pushedparasize:=oldpushedparasize;
  995. rg.restoreunusedstate(unusedstate);
  996. {$ifdef TEMPREGDEBUG}
  997. testregisters32;
  998. {$endif TEMPREGDEBUG}
  999. {$ifdef newra}
  1000. regs_to_free:=regs_to_alloc;
  1001. if (not is_void(resulttype.def)) and
  1002. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  1003. begin
  1004. case funcretloc.loc of
  1005. LOC_REGISTER,LOC_CREGISTER:
  1006. begin
  1007. {$ifndef cpu64bit}
  1008. if funcretloc.size in [OS_S64,OS_64] then
  1009. begin
  1010. exclude(regs_to_free,funcretloc.registerlow.number shr 8);
  1011. exclude(regs_to_free,funcretloc.registerhigh.number shr 8);
  1012. end
  1013. else
  1014. {$endif cpu64bit}
  1015. exclude(regs_to_free,funcretloc.register.number shr 8);
  1016. end;
  1017. end;
  1018. end;
  1019. r.enum:=R_INTREGISTER;
  1020. for i:=first_supreg to last_supreg do
  1021. if i in regs_to_free then
  1022. begin
  1023. r.number:=i shl 8 or R_SUBWHOLE;
  1024. rg.ungetregisterint(exprasmlist,r);
  1025. end;
  1026. {$endif}
  1027. { handle function results }
  1028. if (not is_void(resulttype.def)) then
  1029. handle_return_value
  1030. else
  1031. location_reset(location,LOC_VOID,OS_NO);
  1032. { perhaps i/o check ? }
  1033. if iolabel<>nil then
  1034. begin
  1035. reference_reset_symbol(href,iolabel,0);
  1036. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1037. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1038. paramanager.freeintparaloc(exprasmlist,1);
  1039. end;
  1040. { restore registers }
  1041. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1042. {$ifndef newra}
  1043. rg.restoreusedintregisters(exprasmlist,pushedint);
  1044. {$endif}
  1045. { release temps of paras }
  1046. release_para_temps;
  1047. { if return value is not used }
  1048. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  1049. begin
  1050. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1051. begin
  1052. { data which must be finalized ? }
  1053. if (resulttype.def.needs_inittable) then
  1054. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1055. { release unused temp }
  1056. tg.ungetiftemp(exprasmlist,location.reference)
  1057. end
  1058. else if location.loc=LOC_FPUREGISTER then
  1059. begin
  1060. {$ifdef x86}
  1061. { release FPU stack }
  1062. accreg.enum:=FPU_RESULT_REG;
  1063. emit_reg(A_FSTP,S_NO,accreg);
  1064. {
  1065. dec(trgcpu(rg).fpuvaroffset);
  1066. do NOT decrement as the increment before
  1067. is not called for unused results PM }
  1068. {$endif x86}
  1069. end;
  1070. end;
  1071. end;
  1072. procedure tcgcallnode.inlined_pass_2;
  1073. var
  1074. regs_to_push_int : Tsupregset;
  1075. regs_to_push_other : tregisterset;
  1076. unusedstate: pointer;
  1077. pushedother : tpushedsavedother;
  1078. {$ifndef newra}
  1079. pushedint : tpushedsavedint;
  1080. pushedregs : tmaybesave;
  1081. {$endif}
  1082. funcretloc: tparalocation;
  1083. oldpushedparasize : longint;
  1084. { adress returned from an I/O-error }
  1085. iolabel : tasmlabel;
  1086. { help reference pointer }
  1087. href : treference;
  1088. {$ifdef x86}
  1089. accreg : tregister;
  1090. {$endif x86}
  1091. oldaktcallnode : tcallnode;
  1092. oldprocdef : tprocdef;
  1093. i : longint;
  1094. oldprocinfo : tprocinfo;
  1095. oldinlining_procedure : boolean;
  1096. inlineentrycode,inlineexitcode : TAAsmoutput;
  1097. oldregstate: pointer;
  1098. old_local_fixup,
  1099. old_para_fixup : longint;
  1100. usesacc,usesacchi,usesfpu : boolean;
  1101. pararef,
  1102. localsref : treference;
  1103. {$ifdef GDB}
  1104. startlabel,endlabel : tasmlabel;
  1105. pp : pchar;
  1106. mangled_length : longint;
  1107. {$endif GDB}
  1108. begin
  1109. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  1110. internalerror(200305262);
  1111. oldinlining_procedure:=inlining_procedure;
  1112. oldprocdef:=current_procinfo.procdef;
  1113. oldprocinfo:=current_procinfo;
  1114. { we're inlining a procedure }
  1115. inlining_procedure:=true;
  1116. { calculate the parameter info for the procdef }
  1117. if not procdefinition.has_paraloc_info then
  1118. begin
  1119. paramanager.create_paraloc_info(procdefinition);
  1120. procdefinition.has_paraloc_info:=true;
  1121. end;
  1122. { deallocate the registers used for the current procedure's regvars }
  1123. if assigned(current_procinfo.procdef.regvarinfo) then
  1124. begin
  1125. with pregvarinfo(current_procinfo.procdef.regvarinfo)^ do
  1126. for i := 1 to maxvarregs do
  1127. if assigned(regvars[i]) then
  1128. store_regvar(exprasmlist,regvars[i].reg);
  1129. rg.saveStateForInline(oldregstate);
  1130. { make sure the register allocator knows what the regvars in the }
  1131. { inlined code block are (JM) }
  1132. rg.resetusableregisters;
  1133. rg.clearregistercount;
  1134. {$ifndef newra}
  1135. rg.cleartempgen;
  1136. {$endif}
  1137. if assigned(tprocdef(procdefinition).regvarinfo) then
  1138. with pregvarinfo(tprocdef(procdefinition).regvarinfo)^ do
  1139. for i := 1 to maxvarregs do
  1140. if assigned(regvars[i]) then
  1141. begin
  1142. {Fix me!!}
  1143. {tmpreg:=rg.makeregsize(regvars[i].reg,OS_INT);
  1144. rg.makeregvar(tmpreg);}
  1145. internalerror(200301232);
  1146. end;
  1147. end;
  1148. { create temp procinfo }
  1149. current_procinfo:=cprocinfo.create(nil);
  1150. current_procinfo.procdef:=tprocdef(procdefinition);
  1151. { Localsymtable }
  1152. current_procinfo.procdef.localst.symtablelevel:=oldprocdef.localst.symtablelevel;
  1153. if current_procinfo.procdef.localst.datasize>0 then
  1154. begin
  1155. old_local_fixup:=current_procinfo.procdef.localst.address_fixup;
  1156. tg.GetTemp(exprasmlist,current_procinfo.procdef.localst.datasize,tt_persistent,localsref);
  1157. if tg.direction>0 then
  1158. current_procinfo.procdef.localst.address_fixup:=localsref.offset
  1159. else
  1160. current_procinfo.procdef.localst.address_fixup:=localsref.offset+current_procinfo.procdef.localst.datasize;
  1161. {$ifdef extdebug}
  1162. Comment(V_debug,'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup));
  1163. exprasmList.concat(tai_comment.Create(strpnew(
  1164. 'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup))));
  1165. {$endif extdebug}
  1166. end;
  1167. { Parasymtable }
  1168. current_procinfo.procdef.parast.symtablelevel:=oldprocdef.localst.symtablelevel;
  1169. if current_procinfo.procdef.parast.datasize>0 then
  1170. begin
  1171. old_para_fixup:=current_procinfo.procdef.parast.address_fixup;
  1172. tg.GetTemp(exprasmlist,current_procinfo.procdef.parast.datasize,tt_persistent,pararef);
  1173. current_procinfo.procdef.parast.address_fixup:=pararef.offset;
  1174. {$ifdef extdebug}
  1175. Comment(V_debug,'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup));
  1176. exprasmList.concat(tai_comment.Create(strpnew(
  1177. 'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup))));
  1178. {$endif extdebug}
  1179. end;
  1180. { Calculate offsets }
  1181. current_procinfo.after_header;
  1182. exprasmList.concat(Tai_Marker.Create(InlineStart));
  1183. {$ifdef extdebug}
  1184. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  1185. {$endif extdebug}
  1186. {$ifdef GDB}
  1187. if (cs_debuginfo in aktmoduleswitches) then
  1188. begin
  1189. objectlibrary.getaddrlabel(startlabel);
  1190. objectlibrary.getaddrlabel(endlabel);
  1191. cg.a_label(exprasmlist,startlabel);
  1192. tprocdef(procdefinition).localst.symtabletype:=inlinelocalsymtable;
  1193. procdefinition.parast.symtabletype:=inlineparasymtable;
  1194. { Here we must include the para and local symtable info }
  1195. procdefinition.concatstabto(withdebuglist);
  1196. { set it back for safety }
  1197. tprocdef(procdefinition).localst.symtabletype:=localsymtable;
  1198. procdefinition.parast.symtabletype:=parasymtable;
  1199. mangled_length:=length(oldprocdef.mangledname);
  1200. getmem(pp,mangled_length+50);
  1201. strpcopy(pp,'192,0,0,'+startlabel.name);
  1202. if (target_info.use_function_relative_addresses) then
  1203. begin
  1204. strpcopy(strend(pp),'-');
  1205. strpcopy(strend(pp),oldprocdef.mangledname);
  1206. end;
  1207. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1208. end;
  1209. {$endif GDB}
  1210. iolabel:=nil;
  1211. rg.saveunusedstate(unusedstate);
  1212. { if we allocate the temp. location for ansi- or widestrings }
  1213. { already here, we avoid later a push/pop }
  1214. if is_widestring(resulttype.def) then
  1215. begin
  1216. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  1217. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1218. end
  1219. else if is_ansistring(resulttype.def) then
  1220. begin
  1221. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  1222. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1223. end;
  1224. if (cs_check_io in aktlocalswitches) and
  1225. (po_iocheck in procdefinition.procoptions) and
  1226. not(po_iocheck in current_procinfo.procdef.procoptions) then
  1227. begin
  1228. objectlibrary.getaddrlabel(iolabel);
  1229. cg.a_label(exprasmlist,iolabel);
  1230. end
  1231. else
  1232. iolabel:=nil;
  1233. { save all used registers and possible registers
  1234. used for the return value }
  1235. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  1236. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  1237. if (not is_void(resulttype.def)) and
  1238. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  1239. begin
  1240. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  1241. case funcretloc.loc of
  1242. LOC_REGISTER,LOC_CREGISTER:
  1243. begin
  1244. {$ifndef cpu64bit}
  1245. if funcretloc.size in [OS_S64,OS_64] then
  1246. begin
  1247. include(regs_to_push_int,funcretloc.registerlow.number shr 8);
  1248. include(regs_to_push_int,funcretloc.registerhigh.number shr 8);
  1249. end
  1250. else
  1251. {$endif cpu64bit}
  1252. include(regs_to_push_int,funcretloc.register.number shr 8);
  1253. end;
  1254. end;
  1255. end;
  1256. {$ifndef newra}
  1257. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  1258. {$endif}
  1259. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  1260. {$ifdef i386}
  1261. { give used registers through }
  1262. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  1263. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  1264. {$endif i386}
  1265. { Initialize for pushing the parameters }
  1266. oldpushedparasize:=pushedparasize;
  1267. pushedparasize:=0;
  1268. { Push parameters }
  1269. oldaktcallnode:=aktcallnode;
  1270. aktcallnode:=self;
  1271. if assigned(left) then
  1272. begin
  1273. {$ifndef newra}
  1274. if assigned(right) then
  1275. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  1276. else
  1277. if assigned(methodpointer) then
  1278. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  1279. {$endif}
  1280. { we push from right to left, so start with parameters at the end of
  1281. the parameter block }
  1282. tcallparanode(left).secondcallparan(
  1283. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  1284. 0,procdefinition.parast.address_fixup+procdefinition.parast.datasize);
  1285. {$ifndef newra}
  1286. if assigned(right) then
  1287. maybe_restore(exprasmlist,right.location,pushedregs)
  1288. else
  1289. if assigned(methodpointer) then
  1290. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  1291. {$endif newra}
  1292. end;
  1293. aktcallnode:=oldaktcallnode;
  1294. {$ifndef newra}
  1295. rg.saveintregvars(exprasmlist,regs_to_push_int);
  1296. {$endif}
  1297. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  1298. { takes care of local data initialization }
  1299. inlineentrycode:=TAAsmoutput.Create;
  1300. inlineexitcode:=TAAsmoutput.Create;
  1301. gen_initialize_code(inlineentrycode,true);
  1302. if po_assembler in current_procinfo.procdef.procoptions then
  1303. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  1304. exprasmList.concatlist(inlineentrycode);
  1305. { process the inline code }
  1306. secondpass(inlinecode);
  1307. {$ifdef powerpc}
  1308. { this calculation must be done in pass_1 anyway, so don't worry }
  1309. if tppcprocinfo(current_procinfo).maxpushedparasize<pushedparasize then
  1310. tppcprocinfo(current_procinfo).maxpushedparasize:=pushedparasize;
  1311. {$endif powerpc}
  1312. { Restore }
  1313. pushedparasize:=oldpushedparasize;
  1314. rg.restoreunusedstate(unusedstate);
  1315. {$ifdef TEMPREGDEBUG}
  1316. testregisters32;
  1317. {$endif TEMPREGDEBUG}
  1318. gen_finalize_code(inlineexitcode,true);
  1319. gen_load_return_value(inlineexitcode,usesacc,usesacchi,usesfpu);
  1320. if po_assembler in current_procinfo.procdef.procoptions then
  1321. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  1322. exprasmList.concatlist(inlineexitcode);
  1323. inlineentrycode.free;
  1324. inlineexitcode.free;
  1325. {$ifdef extdebug}
  1326. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  1327. {$endif extdebug}
  1328. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1329. {we can free the local data now, reset also the fixup address }
  1330. if current_procinfo.procdef.localst.datasize>0 then
  1331. begin
  1332. tg.UnGetTemp(exprasmlist,localsref);
  1333. current_procinfo.procdef.localst.address_fixup:=old_local_fixup;
  1334. end;
  1335. {we can free the para data now, reset also the fixup address }
  1336. if current_procinfo.procdef.parast.datasize>0 then
  1337. begin
  1338. tg.UnGetTemp(exprasmlist,pararef);
  1339. current_procinfo.procdef.parast.address_fixup:=old_para_fixup;
  1340. end;
  1341. { free return reference }
  1342. if (resulttype.def.size>0) then
  1343. begin
  1344. { from now on the result can be freed normally }
  1345. // if assigned(funcretnode) and
  1346. // paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1347. // tg.ChangeTempType(exprasmlist,funcretnode.location.reference,tt_normal);
  1348. end;
  1349. { handle function results }
  1350. if (not is_void(resulttype.def)) then
  1351. handle_return_value
  1352. else
  1353. location_reset(location,LOC_VOID,OS_NO);
  1354. { perhaps i/o check ? }
  1355. if iolabel<>nil then
  1356. begin
  1357. reference_reset_symbol(href,iolabel,0);
  1358. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1359. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1360. paramanager.freeintparaloc(exprasmlist,1);
  1361. end;
  1362. { restore registers }
  1363. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1364. {$ifndef newra}
  1365. rg.restoreusedintregisters(exprasmlist,pushedint);
  1366. {$endif}
  1367. { release temps of paras }
  1368. release_para_temps;
  1369. { if return value is not used }
  1370. if (not is_void(resulttype.def)) and
  1371. (not(nf_return_value_used in flags)) then
  1372. begin
  1373. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1374. begin
  1375. { data which must be finalized ? }
  1376. if (resulttype.def.needs_inittable) then
  1377. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1378. { release unused temp }
  1379. tg.ungetiftemp(exprasmlist,location.reference)
  1380. end
  1381. else if location.loc=LOC_FPUREGISTER then
  1382. begin
  1383. {$ifdef x86}
  1384. { release FPU stack }
  1385. accreg.enum:=FPU_RESULT_REG;
  1386. emit_reg(A_FSTP,S_NO,accreg);
  1387. {
  1388. dec(trgcpu(rg).fpuvaroffset);
  1389. do NOT decrement as the increment before
  1390. is not called for unused results PM }
  1391. {$endif x86}
  1392. end;
  1393. end;
  1394. { release procinfo }
  1395. current_procinfo.free;
  1396. current_procinfo:=oldprocinfo;
  1397. {$ifdef GDB}
  1398. if (cs_debuginfo in aktmoduleswitches) then
  1399. begin
  1400. cg.a_label(exprasmlist,endlabel);
  1401. strpcopy(pp,'224,0,0,'+endlabel.name);
  1402. if (target_info.use_function_relative_addresses) then
  1403. begin
  1404. strpcopy(strend(pp),'-');
  1405. strpcopy(strend(pp),oldprocdef.mangledname);
  1406. end;
  1407. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1408. freemem(pp,mangled_length+50);
  1409. end;
  1410. {$endif GDB}
  1411. { restore }
  1412. current_procinfo.procdef:=oldprocdef;
  1413. inlining_procedure:=oldinlining_procedure;
  1414. { reallocate the registers used for the current procedure's regvars, }
  1415. { since they may have been used and then deallocated in the inlined }
  1416. { procedure (JM) }
  1417. if assigned(current_procinfo.procdef.regvarinfo) then
  1418. rg.restoreStateAfterInline(oldregstate);
  1419. end;
  1420. procedure tcgcallnode.pass_2;
  1421. begin
  1422. if assigned(inlinecode) then
  1423. inlined_pass_2
  1424. else
  1425. normal_pass_2;
  1426. end;
  1427. begin
  1428. ccallparanode:=tcgcallparanode;
  1429. ccallnode:=tcgcallnode;
  1430. end.
  1431. {
  1432. $Log$
  1433. Revision 1.96 2003-07-02 22:18:04 peter
  1434. * paraloc splitted in callerparaloc,calleeparaloc
  1435. * sparc calling convention updates
  1436. Revision 1.95 2003/06/17 16:34:44 jonas
  1437. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1438. * renamed all_intregisters to volatile_intregisters and made it
  1439. processor dependent
  1440. Revision 1.94 2003/06/15 16:52:02 jonas
  1441. * release function result registers if the functino result isn't used
  1442. * don't allocate function result register with -dnewra if there is none
  1443. * some optimizations for non-x86 processor (don't save any registers
  1444. before a call)
  1445. Revision 1.93 2003/06/13 21:19:30 peter
  1446. * current_procdef removed, use current_procinfo.procdef instead
  1447. Revision 1.92 2003/06/12 21:10:50 peter
  1448. * newra fixes
  1449. Revision 1.91 2003/06/12 18:38:45 jonas
  1450. * deallocate parameter registers in time for newra
  1451. * for non-i386, procvars and methodpointers always have to be processed
  1452. in advance, whether or not newra is defined
  1453. Revision 1.90 2003/06/09 14:54:26 jonas
  1454. * (de)allocation of registers for parameters is now performed properly
  1455. (and checked on the ppc)
  1456. - removed obsolete allocation of all parameter registers at the start
  1457. of a procedure (and deallocation at the end)
  1458. Revision 1.89 2003/06/09 12:23:29 peter
  1459. * init/final of procedure data splitted from genentrycode
  1460. * use asmnode getposition to insert final at the correct position
  1461. als for the implicit try...finally
  1462. Revision 1.88 2003/06/08 20:01:53 jonas
  1463. * optimized assignments with on the right side a function that returns
  1464. an ansi- or widestring
  1465. Revision 1.87 2003/06/08 18:21:47 jonas
  1466. * fixed weird error in the copyleft statement :)
  1467. Revision 1.86 2003/06/07 18:57:04 jonas
  1468. + added freeintparaloc
  1469. * ppc get/freeintparaloc now check whether the parameter regs are
  1470. properly allocated/deallocated (and get an extra list para)
  1471. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1472. * fixed lot of missing pi_do_call's
  1473. Revision 1.85 2003/06/04 06:43:36 jonas
  1474. * fixed double secondpassing of procvar loads
  1475. Revision 1.84 2003/06/03 21:11:09 peter
  1476. * cg.a_load_* get a from and to size specifier
  1477. * makeregsize only accepts newregister
  1478. * i386 uses generic tcgnotnode,tcgunaryminus
  1479. Revision 1.83 2003/06/03 20:27:02 daniel
  1480. * Restored original methodpointer code for non newra case
  1481. Revision 1.82 2003/06/03 13:01:59 daniel
  1482. * Register allocator finished
  1483. Revision 1.81 2003/06/01 21:38:06 peter
  1484. * getregisterfpu size parameter added
  1485. * op_const_reg size parameter added
  1486. * sparc updates
  1487. Revision 1.80 2003/05/31 15:05:28 peter
  1488. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1489. Revision 1.79 2003/05/31 00:59:44 peter
  1490. * typo in FUNCTION_RESULT_REG
  1491. Revision 1.78 2003/05/30 23:57:08 peter
  1492. * more sparc cleanup
  1493. * accumulator removed, splitted in function_return_reg (called) and
  1494. function_result_reg (caller)
  1495. Revision 1.77 2003/05/29 10:05:40 jonas
  1496. * free callparatemps created for call-by-reference parameters
  1497. Revision 1.76 2003/05/28 23:58:18 jonas
  1498. * added missing initialization of rg.usedintin,byproc
  1499. * ppc now also saves/restores used fpu registers
  1500. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1501. i386
  1502. Revision 1.75 2003/05/26 21:17:17 peter
  1503. * procinlinenode removed
  1504. * aktexit2label removed, fast exit removed
  1505. + tcallnode.inlined_pass_2 added
  1506. Revision 1.74 2003/05/25 11:34:17 peter
  1507. * methodpointer self pushing fixed
  1508. Revision 1.73 2003/05/25 08:59:16 peter
  1509. * inline fixes
  1510. Revision 1.72 2003/05/24 13:36:54 jonas
  1511. * save fpu results in a normal fpu register on non-x86 processors
  1512. Revision 1.71 2003/05/23 19:35:50 jonas
  1513. - undid previous commit, it was wrong
  1514. Revision 1.70 2003/05/23 19:11:58 jonas
  1515. * fixed tests for whether a certain int register is unused
  1516. Revision 1.69 2003/05/23 18:01:56 jonas
  1517. * fixed ppc compiler
  1518. Revision 1.68 2003/05/23 14:27:35 peter
  1519. * remove some unit dependencies
  1520. * current_procinfo changes to store more info
  1521. Revision 1.67 2003/05/17 13:30:08 jonas
  1522. * changed tt_persistant to tt_persistent :)
  1523. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1524. temps, but a ttemptype, so you can also create ansistring temps etc
  1525. Revision 1.66 2003/05/16 14:33:31 peter
  1526. * regvar fixes
  1527. Revision 1.65 2003/05/15 18:58:53 peter
  1528. * removed selfpointer_offset, vmtpointer_offset
  1529. * tvarsym.adjusted_address
  1530. * address in localsymtable is now in the real direction
  1531. * removed some obsolete globals
  1532. Revision 1.64 2003/05/14 19:36:54 jonas
  1533. * patch from Peter for int64 function results
  1534. Revision 1.63 2003/05/13 19:14:41 peter
  1535. * failn removed
  1536. * inherited result code check moven to pexpr
  1537. Revision 1.62 2003/05/13 15:18:18 peter
  1538. * generate code for procvar first before pushing parameters. Made
  1539. the already existing code for powerpc available for all platforms
  1540. Revision 1.61 2003/05/12 18:17:55 jonas
  1541. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1542. already-loaded parameter registers
  1543. Revision 1.60 2003/05/11 21:48:38 jonas
  1544. * fixed procvar bug on the ppc (load procvar before loading para's,
  1545. because the procvar may otherwise destroy the already loaded paras)
  1546. Revision 1.59 2003/05/09 17:47:02 peter
  1547. * self moved to hidden parameter
  1548. * removed hdisposen,hnewn,selfn
  1549. Revision 1.58 2003/05/05 14:53:16 peter
  1550. * vs_hidden replaced by is_hidden boolean
  1551. Revision 1.57 2003/04/30 20:53:32 florian
  1552. * error when address of an abstract method is taken
  1553. * fixed some x86-64 problems
  1554. * merged some more x86-64 and i386 code
  1555. Revision 1.56 2003/04/29 07:28:52 michael
  1556. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1557. Revision 1.55 2003/04/27 11:21:33 peter
  1558. * aktprocdef renamed to current_procinfo.procdef
  1559. * procinfo renamed to current_procinfo
  1560. * procinfo will now be stored in current_module so it can be
  1561. cleaned up properly
  1562. * gen_main_procsym changed to create_main_proc and release_main_proc
  1563. to also generate a tprocinfo structure
  1564. * fixed unit implicit initfinal
  1565. Revision 1.54 2003/04/27 07:29:50 peter
  1566. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  1567. a new procdef declaration
  1568. * aktprocsym removed
  1569. * lexlevel removed, use symtable.symtablelevel instead
  1570. * implicit init/final code uses the normal genentry/genexit
  1571. * funcret state checking updated for new funcret handling
  1572. Revision 1.53 2003/04/25 20:59:33 peter
  1573. * removed funcretn,funcretsym, function result is now in varsym
  1574. and aliases for result and function name are added using absolutesym
  1575. * vs_hidden parameter for funcret passed in parameter
  1576. * vs_hidden fixes
  1577. * writenode changed to printnode and released from extdebug
  1578. * -vp option added to generate a tree.log with the nodetree
  1579. * nicer printnode for statements, callnode
  1580. Revision 1.52 2003/04/25 08:25:26 daniel
  1581. * Ifdefs around a lot of calls to cleartempgen
  1582. * Fixed registers that are allocated but not freed in several nodes
  1583. * Tweak to register allocator to cause less spills
  1584. * 8-bit registers now interfere with esi,edi and ebp
  1585. Compiler can now compile rtl successfully when using new register
  1586. allocator
  1587. Revision 1.51 2003/04/22 23:50:22 peter
  1588. * firstpass uses expectloc
  1589. * checks if there are differences between the expectloc and
  1590. location.loc from secondpass in EXTDEBUG
  1591. Revision 1.50 2003/04/22 14:33:38 peter
  1592. * removed some notes/hints
  1593. Revision 1.49 2003/04/22 13:47:08 peter
  1594. * fixed C style array of const
  1595. * fixed C array passing
  1596. * fixed left to right with high parameters
  1597. Revision 1.48 2003/04/22 10:09:34 daniel
  1598. + Implemented the actual register allocator
  1599. + Scratch registers unavailable when new register allocator used
  1600. + maybe_save/maybe_restore unavailable when new register allocator used
  1601. Revision 1.47 2003/04/22 09:49:44 peter
  1602. * do not load self when calling a non-inherited class constructor
  1603. Revision 1.46 2003/04/21 20:03:32 peter
  1604. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1605. Revision 1.45 2003/04/21 13:53:16 jonas
  1606. - removed copying of all paras when secondpassing a callnode (this used
  1607. to be necessary for inlinign support, but currently the whole inlined
  1608. procedure is already copied in advance). Note that the compiler crashes
  1609. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1610. syntax errors), but that was also the case before this change.
  1611. Revision 1.44 2003/04/10 17:57:52 peter
  1612. * vs_hidden released
  1613. Revision 1.43 2003/04/06 21:11:23 olle
  1614. * changed newasmsymbol to newasmsymboldata for data symbols
  1615. Revision 1.42 2003/04/04 15:38:56 peter
  1616. * moved generic code from n386cal to ncgcal, i386 now also
  1617. uses the generic ncgcal
  1618. Revision 1.41 2003/03/28 19:16:56 peter
  1619. * generic constructor working for i386
  1620. * remove fixed self register
  1621. * esi added as address register for i386
  1622. Revision 1.40 2003/03/06 11:35:50 daniel
  1623. * Fixed internalerror 7843 issue
  1624. Revision 1.39 2003/02/19 22:00:14 daniel
  1625. * Code generator converted to new register notation
  1626. - Horribily outdated todo.txt removed
  1627. Revision 1.38 2003/02/15 22:17:38 carl
  1628. * bugfix of FPU emulation code
  1629. Revision 1.37 2003/02/12 22:10:07 carl
  1630. * load_frame_pointer is now generic
  1631. * change fpu emulation routine names
  1632. Revision 1.36 2003/01/30 21:46:57 peter
  1633. * self fixes for static methods (merged)
  1634. Revision 1.35 2003/01/22 20:45:15 mazen
  1635. * making math code in RTL compiling.
  1636. *NB : This does NOT mean necessary that it will generate correct code!
  1637. Revision 1.34 2003/01/17 12:03:45 daniel
  1638. * Optalign conditional code adapted to record Tregister
  1639. Revision 1.33 2003/01/08 18:43:56 daniel
  1640. * Tregister changed into a record
  1641. Revision 1.32 2002/12/15 22:50:00 florian
  1642. + some stuff for the new hidden parameter handling added
  1643. Revision 1.31 2002/12/15 21:30:12 florian
  1644. * tcallnode.paraitem introduced, all references to defcoll removed
  1645. Revision 1.30 2002/11/27 20:04:39 peter
  1646. * cdecl array of const fixes
  1647. Revision 1.29 2002/11/25 17:43:17 peter
  1648. * splitted defbase in defutil,symutil,defcmp
  1649. * merged isconvertable and is_equal into compare_defs(_ext)
  1650. * made operator search faster by walking the list only once
  1651. Revision 1.28 2002/11/18 17:31:54 peter
  1652. * pass proccalloption to ret_in_xxx and push_xxx functions
  1653. Revision 1.27 2002/11/16 15:34:30 florian
  1654. * generic location for float results
  1655. Revision 1.26 2002/11/15 01:58:51 peter
  1656. * merged changes from 1.0.7 up to 04-11
  1657. - -V option for generating bug report tracing
  1658. - more tracing for option parsing
  1659. - errors for cdecl and high()
  1660. - win32 import stabs
  1661. - win32 records<=8 are returned in eax:edx (turned off by default)
  1662. - heaptrc update
  1663. - more info for temp management in .s file with EXTDEBUG
  1664. Revision 1.25 2002/10/05 12:43:25 carl
  1665. * fixes for Delphi 6 compilation
  1666. (warning : Some features do not work under Delphi)
  1667. Revision 1.24 2002/09/30 07:00:45 florian
  1668. * fixes to common code to get the alpha compiler compiled applied
  1669. Revision 1.23 2002/09/17 18:54:02 jonas
  1670. * a_load_reg_reg() now has two size parameters: source and dest. This
  1671. allows some optimizations on architectures that don't encode the
  1672. register size in the register name.
  1673. Revision 1.22 2002/09/07 15:25:02 peter
  1674. * old logs removed and tabs fixed
  1675. Revision 1.21 2002/09/07 11:50:02 jonas
  1676. * fixed small regalloction info bug
  1677. Revision 1.20 2002/09/02 11:25:20 florian
  1678. * fixed generic procedure variable calling
  1679. Revision 1.19 2002/09/01 21:04:48 florian
  1680. * several powerpc related stuff fixed
  1681. Revision 1.18 2002/09/01 18:43:27 peter
  1682. * include FUNCTION_RETURN_REG in regs_to_push list
  1683. Revision 1.17 2002/09/01 12:13:00 peter
  1684. * use a_call_reg
  1685. * ungetiftemp for procvar of object temp
  1686. Revision 1.16 2002/08/25 19:25:18 peter
  1687. * sym.insert_in_data removed
  1688. * symtable.insertvardata/insertconstdata added
  1689. * removed insert_in_data call from symtable.insert, it needs to be
  1690. called separatly. This allows to deref the address calculation
  1691. * procedures now calculate the parast addresses after the procedure
  1692. directives are parsed. This fixes the cdecl parast problem
  1693. * push_addr_param has an extra argument that specifies if cdecl is used
  1694. or not
  1695. Revision 1.15 2002/08/23 16:14:48 peter
  1696. * tempgen cleanup
  1697. * tt_noreuse temp type added that will be used in genentrycode
  1698. Revision 1.14 2002/08/20 16:55:38 peter
  1699. * don't write (stabs)line info when inlining a procedure
  1700. Revision 1.13 2002/08/19 19:36:42 peter
  1701. * More fixes for cross unit inlining, all tnodes are now implemented
  1702. * Moved pocall_internconst to po_internconst because it is not a
  1703. calling type at all and it conflicted when inlining of these small
  1704. functions was requested
  1705. Revision 1.12 2002/08/18 20:06:23 peter
  1706. * inlining is now also allowed in interface
  1707. * renamed write/load to ppuwrite/ppuload
  1708. * tnode storing in ppu
  1709. * nld,ncon,nbas are already updated for storing in ppu
  1710. Revision 1.11 2002/08/17 22:09:44 florian
  1711. * result type handling in tcgcal.pass_2 overhauled
  1712. * better tnode.dowrite
  1713. * some ppc stuff fixed
  1714. Revision 1.10 2002/08/17 09:23:35 florian
  1715. * first part of procinfo rewrite
  1716. Revision 1.9 2002/08/13 21:40:55 florian
  1717. * more fixes for ppc calling conventions
  1718. Revision 1.8 2002/08/13 18:01:51 carl
  1719. * rename swatoperands to swapoperands
  1720. + m68k first compilable version (still needs a lot of testing):
  1721. assembler generator, system information , inline
  1722. assembler reader.
  1723. Revision 1.7 2002/08/12 15:08:39 carl
  1724. + stab register indexes for powerpc (moved from gdb to cpubase)
  1725. + tprocessor enumeration moved to cpuinfo
  1726. + linker in target_info is now a class
  1727. * many many updates for m68k (will soon start to compile)
  1728. - removed some ifdef or correct them for correct cpu
  1729. Revision 1.6 2002/08/11 14:32:26 peter
  1730. * renamed current_library to objectlibrary
  1731. Revision 1.5 2002/08/11 13:24:11 peter
  1732. * saving of asmsymbols in ppu supported
  1733. * asmsymbollist global is removed and moved into a new class
  1734. tasmlibrarydata that will hold the info of a .a file which
  1735. corresponds with a single module. Added librarydata to tmodule
  1736. to keep the library info stored for the module. In the future the
  1737. objectfiles will also be stored to the tasmlibrarydata class
  1738. * all getlabel/newasmsymbol and friends are moved to the new class
  1739. Revision 1.4 2002/08/06 20:55:20 florian
  1740. * first part of ppc calling conventions fix
  1741. Revision 1.3 2002/07/20 11:57:53 florian
  1742. * types.pas renamed to defbase.pas because D6 contains a types
  1743. unit so this would conflicts if D6 programms are compiled
  1744. + Willamette/SSE2 instructions to assembler added
  1745. Revision 1.2 2002/07/13 19:38:43 florian
  1746. * some more generic calling stuff fixed
  1747. }