ncgcal.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate assembler for call nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncgcal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. globtype,
  24. parabase,
  25. symdef,node,ncal;
  26. type
  27. tcgcallparanode = class(tcallparanode)
  28. private
  29. tempcgpara : tcgpara;
  30. procedure push_addr_para;
  31. procedure push_value_para;
  32. public
  33. constructor create(expr,next : tnode);override;
  34. destructor destroy;override;
  35. procedure secondcallparan;override;
  36. end;
  37. tcgcallnode = class(tcallnode)
  38. private
  39. procedure release_para_temps;
  40. procedure normal_pass_2;
  41. procedure inlined_pass_2;
  42. procedure pushparas;
  43. procedure freeparas;
  44. protected
  45. framepointer_paraloc : tcgpara;
  46. refcountedtemp : treference;
  47. procedure handle_return_value;
  48. {# This routine is used to push the current frame pointer
  49. on the stack. This is used in nested routines where the
  50. value of the frame pointer is always pushed as an extra
  51. parameter.
  52. The default handling is the standard handling used on
  53. most stack based machines, where the frame pointer is
  54. the first invisible parameter.
  55. }
  56. procedure pop_parasize(pop_size:longint);virtual;
  57. procedure extra_interrupt_code;virtual;
  58. procedure extra_call_code;virtual;
  59. procedure do_syscall;virtual;abstract;
  60. public
  61. procedure pass_2;override;
  62. end;
  63. implementation
  64. uses
  65. systems,
  66. cutils,verbose,globals,
  67. symconst,symsym,symtable,defutil,paramgr,
  68. {$ifdef GDB}
  69. {$ifdef delphi}
  70. sysutils,
  71. {$else}
  72. strings,
  73. {$endif}
  74. gdb,
  75. {$endif GDB}
  76. cgbase,pass_2,
  77. aasmbase,aasmtai,
  78. nbas,nmem,nld,ncnv,nutils,
  79. {$ifdef x86}
  80. cga,cgx86,
  81. {$endif x86}
  82. ncgutil,
  83. cgutils,cgobj,tgobj,
  84. procinfo;
  85. {*****************************************************************************
  86. TCGCALLPARANODE
  87. *****************************************************************************}
  88. constructor tcgcallparanode.create(expr,next : tnode);
  89. begin
  90. inherited create(expr,next);
  91. tempcgpara.init;
  92. end;
  93. destructor tcgcallparanode.destroy;
  94. begin
  95. tempcgpara.done;
  96. inherited destroy;
  97. end;
  98. procedure tcgcallparanode.push_addr_para;
  99. begin
  100. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  101. internalerror(200304235);
  102. cg.a_paramaddr_ref(exprasmlist,left.location.reference,tempcgpara);
  103. end;
  104. procedure tcgcallparanode.push_value_para;
  105. {$ifdef i386}
  106. var
  107. cgsize : tcgsize;
  108. href : treference;
  109. size : longint;
  110. {$endif i386}
  111. begin
  112. { we've nothing to push when the size of the parameter is 0 }
  113. if left.resulttype.def.size=0 then
  114. exit;
  115. { Move flags and jump in register to make it less complex }
  116. if left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  117. location_force_reg(exprasmlist,left.location,def_cgsize(left.resulttype.def),false);
  118. { Handle Floating point types differently }
  119. if left.resulttype.def.deftype=floatdef then
  120. begin
  121. {$ifdef i386}
  122. if tempcgpara.location^.loc<>LOC_REFERENCE then
  123. internalerror(200309291);
  124. case left.location.loc of
  125. LOC_FPUREGISTER,
  126. LOC_CFPUREGISTER:
  127. begin
  128. size:=align(TCGSize2Size[left.location.size],tempcgpara.alignment);
  129. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  130. begin
  131. cg.g_stackpointer_alloc(exprasmlist,size);
  132. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  133. end
  134. else
  135. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  136. cg.a_loadfpu_reg_ref(exprasmlist,left.location.size,left.location.register,href);
  137. end;
  138. LOC_MMREGISTER,
  139. LOC_CMMREGISTER:
  140. begin
  141. size:=align(tfloatdef(left.resulttype.def).size,tempcgpara.alignment);
  142. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  143. begin
  144. cg.g_stackpointer_alloc(exprasmlist,size);
  145. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  146. end
  147. else
  148. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  149. cg.a_loadmm_reg_ref(exprasmlist,left.location.size,left.location.size,left.location.register,href,mms_movescalar);
  150. end;
  151. LOC_REFERENCE,
  152. LOC_CREFERENCE :
  153. begin
  154. size:=align(left.resulttype.def.size,tempcgpara.alignment);
  155. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  156. begin
  157. href:=left.location.reference;
  158. inc(href.offset,size);
  159. while (size>0) do
  160. begin
  161. if (size>=4) or (tempcgpara.alignment>=4) then
  162. begin
  163. cgsize:=OS_32;
  164. dec(href.offset,4);
  165. dec(size,4);
  166. end
  167. else
  168. begin
  169. cgsize:=OS_16;
  170. dec(href.offset,2);
  171. dec(size,2);
  172. end;
  173. cg.a_param_ref(exprasmlist,cgsize,href,tempcgpara);
  174. end;
  175. end
  176. else
  177. begin
  178. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  179. cg.g_concatcopy(exprasmlist,left.location.reference,href,size,false);
  180. end;
  181. end;
  182. else
  183. internalerror(2002042430);
  184. end;
  185. {$else i386}
  186. case left.location.loc of
  187. LOC_MMREGISTER,
  188. LOC_CMMREGISTER:
  189. case tempcgpara.location^.loc of
  190. LOC_REFERENCE,
  191. LOC_CREFERENCE,
  192. LOC_MMREGISTER,
  193. LOC_CMMREGISTER:
  194. cg.a_parammm_reg(exprasmlist,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  195. LOC_FPUREGISTER,
  196. LOC_CFPUREGISTER:
  197. begin
  198. location_force_fpureg(exprasmlist,left.location,false);
  199. cg.a_paramfpu_reg(exprasmlist,left.location.size,left.location.register,tempcgpara);
  200. end;
  201. else
  202. internalerror(2002042433);
  203. end;
  204. LOC_FPUREGISTER,
  205. LOC_CFPUREGISTER:
  206. case tempcgpara.location^.loc of
  207. LOC_MMREGISTER,
  208. LOC_CMMREGISTER:
  209. begin
  210. location_force_mmregscalar(exprasmlist,left.location,false);
  211. cg.a_parammm_reg(exprasmlist,left.location.size,left.location.register,tempcgpara,mms_movescalar);
  212. end;
  213. {$ifdef x86_64}
  214. { x86_64 pushes s64comp in normal register }
  215. LOC_REGISTER,
  216. LOC_CREGISTER :
  217. begin
  218. location_force_mem(exprasmlist,left.location);
  219. { force integer size }
  220. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  221. cg.a_param_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara);
  222. end;
  223. {$endif x86_64}
  224. {$ifdef sparc}
  225. { sparc pushes floats in normal registers }
  226. LOC_REGISTER,
  227. LOC_CREGISTER,
  228. {$endif sparc}
  229. LOC_REFERENCE,
  230. LOC_CREFERENCE,
  231. LOC_FPUREGISTER,
  232. LOC_CFPUREGISTER:
  233. cg.a_paramfpu_reg(exprasmlist,left.location.size,left.location.register,tempcgpara);
  234. else
  235. internalerror(2002042433);
  236. end;
  237. LOC_REFERENCE,
  238. LOC_CREFERENCE:
  239. case tempcgpara.location^.loc of
  240. LOC_MMREGISTER,
  241. LOC_CMMREGISTER:
  242. cg.a_parammm_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara,mms_movescalar);
  243. {$ifdef x86_64}
  244. { x86_64 pushes s64comp in normal register }
  245. LOC_REGISTER,
  246. LOC_CREGISTER :
  247. begin
  248. { force integer size }
  249. left.location.size:=int_cgsize(tcgsize2size[left.location.size]);
  250. cg.a_param_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara);
  251. end;
  252. {$endif x86_64}
  253. {$ifdef sparc}
  254. { sparc pushes floats in normal registers }
  255. LOC_REGISTER,
  256. LOC_CREGISTER,
  257. {$endif sparc}
  258. LOC_REFERENCE,
  259. LOC_CREFERENCE,
  260. LOC_FPUREGISTER,
  261. LOC_CFPUREGISTER:
  262. cg.a_paramfpu_ref(exprasmlist,left.location.size,left.location.reference,tempcgpara);
  263. else
  264. internalerror(2002042431);
  265. end;
  266. else
  267. internalerror(2002042432);
  268. end;
  269. {$endif i386}
  270. end
  271. else
  272. begin
  273. { copy the value on the stack or use normal parameter push?
  274. Check for varargs first because that has no paraitem }
  275. if not(cpf_varargs_para in callparaflags) and
  276. paramanager.copy_value_on_stack(paraitem.paratyp,left.resulttype.def,
  277. aktcallnode.procdefinition.proccalloption) then
  278. begin
  279. {$ifdef i386}
  280. if tempcgpara.location^.loc<>LOC_REFERENCE then
  281. internalerror(200309292);
  282. if not (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  283. internalerror(200204241);
  284. { push on stack }
  285. size:=align(left.resulttype.def.size,tempcgpara.alignment);
  286. if tempcgpara.location^.reference.index=NR_STACK_POINTER_REG then
  287. begin
  288. cg.g_stackpointer_alloc(exprasmlist,size);
  289. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  290. end
  291. else
  292. reference_reset_base(href,tempcgpara.location^.reference.index,tempcgpara.location^.reference.offset);
  293. cg.g_concatcopy(exprasmlist,left.location.reference,href,size,false);
  294. {$else i386}
  295. cg.a_param_copy_ref(exprasmlist,left.resulttype.def.size,left.location.reference,tempcgpara);
  296. {$endif i386}
  297. end
  298. else
  299. begin
  300. case left.location.loc of
  301. LOC_CONSTANT,
  302. LOC_REGISTER,
  303. LOC_CREGISTER,
  304. LOC_REFERENCE,
  305. LOC_CREFERENCE :
  306. begin
  307. {$ifndef cpu64bit}
  308. if left.location.size in [OS_64,OS_S64] then
  309. cg64.a_param64_loc(exprasmlist,left.location,tempcgpara)
  310. else
  311. {$endif cpu64bit}
  312. cg.a_param_loc(exprasmlist,left.location,tempcgpara);
  313. end;
  314. {$ifdef SUPPORT_MMX}
  315. LOC_MMXREGISTER,
  316. LOC_CMMXREGISTER:
  317. cg.a_parammm_reg(exprasmlist,left.location.register);
  318. {$endif SUPPORT_MMX}
  319. else
  320. internalerror(200204241);
  321. end;
  322. end;
  323. end;
  324. end;
  325. procedure tcgcallparanode.secondcallparan;
  326. var
  327. otlabel,
  328. oflabel : tasmlabel;
  329. hp : tnode;
  330. begin
  331. if not(assigned(paraitem)) or
  332. not(assigned(paraitem.paratype.def)) or
  333. not(assigned(paraitem.parasym) or
  334. (cpf_varargs_para in callparaflags)) then
  335. internalerror(200304242);
  336. { Skip nothingn nodes which are used after disabling
  337. a parameter }
  338. if (left.nodetype<>nothingn) then
  339. begin
  340. otlabel:=truelabel;
  341. oflabel:=falselabel;
  342. objectlibrary.getlabel(truelabel);
  343. objectlibrary.getlabel(falselabel);
  344. secondpass(left);
  345. if not(assigned(aktcallnode.inlinecode)) then
  346. paramanager.createtempparaloc(exprasmlist,aktcallnode.procdefinition.proccalloption,paraitem,tempcgpara)
  347. else
  348. paramanager.duplicateparaloc(exprasmlist,aktcallnode.procdefinition.proccalloption,paraitem,tempcgpara);
  349. { handle varargs first, because paraitem.parasym is not valid }
  350. if (cpf_varargs_para in callparaflags) then
  351. begin
  352. if paramanager.push_addr_param(vs_value,left.resulttype.def,
  353. aktcallnode.procdefinition.proccalloption) then
  354. push_addr_para
  355. else
  356. push_value_para;
  357. end
  358. { hidden parameters }
  359. else if paraitem.is_hidden then
  360. begin
  361. { don't push a node that already generated a pointer type
  362. by address for implicit hidden parameters }
  363. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  364. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  365. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  366. aktcallnode.procdefinition.proccalloption)) then
  367. push_addr_para
  368. else
  369. push_value_para;
  370. end
  371. { formal def }
  372. else if (paraitem.paratype.def.deftype=formaldef) then
  373. begin
  374. { allow passing of a constant to a const formaldef }
  375. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  376. (left.location.loc=LOC_CONSTANT) then
  377. location_force_mem(exprasmlist,left.location);
  378. { allow (typecasted) @var }
  379. hp:=left;
  380. while (hp.nodetype=typeconvn) do
  381. hp:=ttypeconvnode(hp).left;
  382. if (hp.nodetype=addrn) and
  383. (not(nf_procvarload in hp.flags)) then
  384. cg.a_param_loc(exprasmlist,left.location,tempcgpara)
  385. else
  386. push_addr_para;
  387. end
  388. { Normal parameter }
  389. else
  390. begin
  391. { don't push a node that already generated a pointer type
  392. by address for implicit hidden parameters }
  393. if (not(
  394. paraitem.is_hidden and
  395. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  396. ) and
  397. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  398. aktcallnode.procdefinition.proccalloption)) then
  399. begin
  400. { Check for passing a constant to var,out parameter }
  401. if (paraitem.paratyp in [vs_var,vs_out]) and
  402. (left.location.loc<>LOC_REFERENCE) then
  403. begin
  404. { passing self to a var parameter is allowed in
  405. TP and delphi }
  406. if not((left.location.loc=LOC_CREFERENCE) and
  407. is_self_node(left)) then
  408. internalerror(200106041);
  409. end;
  410. { Force to be in memory }
  411. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  412. location_force_mem(exprasmlist,left.location);
  413. push_addr_para;
  414. end
  415. else
  416. push_value_para;
  417. end;
  418. truelabel:=otlabel;
  419. falselabel:=oflabel;
  420. { update return location in callnode when this is the function
  421. result }
  422. if assigned(paraitem.parasym) and
  423. (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  424. location_copy(aktcallnode.location,left.location);
  425. end;
  426. { next parameter }
  427. if assigned(right) then
  428. tcallparanode(right).secondcallparan;
  429. end;
  430. {*****************************************************************************
  431. TCGCALLNODE
  432. *****************************************************************************}
  433. procedure tcgcallnode.extra_interrupt_code;
  434. begin
  435. end;
  436. procedure tcgcallnode.extra_call_code;
  437. begin
  438. end;
  439. procedure tcgcallnode.pop_parasize(pop_size:longint);
  440. begin
  441. end;
  442. procedure tcgcallnode.handle_return_value;
  443. var
  444. cgsize : tcgsize;
  445. retloc : tlocation;
  446. hregister : tregister;
  447. tempnode : tnode;
  448. resultparaloc : pcgparalocation;
  449. begin
  450. resultparaloc:=procdefinition.funcret_paraloc[callerside].location;
  451. cgsize:=procdefinition.funcret_paraloc[callerside].size;
  452. { structured results are easy to handle....
  453. needed also when result_no_used !! }
  454. if (procdefinition.proctypeoption<>potype_constructor) and
  455. paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  456. begin
  457. { Location should be setup by the funcret para }
  458. if location.loc<>LOC_REFERENCE then
  459. internalerror(200304241);
  460. end
  461. else
  462. { ansi/widestrings must be registered, so we can dispose them }
  463. if resulttype.def.needs_inittable then
  464. begin
  465. if resultparaloc^.loc<>LOC_REGISTER then
  466. internalerror(200409261);
  467. { the FUNCTION_RESULT_REG is already allocated }
  468. if getsupreg(resultparaloc^.register)<first_mm_imreg then
  469. cg.ungetcpuregister(exprasmlist,resultparaloc^.register);
  470. if not assigned(funcretnode) then
  471. begin
  472. location_reset(location,LOC_REFERENCE,OS_ADDR);
  473. location.reference:=refcountedtemp;
  474. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,location.reference);
  475. end
  476. else
  477. begin
  478. hregister := cg.getaddressregister(exprasmlist);
  479. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,resultparaloc^.register,hregister);
  480. { in case of a regular funcretnode with ret_in_param, the }
  481. { original funcretnode isn't touched -> make sure it's }
  482. { the same here (not sure if it's necessary) }
  483. tempnode := funcretnode.getcopy;
  484. tempnode.pass_2;
  485. location := tempnode.location;
  486. tempnode.free;
  487. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference,false);
  488. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  489. end;
  490. { When the result is not used we need to finalize the result and
  491. can release the temp }
  492. if not(cnf_return_value_used in callnodeflags) then
  493. begin
  494. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  495. tg.ungetiftemp(exprasmlist,location.reference)
  496. end;
  497. end
  498. else
  499. { normal (ordinal,float,pointer) result value }
  500. begin
  501. { we have only to handle the result if it is used }
  502. if (cnf_return_value_used in callnodeflags) then
  503. begin
  504. location.loc:=resultparaloc^.loc;
  505. case resultparaloc^.loc of
  506. LOC_FPUREGISTER:
  507. begin
  508. location_reset(location,LOC_FPUREGISTER,cgsize);
  509. location.register:=resultparaloc^.register;
  510. {$ifdef x86}
  511. tcgx86(cg).inc_fpu_stack;
  512. {$else x86}
  513. if getsupreg(resultparaloc^.register)<first_fpu_imreg then
  514. cg.ungetcpuregister(exprasmlist,resultparaloc^.register);
  515. hregister:=cg.getfpuregister(exprasmlist,location.size);
  516. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  517. location.register:=hregister;
  518. {$endif x86}
  519. end;
  520. LOC_REGISTER:
  521. begin
  522. if cgsize<>OS_NO then
  523. begin
  524. location_reset(location,LOC_REGISTER,cgsize);
  525. {$ifndef cpu64bit}
  526. if cgsize in [OS_64,OS_S64] then
  527. begin
  528. procdefinition.funcret_paraloc[callerside].get_location(retloc);
  529. if retloc.loc<>LOC_REGISTER then
  530. internalerror(200409141);
  531. { the function result registers are already allocated }
  532. if getsupreg(retloc.registerlow)<first_int_imreg then
  533. cg.ungetcpuregister(exprasmlist,retloc.registerlow);
  534. location.registerlow:=cg.getintregister(exprasmlist,OS_32);
  535. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,retloc.registerlow,location.registerlow);
  536. if getsupreg(retloc.registerhigh)<first_int_imreg then
  537. cg.ungetcpuregister(exprasmlist,retloc.registerhigh);
  538. location.registerhigh:=cg.getintregister(exprasmlist,OS_32);
  539. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,retloc.registerhigh,location.registerhigh);
  540. end
  541. else
  542. {$endif cpu64bit}
  543. begin
  544. { change register size after the unget because the
  545. getregister was done for the full register
  546. def_cgsize(resulttype.def) is used here because
  547. it could be a constructor call }
  548. if getsupreg(resultparaloc^.register)<first_int_imreg then
  549. cg.ungetcpuregister(exprasmlist,resultparaloc^.register);
  550. location.register:=cg.getintregister(exprasmlist,def_cgsize(resulttype.def));
  551. cg.a_load_reg_reg(exprasmlist,cgsize,def_cgsize(resulttype.def),resultparaloc^.register,location.register);
  552. end;
  553. end
  554. else
  555. begin
  556. if resulttype.def.size>0 then
  557. internalerror(200305131);
  558. end;
  559. end;
  560. LOC_MMREGISTER:
  561. begin
  562. location_reset(location,LOC_MMREGISTER,cgsize);
  563. if getsupreg(resultparaloc^.register)<first_mm_imreg then
  564. cg.ungetcpuregister(exprasmlist,resultparaloc^.register);
  565. location.register:=cg.getmmregister(exprasmlist,cgsize);
  566. cg.a_loadmm_reg_reg(exprasmlist,cgsize,cgsize,resultparaloc^.register,location.register,mms_movescalar);
  567. end;
  568. else
  569. internalerror(200405023);
  570. end;
  571. end
  572. else
  573. begin
  574. {$ifdef x86}
  575. { release FPU stack }
  576. if resultparaloc^.loc=LOC_FPUREGISTER then
  577. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  578. {$endif x86}
  579. if cgsize<>OS_NO then
  580. paramanager.freeparaloc(exprasmlist,procdefinition.funcret_paraloc[callerside]);
  581. location_reset(location,LOC_VOID,OS_NO);
  582. end;
  583. end;
  584. end;
  585. procedure tcgcallnode.release_para_temps;
  586. var
  587. hp : tnode;
  588. ppn : tcallparanode;
  589. begin
  590. { Release temps from parameters }
  591. ppn:=tcallparanode(left);
  592. while assigned(ppn) do
  593. begin
  594. if assigned(ppn.left) then
  595. begin
  596. { don't release the funcret temp }
  597. if not(assigned(ppn.paraitem.parasym)) or
  598. not(vo_is_funcret in tvarsym(ppn.paraitem.parasym).varoptions) then
  599. location_freetemp(exprasmlist,ppn.left.location);
  600. { process also all nodes of an array of const }
  601. if ppn.left.nodetype=arrayconstructorn then
  602. begin
  603. if assigned(tarrayconstructornode(ppn.left).left) then
  604. begin
  605. hp:=ppn.left;
  606. while assigned(hp) do
  607. begin
  608. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  609. hp:=tarrayconstructornode(hp).right;
  610. end;
  611. end;
  612. end;
  613. end;
  614. ppn:=tcallparanode(ppn.right);
  615. end;
  616. end;
  617. procedure tcgcallnode.pushparas;
  618. var
  619. ppn : tcgcallparanode;
  620. callerparaloc,
  621. tmpparaloc : pcgparalocation;
  622. {$ifdef cputargethasfixedstack}
  623. htempref,
  624. href : treference;
  625. {$endif cputargethasfixedstack}
  626. begin
  627. { copy all resources to the allocated registers }
  628. ppn:=tcgcallparanode(left);
  629. while assigned(ppn) do
  630. begin
  631. if (ppn.left.nodetype<>nothingn) then
  632. begin
  633. { better check for the real location of the parameter here, when stack passed parameters
  634. are saved temporary in registers, checking for the tmpparaloc.loc is wrong
  635. }
  636. if not assigned(inlinecode) then
  637. paramanager.freeparaloc(exprasmlist,ppn.tempcgpara);
  638. tmpparaloc:=ppn.tempcgpara.location;
  639. callerparaloc:=ppn.paraitem.paraloc[callerside].location;
  640. while assigned(callerparaloc) do
  641. begin
  642. { Every paraloc must have a matching tmpparaloc }
  643. if not assigned(tmpparaloc) then
  644. internalerror(200408224);
  645. if callerparaloc^.size<>tmpparaloc^.size then
  646. internalerror(200408225);
  647. case callerparaloc^.loc of
  648. LOC_REGISTER:
  649. begin
  650. if tmpparaloc^.loc<>LOC_REGISTER then
  651. internalerror(200408221);
  652. if getsupreg(callerparaloc^.register)<first_int_imreg then
  653. cg.getcpuregister(exprasmlist,callerparaloc^.register);
  654. cg.a_load_reg_reg(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,
  655. tmpparaloc^.register,callerparaloc^.register);
  656. end;
  657. LOC_FPUREGISTER:
  658. begin
  659. if tmpparaloc^.loc<>LOC_FPUREGISTER then
  660. internalerror(200408222);
  661. if getsupreg(callerparaloc^.register)<first_fpu_imreg then
  662. cg.getcpuregister(exprasmlist,callerparaloc^.register);
  663. cg.a_loadfpu_reg_reg(exprasmlist,ppn.tempcgpara.size,tmpparaloc^.register,callerparaloc^.register);
  664. end;
  665. LOC_MMREGISTER:
  666. begin
  667. if tmpparaloc^.loc<>LOC_MMREGISTER then
  668. internalerror(200408223);
  669. if getsupreg(callerparaloc^.register)<first_mm_imreg then
  670. cg.getcpuregister(exprasmlist,callerparaloc^.register);
  671. cg.a_loadmm_reg_reg(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,
  672. tmpparaloc^.register,callerparaloc^.register,mms_movescalar);
  673. end;
  674. LOC_REFERENCE:
  675. begin
  676. if not assigned(inlinecode) then
  677. begin
  678. {$ifdef cputargethasfixedstack}
  679. reference_reset_base(href,callerparaloc^.reference.index,callerparaloc^.reference.offset);
  680. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  681. case tmpparaloc^.loc of
  682. LOC_REFERENCE:
  683. begin
  684. reference_reset_base(htempref,tmpparaloc^.reference.index,tmpparaloc^.reference.offset);
  685. { use concatcopy, because it can also be a float which fails when
  686. load_ref_ref is used }
  687. cg.g_concatcopy(exprasmlist,htempref,href,tcgsize2size[tmpparaloc^.size],false);
  688. end;
  689. LOC_REGISTER:
  690. cg.a_load_reg_ref(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href);
  691. LOC_FPUREGISTER:
  692. cg.a_loadfpu_reg_ref(exprasmlist,tmpparaloc^.size,tmpparaloc^.register,href);
  693. LOC_MMREGISTER:
  694. cg.a_loadmm_reg_ref(exprasmlist,tmpparaloc^.size,tmpparaloc^.size,tmpparaloc^.register,href,mms_movescalar);
  695. else
  696. internalerror(200402081);
  697. end;
  698. {$endif cputargethasfixedstack}
  699. end;
  700. end;
  701. end;
  702. callerparaloc:=callerparaloc^.next;
  703. tmpparaloc:=tmpparaloc^.next;
  704. end;
  705. end;
  706. ppn:=tcgcallparanode(ppn.right);
  707. end;
  708. end;
  709. procedure tcgcallnode.freeparas;
  710. var
  711. ppn : tcgcallparanode;
  712. begin
  713. { free the resources allocated for the parameters }
  714. ppn:=tcgcallparanode(left);
  715. while assigned(ppn) do
  716. begin
  717. if not assigned(inlinecode) or
  718. (ppn.paraitem.paraloc[callerside].location^.loc <> LOC_REFERENCE) then
  719. paramanager.freeparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  720. ppn:=tcgcallparanode(ppn.right);
  721. end;
  722. end;
  723. procedure tcgcallnode.normal_pass_2;
  724. var
  725. regs_to_save_int,
  726. regs_to_save_fpu,
  727. regs_to_save_mm : Tcpuregisterset;
  728. href : treference;
  729. pop_size : longint;
  730. pvreg,
  731. vmtreg : tregister;
  732. oldaktcallnode : tcallnode;
  733. funcretloc : pcgparalocation;
  734. begin
  735. if not assigned(procdefinition) or
  736. not procdefinition.has_paraloc_info then
  737. internalerror(200305264);
  738. if resulttype.def.needs_inittable and
  739. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) and
  740. not assigned(funcretnode) then
  741. begin
  742. tg.gettemptyped(exprasmlist,resulttype.def,tt_normal,refcountedtemp);
  743. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  744. end;
  745. regs_to_save_int:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  746. regs_to_save_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  747. regs_to_save_mm:=paramanager.get_volatile_registers_mm(procdefinition.proccalloption);
  748. { Include Function result registers }
  749. if (not is_void(resulttype.def)) then
  750. begin
  751. funcretloc:=procdefinition.funcret_paraloc[callerside].location;
  752. while assigned(funcretloc) do
  753. begin
  754. case funcretloc^.loc of
  755. LOC_REGISTER,
  756. LOC_CREGISTER:
  757. include(regs_to_save_int,getsupreg(funcretloc^.register));
  758. LOC_FPUREGISTER,
  759. LOC_CFPUREGISTER:
  760. include(regs_to_save_fpu,getsupreg(funcretloc^.register));
  761. LOC_MMREGISTER,
  762. LOC_CMMREGISTER:
  763. include(regs_to_save_mm,getsupreg(funcretloc^.register));
  764. end;
  765. funcretloc:=funcretloc^.next;
  766. end;
  767. end;
  768. { Process parameters, register parameters will be loaded
  769. in imaginary registers. The actual load to the correct
  770. register is done just before the call }
  771. oldaktcallnode:=aktcallnode;
  772. aktcallnode:=self;
  773. if assigned(left) then
  774. tcallparanode(left).secondcallparan;
  775. aktcallnode:=oldaktcallnode;
  776. { procedure variable or normal function call ? }
  777. if (right=nil) then
  778. begin
  779. if (po_virtualmethod in procdefinition.procoptions) and
  780. assigned(methodpointer) then
  781. begin
  782. secondpass(methodpointer);
  783. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  784. { virtual methods require an index }
  785. if tprocdef(procdefinition).extnumber=-1 then
  786. internalerror(200304021);
  787. { VMT should already be loaded in a register }
  788. if methodpointer.location.register=NR_NO then
  789. internalerror(200304022);
  790. { test validity of VMT }
  791. if not(is_interface(tprocdef(procdefinition)._class)) and
  792. not(is_cppclass(tprocdef(procdefinition)._class)) then
  793. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  794. end;
  795. {$warning fixme regvars}
  796. { rg.saveotherregvars(exprasmlist,regs_to_push_other);}
  797. if (po_virtualmethod in procdefinition.procoptions) and
  798. assigned(methodpointer) then
  799. begin
  800. vmtreg:=methodpointer.location.register;
  801. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  802. reference_reset_base(href,vmtreg,
  803. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  804. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,pvreg);
  805. { Load parameters that are in temporary registers in the
  806. correct parameter register }
  807. if assigned(left) then
  808. pushparas;
  809. { free the resources allocated for the parameters }
  810. freeparas;
  811. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  812. if cg.uses_registers(R_FPUREGISTER) then
  813. cg.alloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  814. if cg.uses_registers(R_MMREGISTER) then
  815. cg.alloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  816. { call method }
  817. extra_call_code;
  818. cg.a_call_reg(exprasmlist,pvreg);
  819. end
  820. else
  821. begin
  822. { Load parameters that are in temporary registers in the
  823. correct parameter register }
  824. if assigned(left) then
  825. pushparas;
  826. { free the resources allocated for the parameters }
  827. freeparas;
  828. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  829. if cg.uses_registers(R_FPUREGISTER) then
  830. cg.alloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  831. if cg.uses_registers(R_MMREGISTER) then
  832. cg.alloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  833. if procdefinition.proccalloption=pocall_syscall then
  834. do_syscall
  835. else
  836. begin
  837. { Calling interrupt from the same code requires some
  838. extra code }
  839. if (po_interrupt in procdefinition.procoptions) then
  840. extra_interrupt_code;
  841. extra_call_code;
  842. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  843. end;
  844. end;
  845. end
  846. else
  847. { now procedure variable case }
  848. begin
  849. secondpass(right);
  850. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  851. { Only load OS_ADDR from the reference }
  852. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  853. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,right.location.reference,pvreg)
  854. else
  855. cg.a_load_loc_reg(exprasmlist,OS_ADDR,right.location,pvreg);
  856. location_freetemp(exprasmlist,right.location);
  857. { Load parameters that are in temporary registers in the
  858. correct parameter register }
  859. if assigned(left) then
  860. pushparas;
  861. { free the resources allocated for the parameters }
  862. freeparas;
  863. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  864. if cg.uses_registers(R_FPUREGISTER) then
  865. cg.alloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  866. if cg.uses_registers(R_MMREGISTER) then
  867. cg.alloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  868. { Calling interrupt from the same code requires some
  869. extra code }
  870. if (po_interrupt in procdefinition.procoptions) then
  871. extra_interrupt_code;
  872. {$warning fixme regvars.}
  873. { rg.saveotherregvars(exprasmlist,ALL_OTHERREGISTERS);}
  874. extra_call_code;
  875. cg.a_call_reg(exprasmlist,pvreg);
  876. end;
  877. { Need to remove the parameters from the stack? }
  878. if (procdefinition.proccalloption in clearstack_pocalls) then
  879. begin
  880. pop_size:=pushedparasize;
  881. { for Cdecl functions we don't need to pop the funcret when it
  882. was pushed by para }
  883. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  884. dec(pop_size,sizeof(aint));
  885. { Remove parameters/alignment from the stack }
  886. pop_parasize(pop_size);
  887. end;
  888. { Release registers, but not the registers that contain the
  889. function result }
  890. if (not is_void(resulttype.def)) then
  891. begin
  892. funcretloc:=procdefinition.funcret_paraloc[callerside].location;
  893. while assigned(funcretloc) do
  894. begin
  895. case funcretloc^.loc of
  896. LOC_REGISTER,
  897. LOC_CREGISTER:
  898. exclude(regs_to_save_int,getsupreg(funcretloc^.register));
  899. LOC_FPUREGISTER,
  900. LOC_CFPUREGISTER:
  901. exclude(regs_to_save_fpu,getsupreg(funcretloc^.register));
  902. LOC_MMREGISTER,
  903. LOC_CMMREGISTER:
  904. exclude(regs_to_save_mm,getsupreg(funcretloc^.register));
  905. end;
  906. funcretloc:=funcretloc^.next;
  907. end;
  908. end;
  909. if cg.uses_registers(R_MMREGISTER) then
  910. cg.dealloccpuregisters(exprasmlist,R_MMREGISTER,regs_to_save_mm);
  911. if cg.uses_registers(R_FPUREGISTER) then
  912. cg.dealloccpuregisters(exprasmlist,R_FPUREGISTER,regs_to_save_fpu);
  913. cg.dealloccpuregisters(exprasmlist,R_INTREGISTER,regs_to_save_int);
  914. { handle function results }
  915. if (not is_void(resulttype.def)) then
  916. handle_return_value
  917. else
  918. location_reset(location,LOC_VOID,OS_NO);
  919. { perhaps i/o check ? }
  920. if (cs_check_io in aktlocalswitches) and
  921. (po_iocheck in procdefinition.procoptions) and
  922. not(po_iocheck in current_procinfo.procdef.procoptions) and
  923. { no IO check for methods and procedure variables }
  924. (right=nil) and
  925. not(po_virtualmethod in procdefinition.procoptions) then
  926. begin
  927. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  928. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  929. cg.dealloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  930. end;
  931. { release temps of paras }
  932. release_para_temps;
  933. end;
  934. procedure tcgcallnode.inlined_pass_2;
  935. var
  936. oldaktcallnode : tcallnode;
  937. oldprocinfo : tprocinfo;
  938. oldinlining_procedure : boolean;
  939. inlineentrycode,inlineexitcode : TAAsmoutput;
  940. {$ifdef GDB}
  941. startlabel,endlabel : tasmlabel;
  942. pp : pchar;
  943. mangled_length : longint;
  944. {$endif GDB}
  945. begin
  946. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  947. internalerror(200305262);
  948. oldinlining_procedure:=inlining_procedure;
  949. oldprocinfo:=current_procinfo;
  950. { we're inlining a procedure }
  951. inlining_procedure:=true;
  952. { Add inling start }
  953. {$ifdef GDB}
  954. exprasmlist.concat(Tai_force_line.Create);
  955. {$endif GDB}
  956. exprasmList.concat(Tai_Marker.Create(InlineStart));
  957. {$ifdef extdebug}
  958. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc '+tprocdef(procdefinition).procsym.name)));
  959. {$endif extdebug}
  960. { calculate registers to pass the parameters }
  961. paramanager.create_inline_paraloc_info(procdefinition);
  962. { Allocate parameters and locals }
  963. gen_alloc_inline_parast(exprasmlist,tprocdef(procdefinition));
  964. gen_alloc_inline_funcret(exprasmlist,tprocdef(procdefinition));
  965. if tprocdef(procdefinition).localst.symtabletype=localsymtable then
  966. gen_alloc_localst(exprasmlist,tlocalsymtable(tprocdef(procdefinition).localst));
  967. { if we allocate the temp. location for ansi- or widestrings }
  968. { already here, we avoid later a push/pop }
  969. if resulttype.def.needs_inittable and
  970. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  971. begin
  972. tg.gettemptyped(exprasmlist,resulttype.def,tt_normal,refcountedtemp);
  973. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  974. end;
  975. { Push parameters, still use the old current_procinfo. This
  976. is required that have the correct information available like
  977. _class and nested procedure }
  978. oldaktcallnode:=aktcallnode;
  979. aktcallnode:=self;
  980. if assigned(left) then
  981. begin
  982. tcallparanode(left).secondcallparan;
  983. pushparas;
  984. end;
  985. aktcallnode:=oldaktcallnode;
  986. { create temp procinfo that will be used for the inlinecode tree }
  987. current_procinfo:=cprocinfo.create(nil);
  988. current_procinfo.procdef:=tprocdef(procdefinition);
  989. current_procinfo.flags:=oldprocinfo.flags;
  990. current_procinfo.aktlocaldata.destroy;
  991. current_procinfo.aktlocaldata:=oldprocinfo.aktlocaldata;
  992. { when the oldprocinfo is also being inlined reuse the
  993. inlining_procinfo }
  994. if assigned(oldprocinfo.inlining_procinfo) then
  995. current_procinfo.inlining_procinfo:=oldprocinfo.inlining_procinfo
  996. else
  997. current_procinfo.inlining_procinfo:=oldprocinfo;
  998. { takes care of local data initialization }
  999. inlineentrycode:=TAAsmoutput.Create;
  1000. inlineexitcode:=TAAsmoutput.Create;
  1001. {$ifdef GDB}
  1002. if (cs_debuginfo in aktmoduleswitches) and
  1003. not(cs_gdb_valgrind in aktglobalswitches) then
  1004. begin
  1005. objectlibrary.getaddrlabel(startlabel);
  1006. objectlibrary.getaddrlabel(endlabel);
  1007. cg.a_label(exprasmlist,startlabel);
  1008. { Here we must include the para and local symtable info }
  1009. procdefinition.concatstabto(withdebuglist);
  1010. mangled_length:=length(current_procinfo.inlining_procinfo.procdef.mangledname);
  1011. getmem(pp,mangled_length+50);
  1012. strpcopy(pp,'192,0,0,'+startlabel.name);
  1013. if (target_info.use_function_relative_addresses) then
  1014. begin
  1015. strpcopy(strend(pp),'-');
  1016. strpcopy(strend(pp),current_procinfo.inlining_procinfo.procdef.mangledname);
  1017. end;
  1018. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1019. end;
  1020. {$endif GDB}
  1021. gen_load_para_value(inlineentrycode);
  1022. { now that we've loaded the para's, free them }
  1023. freeparas;
  1024. gen_initialize_code(inlineentrycode);
  1025. if po_assembler in current_procinfo.procdef.procoptions then
  1026. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  1027. exprasmList.concatlist(inlineentrycode);
  1028. { process the inline code }
  1029. secondpass(inlinecode);
  1030. cg.a_label(exprasmlist,current_procinfo.aktexitlabel);
  1031. gen_finalize_code(inlineexitcode);
  1032. gen_load_return_value(inlineexitcode);
  1033. if po_assembler in current_procinfo.procdef.procoptions then
  1034. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  1035. exprasmlist.concatlist(inlineexitcode);
  1036. inlineentrycode.free;
  1037. inlineexitcode.free;
  1038. {$ifdef extdebug}
  1039. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  1040. {$endif extdebug}
  1041. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1042. { handle function results }
  1043. if (not is_void(resulttype.def)) then
  1044. handle_return_value
  1045. else
  1046. location_reset(location,LOC_VOID,OS_NO);
  1047. { perhaps i/o check ? }
  1048. if (cs_check_io in aktlocalswitches) and
  1049. (po_iocheck in procdefinition.procoptions) and
  1050. not(po_iocheck in current_procinfo.procdef.procoptions) and
  1051. { no IO check for methods and procedure variables }
  1052. (right=nil) and
  1053. not(po_virtualmethod in procdefinition.procoptions) then
  1054. begin
  1055. cg.alloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1056. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1057. cg.dealloccpuregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1058. end;
  1059. { release temps of paras }
  1060. release_para_temps;
  1061. { if return value is not used }
  1062. if (not is_void(resulttype.def)) and
  1063. (not(cnf_return_value_used in callnodeflags)) then
  1064. begin
  1065. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1066. begin
  1067. { data which must be finalized ? }
  1068. if (resulttype.def.needs_inittable) then
  1069. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1070. { release unused temp }
  1071. tg.ungetiftemp(exprasmlist,location.reference)
  1072. end
  1073. else if location.loc=LOC_FPUREGISTER then
  1074. begin
  1075. {$ifdef x86}
  1076. { release FPU stack }
  1077. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  1078. {$endif x86}
  1079. end;
  1080. end;
  1081. { Release parameters and locals }
  1082. gen_free_parast(exprasmlist,tparasymtable(current_procinfo.procdef.parast));
  1083. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  1084. gen_free_localst(exprasmlist,tlocalsymtable(current_procinfo.procdef.localst));
  1085. {$ifdef GDB}
  1086. if (cs_debuginfo in aktmoduleswitches) and
  1087. not(cs_gdb_valgrind in aktglobalswitches) then
  1088. begin
  1089. cg.a_label(exprasmlist,endlabel);
  1090. strpcopy(pp,'224,0,0,'+endlabel.name);
  1091. if (target_info.use_function_relative_addresses) then
  1092. begin
  1093. strpcopy(strend(pp),'-');
  1094. strpcopy(strend(pp),current_procinfo.inlining_procinfo.procdef.mangledname);
  1095. end;
  1096. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1097. freemem(pp,mangled_length+50);
  1098. end;
  1099. {$endif GDB}
  1100. { restore }
  1101. current_procinfo.aktlocaldata:=nil;
  1102. current_procinfo.destroy;
  1103. current_procinfo:=oldprocinfo;
  1104. inlining_procedure:=oldinlining_procedure;
  1105. end;
  1106. procedure tcgcallnode.pass_2;
  1107. begin
  1108. if assigned(methodpointerinit) then
  1109. secondpass(methodpointerinit);
  1110. if assigned(inlinecode) then
  1111. inlined_pass_2
  1112. else
  1113. normal_pass_2;
  1114. if assigned(methodpointerdone) then
  1115. secondpass(methodpointerdone);
  1116. end;
  1117. begin
  1118. ccallparanode:=tcgcallparanode;
  1119. ccallnode:=tcgcallnode;
  1120. end.
  1121. {
  1122. $Log$
  1123. Revision 1.176 2004-09-27 15:15:20 peter
  1124. * dealloc function result registers, register allocation is now
  1125. back at pre-paraloc level
  1126. Revision 1.175 2004/09/25 14:23:54 peter
  1127. * ungetregister is now only used for cpuregisters, renamed to
  1128. ungetcpuregister
  1129. * renamed (get|unget)explicitregister(s) to ..cpuregister
  1130. * removed location-release/reference_release
  1131. Revision 1.174 2004/09/21 17:25:12 peter
  1132. * paraloc branch merged
  1133. Revision 1.173.4.3 2004/09/20 20:46:34 peter
  1134. * register allocation optimized for 64bit loading of parameters
  1135. and return values
  1136. Revision 1.173.4.2 2004/09/17 17:19:26 peter
  1137. * fixed 64 bit unaryminus for sparc
  1138. * fixed 64 bit inlining
  1139. * signness of not operation
  1140. Revision 1.173.4.1 2004/08/31 20:43:06 peter
  1141. * paraloc patch
  1142. Revision 1.173 2004/07/12 10:47:42 michael
  1143. + Fix for bug 3207 from Peter
  1144. Revision 1.172 2004/07/11 19:01:13 peter
  1145. * comps are passed in int registers
  1146. Revision 1.171 2004/07/09 23:41:04 jonas
  1147. * support register parameters for inlined procedures + some inline
  1148. cleanups
  1149. Revision 1.170 2004/06/29 20:56:46 peter
  1150. * constructors don't return in parameter
  1151. Revision 1.169 2004/06/20 08:55:29 florian
  1152. * logs truncated
  1153. Revision 1.168 2004/06/16 20:07:08 florian
  1154. * dwarf branch merged
  1155. Revision 1.167 2004/05/23 18:28:41 peter
  1156. * methodpointer is loaded into a temp when it was a calln
  1157. Revision 1.166 2004/05/22 23:34:27 peter
  1158. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1159. Revision 1.165 2004/04/28 15:19:03 florian
  1160. + syscall directive support for MorphOS added
  1161. Revision 1.164.2.13 2004/06/12 17:01:01 florian
  1162. * fixed compilation of arm compiler
  1163. }