cpupara.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Generates the argument location information for i386
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cpupara;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. aasmtai,aasmdata,cpubase,cgbase,cgutils,
  23. symconst,symtype,symsym,symdef,
  24. parabase,paramgr;
  25. type
  26. ti386paramanager = class(tparamanager)
  27. function param_use_paraloc(const cgpara:tcgpara):boolean;override;
  28. function ret_in_param(def:tdef;pd:tabstractprocdef):boolean;override;
  29. function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
  30. function get_para_align(calloption : tproccalloption):byte;override;
  31. function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
  32. function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
  33. function get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;override;
  34. function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
  35. function create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;override;
  36. procedure createtempparaloc(list: TAsmList;calloption : tproccalloption;parasym : tparavarsym;can_use_final_stack_loc : boolean;var cgpara:TCGPara);override;
  37. function get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): TCGPara;override;
  38. private
  39. procedure create_stdcall_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;var parasize:longint);
  40. procedure create_register_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;var parareg,parasize:longint);
  41. end;
  42. implementation
  43. uses
  44. cutils,
  45. systems,verbose,
  46. symtable,
  47. defutil;
  48. const
  49. parasupregs : array[0..2] of tsuperregister = (RS_EAX,RS_EDX,RS_ECX);
  50. {****************************************************************************
  51. TI386PARAMANAGER
  52. ****************************************************************************}
  53. function ti386paramanager.param_use_paraloc(const cgpara:tcgpara):boolean;
  54. var
  55. paraloc : pcgparalocation;
  56. begin
  57. if not assigned(cgpara.location) then
  58. internalerror(200410102);
  59. result:=true;
  60. { All locations are LOC_REFERENCE }
  61. paraloc:=cgpara.location;
  62. while assigned(paraloc) do
  63. begin
  64. if (paraloc^.loc<>LOC_REFERENCE) then
  65. begin
  66. result:=false;
  67. exit;
  68. end;
  69. paraloc:=paraloc^.next;
  70. end;
  71. end;
  72. function ti386paramanager.ret_in_param(def:tdef;pd:tabstractprocdef):boolean;
  73. var
  74. size: longint;
  75. begin
  76. if handle_common_ret_in_param(def,pd,result) then
  77. exit;
  78. case target_info.system of
  79. system_i386_win32 :
  80. begin
  81. case def.typ of
  82. recorddef :
  83. begin
  84. { Win32 GCC returns small records in the FUNCTION_RETURN_REG up to 8 bytes in registers.
  85. For stdcall and register we follow delphi instead of GCC which returns
  86. only records of a size of 1,2 or 4 bytes in FUNCTION_RETURN_REG }
  87. if ((pd.proccalloption in [pocall_stdcall,pocall_register]) and
  88. (def.size in [1,2,4])) or
  89. ((pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  90. (def.size>0) and
  91. (def.size<=8)) then
  92. begin
  93. result:=false;
  94. exit;
  95. end;
  96. end;
  97. end;
  98. end;
  99. system_i386_os2,
  100. system_i386_emx:
  101. begin
  102. case def.typ of
  103. recorddef :
  104. begin
  105. { EMX port of GCC returns small records in the FUNCTION_RETURN_REG up to 4 bytes in registers. }
  106. if ((pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  107. (def.size>0) and
  108. (def.size<=4)) then
  109. begin
  110. result:=false;
  111. exit;
  112. end;
  113. end;
  114. end;
  115. end;
  116. system_i386_freebsd,
  117. system_i386_openbsd,
  118. system_i386_darwin,
  119. system_i386_iphonesim :
  120. begin
  121. if pd.proccalloption in cdecl_pocalls then
  122. begin
  123. case def.typ of
  124. recorddef :
  125. begin
  126. size:=def.size;
  127. if (size>0) and
  128. (size<=8) and
  129. { only if size is a power of 2 }
  130. ((size and (size-1)) = 0) then
  131. begin
  132. result:=false;
  133. exit;
  134. end;
  135. end;
  136. procvardef:
  137. begin
  138. result:=false;
  139. exit;
  140. end;
  141. end;
  142. end;
  143. end;
  144. end;
  145. result:=inherited ret_in_param(def,pd);
  146. end;
  147. function ti386paramanager.push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;
  148. begin
  149. result:=false;
  150. { var,out,constref always require address }
  151. if varspez in [vs_var,vs_out,vs_constref] then
  152. begin
  153. result:=true;
  154. exit;
  155. end;
  156. { Only vs_const, vs_value here }
  157. case def.typ of
  158. variantdef :
  159. begin
  160. { variants are small enough to be passed by value except if
  161. required by the windows api
  162. variants are somethings very delphi/windows specific so do it like
  163. windows/delphi (FK)
  164. }
  165. if ((target_info.system=system_i386_win32) and
  166. (calloption in [pocall_stdcall,pocall_safecall]) and
  167. (varspez=vs_const)) or
  168. (calloption=pocall_register) then
  169. result:=true
  170. else
  171. result:=false;
  172. end;
  173. formaldef :
  174. result:=true;
  175. recorddef :
  176. begin
  177. { Delphi stdcall passes records on the stack for call by value }
  178. if (target_info.system=system_i386_win32) and
  179. (calloption=pocall_stdcall) and
  180. (varspez=vs_value) then
  181. result:=false
  182. else
  183. result:=
  184. (not(calloption in (cdecl_pocalls)) and
  185. (def.size>sizeof(aint))) or
  186. (((calloption = pocall_mwpascal) or (target_info.system=system_i386_wince)) and
  187. (varspez=vs_const));
  188. end;
  189. arraydef :
  190. begin
  191. { array of const values are pushed on the stack as
  192. well as dyn. arrays }
  193. if (calloption in cdecl_pocalls) then
  194. result:=not(is_array_of_const(def) or
  195. is_dynamic_array(def))
  196. else
  197. begin
  198. result:=(
  199. (tarraydef(def).highrange>=tarraydef(def).lowrange) and
  200. (def.size>sizeof(aint))
  201. ) or
  202. is_open_array(def) or
  203. is_array_of_const(def) or
  204. is_array_constructor(def);
  205. end;
  206. end;
  207. objectdef :
  208. result:=is_object(def);
  209. stringdef :
  210. result:= (tstringdef(def).stringtype in [st_shortstring,st_longstring]);
  211. procvardef :
  212. result:=not(calloption in cdecl_pocalls) and not tprocvardef(def).is_addressonly;
  213. setdef :
  214. result:=not(calloption in cdecl_pocalls) and (not is_smallset(def));
  215. end;
  216. end;
  217. function ti386paramanager.get_para_align(calloption : tproccalloption):byte;
  218. begin
  219. if calloption=pocall_oldfpccall then
  220. begin
  221. if target_info.system in [system_i386_go32v2,system_i386_watcom] then
  222. result:=2
  223. else
  224. result:=4;
  225. end
  226. else
  227. result:=std_param_align;
  228. end;
  229. function ti386paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  230. begin
  231. case calloption of
  232. pocall_internproc :
  233. result:=[];
  234. pocall_register,
  235. pocall_safecall,
  236. pocall_stdcall,
  237. pocall_cdecl,
  238. pocall_syscall,
  239. pocall_cppdecl,
  240. pocall_mwpascal :
  241. result:=[RS_EAX,RS_EDX,RS_ECX];
  242. pocall_far16,
  243. pocall_pascal,
  244. pocall_oldfpccall :
  245. result:=[RS_EAX,RS_EDX,RS_ECX,RS_ESI,RS_EDI,RS_EBX];
  246. else
  247. internalerror(200309071);
  248. end;
  249. end;
  250. function ti386paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  251. begin
  252. result:=[0..first_fpu_imreg-1];
  253. end;
  254. function ti386paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
  255. begin
  256. result:=[0..first_mm_imreg-1];
  257. end;
  258. function ti386paramanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): TCGPara;
  259. var
  260. retcgsize : tcgsize;
  261. paraloc : pcgparalocation;
  262. sym: tfieldvarsym;
  263. usedef: tdef;
  264. handled: boolean;
  265. begin
  266. if not assigned(forcetempdef) then
  267. usedef:=p.returndef
  268. else
  269. usedef:=forcetempdef;
  270. { on darwin/i386, if a record has only one field and that field is a
  271. single or double, it has to be returned like a single/double }
  272. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,
  273. system_i386_freebsd,system_i386_openbsd,system_i386_os2]) and
  274. ((usedef.typ=recorddef) or
  275. is_object(usedef)) and
  276. tabstractrecordsymtable(tabstractrecorddef(usedef).symtable).has_single_field(sym) and
  277. (sym.vardef.typ=floatdef) and
  278. (tfloatdef(sym.vardef).floattype in [s32real,s64real]) then
  279. usedef:=sym.vardef;
  280. handled:=set_common_funcretloc_info(p,usedef,retcgsize,result);
  281. { normally forcetempdef is passed straight through to
  282. set_common_funcretloc_info and that one will correctly determine whether
  283. the location is a temporary one, but that doesn't work here because we
  284. sometimes have to change the type }
  285. result.temporary:=assigned(forcetempdef);
  286. if handled then
  287. exit;
  288. { darwin/x86 requires that results < sizeof(aint) are sign/zero
  289. extended to sizeof(aint) }
  290. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) and
  291. (side=calleeside) and
  292. (result.intsize>0) and
  293. (result.intsize<sizeof(aint)) then
  294. begin
  295. result.def:=sinttype;
  296. result.intsize:=sizeof(aint);
  297. retcgsize:=OS_SINT;
  298. result.size:=retcgsize;
  299. end;
  300. { Return in FPU register? }
  301. if result.def.typ=floatdef then
  302. begin
  303. paraloc:=result.add_location;
  304. paraloc^.loc:=LOC_FPUREGISTER;
  305. paraloc^.register:=NR_FPU_RESULT_REG;
  306. paraloc^.size:=retcgsize;
  307. paraloc^.def:=result.def;
  308. end
  309. else
  310. { Return in register }
  311. begin
  312. paraloc:=result.add_location;
  313. paraloc^.loc:=LOC_REGISTER;
  314. if retcgsize in [OS_64,OS_S64] then
  315. begin
  316. { low 32bits }
  317. if side=callerside then
  318. paraloc^.register:=NR_FUNCTION_RESULT64_LOW_REG
  319. else
  320. paraloc^.register:=NR_FUNCTION_RETURN64_LOW_REG;
  321. paraloc^.size:=OS_32;
  322. paraloc^.def:=u32inttype;
  323. { high 32bits }
  324. paraloc:=result.add_location;
  325. paraloc^.loc:=LOC_REGISTER;
  326. if side=callerside then
  327. paraloc^.register:=NR_FUNCTION_RESULT64_HIGH_REG
  328. else
  329. paraloc^.register:=NR_FUNCTION_RETURN64_HIGH_REG;
  330. paraloc^.size:=OS_32;
  331. paraloc^.def:=u32inttype;
  332. end
  333. else
  334. begin
  335. paraloc^.size:=retcgsize;
  336. paraloc^.def:=result.def;
  337. if side=callerside then
  338. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RESULT_REG,cgsize2subreg(R_INTREGISTER,retcgsize))
  339. else
  340. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RETURN_REG,cgsize2subreg(R_INTREGISTER,retcgsize));
  341. end;
  342. end;
  343. end;
  344. procedure ti386paramanager.create_stdcall_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;var parasize:longint);
  345. var
  346. i : integer;
  347. hp : tparavarsym;
  348. paradef : tdef;
  349. paraloc : pcgparalocation;
  350. l,
  351. paralen,
  352. varalign : longint;
  353. paraalign : shortint;
  354. paracgsize : tcgsize;
  355. firstparaloc,
  356. pushaddr : boolean;
  357. begin
  358. paraalign:=get_para_align(p.proccalloption);
  359. { we push Flags and CS as long
  360. to cope with the IRETD
  361. and we save 6 register + 4 selectors }
  362. if po_interrupt in p.procoptions then
  363. inc(parasize,8+6*4+4*2);
  364. { Offset is calculated like:
  365. sub esp,12
  366. mov [esp+8],para3
  367. mov [esp+4],para2
  368. mov [esp],para1
  369. call function
  370. That means for pushes the para with the
  371. highest offset (see para3) needs to be pushed first
  372. }
  373. if p.proccalloption in pushleftright_pocalls then
  374. i:=paras.count-1
  375. else
  376. i:=0;
  377. while ((p.proccalloption in pushleftright_pocalls) and (i>=0)) or
  378. (not(p.proccalloption in pushleftright_pocalls) and (i<=paras.count-1)) do
  379. begin
  380. hp:=tparavarsym(paras[i]);
  381. paradef:=hp.vardef;
  382. pushaddr:=push_addr_param(hp.varspez,paradef,p.proccalloption);
  383. if pushaddr then
  384. begin
  385. paralen:=sizeof(aint);
  386. paracgsize:=OS_ADDR;
  387. paradef:=getpointerdef(paradef);
  388. end
  389. else
  390. begin
  391. paralen:=push_size(hp.varspez,paradef,p.proccalloption);
  392. { darwin/x86 requires that parameters < sizeof(aint) are sign/ }
  393. { zero extended to sizeof(aint) }
  394. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) and
  395. (side = callerside) and
  396. (paralen > 0) and
  397. (paralen < sizeof(aint)) then
  398. begin
  399. paralen:=sizeof(aint);
  400. paracgsize:=OS_SINT;
  401. paradef:=sinttype;
  402. end
  403. else
  404. paracgsize:=def_cgsize(paradef);
  405. end;
  406. hp.paraloc[side].reset;
  407. hp.paraloc[side].size:=paracgsize;
  408. hp.paraloc[side].intsize:=paralen;
  409. hp.paraloc[side].def:=paradef;
  410. hp.paraloc[side].Alignment:=paraalign;
  411. { Copy to stack? }
  412. if (paracgsize=OS_NO) or
  413. (use_fixed_stack) then
  414. begin
  415. paraloc:=hp.paraloc[side].add_location;
  416. paraloc^.loc:=LOC_REFERENCE;
  417. paraloc^.size:=paracgsize;
  418. paraloc^.def:=paradef;
  419. if side=callerside then
  420. paraloc^.reference.index:=NR_STACK_POINTER_REG
  421. else
  422. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  423. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  424. { don't let push_size return 16, because then we can }
  425. { read past the end of the heap since the value is only }
  426. { 10 bytes long (JM) }
  427. if (paracgsize = OS_F80) and
  428. (target_info.system in [system_i386_darwin,system_i386_iphonesim]) then
  429. paralen:=16;
  430. paraloc^.reference.offset:=parasize;
  431. if side=calleeside then
  432. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  433. parasize:=align(parasize+paralen,varalign);
  434. end
  435. else
  436. begin
  437. if paralen=0 then
  438. internalerror(200501163);
  439. firstparaloc:=true;
  440. while (paralen>0) do
  441. begin
  442. paraloc:=hp.paraloc[side].add_location;
  443. paraloc^.loc:=LOC_REFERENCE;
  444. { single and double need a single location }
  445. if (paracgsize in [OS_F64,OS_F32]) then
  446. begin
  447. paraloc^.size:=paracgsize;
  448. paraloc^.def:=paradef;
  449. l:=paralen;
  450. end
  451. else
  452. begin
  453. { We can allocate at maximum 32 bits per location }
  454. if paralen>sizeof(aint) then
  455. begin
  456. l:=sizeof(aint);
  457. paraloc^.def:=uinttype;
  458. end
  459. else
  460. begin
  461. l:=paralen;
  462. paraloc^.def:=get_paraloc_def(paradef,l,firstparaloc);
  463. end;
  464. paraloc^.size:=int_cgsize(l);
  465. end;
  466. if (side=callerside) or
  467. (po_nostackframe in p.procoptions) then
  468. paraloc^.reference.index:=NR_STACK_POINTER_REG
  469. else
  470. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  471. varalign:=used_align(size_2_align(l),paraalign,paraalign);
  472. paraloc^.reference.offset:=parasize;
  473. if side=calleeside then
  474. if not(po_nostackframe in p.procoptions) then
  475. inc(paraloc^.reference.offset,target_info.first_parm_offset)
  476. else
  477. { return addres }
  478. inc(paraloc^.reference.offset,4);
  479. parasize:=align(parasize+l,varalign);
  480. dec(paralen,l);
  481. firstparaloc:=false;
  482. end;
  483. end;
  484. if p.proccalloption in pushleftright_pocalls then
  485. dec(i)
  486. else
  487. inc(i);
  488. end;
  489. end;
  490. procedure ti386paramanager.create_register_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  491. var parareg,parasize:longint);
  492. var
  493. hp : tparavarsym;
  494. paradef : tdef;
  495. paraloc : pcgparalocation;
  496. paracgsize : tcgsize;
  497. i : integer;
  498. l,
  499. paralen,
  500. varalign : longint;
  501. paraalign : shortint;
  502. pass : byte;
  503. firstparaloc,
  504. pushaddr : boolean;
  505. begin
  506. if paras.count=0 then
  507. exit;
  508. paraalign:=get_para_align(p.proccalloption);
  509. { clean up here so we can later detect properly if a parameter has been
  510. assigned or not
  511. }
  512. for i:=0 to paras.count-1 do
  513. tparavarsym(paras[i]).paraloc[side].reset;
  514. { Register parameters are assigned from left to right,
  515. stack parameters from right to left so assign first the
  516. register parameters in a first pass, in the second
  517. pass all unhandled parameters are done }
  518. for pass:=1 to 2 do
  519. begin
  520. if pass=1 then
  521. i:=0
  522. else
  523. i:=paras.count-1;
  524. while true do
  525. begin
  526. hp:=tparavarsym(paras[i]);
  527. paradef:=hp.vardef;
  528. if not(assigned(hp.paraloc[side].location)) then
  529. begin
  530. pushaddr:=push_addr_param(hp.varspez,hp.vardef,p.proccalloption);
  531. if pushaddr then
  532. begin
  533. paralen:=sizeof(aint);
  534. paracgsize:=OS_ADDR;
  535. paradef:=getpointerdef(paradef);
  536. end
  537. else
  538. begin
  539. paralen:=push_size(hp.varspez,hp.vardef,p.proccalloption);
  540. paracgsize:=def_cgsize(hp.vardef);
  541. end;
  542. hp.paraloc[side].size:=paracgsize;
  543. hp.paraloc[side].intsize:=paralen;
  544. hp.paraloc[side].Alignment:=paraalign;
  545. hp.paraloc[side].def:=paradef;
  546. {
  547. EAX
  548. EDX
  549. ECX
  550. Stack
  551. Stack
  552. 64bit values,floats,arrays and records are always
  553. on the stack.
  554. In case of po_delphi_nested_cc, the parent frame pointer
  555. is also always passed on the stack.
  556. }
  557. if (parareg<=high(parasupregs)) and
  558. (paralen<=sizeof(aint)) and
  559. (not(hp.vardef.typ in [floatdef,recorddef,arraydef]) or
  560. pushaddr) and
  561. (not(vo_is_parentfp in hp.varoptions) or
  562. not(po_delphi_nested_cc in p.procoptions)) then
  563. begin
  564. if pass=1 then
  565. begin
  566. paraloc:=hp.paraloc[side].add_location;
  567. paraloc^.size:=paracgsize;
  568. paraloc^.def:=paradef;
  569. paraloc^.loc:=LOC_REGISTER;
  570. paraloc^.register:=newreg(R_INTREGISTER,parasupregs[parareg],cgsize2subreg(R_INTREGISTER,paracgsize));
  571. inc(parareg);
  572. end;
  573. end
  574. else
  575. if pass=2 then
  576. begin
  577. { Copy to stack? }
  578. if (use_fixed_stack) or
  579. (paracgsize=OS_NO) then
  580. begin
  581. paraloc:=hp.paraloc[side].add_location;
  582. paraloc^.loc:=LOC_REFERENCE;
  583. paraloc^.size:=paracgsize;
  584. paraloc^.def:=paradef;
  585. if side=callerside then
  586. paraloc^.reference.index:=NR_STACK_POINTER_REG
  587. else
  588. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  589. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  590. paraloc^.reference.offset:=parasize;
  591. if side=calleeside then
  592. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  593. parasize:=align(parasize+paralen,varalign);
  594. end
  595. else
  596. begin
  597. if paralen=0 then
  598. internalerror(200501163);
  599. firstparaloc:=true;
  600. while (paralen>0) do
  601. begin
  602. paraloc:=hp.paraloc[side].add_location;
  603. paraloc^.loc:=LOC_REFERENCE;
  604. { Extended and double need a single location }
  605. if (paracgsize in [OS_F64,OS_F32]) then
  606. begin
  607. paraloc^.size:=paracgsize;
  608. paraloc^.def:=paradef;
  609. l:=paralen;
  610. end
  611. else
  612. begin
  613. { We can allocate at maximum 32 bits per location }
  614. if paralen>sizeof(aint) then
  615. begin
  616. l:=sizeof(aint);
  617. paraloc^.def:=uinttype;
  618. end
  619. else
  620. begin
  621. l:=paralen;
  622. paraloc^.def:=get_paraloc_def(paradef,l,firstparaloc);
  623. end;
  624. paraloc^.size:=int_cgsize(l);
  625. end;
  626. if side=callerside then
  627. paraloc^.reference.index:=NR_STACK_POINTER_REG
  628. else
  629. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  630. varalign:=used_align(size_2_align(l),paraalign,paraalign);
  631. paraloc^.reference.offset:=parasize;
  632. if side=calleeside then
  633. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  634. parasize:=align(parasize+l,varalign);
  635. dec(paralen,l);
  636. firstparaloc:=false;
  637. end;
  638. end;
  639. end;
  640. end;
  641. case pass of
  642. 1:
  643. begin
  644. if i=paras.count-1 then
  645. break;
  646. inc(i);
  647. end;
  648. 2:
  649. begin
  650. if i=0 then
  651. break;
  652. dec(i);
  653. end;
  654. end;
  655. end;
  656. end;
  657. end;
  658. function ti386paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  659. var
  660. parasize,
  661. parareg : longint;
  662. begin
  663. parasize:=0;
  664. parareg:=0;
  665. case p.proccalloption of
  666. pocall_register :
  667. create_register_paraloc_info(p,side,p.paras,parareg,parasize);
  668. pocall_internproc :
  669. begin
  670. { Use default calling }
  671. {$warnings off}
  672. if (pocall_default=pocall_register) then
  673. create_register_paraloc_info(p,side,p.paras,parareg,parasize)
  674. else
  675. create_stdcall_paraloc_info(p,side,p.paras,parasize);
  676. {$warnings on}
  677. end;
  678. else
  679. create_stdcall_paraloc_info(p,side,p.paras,parasize);
  680. end;
  681. create_funcretloc_info(p,side);
  682. result:=parasize;
  683. end;
  684. function ti386paramanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  685. var
  686. parasize : longint;
  687. begin
  688. parasize:=0;
  689. { calculate the registers for the normal parameters }
  690. create_stdcall_paraloc_info(p,callerside,p.paras,parasize);
  691. { append the varargs }
  692. create_stdcall_paraloc_info(p,callerside,varargspara,parasize);
  693. result:=parasize;
  694. end;
  695. procedure ti386paramanager.createtempparaloc(list: TAsmList;calloption : tproccalloption;parasym : tparavarsym;can_use_final_stack_loc : boolean;var cgpara:TCGPara);
  696. begin
  697. { Never a need for temps when value is pushed (calls inside parameters
  698. will simply allocate even more stack space for their parameters) }
  699. if not(use_fixed_stack) then
  700. can_use_final_stack_loc:=true;
  701. inherited createtempparaloc(list,calloption,parasym,can_use_final_stack_loc,cgpara);
  702. end;
  703. begin
  704. paramanager:=ti386paramanager.create;
  705. end.