ncgcal.pas 50 KB

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