paramgr.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. PowerPC specific calling conventions
  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. {# Parameter passing manager. Used to manage how
  19. parameters are passed to routines.
  20. }
  21. unit paramgr;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. cpubase,
  26. symtype,symdef;
  27. type
  28. {# This class defines some methods to take care of routine
  29. parameters. It should be overriden for each new processor
  30. }
  31. tparamanager = class
  32. {# Returns true if the return value can be put in accumulator }
  33. function ret_in_acc(def : tdef) : boolean;virtual;
  34. {# Returns true if the return value is actually a parameter
  35. pointer.
  36. }
  37. function ret_in_param(def : tdef) : boolean;virtual;
  38. function push_high_param(def : tdef) : boolean;virtual;
  39. {# Returns true if a parameter is too large to copy and only
  40. the address is pushed
  41. }
  42. function push_addr_param(def : tdef) : boolean;virtual;
  43. {# Returns a structure giving the information on
  44. the storage of the parameter (which must be
  45. an integer parameter)
  46. @param(nr Parameter number of routine, starting from 1)
  47. }
  48. function getintparaloc(nr : longint) : tparalocation;virtual;abstract;
  49. procedure create_param_loc_info(p : tabstractprocdef);virtual;abstract;
  50. {#
  51. Returns the location where the invisible parameter for structured
  52. function results will be passed.
  53. }
  54. function getfuncretloc(p : tabstractprocdef) : tparalocation;virtual;abstract;
  55. { Returns the self pointer for the give procdef
  56. function getfuncretloc(p : tabstractprocdef) : tparalocation;virtual;abstract;
  57. }
  58. end;
  59. procedure setparalocs(p : tprocdef);
  60. var
  61. paralocdummy : tparalocation;
  62. paramanager : tparamanager;
  63. implementation
  64. uses
  65. cpuinfo,
  66. symconst,symbase,symsym,
  67. rgobj,
  68. defbase;
  69. { true if the return value is in accumulator (EAX for i386), D0 for 68k }
  70. function tparamanager.ret_in_acc(def : tdef) : boolean;
  71. begin
  72. ret_in_acc:=(def.deftype in [orddef,pointerdef,enumdef,classrefdef]) or
  73. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_ansistring,st_widestring])) or
  74. ((def.deftype=procvardef) and not(po_methodpointer in tprocvardef(def).procoptions)) or
  75. ((def.deftype=objectdef) and not is_object(def)) or
  76. ((def.deftype=setdef) and (tsetdef(def).settype=smallset));
  77. end;
  78. { true if uses a parameter as return value }
  79. function tparamanager.ret_in_param(def : tdef) : boolean;
  80. begin
  81. ret_in_param:=(def.deftype in [arraydef,recorddef]) or
  82. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_shortstring,st_longstring])) or
  83. ((def.deftype=procvardef) and (po_methodpointer in tprocvardef(def).procoptions)) or
  84. ((def.deftype=objectdef) and is_object(def)) or
  85. (def.deftype=variantdef) or
  86. ((def.deftype=setdef) and (tsetdef(def).settype<>smallset));
  87. end;
  88. function tparamanager.push_high_param(def : tdef) : boolean;
  89. begin
  90. push_high_param:=is_open_array(def) or
  91. is_open_string(def) or
  92. is_array_of_const(def);
  93. end;
  94. { true if a parameter is too large to copy and only the address is pushed }
  95. function tparamanager.push_addr_param(def : tdef) : boolean;
  96. begin
  97. push_addr_param:=false;
  98. if never_copy_const_param then
  99. push_addr_param:=true
  100. else
  101. begin
  102. case def.deftype of
  103. variantdef,
  104. formaldef :
  105. push_addr_param:=true;
  106. recorddef :
  107. push_addr_param:=(def.size>pointer_size);
  108. arraydef :
  109. push_addr_param:=((tarraydef(def).highrange>=tarraydef(def).lowrange) and (def.size>pointer_size)) or
  110. is_open_array(def) or
  111. is_array_of_const(def) or
  112. is_array_constructor(def);
  113. objectdef :
  114. push_addr_param:=is_object(def);
  115. stringdef :
  116. push_addr_param:=tstringdef(def).string_typ in [st_shortstring,st_longstring];
  117. procvardef :
  118. push_addr_param:=(po_methodpointer in tprocvardef(def).procoptions);
  119. setdef :
  120. push_addr_param:=(tsetdef(def).settype<>smallset);
  121. end;
  122. end;
  123. end;
  124. procedure setparalocs(p : tprocdef);
  125. var
  126. hp : tparaitem;
  127. begin
  128. hp:=tparaitem(p.para.first);
  129. while assigned(hp) do
  130. begin
  131. if (hp.paraloc.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER]) and
  132. { if the parameter isn't regable, we've to work with the local copy }
  133. ((vo_regable in tvarsym(hp.parasym).varoptions) or
  134. (vo_fpuregable in tvarsym(hp.parasym).varoptions)) then
  135. begin
  136. tvarsym(hp.parasym).reg:=hp.paraloc.register;
  137. rg.regvar_loaded[hp.paraloc.register]:=true;
  138. end;
  139. hp:=tparaitem(hp.next);
  140. end;
  141. end;
  142. finalization
  143. paramanager.free;
  144. end.
  145. {
  146. $Log$
  147. Revision 1.8 2002-08-06 20:55:21 florian
  148. * first part of ppc calling conventions fix
  149. Revision 1.7 2002/08/05 18:27:48 carl
  150. + more more more documentation
  151. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  152. Revision 1.6 2002/07/30 20:50:43 florian
  153. * the code generator knows now if parameters are in registers
  154. Revision 1.5 2002/07/26 21:15:39 florian
  155. * rewrote the system handling
  156. Revision 1.4 2002/07/20 11:57:55 florian
  157. * types.pas renamed to defbase.pas because D6 contains a types
  158. unit so this would conflicts if D6 programms are compiled
  159. + Willamette/SSE2 instructions to assembler added
  160. Revision 1.3 2002/07/13 19:38:43 florian
  161. * some more generic calling stuff fixed
  162. Revision 1.2 2002/07/13 07:17:15 jonas
  163. * fixed memory leak reported by Sergey Korshunoff
  164. Revision 1.1 2002/07/11 14:41:28 florian
  165. * start of the new generic parameter handling
  166. }