ncgcal.pas 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate assembler for call nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncgcal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cpubase,
  22. globtype,
  23. parabase,cgutils,
  24. symdef,node,ncal;
  25. type
  26. tcgcallparanode = class(tcallparanode)
  27. private
  28. tempcgpara : tcgpara;
  29. procedure push_addr_para;
  30. procedure push_value_para;
  31. public
  32. constructor create(expr,next : tnode);override;
  33. destructor destroy;override;
  34. procedure secondcallparan;override;
  35. end;
  36. tcgcallnode = class(tcallnode)
  37. private
  38. procedure release_para_temps;
  39. procedure normal_pass_2;
  40. {$ifdef PASS2INLINE}
  41. procedure inlined_pass_2;
  42. {$endif PASS2INLINE}
  43. procedure pushparas;
  44. procedure freeparas;
  45. protected
  46. framepointer_paraloc : tcgpara;
  47. refcountedtemp : treference;
  48. procedure handle_return_value;
  49. {# This routine is used to push the current frame pointer
  50. on the stack. This is used in nested routines where the
  51. value of the frame pointer is always pushed as an extra
  52. parameter.
  53. The default handling is the standard handling used on
  54. most stack based machines, where the frame pointer is
  55. the first invisible parameter.
  56. }
  57. procedure pop_parasize(pop_size:longint);virtual;
  58. procedure extra_interrupt_code;virtual;
  59. procedure extra_call_code;virtual;
  60. procedure extra_post_call_code;virtual;
  61. procedure do_syscall;virtual;abstract;
  62. public
  63. procedure pass_2;override;
  64. end;
  65. implementation
  66. uses
  67. systems,
  68. cutils,verbose,globals,
  69. symconst,symtable,defutil,paramgr,
  70. {$ifdef GDB}
  71. strings,
  72. gdb,
  73. {$endif GDB}
  74. cgbase,pass_2,
  75. aasmbase,aasmtai,
  76. nbas,nmem,nld,ncnv,nutils,
  77. {$ifdef x86}
  78. cga,cgx86,
  79. {$endif x86}
  80. ncgutil,
  81. cgobj,tgobj,
  82. procinfo;
  83. {*****************************************************************************
  84. TCGCALLPARANODE
  85. *****************************************************************************}
  86. constructor tcgcallparanode.create(expr,next : tnode);
  87. begin
  88. inherited create(expr,next);
  89. tempcgpara.init;
  90. end;
  91. destructor tcgcallparanode.destroy;
  92. begin
  93. tempcgpara.done;
  94. inherited destroy;
  95. end;
  96. procedure tcgcallparanode.push_addr_para;
  97. begin
  98. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  99. internalerror(200304235);
  100. cg.a_paramaddr_ref(exprasmlist,left.location.reference,tempcgpara);
  101. end;
  102. procedure tcgcallparanode.push_value_para;
  103. {$ifdef i386}
  104. var
  105. href : treference;
  106. size : longint;
  107. {$endif i386}
  108. begin
  109. { we've nothing to push when the size of the parameter is 0 }
  110. if left.resulttype.def.size=0 then
  111. exit;
  112. { Move flags and jump in register to make it less complex }
  113. if left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  114. location_force_reg(exprasmlist,left.location,def_cgsize(left.resulttype.def),false);
  115. { Handle Floating point types differently }
  116. if left.resulttype.def.deftype=floatdef then
  117. begin
  118. {$ifdef i386}
  119. if tempcgpara.location^.loc<>LOC_REFERENCE then
  120. internalerror(200309291);
  121. case left.location.loc of
  122. LOC_FPUREGISTER,
  123. LOC_CFPUREGISTER:
  124. begin
  125. size:=align(TCGSize2Size[left.location.size],tempcgpara.alignment);
  126. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  127. begin
  128. cg.g_stackpointer_alloc(exprasmlist,size);
  129. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  130. end
  131. else
  132. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  133. cg.a_loadfpu_reg_ref(exprasmlist,left.location.size,left.location.register,href);
  134. end;
  135. LOC_MMREGISTER,
  136. LOC_CMMREGISTER:
  137. begin
  138. size:=align(tfloatdef(left.resulttype.def).size,tempcgpara.alignment);
  139. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  140. begin
  141. cg.g_stackpointer_alloc(exprasmlist,size);
  142. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  143. end
  144. else
  145. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  146. cg.a_loadmm_reg_ref(exprasmlist,left.location.size,left.location.size,left.location.register,href,mms_movescalar);
  147. end;
  148. LOC_REFERENCE,
  149. LOC_CREFERENCE :
  150. begin
  151. size:=align(left.resulttype.def.size,tempcgpara.alignment);
  152. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  153. cg.a_param_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara)
  154. else
  155. begin
  156. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  157. cg.g_concatcopy(exprasmlist,left.location.reference,href,size);
  158. end;
  159. end;
  160. else
  161. internalerror(2002042430);
  162. end;
  163. {$else i386}
  164. case left.location.loc of
  165. LOC_MMREGISTER,
  166. LOC_CMMREGISTER:
  167. case tempcgpara.location^.loc of
  168. LOC_REFERENCE,
  169. LOC_CREFERENCE,
  170. LOC_MMREGISTER,
  171. LOC_CMMREGISTER:
  172. cg.a_parammm_reg(exprasmlist,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  173. LOC_FPUREGISTER,
  174. LOC_CFPUREGISTER:
  175. begin
  176. location_force_fpureg(exprasmlist,left.location,false);
  177. cg.a_paramfpu_reg(exprasmlist,left.location.size,left.location.register,tempcgpara);
  178. end;
  179. else
  180. internalerror(200204249);
  181. end;
  182. LOC_FPUREGISTER,
  183. LOC_CFPUREGISTER:
  184. case tempcgpara.location^.loc of
  185. LOC_MMREGISTER,
  186. LOC_CMMREGISTER:
  187. begin
  188. location_force_mmregscalar(exprasmlist,left.location,false);
  189. cg.a_parammm_reg(exprasmlist,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  190. end;
  191. {$ifdef x86_64}
  192. { x86_64 pushes s64comp in normal register }
  193. LOC_REGISTER,
  194. LOC_CREGISTER :
  195. begin
  196. location_force_mem(exprasmlist,left.location);
  197. { force integer size }
  198. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  199. cg.a_param_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara);
  200. end;
  201. {$endif x86_64}
  202. {$ifdef powerpc}
  203. LOC_REGISTER,
  204. LOC_CREGISTER :
  205. begin
  206. { aix abi passes floats of varargs in both fpu and }
  207. { integer registers }
  208. location_force_mem(exprasmlist,left.location);
  209. { force integer size }
  210. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  211. if (left.location.size in [OS_32,OS_S32]) then
  212. cg.a_param_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara)
  213. else
  214. cg64.a_param64_ref(exprasmlist,left.location.reference,tempcgpara);
  215. end;
  216. {$endif powerpc}
  217. {$if defined(sparc) or defined(arm)}
  218. { sparc and arm pass floats in normal registers }
  219. LOC_REGISTER,
  220. LOC_CREGISTER,
  221. {$endif sparc}
  222. LOC_REFERENCE,
  223. LOC_CREFERENCE,
  224. LOC_FPUREGISTER,
  225. LOC_CFPUREGISTER:
  226. cg.a_paramfpu_reg(exprasmlist,left.location.size,left.location.register,tempcgpara);
  227. else
  228. internalerror(2002042433);
  229. end;
  230. LOC_REFERENCE,
  231. LOC_CREFERENCE:
  232. case tempcgpara.location^.loc of
  233. LOC_MMREGISTER,
  234. LOC_CMMREGISTER:
  235. cg.a_parammm_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara,mms_movescalar);
  236. {$ifdef x86_64}
  237. { x86_64 pushes s64comp in normal register }
  238. LOC_REGISTER,
  239. LOC_CREGISTER :
  240. begin
  241. { force integer size }
  242. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  243. cg.a_param_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara);
  244. end;
  245. {$endif x86_64}
  246. {$ifdef powerpc}
  247. { x86_64 pushes s64comp in normal register }
  248. LOC_REGISTER,
  249. LOC_CREGISTER :
  250. begin
  251. { force integer size }
  252. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  253. if (left.location.size in [OS_32,OS_S32]) then
  254. cg.a_param_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara)
  255. else
  256. cg64.a_param64_ref(exprasmlist,left.location.reference,tempcgpara);
  257. end;
  258. {$endif powerpc}
  259. {$if defined(sparc) or defined(arm) }
  260. { sparc and arm pass floats in normal registers }
  261. LOC_REGISTER,
  262. LOC_CREGISTER,
  263. {$endif sparc}
  264. LOC_REFERENCE,
  265. LOC_CREFERENCE,
  266. LOC_FPUREGISTER,
  267. LOC_CFPUREGISTER:
  268. cg.a_paramfpu_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara);
  269. else
  270. internalerror(2002042431);
  271. end;
  272. else
  273. internalerror(2002042432);
  274. end;
  275. {$endif i386}
  276. end
  277. else
  278. begin
  279. case left.location.loc of
  280. LOC_CONSTANT,
  281. LOC_REGISTER,
  282. LOC_CREGISTER,
  283. LOC_REFERENCE,
  284. LOC_CREFERENCE :
  285. begin
  286. {$ifndef cpu64bit}
  287. { use cg64 only for int64, not for 8 byte records }
  288. if is_64bit(left.resulttype.def) then
  289. cg64.a_param64_loc(exprasmlist,left.location,tempcgpara)
  290. else
  291. {$endif cpu64bit}
  292. begin
  293. {$ifndef cpu64bit}
  294. { Only a_param_ref supports multiple locations, when the
  295. value is still a const or in a register then write it
  296. to a reference first. This situation can be triggered
  297. by typecasting an int64 constant to a record of 8 bytes }
  298. if left.location.size in [OS_64,OS_S64] then
  299. location_force_mem(exprasmlist,left.location);
  300. {$endif cpu64bit}
  301. cg.a_param_loc(exprasmlist,left.location,tempcgpara);
  302. end;
  303. end;
  304. {$ifdef SUPPORT_MMX}
  305. LOC_MMXREGISTER,
  306. LOC_CMMXREGISTER:
  307. cg.a_parammm_reg(exprasmlist,OS_M64,left.location.register,tempcgpara,nil);
  308. {$endif SUPPORT_MMX}
  309. else
  310. internalerror(200204241);
  311. end;
  312. end;
  313. end;
  314. procedure tcgcallparanode.secondcallparan;
  315. var
  316. href : treference;
  317. otlabel,
  318. oflabel : tasmlabel;
  319. begin
  320. if not(assigned(parasym)) then
  321. internalerror(200304242);
  322. { Skip nothingn nodes which are used after disabling
  323. a parameter }
  324. if (left.nodetype<>nothingn) then
  325. begin
  326. otlabel:=truelabel;
  327. oflabel:=falselabel;
  328. objectlibrary.getlabel(truelabel);
  329. objectlibrary.getlabel(falselabel);
  330. secondpass(left);
  331. { release memory for refcnt out parameters }
  332. if (parasym.varspez=vs_out) and
  333. (left.resulttype.def.needs_inittable) then
  334. begin
  335. location_get_data_ref(exprasmlist,left.location,href,false);
  336. cg.g_decrrefcount(exprasmlist,left.resulttype.def,href);
  337. end;
  338. {$ifdef PASS2INLINE}
  339. if assigned(aktcallnode.inlinecode) then
  340. paramanager.duplicateparaloc(exprasmlist,aktcallnode.procdefinition.proccalloption,parasym,tempcgpara)
  341. else
  342. {$endif PASS2INLINE}
  343. paramanager.createtempparaloc(exprasmlist,aktcallnode.procdefinition.proccalloption,parasym,tempcgpara);
  344. { handle varargs first, because parasym is not valid }
  345. if (cpf_varargs_para in callparaflags) then
  346. begin
  347. if paramanager.push_addr_param(vs_value,left.resulttype.def,
  348. aktcallnode.procdefinition.proccalloption) then
  349. push_addr_para
  350. else
  351. push_value_para;
  352. end
  353. { hidden parameters }
  354. else if (vo_is_hidden_para in parasym.varoptions) then
  355. begin
  356. { don't push a node that already generated a pointer type
  357. by address for implicit hidden parameters }
  358. if (vo_is_funcret in parasym.varoptions) or
  359. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  360. paramanager.push_addr_param(parasym.varspez,parasym.vartype.def,
  361. aktcallnode.procdefinition.proccalloption)) then
  362. push_addr_para
  363. else
  364. push_value_para;
  365. end
  366. { formal def }
  367. else if (parasym.vartype.def.deftype=formaldef) then
  368. begin
  369. { allow passing of a constant to a const formaldef }
  370. if (parasym.varspez=vs_const) and
  371. (left.location.loc in [LOC_CONSTANT,LOC_REGISTER]) then
  372. location_force_mem(exprasmlist,left.location);
  373. push_addr_para;
  374. end
  375. { Normal parameter }
  376. else
  377. begin
  378. { don't push a node that already generated a pointer type
  379. by address for implicit hidden parameters }
  380. if (not(
  381. (vo_is_hidden_para in parasym.varoptions) and
  382. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  383. ) and
  384. paramanager.push_addr_param(parasym.varspez,parasym.vartype.def,
  385. aktcallnode.procdefinition.proccalloption)) and
  386. { dyn. arrays passed to an array of const must be passed by value, see tests/webtbs/tw4219.pp }
  387. not(
  388. is_array_of_const(parasym.vartype.def) and
  389. is_dynamic_array(left.resulttype.def)
  390. ) then
  391. begin
  392. { Passing a var parameter to a var parameter, we can
  393. just push the address transparently }
  394. if (left.nodetype=loadn) and
  395. (tloadnode(left).is_addr_param_load) then
  396. begin
  397. if (left.location.reference.index<>NR_NO) or
  398. (left.location.reference.offset<>0) then
  399. internalerror(200410107);
  400. cg.a_param_reg(exprasmlist,OS_ADDR,left.location.reference.base,tempcgpara)
  401. end
  402. else
  403. begin
  404. { Check for passing a constant to var,out parameter }
  405. if (parasym.varspez in [vs_var,vs_out]) and
  406. (left.location.loc<>LOC_REFERENCE) then
  407. begin
  408. { passing self to a var parameter is allowed in
  409. TP and delphi }
  410. if not((left.location.loc=LOC_CREFERENCE) and
  411. is_self_node(left)) then
  412. internalerror(200106041);
  413. end;
  414. { Force to be in memory }
  415. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  416. location_force_mem(exprasmlist,left.location);
  417. push_addr_para;
  418. end;
  419. end
  420. else
  421. push_value_para;
  422. end;
  423. truelabel:=otlabel;
  424. falselabel:=oflabel;
  425. { update return location in callnode when this is the function
  426. result }
  427. if assigned(parasym) and
  428. (vo_is_funcret in parasym.varoptions) then
  429. location_copy(aktcallnode.location,left.location);
  430. end;
  431. { next parameter }
  432. if assigned(right) then
  433. tcallparanode(right).secondcallparan;
  434. end;
  435. {*****************************************************************************
  436. TCGCALLNODE
  437. *****************************************************************************}
  438. procedure tcgcallnode.extra_interrupt_code;
  439. begin
  440. end;
  441. procedure tcgcallnode.extra_call_code;
  442. begin
  443. end;
  444. procedure tcgcallnode.extra_post_call_code;
  445. begin
  446. end;
  447. procedure tcgcallnode.pop_parasize(pop_size:longint);
  448. begin
  449. end;
  450. procedure tcgcallnode.handle_return_value;
  451. var
  452. cgsize : tcgsize;
  453. retloc : tlocation;
  454. hregister : tregister;
  455. tempnode : tnode;
  456. begin
  457. cgsize:=procdefinition.funcretloc[callerside].size;
  458. { structured results are easy to handle....
  459. needed also when result_no_used !! }
  460. if (procdefinition.proctypeoption<>potype_constructor) and
  461. paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  462. begin
  463. { Location should be setup by the funcret para }
  464. if location.loc<>LOC_REFERENCE then
  465. internalerror(200304241);
  466. end
  467. else
  468. { ansi/widestrings must be registered, so we can dispose them }
  469. if resulttype.def.needs_inittable then
  470. begin
  471. if procdefinition.funcretloc[callerside].loc<>LOC_REGISTER then
  472. internalerror(200409261);
  473. { the FUNCTION_RESULT_REG is already allocated }
  474. if getsupreg(procdefinition.funcretloc[callerside].register)<first_int_imreg then
  475. cg.ungetcpuregister(exprasmlist,procdefinition.funcretloc[callerside].register);
  476. if not assigned(funcretnode) then
  477. begin
  478. { reg_ref could generate two instrcutions and allocate a register so we've to
  479. save the result first before releasing it }
  480. hregister:=cg.getaddressregister(exprasmlist);
  481. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,procdefinition.funcretloc[callerside].register,hregister);
  482. location_reset(location,LOC_REFERENCE,OS_ADDR);
  483. location.reference:=refcountedtemp;
  484. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  485. end
  486. else
  487. begin
  488. hregister := cg.getaddressregister(exprasmlist);
  489. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,procdefinition.funcretloc[callerside].register,hregister);
  490. { in case of a regular funcretnode with ret_in_param, the }
  491. { original funcretnode isn't touched -> make sure it's }
  492. { the same here (not sure if it's necessary) }
  493. tempnode := funcretnode.getcopy;
  494. tempnode.pass_2;
  495. location := tempnode.location;
  496. tempnode.free;
  497. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference);
  498. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  499. end;
  500. end
  501. else
  502. { normal (ordinal,float,pointer) result value }
  503. begin
  504. { we have only to handle the result if it is used }
  505. if (cnf_return_value_used in callnodeflags) then
  506. begin
  507. location.loc:=procdefinition.funcretloc[callerside].loc;
  508. case procdefinition.funcretloc[callerside].loc of
  509. LOC_FPUREGISTER:
  510. begin
  511. location_reset(location,LOC_FPUREGISTER,cgsize);
  512. location.register:=procdefinition.funcretloc[callerside].register;
  513. {$ifdef x86}
  514. tcgx86(cg).inc_fpu_stack;
  515. {$else x86}
  516. if getsupreg(procdefinition.funcretloc[callerside].register)<first_fpu_imreg then
  517. cg.ungetcpuregister(exprasmlist,procdefinition.funcretloc[callerside].register);
  518. hregister:=cg.getfpuregister(exprasmlist,location.size);
  519. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  520. location.register:=hregister;
  521. {$endif x86}
  522. end;
  523. LOC_REGISTER:
  524. begin
  525. if cgsize<>OS_NO then
  526. begin
  527. location_reset(location,LOC_REGISTER,cgsize);
  528. {$ifndef cpu64bit}
  529. if cgsize in [OS_64,OS_S64] then
  530. begin
  531. retloc:=procdefinition.funcretloc[callerside];
  532. if retloc.loc<>LOC_REGISTER then
  533. internalerror(200409141);
  534. { the function result registers are already allocated }
  535. if getsupreg(retloc.register64.reglo)<first_int_imreg then
  536. cg.ungetcpuregister(exprasmlist,retloc.register64.reglo);
  537. location.register64.reglo:=cg.getintregister(exprasmlist,OS_32);
  538. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,retloc.register64.reglo,location.register64.reglo);
  539. if getsupreg(retloc.register64.reghi)<first_int_imreg then
  540. cg.ungetcpuregister(exprasmlist,retloc.register64.reghi);
  541. location.register64.reghi:=cg.getintregister(exprasmlist,OS_32);
  542. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,retloc.register64.reghi,location.register64.reghi);
  543. end
  544. else
  545. {$endif cpu64bit}
  546. begin
  547. { change register size after the unget because the
  548. getregister was done for the full register
  549. def_cgsize(resulttype.def) is used here because
  550. it could be a constructor call }
  551. if getsupreg(procdefinition.funcretloc[callerside].register)<first_int_imreg then
  552. cg.ungetcpuregister(exprasmlist,procdefinition.funcretloc[callerside].register);
  553. location.register:=cg.getintregister(exprasmlist,def_cgsize(resulttype.def));
  554. cg.a_load_reg_reg(exprasmlist,cgsize,def_cgsize(resulttype.def),procdefinition.funcretloc[callerside].register,location.register);
  555. end;
  556. end
  557. else
  558. begin
  559. if resulttype.def.size>0 then
  560. internalerror(200305131);
  561. end;
  562. end;
  563. LOC_MMREGISTER:
  564. begin
  565. location_reset(location,LOC_MMREGISTER,cgsize);
  566. if getsupreg(procdefinition.funcretloc[callerside].register)<first_mm_imreg then
  567. cg.ungetcpuregister(exprasmlist,procdefinition.funcretloc[callerside].register);
  568. location.register:=cg.getmmregister(exprasmlist,cgsize);
  569. cg.a_loadmm_reg_reg(exprasmlist,cgsize,cgsize,procdefinition.funcretloc[callerside].register,location.register,mms_movescalar);
  570. end;
  571. else
  572. internalerror(200405023);
  573. end;
  574. end
  575. else
  576. begin
  577. {$ifdef x86}
  578. { release FPU stack }
  579. if procdefinition.funcretloc[callerside].loc=LOC_FPUREGISTER then
  580. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  581. {$endif x86}
  582. if cgsize<>OS_NO then
  583. location_free(exprasmlist,procdefinition.funcretloc[callerside]);
  584. location_reset(location,LOC_VOID,OS_NO);
  585. end;
  586. end;
  587. { When the result is not used we need to finalize the result and
  588. can release the temp }
  589. if not(cnf_return_value_used in callnodeflags) then
  590. begin
  591. if location.loc=LOC_REFERENCE then
  592. begin
  593. if resulttype.def.needs_inittable then
  594. cg.g_finalize(exprasmlist,resulttype.def,location.reference);
  595. tg.ungetiftemp(exprasmlist,location.reference)
  596. end;
  597. end;
  598. end;
  599. procedure tcgcallnode.release_para_temps;
  600. var
  601. hp : tnode;
  602. ppn : tcallparanode;
  603. begin
  604. { Release temps from parameters }
  605. ppn:=tcallparanode(left);
  606. while assigned(ppn) do
  607. begin
  608. if assigned(ppn.left) then
  609. begin
  610. { don't release the funcret temp }
  611. if not(assigned(ppn.parasym)) or
  612. not(vo_is_funcret in ppn.parasym.varoptions) then
  613. location_freetemp(exprasmlist,ppn.left.location);
  614. { process also all nodes of an array of const }
  615. hp:=ppn.left;
  616. while (hp.nodetype=typeconvn) do
  617. hp:=ttypeconvnode(hp).left;
  618. if (hp.nodetype=arrayconstructorn) and
  619. assigned(tarrayconstructornode(hp).left) then
  620. begin
  621. while assigned(hp) do
  622. begin
  623. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  624. hp:=tarrayconstructornode(hp).right;
  625. end;
  626. end;
  627. end;
  628. ppn:=tcallparanode(ppn.right);
  629. end;
  630. end;
  631. procedure tcgcallnode.pushparas;
  632. var
  633. ppn : tcgcallparanode;
  634. callerparaloc,
  635. tmpparaloc : pcgparalocation;
  636. sizeleft: aint;
  637. {$ifdef cputargethasfixedstack}
  638. htempref,
  639. href : treference;
  640. {$endif cputargethasfixedstack}
  641. begin
  642. { copy all resources to the allocated registers }
  643. ppn:=tcgcallparanode(left);
  644. while assigned(ppn) do
  645. begin
  646. if (ppn.left.nodetype<>nothingn) then
  647. begin
  648. { better check for the real location of the parameter here, when stack passed parameters
  649. are saved temporary in registers, checking for the tmpparaloc.loc is wrong
  650. }
  651. {$ifdef PASS2INLINE}
  652. if not assigned(inlinecode) then
  653. {$endif PASS2INLINE}
  654. paramanager.freeparaloc(exprasmlist,ppn.tempcgpara);
  655. tmpparaloc:=ppn.tempcgpara.location;
  656. sizeleft:=ppn.tempcgpara.intsize;
  657. callerparaloc:=ppn.parasym.paraloc[callerside].location;
  658. while assigned(callerparaloc) do
  659. begin
  660. { Every paraloc must have a matching tmpparaloc }
  661. if not assigned(tmpparaloc) then
  662. internalerror(200408224);
  663. if callerparaloc^.size<>tmpparaloc^.size then
  664. internalerror(200408225);
  665. case callerparaloc^.loc of
  666. LOC_REGISTER:
  667. begin
  668. if tmpparaloc^.loc<>LOC_REGISTER then
  669. internalerror(200408221);
  670. if getsupreg(callerparaloc^.register)<first_int_imreg then
  671. cg.getcpuregister(exprasmlist,callerparaloc^.register);
  672. cg.a_load_reg_reg(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,
  673. tmpparaloc^.register,callerparaloc^.register);
  674. end;
  675. LOC_FPUREGISTER:
  676. begin
  677. if tmpparaloc^.loc<>LOC_FPUREGISTER then
  678. internalerror(200408222);
  679. if getsupreg(callerparaloc^.register)<first_fpu_imreg then
  680. cg.getcpuregister(exprasmlist,callerparaloc^.register);
  681. cg.a_loadfpu_reg_reg(exprasmlist,ppn.tempcgpara.size,tmpparaloc^.register,callerparaloc^.register);
  682. end;
  683. LOC_MMREGISTER:
  684. begin
  685. if tmpparaloc^.loc<>LOC_MMREGISTER then
  686. internalerror(200408223);
  687. if getsupreg(callerparaloc^.register)<first_mm_imreg then
  688. cg.getcpuregister(exprasmlist,callerparaloc^.register);
  689. cg.a_loadmm_reg_reg(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,
  690. tmpparaloc^.register,callerparaloc^.register,mms_movescalar);
  691. end;
  692. LOC_REFERENCE:
  693. begin
  694. {$ifdef PASS2INLINE}
  695. if not assigned(inlinecode) then
  696. {$endif PASS2INLINE}
  697. begin
  698. {$ifdef cputargethasfixedstack}
  699. { Can't have a data copied to the stack, every location
  700. must contain a valid size field }
  701. if (ppn.tempcgpara.size=OS_NO) and
  702. ((tmpparaloc^.loc<>LOC_REFERENCE) or
  703. assigned(tmpparaloc^.next)) then
  704. internalerror(200501281);
  705. reference_reset_base(href,callerparaloc^.reference.index,callerparaloc^.reference.offset);
  706. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  707. case tmpparaloc^.loc of
  708. LOC_REFERENCE:
  709. begin
  710. reference_reset_base(htempref,tmpparaloc^.reference.index,tmpparaloc^.reference.offset);
  711. { use concatcopy, because it can also be a float which fails when
  712. load_ref_ref is used }
  713. if (ppn.tempcgpara.size <> OS_NO) then
  714. cg.g_concatcopy(exprasmlist,htempref,href,tcgsize2size[tmpparaloc^.size])
  715. else
  716. cg.g_concatcopy(exprasmlist,htempref,href,sizeleft)
  717. end;
  718. LOC_REGISTER:
  719. cg.a_load_reg_ref(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  720. LOC_FPUREGISTER:
  721. cg.a_loadfpu_reg_ref(exprasmlist,tmpparaloc^.size,tmpparaloc^.register,href);
  722. LOC_MMREGISTER:
  723. cg.a_loadmm_reg_ref(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href,mms_movescalar);
  724. else
  725. internalerror(200402081);
  726. end;
  727. {$endif cputargethasfixedstack}
  728. end;
  729. end;
  730. end;
  731. dec(sizeleft,tcgsize2size[tmpparaloc^.size]);
  732. callerparaloc:=callerparaloc^.next;
  733. tmpparaloc:=tmpparaloc^.next;
  734. end;
  735. end;
  736. ppn:=tcgcallparanode(ppn.right);
  737. end;
  738. end;
  739. procedure tcgcallnode.freeparas;
  740. var
  741. ppn : tcgcallparanode;
  742. begin
  743. { free the resources allocated for the parameters }
  744. ppn:=tcgcallparanode(left);
  745. while assigned(ppn) do
  746. begin
  747. if (ppn.left.nodetype<>nothingn) then
  748. begin
  749. if
  750. {$ifdef PASS2INLINE}
  751. not assigned(inlinecode) or
  752. {$endif PASS2INLINE}
  753. (ppn.parasym.paraloc[callerside].location^.loc <> LOC_REFERENCE) then
  754. paramanager.freeparaloc(exprasmlist,ppn.parasym.paraloc[callerside]);
  755. end;
  756. ppn:=tcgcallparanode(ppn.right);
  757. end;
  758. end;
  759. procedure tcgcallnode.normal_pass_2;
  760. var
  761. regs_to_save_int,
  762. regs_to_save_fpu,
  763. regs_to_save_mm : Tcpuregisterset;
  764. href : treference;
  765. pop_size : longint;
  766. pvreg,
  767. vmtreg : tregister;
  768. oldaktcallnode : tcallnode;
  769. begin
  770. if not assigned(procdefinition) or
  771. not procdefinition.has_paraloc_info then
  772. internalerror(200305264);
  773. if resulttype.def.needs_inittable and
  774. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) and
  775. not assigned(funcretnode) then
  776. begin
  777. tg.gettemptyped(exprasmlist,resulttype.def,tt_normal,refcountedtemp);
  778. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp);
  779. end;
  780. regs_to_save_int:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  781. regs_to_save_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  782. regs_to_save_mm:=paramanager.get_volatile_registers_mm(procdefinition.proccalloption);
  783. { Include Function result registers }
  784. if (not is_void(resulttype.def)) then
  785. begin
  786. case procdefinition.funcretloc[callerside].loc of
  787. LOC_REGISTER,
  788. LOC_CREGISTER:
  789. include(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register));
  790. LOC_FPUREGISTER,
  791. LOC_CFPUREGISTER:
  792. include(regs_to_save_fpu,getsupreg(procdefinition.funcretloc[callerside].register));
  793. LOC_MMREGISTER,
  794. LOC_CMMREGISTER:
  795. include(regs_to_save_mm,getsupreg(procdefinition.funcretloc[callerside].register));
  796. LOC_REFERENCE,
  797. LOC_VOID:
  798. ;
  799. else
  800. internalerror(2004110213);
  801. end;
  802. end;
  803. { Process parameters, register parameters will be loaded
  804. in imaginary registers. The actual load to the correct
  805. register is done just before the call }
  806. oldaktcallnode:=aktcallnode;
  807. aktcallnode:=self;
  808. if assigned(left) then
  809. tcallparanode(left).secondcallparan;
  810. aktcallnode:=oldaktcallnode;
  811. { procedure variable or normal function call ? }
  812. if (right=nil) then
  813. begin
  814. { When methodpointer is typen we don't need (and can't) load
  815. a pointer. We can directly call the correct procdef (PFV) }
  816. if (po_virtualmethod in procdefinition.procoptions) and
  817. assigned(methodpointer) and
  818. (methodpointer.nodetype<>typen) then
  819. begin
  820. { virtual methods require an index }
  821. if tprocdef(procdefinition).extnumber=$ffff then
  822. internalerror(200304021);
  823. secondpass(methodpointer);
  824. { Load VMT from self }
  825. if methodpointer.resulttype.def.deftype=objectdef then
  826. gen_load_vmt_register(exprasmlist,tobjectdef(methodpointer.resulttype.def),methodpointer.location,vmtreg)
  827. else
  828. begin
  829. { Load VMT value in register }
  830. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  831. vmtreg:=methodpointer.location.register;
  832. end;
  833. { test validity of VMT }
  834. if not(is_interface(tprocdef(procdefinition)._class)) and
  835. not(is_cppclass(tprocdef(procdefinition)._class)) then
  836. cg.g_maybe_testvmt(exprasmlist,vmtreg,tprocdef(procdefinition)._class);
  837. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  838. reference_reset_base(href,vmtreg,
  839. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  840. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,pvreg);
  841. { Load parameters that are in temporary registers in the
  842. correct parameter register }
  843. if assigned(left) then
  844. begin
  845. pushparas;
  846. { free the resources allocated for the parameters }
  847. freeparas;
  848. end;
  849. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  850. if cg.uses_registers(R_FPUREGISTER) then
  851. cg.alloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  852. if cg.uses_registers(R_MMREGISTER) then
  853. cg.alloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  854. { call method }
  855. extra_call_code;
  856. cg.a_call_reg(exprasmlist,pvreg);
  857. extra_post_call_code;
  858. end
  859. else
  860. begin
  861. { Load parameters that are in temporary registers in the
  862. correct parameter register }
  863. if assigned(left) then
  864. begin
  865. pushparas;
  866. { free the resources allocated for the parameters }
  867. freeparas;
  868. end;
  869. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  870. if cg.uses_registers(R_FPUREGISTER) then
  871. cg.alloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  872. if cg.uses_registers(R_MMREGISTER) then
  873. cg.alloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  874. if procdefinition.proccalloption=pocall_syscall then
  875. do_syscall
  876. else
  877. begin
  878. { Calling interrupt from the same code requires some
  879. extra code }
  880. if (po_interrupt in procdefinition.procoptions) then
  881. extra_interrupt_code;
  882. extra_call_code;
  883. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  884. extra_post_call_code;
  885. end;
  886. end;
  887. end
  888. else
  889. { now procedure variable case }
  890. begin
  891. secondpass(right);
  892. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  893. { Only load OS_ADDR from the reference }
  894. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  895. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,right.location.reference,pvreg)
  896. else
  897. cg.a_load_loc_reg(exprasmlist,OS_ADDR,right.location,pvreg);
  898. location_freetemp(exprasmlist,right.location);
  899. { Load parameters that are in temporary registers in the
  900. correct parameter register }
  901. if assigned(left) then
  902. begin
  903. pushparas;
  904. { free the resources allocated for the parameters }
  905. freeparas;
  906. end;
  907. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  908. if cg.uses_registers(R_FPUREGISTER) then
  909. cg.alloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  910. if cg.uses_registers(R_MMREGISTER) then
  911. cg.alloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  912. { Calling interrupt from the same code requires some
  913. extra code }
  914. if (po_interrupt in procdefinition.procoptions) then
  915. extra_interrupt_code;
  916. extra_call_code;
  917. cg.a_call_reg(exprasmlist,pvreg);
  918. extra_post_call_code;
  919. end;
  920. { Need to remove the parameters from the stack? }
  921. if (procdefinition.proccalloption in clearstack_pocalls) then
  922. begin
  923. pop_size:=pushedparasize;
  924. { for Cdecl functions we don't need to pop the funcret when it
  925. was pushed by para }
  926. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  927. dec(pop_size,sizeof(aint));
  928. { Remove parameters/alignment from the stack }
  929. pop_parasize(pop_size);
  930. end;
  931. { Release registers, but not the registers that contain the
  932. function result }
  933. if (not is_void(resulttype.def)) then
  934. begin
  935. case procdefinition.funcretloc[callerside].loc of
  936. LOC_REGISTER,
  937. LOC_CREGISTER:
  938. begin
  939. {$ifndef cpu64bit}
  940. if procdefinition.funcretloc[callerside].size in [OS_64,OS_S64] then
  941. begin
  942. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register64.reghi));
  943. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register64.reglo));
  944. end
  945. else
  946. {$endif cpu64bit}
  947. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register));
  948. end;
  949. LOC_FPUREGISTER,
  950. LOC_CFPUREGISTER:
  951. exclude(regs_to_save_fpu,getsupreg(procdefinition.funcretloc[callerside].register));
  952. LOC_MMREGISTER,
  953. LOC_CMMREGISTER:
  954. exclude(regs_to_save_mm,getsupreg(procdefinition.funcretloc[callerside].register));
  955. LOC_REFERENCE,
  956. LOC_VOID:
  957. ;
  958. else
  959. internalerror(2004110214);
  960. end;
  961. end;
  962. if cg.uses_registers(R_MMREGISTER) then
  963. cg.dealloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  964. if cg.uses_registers(R_FPUREGISTER) then
  965. cg.dealloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  966. cg.dealloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  967. { handle function results }
  968. if (not is_void(resulttype.def)) then
  969. handle_return_value
  970. else
  971. location_reset(location,LOC_VOID,OS_NO);
  972. { perhaps i/o check ? }
  973. if (cs_check_io in aktlocalswitches) and
  974. (po_iocheck in procdefinition.procoptions) and
  975. not(po_iocheck in current_procinfo.procdef.procoptions) and
  976. { no IO check for methods and procedure variables }
  977. (right=nil) and
  978. not(po_virtualmethod in procdefinition.procoptions) then
  979. begin
  980. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  981. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  982. cg.dealloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  983. end;
  984. { release temps of paras }
  985. release_para_temps;
  986. end;
  987. {$ifdef PASS2INLINE}
  988. procedure tcgcallnode.inlined_pass_2;
  989. var
  990. oldaktcallnode : tcallnode;
  991. oldprocinfo : tprocinfo;
  992. oldinlining_procedure : boolean;
  993. inlineentrycode,inlineexitcode : TAAsmoutput;
  994. {$ifdef GDB}
  995. startlabel,endlabel : tasmlabel;
  996. pp : pchar;
  997. mangled_length : longint;
  998. {$endif GDB}
  999. begin
  1000. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  1001. internalerror(200305262);
  1002. oldinlining_procedure:=inlining_procedure;
  1003. oldprocinfo:=current_procinfo;
  1004. { we're inlining a procedure }
  1005. inlining_procedure:=true;
  1006. { Add inling start }
  1007. {$ifdef GDB}
  1008. exprasmlist.concat(Tai_force_line.Create);
  1009. {$endif GDB}
  1010. exprasmList.concat(Tai_Marker.Create(InlineStart));
  1011. {$ifdef extdebug}
  1012. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc '+tprocdef(procdefinition).procsym.name)));
  1013. {$endif extdebug}
  1014. { calculate registers to pass the parameters }
  1015. paramanager.create_inline_paraloc_info(procdefinition);
  1016. { Allocate parameters and locals }
  1017. gen_alloc_inline_parast(exprasmlist,tprocdef(procdefinition));
  1018. gen_alloc_inline_funcret(exprasmlist,tprocdef(procdefinition));
  1019. gen_alloc_symtable(exprasmlist,tprocdef(procdefinition).localst);
  1020. { if we allocate the temp. location for ansi- or widestrings }
  1021. { already here, we avoid later a push/pop }
  1022. if resulttype.def.needs_inittable and
  1023. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1024. begin
  1025. tg.gettemptyped(exprasmlist,resulttype.def,tt_normal,refcountedtemp);
  1026. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp);
  1027. end;
  1028. { Push parameters, still use the old current_procinfo. This
  1029. is required that have the correct information available like
  1030. _class and nested procedure }
  1031. oldaktcallnode:=aktcallnode;
  1032. aktcallnode:=self;
  1033. if assigned(left) then
  1034. begin
  1035. tcallparanode(left).secondcallparan;
  1036. pushparas;
  1037. end;
  1038. aktcallnode:=oldaktcallnode;
  1039. { create temp procinfo that will be used for the inlinecode tree }
  1040. current_procinfo:=cprocinfo.create(nil);
  1041. current_procinfo.procdef:=tprocdef(procdefinition);
  1042. current_procinfo.flags:=oldprocinfo.flags;
  1043. current_procinfo.aktlocaldata.destroy;
  1044. current_procinfo.aktlocaldata:=oldprocinfo.aktlocaldata;
  1045. { when the oldprocinfo is also being inlined reuse the
  1046. inlining_procinfo }
  1047. if assigned(oldprocinfo.inlining_procinfo) then
  1048. current_procinfo.inlining_procinfo:=oldprocinfo.inlining_procinfo
  1049. else
  1050. current_procinfo.inlining_procinfo:=oldprocinfo;
  1051. { takes care of local data initialization }
  1052. inlineentrycode:=TAAsmoutput.Create;
  1053. inlineexitcode:=TAAsmoutput.Create;
  1054. {$ifdef GDB}
  1055. if (cs_debuginfo in aktmoduleswitches) and
  1056. not(cs_gdb_valgrind in aktglobalswitches) then
  1057. begin
  1058. objectlibrary.getaddrlabel(startlabel);
  1059. objectlibrary.getaddrlabel(endlabel);
  1060. cg.a_label(exprasmlist,startlabel);
  1061. { Here we must include the para and local symtable info }
  1062. procdefinition.concatstabto(withdebuglist);
  1063. mangled_length:=length(current_procinfo.inlining_procinfo.procdef.mangledname);
  1064. getmem(pp,mangled_length+50);
  1065. strpcopy(pp,'192,0,0,'+startlabel.name);
  1066. if (target_info.use_function_relative_addresses) then
  1067. begin
  1068. strpcopy(strend(pp),'-');
  1069. strpcopy(strend(pp),current_procinfo.inlining_procinfo.procdef.mangledname);
  1070. end;
  1071. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1072. end;
  1073. {$endif GDB}
  1074. gen_load_para_value(inlineentrycode);
  1075. { now that we've loaded the para's, free them }
  1076. if assigned(left) then
  1077. freeparas;
  1078. gen_initialize_code(inlineentrycode);
  1079. if po_assembler in current_procinfo.procdef.procoptions then
  1080. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  1081. exprasmList.concatlist(inlineentrycode);
  1082. { process the inline code }
  1083. secondpass(inlinecode);
  1084. cg.a_label(exprasmlist,current_procinfo.aktexitlabel);
  1085. gen_finalize_code(inlineexitcode);
  1086. gen_load_return_value(inlineexitcode);
  1087. if po_assembler in current_procinfo.procdef.procoptions then
  1088. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  1089. exprasmlist.concatlist(inlineexitcode);
  1090. inlineentrycode.free;
  1091. inlineexitcode.free;
  1092. {$ifdef extdebug}
  1093. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  1094. {$endif extdebug}
  1095. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1096. { handle function results }
  1097. if (not is_void(resulttype.def)) then
  1098. handle_return_value
  1099. else
  1100. location_reset(location,LOC_VOID,OS_NO);
  1101. { perhaps i/o check ? }
  1102. if (cs_check_io in aktlocalswitches) and
  1103. (po_iocheck in procdefinition.procoptions) and
  1104. not(po_iocheck in current_procinfo.procdef.procoptions) and
  1105. { no IO check for methods and procedure variables }
  1106. (right=nil) and
  1107. not(po_virtualmethod in procdefinition.procoptions) then
  1108. begin
  1109. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1110. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1111. cg.dealloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1112. end;
  1113. { release temps of paras }
  1114. release_para_temps;
  1115. { if return value is not used }
  1116. if (not is_void(resulttype.def)) and
  1117. (not(cnf_return_value_used in callnodeflags)) then
  1118. begin
  1119. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1120. begin
  1121. { data which must be finalized ? }
  1122. if (resulttype.def.needs_inittable) then
  1123. cg.g_finalize(exprasmlist,resulttype.def,location.reference);
  1124. { release unused temp }
  1125. tg.ungetiftemp(exprasmlist,location.reference)
  1126. end
  1127. else if location.loc=LOC_FPUREGISTER then
  1128. begin
  1129. {$ifdef x86}
  1130. { release FPU stack }
  1131. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  1132. {$endif x86}
  1133. end;
  1134. end;
  1135. { Release parameters and locals }
  1136. gen_free_symtable(exprasmlist,tparasymtable(current_procinfo.procdef.parast));
  1137. gen_free_symtable(exprasmlist,tlocalsymtable(current_procinfo.procdef.localst));
  1138. {$ifdef GDB}
  1139. if (cs_debuginfo in aktmoduleswitches) and
  1140. not(cs_gdb_valgrind in aktglobalswitches) then
  1141. begin
  1142. cg.a_label(exprasmlist,endlabel);
  1143. strpcopy(pp,'224,0,0,'+endlabel.name);
  1144. if (target_info.use_function_relative_addresses) then
  1145. begin
  1146. strpcopy(strend(pp),'-');
  1147. strpcopy(strend(pp),current_procinfo.inlining_procinfo.procdef.mangledname);
  1148. end;
  1149. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1150. freemem(pp,mangled_length+50);
  1151. end;
  1152. {$endif GDB}
  1153. { restore }
  1154. current_procinfo.aktlocaldata:=nil;
  1155. current_procinfo.destroy;
  1156. current_procinfo:=oldprocinfo;
  1157. inlining_procedure:=oldinlining_procedure;
  1158. end;
  1159. {$endif PASS2INLINE}
  1160. procedure tcgcallnode.pass_2;
  1161. begin
  1162. if assigned(methodpointerinit) then
  1163. secondpass(methodpointerinit);
  1164. {$ifdef PASS2INLINE}
  1165. if assigned(inlinecode) then
  1166. inlined_pass_2
  1167. else
  1168. {$endif PASS2INLINE}
  1169. normal_pass_2;
  1170. if assigned(methodpointerdone) then
  1171. secondpass(methodpointerdone);
  1172. end;
  1173. begin
  1174. ccallparanode:=tcgcallparanode;
  1175. ccallnode:=tcgcallnode;
  1176. end.