ncgcal.pas 50 KB

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