1 // Copyright 2013 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.
8 #include "src/allocation.h"
10 #include "src/effects.h"
11 #include "src/scopes.h"
12 #include "src/type-info.h"
13 #include "src/types.h"
20 class AstTyper: public AstVisitor {
22 AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
23 Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root);
26 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
29 Effect ObservedOnStack(Object* value);
30 void ObserveTypesAtOsrEntry(IterationStatement* stmt);
32 static const int kNoVar = INT_MIN;
33 typedef v8::internal::Effects<int, kNoVar> Effects;
34 typedef v8::internal::NestedEffects<int, kNoVar> Store;
36 Handle<JSFunction> closure_;
38 BailoutId osr_ast_id_;
39 FunctionLiteral* root_;
40 TypeFeedbackOracle oracle_;
43 TypeFeedbackOracle* oracle() { return &oracle_; }
45 void NarrowType(Expression* e, Bounds b) {
46 e->set_bounds(Bounds::Both(e->bounds(), b, zone()));
48 void NarrowLowerType(Expression* e, Type* t) {
49 e->set_bounds(Bounds::NarrowLower(e->bounds(), t, zone()));
52 Effects EnterEffects() {
53 store_ = store_.Push();
56 void ExitEffects() { store_ = store_.Pop(); }
58 int parameter_index(int index) { return -index - 2; }
59 int stack_local_index(int index) { return index; }
61 int variable_index(Variable* var) {
62 // Stack locals have the range [0 .. l]
63 // Parameters have the range [-1 .. p]
64 // We map this to [-p-2 .. -1, 0 .. l]
65 return var->IsStackLocal() ? stack_local_index(var->index()) :
66 var->IsParameter() ? parameter_index(var->index()) : kNoVar;
69 void VisitDeclarations(ZoneList<Declaration*>* declarations) override;
70 void VisitStatements(ZoneList<Statement*>* statements) override;
72 #define DECLARE_VISIT(type) virtual void Visit##type(type* node) override;
73 AST_NODE_LIST(DECLARE_VISIT)
76 DISALLOW_COPY_AND_ASSIGN(AstTyper);
79 } // namespace internal
82 #endif // V8_TYPING_H_