ncgcal.pas 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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,cgbase,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. procedure load_block_invoke(toreg: tregister);virtual;
  82. public
  83. procedure pass_generate_code;override;
  84. destructor destroy;override;
  85. end;
  86. implementation
  87. uses
  88. systems,
  89. cutils,verbose,globals,
  90. cpuinfo,
  91. symconst,symbase,symtable,symtype,symsym,defutil,paramgr,
  92. pass_2,
  93. aasmbase,aasmtai,aasmdata,
  94. nbas,nmem,nld,ncnv,nutils,
  95. ncgutil,blockutl,
  96. cgobj,tgobj,hlcgobj,
  97. procinfo,
  98. wpobase;
  99. {*****************************************************************************
  100. TCGCALLPARANODE
  101. *****************************************************************************}
  102. constructor tcgcallparanode.create(expr,next : tnode);
  103. begin
  104. inherited create(expr,next);
  105. tempcgpara.init;
  106. end;
  107. destructor tcgcallparanode.destroy;
  108. begin
  109. tempcgpara.done;
  110. inherited destroy;
  111. end;
  112. procedure tcgcallparanode.push_addr_para;
  113. begin
  114. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  115. internalerror(200304235);
  116. hlcg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location.reference,tempcgpara);
  117. end;
  118. procedure tcgcallnode.reorder_parameters;
  119. var
  120. hpcurr,hpprev,hpnext,hpreversestart : tcgcallparanode;
  121. currloc : tcgloc;
  122. begin
  123. { All parameters are now in temporary locations. If we move them to
  124. their regular locations in the same order, then we get the
  125. following pattern for register parameters:
  126. mov para1, tempreg1
  127. mov para2, tempreg2
  128. mov para3, tempreg3
  129. mov tempreg1, parareg1
  130. mov tempreg2, parareg2
  131. mov tempreg3, parareg3
  132. The result is that all tempregs conflict with all pararegs.
  133. A better solution is to use:
  134. mov para1, tempreg1
  135. mov para2, tempreg2
  136. mov para3, tempreg3
  137. mov tempreg3, parareg3
  138. mov tempreg2, parareg2
  139. mov tempreg1, parareg1
  140. This way, tempreg2 can be the same as parareg1 etc.
  141. To achieve this, we invert the order of all LOC_XREGISTER
  142. paras (JM).
  143. }
  144. hpcurr:=tcgcallparanode(left);
  145. { assume all LOC_REFERENCE parameters come first
  146. (see tcallnode.order_parameters)
  147. }
  148. hpreversestart:=nil;
  149. while assigned(hpcurr) do
  150. begin
  151. if not(hpcurr.parasym.paraloc[callerside].location^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  152. hpreversestart:=hpcurr;
  153. hpcurr:=tcgcallparanode(hpcurr.right);
  154. end;
  155. { since all register tempparalocs have basically a complexity of 1,
  156. (unless there are large stack offsets that require a temp register on
  157. some architectures, but that's minor), we don't have to care about
  158. the internal relative order of different register type parameters
  159. }
  160. hpprev:=nil;
  161. hpcurr:=tcgcallparanode(left);
  162. while (hpcurr<>hpreversestart) do
  163. begin
  164. hpnext:=tcgcallparanode(hpcurr.right);
  165. if not(hpcurr.parasym.paraloc[callerside].location^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  166. begin
  167. { remove hpcurr from chain }
  168. if assigned(hpprev) then
  169. hpprev.right:=hpnext
  170. else
  171. left:=hpnext;
  172. { insert right after hpreversestart, so every element will
  173. be inserted right before the previously moved one ->
  174. reverse order; hpreversestart itself is the last register
  175. parameter }
  176. hpcurr.right:=hpreversestart.right;
  177. hpreversestart.right:=hpcurr;
  178. end
  179. else
  180. hpprev:=hpcurr;
  181. hpcurr:=hpnext;
  182. end;
  183. end;
  184. procedure tcgcallparanode.push_value_para;
  185. begin
  186. { we've nothing to push when the size of the parameter is 0
  187. -- except in case of the self parameter of an emptry record on e.g.
  188. the JVM target }
  189. if (left.resultdef.size=0) and
  190. not(vo_is_self in parasym.varoptions) then
  191. exit;
  192. { Move flags and jump in register to make it less complex }
  193. if left.location.loc in [LOC_FLAGS,LOC_JUMP,LOC_SUBSETREG,LOC_CSUBSETREG,LOC_SUBSETREF,LOC_CSUBSETREF] then
  194. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  195. { load the parameter's tlocation into its cgpara }
  196. hlcg.gen_load_loc_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location,tempcgpara)
  197. end;
  198. procedure tcgcallparanode.push_formal_para;
  199. begin
  200. { allow passing of a constant to a const formaldef }
  201. if (parasym.varspez=vs_const) and
  202. (left.location.loc in [LOC_CONSTANT,LOC_REGISTER]) then
  203. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef);
  204. push_addr_para;
  205. end;
  206. procedure tcgcallparanode.secondcallparan;
  207. var
  208. href : treference;
  209. otlabel,
  210. oflabel : tasmlabel;
  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. 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.load_block_invoke(toreg: tregister);
  381. var
  382. href: treference;
  383. srsym: tsym;
  384. srsymtable: tsymtable;
  385. literaldef: trecorddef;
  386. begin
  387. literaldef:=get_block_literal_type_for_proc(tabstractprocdef(right.resultdef));
  388. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,getpointerdef(literaldef),true);
  389. { load the invoke pointer }
  390. hlcg.reference_reset_base(href,right.resultdef,right.location.register,0,right.resultdef.alignment);
  391. if not searchsym_in_record(literaldef,'INVOKE',srsym,srsymtable) or
  392. (srsym.typ<>fieldvarsym) or
  393. (tfieldvarsym(srsym).vardef<>voidpointertype) then
  394. internalerror(2014071506);
  395. href.offset:=tfieldvarsym(srsym).fieldoffset;
  396. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,tfieldvarsym(srsym).vardef,procdefinition,href,toreg);
  397. end;
  398. procedure tcgcallnode.set_result_location(realresdef: tstoreddef);
  399. begin
  400. if realresdef.is_intregable or
  401. realresdef.is_fpuregable or
  402. { avoid temporarily storing pointer-sized entities that can't be
  403. regvars, such as reference-counted pointers, to memory --
  404. no exception can occur right now (except in case of existing
  405. memory corruption), and we'd store them to a regular temp
  406. anyway and that is not safer than keeping them in a register }
  407. ((realresdef.size=sizeof(aint)) and
  408. (retloc.location^.loc=LOC_REGISTER) and
  409. not assigned(retloc.location^.next)) then
  410. location_allocate_register(current_asmdata.CurrAsmList,location,realresdef,false)
  411. else
  412. begin
  413. location_reset_ref(location,LOC_REFERENCE,def_cgsize(realresdef),0);
  414. tg.gethltemp(current_asmdata.CurrAsmList,realresdef,retloc.intsize,tt_normal,location.reference);
  415. end;
  416. end;
  417. procedure tcgcallnode.do_release_unused_return_value;
  418. begin
  419. case location.loc of
  420. LOC_REFERENCE :
  421. begin
  422. if is_managed_type(resultdef) then
  423. hlcg.g_finalize(current_asmdata.CurrAsmList,resultdef,location.reference);
  424. tg.ungetiftemp(current_asmdata.CurrAsmList,location.reference);
  425. end;
  426. end;
  427. end;
  428. procedure tcgcallnode.pop_parasize(pop_size:longint);
  429. begin
  430. end;
  431. procedure tcgcallnode.handle_return_value;
  432. var
  433. realresdef: tstoreddef;
  434. begin
  435. { Check that the return location is set when the result is passed in
  436. a parameter }
  437. if paramanager.ret_in_param(resultdef,procdefinition) then
  438. begin
  439. { self.location is set near the end of secondcallparan so it
  440. refers to the implicit result parameter }
  441. if location.loc<>LOC_REFERENCE then
  442. internalerror(200304241);
  443. exit;
  444. end;
  445. if not assigned(typedef) then
  446. realresdef:=tstoreddef(resultdef)
  447. else
  448. realresdef:=tstoreddef(typedef);
  449. { get a tlocation that can hold the return value that's currently in
  450. the return value's tcgpara }
  451. set_result_location(realresdef);
  452. { Do not move the physical register to a virtual one in case
  453. the return value is not used, because if the virtual one is
  454. then mapped to the same register as the physical one, we will
  455. end up with two deallocs of this register (one inserted here,
  456. one inserted by the register allocator), which unbalances the
  457. register allocation information. The return register(s) will
  458. be freed by location_free() in release_unused_return_value
  459. (mantis #13536). }
  460. if (cnf_return_value_used in callnodeflags) or
  461. assigned(funcretnode) then
  462. hlcg.gen_load_cgpara_loc(current_asmdata.CurrAsmList,realresdef,retloc,location,false);
  463. { copy value to the final location if this was already provided to the
  464. callnode. This must be done after the call node, because the location can
  465. also be used as parameter and may not be finalized yet }
  466. if assigned(funcretnode) then
  467. begin
  468. funcretnode.pass_generate_code;
  469. { Decrease refcount for refcounted types, this can be skipped when
  470. we have used a temp, because then it is already done from tempcreatenode.
  471. Also no finalize is needed, because there is no risk of exceptions from the
  472. function since this is code is only executed after the function call has returned }
  473. if is_managed_type(funcretnode.resultdef) and
  474. (funcretnode.nodetype<>temprefn) then
  475. hlcg.g_finalize(current_asmdata.CurrAsmList,funcretnode.resultdef,funcretnode.location.reference);
  476. case location.loc of
  477. LOC_REGISTER :
  478. begin
  479. {$ifndef cpu64bitalu}
  480. if location.size in [OS_64,OS_S64] then
  481. cg64.a_load64_reg_loc(current_asmdata.CurrAsmList,location.register64,funcretnode.location)
  482. else
  483. {$endif}
  484. hlcg.a_load_reg_loc(current_asmdata.CurrAsmList,resultdef,resultdef,location.register,funcretnode.location);
  485. location_free(current_asmdata.CurrAsmList,location);
  486. end;
  487. LOC_REFERENCE:
  488. begin
  489. case funcretnode.location.loc of
  490. LOC_REGISTER:
  491. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,resultdef,resultdef,location.reference,funcretnode.location.register);
  492. LOC_REFERENCE:
  493. hlcg.g_concatcopy(current_asmdata.CurrAsmList,resultdef,location.reference,funcretnode.location.reference);
  494. else
  495. internalerror(200802121);
  496. end;
  497. location_freetemp(current_asmdata.CurrAsmList,location);
  498. end;
  499. else
  500. internalerror(200709085);
  501. end;
  502. location := funcretnode.location;
  503. end;
  504. end;
  505. procedure tcgcallnode.release_unused_return_value;
  506. begin
  507. { When the result is not used we need to finalize the result and
  508. can release the temp. This need to be after the callcleanupblock
  509. tree is generated, because that converts the temp from persistent to normal }
  510. if not(cnf_return_value_used in callnodeflags) then
  511. begin
  512. do_release_unused_return_value;
  513. if (retloc.intsize<>0) then
  514. paramanager.freecgpara(current_asmdata.CurrAsmList,retloc);
  515. location_reset(location,LOC_VOID,OS_NO);
  516. end;
  517. end;
  518. procedure tcgcallnode.copy_back_paras;
  519. var
  520. ppn : tcallparanode;
  521. begin
  522. ppn:=tcallparanode(left);
  523. while assigned(ppn) do
  524. begin
  525. if assigned(ppn.paracopyback) then
  526. secondpass(ppn.paracopyback);
  527. ppn:=tcallparanode(ppn.right);
  528. end;
  529. end;
  530. procedure tcgcallnode.release_para_temps;
  531. var
  532. hp,
  533. hp2 : tnode;
  534. ppn : tcallparanode;
  535. begin
  536. { Release temps from parameters }
  537. ppn:=tcallparanode(left);
  538. while assigned(ppn) do
  539. begin
  540. if assigned(ppn.left) then
  541. begin
  542. { don't release the funcret temp }
  543. if not(assigned(ppn.parasym)) or
  544. not(vo_is_funcret in ppn.parasym.varoptions) then
  545. location_freetemp(current_asmdata.CurrAsmList,ppn.left.location);
  546. { process also all nodes of an array of const }
  547. hp:=ppn.left;
  548. while (hp.nodetype=typeconvn) do
  549. hp:=ttypeconvnode(hp).left;
  550. if (hp.nodetype=arrayconstructorn) and
  551. assigned(tarrayconstructornode(hp).left) then
  552. begin
  553. while assigned(hp) do
  554. begin
  555. hp2:=tarrayconstructornode(hp).left;
  556. { ignore typeconvs and addrn inserted by arrayconstructn for
  557. passing a shortstring }
  558. if (hp2.nodetype=typeconvn) and
  559. (tunarynode(hp2).left.nodetype=addrn) then
  560. hp2:=tunarynode(tunarynode(hp2).left).left
  561. else if hp2.nodetype=addrn then
  562. hp2:=tunarynode(hp2).left;
  563. location_freetemp(current_asmdata.CurrAsmList,hp2.location);
  564. hp:=tarrayconstructornode(hp).right;
  565. end;
  566. end;
  567. end;
  568. ppn:=tcallparanode(ppn.right);
  569. end;
  570. end;
  571. procedure tcgcallnode.pushparas;
  572. var
  573. ppn : tcgcallparanode;
  574. callerparaloc,
  575. tmpparaloc : pcgparalocation;
  576. sizeleft: aint;
  577. htempref,
  578. href : treference;
  579. calleralignment,
  580. tmpalignment: longint;
  581. skipiffinalloc: boolean;
  582. begin
  583. { copy all resources to the allocated registers }
  584. ppn:=tcgcallparanode(left);
  585. while assigned(ppn) do
  586. begin
  587. if (ppn.left.nodetype<>nothingn) then
  588. begin
  589. { better check for the real location of the parameter here, when stack passed parameters
  590. are saved temporary in registers, checking for the tmpparaloc.loc is wrong
  591. }
  592. paramanager.freecgpara(current_asmdata.CurrAsmList,ppn.tempcgpara);
  593. tmpparaloc:=ppn.tempcgpara.location;
  594. sizeleft:=ppn.tempcgpara.intsize;
  595. calleralignment:=ppn.parasym.paraloc[callerside].alignment;
  596. tmpalignment:=ppn.tempcgpara.alignment;
  597. if (tmpalignment=0) or
  598. (calleralignment=0) then
  599. internalerror(2009020701);
  600. callerparaloc:=ppn.parasym.paraloc[callerside].location;
  601. skipiffinalloc:=
  602. not paramanager.use_fixed_stack or
  603. not(ppn.followed_by_stack_tainting_call_cached);
  604. while assigned(callerparaloc) do
  605. begin
  606. { Every paraloc must have a matching tmpparaloc }
  607. if not assigned(tmpparaloc) then
  608. internalerror(200408224);
  609. if callerparaloc^.size<>tmpparaloc^.size then
  610. internalerror(200408225);
  611. case callerparaloc^.loc of
  612. LOC_REGISTER:
  613. begin
  614. if tmpparaloc^.loc<>LOC_REGISTER then
  615. internalerror(200408221);
  616. if getsupreg(callerparaloc^.register)<first_int_imreg then
  617. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  618. cg.a_load_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  619. tmpparaloc^.register,callerparaloc^.register);
  620. end;
  621. LOC_FPUREGISTER:
  622. begin
  623. if tmpparaloc^.loc<>LOC_FPUREGISTER then
  624. internalerror(200408222);
  625. if getsupreg(callerparaloc^.register)<first_fpu_imreg then
  626. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  627. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,ppn.tempcgpara.size,tmpparaloc^.register,callerparaloc^.register);
  628. end;
  629. LOC_MMREGISTER:
  630. begin
  631. if tmpparaloc^.loc<>LOC_MMREGISTER then
  632. internalerror(200408223);
  633. if getsupreg(callerparaloc^.register)<first_mm_imreg then
  634. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  635. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  636. tmpparaloc^.register,callerparaloc^.register,mms_movescalar);
  637. end;
  638. LOC_REFERENCE:
  639. begin
  640. if not(skipiffinalloc and
  641. paramanager.is_stack_paraloc(callerparaloc)) then
  642. begin
  643. { Can't have a data copied to the stack, every location
  644. must contain a valid size field }
  645. if (tmpparaloc^.size=OS_NO) and
  646. ((tmpparaloc^.loc<>LOC_REFERENCE) or
  647. assigned(tmpparaloc^.next)) then
  648. internalerror(200501281);
  649. reference_reset_base(href,callerparaloc^.reference.index,callerparaloc^.reference.offset,calleralignment);
  650. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  651. case tmpparaloc^.loc of
  652. LOC_REFERENCE:
  653. begin
  654. reference_reset_base(htempref,tmpparaloc^.reference.index,tmpparaloc^.reference.offset,tmpalignment);
  655. { use concatcopy, because it can also be a float which fails when
  656. load_ref_ref is used }
  657. if (ppn.tempcgpara.size <> OS_NO) then
  658. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,tcgsize2size[tmpparaloc^.size])
  659. else
  660. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,sizeleft)
  661. end;
  662. LOC_REGISTER:
  663. cg.a_load_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  664. LOC_FPUREGISTER:
  665. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  666. LOC_MMREGISTER:
  667. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href,mms_movescalar);
  668. else
  669. internalerror(200402081);
  670. end;
  671. end;
  672. end;
  673. end;
  674. dec(sizeleft,tcgsize2size[tmpparaloc^.size]);
  675. callerparaloc:=callerparaloc^.next;
  676. tmpparaloc:=tmpparaloc^.next;
  677. end;
  678. end;
  679. ppn:=tcgcallparanode(ppn.right);
  680. end;
  681. end;
  682. procedure tcgcallnode.freeparas;
  683. var
  684. ppn : tcgcallparanode;
  685. begin
  686. { free the resources allocated for the parameters }
  687. ppn:=tcgcallparanode(left);
  688. while assigned(ppn) do
  689. begin
  690. if (ppn.left.nodetype<>nothingn) then
  691. begin
  692. if (ppn.parasym.paraloc[callerside].location^.loc <> LOC_REFERENCE) then
  693. paramanager.freecgpara(current_asmdata.CurrAsmList,ppn.parasym.paraloc[callerside]);
  694. end;
  695. ppn:=tcgcallparanode(ppn.right);
  696. end;
  697. end;
  698. procedure tcgcallnode.pass_generate_code;
  699. var
  700. name_to_call: TSymStr;
  701. regs_to_save_int,
  702. regs_to_save_address,
  703. regs_to_save_fpu,
  704. regs_to_save_mm : Tcpuregisterset;
  705. href : treference;
  706. pop_size : longint;
  707. vmtoffset : aint;
  708. pvreg,
  709. vmtreg : tregister;
  710. oldaktcallnode : tcallnode;
  711. retlocitem: pcgparalocation;
  712. pd : tprocdef;
  713. proc_addr_size: TCgSize;
  714. proc_addr_voidptrdef: tdef;
  715. callref: boolean;
  716. {$ifdef vtentry}
  717. sym : tasmsymbol;
  718. {$endif vtentry}
  719. {$ifdef SUPPORT_SAFECALL}
  720. cgpara : tcgpara;
  721. {$endif}
  722. begin
  723. if not assigned(procdefinition) or
  724. not(procdefinition.has_paraloc_info in [callerside,callbothsides]) then
  725. internalerror(200305264);
  726. extra_pre_call_code;
  727. if assigned(callinitblock) then
  728. secondpass(tnode(callinitblock));
  729. regs_to_save_int:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  730. regs_to_save_address:=paramanager.get_volatile_registers_address(procdefinition.proccalloption);
  731. regs_to_save_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  732. regs_to_save_mm:=paramanager.get_volatile_registers_mm(procdefinition.proccalloption);
  733. proc_addr_voidptrdef:=procdefinition.address_type;
  734. proc_addr_size:=def_cgsize(proc_addr_voidptrdef);
  735. { Include Function result registers }
  736. if (not is_void(resultdef)) then
  737. begin
  738. { The forced returntype may have a different size than the one
  739. declared for the procdef }
  740. if not assigned(typedef) then
  741. retloc:=procdefinition.funcretloc[callerside]
  742. else
  743. retloc:=paramanager.get_funcretloc(procdefinition,callerside,typedef);
  744. retlocitem:=retloc.location;
  745. while assigned(retlocitem) do
  746. begin
  747. case retlocitem^.loc of
  748. LOC_REGISTER:
  749. include(regs_to_save_int,getsupreg(retlocitem^.register));
  750. LOC_FPUREGISTER:
  751. include(regs_to_save_fpu,getsupreg(retlocitem^.register));
  752. LOC_MMREGISTER:
  753. include(regs_to_save_mm,getsupreg(retlocitem^.register));
  754. LOC_REFERENCE,
  755. LOC_VOID:
  756. ;
  757. else
  758. internalerror(2004110213);
  759. end;
  760. retlocitem:=retlocitem^.next;
  761. end;
  762. end;
  763. { Process parameters, register parameters will be loaded
  764. in imaginary registers. The actual load to the correct
  765. register is done just before the call }
  766. oldaktcallnode:=aktcallnode;
  767. aktcallnode:=self;
  768. if assigned(left) then
  769. tcallparanode(left).secondcallparan;
  770. aktcallnode:=oldaktcallnode;
  771. { procedure variable or normal function call ? }
  772. if (right=nil) then
  773. begin
  774. { register call for WPO (must be done before wpo test below,
  775. otherwise optimised called methods are no longer registered)
  776. }
  777. if (po_virtualmethod in procdefinition.procoptions) and
  778. not is_objectpascal_helper(tprocdef(procdefinition).struct) and
  779. assigned(methodpointer) and
  780. (methodpointer.nodetype<>typen) and
  781. (not assigned(current_procinfo) or
  782. wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname)) then
  783. tobjectdef(tprocdef(procdefinition).struct).register_vmt_call(tprocdef(procdefinition).extnumber);
  784. {$ifdef vtentry}
  785. if not is_interface(tprocdef(procdefinition)._class) then
  786. begin
  787. inc(current_asmdata.NextVTEntryNr);
  788. 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));
  789. end;
  790. {$endif vtentry}
  791. {$ifdef symansistr}
  792. name_to_call:=fforcedprocname;
  793. {$else symansistr}
  794. name_to_call:='';
  795. if assigned(fforcedprocname) then
  796. name_to_call:=fforcedprocname^;
  797. {$endif symansistr}
  798. { When methodpointer is typen we don't need (and can't) load
  799. a pointer. We can directly call the correct procdef (PFV) }
  800. if (name_to_call='') and
  801. (po_virtualmethod in procdefinition.procoptions) and
  802. not is_objectpascal_helper(tprocdef(procdefinition).struct) and
  803. assigned(methodpointer) and
  804. (methodpointer.nodetype<>typen) and
  805. not wpoinfomanager.can_be_devirtualized(methodpointer.resultdef,procdefinition,name_to_call) then
  806. begin
  807. { virtual methods require an index }
  808. if tprocdef(procdefinition).extnumber=$ffff then
  809. internalerror(200304021);
  810. secondpass(methodpointer);
  811. { Load VMT from self }
  812. if methodpointer.resultdef.typ=objectdef then
  813. gen_load_vmt_register(current_asmdata.CurrAsmList,tobjectdef(methodpointer.resultdef),methodpointer.location,vmtreg)
  814. else
  815. begin
  816. { Load VMT value in register }
  817. { todo: fix vmt type for high level cg }
  818. hlcg.location_force_reg(current_asmdata.CurrAsmList,methodpointer.location,proc_addr_voidptrdef,proc_addr_voidptrdef,false);
  819. vmtreg:=methodpointer.location.register;
  820. { test validity of VMT }
  821. if not(is_interface(tprocdef(procdefinition).struct)) and
  822. not(is_cppclass(tprocdef(procdefinition).struct)) then
  823. cg.g_maybe_testvmt(current_asmdata.CurrAsmList,vmtreg,tobjectdef(tprocdef(procdefinition).struct));
  824. end;
  825. { Call through VMT, generate a VTREF symbol to notify the linker }
  826. vmtoffset:=tobjectdef(tprocdef(procdefinition).struct).vmtmethodoffset(tprocdef(procdefinition).extnumber);
  827. { register call for WPO }
  828. if (not assigned(current_procinfo) or
  829. wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname)) then
  830. tobjectdef(tprocdef(procdefinition).struct).register_vmt_call(tprocdef(procdefinition).extnumber);
  831. reference_reset_base(href,vmtreg,vmtoffset,proc_addr_voidptrdef.alignment);
  832. pvreg:=NR_NO;
  833. callref:=can_call_ref(href);
  834. if not callref then
  835. begin
  836. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,proc_addr_size);
  837. cg.a_load_ref_reg(current_asmdata.CurrAsmList,proc_addr_size,proc_addr_size,href,pvreg);
  838. end;
  839. { Load parameters that are in temporary registers in the
  840. correct parameter register }
  841. if assigned(left) then
  842. begin
  843. reorder_parameters;
  844. pushparas;
  845. { free the resources allocated for the parameters }
  846. freeparas;
  847. end;
  848. if callref then
  849. extra_call_ref_code(href);
  850. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  851. if cg.uses_registers(R_ADDRESSREGISTER) then
  852. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  853. if cg.uses_registers(R_FPUREGISTER) then
  854. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  855. if cg.uses_registers(R_MMREGISTER) then
  856. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  857. { call method }
  858. extra_call_code;
  859. if callref then
  860. do_call_ref(href)
  861. else
  862. hlcg.a_call_reg(current_asmdata.CurrAsmList,tabstractprocdef(procdefinition),pvreg);
  863. extra_post_call_code;
  864. end
  865. else
  866. begin
  867. { Load parameters that are in temporary registers in the
  868. correct parameter register }
  869. if assigned(left) then
  870. begin
  871. reorder_parameters;
  872. pushparas;
  873. { free the resources allocated for the parameters }
  874. freeparas;
  875. end;
  876. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  877. if cg.uses_registers(R_ADDRESSREGISTER) then
  878. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  879. if cg.uses_registers(R_FPUREGISTER) then
  880. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  881. if cg.uses_registers(R_MMREGISTER) then
  882. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  883. if procdefinition.proccalloption=pocall_syscall then
  884. do_syscall
  885. else
  886. begin
  887. { Calling interrupt from the same code requires some
  888. extra code }
  889. if (po_interrupt in procdefinition.procoptions) then
  890. extra_interrupt_code;
  891. extra_call_code;
  892. if (name_to_call='') then
  893. name_to_call:=tprocdef(procdefinition).mangledname;
  894. if cnf_inherited in callnodeflags then
  895. hlcg.a_call_name_inherited(current_asmdata.CurrAsmList,tprocdef(procdefinition),name_to_call)
  896. else
  897. hlcg.a_call_name(current_asmdata.CurrAsmList,tprocdef(procdefinition),name_to_call,typedef,po_weakexternal in procdefinition.procoptions).resetiftemp;
  898. extra_post_call_code;
  899. end;
  900. end;
  901. end
  902. else
  903. { now procedure variable case }
  904. begin
  905. secondpass(right);
  906. callref:=false;
  907. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,proc_addr_size);
  908. { Only load OS_ADDR from the reference (when converting to hlcg:
  909. watch out with procedure of object) }
  910. if po_is_block in procdefinition.procoptions then
  911. load_block_invoke(pvreg)
  912. else if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  913. begin
  914. href:=right.location.reference;
  915. callref:=can_call_ref(href);
  916. if not callref then
  917. cg.a_load_ref_reg(current_asmdata.CurrAsmList,proc_addr_size,proc_addr_size,right.location.reference,pvreg)
  918. end
  919. else if right.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  920. begin
  921. { in case left is a method pointer and we are on a big endian target, then
  922. the method address is stored in registerhi }
  923. if (target_info.endian=endian_big) and (right.location.size in [OS_PAIR,OS_SPAIR]) then
  924. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,proc_addr_voidptrdef,proc_addr_voidptrdef,right.location.registerhi,pvreg)
  925. else
  926. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,proc_addr_voidptrdef,proc_addr_voidptrdef,right.location.register,pvreg);
  927. end
  928. else
  929. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,proc_addr_voidptrdef,proc_addr_voidptrdef,right.location,pvreg);
  930. location_freetemp(current_asmdata.CurrAsmList,right.location);
  931. { Load parameters that are in temporary registers in the
  932. correct parameter register }
  933. if assigned(left) then
  934. begin
  935. pushparas;
  936. { free the resources allocated for the parameters }
  937. freeparas;
  938. end;
  939. if callref then
  940. extra_call_ref_code(href);
  941. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  942. if cg.uses_registers(R_ADDRESSREGISTER) then
  943. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  944. if cg.uses_registers(R_FPUREGISTER) then
  945. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  946. if cg.uses_registers(R_MMREGISTER) then
  947. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  948. { Calling interrupt from the same code requires some
  949. extra code }
  950. if (po_interrupt in procdefinition.procoptions) then
  951. extra_interrupt_code;
  952. extra_call_code;
  953. if callref then
  954. do_call_ref(href)
  955. else
  956. hlcg.a_call_reg(current_asmdata.CurrAsmList,procdefinition,pvreg);
  957. extra_post_call_code;
  958. end;
  959. { Need to remove the parameters from the stack? }
  960. if (procdefinition.proccalloption in clearstack_pocalls) then
  961. begin
  962. pop_size:=pushedparasize;
  963. { for Cdecl functions we don't need to pop the funcret when it
  964. was pushed by para. Except for safecall functions with
  965. safecall-exceptions enabled. In that case the funcret is always
  966. returned as a para which is considered a normal para on the
  967. c-side, so the funcret has to be pop'ed normally. }
  968. if not ((procdefinition.proccalloption=pocall_safecall) and
  969. (tf_safecall_exceptions in target_info.flags)) and
  970. paramanager.ret_in_param(procdefinition.returndef,procdefinition) then
  971. dec(pop_size,sizeof(pint));
  972. { Remove parameters/alignment from the stack }
  973. pop_parasize(pop_size);
  974. end
  975. { frame pointer parameter is popped by the caller when it's passed the
  976. Delphi way }
  977. else if (po_delphi_nested_cc in procdefinition.procoptions) and
  978. not paramanager.use_fixed_stack then
  979. pop_parasize(sizeof(pint));
  980. { Release registers, but not the registers that contain the
  981. function result }
  982. if (not is_void(resultdef)) then
  983. begin
  984. retlocitem:=retloc.location;
  985. while assigned(retlocitem) do
  986. begin
  987. case retlocitem^.loc of
  988. LOC_REGISTER:
  989. if getregtype(retlocitem^.register)=R_INTREGISTER then
  990. exclude(regs_to_save_int,getsupreg(retlocitem^.register))
  991. else
  992. exclude(regs_to_save_address,getsupreg(retlocitem^.register));
  993. LOC_FPUREGISTER:
  994. exclude(regs_to_save_fpu,getsupreg(retlocitem^.register));
  995. LOC_MMREGISTER:
  996. exclude(regs_to_save_mm,getsupreg(retlocitem^.register));
  997. LOC_REFERENCE,
  998. LOC_VOID:
  999. ;
  1000. else
  1001. internalerror(2004110214);
  1002. end;
  1003. retlocitem:=retlocitem^.next;
  1004. end;
  1005. end;
  1006. if cg.uses_registers(R_MMREGISTER) then
  1007. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  1008. if cg.uses_registers(R_FPUREGISTER) then
  1009. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  1010. if cg.uses_registers(R_ADDRESSREGISTER) then
  1011. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_ADDRESSREGISTER,regs_to_save_address);
  1012. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  1013. {$ifdef SUPPORT_SAFECALL}
  1014. if (procdefinition.proccalloption=pocall_safecall) and
  1015. (tf_safecall_exceptions in target_info.flags) then
  1016. begin
  1017. pd:=search_system_proc('fpc_safecallcheck');
  1018. cgpara.init;
  1019. paramanager.getintparaloc(pd,1,cgpara);
  1020. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_INT,NR_FUNCTION_RESULT_REG,cgpara);
  1021. paramanager.freecgpara(current_asmdata.CurrAsmList,cgpara);
  1022. cg.g_call(current_asmdata.CurrAsmList,'FPC_SAFECALLCHECK');
  1023. cgpara.done;
  1024. end;
  1025. {$endif}
  1026. { handle function results }
  1027. if (not is_void(resultdef)) then
  1028. handle_return_value
  1029. else
  1030. location_reset(location,LOC_VOID,OS_NO);
  1031. { convert persistent temps for parameters and function result to normal temps }
  1032. if assigned(callcleanupblock) then
  1033. secondpass(tnode(callcleanupblock));
  1034. { copy back copy-out parameters if any }
  1035. copy_back_paras;
  1036. { release temps and finalize unused return values, must be
  1037. after the callcleanupblock because that converts temps
  1038. from persistent to normal }
  1039. release_unused_return_value;
  1040. { release temps of paras }
  1041. release_para_temps;
  1042. { perhaps i/o check ? }
  1043. if (cs_check_io in current_settings.localswitches) and
  1044. (po_iocheck in procdefinition.procoptions) and
  1045. not(po_iocheck in current_procinfo.procdef.procoptions) and
  1046. { no IO check for methods and procedure variables }
  1047. (right=nil) and
  1048. not(po_virtualmethod in procdefinition.procoptions) then
  1049. begin
  1050. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1051. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_IOCHECK',false);
  1052. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1053. end;
  1054. end;
  1055. destructor tcgcallnode.destroy;
  1056. begin
  1057. retloc.resetiftemp;
  1058. inherited destroy;
  1059. end;
  1060. begin
  1061. ccallparanode:=tcgcallparanode;
  1062. ccallnode:=tcgcallnode;
  1063. end.