ncgcal.pas 50 KB

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