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.
10 #include "src/allocation.h"
12 #include "src/effects.h"
13 #include "src/scopes.h"
14 #include "src/type-info.h"
15 #include "src/types.h"
22 class AstTyper: public AstVisitor {
24 static void Run(CompilationInfo* info);
26 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
27 void operator delete(void* pointer, Zone* zone) { }
28 void operator delete(void* pointer) { }
30 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
33 explicit AstTyper(CompilationInfo* info);
35 Effect ObservedOnStack(Object* value);
36 void ObserveTypesAtOsrEntry(IterationStatement* stmt);
38 static const int kNoVar = INT_MIN;
39 typedef v8::internal::Effects<int, kNoVar> Effects;
40 typedef v8::internal::NestedEffects<int, kNoVar> Store;
42 CompilationInfo* info_;
43 TypeFeedbackOracle oracle_;
46 TypeFeedbackOracle* oracle() { return &oracle_; }
48 void NarrowType(Expression* e, Bounds b) {
49 e->set_bounds(Bounds::Both(e->bounds(), b, zone()));
51 void NarrowLowerType(Expression* e, Type* t) {
52 e->set_bounds(Bounds::NarrowLower(e->bounds(), t, zone()));
55 Effects EnterEffects() {
56 store_ = store_.Push();
59 void ExitEffects() { store_ = store_.Pop(); }
61 int parameter_index(int index) { return -index - 2; }
62 int stack_local_index(int index) { return index; }
64 int variable_index(Variable* var) {
65 // Stack locals have the range [0 .. l]
66 // Parameters have the range [-1 .. p]
67 // We map this to [-p-2 .. -1, 0 .. l]
68 return var->IsStackLocal() ? stack_local_index(var->index()) :
69 var->IsParameter() ? parameter_index(var->index()) : kNoVar;
72 void VisitDeclarations(ZoneList<Declaration*>* declarations) OVERRIDE;
73 void VisitStatements(ZoneList<Statement*>* statements) OVERRIDE;
75 #define DECLARE_VISIT(type) virtual void Visit##type(type* node) OVERRIDE;
76 AST_NODE_LIST(DECLARE_VISIT)
79 DISALLOW_COPY_AND_ASSIGN(AstTyper);
82 } } // namespace v8::internal
84 #endif // V8_TYPING_H_