OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef V8_ZONE_TYPE_CACHE_H_ |
| 6 #define V8_ZONE_TYPE_CACHE_H_ |
| 7 |
| 8 |
| 9 #include "src/types.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 |
| 14 class ZoneTypeCache final { |
| 15 private: |
| 16 // This has to be first for the initialization magic to work. |
| 17 Zone zone_; |
| 18 |
| 19 public: |
| 20 ZoneTypeCache() = default; |
| 21 |
| 22 Type* const kInt8 = |
| 23 CreateNative(CreateRange<int8_t>(), Type::UntaggedSigned8()); |
| 24 Type* const kUint8 = |
| 25 CreateNative(CreateRange<uint8_t>(), Type::UntaggedUnsigned8()); |
| 26 Type* const kUint8Clamped = kUint8; |
| 27 Type* const kInt16 = |
| 28 CreateNative(CreateRange<int16_t>(), Type::UntaggedSigned16()); |
| 29 Type* const kUint16 = |
| 30 CreateNative(CreateRange<uint16_t>(), Type::UntaggedUnsigned16()); |
| 31 Type* const kInt32 = CreateNative(Type::Signed32(), Type::UntaggedSigned32()); |
| 32 Type* const kUint32 = |
| 33 CreateNative(Type::Unsigned32(), Type::UntaggedUnsigned32()); |
| 34 Type* const kFloat32 = CreateNative(Type::Number(), Type::UntaggedFloat32()); |
| 35 Type* const kFloat64 = CreateNative(Type::Number(), Type::UntaggedFloat64()); |
| 36 |
| 37 Type* const kSingletonZero = CreateRange(0.0, 0.0); |
| 38 Type* const kSingletonOne = CreateRange(1.0, 1.0); |
| 39 Type* const kZeroOrOne = CreateRange(0.0, 1.0); |
| 40 Type* const kZeroish = |
| 41 Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone()); |
| 42 Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY); |
| 43 Type* const kWeakint = Type::Union(kInteger, Type::MinusZeroOrNaN(), zone()); |
| 44 Type* const kWeakintFunc1 = Type::Function(kWeakint, Type::Number(), zone()); |
| 45 |
| 46 Type* const kRandomFunc0 = Type::Function(Type::OrderedNumber(), zone()); |
| 47 Type* const kAnyFunc0 = Type::Function(Type::Any(), zone()); |
| 48 Type* const kAnyFunc1 = Type::Function(Type::Any(), Type::Any(), zone()); |
| 49 Type* const kAnyFunc2 = |
| 50 Type::Function(Type::Any(), Type::Any(), Type::Any(), zone()); |
| 51 Type* const kAnyFunc3 = Type::Function(Type::Any(), Type::Any(), Type::Any(), |
| 52 Type::Any(), zone()); |
| 53 Type* const kNumberFunc0 = Type::Function(Type::Number(), zone()); |
| 54 Type* const kNumberFunc1 = |
| 55 Type::Function(Type::Number(), Type::Number(), zone()); |
| 56 Type* const kNumberFunc2 = |
| 57 Type::Function(Type::Number(), Type::Number(), Type::Number(), zone()); |
| 58 Type* const kImulFunc = Type::Function(Type::Signed32(), Type::Integral32(), |
| 59 Type::Integral32(), zone()); |
| 60 Type* const kClz32Func = |
| 61 Type::Function(CreateRange(0, 32), Type::Number(), zone()); |
| 62 |
| 63 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ |
| 64 Type* const k##TypeName##Array = CreateArray(k##TypeName); |
| 65 TYPED_ARRAYS(TYPED_ARRAY) |
| 66 #undef TYPED_ARRAY |
| 67 |
| 68 private: |
| 69 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } |
| 70 |
| 71 Type* CreateArrayFunction(Type* array) { |
| 72 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); |
| 73 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); |
| 74 Type* arg3 = arg2; |
| 75 return Type::Function(array, arg1, arg2, arg3, zone()); |
| 76 } |
| 77 |
| 78 Type* CreateNative(Type* semantic, Type* representation) { |
| 79 return Type::Intersect(semantic, representation, zone()); |
| 80 } |
| 81 |
| 82 template <typename T> |
| 83 Type* CreateRange() { |
| 84 return CreateRange(std::numeric_limits<T>::min(), |
| 85 std::numeric_limits<T>::max()); |
| 86 } |
| 87 |
| 88 Type* CreateRange(double min, double max) { |
| 89 return Type::Range(min, max, zone()); |
| 90 } |
| 91 |
| 92 Zone* zone() { return &zone_; } |
| 93 }; |
| 94 |
| 95 } // namespace internal |
| 96 } // namespace v8 |
| 97 |
| 98 #endif // V8_ZONE_TYPE_CACHE_H_ |
OLD | NEW |