ncgcal.pas 54 KB

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