Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 1 | // Copyright 2016 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_COMPILER_OPERATION_TYPER_H_ |
| 6 | #define V8_COMPILER_OPERATION_TYPER_H_ |
| 7 | |
| 8 | #include "src/base/flags.h" |
| 9 | #include "src/compiler/opcodes.h" |
| 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
| 14 | class Isolate; |
| 15 | class RangeType; |
| 16 | class Type; |
| 17 | class TypeCache; |
| 18 | class Zone; |
| 19 | |
| 20 | namespace compiler { |
| 21 | |
| 22 | class OperationTyper { |
| 23 | public: |
| 24 | OperationTyper(Isolate* isolate, Zone* zone); |
| 25 | |
| 26 | // Typing Phi. |
| 27 | Type* Merge(Type* left, Type* right); |
| 28 | |
| 29 | Type* ToPrimitive(Type* type); |
| 30 | |
| 31 | // Helpers for number operation typing. |
| 32 | Type* ToNumber(Type* type); |
| 33 | Type* WeakenRange(Type* current_range, Type* previous_range); |
| 34 | |
| 35 | Type* NumericAdd(Type* lhs, Type* rhs); |
| 36 | Type* NumericSubtract(Type* lhs, Type* rhs); |
| 37 | Type* NumericMultiply(Type* lhs, Type* rhs); |
| 38 | Type* NumericDivide(Type* lhs, Type* rhs); |
| 39 | Type* NumericModulus(Type* lhs, Type* rhs); |
| 40 | |
| 41 | enum ComparisonOutcomeFlags { |
| 42 | kComparisonTrue = 1, |
| 43 | kComparisonFalse = 2, |
| 44 | kComparisonUndefined = 4 |
| 45 | }; |
| 46 | |
| 47 | // Javascript binop typers. |
| 48 | #define DECLARE_CASE(x) Type* Type##x(Type* lhs, Type* rhs); |
| 49 | JS_SIMPLE_BINOP_LIST(DECLARE_CASE) |
| 50 | #undef DECLARE_CASE |
| 51 | |
| 52 | Type* singleton_false() { return singleton_false_; } |
| 53 | Type* singleton_true() { return singleton_true_; } |
| 54 | Type* singleton_the_hole() { return singleton_the_hole_; } |
| 55 | |
| 56 | private: |
| 57 | typedef base::Flags<ComparisonOutcomeFlags> ComparisonOutcome; |
| 58 | |
| 59 | ComparisonOutcome Invert(ComparisonOutcome); |
| 60 | Type* Invert(Type*); |
| 61 | Type* FalsifyUndefined(ComparisonOutcome); |
| 62 | |
| 63 | Type* Rangify(Type*); |
| 64 | Type* AddRanger(double lhs_min, double lhs_max, double rhs_min, |
| 65 | double rhs_max); |
| 66 | Type* SubtractRanger(RangeType* lhs, RangeType* rhs); |
| 67 | Type* MultiplyRanger(Type* lhs, Type* rhs); |
| 68 | Type* ModulusRanger(RangeType* lhs, RangeType* rhs); |
| 69 | |
| 70 | Zone* zone() { return zone_; } |
| 71 | |
| 72 | Zone* zone_; |
| 73 | TypeCache const& cache_; |
| 74 | |
| 75 | Type* singleton_false_; |
| 76 | Type* singleton_true_; |
| 77 | Type* singleton_the_hole_; |
| 78 | }; |
| 79 | |
| 80 | } // namespace compiler |
| 81 | } // namespace internal |
| 82 | } // namespace v8 |
| 83 | |
| 84 | #endif // V8_COMPILER_OPERATION_TYPER_H_ |