Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Unified Diff: src/hydrogen-types.h

Issue 300893003: Refactor HType to get rid of various hacks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix compilation. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | src/hydrogen-types.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen-types.h
diff --git a/src/hydrogen-types.h b/src/hydrogen-types.h
new file mode 100644
index 0000000000000000000000000000000000000000..c34c278eb25177b475b6b7617c5c73bc43d6f1d0
--- /dev/null
+++ b/src/hydrogen-types.h
@@ -0,0 +1,87 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef HYDROGEN_TYPES_H_
+#define HYDROGEN_TYPES_H_
+
+#include <climits>
+
+#include "base/macros.h"
+
+namespace v8 {
+namespace internal {
+
+// Forward declarations.
+template <typename T> class Handle;
+class Object;
+
+#define HTYPE_LIST(V) \
+ V(Any, 0x0) /* 0000 0000 0000 0000 */ \
+ V(Tagged, 0x1) /* 0000 0000 0000 0001 */ \
+ V(TaggedPrimitive, 0x5) /* 0000 0000 0000 0101 */ \
+ V(TaggedNumber, 0xd) /* 0000 0000 0000 1101 */ \
+ V(Smi, 0x1d) /* 0000 0000 0001 1101 */ \
+ V(HeapObject, 0x21) /* 0000 0000 0010 0001 */ \
+ V(HeapPrimitive, 0x25) /* 0000 0000 0010 0101 */ \
+ V(Null, 0x27) /* 0000 0000 0010 0111 */ \
+ V(HeapNumber, 0x2d) /* 0000 0000 0010 1101 */ \
+ V(String, 0x65) /* 0000 0000 0110 0101 */ \
+ V(Boolean, 0xa5) /* 0000 0000 1010 0101 */ \
+ V(Undefined, 0x125) /* 0000 0001 0010 0101 */ \
+ V(JSObject, 0x221) /* 0000 0010 0010 0001 */ \
+ V(JSArray, 0x621) /* 0000 0110 0010 0001 */ \
+ V(None, 0x7ff) /* 0000 0111 1111 1111 */
+
+class HType V8_FINAL {
+ public:
+ #define DECLARE_CONSTRUCTOR(Name, mask) \
+ static HType Name() V8_WARN_UNUSED_RESULT { return HType(k##Name); }
+ HTYPE_LIST(DECLARE_CONSTRUCTOR)
+ #undef DECLARE_CONSTRUCTOR
+
+ // Return the weakest (least precise) common type.
+ HType Combine(HType other) const V8_WARN_UNUSED_RESULT {
+ return HType(static_cast<Kind>(kind_ & other.kind_));
+ }
+
+ bool Equals(HType other) const V8_WARN_UNUSED_RESULT {
+ return kind_ == other.kind_;
+ }
+
+ bool IsSubtypeOf(HType other) const V8_WARN_UNUSED_RESULT {
+ return Combine(other).Equals(other);
+ }
+
+ #define DECLARE_IS_TYPE(Name, mask) \
+ bool Is##Name() const V8_WARN_UNUSED_RESULT { \
+ return IsSubtypeOf(HType::Name()); \
+ }
+ HTYPE_LIST(DECLARE_IS_TYPE)
+ #undef DECLARE_IS_TYPE
+
+ template <class T>
+ static HType FromType(typename T::TypeHandle type) V8_WARN_UNUSED_RESULT;
+ static HType FromValue(Handle<Object> value) V8_WARN_UNUSED_RESULT;
+
+ const char* ToString() const V8_WARN_UNUSED_RESULT;
+
+ private:
+ enum Kind {
+ #define DECLARE_TYPE(Name, mask) k##Name = mask,
+ HTYPE_LIST(DECLARE_TYPE)
+ #undef DECLARE_TYPE
+ LAST_KIND = kNone
+ };
+
+ // Make sure type fits in int16.
+ STATIC_ASSERT(LAST_KIND < (1 << (CHAR_BIT * sizeof(int16_t))));
+
+ explicit HType(Kind kind) : kind_(kind) { }
+
+ int16_t kind_;
+};
+
+} } // namespace v8::internal
+
+#endif // HYDROGEN_TYPES_H_
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | src/hydrogen-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698