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;
20 #define HTYPE_LIST(V) \
21 V(Any, 0x0) /* 0000 0000 0000 0000 */ \
22 V(Tagged, 0x1) /* 0000 0000 0000 0001 */ \
23 V(TaggedPrimitive, 0x5) /* 0000 0000 0000 0101 */ \
24 V(TaggedNumber, 0xd) /* 0000 0000 0000 1101 */ \
25 V(Smi, 0x1d) /* 0000 0000 0001 1101 */ \
26 V(HeapObject, 0x21) /* 0000 0000 0010 0001 */ \
27 V(HeapPrimitive, 0x25) /* 0000 0000 0010 0101 */ \
28 V(Null, 0x27) /* 0000 0000 0010 0111 */ \
29 V(HeapNumber, 0x2d) /* 0000 0000 0010 1101 */ \
30 V(String, 0x65) /* 0000 0000 0110 0101 */ \
31 V(Boolean, 0xa5) /* 0000 0000 1010 0101 */ \
32 V(Undefined, 0x125) /* 0000 0001 0010 0101 */ \
33 V(JSObject, 0x221) /* 0000 0010 0010 0001 */ \
34 V(JSArray, 0x621) /* 0000 0110 0010 0001 */ \
35 V(None, 0x7ff) /* 0000 0111 1111 1111 */
39 #define DECLARE_CONSTRUCTOR(Name, mask) \
40 static HType Name() WARN_UNUSED_RESULT { return HType(k##Name); }
41 HTYPE_LIST(DECLARE_CONSTRUCTOR)
42 #undef DECLARE_CONSTRUCTOR
44 // Return the weakest (least precise) common type.
45 HType Combine(HType other) const WARN_UNUSED_RESULT {
46 return HType(static_cast<Kind>(kind_ & other.kind_));
49 bool Equals(HType other) const WARN_UNUSED_RESULT {
50 return kind_ == other.kind_;
53 bool IsSubtypeOf(HType other) const WARN_UNUSED_RESULT {
54 return Combine(other).Equals(other);
57 #define DECLARE_IS_TYPE(Name, mask) \
58 bool Is##Name() const WARN_UNUSED_RESULT { \
59 return IsSubtypeOf(HType::Name()); \
61 HTYPE_LIST(DECLARE_IS_TYPE)
62 #undef DECLARE_IS_TYPE
65 static HType FromType(typename T::TypeHandle type) WARN_UNUSED_RESULT;
66 static HType FromValue(Handle<Object> value) WARN_UNUSED_RESULT;
68 friend OStream& operator<<(OStream& os, const HType& t);
72 #define DECLARE_TYPE(Name, mask) k##Name = mask,
73 HTYPE_LIST(DECLARE_TYPE)
78 // Make sure type fits in int16.
79 STATIC_ASSERT(LAST_KIND < (1 << (CHAR_BIT * sizeof(int16_t))));
81 explicit HType(Kind kind) : kind_(kind) { }
87 OStream& operator<<(OStream& os, const HType& t);
88 } } // namespace v8::internal
90 #endif // HYDROGEN_TYPES_H_