cpupara.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. Generates the argument location information for i386
  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 i386.
  19. }
  20. unit cpupara;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cpubase,
  25. globtype,
  26. symtype,symdef,paramgr;
  27. type
  28. { Returns the location for the nr-st 32 Bit int parameter
  29. if every parameter before is an 32 Bit int parameter as well
  30. and if the calling conventions for the helper routines of the
  31. rtl are used.
  32. }
  33. ti386paramanager = class(tparamanager)
  34. function ret_in_param(def : tdef;calloption : tproccalloption) : boolean;override;
  35. function push_addr_param(def : tdef;calloption : tproccalloption) : boolean;override;
  36. function getintparaloc(nr : longint) : tparalocation;override;
  37. procedure create_param_loc_info(p : tabstractprocdef);override;
  38. function getselflocation(p : tabstractprocdef) : tparalocation;override;
  39. end;
  40. implementation
  41. uses
  42. systems,verbose,
  43. symconst,
  44. cginfo;
  45. function ti386paramanager.ret_in_param(def : tdef;calloption : tproccalloption) : boolean;
  46. begin
  47. case target_info.system of
  48. system_i386_win32 :
  49. begin
  50. { Win32 returns small records in the accumulator }
  51. case def.deftype of
  52. recorddef :
  53. begin
  54. if (calloption in [pocall_stdcall,pocall_cdecl,pocall_cppdecl]) and (def.size<=8) then
  55. begin
  56. result:=false;
  57. exit;
  58. end;
  59. end;
  60. end;
  61. end;
  62. end;
  63. result:=inherited ret_in_param(def,calloption);
  64. end;
  65. function ti386paramanager.push_addr_param(def : tdef;calloption : tproccalloption) : boolean;
  66. begin
  67. case target_info.system of
  68. system_i386_win32 :
  69. begin
  70. case def.deftype of
  71. recorddef :
  72. begin
  73. if (calloption=pocall_stdcall) and (def.size<=8) then
  74. begin
  75. result:=false;
  76. exit;
  77. end;
  78. end;
  79. arraydef :
  80. begin
  81. if (tarraydef(def).highrange>=tarraydef(def).lowrange) and
  82. (calloption in [pocall_cdecl,pocall_cppdecl]) then
  83. begin
  84. result:=true;
  85. exit;
  86. end;
  87. end;
  88. end;
  89. end;
  90. end;
  91. result:=inherited push_addr_param(def,calloption);
  92. end;
  93. function ti386paramanager.getintparaloc(nr : longint) : tparalocation;
  94. begin
  95. getintparaloc.loc:=LOC_REFERENCE;
  96. getintparaloc.reference.index.enum:=R_EBP;
  97. getintparaloc.reference.offset:=4*nr;
  98. end;
  99. procedure ti386paramanager.create_param_loc_info(p : tabstractprocdef);
  100. begin
  101. { set default para_alignment to target_info.stackalignment }
  102. { if para_alignment=0 then
  103. para_alignment:=aktalignment.paraalign;
  104. }
  105. end;
  106. function ti386paramanager.getselflocation(p : tabstractprocdef) : tparalocation;
  107. begin
  108. getselflocation.loc:=LOC_REFERENCE;
  109. getselflocation.reference.index.enum:=R_ESP;
  110. getselflocation.reference.offset:=4;
  111. end;
  112. begin
  113. paramanager:=ti386paramanager.create;
  114. end.
  115. {
  116. $Log$
  117. Revision 1.11 2003-05-13 15:16:13 peter
  118. * removed ret_in_acc, it's the reverse of ret_in_param
  119. * fixed ret_in_param for win32 cdecl array
  120. Revision 1.10 2003/04/22 23:50:23 peter
  121. * firstpass uses expectloc
  122. * checks if there are differences between the expectloc and
  123. location.loc from secondpass in EXTDEBUG
  124. Revision 1.9 2003/04/22 14:33:38 peter
  125. * removed some notes/hints
  126. Revision 1.8 2003/01/08 18:43:57 daniel
  127. * Tregister changed into a record
  128. Revision 1.7 2002/12/24 15:56:50 peter
  129. * stackpointer_alloc added for adjusting ESP. Win32 needs
  130. this for the pageprotection
  131. Revision 1.6 2002/12/17 22:19:33 peter
  132. * fixed pushing of records>8 bytes with stdcall
  133. * simplified hightree loading
  134. Revision 1.5 2002/11/18 17:32:00 peter
  135. * pass proccalloption to ret_in_xxx and push_xxx functions
  136. Revision 1.4 2002/11/15 01:58:56 peter
  137. * merged changes from 1.0.7 up to 04-11
  138. - -V option for generating bug report tracing
  139. - more tracing for option parsing
  140. - errors for cdecl and high()
  141. - win32 import stabs
  142. - win32 records<=8 are returned in eax:edx (turned off by default)
  143. - heaptrc update
  144. - more info for temp management in .s file with EXTDEBUG
  145. Revision 1.3 2002/08/09 07:33:04 florian
  146. * a couple of interface related fixes
  147. Revision 1.2 2002/07/11 14:41:32 florian
  148. * start of the new generic parameter handling
  149. Revision 1.1 2002/07/07 09:52:33 florian
  150. * powerpc target fixed, very simple units can be compiled
  151. * some basic stuff for better callparanode handling, far from being finished
  152. }