ncgcal.pas 50 KB

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