paramgr.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. {
  19. }
  20. unit paramgr;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cpubase,
  25. symtype,symdef;
  26. type
  27. tparamanager = class
  28. { Returns true if the return value can be put in accumulator }
  29. function ret_in_acc(def : tdef) : boolean;virtual;
  30. { Returns true if uses a parameter as return value (???) }
  31. function ret_in_param(def : tdef) : boolean;virtual;
  32. function push_high_param(def : tdef) : boolean;virtual;
  33. { Returns true if a parameter is too large to copy and only the address is pushed
  34. }
  35. function push_addr_param(def : tdef) : boolean;virtual;
  36. function getintparaloc(nr : longint) : tparalocation;virtual;abstract;
  37. procedure create_param_loc_info(p : tabstractprocdef);virtual;abstract;
  38. { Returns the location where the invisible parameter for structured
  39. function results will be passed.
  40. }
  41. function getfuncretloc(p : tabstractprocdef) : tparalocation;virtual;abstract;
  42. { Returns the self pointer for the give procdef
  43. function getfuncretloc(p : tabstractprocdef) : tparalocation;virtual;abstract;
  44. }
  45. end;
  46. var
  47. paralocdummy : tparalocation;
  48. paramanager : tparamanager;
  49. implementation
  50. uses
  51. cpuinfo,
  52. symconst,symbase,
  53. defbase;
  54. { true if the return value is in accumulator (EAX for i386), D0 for 68k }
  55. function tparamanager.ret_in_acc(def : tdef) : boolean;
  56. begin
  57. ret_in_acc:=(def.deftype in [orddef,pointerdef,enumdef,classrefdef]) or
  58. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_ansistring,st_widestring])) or
  59. ((def.deftype=procvardef) and not(po_methodpointer in tprocvardef(def).procoptions)) or
  60. ((def.deftype=objectdef) and not is_object(def)) or
  61. ((def.deftype=setdef) and (tsetdef(def).settype=smallset));
  62. end;
  63. { true if uses a parameter as return value }
  64. function tparamanager.ret_in_param(def : tdef) : boolean;
  65. begin
  66. ret_in_param:=(def.deftype in [arraydef,recorddef]) or
  67. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_shortstring,st_longstring])) or
  68. ((def.deftype=procvardef) and (po_methodpointer in tprocvardef(def).procoptions)) or
  69. ((def.deftype=objectdef) and is_object(def)) or
  70. (def.deftype=variantdef) or
  71. ((def.deftype=setdef) and (tsetdef(def).settype<>smallset));
  72. end;
  73. function tparamanager.push_high_param(def : tdef) : boolean;
  74. begin
  75. push_high_param:=is_open_array(def) or
  76. is_open_string(def) or
  77. is_array_of_const(def);
  78. end;
  79. { true if a parameter is too large to copy and only the address is pushed }
  80. function tparamanager.push_addr_param(def : tdef) : boolean;
  81. begin
  82. push_addr_param:=false;
  83. if never_copy_const_param then
  84. push_addr_param:=true
  85. else
  86. begin
  87. case def.deftype of
  88. variantdef,
  89. formaldef :
  90. push_addr_param:=true;
  91. recorddef :
  92. push_addr_param:=(def.size>pointer_size);
  93. arraydef :
  94. push_addr_param:=((tarraydef(def).highrange>=tarraydef(def).lowrange) and (def.size>pointer_size)) or
  95. is_open_array(def) or
  96. is_array_of_const(def) or
  97. is_array_constructor(def);
  98. objectdef :
  99. push_addr_param:=is_object(def);
  100. stringdef :
  101. push_addr_param:=tstringdef(def).string_typ in [st_shortstring,st_longstring];
  102. procvardef :
  103. push_addr_param:=(po_methodpointer in tprocvardef(def).procoptions);
  104. setdef :
  105. push_addr_param:=(tsetdef(def).settype<>smallset);
  106. end;
  107. end;
  108. end;
  109. finalization
  110. paramanager.free;
  111. end.
  112. {
  113. $Log$
  114. Revision 1.5 2002-07-26 21:15:39 florian
  115. * rewrote the system handling
  116. Revision 1.4 2002/07/20 11:57:55 florian
  117. * types.pas renamed to defbase.pas because D6 contains a types
  118. unit so this would conflicts if D6 programms are compiled
  119. + Willamette/SSE2 instructions to assembler added
  120. Revision 1.3 2002/07/13 19:38:43 florian
  121. * some more generic calling stuff fixed
  122. Revision 1.2 2002/07/13 07:17:15 jonas
  123. * fixed memory leak reported by Sergey Korshunoff
  124. Revision 1.1 2002/07/11 14:41:28 florian
  125. * start of the new generic parameter handling
  126. }