ncgcal.pas 77 KB

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