cpupara.pas 29 KB

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