cpupara.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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]) and
  273. ((usedef.typ=recorddef) or
  274. is_object(usedef)) and
  275. tabstractrecordsymtable(tabstractrecorddef(usedef).symtable).has_single_field(sym) and
  276. (sym.vardef.typ=floatdef) and
  277. (tfloatdef(sym.vardef).floattype in [s32real,s64real]) then
  278. usedef:=sym.vardef;
  279. handled:=set_common_funcretloc_info(p,usedef,retcgsize,result);
  280. { normally forcetempdef is passed straight through to
  281. set_common_funcretloc_info and that one will correctly determine whether
  282. the location is a temporary one, but that doesn't work here because we
  283. sometimes have to change the type }
  284. result.temporary:=assigned(forcetempdef);
  285. if handled then
  286. exit;
  287. { darwin/x86 requires that results < sizeof(aint) are sign/zero
  288. extended to sizeof(aint) }
  289. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) and
  290. (side=calleeside) and
  291. (result.intsize>0) and
  292. (result.intsize<sizeof(aint)) then
  293. begin
  294. result.def:=sinttype;
  295. result.intsize:=sizeof(aint);
  296. retcgsize:=OS_SINT;
  297. result.size:=retcgsize;
  298. end;
  299. { Return in FPU register? }
  300. if result.def.typ=floatdef then
  301. begin
  302. paraloc:=result.add_location;
  303. paraloc^.loc:=LOC_FPUREGISTER;
  304. paraloc^.register:=NR_FPU_RESULT_REG;
  305. paraloc^.size:=retcgsize;
  306. paraloc^.def:=result.def;
  307. end
  308. else
  309. { Return in register }
  310. begin
  311. paraloc:=result.add_location;
  312. paraloc^.loc:=LOC_REGISTER;
  313. if retcgsize in [OS_64,OS_S64] then
  314. begin
  315. { low 32bits }
  316. if side=callerside then
  317. paraloc^.register:=NR_FUNCTION_RESULT64_LOW_REG
  318. else
  319. paraloc^.register:=NR_FUNCTION_RETURN64_LOW_REG;
  320. paraloc^.size:=OS_32;
  321. paraloc^.def:=u32inttype;
  322. { high 32bits }
  323. paraloc:=result.add_location;
  324. paraloc^.loc:=LOC_REGISTER;
  325. if side=callerside then
  326. paraloc^.register:=NR_FUNCTION_RESULT64_HIGH_REG
  327. else
  328. paraloc^.register:=NR_FUNCTION_RETURN64_HIGH_REG;
  329. paraloc^.size:=OS_32;
  330. paraloc^.def:=u32inttype;
  331. end
  332. else
  333. begin
  334. paraloc^.size:=retcgsize;
  335. paraloc^.def:=result.def;
  336. if side=callerside then
  337. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RESULT_REG,cgsize2subreg(R_INTREGISTER,retcgsize))
  338. else
  339. paraloc^.register:=newreg(R_INTREGISTER,RS_FUNCTION_RETURN_REG,cgsize2subreg(R_INTREGISTER,retcgsize));
  340. end;
  341. end;
  342. end;
  343. procedure ti386paramanager.create_stdcall_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;var parasize:longint);
  344. var
  345. i : integer;
  346. hp : tparavarsym;
  347. paradef : tdef;
  348. paraloc : pcgparalocation;
  349. l,
  350. paralen,
  351. varalign : longint;
  352. paraalign : shortint;
  353. paracgsize : tcgsize;
  354. firstparaloc,
  355. pushaddr : boolean;
  356. begin
  357. paraalign:=get_para_align(p.proccalloption);
  358. { we push Flags and CS as long
  359. to cope with the IRETD
  360. and we save 6 register + 4 selectors }
  361. if po_interrupt in p.procoptions then
  362. inc(parasize,8+6*4+4*2);
  363. { Offset is calculated like:
  364. sub esp,12
  365. mov [esp+8],para3
  366. mov [esp+4],para2
  367. mov [esp],para1
  368. call function
  369. That means for pushes the para with the
  370. highest offset (see para3) needs to be pushed first
  371. }
  372. if p.proccalloption in pushleftright_pocalls then
  373. i:=paras.count-1
  374. else
  375. i:=0;
  376. while ((p.proccalloption in pushleftright_pocalls) and (i>=0)) or
  377. (not(p.proccalloption in pushleftright_pocalls) and (i<=paras.count-1)) do
  378. begin
  379. hp:=tparavarsym(paras[i]);
  380. paradef:=hp.vardef;
  381. pushaddr:=push_addr_param(hp.varspez,paradef,p.proccalloption);
  382. if pushaddr then
  383. begin
  384. paralen:=sizeof(aint);
  385. paracgsize:=OS_ADDR;
  386. paradef:=getpointerdef(paradef);
  387. end
  388. else
  389. begin
  390. paralen:=push_size(hp.varspez,paradef,p.proccalloption);
  391. { darwin/x86 requires that parameters < sizeof(aint) are sign/ }
  392. { zero extended to sizeof(aint) }
  393. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) and
  394. (side = callerside) and
  395. (paralen > 0) and
  396. (paralen < sizeof(aint)) then
  397. begin
  398. paralen:=sizeof(aint);
  399. paracgsize:=OS_SINT;
  400. paradef:=sinttype;
  401. end
  402. else
  403. paracgsize:=def_cgsize(paradef);
  404. end;
  405. hp.paraloc[side].reset;
  406. hp.paraloc[side].size:=paracgsize;
  407. hp.paraloc[side].intsize:=paralen;
  408. hp.paraloc[side].def:=paradef;
  409. hp.paraloc[side].Alignment:=paraalign;
  410. { Copy to stack? }
  411. if (paracgsize=OS_NO) or
  412. (use_fixed_stack) then
  413. begin
  414. paraloc:=hp.paraloc[side].add_location;
  415. paraloc^.loc:=LOC_REFERENCE;
  416. paraloc^.size:=paracgsize;
  417. paraloc^.def:=paradef;
  418. if side=callerside then
  419. paraloc^.reference.index:=NR_STACK_POINTER_REG
  420. else
  421. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  422. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  423. { don't let push_size return 16, because then we can }
  424. { read past the end of the heap since the value is only }
  425. { 10 bytes long (JM) }
  426. if (paracgsize = OS_F80) and
  427. (target_info.system in [system_i386_darwin,system_i386_iphonesim]) then
  428. paralen:=16;
  429. paraloc^.reference.offset:=parasize;
  430. if side=calleeside then
  431. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  432. parasize:=align(parasize+paralen,varalign);
  433. end
  434. else
  435. begin
  436. if paralen=0 then
  437. internalerror(200501163);
  438. firstparaloc:=true;
  439. while (paralen>0) do
  440. begin
  441. paraloc:=hp.paraloc[side].add_location;
  442. paraloc^.loc:=LOC_REFERENCE;
  443. { single and double need a single location }
  444. if (paracgsize in [OS_F64,OS_F32]) then
  445. begin
  446. paraloc^.size:=paracgsize;
  447. paraloc^.def:=paradef;
  448. l:=paralen;
  449. end
  450. else
  451. begin
  452. { We can allocate at maximum 32 bits per location }
  453. if paralen>sizeof(aint) then
  454. begin
  455. l:=sizeof(aint);
  456. paraloc^.def:=uinttype;
  457. end
  458. else
  459. begin
  460. l:=paralen;
  461. paraloc^.def:=get_paraloc_def(paradef,l,firstparaloc);
  462. end;
  463. paraloc^.size:=int_cgsize(l);
  464. end;
  465. if (side=callerside) or
  466. (po_nostackframe in p.procoptions) then
  467. paraloc^.reference.index:=NR_STACK_POINTER_REG
  468. else
  469. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  470. varalign:=used_align(size_2_align(l),paraalign,paraalign);
  471. paraloc^.reference.offset:=parasize;
  472. if side=calleeside then
  473. if not(po_nostackframe in p.procoptions) then
  474. inc(paraloc^.reference.offset,target_info.first_parm_offset)
  475. else
  476. { return addres }
  477. inc(paraloc^.reference.offset,4);
  478. parasize:=align(parasize+l,varalign);
  479. dec(paralen,l);
  480. firstparaloc:=false;
  481. end;
  482. end;
  483. if p.proccalloption in pushleftright_pocalls then
  484. dec(i)
  485. else
  486. inc(i);
  487. end;
  488. end;
  489. procedure ti386paramanager.create_register_paraloc_info(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  490. var parareg,parasize:longint);
  491. var
  492. hp : tparavarsym;
  493. paradef : tdef;
  494. paraloc : pcgparalocation;
  495. paracgsize : tcgsize;
  496. i : integer;
  497. l,
  498. paralen,
  499. varalign : longint;
  500. paraalign : shortint;
  501. pass : byte;
  502. firstparaloc,
  503. pushaddr : boolean;
  504. begin
  505. if paras.count=0 then
  506. exit;
  507. paraalign:=get_para_align(p.proccalloption);
  508. { clean up here so we can later detect properly if a parameter has been
  509. assigned or not
  510. }
  511. for i:=0 to paras.count-1 do
  512. tparavarsym(paras[i]).paraloc[side].reset;
  513. { Register parameters are assigned from left to right,
  514. stack parameters from right to left so assign first the
  515. register parameters in a first pass, in the second
  516. pass all unhandled parameters are done }
  517. for pass:=1 to 2 do
  518. begin
  519. if pass=1 then
  520. i:=0
  521. else
  522. i:=paras.count-1;
  523. while true do
  524. begin
  525. hp:=tparavarsym(paras[i]);
  526. paradef:=hp.vardef;
  527. if not(assigned(hp.paraloc[side].location)) then
  528. begin
  529. pushaddr:=push_addr_param(hp.varspez,hp.vardef,p.proccalloption);
  530. if pushaddr then
  531. begin
  532. paralen:=sizeof(aint);
  533. paracgsize:=OS_ADDR;
  534. paradef:=getpointerdef(paradef);
  535. end
  536. else
  537. begin
  538. paralen:=push_size(hp.varspez,hp.vardef,p.proccalloption);
  539. paracgsize:=def_cgsize(hp.vardef);
  540. end;
  541. hp.paraloc[side].size:=paracgsize;
  542. hp.paraloc[side].intsize:=paralen;
  543. hp.paraloc[side].Alignment:=paraalign;
  544. hp.paraloc[side].def:=paradef;
  545. {
  546. EAX
  547. EDX
  548. ECX
  549. Stack
  550. Stack
  551. 64bit values,floats,arrays and records are always
  552. on the stack.
  553. In case of po_delphi_nested_cc, the parent frame pointer
  554. is also always passed on the stack.
  555. }
  556. if (parareg<=high(parasupregs)) and
  557. (paralen<=sizeof(aint)) and
  558. (not(hp.vardef.typ in [floatdef,recorddef,arraydef]) or
  559. pushaddr) and
  560. (not(vo_is_parentfp in hp.varoptions) or
  561. not(po_delphi_nested_cc in p.procoptions)) then
  562. begin
  563. if pass=1 then
  564. begin
  565. paraloc:=hp.paraloc[side].add_location;
  566. paraloc^.size:=paracgsize;
  567. paraloc^.def:=paradef;
  568. paraloc^.loc:=LOC_REGISTER;
  569. paraloc^.register:=newreg(R_INTREGISTER,parasupregs[parareg],cgsize2subreg(R_INTREGISTER,paracgsize));
  570. inc(parareg);
  571. end;
  572. end
  573. else
  574. if pass=2 then
  575. begin
  576. { Copy to stack? }
  577. if (use_fixed_stack) or
  578. (paracgsize=OS_NO) then
  579. begin
  580. paraloc:=hp.paraloc[side].add_location;
  581. paraloc^.loc:=LOC_REFERENCE;
  582. paraloc^.size:=paracgsize;
  583. paraloc^.def:=paradef;
  584. if side=callerside then
  585. paraloc^.reference.index:=NR_STACK_POINTER_REG
  586. else
  587. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  588. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  589. paraloc^.reference.offset:=parasize;
  590. if side=calleeside then
  591. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  592. parasize:=align(parasize+paralen,varalign);
  593. end
  594. else
  595. begin
  596. if paralen=0 then
  597. internalerror(200501163);
  598. firstparaloc:=true;
  599. while (paralen>0) do
  600. begin
  601. paraloc:=hp.paraloc[side].add_location;
  602. paraloc^.loc:=LOC_REFERENCE;
  603. { Extended and double need a single location }
  604. if (paracgsize in [OS_F64,OS_F32]) then
  605. begin
  606. paraloc^.size:=paracgsize;
  607. paraloc^.def:=paradef;
  608. l:=paralen;
  609. end
  610. else
  611. begin
  612. { We can allocate at maximum 32 bits per location }
  613. if paralen>sizeof(aint) then
  614. begin
  615. l:=sizeof(aint);
  616. paraloc^.def:=uinttype;
  617. end
  618. else
  619. begin
  620. l:=paralen;
  621. paraloc^.def:=get_paraloc_def(paradef,l,firstparaloc);
  622. end;
  623. paraloc^.size:=int_cgsize(l);
  624. end;
  625. if side=callerside then
  626. paraloc^.reference.index:=NR_STACK_POINTER_REG
  627. else
  628. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  629. varalign:=used_align(size_2_align(l),paraalign,paraalign);
  630. paraloc^.reference.offset:=parasize;
  631. if side=calleeside then
  632. inc(paraloc^.reference.offset,target_info.first_parm_offset);
  633. parasize:=align(parasize+l,varalign);
  634. dec(paralen,l);
  635. firstparaloc:=false;
  636. end;
  637. end;
  638. end;
  639. end;
  640. case pass of
  641. 1:
  642. begin
  643. if i=paras.count-1 then
  644. break;
  645. inc(i);
  646. end;
  647. 2:
  648. begin
  649. if i=0 then
  650. break;
  651. dec(i);
  652. end;
  653. end;
  654. end;
  655. end;
  656. end;
  657. function ti386paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  658. var
  659. parasize,
  660. parareg : longint;
  661. begin
  662. parasize:=0;
  663. parareg:=0;
  664. case p.proccalloption of
  665. pocall_register :
  666. create_register_paraloc_info(p,side,p.paras,parareg,parasize);
  667. pocall_internproc :
  668. begin
  669. { Use default calling }
  670. {$warnings off}
  671. if (pocall_default=pocall_register) then
  672. create_register_paraloc_info(p,side,p.paras,parareg,parasize)
  673. else
  674. create_stdcall_paraloc_info(p,side,p.paras,parasize);
  675. {$warnings on}
  676. end;
  677. else
  678. create_stdcall_paraloc_info(p,side,p.paras,parasize);
  679. end;
  680. create_funcretloc_info(p,side);
  681. result:=parasize;
  682. end;
  683. function ti386paramanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  684. var
  685. parasize : longint;
  686. begin
  687. parasize:=0;
  688. { calculate the registers for the normal parameters }
  689. create_stdcall_paraloc_info(p,callerside,p.paras,parasize);
  690. { append the varargs }
  691. create_stdcall_paraloc_info(p,callerside,varargspara,parasize);
  692. result:=parasize;
  693. end;
  694. procedure ti386paramanager.createtempparaloc(list: TAsmList;calloption : tproccalloption;parasym : tparavarsym;can_use_final_stack_loc : boolean;var cgpara:TCGPara);
  695. begin
  696. { Never a need for temps when value is pushed (calls inside parameters
  697. will simply allocate even more stack space for their parameters) }
  698. if not(use_fixed_stack) then
  699. can_use_final_stack_loc:=true;
  700. inherited createtempparaloc(list,calloption,parasym,can_use_final_stack_loc,cgpara);
  701. end;
  702. begin
  703. paramanager:=ti386paramanager.create;
  704. end.