ncgcal.pas 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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. private
  28. tempcgpara : tcgpara;
  29. procedure push_addr_para;
  30. procedure push_value_para;
  31. public
  32. constructor create(expr,next : tnode);override;
  33. destructor destroy;override;
  34. procedure secondcallparan;override;
  35. end;
  36. tcgcallnode = class(tcallnode)
  37. private
  38. procedure release_para_temps;
  39. procedure pushparas;
  40. procedure freeparas;
  41. protected
  42. framepointer_paraloc : tcgpara;
  43. refcountedtemp : treference;
  44. procedure handle_return_value;
  45. {# This routine is used to push the current frame pointer
  46. on the stack. This is used in nested routines where the
  47. value of the frame pointer is always pushed as an extra
  48. parameter.
  49. The default handling is the standard handling used on
  50. most stack based machines, where the frame pointer is
  51. the first invisible parameter.
  52. }
  53. procedure pop_parasize(pop_size:longint);virtual;
  54. procedure extra_interrupt_code;virtual;
  55. procedure extra_call_code;virtual;
  56. procedure extra_post_call_code;virtual;
  57. procedure do_syscall;virtual;abstract;
  58. public
  59. procedure pass_generate_code;override;
  60. end;
  61. implementation
  62. uses
  63. systems,
  64. cutils,verbose,globals,
  65. cpuinfo,
  66. symconst,symtable,defutil,paramgr,
  67. cgbase,pass_2,
  68. aasmbase,aasmtai,aasmdata,
  69. nbas,nmem,nld,ncnv,nutils,
  70. {$ifdef x86}
  71. cga,cgx86,aasmcpu,
  72. {$endif x86}
  73. ncgutil,
  74. cgobj,tgobj,
  75. procinfo;
  76. {*****************************************************************************
  77. TCGCALLPARANODE
  78. *****************************************************************************}
  79. constructor tcgcallparanode.create(expr,next : tnode);
  80. begin
  81. inherited create(expr,next);
  82. tempcgpara.init;
  83. end;
  84. destructor tcgcallparanode.destroy;
  85. begin
  86. tempcgpara.done;
  87. inherited destroy;
  88. end;
  89. procedure tcgcallparanode.push_addr_para;
  90. begin
  91. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  92. internalerror(200304235);
  93. cg.a_paramaddr_ref(current_asmdata.CurrAsmList,left.location.reference,tempcgpara);
  94. end;
  95. procedure tcgcallparanode.push_value_para;
  96. {$ifdef i386}
  97. var
  98. href : treference;
  99. size : longint;
  100. {$endif i386}
  101. begin
  102. { we've nothing to push when the size of the parameter is 0 }
  103. if left.resultdef.size=0 then
  104. exit;
  105. { Move flags and jump in register to make it less complex }
  106. if left.location.loc in [LOC_FLAGS,LOC_JUMP,LOC_SUBSETREG,LOC_CSUBSETREG,LOC_SUBSETREF,LOC_CSUBSETREF] then
  107. location_force_reg(current_asmdata.CurrAsmList,left.location,def_cgsize(left.resultdef),false);
  108. { Handle Floating point types differently
  109. This doesn't depend on emulator settings, emulator settings should
  110. be handled by cpupara }
  111. if left.resultdef.typ=floatdef then
  112. begin
  113. {$ifdef i386}
  114. if tempcgpara.location^.loc<>LOC_REFERENCE then
  115. internalerror(200309291);
  116. case left.location.loc of
  117. LOC_FPUREGISTER,
  118. LOC_CFPUREGISTER:
  119. begin
  120. size:=align(TCGSize2Size[left.location.size],tempcgpara.alignment);
  121. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  122. begin
  123. cg.g_stackpointer_alloc(current_asmdata.CurrAsmList,size);
  124. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  125. end
  126. else
  127. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  128. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,left.location.size,left.location.size,left.location.register,href);
  129. end;
  130. LOC_MMREGISTER,
  131. LOC_CMMREGISTER:
  132. begin
  133. size:=align(tfloatdef(left.resultdef).size,tempcgpara.alignment);
  134. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  135. begin
  136. cg.g_stackpointer_alloc(current_asmdata.CurrAsmList,size);
  137. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  138. end
  139. else
  140. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  141. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,left.location.size,left.location.size,left.location.register,href,mms_movescalar);
  142. end;
  143. LOC_REFERENCE,
  144. LOC_CREFERENCE :
  145. begin
  146. size:=align(left.resultdef.size,tempcgpara.alignment);
  147. if (not use_fixed_stack) and
  148. (tempcgpara.location^.reference.index=NR_STACK_POINTER_REG) then
  149. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara)
  150. else
  151. begin
  152. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  153. cg.g_concatcopy(current_asmdata.CurrAsmList,left.location.reference,href,size);
  154. end;
  155. end;
  156. else
  157. internalerror(2002042430);
  158. end;
  159. {$else i386}
  160. case left.location.loc of
  161. LOC_MMREGISTER,
  162. LOC_CMMREGISTER:
  163. case tempcgpara.location^.loc of
  164. LOC_REFERENCE,
  165. LOC_CREFERENCE,
  166. LOC_MMREGISTER,
  167. LOC_CMMREGISTER:
  168. cg.a_parammm_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  169. {$ifdef x86_64}
  170. LOC_REGISTER,
  171. LOC_CREGISTER :
  172. begin
  173. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_MOVD,S_NO,left.location.register,tempcgpara.location^.register));
  174. end;
  175. {$endif x86_64}
  176. LOC_FPUREGISTER,
  177. LOC_CFPUREGISTER:
  178. begin
  179. location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
  180. cg.a_paramfpu_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara);
  181. end;
  182. else
  183. internalerror(200204249);
  184. end;
  185. LOC_FPUREGISTER,
  186. LOC_CFPUREGISTER:
  187. case tempcgpara.location^.loc of
  188. LOC_MMREGISTER,
  189. LOC_CMMREGISTER:
  190. begin
  191. location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,false);
  192. cg.a_parammm_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  193. end;
  194. {$ifdef cpu64bit}
  195. LOC_REGISTER,
  196. LOC_CREGISTER :
  197. begin
  198. location_force_mem(current_asmdata.CurrAsmList,left.location);
  199. { force integer size }
  200. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  201. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara);
  202. end;
  203. {$endif cpu64bit}
  204. {$ifdef powerpc}
  205. LOC_REGISTER,
  206. LOC_CREGISTER :
  207. begin
  208. { aix abi passes floats of varargs in both fpu and }
  209. { integer registers }
  210. location_force_mem(current_asmdata.CurrAsmList,left.location);
  211. { force integer size }
  212. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  213. if (left.location.size in [OS_32,OS_S32]) then
  214. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara)
  215. else
  216. cg64.a_param64_ref(current_asmdata.CurrAsmList,left.location.reference,tempcgpara);
  217. end;
  218. {$endif powerpc}
  219. {$if defined(sparc) or defined(arm) or defined(m68k)}
  220. { sparc and arm pass floats in normal registers }
  221. LOC_REGISTER,
  222. LOC_CREGISTER,
  223. {$endif sparc}
  224. LOC_REFERENCE,
  225. LOC_CREFERENCE,
  226. LOC_FPUREGISTER,
  227. LOC_CFPUREGISTER:
  228. cg.a_paramfpu_reg(current_asmdata.CurrAsmList,left.location.size,left.location.register,tempcgpara);
  229. else
  230. internalerror(2002042433);
  231. end;
  232. LOC_REFERENCE,
  233. LOC_CREFERENCE:
  234. case tempcgpara.location^.loc of
  235. LOC_MMREGISTER,
  236. LOC_CMMREGISTER:
  237. cg.a_parammm_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara,mms_movescalar);
  238. {$ifdef cpu64bit}
  239. LOC_REGISTER,
  240. LOC_CREGISTER :
  241. begin
  242. { force integer size }
  243. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  244. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara);
  245. end;
  246. {$endif cpu64bit}
  247. {$ifdef powerpc}
  248. { x86_64 pushes s64comp in normal register }
  249. LOC_REGISTER,
  250. LOC_CREGISTER :
  251. begin
  252. { force integer size }
  253. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  254. if (left.location.size in [OS_32,OS_S32]) then
  255. cg.a_param_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara)
  256. else
  257. cg64.a_param64_ref(current_asmdata.CurrAsmList,left.location.reference,tempcgpara);
  258. end;
  259. {$endif powerpc}
  260. {$if defined(sparc) or defined(arm) or defined(m68k)}
  261. { sparc and arm pass floats in normal registers }
  262. LOC_REGISTER,
  263. LOC_CREGISTER,
  264. {$endif}
  265. LOC_REFERENCE,
  266. LOC_CREFERENCE,
  267. LOC_FPUREGISTER,
  268. LOC_CFPUREGISTER:
  269. cg.a_paramfpu_ref(current_asmdata.CurrAsmList,left.location.size,left.location.reference,tempcgpara);
  270. else
  271. internalerror(2002042431);
  272. end;
  273. LOC_REGISTER,
  274. LOC_CREGISTER :
  275. begin
  276. {$ifndef cpu64bit}
  277. { use cg64 only for int64, not for 8 byte records }
  278. if is_64bit(left.resultdef) then
  279. cg64.a_param64_loc(current_asmdata.CurrAsmList,left.location,tempcgpara)
  280. else
  281. {$endif cpu64bit}
  282. begin
  283. {$ifndef cpu64bit}
  284. { Only a_param_ref supports multiple locations, when the
  285. value is still a const or in a register then write it
  286. to a reference first. This situation can be triggered
  287. by typecasting an int64 constant to a record of 8 bytes }
  288. if left.location.size in [OS_64,OS_S64] then
  289. location_force_mem(current_asmdata.CurrAsmList,left.location);
  290. {$endif cpu64bit}
  291. cg.a_param_loc(current_asmdata.CurrAsmList,left.location,tempcgpara);
  292. end;
  293. end;
  294. else
  295. internalerror(2002042432);
  296. end;
  297. {$endif i386}
  298. end
  299. else
  300. begin
  301. case left.location.loc of
  302. LOC_CONSTANT,
  303. LOC_REGISTER,
  304. LOC_CREGISTER,
  305. LOC_REFERENCE,
  306. LOC_CREFERENCE :
  307. begin
  308. {$ifndef cpu64bit}
  309. { use cg64 only for int64, not for 8 byte records }
  310. if is_64bit(left.resultdef) then
  311. cg64.a_param64_loc(current_asmdata.CurrAsmList,left.location,tempcgpara)
  312. else
  313. {$endif cpu64bit}
  314. begin
  315. {$ifndef cpu64bit}
  316. { Only a_param_ref supports multiple locations, when the
  317. value is still a const or in a register then write it
  318. to a reference first. This situation can be triggered
  319. by typecasting an int64 constant to a record of 8 bytes }
  320. if left.location.size in [OS_64,OS_S64] then
  321. location_force_mem(current_asmdata.CurrAsmList,left.location);
  322. {$endif cpu64bit}
  323. cg.a_param_loc(current_asmdata.CurrAsmList,left.location,tempcgpara);
  324. end;
  325. end;
  326. {$ifdef SUPPORT_MMX}
  327. LOC_MMXREGISTER,
  328. LOC_CMMXREGISTER:
  329. cg.a_parammm_reg(current_asmdata.CurrAsmList,OS_M64,left.location.register,tempcgpara,nil);
  330. {$endif SUPPORT_MMX}
  331. else
  332. internalerror(200204241);
  333. end;
  334. end;
  335. end;
  336. procedure tcgcallparanode.secondcallparan;
  337. var
  338. href : treference;
  339. otlabel,
  340. oflabel : tasmlabel;
  341. begin
  342. if not(assigned(parasym)) then
  343. internalerror(200304242);
  344. { Skip nothingn nodes which are used after disabling
  345. a parameter }
  346. if (left.nodetype<>nothingn) then
  347. begin
  348. otlabel:=current_procinfo.CurrTrueLabel;
  349. oflabel:=current_procinfo.CurrFalseLabel;
  350. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  351. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  352. secondpass(left);
  353. maybechangeloadnodereg(current_asmdata.CurrAsmList,left,true);
  354. { release memory for refcnt out parameters }
  355. if (parasym.varspez=vs_out) and
  356. (left.resultdef.needs_inittable) then
  357. begin
  358. location_get_data_ref(current_asmdata.CurrAsmList,left.location,href,false);
  359. cg.g_decrrefcount(current_asmdata.CurrAsmList,left.resultdef,href);
  360. end;
  361. paramanager.createtempparaloc(current_asmdata.CurrAsmList,aktcallnode.procdefinition.proccalloption,parasym,tempcgpara);
  362. { handle varargs first, because parasym is not valid }
  363. if (cpf_varargs_para in callparaflags) then
  364. begin
  365. if paramanager.push_addr_param(vs_value,left.resultdef,
  366. aktcallnode.procdefinition.proccalloption) then
  367. push_addr_para
  368. else
  369. push_value_para;
  370. end
  371. { hidden parameters }
  372. else if (vo_is_hidden_para in parasym.varoptions) then
  373. begin
  374. { don't push a node that already generated a pointer type
  375. by address for implicit hidden parameters }
  376. if (vo_is_funcret in parasym.varoptions) or
  377. { pass "this" in C++ classes explicitly as pointer
  378. because push_addr_param might not be true for them }
  379. (is_cppclass(parasym.vardef) and (vo_is_self in parasym.varoptions)) or
  380. (not(left.resultdef.typ in [pointerdef,classrefdef]) and
  381. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  382. aktcallnode.procdefinition.proccalloption)) then
  383. push_addr_para
  384. else
  385. push_value_para;
  386. end
  387. { formal def }
  388. else if (parasym.vardef.typ=formaldef) then
  389. begin
  390. { allow passing of a constant to a const formaldef }
  391. if (parasym.varspez=vs_const) and
  392. (left.location.loc in [LOC_CONSTANT,LOC_REGISTER]) then
  393. location_force_mem(current_asmdata.CurrAsmList,left.location);
  394. push_addr_para;
  395. end
  396. { Normal parameter }
  397. else
  398. begin
  399. { don't push a node that already generated a pointer type
  400. by address for implicit hidden parameters }
  401. if (not(
  402. (vo_is_hidden_para in parasym.varoptions) and
  403. (left.resultdef.typ in [pointerdef,classrefdef])
  404. ) and
  405. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  406. aktcallnode.procdefinition.proccalloption)) and
  407. { dyn. arrays passed to an array of const must be passed by value, see tests/webtbs/tw4219.pp }
  408. not(
  409. is_array_of_const(parasym.vardef) and
  410. is_dynamic_array(left.resultdef)
  411. ) then
  412. begin
  413. { Passing a var parameter to a var parameter, we can
  414. just push the address transparently }
  415. if (left.nodetype=loadn) and
  416. (tloadnode(left).is_addr_param_load) then
  417. begin
  418. if (left.location.reference.index<>NR_NO) or
  419. (left.location.reference.offset<>0) then
  420. internalerror(200410107);
  421. cg.a_param_reg(current_asmdata.CurrAsmList,OS_ADDR,left.location.reference.base,tempcgpara)
  422. end
  423. else
  424. begin
  425. { Force to be in memory }
  426. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  427. location_force_mem(current_asmdata.CurrAsmList,left.location);
  428. push_addr_para;
  429. end;
  430. end
  431. else
  432. push_value_para;
  433. end;
  434. current_procinfo.CurrTrueLabel:=otlabel;
  435. current_procinfo.CurrFalseLabel:=oflabel;
  436. { update return location in callnode when this is the function
  437. result }
  438. if assigned(parasym) and
  439. (vo_is_funcret in parasym.varoptions) then
  440. location_copy(aktcallnode.location,left.location);
  441. end;
  442. { next parameter }
  443. if assigned(right) then
  444. tcallparanode(right).secondcallparan;
  445. end;
  446. {*****************************************************************************
  447. TCGCALLNODE
  448. *****************************************************************************}
  449. procedure tcgcallnode.extra_interrupt_code;
  450. begin
  451. end;
  452. procedure tcgcallnode.extra_call_code;
  453. begin
  454. end;
  455. procedure tcgcallnode.extra_post_call_code;
  456. begin
  457. end;
  458. procedure tcgcallnode.pop_parasize(pop_size:longint);
  459. begin
  460. end;
  461. procedure tcgcallnode.handle_return_value;
  462. var
  463. cgsize : tcgsize;
  464. retloc : tlocation;
  465. hregister : tregister;
  466. tempnode : tnode;
  467. begin
  468. cgsize:=procdefinition.funcretloc[callerside].size;
  469. { structured results are easy to handle....
  470. needed also when result_no_used !! }
  471. if (procdefinition.proctypeoption<>potype_constructor) and
  472. paramanager.ret_in_param(resultdef,procdefinition.proccalloption) then
  473. begin
  474. { Location should be setup by the funcret para }
  475. if location.loc<>LOC_REFERENCE then
  476. internalerror(200304241);
  477. end
  478. else
  479. { ansi/widestrings must be registered, so we can dispose them }
  480. if resultdef.needs_inittable then
  481. begin
  482. if procdefinition.funcretloc[callerside].loc<>LOC_REGISTER then
  483. internalerror(200409261);
  484. retloc:=procdefinition.funcretloc[callerside];
  485. {$ifndef cpu64bit}
  486. if cgsize in [OS_64,OS_S64] then
  487. begin
  488. { the function result registers are already allocated }
  489. if getsupreg(retloc.register64.reglo)<first_int_imreg then
  490. cg.ungetcpuregister(current_asmdata.CurrAsmList,retloc.register64.reglo);
  491. retloc.register64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  492. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,procdefinition.funcretloc[callerside].register64.reglo,retloc.register64.reglo);
  493. if getsupreg(retloc.register64.reghi)<first_int_imreg then
  494. cg.ungetcpuregister(current_asmdata.CurrAsmList,retloc.register64.reghi);
  495. retloc.register64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  496. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,procdefinition.funcretloc[callerside].register64.reghi,retloc.register64.reghi);
  497. end
  498. else
  499. {$endif cpu64bit}
  500. begin
  501. { the FUNCTION_RESULT_REG is already allocated }
  502. if getsupreg(retloc.register)<first_int_imreg then
  503. cg.ungetcpuregister(current_asmdata.CurrAsmList,retloc.register);
  504. { reg_ref could generate two instrcutions and allocate a register so we've to
  505. save the result first before releasing it }
  506. retloc.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  507. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,procdefinition.funcretloc[callerside].register,retloc.register);
  508. end;
  509. if not assigned(funcretnode) then
  510. begin
  511. location_reset(location,LOC_REFERENCE,cgsize);
  512. location.reference:=refcountedtemp;
  513. end
  514. else
  515. begin
  516. { in case of a regular funcretnode with ret_in_param, the }
  517. { original funcretnode isn't touched -> make sure it's }
  518. { the same here (not sure if it's necessary) }
  519. tempnode := funcretnode.getcopy;
  520. tempnode.pass_generate_code;
  521. location := tempnode.location;
  522. tempnode.free;
  523. cg.g_decrrefcount(current_asmdata.CurrAsmList,resultdef,location.reference);
  524. end;
  525. {$ifndef cpu64bit}
  526. if cgsize in [OS_64,OS_S64] then
  527. cg64.a_load64_reg_ref(current_asmdata.CurrAsmList,retloc.register64,location.reference)
  528. else
  529. {$endif}
  530. cg.a_load_reg_ref(current_asmdata.CurrAsmList,cgsize,cgsize,retloc.register,location.reference);
  531. end
  532. else
  533. { normal (ordinal,float,pointer) result value }
  534. begin
  535. { we have only to handle the result if it is used }
  536. if (cnf_return_value_used in callnodeflags) then
  537. begin
  538. location.loc:=procdefinition.funcretloc[callerside].loc;
  539. case procdefinition.funcretloc[callerside].loc of
  540. LOC_FPUREGISTER:
  541. begin
  542. location_reset(location,LOC_FPUREGISTER,cgsize);
  543. location.register:=procdefinition.funcretloc[callerside].register;
  544. {$ifdef x86}
  545. tcgx86(cg).inc_fpu_stack;
  546. {$else x86}
  547. if getsupreg(procdefinition.funcretloc[callerside].register)<first_fpu_imreg then
  548. cg.ungetcpuregister(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside].register);
  549. hregister:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  550. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,location.size,location.size,location.register,hregister);
  551. location.register:=hregister;
  552. {$endif x86}
  553. end;
  554. LOC_REGISTER:
  555. begin
  556. if cgsize<>OS_NO then
  557. begin
  558. location_reset(location,LOC_REGISTER,cgsize);
  559. {$ifndef cpu64bit}
  560. if cgsize in [OS_64,OS_S64] then
  561. begin
  562. retloc:=procdefinition.funcretloc[callerside];
  563. if retloc.loc<>LOC_REGISTER then
  564. internalerror(200409141);
  565. { the function result registers are already allocated }
  566. if getsupreg(retloc.register64.reglo)<first_int_imreg then
  567. cg.ungetcpuregister(current_asmdata.CurrAsmList,retloc.register64.reglo);
  568. location.register64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  569. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,retloc.register64.reglo,location.register64.reglo);
  570. if getsupreg(retloc.register64.reghi)<first_int_imreg then
  571. cg.ungetcpuregister(current_asmdata.CurrAsmList,retloc.register64.reghi);
  572. location.register64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  573. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,retloc.register64.reghi,location.register64.reghi);
  574. end
  575. else
  576. {$endif cpu64bit}
  577. begin
  578. { change register size after the unget because the
  579. getregister was done for the full register
  580. def_cgsize(resultdef) is used here because
  581. it could be a constructor call }
  582. if getsupreg(procdefinition.funcretloc[callerside].register)<first_int_imreg then
  583. cg.ungetcpuregister(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside].register);
  584. location.register:=cg.getintregister(current_asmdata.CurrAsmList,def_cgsize(resultdef));
  585. cg.a_load_reg_reg(current_asmdata.CurrAsmList,cgsize,def_cgsize(resultdef),procdefinition.funcretloc[callerside].register,location.register);
  586. end;
  587. {$ifdef arm}
  588. if (resultdef.typ=floatdef) and (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) then
  589. begin
  590. location_force_mem(current_asmdata.CurrAsmList,location);
  591. end;
  592. {$endif arm}
  593. end
  594. else
  595. begin
  596. if resultdef.size>0 then
  597. internalerror(200305131);
  598. end;
  599. end;
  600. LOC_MMREGISTER:
  601. begin
  602. location_reset(location,LOC_MMREGISTER,cgsize);
  603. if getsupreg(procdefinition.funcretloc[callerside].register)<first_mm_imreg then
  604. cg.ungetcpuregister(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside].register);
  605. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,cgsize);
  606. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,cgsize,cgsize,procdefinition.funcretloc[callerside].register,location.register,mms_movescalar);
  607. end;
  608. else
  609. internalerror(200405023);
  610. end;
  611. end
  612. else
  613. begin
  614. {$ifdef x86}
  615. { release FPU stack }
  616. if procdefinition.funcretloc[callerside].loc=LOC_FPUREGISTER then
  617. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  618. {$endif x86}
  619. if cgsize<>OS_NO then
  620. location_free(current_asmdata.CurrAsmList,procdefinition.funcretloc[callerside]);
  621. location_reset(location,LOC_VOID,OS_NO);
  622. end;
  623. end;
  624. { When the result is not used we need to finalize the result and
  625. can release the temp }
  626. if not(cnf_return_value_used in callnodeflags) then
  627. begin
  628. if location.loc=LOC_REFERENCE then
  629. begin
  630. if resultdef.needs_inittable then
  631. cg.g_finalize(current_asmdata.CurrAsmList,resultdef,location.reference);
  632. tg.ungetiftemp(current_asmdata.CurrAsmList,location.reference)
  633. end;
  634. end;
  635. end;
  636. procedure tcgcallnode.release_para_temps;
  637. var
  638. hp : tnode;
  639. ppn : tcallparanode;
  640. begin
  641. { Release temps from parameters }
  642. ppn:=tcallparanode(left);
  643. while assigned(ppn) do
  644. begin
  645. if assigned(ppn.left) then
  646. begin
  647. { don't release the funcret temp }
  648. if not(assigned(ppn.parasym)) or
  649. not(vo_is_funcret in ppn.parasym.varoptions) then
  650. location_freetemp(current_asmdata.CurrAsmList,ppn.left.location);
  651. { process also all nodes of an array of const }
  652. hp:=ppn.left;
  653. while (hp.nodetype=typeconvn) do
  654. hp:=ttypeconvnode(hp).left;
  655. if (hp.nodetype=arrayconstructorn) and
  656. assigned(tarrayconstructornode(hp).left) then
  657. begin
  658. while assigned(hp) do
  659. begin
  660. location_freetemp(current_asmdata.CurrAsmList,tarrayconstructornode(hp).left.location);
  661. hp:=tarrayconstructornode(hp).right;
  662. end;
  663. end;
  664. end;
  665. ppn:=tcallparanode(ppn.right);
  666. end;
  667. end;
  668. procedure tcgcallnode.pushparas;
  669. var
  670. ppn : tcgcallparanode;
  671. callerparaloc,
  672. tmpparaloc : pcgparalocation;
  673. sizeleft: aint;
  674. htempref,
  675. href : treference;
  676. begin
  677. { copy all resources to the allocated registers }
  678. ppn:=tcgcallparanode(left);
  679. while assigned(ppn) do
  680. begin
  681. if (ppn.left.nodetype<>nothingn) then
  682. begin
  683. { better check for the real location of the parameter here, when stack passed parameters
  684. are saved temporary in registers, checking for the tmpparaloc.loc is wrong
  685. }
  686. paramanager.freeparaloc(current_asmdata.CurrAsmList,ppn.tempcgpara);
  687. tmpparaloc:=ppn.tempcgpara.location;
  688. sizeleft:=ppn.tempcgpara.intsize;
  689. callerparaloc:=ppn.parasym.paraloc[callerside].location;
  690. while assigned(callerparaloc) do
  691. begin
  692. { Every paraloc must have a matching tmpparaloc }
  693. if not assigned(tmpparaloc) then
  694. internalerror(200408224);
  695. if callerparaloc^.size<>tmpparaloc^.size then
  696. internalerror(200408225);
  697. case callerparaloc^.loc of
  698. LOC_REGISTER:
  699. begin
  700. if tmpparaloc^.loc<>LOC_REGISTER then
  701. internalerror(200408221);
  702. if getsupreg(callerparaloc^.register)<first_int_imreg then
  703. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  704. cg.a_load_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  705. tmpparaloc^.register,callerparaloc^.register);
  706. end;
  707. LOC_FPUREGISTER:
  708. begin
  709. if tmpparaloc^.loc<>LOC_FPUREGISTER then
  710. internalerror(200408222);
  711. if getsupreg(callerparaloc^.register)<first_fpu_imreg then
  712. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  713. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,ppn.tempcgpara.size,tmpparaloc^.register,callerparaloc^.register);
  714. end;
  715. LOC_MMREGISTER:
  716. begin
  717. if tmpparaloc^.loc<>LOC_MMREGISTER then
  718. internalerror(200408223);
  719. if getsupreg(callerparaloc^.register)<first_mm_imreg then
  720. cg.getcpuregister(current_asmdata.CurrAsmList,callerparaloc^.register);
  721. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,
  722. tmpparaloc^.register,callerparaloc^.register,mms_movescalar);
  723. end;
  724. LOC_REFERENCE:
  725. begin
  726. if use_fixed_stack then
  727. begin
  728. { Can't have a data copied to the stack, every location
  729. must contain a valid size field }
  730. if (ppn.tempcgpara.size=OS_NO) and
  731. ((tmpparaloc^.loc<>LOC_REFERENCE) or
  732. assigned(tmpparaloc^.next)) then
  733. internalerror(200501281);
  734. reference_reset_base(href,callerparaloc^.reference.index,callerparaloc^.reference.offset);
  735. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  736. case tmpparaloc^.loc of
  737. LOC_REFERENCE:
  738. begin
  739. reference_reset_base(htempref,tmpparaloc^.reference.index,tmpparaloc^.reference.offset);
  740. { use concatcopy, because it can also be a float which fails when
  741. load_ref_ref is used }
  742. if (ppn.tempcgpara.size <> OS_NO) then
  743. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,tcgsize2size[tmpparaloc^.size])
  744. else
  745. cg.g_concatcopy(current_asmdata.CurrAsmList,htempref,href,sizeleft)
  746. end;
  747. LOC_REGISTER:
  748. cg.a_load_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  749. LOC_FPUREGISTER:
  750. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  751. LOC_MMREGISTER:
  752. cg.a_loadmm_reg_ref(current_asmdata.CurrAsmList,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href,mms_movescalar);
  753. else
  754. internalerror(200402081);
  755. end;
  756. end;
  757. end;
  758. end;
  759. dec(sizeleft,tcgsize2size[tmpparaloc^.size]);
  760. callerparaloc:=callerparaloc^.next;
  761. tmpparaloc:=tmpparaloc^.next;
  762. end;
  763. end;
  764. ppn:=tcgcallparanode(ppn.right);
  765. end;
  766. end;
  767. procedure tcgcallnode.freeparas;
  768. var
  769. ppn : tcgcallparanode;
  770. begin
  771. { free the resources allocated for the parameters }
  772. ppn:=tcgcallparanode(left);
  773. while assigned(ppn) do
  774. begin
  775. if (ppn.left.nodetype<>nothingn) then
  776. begin
  777. if (ppn.parasym.paraloc[callerside].location^.loc <> LOC_REFERENCE) then
  778. paramanager.freeparaloc(current_asmdata.CurrAsmList,ppn.parasym.paraloc[callerside]);
  779. end;
  780. ppn:=tcgcallparanode(ppn.right);
  781. end;
  782. end;
  783. procedure tcgcallnode.pass_generate_code;
  784. var
  785. regs_to_save_int,
  786. regs_to_save_fpu,
  787. regs_to_save_mm : Tcpuregisterset;
  788. href : treference;
  789. pop_size : longint;
  790. vmtoffset : aint;
  791. pvreg,
  792. vmtreg : tregister;
  793. oldaktcallnode : tcallnode;
  794. {$ifdef vtentry}
  795. sym : tasmsymbol;
  796. {$endif vtentry}
  797. begin
  798. if not assigned(procdefinition) or
  799. not procdefinition.has_paraloc_info then
  800. internalerror(200305264);
  801. if assigned(methodpointerinit) then
  802. secondpass(methodpointerinit);
  803. if resultdef.needs_inittable and
  804. not paramanager.ret_in_param(resultdef,procdefinition.proccalloption) and
  805. not assigned(funcretnode) then
  806. begin
  807. tg.gettemptyped(current_asmdata.CurrAsmList,resultdef,tt_normal,refcountedtemp);
  808. { finalize instead of only decrref, because if the called }
  809. { function throws an exception this temp will be decrref'd }
  810. { again (tw7100) }
  811. cg.g_finalize(current_asmdata.CurrAsmList,resultdef,refcountedtemp);
  812. end;
  813. regs_to_save_int:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  814. regs_to_save_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  815. regs_to_save_mm:=paramanager.get_volatile_registers_mm(procdefinition.proccalloption);
  816. { Include Function result registers }
  817. if (not is_void(resultdef)) then
  818. begin
  819. case procdefinition.funcretloc[callerside].loc of
  820. LOC_REGISTER,
  821. LOC_CREGISTER:
  822. include(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register));
  823. LOC_FPUREGISTER,
  824. LOC_CFPUREGISTER:
  825. include(regs_to_save_fpu,getsupreg(procdefinition.funcretloc[callerside].register));
  826. LOC_MMREGISTER,
  827. LOC_CMMREGISTER:
  828. include(regs_to_save_mm,getsupreg(procdefinition.funcretloc[callerside].register));
  829. LOC_REFERENCE,
  830. LOC_VOID:
  831. ;
  832. else
  833. internalerror(2004110213);
  834. end;
  835. end;
  836. { Process parameters, register parameters will be loaded
  837. in imaginary registers. The actual load to the correct
  838. register is done just before the call }
  839. oldaktcallnode:=aktcallnode;
  840. aktcallnode:=self;
  841. if assigned(left) then
  842. tcallparanode(left).secondcallparan;
  843. aktcallnode:=oldaktcallnode;
  844. { procedure variable or normal function call ? }
  845. if (right=nil) then
  846. begin
  847. { When methodpointer is typen we don't need (and can't) load
  848. a pointer. We can directly call the correct procdef (PFV) }
  849. if (po_virtualmethod in procdefinition.procoptions) and
  850. assigned(methodpointer) and
  851. (methodpointer.nodetype<>typen) then
  852. begin
  853. { virtual methods require an index }
  854. if tprocdef(procdefinition).extnumber=$ffff then
  855. internalerror(200304021);
  856. secondpass(methodpointer);
  857. { Load VMT from self }
  858. if methodpointer.resultdef.typ=objectdef then
  859. gen_load_vmt_register(current_asmdata.CurrAsmList,tobjectdef(methodpointer.resultdef),methodpointer.location,vmtreg)
  860. else
  861. begin
  862. { Load VMT value in register }
  863. location_force_reg(current_asmdata.CurrAsmList,methodpointer.location,OS_ADDR,false);
  864. vmtreg:=methodpointer.location.register;
  865. end;
  866. { test validity of VMT }
  867. if not(is_interface(tprocdef(procdefinition)._class)) and
  868. not(is_cppclass(tprocdef(procdefinition)._class)) then
  869. cg.g_maybe_testvmt(current_asmdata.CurrAsmList,vmtreg,tprocdef(procdefinition)._class);
  870. { Call through VMT, generate a VTREF symbol to notify the linker }
  871. vmtoffset:=tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber);
  872. {$ifdef vtentry}
  873. if not is_interface(tprocdef(procdefinition)._class) then
  874. begin
  875. inc(current_asmdata.NextVTEntryNr);
  876. current_asmdata.CurrAsmList.Concat(tai_symbol.CreateName('VTREF'+tostr(current_asmdata.NextVTEntryNr)+'_'+tprocdef(procdefinition)._class.vmt_mangledname+'$$'+tostr(vmtoffset div sizeof(aint)),AT_FUNCTION,0));
  877. end;
  878. {$endif vtentry}
  879. {$ifndef x86}
  880. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  881. {$endif not x86}
  882. reference_reset_base(href,vmtreg,vmtoffset);
  883. {$ifndef x86}
  884. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,href,pvreg);
  885. {$endif not x86}
  886. { Load parameters that are in temporary registers in the
  887. correct parameter register }
  888. if assigned(left) then
  889. begin
  890. pushparas;
  891. { free the resources allocated for the parameters }
  892. freeparas;
  893. end;
  894. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  895. if cg.uses_registers(R_FPUREGISTER) then
  896. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  897. if cg.uses_registers(R_MMREGISTER) then
  898. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  899. { call method }
  900. extra_call_code;
  901. {$ifdef x86}
  902. cg.a_call_ref(current_asmdata.CurrAsmList,href);
  903. {$else x86}
  904. cg.a_call_reg(current_asmdata.CurrAsmList,pvreg);
  905. {$endif x86}
  906. extra_post_call_code;
  907. end
  908. else
  909. begin
  910. { Load parameters that are in temporary registers in the
  911. correct parameter register }
  912. if assigned(left) then
  913. begin
  914. pushparas;
  915. { free the resources allocated for the parameters }
  916. freeparas;
  917. end;
  918. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  919. if cg.uses_registers(R_FPUREGISTER) then
  920. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  921. if cg.uses_registers(R_MMREGISTER) then
  922. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  923. if procdefinition.proccalloption=pocall_syscall then
  924. do_syscall
  925. else
  926. begin
  927. { Calling interrupt from the same code requires some
  928. extra code }
  929. if (po_interrupt in procdefinition.procoptions) then
  930. extra_interrupt_code;
  931. extra_call_code;
  932. cg.a_call_name(current_asmdata.CurrAsmList,tprocdef(procdefinition).mangledname);
  933. extra_post_call_code;
  934. end;
  935. end;
  936. end
  937. else
  938. { now procedure variable case }
  939. begin
  940. secondpass(right);
  941. pvreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  942. { Only load OS_ADDR from the reference }
  943. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  944. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,right.location.reference,pvreg)
  945. else
  946. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_ADDR,right.location,pvreg);
  947. location_freetemp(current_asmdata.CurrAsmList,right.location);
  948. { Load parameters that are in temporary registers in the
  949. correct parameter register }
  950. if assigned(left) then
  951. begin
  952. pushparas;
  953. { free the resources allocated for the parameters }
  954. freeparas;
  955. end;
  956. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  957. if cg.uses_registers(R_FPUREGISTER) then
  958. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  959. if cg.uses_registers(R_MMREGISTER) then
  960. cg.alloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  961. { Calling interrupt from the same code requires some
  962. extra code }
  963. if (po_interrupt in procdefinition.procoptions) then
  964. extra_interrupt_code;
  965. extra_call_code;
  966. cg.a_call_reg(current_asmdata.CurrAsmList,pvreg);
  967. extra_post_call_code;
  968. end;
  969. { Need to remove the parameters from the stack? }
  970. if (procdefinition.proccalloption in clearstack_pocalls) then
  971. begin
  972. pop_size:=pushedparasize;
  973. { for Cdecl functions we don't need to pop the funcret when it
  974. was pushed by para }
  975. if paramanager.ret_in_param(procdefinition.returndef,procdefinition.proccalloption) then
  976. dec(pop_size,sizeof(aint));
  977. { Remove parameters/alignment from the stack }
  978. pop_parasize(pop_size);
  979. end;
  980. { Release registers, but not the registers that contain the
  981. function result }
  982. if (not is_void(resultdef)) then
  983. begin
  984. case procdefinition.funcretloc[callerside].loc of
  985. LOC_REGISTER,
  986. LOC_CREGISTER:
  987. begin
  988. {$ifndef cpu64bit}
  989. if procdefinition.funcretloc[callerside].size in [OS_64,OS_S64] then
  990. begin
  991. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register64.reghi));
  992. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register64.reglo));
  993. end
  994. else
  995. {$endif cpu64bit}
  996. exclude(regs_to_save_int,getsupreg(procdefinition.funcretloc[callerside].register));
  997. end;
  998. LOC_FPUREGISTER,
  999. LOC_CFPUREGISTER:
  1000. exclude(regs_to_save_fpu,getsupreg(procdefinition.funcretloc[callerside].register));
  1001. LOC_MMREGISTER,
  1002. LOC_CMMREGISTER:
  1003. exclude(regs_to_save_mm,getsupreg(procdefinition.funcretloc[callerside].register));
  1004. LOC_REFERENCE,
  1005. LOC_VOID:
  1006. ;
  1007. else
  1008. internalerror(2004110214);
  1009. end;
  1010. end;
  1011. {$if defined(x86) or defined(arm)}
  1012. if procdefinition.proccalloption=pocall_safecall then
  1013. begin
  1014. {$ifdef x86_64}
  1015. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,NR_RAX,NR_RCX);
  1016. {$endif x86_64}
  1017. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1018. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_SAFECALLCHECK');
  1019. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1020. end;
  1021. {$endif}
  1022. if cg.uses_registers(R_MMREGISTER) then
  1023. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_MMREGISTER,regs_to_save_mm);
  1024. if cg.uses_registers(R_FPUREGISTER) then
  1025. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_FPUREGISTER,regs_to_save_fpu);
  1026. cg.dealloccpuregisters(current_asmdata.CurrAsmList,R_INTREGISTER,regs_to_save_int);
  1027. { handle function results }
  1028. if (not is_void(resultdef)) then
  1029. handle_return_value
  1030. else
  1031. location_reset(location,LOC_VOID,OS_NO);
  1032. { perhaps i/o check ? }
  1033. if (cs_check_io in current_settings.localswitches) and
  1034. (po_iocheck in procdefinition.procoptions) and
  1035. not(po_iocheck in current_procinfo.procdef.procoptions) and
  1036. { no IO check for methods and procedure variables }
  1037. (right=nil) and
  1038. not(po_virtualmethod in procdefinition.procoptions) then
  1039. begin
  1040. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1041. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_IOCHECK');
  1042. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1043. end;
  1044. { release temps of paras }
  1045. release_para_temps;
  1046. if assigned(methodpointerdone) then
  1047. secondpass(methodpointerdone);
  1048. end;
  1049. begin
  1050. ccallparanode:=tcgcallparanode;
  1051. ccallnode:=tcgcallnode;
  1052. end.