parabase.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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,cgutils;
  24. type
  25. TCGParaReference = record
  26. index : tregister;
  27. offset : aint;
  28. end;
  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 : TCGParaReference);
  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. function getcopy:tcgpara;
  51. procedure check_simple_location;
  52. function is_simple_reference:boolean;
  53. function add_location:pcgparalocation;
  54. procedure get_location(var newloc:tlocation);
  55. end;
  56. tvarargsinfo = (
  57. va_uses_float_reg
  58. );
  59. tvarargsparalist = class(tlist)
  60. varargsinfo : set of tvarargsinfo;
  61. {$ifdef x86_64}
  62. { x86_64 requires %al to contain the no. SSE regs passed }
  63. mmregsused : longint;
  64. {$endif x86_64}
  65. end;
  66. implementation
  67. uses
  68. systems,verbose;
  69. {****************************************************************************
  70. TCGPara
  71. ****************************************************************************}
  72. constructor tcgpara.init;
  73. begin
  74. alignment:=0;
  75. size:=OS_NO;
  76. location:=nil;
  77. end;
  78. destructor tcgpara.done;
  79. begin
  80. reset;
  81. end;
  82. procedure tcgpara.reset;
  83. var
  84. hlocation : pcgparalocation;
  85. begin
  86. while assigned(location) do
  87. begin
  88. hlocation:=location^.next;
  89. dispose(location);
  90. location:=hlocation;
  91. end;
  92. alignment:=0;
  93. size:=OS_NO;
  94. end;
  95. function tcgpara.getcopy:tcgpara;
  96. var
  97. hlocation : pcgparalocation;
  98. begin
  99. result.init;
  100. while assigned(location) do
  101. begin
  102. hlocation:=result.add_location;
  103. hlocation^:=location^;
  104. hlocation^.next:=nil;
  105. location:=location^.next;
  106. end;
  107. result.alignment:=alignment;
  108. result.size:=size;
  109. end;
  110. function tcgpara.add_location:pcgparalocation;
  111. var
  112. prevlocation,
  113. hlocation : pcgparalocation;
  114. begin
  115. prevlocation:=nil;
  116. hlocation:=location;
  117. while assigned(hlocation) do
  118. begin
  119. prevlocation:=hlocation;
  120. hlocation:=hlocation^.next;
  121. end;
  122. new(hlocation);
  123. Fillchar(hlocation^,sizeof(tcgparalocation),0);
  124. if assigned(prevlocation) then
  125. prevlocation^.next:=hlocation
  126. else
  127. location:=hlocation;
  128. result:=hlocation;
  129. end;
  130. procedure tcgpara.check_simple_location;
  131. begin
  132. if not assigned(location) then
  133. internalerror(200408161);
  134. if assigned(location^.next) then
  135. internalerror(200408162);
  136. end;
  137. function tcgpara.is_simple_reference:boolean;
  138. begin
  139. if not assigned(location) then
  140. internalerror(200410102);
  141. {$ifdef powerpc}
  142. { Powerpc always needs a copy in a local temp }
  143. result:=false;
  144. {$else}
  145. result:=not assigned(location^.next) and
  146. (location^.loc=LOC_REFERENCE);
  147. {$endif}
  148. end;
  149. procedure tcgpara.get_location(var newloc:tlocation);
  150. begin
  151. if not assigned(location) then
  152. internalerror(200408205);
  153. fillchar(newloc,sizeof(newloc),0);
  154. newloc.loc:=location^.loc;
  155. newloc.size:=size;
  156. case location^.loc of
  157. LOC_REGISTER :
  158. begin
  159. {$ifndef cpu64bit}
  160. if size in [OS_64,OS_S64] then
  161. begin
  162. if not assigned(location^.next) then
  163. internalerror(200408206);
  164. if (location^.next^.loc<>LOC_REGISTER) then
  165. internalerror(200408207);
  166. if (target_info.endian = ENDIAN_BIG) then
  167. begin
  168. newloc.register64.reghi:=location^.register;
  169. newloc.register64.reglo:=location^.next^.register;
  170. end
  171. else
  172. begin
  173. newloc.register64.reglo:=location^.register;
  174. newloc.register64.reghi:=location^.next^.register;
  175. end;
  176. end
  177. else
  178. {$endif}
  179. newloc.register:=location^.register;
  180. end;
  181. LOC_FPUREGISTER,
  182. LOC_MMREGISTER :
  183. newloc.register:=location^.register;
  184. LOC_REFERENCE :
  185. begin
  186. newloc.reference.base:=location^.reference.index;
  187. newloc.reference.offset:=location^.reference.offset;
  188. end;
  189. end;
  190. end;
  191. end.
  192. {
  193. $Log$
  194. Revision 1.5 2004-11-15 23:35:31 peter
  195. * tparaitem removed, use tparavarsym instead
  196. * parameter order is now calculated from paranr value in tparavarsym
  197. Revision 1.4 2004/10/31 21:45:03 peter
  198. * generic tlocation
  199. * move tlocation to cgutils
  200. Revision 1.3 2004/10/10 20:22:53 peter
  201. * symtable allocation rewritten
  202. * loading of parameters to local temps/regs cleanup
  203. * regvar support for parameters
  204. * regvar support for staticsymtable (main body)
  205. Revision 1.2 2004/09/21 17:25:12 peter
  206. * paraloc branch merged
  207. Revision 1.1.2.2 2004/09/14 19:09:37 jonas
  208. * fixed typo in IE check
  209. Revision 1.1.2.1 2004/09/02 15:47:58 peter
  210. * missing file
  211. }