ncgcal.pas 73 KB

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