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