ncgcal.pas 50 KB

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