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_type_name(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_type_name(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::IntTypeID: return TYPE_INT;
72  case Type::LongTypeID: return TYPE_LNG;
73  case Type::FloatTypeID: return TYPE_FLT;
74  case Type::DoubleTypeID: return TYPE_DBL;
75  case Type::VoidTypeID: return TYPE_VOID;
76  case Type::ReferenceTypeID: return TYPE_ADR; // XXX is this right?
77  default: /* do nothing */ ;
78  }
79 
80  ABORT_MSG("Could not convert type", "");
81  return Type::VoidTypeID;
82 }
83 
85  switch(type) {
86  case Type::PrimitiveTypeID: return OS << "PrimitiveTypeID";
87  case Type::ReferenceTypeID: return OS << "ReferenceTypeID";
88  case Type::NumericTypeID: return OS << "NumericTypeID";
89  case Type::BooleanTypeID: return OS << "BooleanTypeID";
90  case Type::ReturnAddressTypeID: return OS << "ReturnAddressTypeID";
91  case Type::IntegralTypeID: return OS << "IntegralTypeID";
92  case Type::FloatingPointTypeID: return OS << "FloatingPointTypeID";
93  case Type::ByteTypeID: return OS << "ByteTypeID";
94  case Type::ShortTypeID: return OS << "ShortTypeID";
95  case Type::IntTypeID: return OS << "IntTypeID";
96  case Type::LongTypeID: return OS << "LongTypeID";
97  case Type::CharTypeID: return OS << "CharTypeID";
98  case Type::FloatTypeID: return OS << "FloatTypeID";
99  case Type::DoubleTypeID: return OS << "DoubleTypeID";
100  case Type::GlobalStateTypeID: return OS << "GlobalStateTypeID";
101  case Type::VoidTypeID: return OS << "VoidTypeID";
102  }
104  return OS;
105 }
106 const char* get_type_name(const Type::TypeID &type) {
107  switch(type) {
108  case Type::PrimitiveTypeID: return "PrimitiveTypeID";
109  case Type::ReferenceTypeID: return "ReferenceTypeID";
110  case Type::NumericTypeID: return "NumericTypeID";
111  case Type::BooleanTypeID: return "BooleanTypeID";
112  case Type::ReturnAddressTypeID: return "ReturnAddressTypeID";
113  case Type::IntegralTypeID: return "IntegralTypeID";
114  case Type::FloatingPointTypeID: return "FloatingPointTypeID";
115  case Type::ByteTypeID: return "ByteTypeID";
116  case Type::ShortTypeID: return "ShortTypeID";
117  case Type::IntTypeID: return "IntTypeID";
118  case Type::LongTypeID: return "LongTypeID";
119  case Type::CharTypeID: return "CharTypeID";
120  case Type::FloatTypeID: return "FloatTypeID";
121  case Type::DoubleTypeID: return "DoubleTypeID";
122  case Type::GlobalStateTypeID: return "GlobalStateTypeID";
123  case Type::VoidTypeID: return "VoidTypeID";
124  }
125  return "UnknownType";
126 }
127 #if 0
128 /**
129  * Type Class
130  *
131  * See JVM spec 2.2
132  */
133 class Type {
134 public:
135  static int ID;
136 };
137 
138 class PrimitiveType : public Type {
139 };
140 
141 class ReferenceType : public Type {
142 };
143 
144 
145 class NumericType : public PrimitiveType {
146 };
147 
148 
149 /**
150  * The values of the boolean type encode the truth values true and false,
151  * and the default value is false.
152  */
153 class BooleanType : public PrimitiveType {
154 };
155 
156 /**
157  * The values of the returnAddress type are pointers to the opcodes of Java
158  * Virtual Machine instructions. Of the primitive types, only the returnAddress
159  * type is not directly associated with a Java programming language type.
160  */
161 class ReturnAddressType : public PrimitiveType {
162 };
163 
164 
165 class IntegralType : public NumericType {
166 };
167 class FloatingPointType : public NumericType {
168 };
169 
170 /**
171  * whose values are 8-bit signed two's-complement integers, and whose default value is zero
172  */
173 class ByteType : public IntegralType {
174 };
175 
176 /**
177  * whose values are 16-bit signed two's-complement integers, and whose default value is zero
178  */
179 class ShortType : public IntegralType {
180 };
181 
182 /**
183  * whose values are 32-bit signed two's-complement integers, and whose default value is zero
184  */
185 class IntType : public IntegralType {
186 };
187 
188 /**
189  * whose values are 64-bit signed two's-complement integers, and whose default value is zero
190  */
191 class LongType : public IntegralType {
192 };
193 
194 /**
195  * whose values are 16-bit unsigned integers representing Unicode code points
196  * in the Basic Multilingual Plane, encoded with UTF-16, and whose default value
197  * is the null code point ('\u0000')
198  */
199 class CharType : public IntegralType {
200 };
201 
202 
203 /**
204  * whose values are elements of the float value set or, where supported, the
205  * float-extended-exponent value set, and whose default value is positive zero
206  */
207 class FloatType : public FloatingPointType {
208 };
209 
210 /**
211  * whose values are elements of the double value set or, where supported, the
212  * double-extended-exponent value set, and whose default value is positive zero
213  */
214 class DoubleType : public FloatingPointType {
215 };
216 #endif
217 
218 
219 } // end namespace cacao
220 } // end namespace jit
221 } // end namespace compiler2
222 
223 /*
224  * These are local overrides for various environment variables in Emacs.
225  * Please do not remove this and leave it at the end of the file, where
226  * Emacs will automagically detect them.
227  * ---------------------------------------------------------------------
228  * Local variables:
229  * mode: c++
230  * indent-tabs-mode: t
231  * c-basic-offset: 4
232  * tab-width: 4
233  * End:
234  * vim:noexpandtab:sw=4:ts=4:
235  */
Hex hex
Definition: OStream.cpp:50
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
Type::TypeID convert_to_typeid(int type)
Convert a Type to a Type::TypeID.
Definition: Type.cpp:51
OStream & OS
int convert_to_type(Type::TypeID type)
Convert a Type::TypeID to a Type.
Definition: Type.cpp:69
const char * get_type_name(int type)
Get the printable name of the type.
Definition: Type.cpp:37
static void shouldnotreach()
Definition: os.hpp:690
#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