ncgcal.pas 51 KB

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