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 (vo_is_weakref in parasym.varoptions) 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. if (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)) then
  282. push_addr_para
  283. else
  284. push_value_para;
  285. end
  286. { formal def }
  287. else if (parasym.vardef.typ=formaldef) then
  288. push_formal_para
  289. { Normal parameter }
  290. else if paramanager.push_copyout_param(parasym.varspez,parasym.vardef,
  291. aktcallnode.procdefinition.proccalloption) then
  292. push_copyout_para
  293. else
  294. begin
  295. { don't push a node that already generated a pointer type
  296. by address for implicit hidden parameters }
  297. if (not(
  298. (vo_is_hidden_para in parasym.varoptions) and
  299. (left.resultdef.typ in [pointerdef,classrefdef])
  300. ) and
  301. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  302. aktcallnode.procdefinition.proccalloption)) and
  303. { dyn. arrays passed to an array of const must be passed by value, see tests/webtbs/tw4219.pp }
  304. not(
  305. is_array_of_const(parasym.vardef) and
  306. is_dynamic_array(left.resultdef)
  307. ) then
  308. begin
  309. { Passing a var parameter to a var parameter, we can
  310. just push the address transparently }
  311. if (left.nodetype=loadn) and
  312. (tloadnode(left).is_addr_param_load) then
  313. begin
  314. if (left.location.reference.index<>NR_NO) or
  315. (left.location.reference.offset<>0) then
  316. internalerror(200410107);
  317. hlcg.a_load_reg_cgpara(current_asmdata.CurrAsmList,voidpointertype,left.location.reference.base,tempcgpara)
  318. end
  319. else
  320. begin
  321. { Force to be in memory }
  322. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  323. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef);
  324. push_addr_para;
  325. end;
  326. end
  327. else
  328. push_value_para;
  329. end;
  330. current_procinfo.CurrTrueLabel:=otlabel;
  331. current_procinfo.CurrFalseLabel:=oflabel;
  332. { update return location in callnode when this is the function
  333. result }
  334. if assigned(parasym) and
  335. (
  336. { for type helper/record constructor check that it is self parameter }
  337. (
  338. (vo_is_self in parasym.varoptions) and
  339. (aktcallnode.procdefinition.proctypeoption=potype_constructor) and
  340. (parasym.vardef.typ<>objectdef)
  341. ) or
  342. (vo_is_funcret in parasym.varoptions)
  343. ) then
  344. location_copy(aktcallnode.location,left.location);
  345. end;
  346. { next parameter }
  347. if assigned(right) then
  348. tcallparanode(right).secondcallparan;
  349. end;
  350. {*****************************************************************************
  351. TCGCALLNODE
  352. *****************************************************************************}
  353. {$if first_mm_imreg = 0}
  354. {$WARN 4044 OFF} { Comparison might be always false ... }
  355. {$endif}
  356. procedure tcgcallnode.extra_interrupt_code;
  357. begin
  358. end;
  359. procedure tcgcallnode.extra_pre_call_code;
  360. begin
  361. end;
  362. procedure tcgcallnode.extra_call_code;
  363. begin
  364. end;
  365. procedure tcgcallnode.extra_post_call_code;
  366. begin
  367. end;
  368. function tcgcallnode.can_call_ref(var ref: treference): boolean;
  369. begin
  370. result:=false;
  371. end;
  372. procedure tcgcallnode.extra_call_ref_code(var ref: treference);
  373. begin
  374. { no action by default }
  375. end;
  376. procedure tcgcallnode.do_call_ref(ref: treference);
  377. begin
  378. InternalError(2014012901);
  379. end;
  380. procedure tcgcallnode.set_result_location(realresdef: tstoreddef);
  381. begin
  382. if realresdef.is_intregable or
  383. realresdef.is_fpuregable or
  384. { avoid temporarily storing pointer-sized entities that can't be
  385. regvars, such as reference-counted pointers, to memory --
  386. no exception can occur right now (except in case of existing
  387. memory corruption), and we'd store them to a regular temp
  388. anyway and that is not safer than keeping them in a register }
  389. ((realresdef.size=sizeof(aint)) and
  390. (retloc.location^.loc=LOC_REGISTER) and
  391. not assigned(retloc.location^.next)) then
  392. location_allocate_register(current_asmdata.CurrAsmList,location,realresdef,false)
  393. else
  394. begin
  395. location_reset_ref(location,LOC_REFERENCE,def_cgsize(realresdef),0);
  396. tg.gethltemp(current_asmdata.CurrAsmList,realresdef,retloc.intsize,tt_normal,location.reference);
  397. end;
  398. end;
  399. procedure tcgcallnode.do_release_unused_return_value;
  400. begin
  401. case location.loc of
  402. LOC_REFERENCE :
  403. begin
  404. if is_managed_type(resultdef) then
  405. hlcg.g_finalize(current_asmdata.CurrAsmList,resultdef,location.reference);
  406. tg.ungetiftemp(current_asmdata.CurrAsmList,location.reference);
  407. end;
  408. end;
  409. end;
  410. procedure tcgcallnode.pop_parasize(pop_size:longint);
  411. begin
  412. end;
  413. procedure tcgcallnode.handle_return_value;
  414. var
  415. realresdef: tstoreddef;
  416. begin
  417. { Check that the return location is set when the result is passed in
  418. a parameter }
  419. if paramanager.ret_in_param(resultdef,procdefinition) then
  420. begin
  421. { self.location is set near the end of secondcallparan so it
  422. refers to the implicit result parameter }
  423. if location.loc<>LOC_REFERENCE then
  424. internalerror(200304241);
  425. exit;
  426. end;
  427. if not assigned(typedef) then
  428. realresdef:=tstoreddef(resultdef)
  429. else
  430. realresdef:=tstoreddef(typedef);
  431. { get a tlocation that can hold the return value that's currently in
  432. the return value's tcgpara }
  433. set_result_location(realresdef);
  434. { Do not move the physical register to a virtual one in case
  435. the return value is not used, because if the virtual one is
  436. then mapped to the same register as the physical one, we will
  437. end up with two deallocs of this register (one inserted here,
  438. one inserted by the register allocator), which unbalances the
  439. register allocation information. The return register(s) will
  440. be freed by location_free() in release_unused_return_value
  441. (mantis #13536). }
  442. if (cnf_return_value_used in callnodeflags) or
  443. assigned(funcretnode) then
  444. hlcg.gen_load_cgpara_loc(current_asmdata.CurrAsmList,realresdef,retloc,location,false);
  445. { copy value to the final location if this was already provided to the
  446. callnode. This must be done after the call node, because the location can
  447. also be used as parameter and may not be finalized yet }
  448. if assigned(funcretnode) then
  449. begin
  450. funcretnode.pass_generate_code;
  451. { Decrease refcount for refcounted types, this can be skipped when
  452. we have used a temp, because then it is already done from tempcreatenode.
  453. Also no finalize is needed, because there is no risk of exceptions from the
  454. function since this is code is only executed after the function call has returned }
  455. if is_managed_type(funcretnode.resultdef) and
  456. (funcretnode.nodetype<>temprefn) then
  457. hlcg.g_finalize(current_asmdata.CurrAsmList,funcretnode.resultdef,funcretnode.location.reference);
  458. case location.loc of
  459. LOC_REGISTER :
  460. begin
  461. {$ifndef cpu64bitalu}
  462. if location.size in [OS_64,OS_S64] then
  463. cg64.a_load64_reg_loc(current_asmdata.CurrAsmList,location.register64,funcretnode.location)
  464. else
  465. {$endif}
  466. hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,resultdef,resultdef,location.register,funcretnode.location);
  467. location_free(current_asmdata.CurrAsmList,location);
  468. end;
  469. LOC_REFERENCE:
  470. begin
  471. case funcretnode.location.loc of
  472. LOC_REGISTER:
  473. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,resultdef,resultdef,location.reference,funcretnode.location.register);
  474. LOC_REFERENCE:
  475. hlcg.g_concatcopy(current_asmdata.CurrAsmList,resultdef,location.reference,funcretnode.location.reference);
  476. else
  477. internalerror(200802121);
  478. end;
  479. location_freetemp(current_asmdata.CurrAsmList,location);
  480. end;
  481. else
  482. internalerror(200709085);
  483. end;
  484. location := funcretnode.location;
  485. end;
  486. end;
  487. procedure tcgcallnode.release_unused_return_value;
  488. begin
  489. { When the result is not used we need to finalize the result and
  490. can release the temp. This need to be after the callcleanupblock
  491. tree is generated, because that converts the temp from persistent to normal }
  492. if not(cnf_return_value_used in callnodeflags) then
  493. begin
  494. do_release_unused_return_value;
  495. if (retloc.intsize<>0) then
  496. paramanager.freecgpara(current_asmdata.CurrAsmList,retloc);
  497. location_reset(location,LOC_VOID,OS_NO);
  498. end;
  499. end;
  500. procedure tcgcallnode.copy_back_paras;
  501. var
  502. ppn : tcallparanode;
  503. begin
  504. ppn:=tcallparanode(left);
  505. while assigned(ppn) do
  506. begin
  507. if assigned(ppn.paracopyback) then
  508. secondpass(ppn.paracopyback);
  509. ppn:=tcallparanode(ppn.right);
  510. end;
  511. end;
  512. procedure tcgcallnode.release_para_temps;
  513. var
  514. hp,
  515. hp2 : tnode;
  516. ppn : tcallparanode;
  517. begin
  518. { Release temps from parameters }
  519. ppn:=tcallparanode(left);
  520. while assigned(ppn) do
  521. begin
  522. if assigned(ppn.left) then
  523. begin
  524. { don't release the funcret temp }
  525. if not(assigned(ppn.parasym)) or
  526. not(vo_is_funcret in ppn.parasym.varoptions) then
  527. location_freetemp(current_asmdata.CurrAsmList,ppn.left.location);
  528. { process also all nodes of an array of const }
  529. hp:=ppn.left;
  530. while (hp.nodetype=typeconvn) do
  531. hp:=ttypeconvnode(hp).left;
  532. if (hp.nodetype=arrayconstructorn) and
  533. assigned(tarrayconstructornode(hp).left) then
  534. begin
  535. while assigned(hp) do
  536. begin
  537. hp2:=tarrayconstructornode(hp).left;
  538. { ignore typeconvs and addrn inserted by arrayconstructn for
  539. passing a shortstring }
  540. if (hp2.nodetype=typeconvn) and
  541. (tunarynode(hp2).left.nodetype=addrn) then
  542. hp2:=tunarynode(tunarynode(hp2).left).left
  543. else if hp2.nodetype=addrn then
  544. hp2:=tunarynode(hp2).left;
  545. location_freetemp(current_asmdata.CurrAsmList,hp2.location);
  546. hp:=tarrayconstructornode(hp).right;
  547. end;
  548. end;
  549. end;
  550. ppn:=tcallparanode(ppn.right);
  551. end;
  552. end;
  553. procedure tcgcallnode.pushparas;
  554. var
  555. ppn : tcgcallparanode;
  556. callerparaloc,
  557. tmpparaloc : pcgparalocation;
  558. sizeleft: aint;
  559. htempref,
  560. href : treference;
  561. calleralignment,
  562. tmpalignment: longint;
  563. skipiffinalloc: boolean;
  564. begin
  565. { copy all resources to the allocated registers }
  566. ppn:=tcgcallparanode(left);
  567. while assigned(ppn) do
  568. begin
  569. if (ppn.left.nodetype<>nothingn) then
  570. begin
  571. { better check for the real location of the parameter here, when stack passed parameters
  572. are saved temporary in registers, checking for the tmpparaloc.loc is wrong
  573. }
  574. paramanager.freecgpara(current_asmdata.CurrAsmList,ppn.tempcgpara);
  575. tmpparaloc:=ppn.tempcgpara.location;
  576. sizeleft:=ppn.tempcgpara.intsize;
  577. calleralignment:=ppn.parasym.paraloc[callerside].alignment;
  578. tmpalignment:=ppn.tempcgpara.alignment;
  579. if (tmpalignment=0) or
  580. (calleralignment=0) then
  581. internalerror(2009020701);
  582. callerparaloc:=ppn.parasym.paraloc[callerside].location;
  583. skipiffinalloc:=
  584. not paramanager.use_fixed_stack or
  585. not(ppn.followed_by_stack_tainting_call_cached);
  586. while assigned(callerparaloc) do
  587. begin
  588. { Every paraloc must have a matching tmpparaloc }
  589. if not assigned(tmpparaloc) then
  590. internalerror(200408224);
  591. if callerparaloc^.size<>tmpparaloc^.size then
  592. internalerror(200408225);
  593. case callerparaloc^.loc of
  594. LOC_REGISTER:
  595. begin
  596. if tmpparaloc^.loc<>LOC_REGISTER then
  597. internalerror(200408221);
  598. if getsupreg(callerparaloc^.register)<first_int_imreg then
  599. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  600. cg.a_load_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  601. tmpparaloc^.register,callerparaloc^.register);
  602. end;
  603. LOC_FPUREGISTER:
  604. begin
  605. if tmpparaloc^.loc<>LOC_FPUREGISTER then
  606. internalerror(200408222);
  607. if getsupreg(callerparaloc^.register)<first_fpu_imreg then
  608. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  609. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,ppn.tempcgpara.size,tmpparaloc^.register,callerparaloc^.register);
  610. end;
  611. LOC_MMREGISTER:
  612. begin
  613. if tmpparaloc^.loc<>LOC_MMREGISTER then
  614. internalerror(200408223);
  615. if getsupreg(callerparaloc^.register)<first_mm_imreg then
  616. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  617. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  618. tmpparaloc^.register,callerparaloc^.register,mms_movescalar);
  619. end;
  620. LOC_REFERENCE:
  621. begin
  622. if not(skipiffinalloc and
  623. paramanager.is_stack_paraloc(callerparaloc)) then
  624. begin
  625. { Can't have a data copied to the stack, every location
  626. must contain a valid size field }
  627. if (tmpparaloc^.size=OS_NO) and
  628. ((tmpparaloc^.loc<>LOC_REFERENCE) or
  629. assigned(tmpparaloc^.next)) then
  630. internalerror(200501281);
  631. reference_reset_base(href,callerparaloc^.reference.index,callerparaloc^.reference.offset,calleralignment);
  632. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  633. case tmpparaloc^.loc of
  634. LOC_REFERENCE:
  635. begin
  636. reference_reset_base(htempref,tmpparaloc^.reference.index,tmpparaloc^.reference.offset,tmpalignment);
  637. { use concatcopy, because it can also be a float which fails when
  638. load_ref_ref is used }
  639. if (ppn.tempcgpara.size <> OS_NO) then
  640. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,tcgsize2size[tmpparaloc^.size])
  641. else
  642. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,sizeleft)
  643. end;
  644. LOC_REGISTER:
  645. cg.a_load_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  646. LOC_FPUREGISTER:
  647. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  648. LOC_MMREGISTER:
  649. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href,mms_movescalar);
  650. else
  651. internalerror(200402081);
  652. end;
  653. end;
  654. end;
  655. end;
  656. dec(sizeleft,tcgsize2size[tmpparaloc^.size]);
  657. callerparaloc:=callerparaloc^.next;
  658. tmpparaloc:=tmpparaloc^.next;
  659. end;
  660. end;
  661. ppn:=tcgcallparanode(ppn.right);
  662. end;
  663. end;
  664. procedure tcgcallnode.freeparas;
  665. var
  666. ppn : tcgcallparanode;
  667. begin
  668. { free the resources allocated for the parameters }
  669. ppn:=tcgcallparanode(left);
  670. while assigned(ppn) do
  671. begin
  672. if (ppn.left.nodetype<>nothingn) then
  673. begin
  674. if (ppn.parasym.paraloc[callerside].location^.loc <> LOC_REFERENCE) then
  675. paramanager.freecgpara(current_asmdata.CurrAsmList,ppn.parasym.paraloc[callerside]);
  676. end;
  677. ppn:=tcgcallparanode(ppn.right);
  678. end;
  679. end;
  680. procedure tcgcallnode.pass_generate_code;
  681. var
  682. name_to_call: TSymStr;
  683. regs_to_save_int,
  684. regs_to_save_address,
  685. regs_to_save_fpu,
  686. regs_to_save_mm : Tcpuregisterset;
  687. href : treference;
  688. pop_size : longint;
  689. vmtoffset : aint;
  690. pvreg,
  691. vmtreg : tregister;
  692. oldaktcallnode : tcallnode;
  693. retlocitem: pcgparalocation;
  694. pd : tprocdef;
  695. proc_addr_size: TCgSize;
  696. proc_addr_voidptrdef: tdef;
  697. callref: boolean;
  698. {$ifdef vtentry}
  699. sym : tasmsymbol;
  700. {$endif vtentry}
  701. {$ifdef SUPPORT_SAFECALL}
  702. cgpara : tcgpara;
  703. {$endif}
  704. begin
  705. if not assigned(procdefinition) or
  706. not(procdefinition.has_paraloc_info in [callerside,callbothsides]) then
  707. internalerror(200305264);
  708. extra_pre_call_code;
  709. if assigned(callinitblock) then
  710. secondpass(tnode(callinitblock));
  711. regs_to_save_int:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  712. regs_to_save_address:=paramanager.get_volatile_registers_address(procdefinition.proccalloption);
  713. regs_to_save_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  714. regs_to_save_mm:=paramanager.get_volatile_registers_mm(procdefinition.proccalloption);
  715. proc_addr_voidptrdef:=procdefinition.address_type;
  716. proc_addr_size:=def_cgsize(proc_addr_voidptrdef);
  717. { Include Function result registers }
  718. if (not is_void(resultdef)) then
  719. begin
  720. { The forced returntype may have a different size than the one
  721. declared for the procdef }
  722. if not assigned(typedef) then
  723. retloc:=procdefinition.funcretloc[callerside]
  724. else
  725. retloc:=paramanager.get_funcretloc(procdefinition,callerside,typedef);
  726. retlocitem:=retloc.location;
  727. while assigned(retlocitem) do
  728. begin
  729. case retlocitem^.loc of
  730. LOC_REGISTER:
  731. include(regs_to_save_int,getsupreg(retlocitem^.register));
  732. LOC_FPUREGISTER:
  733. include(regs_to_save_fpu,getsupreg(retlocitem^.register));
  734. LOC_MMREGISTER:
  735. include(regs_to_save_mm,getsupreg(retlocitem^.register));
  736. LOC_REFERENCE,
  737. LOC_VOID:
  738. ;
  739. else
  740. internalerror(2004110213);
  741. end;
  742. retlocitem:=retlocitem^.next;
  743. end;
  744. end;
  745. { Process parameters, register parameters will be loaded
  746. in imaginary registers. The actual load to the correct
  747. register is done just before the call }
  748. oldaktcallnode:=aktcallnode;
  749. aktcallnode:=self;
  750. if assigned(left) then
  751. tcallparanode(left).secondcallparan;
  752. aktcallnode:=oldaktcallnode;
  753. { procedure variable or normal function call ? }
  754. if (right=nil) then
  755. begin
  756. { register call for WPO (must be done before wpo test below,
  757. otherwise optimised called methods are no longer registered)
  758. }
  759. if (po_virtualmethod in procdefinition.procoptions) and
  760. not is_objectpascal_helper(tprocdef(procdefinition).struct) and
  761. assigned(methodpointer) and
  762. (methodpointer.nodetype<>typen) and
  763. (not assigned(current_procinfo) or
  764. wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname)) then
  765. tobjectdef(tprocdef(procdefinition).struct).register_vmt_call(tprocdef(procdefinition).extnumber);
  766. {$ifdef vtentry}
  767. if not is_interface(tprocdef(procdefinition)._class) then
  768. begin
  769. inc(current_asmdata.NextVTEntryNr);
  770. 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));
  771. end;
  772. {$endif vtentry}
  773. {$ifdef symansistr}
  774. name_to_call:=fforcedprocname;
  775. {$else symansistr}
  776. name_to_call:='';
  777. if assigned(fforcedprocname) then
  778. name_to_call:=fforcedprocname^;
  779. {$endif symansistr}
  780. { When methodpointer is typen we don't need (and can't) load
  781. a pointer. We can directly call the correct procdef (PFV) }
  782. if (name_to_call='') and
  783. (po_virtualmethod in procdefinition.procoptions) and
  784. not is_objectpascal_helper(tprocdef(procdefinition).struct) and
  785. assigned(methodpointer) and
  786. (methodpointer.nodetype<>typen) and
  787. not wpoinfomanager.can_be_devirtualized(methodpointer.resultdef,procdefinition,name_to_call) then
  788. begin
  789. { virtual methods require an index }
  790. if tprocdef(procdefinition).extnumber=$ffff then
  791. internalerror(200304021);
  792. secondpass(methodpointer);
  793. { Load VMT from self }
  794. if methodpointer.resultdef.typ=objectdef then
  795. gen_load_vmt_register(current_asmdata.CurrAsmList,tobjectdef(methodpointer.resultdef),methodpointer.location,vmtreg)
  796. else
  797. begin
  798. { Load VMT value in register }
  799. hlcg.location_force_reg(current_asmdata.CurrAsmList,methodpointer.location,methodpointer.resultdef,methodpointer.resultdef,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.