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) {
27 return zone->New(static_cast<int>(size));
29 void operator delete(void* pointer, Zone* zone) { }
30 void operator delete(void* pointer) { }
32 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
35 explicit AstTyper(CompilationInfo* info);
37 Effect ObservedOnStack(Object* value);
38 void ObserveTypesAtOsrEntry(IterationStatement* stmt);
40 static const int kNoVar = INT_MIN;
41 typedef v8::internal::Effects<int, kNoVar> Effects;
42 typedef v8::internal::NestedEffects<int, kNoVar> Store;
44 CompilationInfo* info_;
45 TypeFeedbackOracle oracle_;
48 TypeFeedbackOracle* oracle() { return &oracle_; }
50 void NarrowType(Expression* e, Bounds b) {
51 e->set_bounds(Bounds::Both(e->bounds(), b, zone()));
53 void NarrowLowerType(Expression* e, Type* t) {
54 e->set_bounds(Bounds::NarrowLower(e->bounds(), t, zone()));
57 Effects EnterEffects() {
58 store_ = store_.Push();
61 void ExitEffects() { store_ = store_.Pop(); }
63 int parameter_index(int index) { return -index - 2; }
64 int stack_local_index(int index) { return index; }
66 int variable_index(Variable* var) {
67 // Stack locals have the range [0 .. l]
68 // Parameters have the range [-1 .. p]
69 // We map this to [-p-2 .. -1, 0 .. l]
70 return var->IsStackLocal() ? stack_local_index(var->index()) :
71 var->IsParameter() ? parameter_index(var->index()) : kNoVar;
74 void VisitDeclarations(ZoneList<Declaration*>* declarations) OVERRIDE;
75 void VisitStatements(ZoneList<Statement*>* statements) OVERRIDE;
77 #define DECLARE_VISIT(type) virtual void Visit##type(type* node) OVERRIDE;
78 AST_NODE_LIST(DECLARE_VISIT)
81 DISALLOW_COPY_AND_ASSIGN(AstTyper);
84 } } // namespace v8::internal
86 #endif // V8_TYPING_H_