ncgcal.pas 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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. protected
  28. tempcgpara : tcgpara;
  29. procedure push_addr_para;
  30. procedure push_value_para;virtual;
  31. procedure push_formal_para;virtual;
  32. procedure push_copyout_para;virtual;abstract;
  33. public
  34. constructor create(expr,next : tnode);override;
  35. destructor destroy;override;
  36. procedure secondcallparan;override;
  37. end;
  38. { tcgcallnode }
  39. tcgcallnode = class(tcallnode)
  40. private
  41. procedure handle_return_value;
  42. procedure release_unused_return_value;
  43. procedure copy_back_paras;
  44. procedure release_para_temps;
  45. procedure reorder_parameters;
  46. procedure pushparas;
  47. procedure freeparas;
  48. protected
  49. retloc: tcgpara;
  50. framepointer_paraloc : tcgpara;
  51. {# This routine is used to push the current frame pointer
  52. on the stack. This is used in nested routines where the
  53. value of the frame pointer is always pushed as an extra
  54. parameter.
  55. The default handling is the standard handling used on
  56. most stack based machines, where the frame pointer is
  57. the first invisible parameter.
  58. }
  59. procedure pop_parasize(pop_size:longint);virtual;
  60. procedure extra_interrupt_code;virtual;
  61. procedure extra_pre_call_code;virtual;
  62. procedure extra_call_code;virtual;
  63. procedure extra_post_call_code;virtual;
  64. procedure do_syscall;virtual;abstract;
  65. { The function result is returned in a tcgpara. This tcgpara has to
  66. be translated into a tlocation so the rest of the code generator
  67. can work with it. This routine decides what the most appropriate
  68. tlocation is and sets self.location based on that. }
  69. procedure set_result_location(realresdef: tstoreddef);virtual;
  70. { if an unused return value is in another location than a
  71. LOC_REFERENCE, this method will be called to perform the necessary
  72. cleanups. By default it does not do anything }
  73. procedure do_release_unused_return_value;virtual;
  74. { Override the following three methods to support calls to address in
  75. 'ref' without loading it into register (only x86 targets probably).
  76. If can_call_ref returns true, it should do required simplification
  77. on ref. }
  78. function can_call_ref(var ref: treference):boolean;virtual;
  79. procedure extra_call_ref_code(var ref: treference);virtual;
  80. procedure do_call_ref(ref: treference);virtual;
  81. public
  82. procedure pass_generate_code;override;
  83. destructor destroy;override;
  84. end;
  85. implementation
  86. uses
  87. systems,
  88. cutils,verbose,globals,
  89. cpuinfo,
  90. symconst,symtable,symtype,defutil,paramgr,
  91. cgbase,pass_2,
  92. aasmbase,aasmtai,aasmdata,
  93. nbas,nmem,nld,ncnv,nutils,
  94. ncgutil,
  95. cgobj,tgobj,hlcgobj,
  96. procinfo,
  97. wpobase;
  98. {*****************************************************************************
  99. TCGCALLPARANODE
  100. *****************************************************************************}
  101. constructor tcgcallparanode.create(expr,next : tnode);
  102. begin
  103. inherited create(expr,next);
  104. tempcgpara.init;
  105. end;
  106. destructor tcgcallparanode.destroy;
  107. begin
  108. tempcgpara.done;
  109. inherited destroy;
  110. end;
  111. procedure tcgcallparanode.push_addr_para;
  112. begin
  113. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  114. internalerror(200304235);
  115. hlcg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location.reference,tempcgpara);
  116. end;
  117. procedure tcgcallnode.reorder_parameters;
  118. var
  119. hpcurr,hpprev,hpnext,hpreversestart : tcgcallparanode;
  120. begin
  121. { All parameters are now in temporary locations. If we move them to
  122. their regular locations in the same order, then we get the
  123. following pattern for register parameters:
  124. mov para1, tempreg1
  125. mov para2, tempreg2
  126. mov para3, tempreg3
  127. mov tempreg1, parareg1
  128. mov tempreg2, parareg2
  129. mov tempreg3, parareg3
  130. The result is that all tempregs conflict with all pararegs.
  131. A better solution is to use:
  132. mov para1, tempreg1
  133. mov para2, tempreg2
  134. mov para3, tempreg3
  135. mov tempreg3, parareg3
  136. mov tempreg2, parareg2
  137. mov tempreg1, parareg1
  138. This way, tempreg2 can be the same as parareg1 etc.
  139. To achieve this, we invert the order of all LOC_XREGISTER
  140. paras (JM).
  141. }
  142. hpcurr:=tcgcallparanode(left);
  143. { assume all LOC_REFERENCE parameters come first
  144. (see tcallnode.order_parameters)
  145. }
  146. hpreversestart:=nil;
  147. while assigned(hpcurr) do
  148. begin
  149. if not(hpcurr.parasym.paraloc[callerside].location^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  150. hpreversestart:=hpcurr;
  151. hpcurr:=tcgcallparanode(hpcurr.right);
  152. end;
  153. { since all register tempparalocs have basically a complexity of 1,
  154. (unless there are large stack offsets that require a temp register on
  155. some architectures, but that's minor), we don't have to care about
  156. the internal relative order of different register type parameters
  157. }
  158. hpprev:=nil;
  159. hpcurr:=tcgcallparanode(left);
  160. while (hpcurr<>hpreversestart) do
  161. begin
  162. hpnext:=tcgcallparanode(hpcurr.right);
  163. if not(hpcurr.parasym.paraloc[callerside].location^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  164. begin
  165. { remove hpcurr from chain }
  166. if assigned(hpprev) then
  167. hpprev.right:=hpnext
  168. else
  169. left:=hpnext;
  170. { insert right after hpreversestart, so every element will
  171. be inserted right before the previously moved one ->
  172. reverse order; hpreversestart itself is the last register
  173. parameter }
  174. hpcurr.right:=hpreversestart.right;
  175. hpreversestart.right:=hpcurr;
  176. end
  177. else
  178. hpprev:=hpcurr;
  179. hpcurr:=hpnext;
  180. end;
  181. end;
  182. procedure tcgcallparanode.push_value_para;
  183. begin
  184. { we've nothing to push when the size of the parameter is 0
  185. -- except in case of the self parameter of an emptry record on e.g.
  186. the JVM target }
  187. if (left.resultdef.size=0) and
  188. not(vo_is_self in parasym.varoptions) then
  189. exit;
  190. { Move flags and jump in register to make it less complex }
  191. if left.location.loc in [LOC_FLAGS,LOC_JUMP,LOC_SUBSETREG,LOC_CSUBSETREG,LOC_SUBSETREF,LOC_CSUBSETREF] then
  192. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  193. { load the parameter's tlocation into its cgpara }
  194. hlcg.gen_load_loc_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location,tempcgpara)
  195. end;
  196. procedure tcgcallparanode.push_formal_para;
  197. begin
  198. { allow passing of a constant to a const formaldef }
  199. if (parasym.varspez=vs_const) and
  200. (left.location.loc in [LOC_CONSTANT,LOC_REGISTER]) then
  201. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef);
  202. push_addr_para;
  203. end;
  204. procedure tcgcallparanode.secondcallparan;
  205. var
  206. href : treference;
  207. otlabel,
  208. oflabel : tasmlabel;
  209. begin
  210. if not(assigned(parasym)) then
  211. internalerror(200304242);
  212. { Skip nothingn nodes which are used after disabling
  213. a parameter }
  214. if (left.nodetype<>nothingn) then
  215. begin
  216. otlabel:=current_procinfo.CurrTrueLabel;
  217. oflabel:=current_procinfo.CurrFalseLabel;
  218. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  219. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  220. if assigned(fparainit) then
  221. secondpass(fparainit);
  222. secondpass(left);
  223. maybechangeloadnodereg(current_asmdata.CurrAsmList,left,true);
  224. { release memory for refcnt out parameters }
  225. if (parasym.varspez=vs_out) and
  226. is_managed_type(left.resultdef) and
  227. not(target_info.system in systems_garbage_collected_managed_types) then
  228. begin
  229. hlcg.location_get_data_ref(current_asmdata.CurrAsmList,left.resultdef,left.location,href,false,sizeof(pint));
  230. if is_open_array(resultdef) then
  231. begin
  232. { if elementdef is not managed, omit fpc_decref_array
  233. because it won't do anything anyway }
  234. if is_managed_type(tarraydef(resultdef).elementdef) then
  235. begin
  236. if third=nil then
  237. InternalError(201103063);
  238. secondpass(third);
  239. hlcg.g_array_rtti_helper(current_asmdata.CurrAsmList,tarraydef(resultdef).elementdef,
  240. href,third.location,'fpc_finalize_array');
  241. end;
  242. end
  243. else
  244. hlcg.g_finalize(current_asmdata.CurrAsmList,left.resultdef,href)
  245. end;
  246. paramanager.createtempparaloc(current_asmdata.CurrAsmList,aktcallnode.procdefinition.proccalloption,parasym,not followed_by_stack_tainting_call_cached,tempcgpara);
  247. { handle varargs first, because parasym is not valid }
  248. if (cpf_varargs_para in callparaflags) then
  249. begin
  250. if paramanager.push_addr_param(vs_value,left.resultdef,
  251. aktcallnode.procdefinition.proccalloption) then
  252. push_addr_para
  253. else
  254. push_value_para;
  255. end
  256. { hidden parameters }
  257. else if (vo_is_hidden_para in parasym.varoptions) then
  258. begin
  259. { don't push a node that already generated a pointer type
  260. by address for implicit hidden parameters }
  261. if (vo_is_funcret in parasym.varoptions) or
  262. { pass "this" in C++ classes explicitly as pointer
  263. because push_addr_param might not be true for them }
  264. (is_cppclass(parasym.vardef) and (vo_is_self in parasym.varoptions)) or
  265. (
  266. (
  267. not(left.resultdef.typ in [pointerdef,classrefdef]) or
  268. (
  269. { allow pointerdefs (as self) to be passed as addr
  270. param if the method is part of a type helper which
  271. extends a pointer type }
  272. (vo_is_self in parasym.varoptions) and
  273. (aktcallnode.procdefinition.owner.symtabletype=objectsymtable) and
  274. (is_objectpascal_helper(tdef(aktcallnode.procdefinition.owner.defowner))) and
  275. (tobjectdef(aktcallnode.procdefinition.owner.defowner).extendeddef.typ=pointerdef)
  276. )
  277. ) and
  278. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  279. aktcallnode.procdefinition.proccalloption)) then
  280. push_addr_para
  281. else
  282. push_value_para;
  283. end
  284. { formal def }
  285. else if (parasym.vardef.typ=formaldef) then
  286. push_formal_para
  287. { Normal parameter }
  288. else if paramanager.push_copyout_param(parasym.varspez,parasym.vardef,
  289. aktcallnode.procdefinition.proccalloption) then
  290. push_copyout_para
  291. else
  292. begin
  293. { don't push a node that already generated a pointer type
  294. by address for implicit hidden parameters }
  295. if (not(
  296. (vo_is_hidden_para in parasym.varoptions) and
  297. (left.resultdef.typ in [pointerdef,classrefdef])
  298. ) and
  299. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  300. aktcallnode.procdefinition.proccalloption)) and
  301. { dyn. arrays passed to an array of const must be passed by value, see tests/webtbs/tw4219.pp }
  302. not(
  303. is_array_of_const(parasym.vardef) and
  304. is_dynamic_array(left.resultdef)
  305. ) then
  306. begin
  307. { Passing a var parameter to a var parameter, we can
  308. just push the address transparently }
  309. if (left.nodetype=loadn) and
  310. (tloadnode(left).is_addr_param_load) then
  311. begin
  312. if (left.location.reference.index<>NR_NO) or
  313. (left.location.reference.offset<>0) then
  314. internalerror(200410107);
  315. hlcg.a_load_reg_cgpara(current_asmdata.CurrAsmList,voidpointertype,left.location.reference.base,tempcgpara)
  316. end
  317. else
  318. begin
  319. { Force to be in memory }
  320. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  321. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef);
  322. push_addr_para;
  323. end;
  324. end
  325. else
  326. push_value_para;
  327. end;
  328. current_procinfo.CurrTrueLabel:=otlabel;
  329. current_procinfo.CurrFalseLabel:=oflabel;
  330. { update return location in callnode when this is the function
  331. result }
  332. if assigned(parasym) and
  333. (
  334. { for type helper/record constructor check that it is self parameter }
  335. (
  336. (vo_is_self in parasym.varoptions) and
  337. (aktcallnode.procdefinition.proctypeoption=potype_constructor) and
  338. (parasym.vardef.typ<>objectdef)
  339. ) or
  340. (vo_is_funcret in parasym.varoptions)
  341. ) then
  342. location_copy(aktcallnode.location,left.location);
  343. end;
  344. { next parameter }
  345. if assigned(right) then
  346. tcallparanode(right).secondcallparan;
  347. end;
  348. {*****************************************************************************
  349. TCGCALLNODE
  350. *****************************************************************************}
  351. {$if first_mm_imreg = 0}
  352. {$WARN 4044 OFF} { Comparison might be always false ... }
  353. {$endif}
  354. procedure tcgcallnode.extra_interrupt_code;
  355. begin
  356. end;
  357. procedure tcgcallnode.extra_pre_call_code;
  358. begin
  359. end;
  360. procedure tcgcallnode.extra_call_code;
  361. begin
  362. end;
  363. procedure tcgcallnode.extra_post_call_code;
  364. begin
  365. end;
  366. function tcgcallnode.can_call_ref(var ref: treference): boolean;
  367. begin
  368. result:=false;
  369. end;
  370. procedure tcgcallnode.extra_call_ref_code(var ref: treference);
  371. begin
  372. { no action by default }
  373. end;
  374. procedure tcgcallnode.do_call_ref(ref: treference);
  375. begin
  376. InternalError(2014012901);
  377. end;
  378. procedure tcgcallnode.set_result_location(realresdef: tstoreddef);
  379. begin
  380. if realresdef.is_intregable or
  381. realresdef.is_fpuregable or
  382. { avoid temporarily storing pointer-sized entities that can't be
  383. regvars, such as reference-counted pointers, to memory --
  384. no exception can occur right now (except in case of existing
  385. memory corruption), and we'd store them to a regular temp
  386. anyway and that is not safer than keeping them in a register }
  387. ((realresdef.size=sizeof(aint)) and
  388. (retloc.location^.loc=LOC_REGISTER) and
  389. not assigned(retloc.location^.next)) then
  390. location_allocate_register(current_asmdata.CurrAsmList,location,realresdef,false)
  391. else
  392. begin
  393. location_reset_ref(location,LOC_REFERENCE,def_cgsize(realresdef),0);
  394. tg.gethltemp(current_asmdata.CurrAsmList,realresdef,retloc.intsize,tt_normal,location.reference);
  395. end;
  396. end;
  397. procedure tcgcallnode.do_release_unused_return_value;
  398. begin
  399. case location.loc of
  400. LOC_REFERENCE :
  401. begin
  402. if is_managed_type(resultdef) then
  403. hlcg.g_finalize(current_asmdata.CurrAsmList,resultdef,location.reference);
  404. tg.ungetiftemp(current_asmdata.CurrAsmList,location.reference);
  405. end;
  406. end;
  407. end;
  408. procedure tcgcallnode.pop_parasize(pop_size:longint);
  409. begin
  410. end;
  411. procedure tcgcallnode.handle_return_value;
  412. var
  413. realresdef: tstoreddef;
  414. begin
  415. { Check that the return location is set when the result is passed in
  416. a parameter }
  417. if paramanager.ret_in_param(resultdef,procdefinition) then
  418. begin
  419. { self.location is set near the end of secondcallparan so it
  420. refers to the implicit result parameter }
  421. if location.loc<>LOC_REFERENCE then
  422. internalerror(200304241);
  423. exit;
  424. end;
  425. if not assigned(typedef) then
  426. realresdef:=tstoreddef(resultdef)
  427. else
  428. realresdef:=tstoreddef(typedef);
  429. { get a tlocation that can hold the return value that's currently in
  430. the return value's tcgpara }
  431. set_result_location(realresdef);
  432. { Do not move the physical register to a virtual one in case
  433. the return value is not used, because if the virtual one is
  434. then mapped to the same register as the physical one, we will
  435. end up with two deallocs of this register (one inserted here,
  436. one inserted by the register allocator), which unbalances the
  437. register allocation information. The return register(s) will
  438. be freed by location_free() in release_unused_return_value
  439. (mantis #13536). }
  440. if (cnf_return_value_used in callnodeflags) or
  441. assigned(funcretnode) then
  442. hlcg.gen_load_cgpara_loc(current_asmdata.CurrAsmList,realresdef,retloc,location,false);
  443. { copy value to the final location if this was already provided to the
  444. callnode. This must be done after the call node, because the location can
  445. also be used as parameter and may not be finalized yet }
  446. if assigned(funcretnode) then
  447. begin
  448. funcretnode.pass_generate_code;
  449. { Decrease refcount for refcounted types, this can be skipped when
  450. we have used a temp, because then it is already done from tempcreatenode.
  451. Also no finalize is needed, because there is no risk of exceptions from the
  452. function since this is code is only executed after the function call has returned }
  453. if is_managed_type(funcretnode.resultdef) and
  454. (funcretnode.nodetype<>temprefn) then
  455. hlcg.g_finalize(current_asmdata.CurrAsmList,funcretnode.resultdef,funcretnode.location.reference);
  456. case location.loc of
  457. LOC_REGISTER :
  458. begin
  459. {$ifndef cpu64bitalu}
  460. if location.size in [OS_64,OS_S64] then
  461. cg64.a_load64_reg_loc(current_asmdata.CurrAsmList,location.register64,funcretnode.location)
  462. else
  463. {$endif}
  464. hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,resultdef,resultdef,location.register,funcretnode.location);
  465. location_free(current_asmdata.CurrAsmList,location);
  466. end;
  467. LOC_REFERENCE:
  468. begin
  469. case funcretnode.location.loc of
  470. LOC_REGISTER:
  471. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,resultdef,resultdef,location.reference,funcretnode.location.register);
  472. LOC_REFERENCE:
  473. hlcg.g_concatcopy(current_asmdata.CurrAsmList,resultdef,location.reference,funcretnode.location.reference);
  474. else
  475. internalerror(200802121);
  476. end;
  477. location_freetemp(current_asmdata.CurrAsmList,location);
  478. end;
  479. else
  480. internalerror(200709085);
  481. end;
  482. location := funcretnode.location;
  483. end;
  484. end;
  485. procedure tcgcallnode.release_unused_return_value;
  486. begin
  487. { When the result is not used we need to finalize the result and
  488. can release the temp. This need to be after the callcleanupblock
  489. tree is generated, because that converts the temp from persistent to normal }
  490. if not(cnf_return_value_used in callnodeflags) then
  491. begin
  492. do_release_unused_return_value;
  493. if (retloc.intsize<>0) then
  494. paramanager.freecgpara(current_asmdata.CurrAsmList,retloc);
  495. location_reset(location,LOC_VOID,OS_NO);
  496. end;
  497. end;
  498. procedure tcgcallnode.copy_back_paras;
  499. var
  500. ppn : tcallparanode;
  501. begin
  502. ppn:=tcallparanode(left);
  503. while assigned(ppn) do
  504. begin
  505. if assigned(ppn.paracopyback) then
  506. secondpass(ppn.paracopyback);
  507. ppn:=tcallparanode(ppn.right);
  508. end;
  509. end;
  510. procedure tcgcallnode.release_para_temps;
  511. var
  512. hp,
  513. hp2 : tnode;
  514. ppn : tcallparanode;
  515. begin
  516. { Release temps from parameters }
  517. ppn:=tcallparanode(left);
  518. while assigned(ppn) do
  519. begin
  520. if assigned(ppn.left) then
  521. begin
  522. { don't release the funcret temp }
  523. if not(assigned(ppn.parasym)) or
  524. not(vo_is_funcret in ppn.parasym.varoptions) then
  525. location_freetemp(current_asmdata.CurrAsmList,ppn.left.location);
  526. { process also all nodes of an array of const }
  527. hp:=ppn.left;
  528. while (hp.nodetype=typeconvn) do
  529. hp:=ttypeconvnode(hp).left;
  530. if (hp.nodetype=arrayconstructorn) and
  531. assigned(tarrayconstructornode(hp).left) then
  532. begin
  533. while assigned(hp) do
  534. begin
  535. hp2:=tarrayconstructornode(hp).left;
  536. { ignore typeconvs and addrn inserted by arrayconstructn for
  537. passing a shortstring }
  538. if (hp2.nodetype=typeconvn) and
  539. (tunarynode(hp2).left.nodetype=addrn) then
  540. hp2:=tunarynode(tunarynode(hp2).left).left
  541. else if hp2.nodetype=addrn then
  542. hp2:=tunarynode(hp2).left;
  543. location_freetemp(current_asmdata.CurrAsmList,hp2.location);
  544. hp:=tarrayconstructornode(hp).right;
  545. end;
  546. end;
  547. end;
  548. ppn:=tcallparanode(ppn.right);
  549. end;
  550. end;
  551. procedure tcgcallnode.pushparas;
  552. var
  553. ppn : tcgcallparanode;
  554. callerparaloc,
  555. tmpparaloc : pcgparalocation;
  556. sizeleft: aint;
  557. htempref,
  558. href : treference;
  559. calleralignment,
  560. tmpalignment: longint;
  561. skipiffinalloc: boolean;
  562. begin
  563. { copy all resources to the allocated registers }
  564. ppn:=tcgcallparanode(left);
  565. while assigned(ppn) do
  566. begin
  567. if (ppn.left.nodetype<>nothingn) then
  568. begin
  569. { better check for the real location of the parameter here, when stack passed parameters
  570. are saved temporary in registers, checking for the tmpparaloc.loc is wrong
  571. }
  572. paramanager.freecgpara(current_asmdata.CurrAsmList,ppn.tempcgpara);
  573. tmpparaloc:=ppn.tempcgpara.location;
  574. sizeleft:=ppn.tempcgpara.intsize;
  575. calleralignment:=ppn.parasym.paraloc[callerside].alignment;
  576. tmpalignment:=ppn.tempcgpara.alignment;
  577. if (tmpalignment=0) or
  578. (calleralignment=0) then
  579. internalerror(2009020701);
  580. callerparaloc:=ppn.parasym.paraloc[callerside].location;
  581. skipiffinalloc:=
  582. not paramanager.use_fixed_stack or
  583. not(ppn.followed_by_stack_tainting_call_cached);
  584. while assigned(callerparaloc) do
  585. begin
  586. { Every paraloc must have a matching tmpparaloc }
  587. if not assigned(tmpparaloc) then
  588. internalerror(200408224);
  589. if callerparaloc^.size<>tmpparaloc^.size then
  590. internalerror(200408225);
  591. case callerparaloc^.loc of
  592. LOC_REGISTER:
  593. begin
  594. if tmpparaloc^.loc<>LOC_REGISTER then
  595. internalerror(200408221);
  596. if getsupreg(callerparaloc^.register)<first_int_imreg then
  597. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  598. cg.a_load_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  599. tmpparaloc^.register,callerparaloc^.register);
  600. end;
  601. LOC_FPUREGISTER:
  602. begin
  603. if tmpparaloc^.loc<>LOC_FPUREGISTER then
  604. internalerror(200408222);
  605. if getsupreg(callerparaloc^.register)<first_fpu_imreg then
  606. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  607. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,ppn.tempcgpara.size,tmpparaloc^.register,callerparaloc^.register);
  608. end;
  609. LOC_MMREGISTER:
  610. begin
  611. if tmpparaloc^.loc<>LOC_MMREGISTER then
  612. internalerror(200408223);
  613. if getsupreg(callerparaloc^.register)<first_mm_imreg then
  614. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  615. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  616. tmpparaloc^.register,callerparaloc^.register,mms_movescalar);
  617. end;
  618. LOC_REFERENCE:
  619. begin
  620. if not(skipiffinalloc and
  621. paramanager.is_stack_paraloc(callerparaloc)) then
  622. begin
  623. { Can't have a data copied to the stack, every location
  624. must contain a valid size field }
  625. if (tmpparaloc^.size=OS_NO) and
  626. ((tmpparaloc^.loc<>LOC_REFERENCE) or
  627. assigned(tmpparaloc^.next)) then
  628. internalerror(200501281);
  629. reference_reset_base(href,callerparaloc^.reference.index,callerparaloc^.reference.offset,calleralignment);
  630. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  631. case tmpparaloc^.loc of
  632. LOC_REFERENCE:
  633. begin
  634. reference_reset_base(htempref,tmpparaloc^.reference.index,tmpparaloc^.reference.offset,tmpalignment);
  635. { use concatcopy, because it can also be a float which fails when
  636. load_ref_ref is used }
  637. if (ppn.tempcgpara.size <> OS_NO) then
  638. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,tcgsize2size[tmpparaloc^.size])
  639. else
  640. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,sizeleft)
  641. end;
  642. LOC_REGISTER:
  643. cg.a_load_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  644. LOC_FPUREGISTER:
  645. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  646. LOC_MMREGISTER:
  647. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href,mms_movescalar);
  648. else
  649. internalerror(200402081);
  650. end;
  651. end;
  652. end;
  653. end;
  654. dec(sizeleft,tcgsize2size[tmpparaloc^.size]);
  655. callerparaloc:=callerparaloc^.next;
  656. tmpparaloc:=tmpparaloc^.next;
  657. end;
  658. end;
  659. ppn:=tcgcallparanode(ppn.right);
  660. end;
  661. end;
  662. procedure tcgcallnode.freeparas;
  663. var
  664. ppn : tcgcallparanode;
  665. begin
  666. { free the resources allocated for the parameters }
  667. ppn:=tcgcallparanode(left);
  668. while assigned(ppn) do
  669. begin
  670. if (ppn.left.nodetype<>nothingn) then
  671. begin
  672. if (ppn.parasym.paraloc[callerside].location^.loc <> LOC_REFERENCE) then
  673. paramanager.freecgpara(current_asmdata.CurrAsmList,ppn.parasym.paraloc[callerside]);
  674. end;
  675. ppn:=tcgcallparanode(ppn.right);
  676. end;
  677. end;
  678. procedure tcgcallnode.pass_generate_code;
  679. var
  680. name_to_call: shortstring;
  681. regs_to_save_int,
  682. regs_to_save_address,
  683. regs_to_save_fpu,
  684. regs_to_save_mm : Tcpuregisterset;
  685. href : treference;
  686. pop_size : longint;
  687. vmtoffset : aint;
  688. pvreg,
  689. vmtreg : tregister;
  690. oldaktcallnode : tcallnode;
  691. retlocitem: pcgparalocation;
  692. pd : tprocdef;
  693. proc_addr_size: TCgSize;
  694. proc_addr_voidptrdef: tdef;
  695. callref: boolean;
  696. {$ifdef vtentry}
  697. sym : tasmsymbol;
  698. {$endif vtentry}
  699. {$ifdef SUPPORT_SAFECALL}
  700. cgpara : tcgpara;
  701. {$endif}
  702. begin
  703. if not assigned(procdefinition) or
  704. not(procdefinition.has_paraloc_info in [callerside,callbothsides]) then
  705. internalerror(200305264);
  706. extra_pre_call_code;
  707. if assigned(callinitblock) then
  708. secondpass(tnode(callinitblock));
  709. regs_to_save_int:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  710. regs_to_save_address:=paramanager.get_volatile_registers_address(procdefinition.proccalloption);
  711. regs_to_save_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  712. regs_to_save_mm:=paramanager.get_volatile_registers_mm(procdefinition.proccalloption);
  713. proc_addr_voidptrdef:=procdefinition.address_type;
  714. proc_addr_size:=def_cgsize(proc_addr_voidptrdef);
  715. { Include Function result registers }
  716. if (not is_void(resultdef)) then
  717. begin
  718. { The forced returntype may have a different size than the one
  719. declared for the procdef }
  720. if not assigned(typedef) then
  721. retloc:=procdefinition.funcretloc[callerside]
  722. else
  723. retloc:=paramanager.get_funcretloc(procdefinition,callerside,typedef);
  724. retlocitem:=retloc.location;
  725. while assigned(retlocitem) do
  726. begin
  727. case retlocitem^.loc of
  728. LOC_REGISTER:
  729. include(regs_to_save_int,getsupreg(retlocitem^.register));
  730. LOC_FPUREGISTER:
  731. include(regs_to_save_fpu,getsupreg(retlocitem^.register));
  732. LOC_MMREGISTER:
  733. include(regs_to_save_mm,getsupreg(retlocitem^.register));
  734. LOC_REFERENCE,
  735. LOC_VOID:
  736. ;
  737. else
  738. internalerror(2004110213);
  739. end;
  740. retlocitem:=retlocitem^.next;
  741. end;
  742. end;
  743. { Process parameters, register parameters will be loaded
  744. in imaginary registers. The actual load to the correct
  745. register is done just before the call }
  746. oldaktcallnode:=aktcallnode;
  747. aktcallnode:=self;
  748. if assigned(left) then
  749. tcallparanode(left).secondcallparan;
  750. aktcallnode:=oldaktcallnode;
  751. { procedure variable or normal function call ? }
  752. if (right=nil) then
  753. begin
  754. { register call for WPO (must be done before wpo test below,
  755. otherwise optimised called methods are no longer registered)
  756. }
  757. if (po_virtualmethod in procdefinition.procoptions) and
  758. not is_objectpascal_helper(tprocdef(procdefinition).struct) and
  759. assigned(methodpointer) and
  760. (methodpointer.nodetype<>typen) and
  761. (not assigned(current_procinfo) or
  762. wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname)) then
  763. tobjectdef(tprocdef(procdefinition).struct).register_vmt_call(tprocdef(procdefinition).extnumber);
  764. {$ifdef vtentry}
  765. if not is_interface(tprocdef(procdefinition)._class) then
  766. begin
  767. inc(current_asmdata.NextVTEntryNr);
  768. current_asmdata.CurrAsmList.Concat(tai_symbol.CreateName('VTREF'+tostr(current_asmdata.NextVTEntryNr)+'_'+tprocdef(procdefinition).struct.vmt_mangledname+'$$'+tostr(vmtoffset div sizeof(pint)),AT_FUNCTION,0));
  769. end;
  770. {$endif vtentry}
  771. name_to_call:='';
  772. if assigned(fobjcforcedprocname) then
  773. name_to_call:=fobjcforcedprocname^;
  774. { in the JVM, virtual method calls are also name-based }
  775. {$ifndef jvm}
  776. { When methodpointer is typen we don't need (and can't) load
  777. a pointer. We can directly call the correct procdef (PFV) }
  778. if (name_to_call='') and
  779. (po_virtualmethod in procdefinition.procoptions) and
  780. not is_objectpascal_helper(tprocdef(procdefinition).struct) and
  781. assigned(methodpointer) and
  782. (methodpointer.nodetype<>typen) and
  783. not wpoinfomanager.can_be_devirtualized(methodpointer.resultdef,procdefinition,name_to_call) then
  784. begin
  785. { virtual methods require an index }
  786. if tprocdef(procdefinition).extnumber=$ffff then
  787. internalerror(200304021);
  788. secondpass(methodpointer);
  789. { Load VMT from self }
  790. if methodpointer.resultdef.typ=objectdef then
  791. gen_load_vmt_register(current_asmdata.CurrAsmList,tobjectdef(methodpointer.resultdef),methodpointer.location,vmtreg)
  792. else
  793. begin
  794. { Load VMT value in register }
  795. { todo: fix vmt type for high level cg }
  796. hlcg.location_force_reg(current_asmdata.CurrAsmList,methodpointer.location,proc_addr_voidptrdef,proc_addr_voidptrdef,false);
  797. vmtreg:=methodpointer.location.register;
  798. { test validity of VMT }
  799. if not(is_interface(tprocdef(procdefinition).struct)) and
  800. not(is_cppclass(tprocdef(procdefinition).struct)) then
  801. cg.g_maybe_testvmt(current_asmdata.CurrAsmList,vmtreg,tobjectdef(tprocdef(procdefinition).struct));
  802. end;
  803. { Call through VMT, generate a VTREF symbol to notify the linker }
  804. vmtoffset:=tobjectdef(tprocdef(procdefinition).struct).vmtmethodoffset(tprocdef(procdefinition).extnumber);
  805. { register call for WPO }
  806. if (not assigned(current_procinfo) or
  807. wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname)) then
  808. tobjectdef(tprocdef(procdefinition).struct).register_vmt_call(tprocdef(procdefinition).extnumber);
  809. reference_reset_base(href,vmtreg,vmtoffset,proc_addr_voidptrdef.alignment);
  810. pvreg:=NR_NO;
  811. callref:=can_call_ref(href);
  812. if not callref then
  813. begin
  814. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,proc_addr_size);
  815. cg.a_load_ref_reg(current_asmdata.CurrAsmList,proc_addr_size,proc_addr_size,href,pvreg);
  816. end;
  817. { Load parameters that are in temporary registers in the
  818. correct parameter register }
  819. if assigned(left) then
  820. begin
  821. reorder_parameters;
  822. pushparas;
  823. { free the resources allocated for the parameters }
  824. freeparas;
  825. end;
  826. if callref then
  827. extra_call_ref_code(href);
  828. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  829. if cg.uses_registers(R_ADDRESSREGISTER) then
  830. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  831. if cg.uses_registers(R_FPUREGISTER) then
  832. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  833. if cg.uses_registers(R_MMREGISTER) then
  834. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  835. { call method }
  836. extra_call_code;
  837. if callref then
  838. do_call_ref(href)
  839. else
  840. hlcg.a_call_reg(current_asmdata.CurrAsmList,tabstractprocdef(procdefinition),pvreg);
  841. extra_post_call_code;
  842. end
  843. else
  844. {$endif jvm}
  845. begin
  846. { Load parameters that are in temporary registers in the
  847. correct parameter register }
  848. if assigned(left) then
  849. begin
  850. reorder_parameters;
  851. pushparas;
  852. { free the resources allocated for the parameters }
  853. freeparas;
  854. end;
  855. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  856. if cg.uses_registers(R_ADDRESSREGISTER) then
  857. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  858. if cg.uses_registers(R_FPUREGISTER) then
  859. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  860. if cg.uses_registers(R_MMREGISTER) then
  861. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  862. if procdefinition.proccalloption=pocall_syscall then
  863. do_syscall
  864. else
  865. begin
  866. { Calling interrupt from the same code requires some
  867. extra code }
  868. if (po_interrupt in procdefinition.procoptions) then
  869. extra_interrupt_code;
  870. extra_call_code;
  871. if (name_to_call='') then
  872. if cnf_inherited in callnodeflags then
  873. hlcg.a_call_name_inherited(current_asmdata.CurrAsmList,tprocdef(procdefinition),tprocdef(procdefinition).mangledname)
  874. else
  875. hlcg.a_call_name(current_asmdata.CurrAsmList,tprocdef(procdefinition),tprocdef(procdefinition).mangledname,typedef,po_weakexternal in procdefinition.procoptions).resetiftemp
  876. else
  877. hlcg.a_call_name(current_asmdata.CurrAsmList,tprocdef(procdefinition),name_to_call,typedef,po_weakexternal in procdefinition.procoptions).resetiftemp;
  878. extra_post_call_code;
  879. end;
  880. end;
  881. end
  882. else
  883. { now procedure variable case }
  884. begin
  885. secondpass(right);
  886. callref:=false;
  887. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,proc_addr_size);
  888. { Only load OS_ADDR from the reference (when converting to hlcg:
  889. watch out with procedure of object) }
  890. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  891. begin
  892. href:=right.location.reference;
  893. callref:=can_call_ref(href);
  894. if not callref then
  895. cg.a_load_ref_reg(current_asmdata.CurrAsmList,proc_addr_size,proc_addr_size,right.location.reference,pvreg)
  896. end
  897. else if right.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  898. begin
  899. { in case left is a method pointer and we are on a big endian target, then
  900. the method address is stored in registerhi }
  901. if (target_info.endian=endian_big) and (right.location.size in [OS_PAIR,OS_SPAIR]) then
  902. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,proc_addr_voidptrdef,proc_addr_voidptrdef,right.location.registerhi,pvreg)
  903. else
  904. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,proc_addr_voidptrdef,proc_addr_voidptrdef,right.location.register,pvreg);
  905. end
  906. else
  907. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,proc_addr_voidptrdef,proc_addr_voidptrdef,right.location,pvreg);
  908. location_freetemp(current_asmdata.CurrAsmList,right.location);
  909. { Load parameters that are in temporary registers in the
  910. correct parameter register }
  911. if assigned(left) then
  912. begin
  913. pushparas;
  914. { free the resources allocated for the parameters }
  915. freeparas;
  916. end;
  917. if callref then
  918. extra_call_ref_code(href);
  919. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  920. if cg.uses_registers(R_ADDRESSREGISTER) then
  921. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  922. if cg.uses_registers(R_FPUREGISTER) then
  923. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  924. if cg.uses_registers(R_MMREGISTER) then
  925. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  926. { Calling interrupt from the same code requires some
  927. extra code }
  928. if (po_interrupt in procdefinition.procoptions) then
  929. extra_interrupt_code;
  930. extra_call_code;
  931. if callref then
  932. do_call_ref(href)
  933. else
  934. hlcg.a_call_reg(current_asmdata.CurrAsmList,procdefinition,pvreg);
  935. extra_post_call_code;
  936. end;
  937. { Need to remove the parameters from the stack? }
  938. if (procdefinition.proccalloption in clearstack_pocalls) then
  939. begin
  940. pop_size:=pushedparasize;
  941. { for Cdecl functions we don't need to pop the funcret when it
  942. was pushed by para. Except for safecall functions with
  943. safecall-exceptions enabled. In that case the funcret is always
  944. returned as a para which is considered a normal para on the
  945. c-side, so the funcret has to be pop'ed normally. }
  946. if not ((procdefinition.proccalloption=pocall_safecall) and
  947. (tf_safecall_exceptions in target_info.flags)) and
  948. paramanager.ret_in_param(procdefinition.returndef,procdefinition) then
  949. dec(pop_size,sizeof(pint));
  950. { Remove parameters/alignment from the stack }
  951. pop_parasize(pop_size);
  952. end
  953. { frame pointer parameter is popped by the caller when it's passed the
  954. Delphi way }
  955. else if (po_delphi_nested_cc in procdefinition.procoptions) and
  956. not paramanager.use_fixed_stack then
  957. pop_parasize(sizeof(pint));
  958. { Release registers, but not the registers that contain the
  959. function result }
  960. if (not is_void(resultdef)) then
  961. begin
  962. retlocitem:=retloc.location;
  963. while assigned(retlocitem) do
  964. begin
  965. case retlocitem^.loc of
  966. LOC_REGISTER:
  967. if getregtype(retlocitem^.register)=R_INTREGISTER then
  968. exclude(regs_to_save_int,getsupreg(retlocitem^.register))
  969. else
  970. exclude(regs_to_save_address,getsupreg(retlocitem^.register));
  971. LOC_FPUREGISTER:
  972. exclude(regs_to_save_fpu,getsupreg(retlocitem^.register));
  973. LOC_MMREGISTER:
  974. exclude(regs_to_save_mm,getsupreg(retlocitem^.register));
  975. LOC_REFERENCE,
  976. LOC_VOID:
  977. ;
  978. else
  979. internalerror(2004110214);
  980. end;
  981. retlocitem:=retlocitem^.next;
  982. end;
  983. end;
  984. if cg.uses_registers(R_MMREGISTER) then
  985. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  986. if cg.uses_registers(R_FPUREGISTER) then
  987. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  988. if cg.uses_registers(R_ADDRESSREGISTER) then
  989. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  990. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  991. {$ifdef SUPPORT_SAFECALL}
  992. if (procdefinition.proccalloption=pocall_safecall) and
  993. (tf_safecall_exceptions in target_info.flags) then
  994. begin
  995. pd:=search_system_proc('fpc_safecallcheck');
  996. cgpara.init;
  997. paramanager.getintparaloc(pd,1,cgpara);
  998. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_INT,NR_FUNCTION_RESULT_REG,cgpara);
  999. paramanager.freecgpara(current_asmdata.CurrAsmList,cgpara);
  1000. cg.g_call(current_asmdata.CurrAsmList,'FPC_SAFECALLCHECK');
  1001. cgpara.done;
  1002. end;
  1003. {$endif}
  1004. { handle function results }
  1005. if (not is_void(resultdef)) then
  1006. handle_return_value
  1007. else
  1008. location_reset(location,LOC_VOID,OS_NO);
  1009. { convert persistent temps for parameters and function result to normal temps }
  1010. if assigned(callcleanupblock) then
  1011. secondpass(tnode(callcleanupblock));
  1012. { copy back copy-out parameters if any }
  1013. copy_back_paras;
  1014. { release temps and finalize unused return values, must be
  1015. after the callcleanupblock because that converts temps
  1016. from persistent to normal }
  1017. release_unused_return_value;
  1018. { release temps of paras }
  1019. release_para_temps;
  1020. { perhaps i/o check ? }
  1021. if (cs_check_io in current_settings.localswitches) and
  1022. (po_iocheck in procdefinition.procoptions) and
  1023. not(po_iocheck in current_procinfo.procdef.procoptions) and
  1024. { no IO check for methods and procedure variables }
  1025. (right=nil) and
  1026. not(po_virtualmethod in procdefinition.procoptions) then
  1027. begin
  1028. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1029. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_IOCHECK',false);
  1030. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1031. end;
  1032. end;
  1033. destructor tcgcallnode.destroy;
  1034. begin
  1035. retloc.resetiftemp;
  1036. inherited destroy;
  1037. end;
  1038. begin
  1039. ccallparanode:=tcgcallparanode;
  1040. ccallnode:=tcgcallnode;
  1041. end.