paramgr.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. end;
  43. var
  44. paralocdummy : tparalocation;
  45. paramanager : tparamanager;
  46. implementation
  47. uses
  48. cpuinfo,
  49. symconst,symbase,
  50. defbase;
  51. { true if the return value is in accumulator (EAX for i386), D0 for 68k }
  52. function tparamanager.ret_in_acc(def : tdef) : boolean;
  53. begin
  54. ret_in_acc:=(def.deftype in [orddef,pointerdef,enumdef,classrefdef]) or
  55. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_ansistring,st_widestring])) or
  56. ((def.deftype=procvardef) and not(po_methodpointer in tprocvardef(def).procoptions)) or
  57. ((def.deftype=objectdef) and not is_object(def)) or
  58. ((def.deftype=setdef) and (tsetdef(def).settype=smallset));
  59. end;
  60. { true if uses a parameter as return value }
  61. function tparamanager.ret_in_param(def : tdef) : boolean;
  62. begin
  63. ret_in_param:=(def.deftype in [arraydef,recorddef]) or
  64. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_shortstring,st_longstring])) or
  65. ((def.deftype=procvardef) and (po_methodpointer in tprocvardef(def).procoptions)) or
  66. ((def.deftype=objectdef) and is_object(def)) or
  67. (def.deftype=variantdef) or
  68. ((def.deftype=setdef) and (tsetdef(def).settype<>smallset));
  69. end;
  70. function tparamanager.push_high_param(def : tdef) : boolean;
  71. begin
  72. push_high_param:=is_open_array(def) or
  73. is_open_string(def) or
  74. is_array_of_const(def);
  75. end;
  76. { true if a parameter is too large to copy and only the address is pushed }
  77. function tparamanager.push_addr_param(def : tdef) : boolean;
  78. begin
  79. push_addr_param:=false;
  80. if never_copy_const_param then
  81. push_addr_param:=true
  82. else
  83. begin
  84. case def.deftype of
  85. variantdef,
  86. formaldef :
  87. push_addr_param:=true;
  88. recorddef :
  89. push_addr_param:=(def.size>pointer_size);
  90. arraydef :
  91. push_addr_param:=((tarraydef(def).highrange>=tarraydef(def).lowrange) and (def.size>pointer_size)) or
  92. is_open_array(def) or
  93. is_array_of_const(def) or
  94. is_array_constructor(def);
  95. objectdef :
  96. push_addr_param:=is_object(def);
  97. stringdef :
  98. push_addr_param:=tstringdef(def).string_typ in [st_shortstring,st_longstring];
  99. procvardef :
  100. push_addr_param:=(po_methodpointer in tprocvardef(def).procoptions);
  101. setdef :
  102. push_addr_param:=(tsetdef(def).settype<>smallset);
  103. end;
  104. end;
  105. end;
  106. finalization
  107. paramanager.free;
  108. end.
  109. {
  110. $Log$
  111. Revision 1.4 2002-07-20 11:57:55 florian
  112. * types.pas renamed to defbase.pas because D6 contains a types
  113. unit so this would conflicts if D6 programms are compiled
  114. + Willamette/SSE2 instructions to assembler added
  115. Revision 1.3 2002/07/13 19:38:43 florian
  116. * some more generic calling stuff fixed
  117. Revision 1.2 2002/07/13 07:17:15 jonas
  118. * fixed memory leak reported by Sergey Korshunoff
  119. Revision 1.1 2002/07/11 14:41:28 florian
  120. * start of the new generic parameter handling
  121. }