parabase.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. Generic calling convention handling
  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. unit parabase;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,globtype,
  23. cpubase,cgbase;
  24. type
  25. { tparamlocation describes where a parameter for a procedure is stored.
  26. References are given from the caller's point of view. The usual
  27. TLocation isn't used, because contains a lot of unnessary fields.
  28. }
  29. PCGParaLocation = ^TCGParaLocation;
  30. TCGParaLocation = record
  31. Next : PCGParaLocation;
  32. Size : TCGSize; { size of this location }
  33. Loc : TCGLoc;
  34. case TCGLoc of
  35. LOC_REFERENCE : (reference : tparareference);
  36. LOC_FPUREGISTER,
  37. LOC_CFPUREGISTER,
  38. LOC_MMREGISTER,
  39. LOC_CMMREGISTER,
  40. LOC_REGISTER,
  41. LOC_CREGISTER : (register : tregister);
  42. end;
  43. TCGPara = object
  44. Alignment : ShortInt;
  45. Size : TCGSize; { Size of the parameter included in all locations }
  46. Location : PCGParalocation;
  47. constructor init;
  48. destructor done;
  49. procedure reset;
  50. procedure check_simple_location;
  51. function is_simple_reference:boolean;
  52. function add_location:pcgparalocation;
  53. procedure get_location(var newloc:tlocation);
  54. end;
  55. tvarargsinfo = (
  56. va_uses_float_reg
  57. );
  58. tvarargspara = class(tlinkedlist)
  59. varargsinfo : set of tvarargsinfo;
  60. {$ifdef x86_64}
  61. { x86_64 requires %al to contain the no. SSE regs passed }
  62. mmregsused : longint;
  63. {$endif x86_64}
  64. end;
  65. implementation
  66. uses
  67. systems,verbose;
  68. {****************************************************************************
  69. TCGPara
  70. ****************************************************************************}
  71. constructor tcgpara.init;
  72. begin
  73. alignment:=0;
  74. size:=OS_NO;
  75. location:=nil;
  76. end;
  77. destructor tcgpara.done;
  78. begin
  79. reset;
  80. end;
  81. procedure tcgpara.reset;
  82. var
  83. hlocation : pcgparalocation;
  84. begin
  85. while assigned(location) do
  86. begin
  87. hlocation:=location^.next;
  88. dispose(location);
  89. location:=hlocation;
  90. end;
  91. alignment:=0;
  92. size:=OS_NO;
  93. end;
  94. function tcgpara.add_location:pcgparalocation;
  95. var
  96. prevlocation,
  97. hlocation : pcgparalocation;
  98. begin
  99. prevlocation:=nil;
  100. hlocation:=location;
  101. while assigned(hlocation) do
  102. begin
  103. prevlocation:=hlocation;
  104. hlocation:=hlocation^.next;
  105. end;
  106. new(hlocation);
  107. Fillchar(hlocation^,sizeof(tcgparalocation),0);
  108. if assigned(prevlocation) then
  109. prevlocation^.next:=hlocation
  110. else
  111. location:=hlocation;
  112. result:=hlocation;
  113. end;
  114. procedure tcgpara.check_simple_location;
  115. begin
  116. if not assigned(location) then
  117. internalerror(200408161);
  118. if assigned(location^.next) then
  119. internalerror(200408162);
  120. end;
  121. function tcgpara.is_simple_reference:boolean;
  122. begin
  123. if not assigned(location) then
  124. internalerror(200410102);
  125. {$ifdef powerpc}
  126. { Powerpc always needs a copy in a local temp }
  127. result:=false;
  128. {$else}
  129. result:=not assigned(location^.next) and
  130. (location^.loc=LOC_REFERENCE);
  131. {$endif}
  132. end;
  133. procedure tcgpara.get_location(var newloc:tlocation);
  134. begin
  135. if not assigned(location) then
  136. internalerror(200408205);
  137. fillchar(newloc,sizeof(newloc),0);
  138. newloc.loc:=location^.loc;
  139. newloc.size:=size;
  140. case location^.loc of
  141. LOC_REGISTER :
  142. begin
  143. {$ifndef cpu64bit}
  144. if size in [OS_64,OS_S64] then
  145. begin
  146. if not assigned(location^.next) then
  147. internalerror(200408206);
  148. if (location^.next^.loc<>LOC_REGISTER) then
  149. internalerror(200408207);
  150. if (target_info.endian = ENDIAN_BIG) then
  151. begin
  152. newloc.registerhigh:=location^.register;
  153. newloc.registerlow:=location^.next^.register;
  154. end
  155. else
  156. begin
  157. newloc.registerlow:=location^.register;
  158. newloc.registerhigh:=location^.next^.register;
  159. end;
  160. end
  161. else
  162. {$endif}
  163. newloc.register:=location^.register;
  164. end;
  165. LOC_FPUREGISTER,
  166. LOC_MMREGISTER :
  167. newloc.register:=location^.register;
  168. LOC_REFERENCE :
  169. begin
  170. newloc.reference.base:=location^.reference.index;
  171. newloc.reference.offset:=location^.reference.offset;
  172. end;
  173. end;
  174. end;
  175. end.
  176. {
  177. $Log$
  178. Revision 1.3 2004-10-10 20:22:53 peter
  179. * symtable allocation rewritten
  180. * loading of parameters to local temps/regs cleanup
  181. * regvar support for parameters
  182. * regvar support for staticsymtable (main body)
  183. Revision 1.2 2004/09/21 17:25:12 peter
  184. * paraloc branch merged
  185. Revision 1.1.2.2 2004/09/14 19:09:37 jonas
  186. * fixed typo in IE check
  187. Revision 1.1.2.1 2004/09/02 15:47:58 peter
  188. * missing file
  189. }