blob: c7984b2965c29fe0825343b3140d65319f14bf48 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 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_TYPING_ASM_H_
6#define V8_TYPING_ASM_H_
7
8#include "src/allocation.h"
9#include "src/ast/ast.h"
10#include "src/effects.h"
11#include "src/type-info.h"
12#include "src/types.h"
13#include "src/zone.h"
14
15namespace v8 {
16namespace internal {
17
18class TypeCache;
19
20class AsmTyper : public AstVisitor {
21 public:
22 explicit AsmTyper(Isolate* isolate, Zone* zone, Script* script,
23 FunctionLiteral* root);
24 bool Validate();
Ben Murdoch097c5b22016-05-18 11:27:45 +010025 void set_allow_simd(bool simd) { allow_simd_ = simd; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 const char* error_message() { return error_message_; }
27
28 enum StandardMember {
29 kNone = 0,
30 kStdlib,
31 kInfinity,
32 kNaN,
33 kMathAcos,
34 kMathAsin,
35 kMathAtan,
36 kMathCos,
37 kMathSin,
38 kMathTan,
39 kMathExp,
40 kMathLog,
41 kMathCeil,
42 kMathFloor,
43 kMathSqrt,
44 kMathAbs,
45 kMathMin,
46 kMathMax,
47 kMathAtan2,
48 kMathPow,
49 kMathImul,
50 kMathFround,
51 kMathE,
52 kMathLN10,
53 kMathLN2,
54 kMathLOG2E,
55 kMathLOG10E,
56 kMathPI,
57 kMathSQRT1_2,
58 kMathSQRT2,
59 };
60
61 StandardMember VariableAsStandardMember(Variable* variable);
62
63 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
64
65 private:
66 Zone* zone_;
67 Isolate* isolate_;
68 Script* script_;
69 FunctionLiteral* root_;
70 bool valid_;
71 bool allow_simd_;
72
73 struct VariableInfo : public ZoneObject {
74 Type* type;
75 bool is_check_function;
76 bool is_constructor_function;
77 StandardMember standard_member;
78
79 VariableInfo()
80 : type(NULL),
81 is_check_function(false),
82 is_constructor_function(false),
83 standard_member(kNone) {}
84 explicit VariableInfo(Type* t)
85 : type(t),
86 is_check_function(false),
87 is_constructor_function(false),
88 standard_member(kNone) {}
89 };
90
91 // Information for bi-directional typing with a cap on nesting depth.
92 Type* expected_type_;
93 Type* computed_type_;
94 VariableInfo* property_info_;
Ben Murdochda12d292016-06-02 14:46:10 +010095 int32_t intish_; // How many ops we've gone without a x|0.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000096
97 Type* return_type_; // Return type of last function.
98 size_t array_size_; // Array size of last ArrayLiteral.
99
100 typedef ZoneMap<std::string, VariableInfo*> ObjectTypeMap;
101 ObjectTypeMap stdlib_types_;
102 ObjectTypeMap stdlib_heap_types_;
103 ObjectTypeMap stdlib_math_types_;
104#define V(NAME, Name, name, lane_count, lane_type) \
105 ObjectTypeMap stdlib_simd_##name##_types_; \
106 VariableInfo* stdlib_simd_##name##_constructor_type_;
107 SIMD128_TYPES(V)
108#undef V
109
110 // Map from Variable* to global/local variable Type*.
111 ZoneHashMap global_variable_type_;
112 ZoneHashMap local_variable_type_;
113
114 bool in_function_; // In module function?
115 bool building_function_tables_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100116 bool visiting_exports_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117
118 TypeCache const& cache_;
119
120 static const int kErrorMessageLimit = 100;
121 char error_message_[kErrorMessageLimit];
122
123 static const int kMaxUncombinedAdditiveSteps = 1 << 20;
124 static const int kMaxUncombinedMultiplicativeSteps = 1;
125
126 void InitializeStdlib();
127 void InitializeStdlibSIMD();
128
129 void VisitDeclarations(ZoneList<Declaration*>* d) override;
130 void VisitStatements(ZoneList<Statement*>* s) override;
131
132 void VisitExpressionAnnotation(Expression* e, Variable* var, bool is_return);
133 void VisitFunctionAnnotation(FunctionLiteral* f);
134 void VisitAsmModule(FunctionLiteral* f);
135
136 void VisitHeapAccess(Property* expr, bool assigning, Type* assignment_type);
137
Ben Murdochda12d292016-06-02 14:46:10 +0100138 void CheckPolymorphicStdlibArguments(enum StandardMember standard_member,
139 ZoneList<Expression*>* args);
140
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141 Expression* GetReceiverOfPropertyAccess(Expression* expr, const char* name);
142 bool IsMathObject(Expression* expr);
143 bool IsSIMDObject(Expression* expr);
144 bool IsSIMDTypeObject(Expression* expr, const char* name);
145 bool IsStdlibObject(Expression* expr);
146
147 void VisitSIMDProperty(Property* expr);
148
149 int ElementShiftSize(Type* type);
150 Type* StorageType(Type* type);
151
152 void SetType(Variable* variable, Type* type);
153 Type* GetType(Variable* variable);
154 VariableInfo* GetVariableInfo(Variable* variable, bool setting);
155 void SetVariableInfo(Variable* variable, const VariableInfo* info);
156
157 VariableInfo* LibType(ObjectTypeMap* map, Handle<String> name);
158 void VisitLibraryAccess(ObjectTypeMap* map, Property* expr);
159
160 void SetResult(Expression* expr, Type* type);
161 void IntersectResult(Expression* expr, Type* type);
162
163 void VisitWithExpectation(Expression* expr, Type* expected_type,
164 const char* msg);
165
166 void VisitLiteral(Literal* expr, bool is_return);
167
Ben Murdoch097c5b22016-05-18 11:27:45 +0100168 void VisitVariableProxy(VariableProxy* expr, bool assignment);
169
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000170 void VisitIntegerBitwiseOperator(BinaryOperation* expr, Type* left_expected,
171 Type* right_expected, Type* result_type,
172 bool conversion);
173
174 Zone* zone() const { return zone_; }
175
176#define DECLARE_VISIT(type) void Visit##type(type* node) override;
177 AST_NODE_LIST(DECLARE_VISIT)
178#undef DECLARE_VISIT
179
180 DISALLOW_COPY_AND_ASSIGN(AsmTyper);
181};
182} // namespace internal
183} // namespace v8
184
185#endif // V8_TYPING_ASM_H_