ncgcal.pas 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961
  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,callerside);
  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.deftype<>floatdef then
  707. if resulttype.def.size>sizeof(aword) then
  708. begin
  709. include(regs_to_push_int,RS_FUNCTION_RESULT64_LOW_REG);
  710. include(regs_to_push_int,RS_FUNCTION_RESULT64_HIGH_REG);
  711. end
  712. else
  713. {$endif cpu64bit}
  714. include(regs_to_push_int,RS_FUNCTION_RESULT_REG);
  715. end;
  716. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  717. {$endif}
  718. {$ifdef i386}
  719. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  720. {$else i386}
  721. regs_to_push_other := [];
  722. {$endif i386}
  723. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  724. { on the ppc, ever procedure saves the non-volatile registers it uses itself }
  725. { and must make sure it saves its volatile registers before doing a call }
  726. {$ifdef i386}
  727. { give used registers through }
  728. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  729. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  730. {$endif i386}
  731. end
  732. else
  733. begin
  734. {No procedure is allowed to destroy ebp.}
  735. {$ifdef newra}
  736. regs_to_alloc:=VOLATILE_INTREGISTERS-[RS_FRAME_POINTER_REG,RS_STACK_POINTER_REG];
  737. if (not is_void(resulttype.def)) and
  738. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  739. begin
  740. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  741. case funcretloc.loc of
  742. LOC_REGISTER,LOC_CREGISTER:
  743. begin
  744. {$ifndef cpu64bit}
  745. if funcretloc.size in [OS_S64,OS_64] then
  746. begin
  747. include(regs_to_alloc,funcretloc.registerlow.number shr 8);
  748. include(regs_to_alloc,funcretloc.registerhigh.number shr 8);
  749. end
  750. else
  751. {$endif cpu64bit}
  752. include(regs_to_alloc,funcretloc.register.number shr 8);
  753. end;
  754. end;
  755. end;
  756. {$else}
  757. regs_to_push_int := VOLATILE_INTREGISTERS-[RS_FRAME_POINTER_REG];
  758. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  759. {$endif}
  760. {$ifdef i386}
  761. regs_to_push_other := all_registers;
  762. {$else i386}
  763. regs_to_push_other := [];
  764. {$endif i386}
  765. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  766. {$ifdef i386}
  767. rg.used_in_proc_other:=all_registers;
  768. {$endif i386}
  769. { no IO check for methods and procedure variables }
  770. iolabel:=nil;
  771. end;
  772. { Initialize for pushing the parameters }
  773. oldpushedparasize:=pushedparasize;
  774. pushedparasize:=0;
  775. { Align stack if required }
  776. pop_size:=align_parasize;
  777. { Push parameters }
  778. oldaktcallnode:=aktcallnode;
  779. aktcallnode:=self;
  780. {$ifndef i386}
  781. { process procvar. Done here already, because otherwise it may }
  782. { destroy registers containing a parameter for the actual }
  783. { function call (e.g. if it's a function, its result will }
  784. { overwrite r3, which contains the first parameter) (JM) }
  785. if assigned(right) then
  786. secondpass(right);
  787. if (po_virtualmethod in procdefinition.procoptions) and
  788. assigned(methodpointer) then
  789. begin
  790. secondpass(methodpointer);
  791. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  792. { virtual methods require an index }
  793. if tprocdef(procdefinition).extnumber=-1 then
  794. internalerror(200304021);
  795. { VMT should already be loaded in a register }
  796. if methodpointer.location.register.number=NR_NO then
  797. internalerror(200304022);
  798. { test validity of VMT }
  799. if not(is_interface(tprocdef(procdefinition)._class)) and
  800. not(is_cppclass(tprocdef(procdefinition)._class)) then
  801. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  802. end;
  803. {$endif not i386}
  804. if assigned(left) then
  805. begin
  806. {$ifndef newra}
  807. if assigned(right) then
  808. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  809. else
  810. if assigned(methodpointer) then
  811. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  812. {$endif}
  813. tcallparanode(left).secondcallparan(
  814. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  815. para_alignment,0);
  816. {$ifndef newra}
  817. if assigned(right) then
  818. maybe_restore(exprasmlist,right.location,pushedregs)
  819. else
  820. if assigned(methodpointer) then
  821. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  822. {$endif newra}
  823. end;
  824. aktcallnode:=oldaktcallnode;
  825. { procedure variable or normal function call ? }
  826. if (right=nil) then
  827. begin
  828. { push base pointer ?}
  829. if (current_procinfo.procdef.parast.symtablelevel>=normal_function_level) and
  830. assigned(tprocdef(procdefinition).parast) and
  831. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  832. push_framepointer;
  833. {$ifndef newra}
  834. rg.saveintregvars(exprasmlist,regs_to_push_int);
  835. {$endif}
  836. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  837. if (po_virtualmethod in procdefinition.procoptions) and
  838. assigned(methodpointer) then
  839. begin
  840. {$ifdef i386}
  841. secondpass(methodpointer);
  842. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  843. vmtreg:=methodpointer.location.register;
  844. { virtual methods require an index }
  845. if tprocdef(procdefinition).extnumber=-1 then
  846. internalerror(200304021);
  847. { VMT should already be loaded in a register }
  848. if vmtreg.number=NR_NO then
  849. internalerror(200304022);
  850. { test validity of VMT }
  851. if not(is_interface(tprocdef(procdefinition)._class)) and
  852. not(is_cppclass(tprocdef(procdefinition)._class)) then
  853. cg.g_maybe_testvmt(exprasmlist,vmtreg,tprocdef(procdefinition)._class);
  854. {$else}
  855. vmtreg:=methodpointer.location.register;
  856. {$endif}
  857. {$ifdef newra}
  858. { release self }
  859. rg.ungetaddressregister(exprasmlist,vmtreg);
  860. vmtreg2:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  861. rg.ungetregisterint(exprasmlist,vmtreg2);
  862. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,vmtreg,vmtreg2);
  863. {$endif newra}
  864. { free the resources allocated for the parameters }
  865. paraitem:=tparaitem(procdefinition.para.first);
  866. while assigned(paraitem) do
  867. begin
  868. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  869. paraitem:=tparaitem(paraitem.next);
  870. end;
  871. {$ifdef newra}
  872. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  873. {$endif}
  874. { call method }
  875. reference_reset_base(href,{$ifdef newra}vmtreg2{$else}vmtreg{$endif},
  876. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  877. cg.a_call_ref(exprasmlist,href);
  878. {$ifndef newra}
  879. { release self }
  880. rg.ungetaddressregister(exprasmlist,vmtreg);
  881. {$endif}
  882. end
  883. else
  884. begin
  885. { free the resources allocated for the parameters }
  886. paraitem:=tparaitem(procdefinition.para.first);
  887. while assigned(paraitem) do
  888. begin
  889. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  890. paraitem:=tparaitem(paraitem.next);
  891. end;
  892. {$ifdef newra}
  893. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  894. {$endif}
  895. { Calling interrupt from the same code requires some
  896. extra code }
  897. if (po_interrupt in procdefinition.procoptions) then
  898. extra_interrupt_code;
  899. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  900. end;
  901. end
  902. else
  903. { now procedure variable case }
  904. begin
  905. {$ifdef i386}
  906. secondpass(right);
  907. {$endif i386}
  908. {$ifdef newra}
  909. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  910. begin
  911. helpref:=right.location.reference;
  912. if (helpref.index.number<>NR_NO) and (helpref.index.number<>NR_FRAME_POINTER_REG) then
  913. begin
  914. rg.ungetregisterint(exprasmlist,helpref.index);
  915. helpref.index:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  916. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,
  917. right.location.reference.index,helpref.index);
  918. end;
  919. if (helpref.base.number<>NR_NO) and (helpref.base.number<>NR_FRAME_POINTER_REG) then
  920. begin
  921. rg.ungetregisterint(exprasmlist,helpref.base);
  922. helpref.base:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  923. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,
  924. right.location.reference.base,helpref.base);
  925. end;
  926. end
  927. else
  928. rg.ungetregisterint(exprasmlist,right.location.register);
  929. reference_release(exprasmlist,helpref);
  930. location_freetemp(exprasmlist,right.location);
  931. {$endif newra}
  932. { free the resources allocated for the parameters }
  933. paraitem:=tparaitem(procdefinition.para.first);
  934. while assigned(paraitem) do
  935. begin
  936. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  937. paraitem:=tparaitem(paraitem.next);
  938. end;
  939. {$ifdef newra}
  940. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  941. {$endif}
  942. { Calling interrupt from the same code requires some
  943. extra code }
  944. if (po_interrupt in procdefinition.procoptions) then
  945. extra_interrupt_code;
  946. {$ifndef newra}
  947. helpref:=right.location.reference;
  948. rg.saveintregvars(exprasmlist,VOLATILE_INTREGISTERS);
  949. {$endif}
  950. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  951. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  952. cg.a_call_ref(exprasmlist,helpref)
  953. else
  954. cg.a_call_reg(exprasmlist,right.location.register);
  955. { cg.a_call_loc(exprasmlist,right.location);}
  956. {$ifndef newra}
  957. location_release(exprasmlist,right.location);
  958. location_freetemp(exprasmlist,right.location);
  959. {$endif newra}
  960. end;
  961. { Need to remove the parameters from the stack? }
  962. if (po_clearstack in procdefinition.procoptions) then
  963. begin
  964. { the old pop_size was already included in pushedparasize }
  965. pop_size:=pushedparasize;
  966. { for Cdecl functions we don't need to pop the funcret when it
  967. was pushed by para }
  968. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  969. dec(pop_size,POINTER_SIZE);
  970. end;
  971. { Remove parameters/alignment from the stack }
  972. if pop_size>0 then
  973. pop_parasize(pop_size);
  974. {$ifdef powerpc}
  975. { this calculation must be done in pass_1 anyway, so don't worry }
  976. if tppcprocinfo(current_procinfo).maxpushedparasize<pushedparasize then
  977. tppcprocinfo(current_procinfo).maxpushedparasize:=pushedparasize;
  978. {$endif powerpc}
  979. { Restore }
  980. pushedparasize:=oldpushedparasize;
  981. rg.restoreunusedstate(unusedstate);
  982. {$ifdef TEMPREGDEBUG}
  983. testregisters32;
  984. {$endif TEMPREGDEBUG}
  985. {$ifdef newra}
  986. regs_to_free:=regs_to_alloc;
  987. if (not is_void(resulttype.def)) and
  988. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  989. begin
  990. case funcretloc.loc of
  991. LOC_REGISTER,LOC_CREGISTER:
  992. begin
  993. {$ifndef cpu64bit}
  994. if funcretloc.size in [OS_S64,OS_64] then
  995. begin
  996. exclude(regs_to_free,funcretloc.registerlow.number shr 8);
  997. exclude(regs_to_free,funcretloc.registerhigh.number shr 8);
  998. end
  999. else
  1000. {$endif cpu64bit}
  1001. exclude(regs_to_free,funcretloc.register.number shr 8);
  1002. end;
  1003. end;
  1004. end;
  1005. rg.deallocexplicitregistersint(exprasmlist,regs_to_free);
  1006. {$endif}
  1007. { handle function results }
  1008. if (not is_void(resulttype.def)) then
  1009. handle_return_value
  1010. else
  1011. location_reset(location,LOC_VOID,OS_NO);
  1012. { perhaps i/o check ? }
  1013. if iolabel<>nil then
  1014. begin
  1015. reference_reset_symbol(href,iolabel,0);
  1016. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1017. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1018. paramanager.freeintparaloc(exprasmlist,1);
  1019. end;
  1020. { restore registers }
  1021. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1022. {$ifndef newra}
  1023. rg.restoreusedintregisters(exprasmlist,pushedint);
  1024. {$endif}
  1025. { release temps of paras }
  1026. release_para_temps;
  1027. { if return value is not used }
  1028. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  1029. begin
  1030. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1031. begin
  1032. { data which must be finalized ? }
  1033. if (resulttype.def.needs_inittable) then
  1034. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1035. { release unused temp }
  1036. tg.ungetiftemp(exprasmlist,location.reference)
  1037. end
  1038. else if location.loc=LOC_FPUREGISTER then
  1039. begin
  1040. {$ifdef x86}
  1041. { release FPU stack }
  1042. accreg.enum:=FPU_RESULT_REG;
  1043. emit_reg(A_FSTP,S_NO,accreg);
  1044. {
  1045. dec(trgcpu(rg).fpuvaroffset);
  1046. do NOT decrement as the increment before
  1047. is not called for unused results PM }
  1048. {$endif x86}
  1049. end;
  1050. end;
  1051. end;
  1052. procedure tcgcallnode.inlined_pass_2;
  1053. var
  1054. regs_to_push_int : Tsupregset;
  1055. regs_to_push_other : tregisterset;
  1056. unusedstate: pointer;
  1057. pushedother : tpushedsavedother;
  1058. {$ifndef newra}
  1059. pushedint : tpushedsavedint;
  1060. pushedregs : tmaybesave;
  1061. {$endif}
  1062. funcretloc: tparalocation;
  1063. oldpushedparasize : longint;
  1064. { adress returned from an I/O-error }
  1065. iolabel : tasmlabel;
  1066. { help reference pointer }
  1067. href : treference;
  1068. {$ifdef x86}
  1069. accreg : tregister;
  1070. {$endif x86}
  1071. oldaktcallnode : tcallnode;
  1072. oldprocdef : tprocdef;
  1073. i : longint;
  1074. oldprocinfo : tprocinfo;
  1075. oldinlining_procedure : boolean;
  1076. inlineentrycode,inlineexitcode : TAAsmoutput;
  1077. oldregstate: pointer;
  1078. old_local_fixup,
  1079. old_para_fixup : longint;
  1080. usesacc,usesacchi,usesfpu : boolean;
  1081. pararef,
  1082. localsref : treference;
  1083. {$ifdef GDB}
  1084. startlabel,endlabel : tasmlabel;
  1085. pp : pchar;
  1086. mangled_length : longint;
  1087. {$endif GDB}
  1088. begin
  1089. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  1090. internalerror(200305262);
  1091. oldinlining_procedure:=inlining_procedure;
  1092. oldprocdef:=current_procinfo.procdef;
  1093. oldprocinfo:=current_procinfo;
  1094. { we're inlining a procedure }
  1095. inlining_procedure:=true;
  1096. { calculate the parameter info for the procdef }
  1097. if not procdefinition.has_paraloc_info then
  1098. begin
  1099. paramanager.create_paraloc_info(procdefinition,callerside);
  1100. procdefinition.has_paraloc_info:=true;
  1101. end;
  1102. { deallocate the registers used for the current procedure's regvars }
  1103. if assigned(current_procinfo.procdef.regvarinfo) then
  1104. begin
  1105. with pregvarinfo(current_procinfo.procdef.regvarinfo)^ do
  1106. for i := 1 to maxvarregs do
  1107. if assigned(regvars[i]) then
  1108. store_regvar(exprasmlist,regvars[i].reg);
  1109. rg.saveStateForInline(oldregstate);
  1110. { make sure the register allocator knows what the regvars in the }
  1111. { inlined code block are (JM) }
  1112. rg.resetusableregisters;
  1113. rg.clearregistercount;
  1114. {$ifndef newra}
  1115. rg.cleartempgen;
  1116. {$endif}
  1117. if assigned(tprocdef(procdefinition).regvarinfo) then
  1118. with pregvarinfo(tprocdef(procdefinition).regvarinfo)^ do
  1119. for i := 1 to maxvarregs do
  1120. if assigned(regvars[i]) then
  1121. begin
  1122. {Fix me!!}
  1123. {tmpreg:=rg.makeregsize(regvars[i].reg,OS_INT);
  1124. rg.makeregvar(tmpreg);}
  1125. internalerror(200301232);
  1126. end;
  1127. end;
  1128. { create temp procinfo }
  1129. current_procinfo:=cprocinfo.create(nil);
  1130. current_procinfo.procdef:=tprocdef(procdefinition);
  1131. { Localsymtable }
  1132. current_procinfo.procdef.localst.symtablelevel:=oldprocdef.localst.symtablelevel;
  1133. if current_procinfo.procdef.localst.datasize>0 then
  1134. begin
  1135. old_local_fixup:=current_procinfo.procdef.localst.address_fixup;
  1136. tg.GetTemp(exprasmlist,current_procinfo.procdef.localst.datasize,tt_persistent,localsref);
  1137. if tg.direction>0 then
  1138. current_procinfo.procdef.localst.address_fixup:=localsref.offset
  1139. else
  1140. current_procinfo.procdef.localst.address_fixup:=localsref.offset+current_procinfo.procdef.localst.datasize;
  1141. {$ifdef extdebug}
  1142. Comment(V_debug,'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup));
  1143. exprasmList.concat(tai_comment.Create(strpnew(
  1144. 'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup))));
  1145. {$endif extdebug}
  1146. end;
  1147. { Parasymtable }
  1148. current_procinfo.procdef.parast.symtablelevel:=oldprocdef.localst.symtablelevel;
  1149. if current_procinfo.procdef.parast.datasize>0 then
  1150. begin
  1151. old_para_fixup:=current_procinfo.procdef.parast.address_fixup;
  1152. tg.GetTemp(exprasmlist,current_procinfo.procdef.parast.datasize,tt_persistent,pararef);
  1153. current_procinfo.procdef.parast.address_fixup:=pararef.offset;
  1154. {$ifdef extdebug}
  1155. Comment(V_debug,'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup));
  1156. exprasmList.concat(tai_comment.Create(strpnew(
  1157. 'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup))));
  1158. {$endif extdebug}
  1159. end;
  1160. { Calculate offsets }
  1161. current_procinfo.after_header;
  1162. exprasmList.concat(Tai_Marker.Create(InlineStart));
  1163. {$ifdef extdebug}
  1164. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  1165. {$endif extdebug}
  1166. {$ifdef GDB}
  1167. if (cs_debuginfo in aktmoduleswitches) then
  1168. begin
  1169. objectlibrary.getaddrlabel(startlabel);
  1170. objectlibrary.getaddrlabel(endlabel);
  1171. cg.a_label(exprasmlist,startlabel);
  1172. tprocdef(procdefinition).localst.symtabletype:=inlinelocalsymtable;
  1173. procdefinition.parast.symtabletype:=inlineparasymtable;
  1174. { Here we must include the para and local symtable info }
  1175. procdefinition.concatstabto(withdebuglist);
  1176. { set it back for safety }
  1177. tprocdef(procdefinition).localst.symtabletype:=localsymtable;
  1178. procdefinition.parast.symtabletype:=parasymtable;
  1179. mangled_length:=length(oldprocdef.mangledname);
  1180. getmem(pp,mangled_length+50);
  1181. strpcopy(pp,'192,0,0,'+startlabel.name);
  1182. if (target_info.use_function_relative_addresses) then
  1183. begin
  1184. strpcopy(strend(pp),'-');
  1185. strpcopy(strend(pp),oldprocdef.mangledname);
  1186. end;
  1187. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1188. end;
  1189. {$endif GDB}
  1190. iolabel:=nil;
  1191. rg.saveunusedstate(unusedstate);
  1192. { if we allocate the temp. location for ansi- or widestrings }
  1193. { already here, we avoid later a push/pop }
  1194. if is_widestring(resulttype.def) then
  1195. begin
  1196. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  1197. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1198. end
  1199. else if is_ansistring(resulttype.def) then
  1200. begin
  1201. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  1202. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1203. end;
  1204. if (cs_check_io in aktlocalswitches) and
  1205. (po_iocheck in procdefinition.procoptions) and
  1206. not(po_iocheck in current_procinfo.procdef.procoptions) then
  1207. begin
  1208. objectlibrary.getaddrlabel(iolabel);
  1209. cg.a_label(exprasmlist,iolabel);
  1210. end
  1211. else
  1212. iolabel:=nil;
  1213. { save all used registers and possible registers
  1214. used for the return value }
  1215. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  1216. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  1217. if (not is_void(resulttype.def)) and
  1218. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  1219. begin
  1220. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  1221. case funcretloc.loc of
  1222. LOC_REGISTER,LOC_CREGISTER:
  1223. begin
  1224. {$ifndef cpu64bit}
  1225. if funcretloc.size in [OS_S64,OS_64] then
  1226. begin
  1227. include(regs_to_push_int,funcretloc.registerlow.number shr 8);
  1228. include(regs_to_push_int,funcretloc.registerhigh.number shr 8);
  1229. end
  1230. else
  1231. {$endif cpu64bit}
  1232. include(regs_to_push_int,funcretloc.register.number shr 8);
  1233. end;
  1234. end;
  1235. end;
  1236. {$ifndef newra}
  1237. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  1238. {$endif}
  1239. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  1240. {$ifdef i386}
  1241. { give used registers through }
  1242. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  1243. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  1244. {$endif i386}
  1245. { Initialize for pushing the parameters }
  1246. oldpushedparasize:=pushedparasize;
  1247. pushedparasize:=0;
  1248. { Push parameters }
  1249. oldaktcallnode:=aktcallnode;
  1250. aktcallnode:=self;
  1251. if assigned(left) then
  1252. begin
  1253. {$ifndef newra}
  1254. if assigned(right) then
  1255. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  1256. else
  1257. if assigned(methodpointer) then
  1258. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  1259. {$endif}
  1260. { we push from right to left, so start with parameters at the end of
  1261. the parameter block }
  1262. tcallparanode(left).secondcallparan(
  1263. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  1264. 0,procdefinition.parast.address_fixup+procdefinition.parast.datasize);
  1265. {$ifndef newra}
  1266. if assigned(right) then
  1267. maybe_restore(exprasmlist,right.location,pushedregs)
  1268. else
  1269. if assigned(methodpointer) then
  1270. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  1271. {$endif newra}
  1272. end;
  1273. aktcallnode:=oldaktcallnode;
  1274. {$ifndef newra}
  1275. rg.saveintregvars(exprasmlist,regs_to_push_int);
  1276. {$endif}
  1277. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  1278. { takes care of local data initialization }
  1279. inlineentrycode:=TAAsmoutput.Create;
  1280. inlineexitcode:=TAAsmoutput.Create;
  1281. gen_initialize_code(inlineentrycode,true);
  1282. if po_assembler in current_procinfo.procdef.procoptions then
  1283. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  1284. exprasmList.concatlist(inlineentrycode);
  1285. { process the inline code }
  1286. secondpass(inlinecode);
  1287. {$ifdef powerpc}
  1288. { this calculation must be done in pass_1 anyway, so don't worry }
  1289. if tppcprocinfo(current_procinfo).maxpushedparasize<pushedparasize then
  1290. tppcprocinfo(current_procinfo).maxpushedparasize:=pushedparasize;
  1291. {$endif powerpc}
  1292. { Restore }
  1293. pushedparasize:=oldpushedparasize;
  1294. rg.restoreunusedstate(unusedstate);
  1295. {$ifdef TEMPREGDEBUG}
  1296. testregisters32;
  1297. {$endif TEMPREGDEBUG}
  1298. gen_finalize_code(inlineexitcode,true);
  1299. gen_load_return_value(inlineexitcode,usesacc,usesacchi,usesfpu);
  1300. if po_assembler in current_procinfo.procdef.procoptions then
  1301. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  1302. exprasmList.concatlist(inlineexitcode);
  1303. inlineentrycode.free;
  1304. inlineexitcode.free;
  1305. {$ifdef extdebug}
  1306. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  1307. {$endif extdebug}
  1308. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1309. {we can free the local data now, reset also the fixup address }
  1310. if current_procinfo.procdef.localst.datasize>0 then
  1311. begin
  1312. tg.UnGetTemp(exprasmlist,localsref);
  1313. current_procinfo.procdef.localst.address_fixup:=old_local_fixup;
  1314. end;
  1315. {we can free the para data now, reset also the fixup address }
  1316. if current_procinfo.procdef.parast.datasize>0 then
  1317. begin
  1318. tg.UnGetTemp(exprasmlist,pararef);
  1319. current_procinfo.procdef.parast.address_fixup:=old_para_fixup;
  1320. end;
  1321. { free return reference }
  1322. if (resulttype.def.size>0) then
  1323. begin
  1324. { from now on the result can be freed normally }
  1325. // if assigned(funcretnode) and
  1326. // paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1327. // tg.ChangeTempType(exprasmlist,funcretnode.location.reference,tt_normal);
  1328. end;
  1329. { handle function results }
  1330. if (not is_void(resulttype.def)) then
  1331. handle_return_value
  1332. else
  1333. location_reset(location,LOC_VOID,OS_NO);
  1334. { perhaps i/o check ? }
  1335. if iolabel<>nil then
  1336. begin
  1337. reference_reset_symbol(href,iolabel,0);
  1338. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1339. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1340. paramanager.freeintparaloc(exprasmlist,1);
  1341. end;
  1342. { restore registers }
  1343. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1344. {$ifndef newra}
  1345. rg.restoreusedintregisters(exprasmlist,pushedint);
  1346. {$endif}
  1347. { release temps of paras }
  1348. release_para_temps;
  1349. { if return value is not used }
  1350. if (not is_void(resulttype.def)) and
  1351. (not(nf_return_value_used in flags)) then
  1352. begin
  1353. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1354. begin
  1355. { data which must be finalized ? }
  1356. if (resulttype.def.needs_inittable) then
  1357. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1358. { release unused temp }
  1359. tg.ungetiftemp(exprasmlist,location.reference)
  1360. end
  1361. else if location.loc=LOC_FPUREGISTER then
  1362. begin
  1363. {$ifdef x86}
  1364. { release FPU stack }
  1365. accreg.enum:=FPU_RESULT_REG;
  1366. emit_reg(A_FSTP,S_NO,accreg);
  1367. {
  1368. dec(trgcpu(rg).fpuvaroffset);
  1369. do NOT decrement as the increment before
  1370. is not called for unused results PM }
  1371. {$endif x86}
  1372. end;
  1373. end;
  1374. { release procinfo }
  1375. current_procinfo.free;
  1376. current_procinfo:=oldprocinfo;
  1377. {$ifdef GDB}
  1378. if (cs_debuginfo in aktmoduleswitches) then
  1379. begin
  1380. cg.a_label(exprasmlist,endlabel);
  1381. strpcopy(pp,'224,0,0,'+endlabel.name);
  1382. if (target_info.use_function_relative_addresses) then
  1383. begin
  1384. strpcopy(strend(pp),'-');
  1385. strpcopy(strend(pp),oldprocdef.mangledname);
  1386. end;
  1387. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1388. freemem(pp,mangled_length+50);
  1389. end;
  1390. {$endif GDB}
  1391. { restore }
  1392. current_procinfo.procdef:=oldprocdef;
  1393. inlining_procedure:=oldinlining_procedure;
  1394. { reallocate the registers used for the current procedure's regvars, }
  1395. { since they may have been used and then deallocated in the inlined }
  1396. { procedure (JM) }
  1397. if assigned(current_procinfo.procdef.regvarinfo) then
  1398. rg.restoreStateAfterInline(oldregstate);
  1399. end;
  1400. procedure tcgcallnode.pass_2;
  1401. begin
  1402. if assigned(inlinecode) then
  1403. inlined_pass_2
  1404. else
  1405. normal_pass_2;
  1406. end;
  1407. begin
  1408. ccallparanode:=tcgcallparanode;
  1409. ccallnode:=tcgcallnode;
  1410. end.
  1411. {
  1412. $Log$
  1413. Revision 1.98 2003-07-06 15:31:20 daniel
  1414. * Fixed register allocator. *Lots* of fixes.
  1415. Revision 1.97 2003/07/05 20:21:26 jonas
  1416. * create_paraloc_info() is now called separately for the caller and
  1417. callee info
  1418. * fixed ppc cycle
  1419. Revision 1.96 2003/07/02 22:18:04 peter
  1420. * paraloc splitted in callerparaloc,calleeparaloc
  1421. * sparc calling convention updates
  1422. Revision 1.95 2003/06/17 16:34:44 jonas
  1423. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1424. * renamed all_intregisters to volatile_intregisters and made it
  1425. processor dependent
  1426. Revision 1.94 2003/06/15 16:52:02 jonas
  1427. * release function result registers if the functino result isn't used
  1428. * don't allocate function result register with -dnewra if there is none
  1429. * some optimizations for non-x86 processor (don't save any registers
  1430. before a call)
  1431. Revision 1.93 2003/06/13 21:19:30 peter
  1432. * current_procdef removed, use current_procinfo.procdef instead
  1433. Revision 1.92 2003/06/12 21:10:50 peter
  1434. * newra fixes
  1435. Revision 1.91 2003/06/12 18:38:45 jonas
  1436. * deallocate parameter registers in time for newra
  1437. * for non-i386, procvars and methodpointers always have to be processed
  1438. in advance, whether or not newra is defined
  1439. Revision 1.90 2003/06/09 14:54:26 jonas
  1440. * (de)allocation of registers for parameters is now performed properly
  1441. (and checked on the ppc)
  1442. - removed obsolete allocation of all parameter registers at the start
  1443. of a procedure (and deallocation at the end)
  1444. Revision 1.89 2003/06/09 12:23:29 peter
  1445. * init/final of procedure data splitted from genentrycode
  1446. * use asmnode getposition to insert final at the correct position
  1447. als for the implicit try...finally
  1448. Revision 1.88 2003/06/08 20:01:53 jonas
  1449. * optimized assignments with on the right side a function that returns
  1450. an ansi- or widestring
  1451. Revision 1.87 2003/06/08 18:21:47 jonas
  1452. * fixed weird error in the copyleft statement :)
  1453. Revision 1.86 2003/06/07 18:57:04 jonas
  1454. + added freeintparaloc
  1455. * ppc get/freeintparaloc now check whether the parameter regs are
  1456. properly allocated/deallocated (and get an extra list para)
  1457. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1458. * fixed lot of missing pi_do_call's
  1459. Revision 1.85 2003/06/04 06:43:36 jonas
  1460. * fixed double secondpassing of procvar loads
  1461. Revision 1.84 2003/06/03 21:11:09 peter
  1462. * cg.a_load_* get a from and to size specifier
  1463. * makeregsize only accepts newregister
  1464. * i386 uses generic tcgnotnode,tcgunaryminus
  1465. Revision 1.83 2003/06/03 20:27:02 daniel
  1466. * Restored original methodpointer code for non newra case
  1467. Revision 1.82 2003/06/03 13:01:59 daniel
  1468. * Register allocator finished
  1469. Revision 1.81 2003/06/01 21:38:06 peter
  1470. * getregisterfpu size parameter added
  1471. * op_const_reg size parameter added
  1472. * sparc updates
  1473. Revision 1.80 2003/05/31 15:05:28 peter
  1474. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1475. Revision 1.79 2003/05/31 00:59:44 peter
  1476. * typo in FUNCTION_RESULT_REG
  1477. Revision 1.78 2003/05/30 23:57:08 peter
  1478. * more sparc cleanup
  1479. * accumulator removed, splitted in function_return_reg (called) and
  1480. function_result_reg (caller)
  1481. Revision 1.77 2003/05/29 10:05:40 jonas
  1482. * free callparatemps created for call-by-reference parameters
  1483. Revision 1.76 2003/05/28 23:58:18 jonas
  1484. * added missing initialization of rg.usedintin,byproc
  1485. * ppc now also saves/restores used fpu registers
  1486. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1487. i386
  1488. Revision 1.75 2003/05/26 21:17:17 peter
  1489. * procinlinenode removed
  1490. * aktexit2label removed, fast exit removed
  1491. + tcallnode.inlined_pass_2 added
  1492. Revision 1.74 2003/05/25 11:34:17 peter
  1493. * methodpointer self pushing fixed
  1494. Revision 1.73 2003/05/25 08:59:16 peter
  1495. * inline fixes
  1496. Revision 1.72 2003/05/24 13:36:54 jonas
  1497. * save fpu results in a normal fpu register on non-x86 processors
  1498. Revision 1.71 2003/05/23 19:35:50 jonas
  1499. - undid previous commit, it was wrong
  1500. Revision 1.70 2003/05/23 19:11:58 jonas
  1501. * fixed tests for whether a certain int register is unused
  1502. Revision 1.69 2003/05/23 18:01:56 jonas
  1503. * fixed ppc compiler
  1504. Revision 1.68 2003/05/23 14:27:35 peter
  1505. * remove some unit dependencies
  1506. * current_procinfo changes to store more info
  1507. Revision 1.67 2003/05/17 13:30:08 jonas
  1508. * changed tt_persistant to tt_persistent :)
  1509. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1510. temps, but a ttemptype, so you can also create ansistring temps etc
  1511. Revision 1.66 2003/05/16 14:33:31 peter
  1512. * regvar fixes
  1513. Revision 1.65 2003/05/15 18:58:53 peter
  1514. * removed selfpointer_offset, vmtpointer_offset
  1515. * tvarsym.adjusted_address
  1516. * address in localsymtable is now in the real direction
  1517. * removed some obsolete globals
  1518. Revision 1.64 2003/05/14 19:36:54 jonas
  1519. * patch from Peter for int64 function results
  1520. Revision 1.63 2003/05/13 19:14:41 peter
  1521. * failn removed
  1522. * inherited result code check moven to pexpr
  1523. Revision 1.62 2003/05/13 15:18:18 peter
  1524. * generate code for procvar first before pushing parameters. Made
  1525. the already existing code for powerpc available for all platforms
  1526. Revision 1.61 2003/05/12 18:17:55 jonas
  1527. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1528. already-loaded parameter registers
  1529. Revision 1.60 2003/05/11 21:48:38 jonas
  1530. * fixed procvar bug on the ppc (load procvar before loading para's,
  1531. because the procvar may otherwise destroy the already loaded paras)
  1532. Revision 1.59 2003/05/09 17:47:02 peter
  1533. * self moved to hidden parameter
  1534. * removed hdisposen,hnewn,selfn
  1535. Revision 1.58 2003/05/05 14:53:16 peter
  1536. * vs_hidden replaced by is_hidden boolean
  1537. Revision 1.57 2003/04/30 20:53:32 florian
  1538. * error when address of an abstract method is taken
  1539. * fixed some x86-64 problems
  1540. * merged some more x86-64 and i386 code
  1541. Revision 1.56 2003/04/29 07:28:52 michael
  1542. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1543. Revision 1.55 2003/04/27 11:21:33 peter
  1544. * aktprocdef renamed to current_procinfo.procdef
  1545. * procinfo renamed to current_procinfo
  1546. * procinfo will now be stored in current_module so it can be
  1547. cleaned up properly
  1548. * gen_main_procsym changed to create_main_proc and release_main_proc
  1549. to also generate a tprocinfo structure
  1550. * fixed unit implicit initfinal
  1551. Revision 1.54 2003/04/27 07:29:50 peter
  1552. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  1553. a new procdef declaration
  1554. * aktprocsym removed
  1555. * lexlevel removed, use symtable.symtablelevel instead
  1556. * implicit init/final code uses the normal genentry/genexit
  1557. * funcret state checking updated for new funcret handling
  1558. Revision 1.53 2003/04/25 20:59:33 peter
  1559. * removed funcretn,funcretsym, function result is now in varsym
  1560. and aliases for result and function name are added using absolutesym
  1561. * vs_hidden parameter for funcret passed in parameter
  1562. * vs_hidden fixes
  1563. * writenode changed to printnode and released from extdebug
  1564. * -vp option added to generate a tree.log with the nodetree
  1565. * nicer printnode for statements, callnode
  1566. Revision 1.52 2003/04/25 08:25:26 daniel
  1567. * Ifdefs around a lot of calls to cleartempgen
  1568. * Fixed registers that are allocated but not freed in several nodes
  1569. * Tweak to register allocator to cause less spills
  1570. * 8-bit registers now interfere with esi,edi and ebp
  1571. Compiler can now compile rtl successfully when using new register
  1572. allocator
  1573. Revision 1.51 2003/04/22 23:50:22 peter
  1574. * firstpass uses expectloc
  1575. * checks if there are differences between the expectloc and
  1576. location.loc from secondpass in EXTDEBUG
  1577. Revision 1.50 2003/04/22 14:33:38 peter
  1578. * removed some notes/hints
  1579. Revision 1.49 2003/04/22 13:47:08 peter
  1580. * fixed C style array of const
  1581. * fixed C array passing
  1582. * fixed left to right with high parameters
  1583. Revision 1.48 2003/04/22 10:09:34 daniel
  1584. + Implemented the actual register allocator
  1585. + Scratch registers unavailable when new register allocator used
  1586. + maybe_save/maybe_restore unavailable when new register allocator used
  1587. Revision 1.47 2003/04/22 09:49:44 peter
  1588. * do not load self when calling a non-inherited class constructor
  1589. Revision 1.46 2003/04/21 20:03:32 peter
  1590. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1591. Revision 1.45 2003/04/21 13:53:16 jonas
  1592. - removed copying of all paras when secondpassing a callnode (this used
  1593. to be necessary for inlinign support, but currently the whole inlined
  1594. procedure is already copied in advance). Note that the compiler crashes
  1595. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1596. syntax errors), but that was also the case before this change.
  1597. Revision 1.44 2003/04/10 17:57:52 peter
  1598. * vs_hidden released
  1599. Revision 1.43 2003/04/06 21:11:23 olle
  1600. * changed newasmsymbol to newasmsymboldata for data symbols
  1601. Revision 1.42 2003/04/04 15:38:56 peter
  1602. * moved generic code from n386cal to ncgcal, i386 now also
  1603. uses the generic ncgcal
  1604. Revision 1.41 2003/03/28 19:16:56 peter
  1605. * generic constructor working for i386
  1606. * remove fixed self register
  1607. * esi added as address register for i386
  1608. Revision 1.40 2003/03/06 11:35:50 daniel
  1609. * Fixed internalerror 7843 issue
  1610. Revision 1.39 2003/02/19 22:00:14 daniel
  1611. * Code generator converted to new register notation
  1612. - Horribily outdated todo.txt removed
  1613. Revision 1.38 2003/02/15 22:17:38 carl
  1614. * bugfix of FPU emulation code
  1615. Revision 1.37 2003/02/12 22:10:07 carl
  1616. * load_frame_pointer is now generic
  1617. * change fpu emulation routine names
  1618. Revision 1.36 2003/01/30 21:46:57 peter
  1619. * self fixes for static methods (merged)
  1620. Revision 1.35 2003/01/22 20:45:15 mazen
  1621. * making math code in RTL compiling.
  1622. *NB : This does NOT mean necessary that it will generate correct code!
  1623. Revision 1.34 2003/01/17 12:03:45 daniel
  1624. * Optalign conditional code adapted to record Tregister
  1625. Revision 1.33 2003/01/08 18:43:56 daniel
  1626. * Tregister changed into a record
  1627. Revision 1.32 2002/12/15 22:50:00 florian
  1628. + some stuff for the new hidden parameter handling added
  1629. Revision 1.31 2002/12/15 21:30:12 florian
  1630. * tcallnode.paraitem introduced, all references to defcoll removed
  1631. Revision 1.30 2002/11/27 20:04:39 peter
  1632. * cdecl array of const fixes
  1633. Revision 1.29 2002/11/25 17:43:17 peter
  1634. * splitted defbase in defutil,symutil,defcmp
  1635. * merged isconvertable and is_equal into compare_defs(_ext)
  1636. * made operator search faster by walking the list only once
  1637. Revision 1.28 2002/11/18 17:31:54 peter
  1638. * pass proccalloption to ret_in_xxx and push_xxx functions
  1639. Revision 1.27 2002/11/16 15:34:30 florian
  1640. * generic location for float results
  1641. Revision 1.26 2002/11/15 01:58:51 peter
  1642. * merged changes from 1.0.7 up to 04-11
  1643. - -V option for generating bug report tracing
  1644. - more tracing for option parsing
  1645. - errors for cdecl and high()
  1646. - win32 import stabs
  1647. - win32 records<=8 are returned in eax:edx (turned off by default)
  1648. - heaptrc update
  1649. - more info for temp management in .s file with EXTDEBUG
  1650. Revision 1.25 2002/10/05 12:43:25 carl
  1651. * fixes for Delphi 6 compilation
  1652. (warning : Some features do not work under Delphi)
  1653. Revision 1.24 2002/09/30 07:00:45 florian
  1654. * fixes to common code to get the alpha compiler compiled applied
  1655. Revision 1.23 2002/09/17 18:54:02 jonas
  1656. * a_load_reg_reg() now has two size parameters: source and dest. This
  1657. allows some optimizations on architectures that don't encode the
  1658. register size in the register name.
  1659. Revision 1.22 2002/09/07 15:25:02 peter
  1660. * old logs removed and tabs fixed
  1661. Revision 1.21 2002/09/07 11:50:02 jonas
  1662. * fixed small regalloction info bug
  1663. Revision 1.20 2002/09/02 11:25:20 florian
  1664. * fixed generic procedure variable calling
  1665. Revision 1.19 2002/09/01 21:04:48 florian
  1666. * several powerpc related stuff fixed
  1667. Revision 1.18 2002/09/01 18:43:27 peter
  1668. * include FUNCTION_RETURN_REG in regs_to_push list
  1669. Revision 1.17 2002/09/01 12:13:00 peter
  1670. * use a_call_reg
  1671. * ungetiftemp for procvar of object temp
  1672. Revision 1.16 2002/08/25 19:25:18 peter
  1673. * sym.insert_in_data removed
  1674. * symtable.insertvardata/insertconstdata added
  1675. * removed insert_in_data call from symtable.insert, it needs to be
  1676. called separatly. This allows to deref the address calculation
  1677. * procedures now calculate the parast addresses after the procedure
  1678. directives are parsed. This fixes the cdecl parast problem
  1679. * push_addr_param has an extra argument that specifies if cdecl is used
  1680. or not
  1681. Revision 1.15 2002/08/23 16:14:48 peter
  1682. * tempgen cleanup
  1683. * tt_noreuse temp type added that will be used in genentrycode
  1684. Revision 1.14 2002/08/20 16:55:38 peter
  1685. * don't write (stabs)line info when inlining a procedure
  1686. Revision 1.13 2002/08/19 19:36:42 peter
  1687. * More fixes for cross unit inlining, all tnodes are now implemented
  1688. * Moved pocall_internconst to po_internconst because it is not a
  1689. calling type at all and it conflicted when inlining of these small
  1690. functions was requested
  1691. Revision 1.12 2002/08/18 20:06:23 peter
  1692. * inlining is now also allowed in interface
  1693. * renamed write/load to ppuwrite/ppuload
  1694. * tnode storing in ppu
  1695. * nld,ncon,nbas are already updated for storing in ppu
  1696. Revision 1.11 2002/08/17 22:09:44 florian
  1697. * result type handling in tcgcal.pass_2 overhauled
  1698. * better tnode.dowrite
  1699. * some ppc stuff fixed
  1700. Revision 1.10 2002/08/17 09:23:35 florian
  1701. * first part of procinfo rewrite
  1702. Revision 1.9 2002/08/13 21:40:55 florian
  1703. * more fixes for ppc calling conventions
  1704. Revision 1.8 2002/08/13 18:01:51 carl
  1705. * rename swatoperands to swapoperands
  1706. + m68k first compilable version (still needs a lot of testing):
  1707. assembler generator, system information , inline
  1708. assembler reader.
  1709. Revision 1.7 2002/08/12 15:08:39 carl
  1710. + stab register indexes for powerpc (moved from gdb to cpubase)
  1711. + tprocessor enumeration moved to cpuinfo
  1712. + linker in target_info is now a class
  1713. * many many updates for m68k (will soon start to compile)
  1714. - removed some ifdef or correct them for correct cpu
  1715. Revision 1.6 2002/08/11 14:32:26 peter
  1716. * renamed current_library to objectlibrary
  1717. Revision 1.5 2002/08/11 13:24:11 peter
  1718. * saving of asmsymbols in ppu supported
  1719. * asmsymbollist global is removed and moved into a new class
  1720. tasmlibrarydata that will hold the info of a .a file which
  1721. corresponds with a single module. Added librarydata to tmodule
  1722. to keep the library info stored for the module. In the future the
  1723. objectfiles will also be stored to the tasmlibrarydata class
  1724. * all getlabel/newasmsymbol and friends are moved to the new class
  1725. Revision 1.4 2002/08/06 20:55:20 florian
  1726. * first part of ppc calling conventions fix
  1727. Revision 1.3 2002/07/20 11:57:53 florian
  1728. * types.pas renamed to defbase.pas because D6 contains a types
  1729. unit so this would conflicts if D6 programms are compiled
  1730. + Willamette/SSE2 instructions to assembler added
  1731. Revision 1.2 2002/07/13 19:38:43 florian
  1732. * some more generic calling stuff fixed
  1733. }