CACAO
Type.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Type.cpp - Types used in the 2nd stage compiler IR
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
26 #include "toolbox/OStream.hpp"
27 #include "toolbox/logging.hpp"
28 #include "vm/os.hpp"
29 
30 #include <cassert>
31 
32 namespace cacao {
33 namespace jit {
34 namespace compiler2 {
35 
36 // conversion functions
37 const char * get_var_type(int type)
38 {
39  switch(type) {
40  case TYPE_INT: return "TYPE_INT";
41  case TYPE_LNG: return "TYPE_LNG";
42  case TYPE_FLT: return "TYPE_FLT";
43  case TYPE_DBL: return "TYPE_DBL";
44  case TYPE_ADR: return "TYPE_ADR";
45  case TYPE_RET: return "TYPE_RET";
46  case TYPE_VOID: return "TYPE_VOID";
47  }
48  return "(unknown type)";
49 }
50 
52 {
53  switch(type) {
54  case TYPE_INT: return Type::IntTypeID;
55  case TYPE_LNG: return Type::LongTypeID;
56  case TYPE_FLT: return Type::FloatTypeID;
57  case TYPE_DBL: return Type::DoubleTypeID;
58  case TYPE_VOID: return Type::VoidTypeID;
59  case TYPE_ADR: return Type::ReferenceTypeID; // XXX is this right?
60  case TYPE_RET:
61  default: /* do nothing */ ;
62  }
63  ABORT_MSG("Type not supported", "type: " << get_var_type(type) << " (0x" << setz(2) << hex << type << dec << ") "
64  << " not yet supported!");
65  //assert( 0 && "Unsupported type");
66  return Type::VoidTypeID;
67 }
68 
70  switch(type) {
71  case Type::PrimitiveTypeID: return OS << "PrimitiveTypeID";
72  case Type::ReferenceTypeID: return OS << "ReferenceTypeID";
73  case Type::NumericTypeID: return OS << "NumericTypeID";
74  case Type::BooleanTypeID: return OS << "BooleanTypeID";
75  case Type::ReturnAddressTypeID: return OS << "ReturnAddressTypeID";
76  case Type::IntegralTypeID: return OS << "IntegralTypeID";
77  case Type::FloatingPointTypeID: return OS << "FloatingPointTypeID";
78  case Type::ByteTypeID: return OS << "ByteTypeID";
79  case Type::ShortTypeID: return OS << "ShortTypeID";
80  case Type::IntTypeID: return OS << "IntTypeID";
81  case Type::LongTypeID: return OS << "LongTypeID";
82  case Type::CharTypeID: return OS << "CharTypeID";
83  case Type::FloatTypeID: return OS << "FloatTypeID";
84  case Type::DoubleTypeID: return OS << "DoubleTypeID";
85  case Type::GlobalStateTypeID: return OS << "GlobalStateTypeID";
86  case Type::VoidTypeID: return OS << "VoidTypeID";
87  }
89  return OS;
90 }
91 const char* get_type_name(const Type::TypeID &type) {
92  switch(type) {
93  case Type::PrimitiveTypeID: return "PrimitiveTypeID";
94  case Type::ReferenceTypeID: return "ReferenceTypeID";
95  case Type::NumericTypeID: return "NumericTypeID";
96  case Type::BooleanTypeID: return "BooleanTypeID";
97  case Type::ReturnAddressTypeID: return "ReturnAddressTypeID";
98  case Type::IntegralTypeID: return "IntegralTypeID";
99  case Type::FloatingPointTypeID: return "FloatingPointTypeID";
100  case Type::ByteTypeID: return "ByteTypeID";
101  case Type::ShortTypeID: return "ShortTypeID";
102  case Type::IntTypeID: return "IntTypeID";
103  case Type::LongTypeID: return "LongTypeID";
104  case Type::CharTypeID: return "CharTypeID";
105  case Type::FloatTypeID: return "FloatTypeID";
106  case Type::DoubleTypeID: return "DoubleTypeID";
107  case Type::GlobalStateTypeID: return "GlobalStateTypeID";
108  case Type::VoidTypeID: return "VoidTypeID";
109  }
110  return "UnknownType";
111 }
112 #if 0
113 /**
114  * Type Class
115  *
116  * See JVM spec 2.2
117  */
118 class Type {
119 public:
120  static int ID;
121 };
122 
123 class PrimitiveType : public Type {
124 };
125 
126 class ReferenceType : public Type {
127 };
128 
129 
130 class NumericType : public PrimitiveType {
131 };
132 
133 
134 /**
135  * The values of the boolean type encode the truth values true and false,
136  * and the default value is false.
137  */
138 class BooleanType : public PrimitiveType {
139 };
140 
141 /**
142  * The values of the returnAddress type are pointers to the opcodes of Java
143  * Virtual Machine instructions. Of the primitive types, only the returnAddress
144  * type is not directly associated with a Java programming language type.
145  */
146 class ReturnAddressType : public PrimitiveType {
147 };
148 
149 
150 class IntegralType : public NumericType {
151 };
152 class FloatingPointType : public NumericType {
153 };
154 
155 /**
156  * whose values are 8-bit signed two's-complement integers, and whose default value is zero
157  */
158 class ByteType : public IntegralType {
159 };
160 
161 /**
162  * whose values are 16-bit signed two's-complement integers, and whose default value is zero
163  */
164 class ShortType : public IntegralType {
165 };
166 
167 /**
168  * whose values are 32-bit signed two's-complement integers, and whose default value is zero
169  */
170 class IntType : public IntegralType {
171 };
172 
173 /**
174  * whose values are 64-bit signed two's-complement integers, and whose default value is zero
175  */
176 class LongType : public IntegralType {
177 };
178 
179 /**
180  * whose values are 16-bit unsigned integers representing Unicode code points
181  * in the Basic Multilingual Plane, encoded with UTF-16, and whose default value
182  * is the null code point ('\u0000')
183  */
184 class CharType : public IntegralType {
185 };
186 
187 
188 /**
189  * whose values are elements of the float value set or, where supported, the
190  * float-extended-exponent value set, and whose default value is positive zero
191  */
192 class FloatType : public FloatingPointType {
193 };
194 
195 /**
196  * whose values are elements of the double value set or, where supported, the
197  * double-extended-exponent value set, and whose default value is positive zero
198  */
199 class DoubleType : public FloatingPointType {
200 };
201 #endif
202 
203 
204 } // end namespace cacao
205 } // end namespace jit
206 } // end namespace compiler2
207 
208 /*
209  * These are local overrides for various environment variables in Emacs.
210  * Please do not remove this and leave it at the end of the file, where
211  * Emacs will automagically detect them.
212  * ---------------------------------------------------------------------
213  * Local variables:
214  * mode: c++
215  * indent-tabs-mode: t
216  * c-basic-offset: 4
217  * tab-width: 4
218  * End:
219  * vim:noexpandtab:sw=4:ts=4:
220  */
Hex hex
Definition: OStream.cpp:50
const char * get_type_name(const Type::TypeID &type)
Definition: Type.cpp:91
PrimitiveType
JVM types.
Definition: primitive.hpp:55
Simple stream class for formatted output.
Definition: OStream.hpp:141
Type
Types used internally by JITTED code.
Definition: global.hpp:117
OStream & operator<<(OStream &OS, const Conditional::CondID &cond)
Definition: Conditional.cpp:34
OStream & OS
Type::TypeID convert_var_type(int type)
Definition: Type.cpp:51
static void shouldnotreach()
Definition: os.hpp:690
const char * get_var_type(int type)
Definition: Type.cpp:37
#define ABORT_MSG(EXPR_SHORT, EXPR_LONG)
Definition: logging.hpp:133
static SetZero setz(size_t w)
Definition: OStream.hpp:398
Dec dec
Definition: OStream.cpp:48