ncgcal.pas 54 KB

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