ncgcal.pas 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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 handle_return_value;
  39. procedure release_unused_return_value;
  40. procedure release_para_temps;
  41. procedure pushparas;
  42. procedure freeparas;
  43. protected
  44. framepointer_paraloc : tcgpara;
  45. {# This routine is used to push the current frame pointer
  46. on the stack. This is used in nested routines where the
  47. value of the frame pointer is always pushed as an extra
  48. parameter.
  49. The default handling is the standard handling used on
  50. most stack based machines, where the frame pointer is
  51. the first invisible parameter.
  52. }
  53. procedure pop_parasize(pop_size:longint);virtual;
  54. procedure extra_interrupt_code;virtual;
  55. procedure extra_call_code;virtual;
  56. procedure extra_post_call_code;virtual;
  57. procedure do_syscall;virtual;abstract;
  58. public
  59. procedure pass_generate_code;override;
  60. end;
  61. implementation
  62. uses
  63. systems,
  64. cutils,verbose,globals,
  65. cpuinfo,
  66. symconst,symtable,defutil,paramgr,
  67. cgbase,pass_2,
  68. aasmbase,aasmtai,aasmdata,
  69. nbas,nmem,nld,ncnv,nutils,
  70. {$ifdef x86}
  71. cga,cgx86,aasmcpu,
  72. {$endif x86}
  73. ncgutil,
  74. cgobj,tgobj,
  75. procinfo;
  76. {*****************************************************************************
  77. TCGCALLPARANODE
  78. *****************************************************************************}
  79. constructor tcgcallparanode.create(expr,next : tnode);
  80. begin
  81. inherited create(expr,next);
  82. tempcgpara.init;
  83. end;
  84. destructor tcgcallparanode.destroy;
  85. begin
  86. tempcgpara.done;
  87. inherited destroy;
  88. end;
  89. procedure tcgcallparanode.push_addr_para;
  90. begin
  91. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  92. internalerror(200304235);
  93. cg.a_paramaddr_ref(current_asmdata.CurrAsmList,left.location.reference,tempcgpara);
  94. end;
  95. procedure tcgcallparanode.push_value_para;
  96. {$ifdef i386}
  97. var
  98. href : treference;
  99. size : longint;
  100. {$endif i386}
  101. begin
  102. { we've nothing to push when the size of the parameter is 0 }
  103. if left.resultdef.size=0 then
  104. exit;
  105. { Move flags and jump in register to make it less complex }
  106. if left.location.loc in [LOC_FLAGS,LOC_JUMP,LOC_SUBSETREG,LOC_CSUBSETREG,LOC_SUBSETREF,LOC_CSUBSETREF] then
  107. location_force_reg(current_asmdata.CurrAsmList,left.location,def_cgsize(left.resultdef),false);
  108. { Handle Floating point types differently
  109. This doesn't depend on emulator settings, emulator settings should
  110. be handled by cpupara }
  111. if left.resultdef.typ=floatdef then
  112. begin
  113. {$ifdef i386}
  114. if tempcgpara.location^.loc<>LOC_REFERENCE then
  115. internalerror(200309291);
  116. case left.location.loc of
  117. LOC_FPUREGISTER,
  118. LOC_CFPUREGISTER:
  119. begin
  120. size:=align(TCGSize2Size[left.location.size],tempcgpara.alignment);
  121. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  122. begin
  123. cg.g_stackpointer_alloc(current_asmdata.CurrAsmList,size);
  124. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  125. end
  126. else
  127. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  128. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,left.location.size,left.location.size,left.location.register,href);
  129. end;
  130. LOC_MMREGISTER,
  131. LOC_CMMREGISTER:
  132. begin
  133. size:=align(tfloatdef(left.resultdef).size,tempcgpara.alignment);
  134. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  135. begin
  136. cg.g_stackpointer_alloc(current_asmdata.CurrAsmList,size);
  137. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  138. end
  139. else
  140. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  141. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,left.location.size,left.location.size,left.location.register,href,mms_movescalar);
  142. end;
  143. LOC_REFERENCE,
  144. LOC_CREFERENCE :
  145. begin
  146. size:=align(left.resultdef.size,tempcgpara.alignment);
  147. if (not use_fixed_stack) and
  148. (tempcgpara.location^.reference.index=NR_STACK_POINTER_REG) then
  149. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara)
  150. else
  151. begin
  152. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  153. cg.g_concatcopy(current_asmdata.CurrAsmList,left.location.reference,href,size);
  154. end;
  155. end;
  156. else
  157. internalerror(2002042430);
  158. end;
  159. {$else i386}
  160. case left.location.loc of
  161. LOC_MMREGISTER,
  162. LOC_CMMREGISTER:
  163. case tempcgpara.location^.loc of
  164. LOC_REFERENCE,
  165. LOC_CREFERENCE,
  166. LOC_MMREGISTER,
  167. LOC_CMMREGISTER:
  168. cg.a_parammm_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  169. {$ifdef x86_64}
  170. LOC_REGISTER,
  171. LOC_CREGISTER :
  172. begin
  173. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_MOVD,S_NO,left.location.register,tempcgpara.location^.register));
  174. end;
  175. {$endif x86_64}
  176. LOC_FPUREGISTER,
  177. LOC_CFPUREGISTER:
  178. begin
  179. location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
  180. cg.a_paramfpu_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara);
  181. end;
  182. else
  183. internalerror(200204249);
  184. end;
  185. LOC_FPUREGISTER,
  186. LOC_CFPUREGISTER:
  187. case tempcgpara.location^.loc of
  188. LOC_MMREGISTER,
  189. LOC_CMMREGISTER:
  190. begin
  191. location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,false);
  192. cg.a_parammm_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  193. end;
  194. {$ifdef cpu64bit}
  195. LOC_REGISTER,
  196. LOC_CREGISTER :
  197. begin
  198. location_force_mem(current_asmdata.CurrAsmList,left.location);
  199. { force integer size }
  200. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  201. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara);
  202. end;
  203. {$endif cpu64bit}
  204. {$ifdef powerpc}
  205. LOC_REGISTER,
  206. LOC_CREGISTER :
  207. begin
  208. { aix abi passes floats of varargs in both fpu and }
  209. { integer registers }
  210. location_force_mem(current_asmdata.CurrAsmList,left.location);
  211. { force integer size }
  212. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  213. if (left.location.size in [OS_32,OS_S32]) then
  214. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara)
  215. else
  216. cg64.a_param64_ref(current_asmdata.CurrAsmList,left.location.reference,tempcgpara);
  217. end;
  218. {$endif powerpc}
  219. {$if defined(sparc) or defined(arm) or defined(m68k)}
  220. { sparc and arm pass floats in normal registers }
  221. LOC_REGISTER,
  222. LOC_CREGISTER,
  223. {$endif sparc}
  224. LOC_REFERENCE,
  225. LOC_CREFERENCE,
  226. LOC_FPUREGISTER,
  227. LOC_CFPUREGISTER:
  228. cg.a_paramfpu_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara);
  229. else
  230. internalerror(2002042433);
  231. end;
  232. LOC_REFERENCE,
  233. LOC_CREFERENCE:
  234. case tempcgpara.location^.loc of
  235. LOC_MMREGISTER,
  236. LOC_CMMREGISTER:
  237. cg.a_parammm_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara,mms_movescalar);
  238. {$ifdef cpu64bit}
  239. LOC_REGISTER,
  240. LOC_CREGISTER :
  241. begin
  242. { force integer size }
  243. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  244. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara);
  245. end;
  246. {$endif cpu64bit}
  247. {$ifdef powerpc}
  248. { x86_64 pushes s64comp in normal register }
  249. LOC_REGISTER,
  250. LOC_CREGISTER :
  251. begin
  252. { force integer size }
  253. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  254. if (left.location.size in [OS_32,OS_S32]) then
  255. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara)
  256. else
  257. cg64.a_param64_ref(current_asmdata.CurrAsmList,left.location.reference,tempcgpara);
  258. end;
  259. {$endif powerpc}
  260. {$if defined(sparc) or defined(arm) or defined(m68k)}
  261. { sparc and arm pass floats in normal registers }
  262. LOC_REGISTER,
  263. LOC_CREGISTER,
  264. {$endif}
  265. LOC_REFERENCE,
  266. LOC_CREFERENCE,
  267. LOC_FPUREGISTER,
  268. LOC_CFPUREGISTER:
  269. cg.a_paramfpu_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara);
  270. else
  271. internalerror(2002042431);
  272. end;
  273. LOC_REGISTER,
  274. LOC_CREGISTER :
  275. begin
  276. {$ifndef cpu64bit}
  277. { use cg64 only for int64, not for 8 byte records }
  278. if is_64bit(left.resultdef) then
  279. cg64.a_param64_loc(current_asmdata.CurrAsmList,left.location,tempcgpara)
  280. else
  281. {$endif cpu64bit}
  282. begin
  283. {$ifndef cpu64bit}
  284. { Only a_param_ref supports multiple locations, when the
  285. value is still a const or in a register then write it
  286. to a reference first. This situation can be triggered
  287. by typecasting an int64 constant to a record of 8 bytes }
  288. if left.location.size in [OS_64,OS_S64] then
  289. location_force_mem(current_asmdata.CurrAsmList,left.location);
  290. {$endif cpu64bit}
  291. cg.a_param_loc(current_asmdata.CurrAsmList,left.location,tempcgpara);
  292. end;
  293. end;
  294. else
  295. internalerror(2002042432);
  296. end;
  297. {$endif i386}
  298. end
  299. else
  300. begin
  301. case left.location.loc of
  302. LOC_CONSTANT,
  303. LOC_REGISTER,
  304. LOC_CREGISTER,
  305. LOC_REFERENCE,
  306. LOC_CREFERENCE :
  307. begin
  308. {$ifndef cpu64bit}
  309. { use cg64 only for int64, not for 8 byte records }
  310. if is_64bit(left.resultdef) then
  311. cg64.a_param64_loc(current_asmdata.CurrAsmList,left.location,tempcgpara)
  312. else
  313. {$endif cpu64bit}
  314. begin
  315. {$ifndef cpu64bit}
  316. { Only a_param_ref supports multiple locations, when the
  317. value is still a const or in a register then write it
  318. to a reference first. This situation can be triggered
  319. by typecasting an int64 constant to a record of 8 bytes }
  320. if left.location.size in [OS_64,OS_S64] then
  321. location_force_mem(current_asmdata.CurrAsmList,left.location);
  322. {$endif cpu64bit}
  323. cg.a_param_loc(current_asmdata.CurrAsmList,left.location,tempcgpara);
  324. end;
  325. end;
  326. {$ifdef SUPPORT_MMX}
  327. LOC_MMXREGISTER,
  328. LOC_CMMXREGISTER:
  329. cg.a_parammm_reg(current_asmdata.CurrAsmList,OS_M64,left.location.register,tempcgpara,nil);
  330. {$endif SUPPORT_MMX}
  331. else
  332. internalerror(200204241);
  333. end;
  334. end;
  335. end;
  336. procedure tcgcallparanode.secondcallparan;
  337. var
  338. href : treference;
  339. otlabel,
  340. oflabel : tasmlabel;
  341. begin
  342. if not(assigned(parasym)) then
  343. internalerror(200304242);
  344. { Skip nothingn nodes which are used after disabling
  345. a parameter }
  346. if (left.nodetype<>nothingn) then
  347. begin
  348. otlabel:=current_procinfo.CurrTrueLabel;
  349. oflabel:=current_procinfo.CurrFalseLabel;
  350. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  351. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  352. secondpass(left);
  353. maybechangeloadnodereg(current_asmdata.CurrAsmList,left,true);
  354. { release memory for refcnt out parameters }
  355. if (parasym.varspez=vs_out) and
  356. (left.resultdef.needs_inittable) then
  357. begin
  358. location_get_data_ref(current_asmdata.CurrAsmList,left.location,href,false);
  359. cg.g_decrrefcount(current_asmdata.CurrAsmList,left.resultdef,href);
  360. end;
  361. paramanager.createtempparaloc(current_asmdata.CurrAsmList,aktcallnode.procdefinition.proccalloption,parasym,tempcgpara);
  362. { handle varargs first, because parasym is not valid }
  363. if (cpf_varargs_para in callparaflags) then
  364. begin
  365. if paramanager.push_addr_param(vs_value,left.resultdef,
  366. aktcallnode.procdefinition.proccalloption) then
  367. push_addr_para
  368. else
  369. push_value_para;
  370. end
  371. { hidden parameters }
  372. else if (vo_is_hidden_para in parasym.varoptions) then
  373. begin
  374. { don't push a node that already generated a pointer type
  375. by address for implicit hidden parameters }
  376. if (vo_is_funcret in parasym.varoptions) or
  377. { pass "this" in C++ classes explicitly as pointer
  378. because push_addr_param might not be true for them }
  379. (is_cppclass(parasym.vardef) and (vo_is_self in parasym.varoptions)) or
  380. (not(left.resultdef.typ in [pointerdef,classrefdef]) and
  381. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  382. aktcallnode.procdefinition.proccalloption)) then
  383. push_addr_para
  384. else
  385. push_value_para;
  386. end
  387. { formal def }
  388. else if (parasym.vardef.typ=formaldef) then
  389. begin
  390. { allow passing of a constant to a const formaldef }
  391. if (parasym.varspez=vs_const) and
  392. (left.location.loc in [LOC_CONSTANT,LOC_REGISTER]) then
  393. location_force_mem(current_asmdata.CurrAsmList,left.location);
  394. push_addr_para;
  395. end
  396. { Normal parameter }
  397. else
  398. begin
  399. { don't push a node that already generated a pointer type
  400. by address for implicit hidden parameters }
  401. if (not(
  402. (vo_is_hidden_para in parasym.varoptions) and
  403. (left.resultdef.typ in [pointerdef,classrefdef])
  404. ) and
  405. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  406. aktcallnode.procdefinition.proccalloption)) and
  407. { dyn. arrays passed to an array of const must be passed by value, see tests/webtbs/tw4219.pp }
  408. not(
  409. is_array_of_const(parasym.vardef) and
  410. is_dynamic_array(left.resultdef)
  411. ) then
  412. begin
  413. { Passing a var parameter to a var parameter, we can
  414. just push the address transparently }
  415. if (left.nodetype=loadn) and
  416. (tloadnode(left).is_addr_param_load) then
  417. begin
  418. if (left.location.reference.index<>NR_NO) or
  419. (left.location.reference.offset<>0) then
  420. internalerror(200410107);
  421. cg.a_param_reg(current_asmdata.CurrAsmList,OS_ADDR,left.location.reference.base,tempcgpara)
  422. end
  423. else
  424. begin
  425. { Force to be in memory }
  426. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  427. location_force_mem(current_asmdata.CurrAsmList,left.location);
  428. push_addr_para;
  429. end;
  430. end
  431. else
  432. push_value_para;
  433. end;
  434. current_procinfo.CurrTrueLabel:=otlabel;
  435. current_procinfo.CurrFalseLabel:=oflabel;
  436. { update return location in callnode when this is the function
  437. result }
  438. if assigned(parasym) and
  439. (vo_is_funcret in parasym.varoptions) then
  440. location_copy(aktcallnode.location,left.location);
  441. end;
  442. { next parameter }
  443. if assigned(right) then
  444. tcallparanode(right).secondcallparan;
  445. end;
  446. {*****************************************************************************
  447. TCGCALLNODE
  448. *****************************************************************************}
  449. procedure tcgcallnode.extra_interrupt_code;
  450. begin
  451. end;
  452. procedure tcgcallnode.extra_call_code;
  453. begin
  454. end;
  455. procedure tcgcallnode.extra_post_call_code;
  456. begin
  457. end;
  458. procedure tcgcallnode.pop_parasize(pop_size:longint);
  459. begin
  460. end;
  461. procedure tcgcallnode.handle_return_value;
  462. var
  463. cgsize : tcgsize;
  464. retloc : tlocation;
  465. ref : treference;
  466. {$ifndef x86}
  467. hregister : tregister;
  468. {$endif not x86}
  469. begin
  470. { Check that the return location is set when the result is passed in
  471. a parameter }
  472. if (procdefinition.proctypeoption<>potype_constructor) and
  473. paramanager.ret_in_param(resultdef,procdefinition.proccalloption) then
  474. begin
  475. if location.loc<>LOC_REFERENCE then
  476. internalerror(200304241);
  477. exit;
  478. end;
  479. { Load normal (ordinal,float,pointer) result value from accumulator }
  480. cgsize:=procdefinition.funcretloc[callerside].size;
  481. case procdefinition.funcretloc[callerside].loc of
  482. LOC_FPUREGISTER:
  483. begin
  484. location_reset(location,LOC_FPUREGISTER,cgsize);
  485. location.register:=procdefinition.funcretloc[callerside].register;
  486. {$ifdef x86}
  487. tcgx86(cg).inc_fpu_stack;
  488. {$else x86}
  489. if getsupreg(procdefinition.funcretloc[callerside].register)<first_fpu_imreg then
  490. cg.ungetcpuregister(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside].register);
  491. hregister:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  492. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,location.size,location.size,location.register,hregister);
  493. location.register:=hregister;
  494. {$endif x86}
  495. end;
  496. LOC_REGISTER:
  497. begin
  498. if cgsize<>OS_NO then
  499. begin
  500. location_reset(location,LOC_REGISTER,cgsize);
  501. {$ifdef cpu64bit}
  502. { x86-64 system v abi:
  503. structs with up to 16 bytes are returned in registers }
  504. if cgsize in [OS_128,OS_S128] then
  505. begin
  506. tg.GetTemp(current_asmdata.CurrAsmList,16,tt_normal,ref);
  507. location_reset(location,LOC_REFERENCE,OS_NO);
  508. location.reference:=ref;
  509. cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_64,OS_64,procdefinition.funcretloc[callerside].register,ref);
  510. inc(ref.offset,8);
  511. cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_64,OS_64,procdefinition.funcretloc[callerside].registerhi,ref);
  512. end
  513. else
  514. {$else cpu64bit}
  515. if cgsize in [OS_64,OS_S64] then
  516. begin
  517. retloc:=procdefinition.funcretloc[callerside];
  518. if retloc.loc<>LOC_REGISTER then
  519. internalerror(200409141);
  520. { the function result registers are already allocated }
  521. if getsupreg(retloc.register64.reglo)<first_int_imreg then
  522. cg.ungetcpuregister(current_asmdata.CurrAsmList,retloc.register64.reglo);
  523. location.register64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  524. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,retloc.register64.reglo,location.register64.reglo);
  525. if getsupreg(retloc.register64.reghi)<first_int_imreg then
  526. cg.ungetcpuregister(current_asmdata.CurrAsmList,retloc.register64.reghi);
  527. location.register64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  528. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,retloc.register64.reghi,location.register64.reghi);
  529. end
  530. else
  531. {$endif cpu64bit}
  532. begin
  533. { change register size after the unget because the
  534. getregister was done for the full register
  535. def_cgsize(resultdef) is used here because
  536. it could be a constructor call }
  537. if getsupreg(procdefinition.funcretloc[callerside].register)<first_int_imreg then
  538. cg.ungetcpuregister(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside].register);
  539. location.register:=cg.getintregister(current_asmdata.CurrAsmList,def_cgsize(resultdef));
  540. cg.a_load_reg_reg(current_asmdata.CurrAsmList,cgsize,def_cgsize(resultdef),procdefinition.funcretloc[callerside].register,location.register);
  541. end;
  542. {$ifdef arm}
  543. if (resultdef.typ=floatdef) and (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) then
  544. begin
  545. location_force_mem(current_asmdata.CurrAsmList,location);
  546. end;
  547. {$endif arm}
  548. end
  549. else
  550. begin
  551. if resultdef.size>0 then
  552. internalerror(200305131);
  553. end;
  554. end;
  555. LOC_MMREGISTER:
  556. begin
  557. location_reset(location,LOC_MMREGISTER,cgsize);
  558. if getsupreg(procdefinition.funcretloc[callerside].register)<first_mm_imreg then
  559. cg.ungetcpuregister(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside].register);
  560. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,cgsize);
  561. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,cgsize,cgsize,procdefinition.funcretloc[callerside].register,location.register,mms_movescalar);
  562. end;
  563. else
  564. internalerror(200405023);
  565. end;
  566. { copy value to the final location if this was already provided to the
  567. callnode. This must be done after the call node, because the location can
  568. also be used as parameter and may not be finalized yet }
  569. if assigned(funcretnode) then
  570. begin
  571. funcretnode.pass_generate_code;
  572. { Decrease refcount for refcounted types, this can be skipped when
  573. we have used a temp, because then it is already done from tempcreatenode.
  574. Also no finalize is needed, because there is no risk of exceptions from the
  575. function since this is code is only executed after the function call has returned }
  576. if funcretnode.resultdef.needs_inittable and
  577. (funcretnode.nodetype<>temprefn) then
  578. cg.g_decrrefcount(current_asmdata.CurrAsmList,funcretnode.resultdef,funcretnode.location.reference);
  579. case location.loc of
  580. LOC_REGISTER :
  581. {$ifndef cpu64bit}
  582. if cgsize in [OS_64,OS_S64] then
  583. cg64.a_load64_reg_loc(current_asmdata.CurrAsmList,location.register64,funcretnode.location)
  584. else
  585. {$endif}
  586. cg.a_load_reg_loc(current_asmdata.CurrAsmList,cgsize,location.register,funcretnode.location);
  587. else
  588. internalerror(200709085);
  589. end;
  590. location := funcretnode.location;
  591. end;
  592. end;
  593. procedure tcgcallnode.release_unused_return_value;
  594. begin
  595. { When the result is not used we need to finalize the result and
  596. can release the temp. This need to be after the callcleanupblock
  597. tree is generated, because that converts the temp from persistent to normal }
  598. if not(cnf_return_value_used in callnodeflags) then
  599. begin
  600. case location.loc of
  601. LOC_REFERENCE :
  602. begin
  603. if resultdef.needs_inittable then
  604. cg.g_finalize(current_asmdata.CurrAsmList,resultdef,location.reference);
  605. tg.ungetiftemp(current_asmdata.CurrAsmList,location.reference);
  606. end;
  607. {$ifdef x86}
  608. LOC_FPUREGISTER :
  609. begin
  610. { release FPU stack }
  611. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  612. tcgx86(cg).dec_fpu_stack;
  613. end;
  614. {$endif x86}
  615. end;
  616. if procdefinition.funcretloc[callerside].size<>OS_NO then
  617. location_free(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside]);
  618. location_reset(location,LOC_VOID,OS_NO);
  619. end;
  620. end;
  621. procedure tcgcallnode.release_para_temps;
  622. var
  623. hp,
  624. hp2 : tnode;
  625. ppn : tcallparanode;
  626. begin
  627. { Release temps from parameters }
  628. ppn:=tcallparanode(left);
  629. while assigned(ppn) do
  630. begin
  631. if assigned(ppn.left) then
  632. begin
  633. { don't release the funcret temp }
  634. if not(assigned(ppn.parasym)) or
  635. not(vo_is_funcret in ppn.parasym.varoptions) then
  636. location_freetemp(current_asmdata.CurrAsmList,ppn.left.location);
  637. { process also all nodes of an array of const }
  638. hp:=ppn.left;
  639. while (hp.nodetype=typeconvn) do
  640. hp:=ttypeconvnode(hp).left;
  641. if (hp.nodetype=arrayconstructorn) and
  642. assigned(tarrayconstructornode(hp).left) then
  643. begin
  644. while assigned(hp) do
  645. begin
  646. hp2:=tarrayconstructornode(hp).left;
  647. { ignore typeconvs and addrn inserted by arrayconstructn for
  648. passing a shortstring }
  649. if (hp2.nodetype=typeconvn) and
  650. (tunarynode(hp2).left.nodetype=addrn) then
  651. hp2:=tunarynode(tunarynode(hp2).left).left;
  652. location_freetemp(current_asmdata.CurrAsmList,hp2.location);
  653. hp:=tarrayconstructornode(hp).right;
  654. end;
  655. end;
  656. end;
  657. ppn:=tcallparanode(ppn.right);
  658. end;
  659. end;
  660. procedure tcgcallnode.pushparas;
  661. var
  662. ppn : tcgcallparanode;
  663. callerparaloc,
  664. tmpparaloc : pcgparalocation;
  665. sizeleft: aint;
  666. htempref,
  667. href : treference;
  668. begin
  669. { copy all resources to the allocated registers }
  670. ppn:=tcgcallparanode(left);
  671. while assigned(ppn) do
  672. begin
  673. if (ppn.left.nodetype<>nothingn) then
  674. begin
  675. { better check for the real location of the parameter here, when stack passed parameters
  676. are saved temporary in registers, checking for the tmpparaloc.loc is wrong
  677. }
  678. paramanager.freeparaloc(current_asmdata.CurrAsmList,ppn.tempcgpara);
  679. tmpparaloc:=ppn.tempcgpara.location;
  680. sizeleft:=ppn.tempcgpara.intsize;
  681. callerparaloc:=ppn.parasym.paraloc[callerside].location;
  682. while assigned(callerparaloc) do
  683. begin
  684. { Every paraloc must have a matching tmpparaloc }
  685. if not assigned(tmpparaloc) then
  686. internalerror(200408224);
  687. if callerparaloc^.size<>tmpparaloc^.size then
  688. internalerror(200408225);
  689. case callerparaloc^.loc of
  690. LOC_REGISTER:
  691. begin
  692. if tmpparaloc^.loc<>LOC_REGISTER then
  693. internalerror(200408221);
  694. if getsupreg(callerparaloc^.register)<first_int_imreg then
  695. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  696. cg.a_load_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  697. tmpparaloc^.register,callerparaloc^.register);
  698. end;
  699. LOC_FPUREGISTER:
  700. begin
  701. if tmpparaloc^.loc<>LOC_FPUREGISTER then
  702. internalerror(200408222);
  703. if getsupreg(callerparaloc^.register)<first_fpu_imreg then
  704. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  705. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,ppn.tempcgpara.size,tmpparaloc^.register,callerparaloc^.register);
  706. end;
  707. LOC_MMREGISTER:
  708. begin
  709. if tmpparaloc^.loc<>LOC_MMREGISTER then
  710. internalerror(200408223);
  711. if getsupreg(callerparaloc^.register)<first_mm_imreg then
  712. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  713. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  714. tmpparaloc^.register,callerparaloc^.register,mms_movescalar);
  715. end;
  716. LOC_REFERENCE:
  717. begin
  718. if use_fixed_stack then
  719. begin
  720. { Can't have a data copied to the stack, every location
  721. must contain a valid size field }
  722. if (ppn.tempcgpara.size=OS_NO) and
  723. ((tmpparaloc^.loc<>LOC_REFERENCE) or
  724. assigned(tmpparaloc^.next)) then
  725. internalerror(200501281);
  726. reference_reset_base(href,callerparaloc^.reference.index,callerparaloc^.reference.offset);
  727. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  728. case tmpparaloc^.loc of
  729. LOC_REFERENCE:
  730. begin
  731. reference_reset_base(htempref,tmpparaloc^.reference.index,tmpparaloc^.reference.offset);
  732. { use concatcopy, because it can also be a float which fails when
  733. load_ref_ref is used }
  734. if (ppn.tempcgpara.size <> OS_NO) then
  735. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,tcgsize2size[tmpparaloc^.size])
  736. else
  737. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,sizeleft)
  738. end;
  739. LOC_REGISTER:
  740. cg.a_load_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  741. LOC_FPUREGISTER:
  742. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  743. LOC_MMREGISTER:
  744. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href,mms_movescalar);
  745. else
  746. internalerror(200402081);
  747. end;
  748. end;
  749. end;
  750. end;
  751. dec(sizeleft,tcgsize2size[tmpparaloc^.size]);
  752. callerparaloc:=callerparaloc^.next;
  753. tmpparaloc:=tmpparaloc^.next;
  754. end;
  755. end;
  756. ppn:=tcgcallparanode(ppn.right);
  757. end;
  758. end;
  759. procedure tcgcallnode.freeparas;
  760. var
  761. ppn : tcgcallparanode;
  762. begin
  763. { free the resources allocated for the parameters }
  764. ppn:=tcgcallparanode(left);
  765. while assigned(ppn) do
  766. begin
  767. if (ppn.left.nodetype<>nothingn) then
  768. begin
  769. if (ppn.parasym.paraloc[callerside].location^.loc <> LOC_REFERENCE) then
  770. paramanager.freeparaloc(current_asmdata.CurrAsmList,ppn.parasym.paraloc[callerside]);
  771. end;
  772. ppn:=tcgcallparanode(ppn.right);
  773. end;
  774. end;
  775. procedure tcgcallnode.pass_generate_code;
  776. var
  777. regs_to_save_int,
  778. regs_to_save_fpu,
  779. regs_to_save_mm : Tcpuregisterset;
  780. href : treference;
  781. pop_size : longint;
  782. vmtoffset : aint;
  783. pvreg,
  784. vmtreg : tregister;
  785. oldaktcallnode : tcallnode;
  786. {$ifdef vtentry}
  787. sym : tasmsymbol;
  788. {$endif vtentry}
  789. cgpara : tcgpara;
  790. begin
  791. if not assigned(procdefinition) or
  792. not procdefinition.has_paraloc_info then
  793. internalerror(200305264);
  794. if assigned(callinitblock) then
  795. secondpass(callinitblock);
  796. regs_to_save_int:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  797. regs_to_save_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  798. regs_to_save_mm:=paramanager.get_volatile_registers_mm(procdefinition.proccalloption);
  799. { Include Function result registers }
  800. if (not is_void(resultdef)) then
  801. begin
  802. case procdefinition.funcretloc[callerside].loc of
  803. LOC_REGISTER,
  804. LOC_CREGISTER:
  805. include(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register));
  806. LOC_FPUREGISTER,
  807. LOC_CFPUREGISTER:
  808. include(regs_to_save_fpu,getsupreg(procdefinition.funcretloc[callerside].register));
  809. LOC_MMREGISTER,
  810. LOC_CMMREGISTER:
  811. include(regs_to_save_mm,getsupreg(procdefinition.funcretloc[callerside].register));
  812. LOC_REFERENCE,
  813. LOC_VOID:
  814. ;
  815. else
  816. internalerror(2004110213);
  817. end;
  818. end;
  819. { Process parameters, register parameters will be loaded
  820. in imaginary registers. The actual load to the correct
  821. register is done just before the call }
  822. oldaktcallnode:=aktcallnode;
  823. aktcallnode:=self;
  824. if assigned(left) then
  825. tcallparanode(left).secondcallparan;
  826. aktcallnode:=oldaktcallnode;
  827. { procedure variable or normal function call ? }
  828. if (right=nil) then
  829. begin
  830. { When methodpointer is typen we don't need (and can't) load
  831. a pointer. We can directly call the correct procdef (PFV) }
  832. if (po_virtualmethod in procdefinition.procoptions) and
  833. assigned(methodpointer) and
  834. (methodpointer.nodetype<>typen) then
  835. begin
  836. { virtual methods require an index }
  837. if tprocdef(procdefinition).extnumber=$ffff then
  838. internalerror(200304021);
  839. secondpass(methodpointer);
  840. { Load VMT from self }
  841. if methodpointer.resultdef.typ=objectdef then
  842. gen_load_vmt_register(current_asmdata.CurrAsmList,tobjectdef(methodpointer.resultdef),methodpointer.location,vmtreg)
  843. else
  844. begin
  845. { Load VMT value in register }
  846. location_force_reg(current_asmdata.CurrAsmList,methodpointer.location,OS_ADDR,false);
  847. vmtreg:=methodpointer.location.register;
  848. end;
  849. { test validity of VMT }
  850. if not(is_interface(tprocdef(procdefinition)._class)) and
  851. not(is_cppclass(tprocdef(procdefinition)._class)) then
  852. cg.g_maybe_testvmt(current_asmdata.CurrAsmList,vmtreg,tprocdef(procdefinition)._class);
  853. { Call through VMT, generate a VTREF symbol to notify the linker }
  854. vmtoffset:=tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber);
  855. {$ifdef vtentry}
  856. if not is_interface(tprocdef(procdefinition)._class) then
  857. begin
  858. inc(current_asmdata.NextVTEntryNr);
  859. current_asmdata.CurrAsmList.Concat(tai_symbol.CreateName('VTREF'+tostr(current_asmdata.NextVTEntryNr)+'_'+tprocdef(procdefinition)._class.vmt_mangledname+'$$'+tostr(vmtoffset div sizeof(aint)),AT_FUNCTION,0));
  860. end;
  861. {$endif vtentry}
  862. {$ifndef x86}
  863. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  864. {$endif not x86}
  865. reference_reset_base(href,vmtreg,vmtoffset);
  866. {$ifndef x86}
  867. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,href,pvreg);
  868. {$endif not x86}
  869. { Load parameters that are in temporary registers in the
  870. correct parameter register }
  871. if assigned(left) then
  872. begin
  873. pushparas;
  874. { free the resources allocated for the parameters }
  875. freeparas;
  876. end;
  877. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  878. if cg.uses_registers(R_FPUREGISTER) then
  879. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  880. if cg.uses_registers(R_MMREGISTER) then
  881. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  882. { call method }
  883. extra_call_code;
  884. {$ifdef x86}
  885. cg.a_call_ref(current_asmdata.CurrAsmList,href);
  886. {$else x86}
  887. cg.a_call_reg(current_asmdata.CurrAsmList,pvreg);
  888. {$endif x86}
  889. extra_post_call_code;
  890. end
  891. else
  892. begin
  893. { Load parameters that are in temporary registers in the
  894. correct parameter register }
  895. if assigned(left) then
  896. begin
  897. pushparas;
  898. { free the resources allocated for the parameters }
  899. freeparas;
  900. end;
  901. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  902. if cg.uses_registers(R_FPUREGISTER) then
  903. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  904. if cg.uses_registers(R_MMREGISTER) then
  905. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  906. if procdefinition.proccalloption=pocall_syscall then
  907. do_syscall
  908. else
  909. begin
  910. { Calling interrupt from the same code requires some
  911. extra code }
  912. if (po_interrupt in procdefinition.procoptions) then
  913. extra_interrupt_code;
  914. extra_call_code;
  915. cg.a_call_name(current_asmdata.CurrAsmList,tprocdef(procdefinition).mangledname);
  916. extra_post_call_code;
  917. end;
  918. end;
  919. end
  920. else
  921. { now procedure variable case }
  922. begin
  923. secondpass(right);
  924. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  925. { Only load OS_ADDR from the reference }
  926. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  927. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,right.location.reference,pvreg)
  928. else
  929. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_ADDR,right.location,pvreg);
  930. location_freetemp(current_asmdata.CurrAsmList,right.location);
  931. { Load parameters that are in temporary registers in the
  932. correct parameter register }
  933. if assigned(left) then
  934. begin
  935. pushparas;
  936. { free the resources allocated for the parameters }
  937. freeparas;
  938. end;
  939. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  940. if cg.uses_registers(R_FPUREGISTER) then
  941. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  942. if cg.uses_registers(R_MMREGISTER) then
  943. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  944. { Calling interrupt from the same code requires some
  945. extra code }
  946. if (po_interrupt in procdefinition.procoptions) then
  947. extra_interrupt_code;
  948. extra_call_code;
  949. cg.a_call_reg(current_asmdata.CurrAsmList,pvreg);
  950. extra_post_call_code;
  951. end;
  952. { Need to remove the parameters from the stack? }
  953. if (procdefinition.proccalloption in clearstack_pocalls) then
  954. begin
  955. pop_size:=pushedparasize;
  956. { for Cdecl functions we don't need to pop the funcret when it
  957. was pushed by para }
  958. if paramanager.ret_in_param(procdefinition.returndef,procdefinition.proccalloption) then
  959. dec(pop_size,sizeof(aint));
  960. { Remove parameters/alignment from the stack }
  961. pop_parasize(pop_size);
  962. end;
  963. { Release registers, but not the registers that contain the
  964. function result }
  965. if (not is_void(resultdef)) then
  966. begin
  967. case procdefinition.funcretloc[callerside].loc of
  968. LOC_REGISTER,
  969. LOC_CREGISTER:
  970. begin
  971. {$ifndef cpu64bit}
  972. if procdefinition.funcretloc[callerside].size in [OS_64,OS_S64] then
  973. begin
  974. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register64.reghi));
  975. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register64.reglo));
  976. end
  977. else
  978. {$endif cpu64bit}
  979. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register));
  980. end;
  981. LOC_FPUREGISTER,
  982. LOC_CFPUREGISTER:
  983. exclude(regs_to_save_fpu,getsupreg(procdefinition.funcretloc[callerside].register));
  984. LOC_MMREGISTER,
  985. LOC_CMMREGISTER:
  986. exclude(regs_to_save_mm,getsupreg(procdefinition.funcretloc[callerside].register));
  987. LOC_REFERENCE,
  988. LOC_VOID:
  989. ;
  990. else
  991. internalerror(2004110214);
  992. end;
  993. end;
  994. {$if defined(x86) or defined(arm)}
  995. if procdefinition.proccalloption=pocall_safecall then
  996. begin
  997. {$ifdef x86_64}
  998. cgpara.init;
  999. paramanager.getintparaloc(pocall_default,1,cgpara);
  1000. cg.a_param_reg(current_asmdata.CurrAsmList,OS_ADDR,NR_RAX,cgpara);
  1001. cgpara.done;
  1002. {$endif x86_64}
  1003. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1004. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_SAFECALLCHECK');
  1005. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1006. end;
  1007. {$endif}
  1008. if cg.uses_registers(R_MMREGISTER) then
  1009. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  1010. if cg.uses_registers(R_FPUREGISTER) then
  1011. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  1012. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  1013. { handle function results }
  1014. if (not is_void(resultdef)) then
  1015. handle_return_value
  1016. else
  1017. location_reset(location,LOC_VOID,OS_NO);
  1018. { convert persistent temps for parameters and function result to normal temps }
  1019. if assigned(callcleanupblock) then
  1020. secondpass(callcleanupblock);
  1021. { release temps and finalize unused return values, must be
  1022. after the callcleanupblock because that converts temps
  1023. from persistent to normal }
  1024. release_unused_return_value;
  1025. { release temps of paras }
  1026. release_para_temps;
  1027. { perhaps i/o check ? }
  1028. if (cs_check_io in current_settings.localswitches) and
  1029. (po_iocheck in procdefinition.procoptions) and
  1030. not(po_iocheck in current_procinfo.procdef.procoptions) and
  1031. { no IO check for methods and procedure variables }
  1032. (right=nil) and
  1033. not(po_virtualmethod in procdefinition.procoptions) then
  1034. begin
  1035. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1036. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_IOCHECK');
  1037. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1038. end;
  1039. end;
  1040. begin
  1041. ccallparanode:=tcgcallparanode;
  1042. ccallnode:=tcgcallnode;
  1043. end.