summaryrefslogtreecommitdiff
path: root/deps/v8/src/number-info.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/number-info.h')
-rw-r--r--deps/v8/src/number-info.h160
1 files changed, 139 insertions, 21 deletions
diff --git a/deps/v8/src/number-info.h b/deps/v8/src/number-info.h
index c6f32e47c1..bfc0d9fd2d 100644
--- a/deps/v8/src/number-info.h
+++ b/deps/v8/src/number-info.h
@@ -31,42 +31,160 @@
namespace v8 {
namespace internal {
-class NumberInfo : public AllStatic {
+// Unknown
+// |
+// Number
+// / |
+// HeapNumber Integer32
+// | |
+// | Smi
+// | /
+// Uninitialized.
+
+class NumberInfo {
public:
- enum Type {
- kUnknown = 0,
- kNumber = 1,
- kSmi = 3,
- kHeapNumber = 5,
- kUninitialized = 7
- };
+ NumberInfo() { }
+
+ static inline NumberInfo Unknown();
+ // We know it's a number of some sort.
+ static inline NumberInfo Number();
+ // We know it's signed or unsigned 32 bit integer.
+ static inline NumberInfo Integer32();
+ // We know it's a Smi.
+ static inline NumberInfo Smi();
+ // We know it's a heap number.
+ static inline NumberInfo HeapNumber();
+ // We haven't started collecting info yet.
+ static inline NumberInfo Uninitialized();
+
+ // Return compact representation. Very sensitive to enum values below!
+ int ThreeBitRepresentation() {
+ ASSERT(type_ != kUninitializedType);
+ int answer = type_ > 6 ? type_ -2 : type_;
+ ASSERT(answer >= 0);
+ ASSERT(answer <= 7);
+ return answer;
+ }
+
+ // Decode compact representation. Very sensitive to enum values below!
+ static NumberInfo ExpandedRepresentation(int three_bit_representation) {
+ Type t = static_cast<Type>(three_bit_representation >= 6 ?
+ three_bit_representation + 2 :
+ three_bit_representation);
+ ASSERT(t == kUnknownType ||
+ t == kNumberType ||
+ t == kInteger32Type ||
+ t == kSmiType ||
+ t == kHeapNumberType);
+ return NumberInfo(t);
+ }
+
+ int ToInt() {
+ return type_;
+ }
+
+ static NumberInfo FromInt(int bit_representation) {
+ Type t = static_cast<Type>(bit_representation);
+ ASSERT(t == kUnknownType ||
+ t == kNumberType ||
+ t == kInteger32Type ||
+ t == kSmiType ||
+ t == kHeapNumberType);
+ return NumberInfo(t);
+ }
// Return the weakest (least precise) common type.
- static Type Combine(Type a, Type b) {
- // Make use of the order of enum values.
- return static_cast<Type>(a & b);
+ static NumberInfo Combine(NumberInfo a, NumberInfo b) {
+ return NumberInfo(static_cast<Type>(a.type_ & b.type_));
+ }
+
+ inline bool IsUnknown() {
+ return type_ == kUnknownType;
+ }
+
+ inline bool IsNumber() {
+ ASSERT(type_ != kUninitializedType);
+ return ((type_ & kNumberType) == kNumberType);
+ }
+
+ inline bool IsSmi() {
+ ASSERT(type_ != kUninitializedType);
+ return ((type_ & kSmiType) == kSmiType);
+ }
+
+ inline bool IsInteger32() {
+ ASSERT(type_ != kUninitializedType);
+ return ((type_ & kInteger32Type) == kInteger32Type);
+ }
+
+ inline bool IsHeapNumber() {
+ ASSERT(type_ != kUninitializedType);
+ return ((type_ & kHeapNumberType) == kHeapNumberType);
}
- static bool IsNumber(Type a) {
- ASSERT(a != kUninitialized);
- return ((a & kNumber) != 0);
+ inline bool IsUninitialized() {
+ return type_ == kUninitializedType;
}
- static const char* ToString(Type a) {
- switch (a) {
- case kUnknown: return "UnknownType";
- case kNumber: return "NumberType";
- case kSmi: return "SmiType";
- case kHeapNumber: return "HeapNumberType";
- case kUninitialized:
+ const char* ToString() {
+ switch (type_) {
+ case kUnknownType: return "UnknownType";
+ case kNumberType: return "NumberType";
+ case kSmiType: return "SmiType";
+ case kHeapNumberType: return "HeapNumberType";
+ case kInteger32Type: return "Integer32Type";
+ case kUninitializedType:
UNREACHABLE();
return "UninitializedType";
}
UNREACHABLE();
return "Unreachable code";
}
+
+ private:
+ enum Type {
+ kUnknownType = 0,
+ kNumberType = 1,
+ kInteger32Type = 3,
+ kSmiType = 7,
+ kHeapNumberType = 9,
+ kUninitializedType = 15
+ };
+ explicit inline NumberInfo(Type t) : type_(t) { }
+
+ Type type_;
};
+
+NumberInfo NumberInfo::Unknown() {
+ return NumberInfo(kUnknownType);
+}
+
+
+NumberInfo NumberInfo::Number() {
+ return NumberInfo(kNumberType);
+}
+
+
+NumberInfo NumberInfo::Integer32() {
+ return NumberInfo(kInteger32Type);
+}
+
+
+NumberInfo NumberInfo::Smi() {
+ return NumberInfo(kSmiType);
+}
+
+
+NumberInfo NumberInfo::HeapNumber() {
+ return NumberInfo(kHeapNumberType);
+}
+
+
+NumberInfo NumberInfo::Uninitialized() {
+ return NumberInfo(kUninitializedType);
+}
+
} } // namespace v8::internal
#endif // V8_NUMBER_INFO_H_