1 // 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.
5 #ifndef V8_TYPING_ASM_H_
6 #define V8_TYPING_ASM_H_
8 #include "src/allocation.h"
10 #include "src/effects.h"
11 #include "src/type-info.h"
12 #include "src/types.h"
20 class AsmTyper : public AstVisitor {
22 explicit AsmTyper(Isolate* isolate, Zone* zone, Script* script,
23 FunctionLiteral* root);
25 const char* error_message() { return error_message_; }
27 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
31 FunctionLiteral* root_;
34 // Information for bi-directional typing with a cap on nesting depth.
37 int intish_; // How many ops we've gone without a x|0.
39 Type* return_type_; // Return type of last function.
40 size_t array_size_; // Array size of last ArrayLiteral.
42 typedef ZoneMap<std::string, Type*> ObjectTypeMap;
43 ObjectTypeMap stdlib_types_;
44 ObjectTypeMap stdlib_heap_types_;
45 ObjectTypeMap stdlib_math_types_;
47 // Map from Variable* to global/local variable Type*.
48 ZoneHashMap global_variable_type_;
49 ZoneHashMap local_variable_type_;
51 bool in_function_; // In module function?
52 bool building_function_tables_;
54 ZoneTypeCache const& cache_;
56 static const int kErrorMessageLimit = 100;
57 char error_message_[kErrorMessageLimit];
59 static const int kMaxUncombinedAdditiveSteps = 1 << 20;
60 static const int kMaxUncombinedMultiplicativeSteps = 1;
62 void InitializeStdlib();
64 void VisitDeclarations(ZoneList<Declaration*>* d) override;
65 void VisitStatements(ZoneList<Statement*>* s) override;
67 void VisitExpressionAnnotation(Expression* e);
68 void VisitFunctionAnnotation(FunctionLiteral* f);
69 void VisitAsmModule(FunctionLiteral* f);
71 void VisitHeapAccess(Property* expr);
73 int ElementShiftSize(Type* type);
75 void SetType(Variable* variable, Type* type);
76 Type* GetType(Variable* variable);
78 Type* LibType(ObjectTypeMap map, Handle<String> name);
80 void SetResult(Expression* expr, Type* type);
81 void IntersectResult(Expression* expr, Type* type);
83 void VisitWithExpectation(Expression* expr, Type* expected_type,
86 #define DECLARE_VISIT(type) virtual void Visit##type(type* node) override;
87 AST_NODE_LIST(DECLARE_VISIT)
90 DISALLOW_COPY_AND_ASSIGN(AsmTyper);
93 } // namespace v8::internal
95 #endif // V8_TYPING_ASM_H_