ncgcal.pas 56 KB

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