parabase.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 add_location:pcgparalocation;
  52. procedure get_location(var newloc:tlocation);
  53. end;
  54. tvarargsinfo = (
  55. va_uses_float_reg
  56. );
  57. tvarargspara = class(tlinkedlist)
  58. varargsinfo : set of tvarargsinfo;
  59. {$ifdef x86_64}
  60. { x86_64 requires %al to contain the no. SSE regs passed }
  61. mmregsused : longint;
  62. {$endif x86_64}
  63. end;
  64. implementation
  65. uses
  66. systems,verbose;
  67. {****************************************************************************
  68. TCGPara
  69. ****************************************************************************}
  70. constructor tcgpara.init;
  71. begin
  72. alignment:=0;
  73. size:=OS_NO;
  74. location:=nil;
  75. end;
  76. destructor tcgpara.done;
  77. begin
  78. reset;
  79. end;
  80. procedure tcgpara.reset;
  81. var
  82. hlocation : pcgparalocation;
  83. begin
  84. while assigned(location) do
  85. begin
  86. hlocation:=location^.next;
  87. dispose(location);
  88. location:=hlocation;
  89. end;
  90. alignment:=0;
  91. size:=OS_NO;
  92. end;
  93. function tcgpara.add_location:pcgparalocation;
  94. var
  95. prevlocation,
  96. hlocation : pcgparalocation;
  97. begin
  98. prevlocation:=nil;
  99. hlocation:=location;
  100. while assigned(hlocation) do
  101. begin
  102. prevlocation:=hlocation;
  103. hlocation:=hlocation^.next;
  104. end;
  105. new(hlocation);
  106. Fillchar(hlocation^,sizeof(tcgparalocation),0);
  107. if assigned(prevlocation) then
  108. prevlocation^.next:=hlocation
  109. else
  110. location:=hlocation;
  111. result:=hlocation;
  112. end;
  113. procedure tcgpara.check_simple_location;
  114. begin
  115. if not assigned(location) then
  116. internalerror(200408161);
  117. if assigned(location^.next) then
  118. internalerror(200408162);
  119. end;
  120. procedure tcgpara.get_location(var newloc:tlocation);
  121. begin
  122. if not assigned(location) then
  123. internalerror(200408205);
  124. fillchar(newloc,sizeof(newloc),0);
  125. newloc.loc:=location^.loc;
  126. newloc.size:=size;
  127. case location^.loc of
  128. LOC_REGISTER :
  129. begin
  130. {$ifndef cpu64bit}
  131. if size in [OS_64,OS_S64] then
  132. begin
  133. if not assigned(location^.next) then
  134. internalerror(200408206);
  135. if (location^.next^.loc<>LOC_REGISTER) then
  136. internalerror(200408207);
  137. if (target_info.endian = ENDIAN_BIG) then
  138. begin
  139. newloc.registerhigh:=location^.register;
  140. newloc.registerlow:=location^.next^.register;
  141. end
  142. else
  143. begin
  144. newloc.registerlow:=location^.register;
  145. newloc.registerhigh:=location^.next^.register;
  146. end;
  147. end
  148. else
  149. {$endif}
  150. newloc.register:=location^.register;
  151. end;
  152. LOC_FPUREGISTER,
  153. LOC_MMREGISTER :
  154. newloc.register:=location^.register;
  155. LOC_REFERENCE :
  156. begin
  157. newloc.reference.base:=location^.reference.index;
  158. newloc.reference.offset:=location^.reference.offset;
  159. end;
  160. end;
  161. end;
  162. end.
  163. {
  164. $Log$
  165. Revision 1.2 2004-09-21 17:25:12 peter
  166. * paraloc branch merged
  167. Revision 1.1.2.2 2004/09/14 19:09:37 jonas
  168. * fixed typo in IE check
  169. Revision 1.1.2.1 2004/09/02 15:47:58 peter
  170. * missing file
  171. }