cginfo.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit exports some types and constants for the code generation
  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. {# This unit exports some types which are used across the code generator }
  19. unit cginfo;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses cpuinfo,symconst;
  23. type
  24. { Location types where value can be stored }
  25. TCGLoc=(
  26. LOC_INVALID, { added for tracking problems}
  27. LOC_VOID, { no value is available }
  28. LOC_CONSTANT, { constant value }
  29. LOC_JUMP, { boolean results only, jump to false or true label }
  30. LOC_FLAGS, { boolean results only, flags are set }
  31. LOC_CREFERENCE, { in memory constant value reference (cannot change) }
  32. LOC_REFERENCE, { in memory value }
  33. LOC_REGISTER, { in a processor register }
  34. LOC_CREGISTER, { Constant register which shouldn't be modified }
  35. LOC_FPUREGISTER, { FPU stack }
  36. LOC_CFPUREGISTER, { if it is a FPU register variable on the fpu stack }
  37. LOC_MMXREGISTER, { MMX register }
  38. { MMX register variable }
  39. LOC_CMMXREGISTER,
  40. LOC_SSEREGISTER,
  41. LOC_CSSEREGISTER,
  42. { multimedia register }
  43. LOC_MMREGISTER,
  44. { Constant multimedia reg which shouldn't be modified }
  45. LOC_CMMREGISTER
  46. );
  47. {# Generic opcodes, which must be supported by all processors
  48. }
  49. topcg =
  50. (
  51. OP_NONE,
  52. OP_ADD, { simple addition }
  53. OP_AND, { simple logical and }
  54. OP_DIV, { simple unsigned division }
  55. OP_IDIV, { simple signed division }
  56. OP_IMUL, { simple signed multiply }
  57. OP_MUL, { simple unsigned multiply }
  58. OP_NEG, { simple negate }
  59. OP_NOT, { simple logical not }
  60. OP_OR, { simple logical or }
  61. OP_SAR, { arithmetic shift-right }
  62. OP_SHL, { logical shift left }
  63. OP_SHR, { logical shift right }
  64. OP_SUB, { simple subtraction }
  65. OP_XOR { simple exclusive or }
  66. );
  67. {# Generic flag values - used for jump locations }
  68. TOpCmp =
  69. (
  70. OC_NONE,
  71. OC_EQ, { equality comparison }
  72. OC_GT, { greater than (signed) }
  73. OC_LT, { less than (signed) }
  74. OC_GTE, { greater or equal than (signed) }
  75. OC_LTE, { less or equal than (signed) }
  76. OC_NE, { not equal }
  77. OC_BE, { less or equal than (unsigned) }
  78. OC_B, { less than (unsigned) }
  79. OC_AE, { greater or equal than (unsigned) }
  80. OC_A { greater than (unsigned) }
  81. );
  82. { OS_NO is also used memory references with large data that can
  83. not be loaded in a register directly }
  84. TCgSize = (OS_NO,
  85. { integer registers }
  86. OS_8,OS_16,OS_32,OS_64,OS_S8,OS_S16,OS_S32,OS_S64,
  87. { single,double,extended,comp,float128 }
  88. OS_F32,OS_F64,OS_F80,OS_C64,OS_F128,
  89. { multi-media sizes: split in byte, word, dword, ... }
  90. { entities, then the signed counterparts }
  91. OS_M8,OS_M16,OS_M32,OS_M64,OS_M128,OS_MS8,OS_MS16,OS_MS32,
  92. OS_MS64,OS_MS128);
  93. const
  94. tcgsize2size : Array[tcgsize] of integer =
  95. { integer values }
  96. (0,1,2,4,8,1,2,4,8,
  97. { floating point values }
  98. 4,8,EXTENDED_SIZE,8,16,
  99. { multimedia values }
  100. 1,2,4,8,16,1,2,4,8,16);
  101. tfloat2tcgsize: array[tfloattype] of tcgsize =
  102. (OS_F32,OS_F64,OS_F80,OS_C64,OS_C64,OS_F128);
  103. tcgsize2tfloat: array[OS_F32..OS_C64] of tfloattype =
  104. (s32real,s64real,s80real,s64comp);
  105. { Table to convert tcgsize variables to the correspondending
  106. unsigned types }
  107. tcgsize2unsigned : array[tcgsize] of tcgsize = (OS_NO,
  108. OS_8,OS_16,OS_32,OS_64,OS_8,OS_16,OS_32,OS_64,
  109. OS_F32,OS_F64,OS_F80,OS_C64,OS_F128,
  110. OS_M8,OS_M16,OS_M32,OS_M64,OS_M128,OS_M8,OS_M16,OS_M32,
  111. OS_M64,OS_M128);
  112. tcgloc2str : array[TCGLoc] of string[11] = (
  113. 'LOC_INVALID',
  114. 'LOC_VOID',
  115. 'LOC_CONST',
  116. 'LOC_JUMP',
  117. 'LOC_FLAGS',
  118. 'LOC_CREF',
  119. 'LOC_REF',
  120. 'LOC_REG',
  121. 'LOC_CREG',
  122. 'LOC_FPUREG',
  123. 'LOC_CFPUREG',
  124. 'LOC_MMXREG',
  125. 'LOC_CMMXREG',
  126. 'LOC_SSEREG',
  127. 'LOC_CSSEREG',
  128. 'LOC_MMREG',
  129. 'LOC_CMMREG');
  130. implementation
  131. end.
  132. {
  133. $Log$
  134. Revision 1.21 2003-04-25 20:59:33 peter
  135. * removed funcretn,funcretsym, function result is now in varsym
  136. and aliases for result and function name are added using absolutesym
  137. * vs_hidden parameter for funcret passed in parameter
  138. * vs_hidden fixes
  139. * writenode changed to printnode and released from extdebug
  140. * -vp option added to generate a tree.log with the nodetree
  141. * nicer printnode for statements, callnode
  142. Revision 1.20 2003/04/23 12:35:34 florian
  143. * fixed several issues with powerpc
  144. + applied a patch from Jonas for nested function calls (PowerPC only)
  145. * ...
  146. Revision 1.19 2003/04/22 23:50:22 peter
  147. * firstpass uses expectloc
  148. * checks if there are differences between the expectloc and
  149. location.loc from secondpass in EXTDEBUG
  150. Revision 1.18 2003/01/09 22:00:53 florian
  151. * fixed some PowerPC issues
  152. Revision 1.17 2003/01/05 13:36:53 florian
  153. * x86-64 compiles
  154. + very basic support for float128 type (x86-64 only)
  155. Revision 1.16 2002/09/07 15:25:01 peter
  156. * old logs removed and tabs fixed
  157. Revision 1.15 2002/08/05 18:27:48 carl
  158. + more more more documentation
  159. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  160. Revision 1.14 2002/08/04 19:06:41 carl
  161. + added generic exception support (still does not work!)
  162. + more documentation
  163. Revision 1.13 2002/07/07 09:52:32 florian
  164. * powerpc target fixed, very simple units can be compiled
  165. * some basic stuff for better callparanode handling, far from being finished
  166. Revision 1.12 2002/07/01 16:23:52 peter
  167. * cg64 patch
  168. * basics for currency
  169. * asnode updates for class and interface (not finished)
  170. Revision 1.11 2002/05/27 19:16:08 carl
  171. + added comments to virtual comparison flags
  172. Revision 1.10 2002/05/18 13:34:05 peter
  173. * readded missing revisions
  174. Revision 1.9 2002/05/16 19:46:35 carl
  175. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  176. + try to fix temp allocation (still in ifdef)
  177. + generic constructor calls
  178. + start of tassembler / tmodulebase class cleanup
  179. Revision 1.7 2002/05/13 19:54:36 peter
  180. * removed n386ld and n386util units
  181. * maybe_save/maybe_restore added instead of the old maybe_push
  182. Revision 1.6 2002/05/06 19:48:26 carl
  183. + added more patches from Mazen for SPARC port
  184. Revision 1.5 2002/04/21 19:46:52 carl
  185. + added patch for SPARC from Mazen (to move to cpuinfo)
  186. Revision 1.4 2002/04/21 15:26:15 carl
  187. * move stuff to cpuinfo and cpubase
  188. + documented
  189. Revision 1.3 2002/04/20 21:32:23 carl
  190. + generic FPC_CHECKPOINTER
  191. + first parameter offset in stack now portable
  192. * rename some constants
  193. + move some cpu stuff to other units
  194. - remove unused constents
  195. * fix stacksize for some targets
  196. * fix generic size problems which depend now on EXTEND_SIZE constant
  197. Revision 1.2 2002/04/19 15:46:01 peter
  198. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  199. in most cases and not written to the ppu
  200. * add mangeledname_prefix() routine to generate the prefix of
  201. manglednames depending on the current procedure, object and module
  202. * removed static procprefix since the mangledname is now build only
  203. on demand from tprocdef.mangledname
  204. Revision 1.1 2002/04/02 18:09:47 jonas
  205. + initial implementation (Peter forgot to commit it)
  206. }