ncgcal.pas 50 KB

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