parabase.pas 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. Location : PCGParalocation;
  45. Alignment : ShortInt;
  46. Size : TCGSize; { Size of the parameter included in all locations }
  47. IntSize: aint; { size of the total location in bytes }
  48. {$ifdef powerpc}
  49. composite: boolean; { under the AIX abi, how certain parameters are passed depends on whether they are composite or not }
  50. {$endif powerpc}
  51. constructor init;
  52. destructor done;
  53. procedure reset;
  54. function getcopy:tcgpara;
  55. procedure check_simple_location;
  56. function add_location:pcgparalocation;
  57. procedure get_location(var newloc:tlocation);
  58. end;
  59. tvarargsinfo = (
  60. va_uses_float_reg
  61. );
  62. tparalist = class(tlist)
  63. procedure SortParas;
  64. end;
  65. tvarargsparalist = class(tparalist)
  66. varargsinfo : set of tvarargsinfo;
  67. {$ifdef x86_64}
  68. { x86_64 requires %al to contain the no. SSE regs passed }
  69. mmregsused : longint;
  70. {$endif x86_64}
  71. end;
  72. implementation
  73. uses
  74. systems,verbose,
  75. symsym;
  76. {****************************************************************************
  77. TCGPara
  78. ****************************************************************************}
  79. constructor tcgpara.init;
  80. begin
  81. alignment:=0;
  82. size:=OS_NO;
  83. intsize:=0;
  84. location:=nil;
  85. {$ifdef powerpc}
  86. composite:=false;
  87. {$endif powerpc}
  88. end;
  89. destructor tcgpara.done;
  90. begin
  91. reset;
  92. end;
  93. procedure tcgpara.reset;
  94. var
  95. hlocation : pcgparalocation;
  96. begin
  97. while assigned(location) do
  98. begin
  99. hlocation:=location^.next;
  100. dispose(location);
  101. location:=hlocation;
  102. end;
  103. alignment:=0;
  104. size:=OS_NO;
  105. intsize:=0;
  106. {$ifdef powerpc}
  107. composite:=false;
  108. {$endif powerpc}
  109. end;
  110. function tcgpara.getcopy:tcgpara;
  111. var
  112. hlocation : pcgparalocation;
  113. begin
  114. result.init;
  115. while assigned(location) do
  116. begin
  117. hlocation:=result.add_location;
  118. hlocation^:=location^;
  119. hlocation^.next:=nil;
  120. location:=location^.next;
  121. end;
  122. result.alignment:=alignment;
  123. result.size:=size;
  124. result.intsize:=intsize;
  125. {$ifdef powerpc}
  126. result.composite:=composite;
  127. {$endif powerpc}
  128. end;
  129. function tcgpara.add_location:pcgparalocation;
  130. var
  131. prevlocation,
  132. hlocation : pcgparalocation;
  133. begin
  134. prevlocation:=nil;
  135. hlocation:=location;
  136. while assigned(hlocation) do
  137. begin
  138. prevlocation:=hlocation;
  139. hlocation:=hlocation^.next;
  140. end;
  141. new(hlocation);
  142. Fillchar(hlocation^,sizeof(tcgparalocation),0);
  143. if assigned(prevlocation) then
  144. prevlocation^.next:=hlocation
  145. else
  146. location:=hlocation;
  147. result:=hlocation;
  148. end;
  149. procedure tcgpara.check_simple_location;
  150. begin
  151. if not assigned(location) then
  152. internalerror(200408161);
  153. if assigned(location^.next) then
  154. internalerror(200408162);
  155. end;
  156. procedure tcgpara.get_location(var newloc:tlocation);
  157. begin
  158. if not assigned(location) then
  159. internalerror(200408205);
  160. fillchar(newloc,sizeof(newloc),0);
  161. newloc.loc:=location^.loc;
  162. newloc.size:=size;
  163. case location^.loc of
  164. LOC_REGISTER :
  165. begin
  166. {$ifndef cpu64bit}
  167. if size in [OS_64,OS_S64] then
  168. begin
  169. if not assigned(location^.next) then
  170. internalerror(200408206);
  171. if (location^.next^.loc<>LOC_REGISTER) then
  172. internalerror(200408207);
  173. if (target_info.endian = ENDIAN_BIG) then
  174. begin
  175. newloc.register64.reghi:=location^.register;
  176. newloc.register64.reglo:=location^.next^.register;
  177. end
  178. else
  179. begin
  180. newloc.register64.reglo:=location^.register;
  181. newloc.register64.reghi:=location^.next^.register;
  182. end;
  183. end
  184. else
  185. {$endif}
  186. newloc.register:=location^.register;
  187. end;
  188. LOC_FPUREGISTER,
  189. LOC_MMREGISTER :
  190. newloc.register:=location^.register;
  191. LOC_REFERENCE :
  192. begin
  193. newloc.reference.base:=location^.reference.index;
  194. newloc.reference.offset:=location^.reference.offset;
  195. end;
  196. end;
  197. end;
  198. {****************************************************************************
  199. TParaList
  200. ****************************************************************************}
  201. function ParaNrCompare(Item1, Item2: Pointer): Integer;
  202. var
  203. I1 : tparavarsym absolute Item1;
  204. I2 : tparavarsym absolute Item2;
  205. begin
  206. Result:=I1.paranr-I2.paranr;
  207. end;
  208. procedure TParaList.SortParas;
  209. begin
  210. Sort(@ParaNrCompare);
  211. end;
  212. end.
  213. {
  214. $Log$
  215. Revision 1.12 2005-02-15 21:39:48 peter
  216. * remove is_single_reference
  217. * revert loading of ref-to-ref para valu
  218. Revision 1.11 2005/02/14 17:13:07 peter
  219. * truncate log
  220. Revision 1.10 2005/01/30 21:51:57 jonas
  221. * fixed darwin cycle
  222. Revision 1.9 2005/01/18 22:19:20 peter
  223. * multiple location support for i386 a_param_ref
  224. * remove a_param_copy_ref for i386
  225. Revision 1.8 2005/01/10 21:50:05 jonas
  226. + support for passing records in registers under darwin
  227. * tcgpara now also has an intsize field, which contains the size in
  228. bytes of the whole parameter
  229. Revision 1.7 2005/01/07 16:22:54 florian
  230. + implemented abi compliant handling of strucutured functions results on sparc platform
  231. }