ncgcal.pas 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  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 free_pushed_framepointer;virtual;
  51. procedure extra_interrupt_code;virtual;
  52. public
  53. procedure pass_2;override;
  54. end;
  55. implementation
  56. uses
  57. systems,
  58. cutils,verbose,globals,
  59. symconst,symbase,symsym,symtable,defutil,paramgr,
  60. {$ifdef GDB}
  61. {$ifdef delphi}
  62. sysutils,
  63. {$else}
  64. strings,
  65. {$endif}
  66. gdb,
  67. {$endif GDB}
  68. cginfo,cgbase,pass_2,
  69. cpuinfo,aasmbase,aasmtai,aasmcpu,
  70. nbas,nmem,nld,ncnv,
  71. {$ifdef x86}
  72. cga,
  73. {$endif x86}
  74. {$ifdef cpu64bit}
  75. cg64f64,
  76. {$else cpu64bit}
  77. cg64f32,
  78. {$endif cpu64bit}
  79. ncgutil,cgobj,tgobj,regvars,rgobj,rgcpu;
  80. {*****************************************************************************
  81. TCGCALLPARANODE
  82. *****************************************************************************}
  83. procedure tcgcallparanode.secondcallparan(push_from_left_to_right:boolean;calloption:tproccalloption;para_alignment,para_offset : longint);
  84. var
  85. otlabel,
  86. oflabel : tasmlabel;
  87. tmpreg : tregister;
  88. href : treference;
  89. begin
  90. if not(assigned(paraitem.paratype.def) or
  91. assigned(paraitem.parasym)) then
  92. internalerror(200304242);
  93. { set default para_alignment to target_info.stackalignment }
  94. if para_alignment=0 then
  95. para_alignment:=aktalignment.paraalign;
  96. { push from left to right if specified }
  97. if push_from_left_to_right and assigned(right) then
  98. begin
  99. tcallparanode(right).secondcallparan(push_from_left_to_right,
  100. calloption,para_alignment,para_offset);
  101. end;
  102. otlabel:=truelabel;
  103. oflabel:=falselabel;
  104. objectlibrary.getlabel(truelabel);
  105. objectlibrary.getlabel(falselabel);
  106. secondpass(left);
  107. { allocate paraloc }
  108. paramanager.allocparaloc(exprasmlist,paraitem.callerparaloc);
  109. { handle varargs first, because defcoll is not valid }
  110. if (nf_varargs_para in flags) then
  111. begin
  112. if paramanager.push_addr_param(left.resulttype.def,calloption) then
  113. begin
  114. inc(pushedparasize,POINTER_SIZE);
  115. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  116. location_release(exprasmlist,left.location);
  117. end
  118. else
  119. push_value_para(exprasmlist,left,calloption,para_offset,para_alignment,paraitem.callerparaloc);
  120. end
  121. { hidden parameters }
  122. else if paraitem.is_hidden then
  123. begin
  124. { don't push a node that already generated a pointer type
  125. by address for implicit hidden parameters }
  126. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  127. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  128. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  129. begin
  130. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  131. internalerror(200305071);
  132. inc(pushedparasize,POINTER_SIZE);
  133. if calloption=pocall_inline then
  134. begin
  135. {$ifdef newra}
  136. tmpreg:=rg.getaddressregister(exprasmlist);
  137. {$else}
  138. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  139. {$endif}
  140. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  141. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  142. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  143. {$ifdef newra}
  144. rg.ungetregisterint(exprasmlist,tmpreg);
  145. {$else}
  146. cg.free_scratch_reg(exprasmlist,tmpreg);
  147. {$endif}
  148. end
  149. else
  150. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  151. location_release(exprasmlist,left.location);
  152. end
  153. else
  154. begin
  155. push_value_para(exprasmlist,left,calloption,
  156. para_offset,para_alignment,paraitem.callerparaloc);
  157. end;
  158. end
  159. { filter array of const c styled args }
  160. else if is_array_of_const(left.resulttype.def) and (nf_cargs in left.flags) then
  161. begin
  162. { nothing, everything is already pushed }
  163. end
  164. { in codegen.handleread.. paraitem.data is set to nil }
  165. else if assigned(paraitem.paratype.def) and
  166. (paraitem.paratype.def.deftype=formaldef) then
  167. begin
  168. { allow passing of a constant to a const formaldef }
  169. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  170. (left.location.loc=LOC_CONSTANT) then
  171. location_force_mem(exprasmlist,left.location);
  172. { allow @var }
  173. inc(pushedparasize,POINTER_SIZE);
  174. if (left.nodetype=addrn) and
  175. (not(nf_procvarload in left.flags)) then
  176. begin
  177. if calloption=pocall_inline then
  178. begin
  179. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  180. cg.a_load_loc_ref(exprasmlist,OS_ADDR,left.location,href);
  181. end
  182. else
  183. cg.a_param_loc(exprasmlist,left.location,paraitem.callerparaloc);
  184. location_release(exprasmlist,left.location);
  185. end
  186. else
  187. begin
  188. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  189. internalerror(200304235);
  190. if calloption=pocall_inline then
  191. begin
  192. {$ifdef newra}
  193. tmpreg:=rg.getaddressregister(exprasmlist);
  194. {$else}
  195. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  196. {$endif newra}
  197. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  198. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  199. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  200. {$ifdef newra}
  201. rg.ungetregisterint(exprasmlist,tmpreg);
  202. {$else}
  203. cg.free_scratch_reg(exprasmlist,tmpreg);
  204. {$endif}
  205. end
  206. else
  207. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  208. location_release(exprasmlist,left.location);
  209. end;
  210. end
  211. { handle call by reference parameter }
  212. else if (paraitem.paratyp in [vs_var,vs_out]) then
  213. begin
  214. if (left.location.loc<>LOC_REFERENCE) then
  215. begin
  216. { passing self to a var parameter is allowed in
  217. TP and delphi }
  218. if not((left.location.loc=LOC_CREFERENCE) and
  219. is_self_node(left)) then
  220. internalerror(200106041);
  221. end;
  222. if (paraitem.paratyp=vs_out) and
  223. assigned(paraitem.paratype.def) and
  224. not is_class(paraitem.paratype.def) and
  225. paraitem.paratype.def.needs_inittable then
  226. cg.g_finalize(exprasmlist,paraitem.paratype.def,left.location.reference,false);
  227. inc(pushedparasize,POINTER_SIZE);
  228. if calloption=pocall_inline then
  229. begin
  230. {$ifdef newra}
  231. tmpreg:=rg.getaddressregister(exprasmlist);
  232. {$else}
  233. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  234. {$endif}
  235. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  236. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  237. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  238. {$ifdef newra}
  239. rg.ungetregisterint(exprasmlist,tmpreg);
  240. {$else}
  241. cg.free_scratch_reg(exprasmlist,tmpreg);
  242. {$endif}
  243. end
  244. else
  245. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  246. location_release(exprasmlist,left.location);
  247. end
  248. else
  249. begin
  250. { don't push a node that already generated a pointer type
  251. by address for implicit hidden parameters }
  252. if (not(
  253. paraitem.is_hidden and
  254. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  255. ) and
  256. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  257. begin
  258. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  259. begin
  260. { allow passing nil to a procvardef (methodpointer) }
  261. if (left.nodetype=typeconvn) and
  262. (left.resulttype.def.deftype=procvardef) and
  263. (ttypeconvnode(left).left.nodetype=niln) then
  264. begin
  265. tg.GetTemp(exprasmlist,tcgsize2size[left.location.size],tt_normal,href);
  266. if not (left.location.size in [OS_64,OS_S64]) then
  267. cg.a_load_loc_ref(exprasmlist,left.location.size,left.location,href)
  268. else
  269. cg64.a_load64_loc_ref(exprasmlist,left.location,href);
  270. location_reset(left.location,LOC_REFERENCE,left.location.size);
  271. left.location.reference:=href;
  272. end
  273. else
  274. internalerror(200204011);
  275. end;
  276. inc(pushedparasize,POINTER_SIZE);
  277. if calloption=pocall_inline then
  278. begin
  279. {$ifdef newra}
  280. tmpreg:=rg.getaddressregister(exprasmlist);
  281. {$else}
  282. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  283. {$endif}
  284. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  285. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  286. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  287. {$ifdef newra}
  288. rg.ungetregisterint(exprasmlist,tmpreg);
  289. {$else}
  290. cg.free_scratch_reg(exprasmlist,tmpreg);
  291. {$endif}
  292. end
  293. else
  294. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  295. location_release(exprasmlist,left.location);
  296. end
  297. else
  298. begin
  299. push_value_para(exprasmlist,left,calloption,
  300. para_offset,para_alignment,paraitem.callerparaloc);
  301. end;
  302. end;
  303. truelabel:=otlabel;
  304. falselabel:=oflabel;
  305. { update return location in callnode when this is the function
  306. result }
  307. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  308. begin
  309. location_copy(aktcallnode.location,left.location);
  310. end;
  311. { push from right to left }
  312. if not push_from_left_to_right and assigned(right) then
  313. begin
  314. tcallparanode(right).secondcallparan(push_from_left_to_right,
  315. calloption,para_alignment,para_offset);
  316. end;
  317. end;
  318. {*****************************************************************************
  319. TCGCALLNODE
  320. *****************************************************************************}
  321. procedure tcgcallnode.extra_interrupt_code;
  322. begin
  323. end;
  324. function tcgcallnode.align_parasize:longint;
  325. begin
  326. result:=0;
  327. end;
  328. procedure tcgcallnode.pop_parasize(pop_size:longint);
  329. begin
  330. end;
  331. procedure tcgcallnode.push_framepointer;
  332. var
  333. href : treference;
  334. hregister : tregister;
  335. begin
  336. { this routine is itself not nested }
  337. if current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel) then
  338. begin
  339. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.parent_framepointer_offset);
  340. cg.a_param_ref(exprasmlist,OS_ADDR,href,paramanager.getintparaloc(exprasmlist,1));
  341. end
  342. { one nesting level }
  343. else if (current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  344. begin
  345. cg.a_param_reg(exprasmlist,OS_ADDR,current_procinfo.framepointer,paramanager.getintparaloc(exprasmlist,1));
  346. end
  347. { very complex nesting level ... }
  348. else if (current_procinfo.procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  349. begin
  350. hregister:=rg.getaddressregister(exprasmlist);
  351. cg.g_load_parent_framepointer(exprasmlist,tprocdef(procdefinition).parast,hregister);
  352. cg.a_param_reg(exprasmlist,OS_ADDR,hregister,paramanager.getintparaloc(exprasmlist,1));
  353. rg.ungetaddressregister(exprasmlist,hregister);
  354. end;
  355. end;
  356. procedure tcgcallnode.free_pushed_framepointer;
  357. begin
  358. paramanager.freeintparaloc(exprasmlist,1);
  359. end;
  360. procedure tcgcallnode.handle_return_value;
  361. var
  362. cgsize : tcgsize;
  363. r,hregister : tregister;
  364. href: treference;
  365. tempnode: tnode;
  366. begin
  367. { structured results are easy to handle.... }
  368. { needed also when result_no_used !! }
  369. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  370. begin
  371. { Location should be setup by the funcret para }
  372. if location.loc<>LOC_REFERENCE then
  373. internalerror(200304241);
  374. end
  375. else
  376. { ansi/widestrings must be registered, so we can dispose them }
  377. if is_ansistring(resulttype.def) or
  378. is_widestring(resulttype.def) then
  379. begin
  380. r.enum:=R_INTREGISTER;
  381. r.number:=NR_FUNCTION_RETURN_REG;
  382. {$ifdef newra}
  383. { the FUNCTION_RESULT_REG is already allocated }
  384. rg.ungetregisterint(exprasmlist,r);
  385. {$else}
  386. cg.a_reg_alloc(exprasmlist,r);
  387. {$endif}
  388. if not assigned(funcretnode) then
  389. begin
  390. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  391. location.reference:=refcountedtemp;
  392. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,r,location.reference);
  393. {$ifndef newra}
  394. cg.a_reg_dealloc(exprasmlist,r);
  395. {$endif newra}
  396. end
  397. else
  398. begin
  399. {$ifndef newra}
  400. tg.gettemp(exprasmlist,pointer_size,tt_normal,href);
  401. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,r,href);
  402. cg.a_reg_dealloc(exprasmlist,r);
  403. {$else newra}
  404. hregister := rg.getaddressregister(exprasmlist);
  405. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,r,hregister);
  406. {$endif newra}
  407. { in case of a regular funcretnode with ret_in_param, the }
  408. { original funcretnode isn't touched -> make sure it's }
  409. { the same here (not sure if it's necessary) }
  410. tempnode := funcretnode.getcopy;
  411. tempnode.pass_2;
  412. location := tempnode.location;
  413. tempnode.free;
  414. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference, false);
  415. {$ifndef newra}
  416. cg.a_load_ref_ref(exprasmlist,OS_ADDR,OS_ADDR,href,location.reference);
  417. { since we used a normal temp, it won't be finalized or }
  418. { decref'd later -> no need to zero it }
  419. tg.ungettemp(exprasmlist,href);
  420. {$else newra}
  421. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  422. rg.ungetregisterint(exprasmlist,hregister);
  423. {$endif newra}
  424. end;
  425. end
  426. else
  427. { we have only to handle the result if it is used }
  428. if (nf_return_value_used in flags) then
  429. begin
  430. if (resulttype.def.deftype=floatdef) then
  431. begin
  432. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  433. {$ifdef cpufpemu}
  434. if cs_fp_emulation in aktmoduleswitches then
  435. location.register.enum := FUNCTION_RESULT_REG
  436. else
  437. {$endif cpufpemu}
  438. location.register.enum:=FPU_RESULT_REG;
  439. {$ifdef x86}
  440. inc(trgcpu(rg).fpuvaroffset);
  441. {$else x86}
  442. hregister := rg.getregisterfpu(exprasmlist,location.size);
  443. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  444. location.register := hregister;
  445. {$endif x86}
  446. end
  447. else
  448. begin
  449. cgsize:=def_cgsize(resulttype.def);
  450. { an object constructor is a function with pointer result }
  451. if (procdefinition.proctypeoption=potype_constructor) then
  452. cgsize:=OS_ADDR;
  453. if cgsize<>OS_NO then
  454. begin
  455. location_reset(location,LOC_REGISTER,cgsize);
  456. {$ifndef cpu64bit}
  457. if cgsize in [OS_64,OS_S64] then
  458. begin
  459. { Move the function result to free registers, preferably the
  460. FUNCTION_RESULT_REG/FUNCTION_RESULTHIGH_REG, so no move is necessary.}
  461. r.enum:=R_INTREGISTER;
  462. r.number:=NR_FUNCTION_RESULT64_LOW_REG;
  463. hregister.enum:=R_INTREGISTER;
  464. hregister.number:=NR_FUNCTION_RESULT64_HIGH_REG;
  465. {$ifdef newra}
  466. { the FUNCTION_RESULT_LOW_REG/FUNCTION_RESULT_HIGH_REG
  467. are already allocated }
  468. rg.ungetregisterint(exprasmlist,r);
  469. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  470. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,r,location.registerlow);
  471. rg.ungetregisterint(exprasmlist,hregister);
  472. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  473. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,hregister,location.registerhigh);
  474. {$else newra}
  475. if RS_FUNCTION_RESULT64_LOW_REG in rg.unusedregsint then
  476. location.registerlow:=rg.getexplicitregisterint(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG)
  477. else
  478. cg.a_reg_alloc(exprasmlist,r);
  479. if RS_FUNCTION_RESULT64_HIGH_REG in rg.unusedregsint then
  480. location.registerhigh:=rg.getexplicitregisterint(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG)
  481. else
  482. cg.a_reg_alloc(exprasmlist,hregister);
  483. { do this after both low,high are allocated, else it is possible that
  484. low will be loaded in the register that still contains high }
  485. if location.registerlow.number=NR_NO then
  486. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  487. if location.registerhigh.number=NR_NO then
  488. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  489. cg64.a_load64_reg_reg(exprasmlist,joinreg64(r,hregister),
  490. location.register64{$ifdef newra},false{$endif});
  491. {$endif newra}
  492. end
  493. else
  494. {$endif cpu64bit}
  495. begin
  496. {Move the function result to a free register, preferably the
  497. FUNCTION_RESULT_REG, so no move is necessary.}
  498. r.enum:=R_INTREGISTER;
  499. r.number:=NR_FUNCTION_RESULT_REG;
  500. {$ifdef newra}
  501. { the FUNCTION_RESULT_REG is already allocated }
  502. rg.ungetregisterint(exprasmlist,r);
  503. { change register size after the unget because the
  504. getregister was done for the full register }
  505. r:=rg.makeregsize(r,cgsize);
  506. location.register:=rg.getregisterint(exprasmlist,cgsize);
  507. {$else newra}
  508. r:=rg.makeregsize(r,cgsize);
  509. cg.a_reg_alloc(exprasmlist,r);
  510. if RS_FUNCTION_RESULT_REG in rg.unusedregsint then
  511. begin
  512. location.register:=rg.makeregsize(rg.getexplicitregisterint(
  513. exprasmlist,NR_FUNCTION_RESULT_REG),cgsize);
  514. end
  515. else
  516. location.register:=rg.getregisterint(exprasmlist,cgsize);
  517. {$endif newra}
  518. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,r,location.register);
  519. end;
  520. end
  521. else
  522. begin
  523. if resulttype.def.size>0 then
  524. internalerror(200305131);
  525. end;
  526. end;
  527. end
  528. else
  529. begin
  530. {$ifdef newra}
  531. cgsize:=def_cgsize(resulttype.def);
  532. { an object constructor is a function with pointer result }
  533. if (procdefinition.proctypeoption=potype_constructor) then
  534. cgsize:=OS_ADDR;
  535. if cgsize<>OS_NO then
  536. {$ifndef cpu64bit}
  537. if cgsize in [OS_64,OS_S64] then
  538. begin
  539. r.enum:=R_INTREGISTER;
  540. r.number:=NR_FUNCTION_RESULT64_LOW_REG;
  541. hregister.enum:=R_INTREGISTER;
  542. hregister.number:=NR_FUNCTION_RESULT64_HIGH_REG;
  543. rg.ungetregisterint(exprasmlist,r);
  544. rg.ungetregisterint(exprasmlist,hregister);
  545. end
  546. else
  547. {$endif cpu64bit}
  548. begin
  549. r.enum:=R_INTREGISTER;
  550. r.number:=NR_FUNCTION_RESULT_REG;
  551. rg.ungetregisterint(exprasmlist,r);
  552. end;
  553. {$endif newra}
  554. location_reset(location,LOC_VOID,OS_NO);
  555. end;
  556. end;
  557. procedure tcgcallnode.release_para_temps;
  558. var
  559. hp : tnode;
  560. ppn : tcallparanode;
  561. begin
  562. { Release temps from parameters }
  563. ppn:=tcallparanode(left);
  564. while assigned(ppn) do
  565. begin
  566. if assigned(ppn.left) then
  567. begin
  568. { don't release the funcret temp }
  569. if not(vo_is_funcret in tvarsym(ppn.paraitem.parasym).varoptions) then
  570. begin
  571. {$ifdef callparatemp}
  572. { free call-by-reference temps }
  573. if (ppn.left.nodetype = typeconvn) and
  574. (ttypeconvnode(ppn.left).left.nodetype = derefn) and
  575. (tderefnode(ttypeconvnode(ppn.left).left).left.nodetype = temprefn) then
  576. location_freetemp(exprasmlist,tderefnode(ttypeconvnode(ppn.left).left).left.location)
  577. else
  578. {$endif callparatemp}
  579. location_freetemp(exprasmlist,ppn.left.location);
  580. end;
  581. { process also all nodes of an array of const }
  582. if ppn.left.nodetype=arrayconstructorn then
  583. begin
  584. if assigned(tarrayconstructornode(ppn.left).left) then
  585. begin
  586. hp:=ppn.left;
  587. while assigned(hp) do
  588. begin
  589. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  590. hp:=tarrayconstructornode(hp).right;
  591. end;
  592. end;
  593. end;
  594. end;
  595. ppn:=tcallparanode(ppn.right);
  596. end;
  597. end;
  598. procedure tcgcallnode.normal_pass_2;
  599. var
  600. regs_to_push_other : tregisterset;
  601. unusedstate: pointer;
  602. {$ifdef newra}
  603. i:Tsuperregister;
  604. regs_to_alloc,regs_to_free:Tsupregset;
  605. funcretloc: tparalocation;
  606. {$else}
  607. regs_to_push_int : Tsupregset;
  608. pushedint : tpushedsavedint;
  609. pushedregs : tmaybesave;
  610. {$endif}
  611. pushedother : tpushedsavedother;
  612. oldpushedparasize : longint;
  613. { adress returned from an I/O-error }
  614. iolabel : tasmlabel;
  615. { help reference pointer }
  616. href,helpref : treference;
  617. para_alignment,
  618. pop_size : longint;
  619. r,
  620. {$ifdef x86}
  621. accreg,
  622. {$endif x86}
  623. vmtreg,vmtreg2 : tregister;
  624. oldaktcallnode : tcallnode;
  625. procedure freeparas;
  626. var
  627. paraitem : tparaitem;
  628. begin
  629. { free the resources allocated for the parameters }
  630. paraitem:=tparaitem(procdefinition.para.first);
  631. while assigned(paraitem) do
  632. begin
  633. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  634. paraitem:=tparaitem(paraitem.next);
  635. end;
  636. { free pushed base pointer }
  637. if (right=nil) and
  638. (current_procinfo.procdef.parast.symtablelevel>=normal_function_level) and
  639. assigned(tprocdef(procdefinition).parast) and
  640. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  641. free_pushed_framepointer;
  642. end;
  643. begin
  644. if not assigned(procdefinition) then
  645. internalerror(200305264);
  646. { calculate the parameter info for the procdef }
  647. if not procdefinition.has_paraloc_info then
  648. begin
  649. paramanager.create_paraloc_info(procdefinition,callerside);
  650. procdefinition.has_paraloc_info:=true;
  651. end;
  652. iolabel:=nil;
  653. rg.saveunusedstate(unusedstate);
  654. if not assigned(funcretnode) then
  655. begin
  656. { if we allocate the temp. location for ansi- or widestrings }
  657. { already here, we avoid later a push/pop }
  658. if is_widestring(resulttype.def) then
  659. begin
  660. tg.gettemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  661. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  662. end
  663. else if is_ansistring(resulttype.def) then
  664. begin
  665. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  666. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  667. end;
  668. end;
  669. if (procdefinition.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_stdcall]) then
  670. para_alignment:=4
  671. else
  672. para_alignment:=aktalignment.paraalign;
  673. { proc variables destroy all registers }
  674. if (right=nil) and
  675. { virtual methods too }
  676. not(po_virtualmethod in procdefinition.procoptions) then
  677. begin
  678. if (cs_check_io in aktlocalswitches) and
  679. (po_iocheck in procdefinition.procoptions) and
  680. not(po_iocheck in current_procinfo.procdef.procoptions) then
  681. begin
  682. objectlibrary.getaddrlabel(iolabel);
  683. cg.a_label(exprasmlist,iolabel);
  684. end
  685. else
  686. iolabel:=nil;
  687. {$ifdef newra}
  688. regs_to_alloc:=Tprocdef(procdefinition).usedintregisters;
  689. if (not is_void(resulttype.def)) and
  690. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  691. begin
  692. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  693. case funcretloc.loc of
  694. LOC_REGISTER,LOC_CREGISTER:
  695. begin
  696. {$ifndef cpu64bit}
  697. if funcretloc.size in [OS_S64,OS_64] then
  698. begin
  699. include(regs_to_alloc,funcretloc.registerlow.number shr 8);
  700. include(regs_to_alloc,funcretloc.registerhigh.number shr 8);
  701. end
  702. else
  703. {$endif cpu64bit}
  704. include(regs_to_alloc,funcretloc.register.number shr 8);
  705. end;
  706. end;
  707. end;
  708. {$else}
  709. { save all used registers and possible registers
  710. used for the return value }
  711. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  712. if (not is_void(resulttype.def)) and
  713. (not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  714. begin
  715. {$ifndef cpu64bit}
  716. if resulttype.def.deftype<>floatdef then
  717. if resulttype.def.size>sizeof(aword) then
  718. begin
  719. include(regs_to_push_int,RS_FUNCTION_RESULT64_LOW_REG);
  720. include(regs_to_push_int,RS_FUNCTION_RESULT64_HIGH_REG);
  721. end
  722. else
  723. {$endif cpu64bit}
  724. include(regs_to_push_int,RS_FUNCTION_RESULT_REG);
  725. end;
  726. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  727. {$endif}
  728. {$ifdef i386}
  729. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  730. {$else i386}
  731. regs_to_push_other := [];
  732. {$endif i386}
  733. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  734. { on the ppc, ever procedure saves the non-volatile registers it uses itself }
  735. { and must make sure it saves its volatile registers before doing a call }
  736. {$ifdef i386}
  737. { give used registers through }
  738. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  739. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  740. {$endif i386}
  741. end
  742. else
  743. begin
  744. {No procedure is allowed to destroy ebp.}
  745. {$ifdef newra}
  746. regs_to_alloc:=VOLATILE_INTREGISTERS;
  747. if (not is_void(resulttype.def)) and
  748. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  749. begin
  750. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  751. case funcretloc.loc of
  752. LOC_REGISTER,LOC_CREGISTER:
  753. begin
  754. {$ifndef cpu64bit}
  755. if funcretloc.size in [OS_S64,OS_64] then
  756. begin
  757. include(regs_to_alloc,funcretloc.registerlow.number shr 8);
  758. include(regs_to_alloc,funcretloc.registerhigh.number shr 8);
  759. end
  760. else
  761. {$endif cpu64bit}
  762. include(regs_to_alloc,funcretloc.register.number shr 8);
  763. end;
  764. end;
  765. end;
  766. {$else}
  767. regs_to_push_int := VOLATILE_INTREGISTERS;
  768. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  769. {$endif}
  770. {$ifdef i386}
  771. regs_to_push_other := all_registers;
  772. {$else i386}
  773. regs_to_push_other := [];
  774. {$endif i386}
  775. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  776. {$ifdef i386}
  777. rg.used_in_proc_other:=all_registers;
  778. {$endif i386}
  779. { no IO check for methods and procedure variables }
  780. iolabel:=nil;
  781. end;
  782. { Initialize for pushing the parameters }
  783. oldpushedparasize:=pushedparasize;
  784. pushedparasize:=0;
  785. { Align stack if required }
  786. pop_size:=align_parasize;
  787. { Push parameters }
  788. oldaktcallnode:=aktcallnode;
  789. aktcallnode:=self;
  790. {$ifndef i386}
  791. { process procvar. Done here already, because otherwise it may }
  792. { destroy registers containing a parameter for the actual }
  793. { function call (e.g. if it's a function, its result will }
  794. { overwrite r3, which contains the first parameter) (JM) }
  795. if assigned(right) then
  796. secondpass(right);
  797. if (po_virtualmethod in procdefinition.procoptions) and
  798. assigned(methodpointer) then
  799. begin
  800. secondpass(methodpointer);
  801. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  802. { virtual methods require an index }
  803. if tprocdef(procdefinition).extnumber=-1 then
  804. internalerror(200304021);
  805. { VMT should already be loaded in a register }
  806. if methodpointer.location.register.number=NR_NO then
  807. internalerror(200304022);
  808. { test validity of VMT }
  809. if not(is_interface(tprocdef(procdefinition)._class)) and
  810. not(is_cppclass(tprocdef(procdefinition)._class)) then
  811. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  812. end;
  813. {$endif not i386}
  814. if assigned(left) then
  815. begin
  816. {$ifndef newra}
  817. if assigned(right) then
  818. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  819. else
  820. if assigned(methodpointer) then
  821. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  822. {$endif}
  823. tcallparanode(left).secondcallparan(
  824. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  825. para_alignment,0);
  826. {$ifndef newra}
  827. if assigned(right) then
  828. maybe_restore(exprasmlist,right.location,pushedregs)
  829. else
  830. if assigned(methodpointer) then
  831. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  832. {$endif newra}
  833. end;
  834. aktcallnode:=oldaktcallnode;
  835. { procedure variable or normal function call ? }
  836. if (right=nil) then
  837. begin
  838. { push base pointer ?}
  839. if (current_procinfo.procdef.parast.symtablelevel>=normal_function_level) and
  840. assigned(tprocdef(procdefinition).parast) and
  841. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  842. push_framepointer;
  843. {$ifndef newra}
  844. rg.saveintregvars(exprasmlist,regs_to_push_int);
  845. {$endif}
  846. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  847. if (po_virtualmethod in procdefinition.procoptions) and
  848. assigned(methodpointer) then
  849. begin
  850. {$ifdef i386}
  851. secondpass(methodpointer);
  852. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  853. vmtreg:=methodpointer.location.register;
  854. { virtual methods require an index }
  855. if tprocdef(procdefinition).extnumber=-1 then
  856. internalerror(200304021);
  857. { VMT should already be loaded in a register }
  858. if vmtreg.number=NR_NO then
  859. internalerror(200304022);
  860. { test validity of VMT }
  861. if not(is_interface(tprocdef(procdefinition)._class)) and
  862. not(is_cppclass(tprocdef(procdefinition)._class)) then
  863. cg.g_maybe_testvmt(exprasmlist,vmtreg,tprocdef(procdefinition)._class);
  864. {$else}
  865. vmtreg:=methodpointer.location.register;
  866. {$endif}
  867. {$ifdef newra}
  868. { release self }
  869. rg.ungetaddressregister(exprasmlist,vmtreg);
  870. vmtreg2:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  871. rg.ungetregisterint(exprasmlist,vmtreg2);
  872. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,vmtreg,vmtreg2);
  873. {$endif newra}
  874. { free the resources allocated for the parameters }
  875. freeparas;
  876. {$ifdef newra}
  877. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  878. {$endif}
  879. { call method }
  880. reference_reset_base(href,{$ifdef newra}vmtreg2{$else}vmtreg{$endif},
  881. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  882. cg.a_call_ref(exprasmlist,href);
  883. {$ifndef newra}
  884. { release self }
  885. rg.ungetaddressregister(exprasmlist,vmtreg);
  886. {$endif}
  887. end
  888. else
  889. begin
  890. { free the resources allocated for the parameters }
  891. freeparas;
  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. freeparas;
  934. {$ifdef newra}
  935. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  936. {$endif}
  937. { Calling interrupt from the same code requires some
  938. extra code }
  939. if (po_interrupt in procdefinition.procoptions) then
  940. extra_interrupt_code;
  941. {$ifndef newra}
  942. helpref:=right.location.reference;
  943. rg.saveintregvars(exprasmlist,VOLATILE_INTREGISTERS);
  944. {$endif}
  945. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  946. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  947. cg.a_call_ref(exprasmlist,helpref)
  948. else
  949. cg.a_call_reg(exprasmlist,right.location.register);
  950. { cg.a_call_loc(exprasmlist,right.location);}
  951. location_release(exprasmlist,right.location);
  952. location_freetemp(exprasmlist,right.location);
  953. end;
  954. { Need to remove the parameters from the stack? }
  955. if (po_clearstack in procdefinition.procoptions) then
  956. begin
  957. { the old pop_size was already included in pushedparasize }
  958. pop_size:=pushedparasize;
  959. { for Cdecl functions we don't need to pop the funcret when it
  960. was pushed by para }
  961. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  962. dec(pop_size,POINTER_SIZE);
  963. end;
  964. { Remove parameters/alignment from the stack }
  965. if pop_size>0 then
  966. pop_parasize(pop_size);
  967. { Reserve space for storing parameters that will be pushed }
  968. current_procinfo.allocate_push_parasize(pushedparasize);
  969. { Restore }
  970. pushedparasize:=oldpushedparasize;
  971. rg.restoreunusedstate(unusedstate);
  972. {$ifdef TEMPREGDEBUG}
  973. testregisters32;
  974. {$endif TEMPREGDEBUG}
  975. {$ifdef newra}
  976. regs_to_free:=regs_to_alloc;
  977. if (not is_void(resulttype.def)) and
  978. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  979. begin
  980. case funcretloc.loc of
  981. LOC_REGISTER,LOC_CREGISTER:
  982. begin
  983. {$ifndef cpu64bit}
  984. if funcretloc.size in [OS_S64,OS_64] then
  985. begin
  986. exclude(regs_to_free,funcretloc.registerlow.number shr 8);
  987. exclude(regs_to_free,funcretloc.registerhigh.number shr 8);
  988. end
  989. else
  990. {$endif cpu64bit}
  991. exclude(regs_to_free,funcretloc.register.number shr 8);
  992. end;
  993. end;
  994. end;
  995. rg.deallocexplicitregistersint(exprasmlist,regs_to_free);
  996. {$endif}
  997. { handle function results }
  998. if (not is_void(resulttype.def)) then
  999. handle_return_value
  1000. else
  1001. location_reset(location,LOC_VOID,OS_NO);
  1002. { perhaps i/o check ? }
  1003. if iolabel<>nil then
  1004. begin
  1005. reference_reset_symbol(href,iolabel,0);
  1006. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1007. paramanager.freeintparaloc(exprasmlist,1);
  1008. {$ifdef newra}
  1009. rg.allocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1010. {$endif newra}
  1011. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1012. {$ifdef newra}
  1013. rg.deallocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1014. {$endif newra}
  1015. end;
  1016. { restore registers }
  1017. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1018. {$ifndef newra}
  1019. rg.restoreusedintregisters(exprasmlist,pushedint);
  1020. {$endif}
  1021. { release temps of paras }
  1022. release_para_temps;
  1023. { if return value is not used }
  1024. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  1025. begin
  1026. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1027. begin
  1028. { data which must be finalized ? }
  1029. if (resulttype.def.needs_inittable) then
  1030. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1031. { release unused temp }
  1032. tg.ungetiftemp(exprasmlist,location.reference)
  1033. end
  1034. else if location.loc=LOC_FPUREGISTER then
  1035. begin
  1036. {$ifdef x86}
  1037. { release FPU stack }
  1038. accreg.enum:=FPU_RESULT_REG;
  1039. emit_reg(A_FSTP,S_NO,accreg);
  1040. {
  1041. dec(trgcpu(rg).fpuvaroffset);
  1042. do NOT decrement as the increment before
  1043. is not called for unused results PM }
  1044. {$endif x86}
  1045. end;
  1046. end;
  1047. end;
  1048. procedure tcgcallnode.inlined_pass_2;
  1049. var
  1050. regs_to_push_int : Tsupregset;
  1051. regs_to_push_other : tregisterset;
  1052. unusedstate: pointer;
  1053. pushedother : tpushedsavedother;
  1054. {$ifndef newra}
  1055. pushedint : tpushedsavedint;
  1056. pushedregs : tmaybesave;
  1057. {$endif}
  1058. funcretloc: tparalocation;
  1059. oldpushedparasize : longint;
  1060. { adress returned from an I/O-error }
  1061. iolabel : tasmlabel;
  1062. { help reference pointer }
  1063. href : treference;
  1064. {$ifdef x86}
  1065. accreg : tregister;
  1066. {$endif x86}
  1067. oldaktcallnode : tcallnode;
  1068. oldprocdef : tprocdef;
  1069. i : longint;
  1070. oldprocinfo : tprocinfo;
  1071. oldinlining_procedure : boolean;
  1072. inlineentrycode,inlineexitcode : TAAsmoutput;
  1073. oldregstate: pointer;
  1074. old_local_fixup,
  1075. old_para_fixup : longint;
  1076. usesacc,usesacchi,usesfpu : boolean;
  1077. pararef,
  1078. localsref : treference;
  1079. {$ifdef GDB}
  1080. startlabel,endlabel : tasmlabel;
  1081. pp : pchar;
  1082. mangled_length : longint;
  1083. {$endif GDB}
  1084. begin
  1085. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  1086. internalerror(200305262);
  1087. oldinlining_procedure:=inlining_procedure;
  1088. oldprocdef:=current_procinfo.procdef;
  1089. oldprocinfo:=current_procinfo;
  1090. { we're inlining a procedure }
  1091. inlining_procedure:=true;
  1092. { calculate the parameter info for the procdef }
  1093. if not procdefinition.has_paraloc_info then
  1094. begin
  1095. paramanager.create_paraloc_info(procdefinition,callerside);
  1096. procdefinition.has_paraloc_info:=true;
  1097. end;
  1098. { deallocate the registers used for the current procedure's regvars }
  1099. if assigned(current_procinfo.procdef.regvarinfo) then
  1100. begin
  1101. with pregvarinfo(current_procinfo.procdef.regvarinfo)^ do
  1102. for i := 1 to maxvarregs do
  1103. if assigned(regvars[i]) then
  1104. store_regvar(exprasmlist,regvars[i].reg);
  1105. rg.saveStateForInline(oldregstate);
  1106. { make sure the register allocator knows what the regvars in the }
  1107. { inlined code block are (JM) }
  1108. rg.resetusableregisters;
  1109. rg.clearregistercount;
  1110. {$ifndef newra}
  1111. rg.cleartempgen;
  1112. {$endif}
  1113. if assigned(tprocdef(procdefinition).regvarinfo) then
  1114. with pregvarinfo(tprocdef(procdefinition).regvarinfo)^ do
  1115. for i := 1 to maxvarregs do
  1116. if assigned(regvars[i]) then
  1117. begin
  1118. {Fix me!!}
  1119. {tmpreg:=rg.makeregsize(regvars[i].reg,OS_INT);
  1120. rg.makeregvar(tmpreg);}
  1121. internalerror(200301232);
  1122. end;
  1123. end;
  1124. { create temp procinfo }
  1125. current_procinfo:=cprocinfo.create(nil);
  1126. current_procinfo.procdef:=tprocdef(procdefinition);
  1127. { Localsymtable }
  1128. current_procinfo.procdef.localst.symtablelevel:=oldprocdef.localst.symtablelevel;
  1129. if current_procinfo.procdef.localst.datasize>0 then
  1130. begin
  1131. old_local_fixup:=current_procinfo.procdef.localst.address_fixup;
  1132. tg.GetTemp(exprasmlist,current_procinfo.procdef.localst.datasize,tt_persistent,localsref);
  1133. if tg.direction>0 then
  1134. current_procinfo.procdef.localst.address_fixup:=localsref.offset
  1135. else
  1136. current_procinfo.procdef.localst.address_fixup:=localsref.offset+current_procinfo.procdef.localst.datasize;
  1137. {$ifdef extdebug}
  1138. Comment(V_debug,'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup));
  1139. exprasmList.concat(tai_comment.Create(strpnew(
  1140. 'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup))));
  1141. {$endif extdebug}
  1142. end;
  1143. { Parasymtable }
  1144. current_procinfo.procdef.parast.symtablelevel:=oldprocdef.localst.symtablelevel;
  1145. if current_procinfo.procdef.parast.datasize>0 then
  1146. begin
  1147. old_para_fixup:=current_procinfo.procdef.parast.address_fixup;
  1148. tg.GetTemp(exprasmlist,current_procinfo.procdef.parast.datasize,tt_persistent,pararef);
  1149. current_procinfo.procdef.parast.address_fixup:=pararef.offset;
  1150. {$ifdef extdebug}
  1151. Comment(V_debug,'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup));
  1152. exprasmList.concat(tai_comment.Create(strpnew(
  1153. 'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup))));
  1154. {$endif extdebug}
  1155. end;
  1156. exprasmList.concat(Tai_Marker.Create(InlineStart));
  1157. {$ifdef extdebug}
  1158. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  1159. {$endif extdebug}
  1160. {$ifdef GDB}
  1161. if (cs_debuginfo in aktmoduleswitches) then
  1162. begin
  1163. objectlibrary.getaddrlabel(startlabel);
  1164. objectlibrary.getaddrlabel(endlabel);
  1165. cg.a_label(exprasmlist,startlabel);
  1166. tprocdef(procdefinition).localst.symtabletype:=inlinelocalsymtable;
  1167. procdefinition.parast.symtabletype:=inlineparasymtable;
  1168. { Here we must include the para and local symtable info }
  1169. procdefinition.concatstabto(withdebuglist);
  1170. { set it back for safety }
  1171. tprocdef(procdefinition).localst.symtabletype:=localsymtable;
  1172. procdefinition.parast.symtabletype:=parasymtable;
  1173. mangled_length:=length(oldprocdef.mangledname);
  1174. getmem(pp,mangled_length+50);
  1175. strpcopy(pp,'192,0,0,'+startlabel.name);
  1176. if (target_info.use_function_relative_addresses) then
  1177. begin
  1178. strpcopy(strend(pp),'-');
  1179. strpcopy(strend(pp),oldprocdef.mangledname);
  1180. end;
  1181. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1182. end;
  1183. {$endif GDB}
  1184. iolabel:=nil;
  1185. rg.saveunusedstate(unusedstate);
  1186. { if we allocate the temp. location for ansi- or widestrings }
  1187. { already here, we avoid later a push/pop }
  1188. if is_widestring(resulttype.def) then
  1189. begin
  1190. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  1191. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1192. end
  1193. else if is_ansistring(resulttype.def) then
  1194. begin
  1195. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  1196. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1197. end;
  1198. if (cs_check_io in aktlocalswitches) and
  1199. (po_iocheck in procdefinition.procoptions) and
  1200. not(po_iocheck in current_procinfo.procdef.procoptions) then
  1201. begin
  1202. objectlibrary.getaddrlabel(iolabel);
  1203. cg.a_label(exprasmlist,iolabel);
  1204. end
  1205. else
  1206. iolabel:=nil;
  1207. { save all used registers and possible registers
  1208. used for the return value }
  1209. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  1210. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  1211. if (not is_void(resulttype.def)) and
  1212. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  1213. begin
  1214. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  1215. case funcretloc.loc of
  1216. LOC_REGISTER,LOC_CREGISTER:
  1217. begin
  1218. {$ifndef cpu64bit}
  1219. if funcretloc.size in [OS_S64,OS_64] then
  1220. begin
  1221. include(regs_to_push_int,funcretloc.registerlow.number shr 8);
  1222. include(regs_to_push_int,funcretloc.registerhigh.number shr 8);
  1223. end
  1224. else
  1225. {$endif cpu64bit}
  1226. include(regs_to_push_int,funcretloc.register.number shr 8);
  1227. end;
  1228. end;
  1229. end;
  1230. {$ifndef newra}
  1231. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  1232. {$endif}
  1233. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  1234. {$ifdef i386}
  1235. { give used registers through }
  1236. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  1237. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  1238. {$endif i386}
  1239. { Initialize for pushing the parameters }
  1240. oldpushedparasize:=pushedparasize;
  1241. pushedparasize:=0;
  1242. { Push parameters }
  1243. oldaktcallnode:=aktcallnode;
  1244. aktcallnode:=self;
  1245. if assigned(left) then
  1246. begin
  1247. {$ifndef newra}
  1248. if assigned(right) then
  1249. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  1250. else
  1251. if assigned(methodpointer) then
  1252. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  1253. {$endif}
  1254. { we push from right to left, so start with parameters at the end of
  1255. the parameter block }
  1256. tcallparanode(left).secondcallparan(
  1257. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  1258. 0,procdefinition.parast.address_fixup+procdefinition.parast.datasize);
  1259. {$ifndef newra}
  1260. if assigned(right) then
  1261. maybe_restore(exprasmlist,right.location,pushedregs)
  1262. else
  1263. if assigned(methodpointer) then
  1264. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  1265. {$endif newra}
  1266. end;
  1267. aktcallnode:=oldaktcallnode;
  1268. {$ifndef newra}
  1269. rg.saveintregvars(exprasmlist,regs_to_push_int);
  1270. {$endif}
  1271. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  1272. { takes care of local data initialization }
  1273. inlineentrycode:=TAAsmoutput.Create;
  1274. inlineexitcode:=TAAsmoutput.Create;
  1275. gen_initialize_code(inlineentrycode,true);
  1276. if po_assembler in current_procinfo.procdef.procoptions then
  1277. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  1278. exprasmList.concatlist(inlineentrycode);
  1279. { process the inline code }
  1280. secondpass(inlinecode);
  1281. { Reserve space for storing parameters that will be pushed }
  1282. current_procinfo.allocate_push_parasize(pushedparasize);
  1283. { Restore }
  1284. pushedparasize:=oldpushedparasize;
  1285. rg.restoreunusedstate(unusedstate);
  1286. {$ifdef TEMPREGDEBUG}
  1287. testregisters32;
  1288. {$endif TEMPREGDEBUG}
  1289. gen_finalize_code(inlineexitcode,true);
  1290. gen_load_return_value(inlineexitcode,usesacc,usesacchi,usesfpu);
  1291. if po_assembler in current_procinfo.procdef.procoptions then
  1292. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  1293. exprasmList.concatlist(inlineexitcode);
  1294. inlineentrycode.free;
  1295. inlineexitcode.free;
  1296. {$ifdef extdebug}
  1297. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  1298. {$endif extdebug}
  1299. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1300. {we can free the local data now, reset also the fixup address }
  1301. if current_procinfo.procdef.localst.datasize>0 then
  1302. begin
  1303. tg.UnGetTemp(exprasmlist,localsref);
  1304. current_procinfo.procdef.localst.address_fixup:=old_local_fixup;
  1305. end;
  1306. {we can free the para data now, reset also the fixup address }
  1307. if current_procinfo.procdef.parast.datasize>0 then
  1308. begin
  1309. tg.UnGetTemp(exprasmlist,pararef);
  1310. current_procinfo.procdef.parast.address_fixup:=old_para_fixup;
  1311. end;
  1312. { free return reference }
  1313. if (resulttype.def.size>0) then
  1314. begin
  1315. { from now on the result can be freed normally }
  1316. // if assigned(funcretnode) and
  1317. // paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1318. // tg.ChangeTempType(exprasmlist,funcretnode.location.reference,tt_normal);
  1319. end;
  1320. { handle function results }
  1321. if (not is_void(resulttype.def)) then
  1322. handle_return_value
  1323. else
  1324. location_reset(location,LOC_VOID,OS_NO);
  1325. { perhaps i/o check ? }
  1326. if iolabel<>nil then
  1327. begin
  1328. reference_reset_symbol(href,iolabel,0);
  1329. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1330. paramanager.freeintparaloc(exprasmlist,1);
  1331. {$ifdef newra}
  1332. rg.allocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1333. {$endif newra}
  1334. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1335. {$ifdef newra}
  1336. rg.deallocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1337. {$endif newra}
  1338. end;
  1339. { restore registers }
  1340. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1341. {$ifndef newra}
  1342. rg.restoreusedintregisters(exprasmlist,pushedint);
  1343. {$endif}
  1344. { release temps of paras }
  1345. release_para_temps;
  1346. { if return value is not used }
  1347. if (not is_void(resulttype.def)) and
  1348. (not(nf_return_value_used in flags)) then
  1349. begin
  1350. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1351. begin
  1352. { data which must be finalized ? }
  1353. if (resulttype.def.needs_inittable) then
  1354. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1355. { release unused temp }
  1356. tg.ungetiftemp(exprasmlist,location.reference)
  1357. end
  1358. else if location.loc=LOC_FPUREGISTER then
  1359. begin
  1360. {$ifdef x86}
  1361. { release FPU stack }
  1362. accreg.enum:=FPU_RESULT_REG;
  1363. emit_reg(A_FSTP,S_NO,accreg);
  1364. {
  1365. dec(trgcpu(rg).fpuvaroffset);
  1366. do NOT decrement as the increment before
  1367. is not called for unused results PM }
  1368. {$endif x86}
  1369. end;
  1370. end;
  1371. { release procinfo }
  1372. current_procinfo.free;
  1373. current_procinfo:=oldprocinfo;
  1374. {$ifdef GDB}
  1375. if (cs_debuginfo in aktmoduleswitches) then
  1376. begin
  1377. cg.a_label(exprasmlist,endlabel);
  1378. strpcopy(pp,'224,0,0,'+endlabel.name);
  1379. if (target_info.use_function_relative_addresses) then
  1380. begin
  1381. strpcopy(strend(pp),'-');
  1382. strpcopy(strend(pp),oldprocdef.mangledname);
  1383. end;
  1384. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1385. freemem(pp,mangled_length+50);
  1386. end;
  1387. {$endif GDB}
  1388. { restore }
  1389. current_procinfo.procdef:=oldprocdef;
  1390. inlining_procedure:=oldinlining_procedure;
  1391. { reallocate the registers used for the current procedure's regvars, }
  1392. { since they may have been used and then deallocated in the inlined }
  1393. { procedure (JM) }
  1394. if assigned(current_procinfo.procdef.regvarinfo) then
  1395. rg.restoreStateAfterInline(oldregstate);
  1396. end;
  1397. procedure tcgcallnode.pass_2;
  1398. begin
  1399. if assigned(inlinecode) then
  1400. inlined_pass_2
  1401. else
  1402. normal_pass_2;
  1403. end;
  1404. begin
  1405. ccallparanode:=tcgcallparanode;
  1406. ccallnode:=tcgcallnode;
  1407. end.
  1408. {
  1409. $Log$
  1410. Revision 1.104 2003-08-11 14:22:06 mazen
  1411. - dupplicated code removed
  1412. Revision 1.103 2003/07/23 11:01:14 jonas
  1413. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  1414. pairs round calls to helpers
  1415. Revision 1.102 2003/07/21 13:51:50 jonas
  1416. * fixed 64bit int results with -dnewra (you can't free both registers and
  1417. then allocate two new ones, because then the registers could be reversed
  1418. afterwards -> you get something like "movl %eax, %edx; movl %edx,%eax")
  1419. Revision 1.101 2003/07/08 21:24:59 peter
  1420. * sparc fixes
  1421. Revision 1.100 2003/07/06 21:50:33 jonas
  1422. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  1423. so that it doesn't include ebp and esp anymore
  1424. Revision 1.99 2003/07/06 17:58:22 peter
  1425. * framepointer fixes for sparc
  1426. * parent framepointer code more generic
  1427. Revision 1.98 2003/07/06 15:31:20 daniel
  1428. * Fixed register allocator. *Lots* of fixes.
  1429. Revision 1.97 2003/07/05 20:21:26 jonas
  1430. * create_paraloc_info() is now called separately for the caller and
  1431. callee info
  1432. * fixed ppc cycle
  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. }