ncgcal.pas 55 KB

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