Index: src/machine-type.h |
diff --git a/src/machine-type.h b/src/machine-type.h |
index 69a48e76f788c5cc8b638f16f7a3c663fe5d2d0f..97f6ae3bbdb92342aaeed48d8d63badf4f323087 100644 |
--- a/src/machine-type.h |
+++ b/src/machine-type.h |
@@ -15,91 +15,179 @@ |
namespace v8 { |
namespace internal { |
-// Machine-level types and representations. |
-// TODO(titzer): Use the real type system instead of MachineType. |
-enum MachineType : uint16_t { |
- // Representations. |
- kRepBit = 1u << 0, |
- kRepWord8 = 1u << 1, |
- kRepWord16 = 1u << 2, |
- kRepWord32 = 1u << 3, |
- kRepWord64 = 1u << 4, |
- kRepFloat32 = 1u << 5, |
- kRepFloat64 = 1u << 6, |
- kRepTagged = 1u << 7, |
- |
- // Types. |
- kTypeBool = 1u << 8, |
- kTypeInt32 = 1u << 9, |
- kTypeUint32 = 1u << 10, |
- kTypeInt64 = 1u << 11, |
- kTypeUint64 = 1u << 12, |
- kTypeNumber = 1u << 13, |
- kTypeAny = 1u << 14, |
- |
- // Machine types. |
- kMachNone = 0u, |
- kMachBool = kRepBit | kTypeBool, |
- kMachFloat32 = kRepFloat32 | kTypeNumber, |
- kMachFloat64 = kRepFloat64 | kTypeNumber, |
- kMachInt8 = kRepWord8 | kTypeInt32, |
- kMachUint8 = kRepWord8 | kTypeUint32, |
- kMachInt16 = kRepWord16 | kTypeInt32, |
- kMachUint16 = kRepWord16 | kTypeUint32, |
- kMachInt32 = kRepWord32 | kTypeInt32, |
- kMachUint32 = kRepWord32 | kTypeUint32, |
- kMachInt64 = kRepWord64 | kTypeInt64, |
- kMachUint64 = kRepWord64 | kTypeUint64, |
- kMachIntPtr = (kPointerSize == 4) ? kMachInt32 : kMachInt64, |
- kMachUintPtr = (kPointerSize == 4) ? kMachUint32 : kMachUint64, |
- kMachPtr = (kPointerSize == 4) ? kRepWord32 : kRepWord64, |
- kMachAnyTagged = kRepTagged | kTypeAny |
+enum class MachineRepresentation : uint8_t { |
+ kNone, |
+ kBit, |
+ kWord8, |
+ kWord16, |
+ kWord32, |
+ kWord64, |
+ kFloat32, |
+ kFloat64, |
+ kTagged |
}; |
-V8_INLINE size_t hash_value(MachineType type) { |
- return static_cast<size_t>(type); |
-} |
+enum class MachineSemantic : uint8_t { |
+ kNone, |
+ kBool, |
+ kInt32, |
+ kUint32, |
+ kInt64, |
+ kUint64, |
+ kNumber, |
+ kAny |
+}; |
+ |
+class MachineType { |
+ public: |
+ MachineType() |
+ : representation_(MachineRepresentation::kNone), |
+ semantic_(MachineSemantic::kNone) {} |
+ MachineType(MachineRepresentation representation, MachineSemantic semantic) |
+ : representation_(representation), semantic_(semantic) {} |
+ |
+ bool operator==(MachineType other) const { |
+ return representation() == other.representation() && |
+ semantic() == other.semantic(); |
+ } |
+ |
+ bool operator!=(MachineType other) const { return !(*this == other); } |
-std::ostream& operator<<(std::ostream& os, const MachineType& type); |
-typedef uint16_t MachineTypeUnion; |
+ MachineRepresentation representation() const { return representation_; } |
+ MachineSemantic semantic() const { return semantic_; } |
-// Globally useful machine types and constants. |
-const MachineTypeUnion kRepMask = kRepBit | kRepWord8 | kRepWord16 | |
- kRepWord32 | kRepWord64 | kRepFloat32 | |
- kRepFloat64 | kRepTagged; |
-const MachineTypeUnion kTypeMask = kTypeBool | kTypeInt32 | kTypeUint32 | |
- kTypeInt64 | kTypeUint64 | kTypeNumber | |
- kTypeAny; |
+ bool IsSigned() { |
+ return semantic() == MachineSemantic::kInt32 || |
+ semantic() == MachineSemantic::kInt64; |
+ } |
+ bool IsUnsigned() { |
+ return semantic() == MachineSemantic::kUint32 || |
+ semantic() == MachineSemantic::kUint64; |
+ } |
-// Gets only the type of the given type. |
-inline MachineType TypeOf(MachineType machine_type) { |
- int result = machine_type & kTypeMask; |
- return static_cast<MachineType>(result); |
+ static MachineRepresentation PointerRepresentation() { |
+ return (kPointerSize == 4) ? MachineRepresentation::kWord32 |
+ : MachineRepresentation::kWord64; |
+ } |
+ static MachineType Pointer() { |
+ return MachineType(PointerRepresentation(), MachineSemantic::kNone); |
+ } |
+ static MachineType IntPtr() { |
+ return (kPointerSize == 4) ? Int32() : Int64(); |
+ } |
+ static MachineType Float32() { |
+ return MachineType(MachineRepresentation::kFloat32, |
+ MachineSemantic::kNumber); |
+ } |
+ static MachineType Float64() { |
+ return MachineType(MachineRepresentation::kFloat64, |
+ MachineSemantic::kNumber); |
+ } |
+ static MachineType Int8() { |
+ return MachineType(MachineRepresentation::kWord8, MachineSemantic::kInt32); |
+ } |
+ static MachineType Uint8() { |
+ return MachineType(MachineRepresentation::kWord8, MachineSemantic::kUint32); |
+ } |
+ static MachineType Int16() { |
+ return MachineType(MachineRepresentation::kWord16, MachineSemantic::kInt32); |
+ } |
+ static MachineType Uint16() { |
+ return MachineType(MachineRepresentation::kWord16, |
+ MachineSemantic::kUint32); |
+ } |
+ static MachineType Int32() { |
+ return MachineType(MachineRepresentation::kWord32, MachineSemantic::kInt32); |
+ } |
+ static MachineType Uint32() { |
+ return MachineType(MachineRepresentation::kWord32, |
+ MachineSemantic::kUint32); |
+ } |
+ static MachineType Int64() { |
+ return MachineType(MachineRepresentation::kWord64, MachineSemantic::kInt64); |
+ } |
+ static MachineType Uint64() { |
+ return MachineType(MachineRepresentation::kWord64, |
+ MachineSemantic::kUint64); |
+ } |
+ static MachineType AnyTagged() { |
+ return MachineType(MachineRepresentation::kTagged, MachineSemantic::kAny); |
+ } |
+ static MachineType Bool() { |
+ return MachineType(MachineRepresentation::kBit, MachineSemantic::kBool); |
+ } |
+ static MachineType TaggedBool() { |
+ return MachineType(MachineRepresentation::kTagged, MachineSemantic::kBool); |
+ } |
+ static MachineType None() { |
+ return MachineType(MachineRepresentation::kNone, MachineSemantic::kNone); |
+ } |
+ |
+ // These naked representations should eventually go away. |
+ static MachineType RepWord8() { |
+ return MachineType(MachineRepresentation::kWord8, MachineSemantic::kNone); |
+ } |
+ static MachineType RepWord16() { |
+ return MachineType(MachineRepresentation::kWord16, MachineSemantic::kNone); |
+ } |
+ static MachineType RepWord32() { |
+ return MachineType(MachineRepresentation::kWord32, MachineSemantic::kNone); |
+ } |
+ static MachineType RepWord64() { |
+ return MachineType(MachineRepresentation::kWord64, MachineSemantic::kNone); |
+ } |
+ static MachineType RepFloat32() { |
+ return MachineType(MachineRepresentation::kFloat32, MachineSemantic::kNone); |
+ } |
+ static MachineType RepFloat64() { |
+ return MachineType(MachineRepresentation::kFloat64, MachineSemantic::kNone); |
+ } |
+ static MachineType RepTagged() { |
+ return MachineType(MachineRepresentation::kTagged, MachineSemantic::kNone); |
+ } |
+ static MachineType RepBit() { |
+ return MachineType(MachineRepresentation::kBit, MachineSemantic::kNone); |
+ } |
+ |
+ private: |
+ MachineRepresentation representation_; |
+ MachineSemantic semantic_; |
+}; |
+ |
+V8_INLINE size_t hash_value(MachineRepresentation rep) { |
+ return static_cast<size_t>(rep); |
} |
-// Gets only the representation of the given type. |
-inline MachineType RepresentationOf(MachineType machine_type) { |
- int result = machine_type & kRepMask; |
- CHECK(base::bits::IsPowerOfTwo32(result)); |
- return static_cast<MachineType>(result); |
+V8_INLINE size_t hash_value(MachineType type) { |
+ return static_cast<size_t>(type.representation()) + |
+ static_cast<size_t>(type.semantic()) * 16; |
+} |
+ |
+std::ostream& operator<<(std::ostream& os, MachineRepresentation rep); |
+std::ostream& operator<<(std::ostream& os, MachineSemantic type); |
+std::ostream& operator<<(std::ostream& os, MachineType type); |
+ |
+inline bool IsFloatingPoint(MachineRepresentation rep) { |
+ return rep == MachineRepresentation::kFloat32 || |
+ rep == MachineRepresentation::kFloat64; |
} |
// Gets the log2 of the element size in bytes of the machine type. |
-inline int ElementSizeLog2Of(MachineType machine_type) { |
- switch (RepresentationOf(machine_type)) { |
- case kRepBit: |
- case kRepWord8: |
+inline int ElementSizeLog2Of(MachineRepresentation rep) { |
+ switch (rep) { |
+ case MachineRepresentation::kBit: |
+ case MachineRepresentation::kWord8: |
return 0; |
- case kRepWord16: |
+ case MachineRepresentation::kWord16: |
return 1; |
- case kRepWord32: |
- case kRepFloat32: |
+ case MachineRepresentation::kWord32: |
+ case MachineRepresentation::kFloat32: |
return 2; |
- case kRepWord64: |
- case kRepFloat64: |
+ case MachineRepresentation::kWord64: |
+ case MachineRepresentation::kFloat64: |
return 3; |
- case kRepTagged: |
+ case MachineRepresentation::kTagged: |
return kPointerSizeLog2; |
default: |
break; |
@@ -108,18 +196,6 @@ inline int ElementSizeLog2Of(MachineType machine_type) { |
return -1; |
} |
-// Gets the element size in bytes of the machine type. |
-inline int ElementSizeOf(MachineType machine_type) { |
- const int shift = ElementSizeLog2Of(machine_type); |
- DCHECK_NE(-1, shift); |
- return 1 << shift; |
-} |
- |
-inline bool IsFloatingPoint(MachineType type) { |
- MachineType rep = RepresentationOf(type); |
- return rep == kRepFloat32 || rep == kRepFloat64; |
-} |
- |
typedef Signature<MachineType> MachineSignature; |
} // namespace internal |