ncgcal.pas 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  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 bymethodpointer
  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. protected
  33. refcountedtemp : treference;
  34. procedure handle_return_value(inlined:boolean);
  35. {# This routine is used to push the current frame pointer
  36. on the stack. This is used in nested routines where the
  37. value of the frame pointer is always pushed as an extra
  38. parameter.
  39. The default handling is the standard handling used on
  40. most stack based machines, where the frame pointer is
  41. the first invisible parameter.
  42. }
  43. function align_parasize(parasize,para_alignment:longint):longint;virtual;
  44. procedure pop_parasize(pop_size:longint);virtual;
  45. procedure push_framepointer;virtual;
  46. procedure extra_interrupt_code;virtual;
  47. public
  48. procedure pass_2;override;
  49. end;
  50. tcgprocinlinenode = class(tprocinlinenode)
  51. procedure pass_2;override;
  52. end;
  53. implementation
  54. uses
  55. systems,
  56. cutils,verbose,globals,
  57. symconst,symbase,symsym,symtable,defutil,paramgr,
  58. {$ifdef GDB}
  59. {$ifdef delphi}
  60. sysutils,
  61. {$else}
  62. strings,
  63. {$endif}
  64. gdb,
  65. {$endif GDB}
  66. cginfo,cgbase,pass_2,
  67. cpuinfo,cpupi,aasmbase,aasmtai,aasmcpu,
  68. nbas,nmem,nld,ncnv,
  69. {$ifdef x86}
  70. cga,
  71. {$endif x86}
  72. {$ifdef cpu64bit}
  73. cg64f64,
  74. {$else cpu64bit}
  75. cg64f32,
  76. {$endif cpu64bit}
  77. ncgutil,cgobj,tgobj,regvars,rgobj,rgcpu,cgcpu;
  78. var
  79. { Current callnode, this is needed for having a link
  80. between the callparanodes and the callnode they belong to }
  81. aktcallnode : tcallnode;
  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. if (nf_varargs_para in flags) then
  102. tcallparanode(right).secondcallparan(push_from_left_to_right,
  103. calloption,para_alignment,para_offset)
  104. else
  105. tcallparanode(right).secondcallparan(push_from_left_to_right,
  106. calloption,para_alignment,para_offset);
  107. end;
  108. otlabel:=truelabel;
  109. oflabel:=falselabel;
  110. objectlibrary.getlabel(truelabel);
  111. objectlibrary.getlabel(falselabel);
  112. secondpass(left);
  113. { handle varargs first, because defcoll is not valid }
  114. if (nf_varargs_para in flags) then
  115. begin
  116. if paramanager.push_addr_param(left.resulttype.def,calloption) then
  117. begin
  118. inc(pushedparasize,POINTER_SIZE);
  119. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  120. location_release(exprasmlist,left.location);
  121. end
  122. else
  123. push_value_para(exprasmlist,left,calloption,para_offset,para_alignment,paraitem.paraloc);
  124. end
  125. { hidden parameters }
  126. else if paraitem.is_hidden then
  127. begin
  128. { don't push a node that already generated a pointer type
  129. by address for implicit hidden parameters }
  130. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  131. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  132. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  133. begin
  134. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  135. internalerror(200305071);
  136. inc(pushedparasize,POINTER_SIZE);
  137. if calloption=pocall_inline then
  138. begin
  139. {$ifdef newra}
  140. tmpreg:=rg.getaddressregister(exprasmlist);
  141. {$else}
  142. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  143. {$endif}
  144. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  145. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  146. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  147. {$ifdef newra}
  148. rg.ungetregisterint(exprasmlist,tmpreg);
  149. {$else}
  150. cg.free_scratch_reg(exprasmlist,tmpreg);
  151. {$endif}
  152. end
  153. else
  154. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  155. location_release(exprasmlist,left.location);
  156. end
  157. else
  158. begin
  159. push_value_para(exprasmlist,left,calloption,
  160. para_offset,para_alignment,paraitem.paraloc);
  161. end;
  162. end
  163. { filter array of const c styled args }
  164. else if is_array_of_const(left.resulttype.def) and (nf_cargs in left.flags) then
  165. begin
  166. { nothing, everything is already pushed }
  167. end
  168. { in codegen.handleread.. paraitem.data is set to nil }
  169. else if assigned(paraitem.paratype.def) and
  170. (paraitem.paratype.def.deftype=formaldef) then
  171. begin
  172. { allow passing of a constant to a const formaldef }
  173. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  174. (left.location.loc=LOC_CONSTANT) then
  175. location_force_mem(exprasmlist,left.location);
  176. { allow @var }
  177. inc(pushedparasize,POINTER_SIZE);
  178. if (left.nodetype=addrn) and
  179. (not(nf_procvarload in left.flags)) then
  180. begin
  181. if calloption=pocall_inline then
  182. begin
  183. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  184. cg.a_load_loc_ref(exprasmlist,left.location,href);
  185. end
  186. else
  187. cg.a_param_loc(exprasmlist,left.location,paraitem.paraloc);
  188. location_release(exprasmlist,left.location);
  189. end
  190. else
  191. begin
  192. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  193. internalerror(200304235);
  194. if calloption=pocall_inline then
  195. begin
  196. {$ifdef newra}
  197. tmpreg:=rg.getaddressregister(exprasmlist);
  198. {$else}
  199. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  200. {$endif newra}
  201. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  202. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  203. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  204. {$ifdef newra}
  205. rg.ungetregisterint(exprasmlist,tmpreg);
  206. {$else}
  207. cg.free_scratch_reg(exprasmlist,tmpreg);
  208. {$endif}
  209. end
  210. else
  211. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  212. location_release(exprasmlist,left.location);
  213. end;
  214. end
  215. { handle call by reference parameter }
  216. else if (paraitem.paratyp in [vs_var,vs_out]) then
  217. begin
  218. if (left.location.loc<>LOC_REFERENCE) then
  219. begin
  220. { passing self to a var parameter is allowed in
  221. TP and delphi }
  222. if not((left.location.loc=LOC_CREFERENCE) and
  223. is_self_node(left)) then
  224. internalerror(200106041);
  225. end;
  226. if (paraitem.paratyp=vs_out) and
  227. assigned(paraitem.paratype.def) and
  228. not is_class(paraitem.paratype.def) and
  229. paraitem.paratype.def.needs_inittable then
  230. cg.g_finalize(exprasmlist,paraitem.paratype.def,left.location.reference,false);
  231. inc(pushedparasize,POINTER_SIZE);
  232. if calloption=pocall_inline then
  233. begin
  234. {$ifdef newra}
  235. tmpreg:=rg.getaddressregister(exprasmlist);
  236. {$else}
  237. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  238. {$endif}
  239. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  240. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  241. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  242. {$ifdef newra}
  243. rg.ungetregisterint(exprasmlist,tmpreg);
  244. {$else}
  245. cg.free_scratch_reg(exprasmlist,tmpreg);
  246. {$endif}
  247. end
  248. else
  249. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  250. location_release(exprasmlist,left.location);
  251. end
  252. else
  253. begin
  254. { don't push a node that already generated a pointer type
  255. by address for implicit hidden parameters }
  256. if (not(
  257. paraitem.is_hidden and
  258. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  259. ) and
  260. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  261. begin
  262. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  263. begin
  264. { allow passing nil to a procvardef (methodpointer) }
  265. if (left.nodetype=typeconvn) and
  266. (left.resulttype.def.deftype=procvardef) and
  267. (ttypeconvnode(left).left.nodetype=niln) then
  268. begin
  269. tg.GetTemp(exprasmlist,tcgsize2size[left.location.size],tt_normal,href);
  270. if not (left.location.size in [OS_64,OS_S64]) then
  271. cg.a_load_loc_ref(exprasmlist,left.location,href)
  272. else
  273. cg64.a_load64_loc_ref(exprasmlist,left.location,href);
  274. location_reset(left.location,LOC_REFERENCE,left.location.size);
  275. left.location.reference:=href;
  276. end
  277. else
  278. internalerror(200204011);
  279. end;
  280. inc(pushedparasize,POINTER_SIZE);
  281. if calloption=pocall_inline then
  282. begin
  283. {$ifdef newra}
  284. tmpreg:=rg.getaddressregister(exprasmlist);
  285. {$else}
  286. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  287. {$endif}
  288. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  289. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  290. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  291. {$ifdef newra}
  292. rg.ungetregisterint(exprasmlist,tmpreg);
  293. {$else}
  294. cg.free_scratch_reg(exprasmlist,tmpreg);
  295. {$endif}
  296. end
  297. else
  298. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  299. location_release(exprasmlist,left.location);
  300. end
  301. else
  302. begin
  303. push_value_para(exprasmlist,left,calloption,
  304. para_offset,para_alignment,paraitem.paraloc);
  305. end;
  306. end;
  307. truelabel:=otlabel;
  308. falselabel:=oflabel;
  309. { update return location in callnode when this is the function
  310. result }
  311. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  312. begin
  313. location_copy(aktcallnode.location,left.location);
  314. end;
  315. { push from right to left }
  316. if not push_from_left_to_right and assigned(right) then
  317. begin
  318. if (nf_varargs_para in flags) then
  319. tcallparanode(right).secondcallparan(push_from_left_to_right,
  320. calloption,para_alignment,para_offset)
  321. else
  322. tcallparanode(right).secondcallparan(push_from_left_to_right,
  323. calloption,para_alignment,para_offset);
  324. end;
  325. end;
  326. {*****************************************************************************
  327. TCGCALLNODE
  328. *****************************************************************************}
  329. procedure tcgcallnode.extra_interrupt_code;
  330. begin
  331. end;
  332. function tcgcallnode.align_parasize(parasize,para_alignment:longint):longint;
  333. begin
  334. result:=0;
  335. end;
  336. procedure tcgcallnode.pop_parasize(pop_size:longint);
  337. begin
  338. end;
  339. procedure tcgcallnode.push_framepointer;
  340. var
  341. href : treference;
  342. hregister : tregister;
  343. i : integer;
  344. begin
  345. { this routine is itself not nested }
  346. if current_procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel) then
  347. begin
  348. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  349. cg.a_param_ref(exprasmlist,OS_ADDR,href,paramanager.getintparaloc(1));
  350. end
  351. { one nesting level }
  352. else if (current_procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  353. begin
  354. cg.a_param_reg(exprasmlist,OS_ADDR,current_procinfo.framepointer,paramanager.getintparaloc(1));
  355. end
  356. { very complex nesting level ... }
  357. else if (current_procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  358. begin
  359. hregister:=rg.getaddressregister(exprasmlist);
  360. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  361. cg.a_load_ref_reg(exprasmlist,OS_ADDR,href,hregister);
  362. i:=current_procdef.parast.symtablelevel;
  363. while (i>tprocdef(procdefinition).parast.symtablelevel) do
  364. begin
  365. reference_reset_base(href,hregister,current_procinfo.framepointer_offset);
  366. cg.a_load_ref_reg(exprasmlist,OS_ADDR,href,hregister);
  367. dec(i);
  368. end;
  369. cg.a_param_reg(exprasmlist,OS_ADDR,hregister,paramanager.getintparaloc(1));
  370. rg.ungetaddressregister(exprasmlist,hregister);
  371. end;
  372. end;
  373. procedure tcgcallnode.handle_return_value(inlined:boolean);
  374. var
  375. cgsize : tcgsize;
  376. r,hregister : tregister;
  377. nr:Tnewregister;
  378. begin
  379. { structured results are easy to handle.... }
  380. { needed also when result_no_used !! }
  381. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  382. begin
  383. { Location should be setup by the funcret para }
  384. if location.loc<>LOC_REFERENCE then
  385. internalerror(200304241);
  386. end
  387. else
  388. { ansi/widestrings must be registered, so we can dispose them }
  389. if is_ansistring(resulttype.def) or
  390. is_widestring(resulttype.def) then
  391. begin
  392. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  393. location.reference:=refcountedtemp;
  394. r.enum:=accumulator;
  395. cg.a_reg_alloc(exprasmlist,r);
  396. cg.a_load_reg_ref(exprasmlist,OS_ADDR,r,location.reference);
  397. cg.a_reg_dealloc(exprasmlist,r);
  398. end
  399. else
  400. { we have only to handle the result if it is used }
  401. if (nf_return_value_used in flags) then
  402. begin
  403. if (resulttype.def.deftype=floatdef) then
  404. begin
  405. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  406. {$ifdef cpufpemu}
  407. if cs_fp_emulation in aktmoduleswitches then
  408. location.register.enum := accumulator
  409. else
  410. {$endif cpufpemu}
  411. location.register.enum:=FPU_RESULT_REG;
  412. {$ifdef x86}
  413. inc(trgcpu(rg).fpuvaroffset);
  414. {$endif x86}
  415. end
  416. else
  417. begin
  418. cgsize:=def_cgsize(resulttype.def);
  419. { an object constructor is a function with pointer result }
  420. if (inlined or (right=nil)) and
  421. (procdefinition.proctypeoption=potype_constructor) then
  422. cgsize:=OS_ADDR;
  423. if cgsize<>OS_NO then
  424. begin
  425. location_reset(location,LOC_REGISTER,cgsize);
  426. {$ifndef cpu64bit}
  427. if cgsize in [OS_64,OS_S64] then
  428. begin
  429. {Move the function result to free registers, preferably the
  430. accumulator/accumulatorhigh, so no move is necessary.}
  431. r.enum:=R_INTREGISTER;
  432. r.number:=NR_ACCUMULATOR;
  433. hregister.enum:=R_INTREGISTER;
  434. hregister.number:=NR_ACCUMULATORHIGH;
  435. {$ifdef newra}
  436. rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATOR);
  437. rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATORHIGH);
  438. rg.ungetregisterint(exprasmlist,r);
  439. rg.ungetregisterint(exprasmlist,hregister);
  440. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  441. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  442. {$else newra}
  443. cg.a_reg_alloc(exprasmlist,r);
  444. cg.a_reg_alloc(exprasmlist,hregister);
  445. if RS_ACCUMULATOR in rg.unusedregsint then
  446. location.registerlow:=rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATOR)
  447. else
  448. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  449. if RS_ACCUMULATORHIGH in rg.unusedregsint then
  450. location.registerhigh:=rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATORHIGH)
  451. else
  452. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  453. {$endif newra}
  454. cg64.a_load64_reg_reg(exprasmlist,joinreg64(r,hregister),
  455. location.register64);
  456. end
  457. else
  458. {$endif cpu64bit}
  459. begin
  460. {Move the function result to a free register, preferably the
  461. accumulator, so no move is necessary.}
  462. nr:=RS_ACCUMULATOR shl 8 or cgsize2subreg(cgsize);
  463. r.enum:=R_INTREGISTER;
  464. r.number:=nr;
  465. {$ifdef newra}
  466. rg.getexplicitregisterint(exprasmlist,nr);
  467. rg.ungetregisterint(exprasmlist,r);
  468. location.register:=rg.getregisterint(exprasmlist,cgsize);
  469. {$else newra}
  470. cg.a_reg_alloc(exprasmlist,r);
  471. if RS_ACCUMULATOR in rg.unusedregsint then
  472. location.register:=rg.getexplicitregisterint(exprasmlist,nr)
  473. else
  474. location.register:=rg.getregisterint(exprasmlist,cgsize);
  475. {$endif newra}
  476. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,r,location.register);
  477. end;
  478. end
  479. else
  480. begin
  481. if resulttype.def.size>0 then
  482. internalerror(200305131);
  483. end;
  484. end;
  485. end
  486. else
  487. location_reset(location,LOC_VOID,OS_NO);
  488. end;
  489. procedure tcgcallnode.pass_2;
  490. var
  491. regs_to_push_int : Tsupregset;
  492. regs_to_push_other : tregisterset;
  493. unusedstate: pointer;
  494. pushed : tpushedsaved;
  495. pushedint : tpushedsavedint;
  496. oldpushedparasize : longint;
  497. { adress returned from an I/O-error }
  498. iolabel : tasmlabel;
  499. { help reference pointer }
  500. href : treference;
  501. hp : tnode;
  502. pp : tcallparanode;
  503. inlined : boolean;
  504. inlinecode : tprocinlinenode;
  505. pushedregs : tmaybesave;
  506. store_parast_fixup,
  507. para_alignment,
  508. para_offset : longint;
  509. pop_size : longint;
  510. returnref,
  511. pararef : treference;
  512. accreg : tregister;
  513. oldaktcallnode : tcallnode;
  514. begin
  515. iolabel:=nil;
  516. inlinecode:=nil;
  517. inlined:=false;
  518. rg.saveunusedstate(unusedstate);
  519. { if we allocate the temp. location for ansi- or widestrings }
  520. { already here, we avoid later a push/pop }
  521. if is_widestring(resulttype.def) then
  522. begin
  523. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  524. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  525. end
  526. else if is_ansistring(resulttype.def) then
  527. begin
  528. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  529. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  530. end;
  531. if (procdefinition.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_stdcall]) then
  532. para_alignment:=4
  533. else
  534. para_alignment:=aktalignment.paraalign;
  535. if not assigned(procdefinition) then
  536. exit;
  537. if (procdefinition.proccalloption=pocall_inline) then
  538. begin
  539. inlined:=true;
  540. inlinecode:=tprocinlinenode(right);
  541. right:=nil;
  542. { set it to the same lexical level as the local symtable, becuase
  543. the para's are stored there }
  544. tprocdef(procdefinition).parast.symtablelevel:=current_procdef.localst.symtablelevel;
  545. if assigned(left) then
  546. begin
  547. inlinecode.para_size:=tprocdef(procdefinition).para_size(para_alignment);
  548. tg.GetTemp(exprasmlist,inlinecode.para_size,tt_persistant,pararef);
  549. inlinecode.para_offset:=pararef.offset;
  550. end;
  551. store_parast_fixup:=tprocdef(procdefinition).parast.address_fixup;
  552. tprocdef(procdefinition).parast.address_fixup:=inlinecode.para_offset;
  553. {$ifdef extdebug}
  554. Comment(V_debug,
  555. 'inlined parasymtable is at offset '
  556. +tostr(tprocdef(procdefinition).parast.address_fixup));
  557. exprasmList.concat(tai_comment.Create(
  558. strpnew('inlined parasymtable is at offset '
  559. +tostr(tprocdef(procdefinition).parast.address_fixup))));
  560. {$endif extdebug}
  561. end;
  562. { proc variables destroy all registers }
  563. if (inlined or
  564. (right=nil)) and
  565. { virtual methods too }
  566. not(po_virtualmethod in procdefinition.procoptions) then
  567. begin
  568. if (cs_check_io in aktlocalswitches) and
  569. (po_iocheck in procdefinition.procoptions) and
  570. not(po_iocheck in current_procdef.procoptions) then
  571. begin
  572. objectlibrary.getaddrlabel(iolabel);
  573. cg.a_label(exprasmlist,iolabel);
  574. end
  575. else
  576. iolabel:=nil;
  577. { save all used registers and possible registers
  578. used for the return value }
  579. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  580. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  581. if (not is_void(resulttype.def)) and
  582. (not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  583. begin
  584. include(regs_to_push_int,RS_ACCUMULATOR);
  585. {$ifndef cpu64bit}
  586. if resulttype.def.size>sizeof(aword) then
  587. include(regs_to_push_int,RS_ACCUMULATORHIGH);
  588. {$endif cpu64bit}
  589. end;
  590. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  591. rg.saveusedotherregisters(exprasmlist,pushed,regs_to_push_other);
  592. { give used registers through }
  593. rg.usedintinproc:=rg.usedintinproc + tprocdef(procdefinition).usedintregisters;
  594. rg.usedinproc:=rg.usedinproc + tprocdef(procdefinition).usedotherregisters;
  595. end
  596. else
  597. begin
  598. regs_to_push_int := all_intregisters;
  599. regs_to_push_other := all_registers;
  600. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  601. rg.saveusedotherregisters(exprasmlist,pushed,regs_to_push_other);
  602. rg.usedinproc:=all_registers;
  603. { no IO check for methods and procedure variables }
  604. iolabel:=nil;
  605. end;
  606. { Initialize for pushing the parameters }
  607. oldpushedparasize:=pushedparasize;
  608. pushedparasize:=0;
  609. pop_size:=0;
  610. { Align stack if required }
  611. if not inlined then
  612. pop_size:=align_parasize(oldpushedparasize,para_alignment);
  613. { Push parameters }
  614. oldaktcallnode:=aktcallnode;
  615. aktcallnode:=self;
  616. { process procvar. Done here already, because otherwise it may }
  617. { destroy registers containing a parameter for the actual }
  618. { function call (e.g. if it's a function, its result will }
  619. { overwrite r3, which contains the first parameter) (JM) }
  620. if not(inlined) and
  621. assigned(right) then
  622. secondpass(right);
  623. if inlined or
  624. (right = nil) then
  625. begin
  626. if (po_virtualmethod in procdefinition.procoptions) and
  627. assigned(methodpointer) then
  628. begin
  629. secondpass(methodpointer);
  630. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  631. { virtual methods require an index }
  632. if tprocdef(procdefinition).extnumber=-1 then
  633. internalerror(200304021);
  634. { VMT should already be loaded in a register }
  635. if methodpointer.location.register.number=NR_NO then
  636. internalerror(200304022);
  637. { test validity of VMT }
  638. if not(is_interface(tprocdef(procdefinition)._class)) and
  639. not(is_cppclass(tprocdef(procdefinition)._class)) then
  640. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  641. end;
  642. end;
  643. if assigned(left) then
  644. begin
  645. {$ifndef newra}
  646. if assigned(right) then
  647. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  648. else
  649. if assigned(methodpointer) then
  650. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  651. {$endif}
  652. { be found elsewhere }
  653. if inlined then
  654. para_offset:=tprocdef(procdefinition).parast.address_fixup+
  655. tprocdef(procdefinition).parast.datasize
  656. else
  657. para_offset:=0;
  658. if not(inlined) and
  659. assigned(right) then
  660. tcallparanode(left).secondcallparan(
  661. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  662. para_alignment,para_offset)
  663. else
  664. tcallparanode(left).secondcallparan(
  665. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  666. para_alignment,para_offset);
  667. {$ifndef newra}
  668. if assigned(right) then
  669. maybe_restore(exprasmlist,right.location,pushedregs)
  670. else
  671. if assigned(methodpointer) then
  672. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  673. {$endif newra}
  674. end;
  675. aktcallnode:=oldaktcallnode;
  676. { Allocate return value for inlined routines }
  677. if inlined and
  678. (resulttype.def.size>0) then
  679. begin
  680. tg.GetTemp(exprasmlist,Align(resulttype.def.size,aktalignment.paraalign),tt_persistant,returnref);
  681. inlinecode.retoffset:=returnref.offset;
  682. end;
  683. { procedure variable or normal function call ? }
  684. if inlined or
  685. (right=nil) then
  686. begin
  687. { push base pointer ?}
  688. { never when inlining, since if necessary, the base pointer }
  689. { can/will be gottten from the current procedure's symtable }
  690. { (JM) }
  691. if not inlined then
  692. if (current_procdef.parast.symtablelevel>=normal_function_level) and
  693. assigned(tprocdef(procdefinition).parast) and
  694. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  695. push_framepointer;
  696. rg.saveintregvars(exprasmlist,regs_to_push_int);
  697. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  698. if (po_virtualmethod in procdefinition.procoptions) and
  699. assigned(methodpointer) then
  700. begin
  701. { call method }
  702. reference_reset_base(href,methodpointer.location.register,
  703. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  704. cg.a_call_ref(exprasmlist,href);
  705. { release self }
  706. rg.ungetaddressregister(exprasmlist,methodpointer.location.register);
  707. end
  708. else
  709. begin
  710. if not inlined then
  711. begin
  712. { Calling interrupt from the same code requires some
  713. extra code }
  714. if (po_interrupt in procdefinition.procoptions) then
  715. extra_interrupt_code;
  716. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  717. end
  718. else { inlined proc }
  719. begin
  720. { process the inlinecode }
  721. secondpass(tnode(inlinecode));
  722. { free the args }
  723. if tprocdef(procdefinition).parast.datasize>0 then
  724. tg.UnGetTemp(exprasmlist,pararef);
  725. end;
  726. end;
  727. end
  728. else
  729. { now procedure variable case }
  730. begin
  731. { Calling interrupt from the same code requires some
  732. extra code }
  733. if (po_interrupt in procdefinition.procoptions) then
  734. extra_interrupt_code;
  735. if (po_methodpointer in procdefinition.procoptions) then
  736. begin
  737. { push self, but not if it's already explicitly pushed }
  738. if not(po_containsself in procdefinition.procoptions) then
  739. begin
  740. { push self }
  741. href:=right.location.reference;
  742. inc(href.offset,POINTER_SIZE);
  743. cg.a_param_ref(exprasmlist,OS_ADDR,href,paramanager.getintparaloc(1));
  744. end;
  745. rg.saveintregvars(exprasmlist,ALL_INTREGISTERS);
  746. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  747. cg.a_call_ref(exprasmlist,right.location.reference);
  748. reference_release(exprasmlist,right.location.reference);
  749. tg.Ungetiftemp(exprasmlist,right.location.reference);
  750. end
  751. else
  752. begin
  753. rg.saveintregvars(exprasmlist,ALL_INTREGISTERS);
  754. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  755. cg.a_call_loc(exprasmlist,right.location);
  756. location_release(exprasmlist,right.location);
  757. location_freetemp(exprasmlist,right.location);
  758. end;
  759. end;
  760. { Need to remove the parameters from the stack? }
  761. if (not inlined) and (po_clearstack in procdefinition.procoptions) then
  762. begin
  763. { the old pop_size was already included in pushedparasize }
  764. pop_size:=pushedparasize;
  765. { for Cdecl functions we don't need to pop the funcret when it
  766. was pushed by para }
  767. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  768. dec(pop_size,POINTER_SIZE);
  769. end;
  770. { Remove parameters/alignment from the stack }
  771. if pop_size>0 then
  772. pop_parasize(pop_size);
  773. {$ifdef powerpc}
  774. { this calculation must be done in pass_1 anyway, so don't worry }
  775. if tppcprocinfo(current_procinfo).maxpushedparasize<pushedparasize then
  776. tppcprocinfo(current_procinfo).maxpushedparasize:=pushedparasize;
  777. {$endif powerpc}
  778. { Restore }
  779. pushedparasize:=oldpushedparasize;
  780. rg.restoreunusedstate(unusedstate);
  781. {$ifdef TEMPREGDEBUG}
  782. testregisters32;
  783. {$endif TEMPREGDEBUG}
  784. { Called an inherited constructor? Then
  785. we need to check the result }
  786. if (inlined or (right=nil)) and
  787. (procdefinition.proctypeoption=potype_constructor) and
  788. assigned(methodpointer) and
  789. (methodpointer.nodetype=typen) and
  790. (current_procdef.proctypeoption=potype_constructor) then
  791. begin
  792. accreg.enum:=R_INTREGISTER;
  793. accreg.number:=NR_ACCUMULATOR;
  794. cg.a_reg_alloc(exprasmlist,accreg);
  795. cg.a_cmp_const_reg_label(exprasmlist,OS_ADDR,OC_EQ,0,accreg,faillabel);
  796. cg.a_reg_dealloc(exprasmlist,accreg);
  797. end;
  798. { handle function results }
  799. if (not is_void(resulttype.def)) then
  800. handle_return_value(inlined)
  801. else
  802. location_reset(location,LOC_VOID,OS_NO);
  803. { perhaps i/o check ? }
  804. if iolabel<>nil then
  805. begin
  806. reference_reset_symbol(href,iolabel,0);
  807. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(1));
  808. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  809. end;
  810. { restore registers }
  811. rg.restoreusedotherregisters(exprasmlist,pushed);
  812. rg.restoreusedintregisters(exprasmlist,pushedint);
  813. { Release temps from parameters }
  814. pp:=tcallparanode(left);
  815. while assigned(pp) do
  816. begin
  817. if assigned(pp.left) then
  818. begin
  819. { don't release the funcret temp }
  820. if not(vo_is_funcret in tvarsym(pp.paraitem.parasym).varoptions) then
  821. location_freetemp(exprasmlist,pp.left.location);
  822. { process also all nodes of an array of const }
  823. if pp.left.nodetype=arrayconstructorn then
  824. begin
  825. if assigned(tarrayconstructornode(pp.left).left) then
  826. begin
  827. hp:=pp.left;
  828. while assigned(hp) do
  829. begin
  830. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  831. hp:=tarrayconstructornode(hp).right;
  832. end;
  833. end;
  834. end;
  835. end;
  836. pp:=tcallparanode(pp.right);
  837. end;
  838. if inlined then
  839. begin
  840. if (resulttype.def.size>0) then
  841. tg.UnGetTemp(exprasmlist,returnref);
  842. tprocdef(procdefinition).parast.address_fixup:=store_parast_fixup;
  843. right:=inlinecode;
  844. { from now on the result can be freed normally }
  845. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  846. tg.ChangeTempType(exprasmlist,funcretnode.location.reference,tt_normal);
  847. end;
  848. { if return value is not used }
  849. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  850. begin
  851. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  852. begin
  853. { data which must be finalized ? }
  854. if (resulttype.def.needs_inittable) then
  855. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  856. { release unused temp }
  857. tg.ungetiftemp(exprasmlist,location.reference)
  858. end
  859. else if location.loc=LOC_FPUREGISTER then
  860. begin
  861. {$ifdef x86}
  862. { release FPU stack }
  863. accreg.enum:=FPU_RESULT_REG;
  864. emit_reg(A_FSTP,S_NO,accreg);
  865. {
  866. dec(trgcpu(rg).fpuvaroffset);
  867. do NOT decrement as the increment before
  868. is not called for unused results PM }
  869. {$endif x86}
  870. end;
  871. end;
  872. end;
  873. {*****************************************************************************
  874. TCGPROCINLINENODE
  875. *****************************************************************************}
  876. procedure tcgprocinlinenode.pass_2;
  877. var st : tsymtable;
  878. oldprocdef : tprocdef;
  879. ps, i : longint;
  880. oldprocinfo : tprocinfo;
  881. oldinlining_procedure,
  882. nostackframe,make_global : boolean;
  883. inlineentrycode,inlineexitcode : TAAsmoutput;
  884. oldexitlabel,oldexit2label,oldquickexitlabel:tasmlabel;
  885. oldregstate: pointer;
  886. localsref : treference;
  887. {$ifdef GDB}
  888. startlabel,endlabel : tasmlabel;
  889. pp : pchar;
  890. mangled_length : longint;
  891. {$endif GDB}
  892. begin
  893. { deallocate the registers used for the current procedure's regvars }
  894. if assigned(current_procdef.regvarinfo) then
  895. begin
  896. with pregvarinfo(current_procdef.regvarinfo)^ do
  897. for i := 1 to maxvarregs do
  898. if assigned(regvars[i]) then
  899. store_regvar(exprasmlist,regvars[i].reg);
  900. rg.saveStateForInline(oldregstate);
  901. { make sure the register allocator knows what the regvars in the }
  902. { inlined code block are (JM) }
  903. rg.resetusableregisters;
  904. rg.clearregistercount;
  905. {$ifndef newra}
  906. rg.cleartempgen;
  907. {$endif}
  908. if assigned(inlineprocdef.regvarinfo) then
  909. with pregvarinfo(inlineprocdef.regvarinfo)^ do
  910. for i := 1 to maxvarregs do
  911. if assigned(regvars[i]) then
  912. begin
  913. {Fix me!!}
  914. {tmpreg:=rg.makeregsize(regvars[i].reg,OS_INT);
  915. rg.makeregvar(tmpreg);}
  916. internalerror(200301232);
  917. end;
  918. end;
  919. oldinlining_procedure:=inlining_procedure;
  920. oldexitlabel:=aktexitlabel;
  921. oldexit2label:=aktexit2label;
  922. oldquickexitlabel:=quickexitlabel;
  923. oldprocdef:=current_procdef;
  924. oldprocinfo:=current_procinfo;
  925. objectlibrary.getlabel(aktexitlabel);
  926. objectlibrary.getlabel(aktexit2label);
  927. { we're inlining a procedure }
  928. inlining_procedure:=true;
  929. current_procdef:=inlineprocdef;
  930. { clone procinfo, but not the asmlists }
  931. current_procinfo:=tprocinfo(cprocinfo.newinstance);
  932. move(pointer(oldprocinfo)^,pointer(current_procinfo)^,cprocinfo.InstanceSize);
  933. current_procinfo.aktentrycode:=nil;
  934. current_procinfo.aktexitcode:=nil;
  935. current_procinfo.aktproccode:=nil;
  936. current_procinfo.aktlocaldata:=nil;
  937. { set new procinfo }
  938. current_procinfo.return_offset:=retoffset;
  939. { arg space has been filled by the parent secondcall }
  940. st:=current_procdef.localst;
  941. { set it to the same lexical level }
  942. st.symtablelevel:=oldprocdef.localst.symtablelevel;
  943. if st.datasize>0 then
  944. begin
  945. tg.GetTemp(exprasmlist,st.datasize,tt_persistant,localsref);
  946. st.address_fixup:=localsref.offset+st.datasize;
  947. {$ifdef extdebug}
  948. Comment(V_debug,'local symtable is at offset '+tostr(st.address_fixup));
  949. exprasmList.concat(tai_comment.Create(strpnew(
  950. 'local symtable is at offset '+tostr(st.address_fixup))));
  951. {$endif extdebug}
  952. end;
  953. exprasmList.concat(Tai_Marker.Create(InlineStart));
  954. {$ifdef extdebug}
  955. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  956. {$endif extdebug}
  957. {$ifdef GDB}
  958. if (cs_debuginfo in aktmoduleswitches) then
  959. begin
  960. objectlibrary.getaddrlabel(startlabel);
  961. objectlibrary.getaddrlabel(endlabel);
  962. cg.a_label(exprasmlist,startlabel);
  963. inlineprocdef.localst.symtabletype:=inlinelocalsymtable;
  964. inlineprocdef.parast.symtabletype:=inlineparasymtable;
  965. { Here we must include the para and local symtable info }
  966. inlineprocdef.concatstabto(withdebuglist);
  967. { set it back for safety }
  968. inlineprocdef.localst.symtabletype:=localsymtable;
  969. inlineprocdef.parast.symtabletype:=parasymtable;
  970. mangled_length:=length(oldprocdef.mangledname);
  971. getmem(pp,mangled_length+50);
  972. strpcopy(pp,'192,0,0,'+startlabel.name);
  973. if (target_info.use_function_relative_addresses) then
  974. begin
  975. strpcopy(strend(pp),'-');
  976. strpcopy(strend(pp),oldprocdef.mangledname);
  977. end;
  978. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  979. end;
  980. {$endif GDB}
  981. { takes care of local data initialization }
  982. inlineentrycode:=TAAsmoutput.Create;
  983. inlineexitcode:=TAAsmoutput.Create;
  984. ps:=para_size;
  985. make_global:=false; { to avoid warning }
  986. genentrycode(inlineentrycode,make_global,0,ps,nostackframe,true);
  987. if po_assembler in current_procdef.procoptions then
  988. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  989. exprasmList.concatlist(inlineentrycode);
  990. secondpass(inlinetree);
  991. genexitcode(inlineexitcode,0,false,true);
  992. if po_assembler in current_procdef.procoptions then
  993. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  994. exprasmList.concatlist(inlineexitcode);
  995. inlineentrycode.free;
  996. inlineexitcode.free;
  997. {$ifdef extdebug}
  998. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  999. {$endif extdebug}
  1000. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1001. {we can free the local data now, reset also the fixup address }
  1002. if st.datasize>0 then
  1003. begin
  1004. tg.UnGetTemp(exprasmlist,localsref);
  1005. st.address_fixup:=0;
  1006. end;
  1007. { restore procinfo }
  1008. current_procinfo.free;
  1009. current_procinfo:=oldprocinfo;
  1010. {$ifdef GDB}
  1011. if (cs_debuginfo in aktmoduleswitches) then
  1012. begin
  1013. cg.a_label(exprasmlist,endlabel);
  1014. strpcopy(pp,'224,0,0,'+endlabel.name);
  1015. if (target_info.use_function_relative_addresses) then
  1016. begin
  1017. strpcopy(strend(pp),'-');
  1018. strpcopy(strend(pp),oldprocdef.mangledname);
  1019. end;
  1020. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1021. freemem(pp,mangled_length+50);
  1022. end;
  1023. {$endif GDB}
  1024. { restore }
  1025. current_procdef:=oldprocdef;
  1026. aktexitlabel:=oldexitlabel;
  1027. aktexit2label:=oldexit2label;
  1028. quickexitlabel:=oldquickexitlabel;
  1029. inlining_procedure:=oldinlining_procedure;
  1030. { reallocate the registers used for the current procedure's regvars, }
  1031. { since they may have been used and then deallocated in the inlined }
  1032. { procedure (JM) }
  1033. if assigned(current_procdef.regvarinfo) then
  1034. begin
  1035. rg.restoreStateAfterInline(oldregstate);
  1036. end;
  1037. end;
  1038. begin
  1039. ccallparanode:=tcgcallparanode;
  1040. ccallnode:=tcgcallnode;
  1041. cprocinlinenode:=tcgprocinlinenode;
  1042. end.
  1043. {
  1044. $Log$
  1045. Revision 1.62 2003-05-13 15:18:18 peter
  1046. * generate code for procvar first before pushing parameters. Made
  1047. the already existing code for powerpc available for all platforms
  1048. Revision 1.61 2003/05/12 18:17:55 jonas
  1049. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1050. already-loaded parameter registers
  1051. Revision 1.60 2003/05/11 21:48:38 jonas
  1052. * fixed procvar bug on the ppc (load procvar before loading para's,
  1053. because the procvar may otherwise destroy the already loaded paras)
  1054. Revision 1.59 2003/05/09 17:47:02 peter
  1055. * self moved to hidden parameter
  1056. * removed hdisposen,hnewn,selfn
  1057. Revision 1.58 2003/05/05 14:53:16 peter
  1058. * vs_hidden replaced by is_hidden boolean
  1059. Revision 1.57 2003/04/30 20:53:32 florian
  1060. * error when address of an abstract method is taken
  1061. * fixed some x86-64 problems
  1062. * merged some more x86-64 and i386 code
  1063. Revision 1.56 2003/04/29 07:28:52 michael
  1064. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1065. Revision 1.55 2003/04/27 11:21:33 peter
  1066. * aktprocdef renamed to current_procdef
  1067. * procinfo renamed to current_procinfo
  1068. * procinfo will now be stored in current_module so it can be
  1069. cleaned up properly
  1070. * gen_main_procsym changed to create_main_proc and release_main_proc
  1071. to also generate a tprocinfo structure
  1072. * fixed unit implicit initfinal
  1073. Revision 1.54 2003/04/27 07:29:50 peter
  1074. * current_procdef cleanup, current_procdef is now always nil when parsing
  1075. a new procdef declaration
  1076. * aktprocsym removed
  1077. * lexlevel removed, use symtable.symtablelevel instead
  1078. * implicit init/final code uses the normal genentry/genexit
  1079. * funcret state checking updated for new funcret handling
  1080. Revision 1.53 2003/04/25 20:59:33 peter
  1081. * removed funcretn,funcretsym, function result is now in varsym
  1082. and aliases for result and function name are added using absolutesym
  1083. * vs_hidden parameter for funcret passed in parameter
  1084. * vs_hidden fixes
  1085. * writenode changed to printnode and released from extdebug
  1086. * -vp option added to generate a tree.log with the nodetree
  1087. * nicer printnode for statements, callnode
  1088. Revision 1.52 2003/04/25 08:25:26 daniel
  1089. * Ifdefs around a lot of calls to cleartempgen
  1090. * Fixed registers that are allocated but not freed in several nodes
  1091. * Tweak to register allocator to cause less spills
  1092. * 8-bit registers now interfere with esi,edi and ebp
  1093. Compiler can now compile rtl successfully when using new register
  1094. allocator
  1095. Revision 1.51 2003/04/22 23:50:22 peter
  1096. * firstpass uses expectloc
  1097. * checks if there are differences between the expectloc and
  1098. location.loc from secondpass in EXTDEBUG
  1099. Revision 1.50 2003/04/22 14:33:38 peter
  1100. * removed some notes/hints
  1101. Revision 1.49 2003/04/22 13:47:08 peter
  1102. * fixed C style array of const
  1103. * fixed C array passing
  1104. * fixed left to right with high parameters
  1105. Revision 1.48 2003/04/22 10:09:34 daniel
  1106. + Implemented the actual register allocator
  1107. + Scratch registers unavailable when new register allocator used
  1108. + maybe_save/maybe_restore unavailable when new register allocator used
  1109. Revision 1.47 2003/04/22 09:49:44 peter
  1110. * do not load self when calling a non-inherited class constructor
  1111. Revision 1.46 2003/04/21 20:03:32 peter
  1112. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1113. Revision 1.45 2003/04/21 13:53:16 jonas
  1114. - removed copying of all paras when secondpassing a callnode (this used
  1115. to be necessary for inlinign support, but currently the whole inlined
  1116. procedure is already copied in advance). Note that the compiler crashes
  1117. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1118. syntax errors), but that was also the case before this change.
  1119. Revision 1.44 2003/04/10 17:57:52 peter
  1120. * vs_hidden released
  1121. Revision 1.43 2003/04/06 21:11:23 olle
  1122. * changed newasmsymbol to newasmsymboldata for data symbols
  1123. Revision 1.42 2003/04/04 15:38:56 peter
  1124. * moved generic code from n386cal to ncgcal, i386 now also
  1125. uses the generic ncgcal
  1126. Revision 1.41 2003/03/28 19:16:56 peter
  1127. * generic constructor working for i386
  1128. * remove fixed self register
  1129. * esi added as address register for i386
  1130. Revision 1.40 2003/03/06 11:35:50 daniel
  1131. * Fixed internalerror 7843 issue
  1132. Revision 1.39 2003/02/19 22:00:14 daniel
  1133. * Code generator converted to new register notation
  1134. - Horribily outdated todo.txt removed
  1135. Revision 1.38 2003/02/15 22:17:38 carl
  1136. * bugfix of FPU emulation code
  1137. Revision 1.37 2003/02/12 22:10:07 carl
  1138. * load_frame_pointer is now generic
  1139. * change fpu emulation routine names
  1140. Revision 1.36 2003/01/30 21:46:57 peter
  1141. * self fixes for static methods (merged)
  1142. Revision 1.35 2003/01/22 20:45:15 mazen
  1143. * making math code in RTL compiling.
  1144. *NB : This does NOT mean necessary that it will generate correct code!
  1145. Revision 1.34 2003/01/17 12:03:45 daniel
  1146. * Optalign conditional code adapted to record Tregister
  1147. Revision 1.33 2003/01/08 18:43:56 daniel
  1148. * Tregister changed into a record
  1149. Revision 1.32 2002/12/15 22:50:00 florian
  1150. + some stuff for the new hidden parameter handling added
  1151. Revision 1.31 2002/12/15 21:30:12 florian
  1152. * tcallnode.paraitem introduced, all references to defcoll removed
  1153. Revision 1.30 2002/11/27 20:04:39 peter
  1154. * cdecl array of const fixes
  1155. Revision 1.29 2002/11/25 17:43:17 peter
  1156. * splitted defbase in defutil,symutil,defcmp
  1157. * merged isconvertable and is_equal into compare_defs(_ext)
  1158. * made operator search faster by walking the list only once
  1159. Revision 1.28 2002/11/18 17:31:54 peter
  1160. * pass proccalloption to ret_in_xxx and push_xxx functions
  1161. Revision 1.27 2002/11/16 15:34:30 florian
  1162. * generic location for float results
  1163. Revision 1.26 2002/11/15 01:58:51 peter
  1164. * merged changes from 1.0.7 up to 04-11
  1165. - -V option for generating bug report tracing
  1166. - more tracing for option parsing
  1167. - errors for cdecl and high()
  1168. - win32 import stabs
  1169. - win32 records<=8 are returned in eax:edx (turned off by default)
  1170. - heaptrc update
  1171. - more info for temp management in .s file with EXTDEBUG
  1172. Revision 1.25 2002/10/05 12:43:25 carl
  1173. * fixes for Delphi 6 compilation
  1174. (warning : Some features do not work under Delphi)
  1175. Revision 1.24 2002/09/30 07:00:45 florian
  1176. * fixes to common code to get the alpha compiler compiled applied
  1177. Revision 1.23 2002/09/17 18:54:02 jonas
  1178. * a_load_reg_reg() now has two size parameters: source and dest. This
  1179. allows some optimizations on architectures that don't encode the
  1180. register size in the register name.
  1181. Revision 1.22 2002/09/07 15:25:02 peter
  1182. * old logs removed and tabs fixed
  1183. Revision 1.21 2002/09/07 11:50:02 jonas
  1184. * fixed small regalloction info bug
  1185. Revision 1.20 2002/09/02 11:25:20 florian
  1186. * fixed generic procedure variable calling
  1187. Revision 1.19 2002/09/01 21:04:48 florian
  1188. * several powerpc related stuff fixed
  1189. Revision 1.18 2002/09/01 18:43:27 peter
  1190. * include accumulator in regs_to_push list
  1191. Revision 1.17 2002/09/01 12:13:00 peter
  1192. * use a_call_reg
  1193. * ungetiftemp for procvar of object temp
  1194. Revision 1.16 2002/08/25 19:25:18 peter
  1195. * sym.insert_in_data removed
  1196. * symtable.insertvardata/insertconstdata added
  1197. * removed insert_in_data call from symtable.insert, it needs to be
  1198. called separatly. This allows to deref the address calculation
  1199. * procedures now calculate the parast addresses after the procedure
  1200. directives are parsed. This fixes the cdecl parast problem
  1201. * push_addr_param has an extra argument that specifies if cdecl is used
  1202. or not
  1203. Revision 1.15 2002/08/23 16:14:48 peter
  1204. * tempgen cleanup
  1205. * tt_noreuse temp type added that will be used in genentrycode
  1206. Revision 1.14 2002/08/20 16:55:38 peter
  1207. * don't write (stabs)line info when inlining a procedure
  1208. Revision 1.13 2002/08/19 19:36:42 peter
  1209. * More fixes for cross unit inlining, all tnodes are now implemented
  1210. * Moved pocall_internconst to po_internconst because it is not a
  1211. calling type at all and it conflicted when inlining of these small
  1212. functions was requested
  1213. Revision 1.12 2002/08/18 20:06:23 peter
  1214. * inlining is now also allowed in interface
  1215. * renamed write/load to ppuwrite/ppuload
  1216. * tnode storing in ppu
  1217. * nld,ncon,nbas are already updated for storing in ppu
  1218. Revision 1.11 2002/08/17 22:09:44 florian
  1219. * result type handling in tcgcal.pass_2 overhauled
  1220. * better tnode.dowrite
  1221. * some ppc stuff fixed
  1222. Revision 1.10 2002/08/17 09:23:35 florian
  1223. * first part of procinfo rewrite
  1224. Revision 1.9 2002/08/13 21:40:55 florian
  1225. * more fixes for ppc calling conventions
  1226. Revision 1.8 2002/08/13 18:01:51 carl
  1227. * rename swatoperands to swapoperands
  1228. + m68k first compilable version (still needs a lot of testing):
  1229. assembler generator, system information , inline
  1230. assembler reader.
  1231. Revision 1.7 2002/08/12 15:08:39 carl
  1232. + stab register indexes for powerpc (moved from gdb to cpubase)
  1233. + tprocessor enumeration moved to cpuinfo
  1234. + linker in target_info is now a class
  1235. * many many updates for m68k (will soon start to compile)
  1236. - removed some ifdef or correct them for correct cpu
  1237. Revision 1.6 2002/08/11 14:32:26 peter
  1238. * renamed current_library to objectlibrary
  1239. Revision 1.5 2002/08/11 13:24:11 peter
  1240. * saving of asmsymbols in ppu supported
  1241. * asmsymbollist global is removed and moved into a new class
  1242. tasmlibrarydata that will hold the info of a .a file which
  1243. corresponds with a single module. Added librarydata to tmodule
  1244. to keep the library info stored for the module. In the future the
  1245. objectfiles will also be stored to the tasmlibrarydata class
  1246. * all getlabel/newasmsymbol and friends are moved to the new class
  1247. Revision 1.4 2002/08/06 20:55:20 florian
  1248. * first part of ppc calling conventions fix
  1249. Revision 1.3 2002/07/20 11:57:53 florian
  1250. * types.pas renamed to defbase.pas because D6 contains a types
  1251. unit so this would conflicts if D6 programms are compiled
  1252. + Willamette/SSE2 instructions to assembler added
  1253. Revision 1.2 2002/07/13 19:38:43 florian
  1254. * some more generic calling stuff fixed
  1255. }