1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef HYDROGEN_TYPES_H_
6 #define HYDROGEN_TYPES_H_
10 #include "src/base/macros.h"
15 // Forward declarations.
16 template <typename T> class Handle;
19 #define HTYPE_LIST(V) \
20 V(Any, 0x0) /* 0000 0000 0000 0000 */ \
21 V(Tagged, 0x1) /* 0000 0000 0000 0001 */ \
22 V(TaggedPrimitive, 0x5) /* 0000 0000 0000 0101 */ \
23 V(TaggedNumber, 0xd) /* 0000 0000 0000 1101 */ \
24 V(Smi, 0x1d) /* 0000 0000 0001 1101 */ \
25 V(HeapObject, 0x21) /* 0000 0000 0010 0001 */ \
26 V(HeapPrimitive, 0x25) /* 0000 0000 0010 0101 */ \
27 V(Null, 0x27) /* 0000 0000 0010 0111 */ \
28 V(HeapNumber, 0x2d) /* 0000 0000 0010 1101 */ \
29 V(String, 0x65) /* 0000 0000 0110 0101 */ \
30 V(Boolean, 0xa5) /* 0000 0000 1010 0101 */ \
31 V(Undefined, 0x125) /* 0000 0001 0010 0101 */ \
32 V(JSObject, 0x221) /* 0000 0010 0010 0001 */ \
33 V(JSArray, 0x621) /* 0000 0110 0010 0001 */ \
34 V(None, 0x7ff) /* 0000 0111 1111 1111 */
36 class HType V8_FINAL {
38 #define DECLARE_CONSTRUCTOR(Name, mask) \
39 static HType Name() V8_WARN_UNUSED_RESULT { return HType(k##Name); }
40 HTYPE_LIST(DECLARE_CONSTRUCTOR)
41 #undef DECLARE_CONSTRUCTOR
43 // Return the weakest (least precise) common type.
44 HType Combine(HType other) const V8_WARN_UNUSED_RESULT {
45 return HType(static_cast<Kind>(kind_ & other.kind_));
48 bool Equals(HType other) const V8_WARN_UNUSED_RESULT {
49 return kind_ == other.kind_;
52 bool IsSubtypeOf(HType other) const V8_WARN_UNUSED_RESULT {
53 return Combine(other).Equals(other);
56 #define DECLARE_IS_TYPE(Name, mask) \
57 bool Is##Name() const V8_WARN_UNUSED_RESULT { \
58 return IsSubtypeOf(HType::Name()); \
60 HTYPE_LIST(DECLARE_IS_TYPE)
61 #undef DECLARE_IS_TYPE
64 static HType FromType(typename T::TypeHandle type) V8_WARN_UNUSED_RESULT;
65 static HType FromValue(Handle<Object> value) V8_WARN_UNUSED_RESULT;
67 const char* ToString() const V8_WARN_UNUSED_RESULT;
71 #define DECLARE_TYPE(Name, mask) k##Name = mask,
72 HTYPE_LIST(DECLARE_TYPE)
77 // Make sure type fits in int16.
78 STATIC_ASSERT(LAST_KIND < (1 << (CHAR_BIT * sizeof(int16_t))));
80 explicit HType(Kind kind) : kind_(kind) { }
85 } } // namespace v8::internal
87 #endif // HYDROGEN_TYPES_H_