ncgcal.pas 53 KB

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