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 kZeroToThirtyTwo = CreateRange(0.0, 32.0); | |
41 Type* const kZeroish = | |
42 Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone()); | |
43 Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY); | |
44 Type* const kWeakint = Type::Union(kInteger, Type::MinusZeroOrNaN(), zone()); | |
45 | |
46 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ | |
47 Type* const k##TypeName##Array = CreateArray(k##TypeName); | |
48 TYPED_ARRAYS(TYPED_ARRAY) | |
49 #undef TYPED_ARRAY | |
50 | |
51 private: | |
52 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } | |
53 | |
54 Type* CreateArrayFunction(Type* array) { | |
55 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); | |
56 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); | |
57 Type* arg3 = arg2; | |
58 return Type::Function(array, arg1, arg2, arg3, zone()); | |
59 } | |
60 | |
61 Type* CreateNative(Type* semantic, Type* representation) { | |
62 return Type::Intersect(semantic, representation, zone()); | |
63 } | |
64 | |
65 template <typename T> | |
66 Type* CreateRange() { | |
67 return CreateRange(std::numeric_limits<T>::min(), | |
68 std::numeric_limits<T>::max()); | |
69 } | |
70 | |
71 Type* CreateRange(double min, double max) { | |
72 return Type::Range(min, max, zone()); | |
73 } | |
74 | |
75 Zone* zone() { return &zone_; } | |
76 }; | |
77 | |
78 } // namespace internal | |
79 } // namespace v8 | |
80 | |
81 #endif // V8_ZONE_TYPE_CACHE_H_ | |
OLD | NEW |