cpupara.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. Generates the argument location information for x86-64 target
  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 bymethodpointer
  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. { Generates the argument location information for x86-64 target.
  19. }
  20. unit cpupara;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cpubase,
  25. symconst,symbase,symtype,symdef,paramgr;
  26. type
  27. { Returns the location for the nr-st 32 Bit int parameter
  28. if every parameter before is an 32 Bit int parameter as well
  29. and if the calling conventions for the helper routines of the
  30. rtl are used.
  31. }
  32. tx86_64paramanager = class(tparamanager)
  33. function getintparaloc(nr : longint) : tparalocation;override;
  34. procedure create_param_loc_info(p : tabstractprocdef);override;
  35. end;
  36. implementation
  37. uses
  38. verbose,
  39. globtype,
  40. cpuinfo,cginfo,cgbase,
  41. defutil;
  42. function getparaloc(p : tdef) : tcgloc;
  43. begin
  44. { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
  45. if push_addr_param for the def is true
  46. }
  47. // !!!!! Fix aggregate types
  48. case p.deftype of
  49. orddef:
  50. getparaloc:=LOC_REGISTER;
  51. floatdef:
  52. case tfloatdef(p).typ of
  53. s80real:
  54. getparaloc:=LOC_REFERENCE;
  55. s32real,
  56. s64real,
  57. s64comp,
  58. s64currency,
  59. s128real:
  60. getparaloc:=LOC_MMREGISTER;
  61. end;
  62. enumdef:
  63. getparaloc:=LOC_REGISTER;
  64. pointerdef:
  65. getparaloc:=LOC_REGISTER;
  66. formaldef:
  67. getparaloc:=LOC_REGISTER;
  68. classrefdef:
  69. getparaloc:=LOC_REGISTER;
  70. recorddef:
  71. getparaloc:=LOC_REFERENCE;
  72. objectdef:
  73. if is_object(p) then
  74. getparaloc:=LOC_REFERENCE
  75. else
  76. getparaloc:=LOC_REGISTER;
  77. stringdef:
  78. if is_shortstring(p) or is_longstring(p) then
  79. getparaloc:=LOC_REFERENCE
  80. else
  81. getparaloc:=LOC_REGISTER;
  82. procvardef:
  83. if (po_methodpointer in tprocvardef(p).procoptions) then
  84. getparaloc:=LOC_REFERENCE
  85. else
  86. getparaloc:=LOC_REGISTER;
  87. filedef:
  88. getparaloc:=LOC_REGISTER;
  89. arraydef:
  90. getparaloc:=LOC_REFERENCE;
  91. setdef:
  92. if is_smallset(p) then
  93. getparaloc:=LOC_REGISTER
  94. else
  95. getparaloc:=LOC_REFERENCE;
  96. variantdef:
  97. getparaloc:=LOC_REFERENCE;
  98. { avoid problems with errornous definitions }
  99. errordef:
  100. getparaloc:=LOC_REGISTER;
  101. else
  102. internalerror(2002071001);
  103. end;
  104. end;
  105. function tx86_64paramanager.getintparaloc(nr : longint) : tparalocation;
  106. const
  107. nr2reg : array[1..6] of word = (NR_RDI,NR_RSI,NR_RDX,NR_RCX,NR_R8,NR_R9);
  108. begin
  109. fillchar(result,sizeof(tparalocation),0);
  110. if nr<1 then
  111. internalerror(200304303)
  112. else if nr<=6 then
  113. begin
  114. result.loc:=LOC_REGISTER;
  115. result.register.enum:=R_INTREGISTER;
  116. result.register.number:=nr2reg[nr];
  117. end
  118. else
  119. begin
  120. result.loc:=LOC_REFERENCE;
  121. result.reference.index.enum:=R_INTREGISTER;
  122. result.reference.index.number:=NR_STACK_POINTER_REG;
  123. result.reference.offset:=(nr-6)*8;
  124. end;
  125. end;
  126. procedure tx86_64paramanager.create_param_loc_info(p : tabstractprocdef);
  127. begin
  128. { set default para_alignment to target_info.stackalignment }
  129. { if para_alignment=0 then
  130. para_alignment:=aktalignment.paraalign;
  131. }
  132. end;
  133. begin
  134. paramanager:=tx86_64paramanager.create;
  135. end.
  136. {
  137. $Log$
  138. Revision 1.4 2003-04-30 20:53:32 florian
  139. * error when address of an abstract method is taken
  140. * fixed some x86-64 problems
  141. * merged some more x86-64 and i386 code
  142. Revision 1.3 2002/04/25 16:12:09 florian
  143. * fixed more problems with cpubase and x86-64
  144. Revision 1.2 2003/01/05 13:36:54 florian
  145. * x86-64 compiles
  146. + very basic support for float128 type (x86-64 only)
  147. Revision 1.1 2002/07/24 22:38:15 florian
  148. + initial release of x86-64 target code
  149. }