typing.h 2.33 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_CRANKSHAFT_TYPING_H_
#define V8_CRANKSHAFT_TYPING_H_
7

8
#include "src/allocation.h"
9 10
#include "src/ast/ast.h"
#include "src/ast/scopes.h"
11
#include "src/effects.h"
12 13 14
#include "src/type-info.h"
#include "src/types.h"
#include "src/zone.h"
15 16 17 18 19 20 21

namespace v8 {
namespace internal {


class AstTyper: public AstVisitor {
 public:
22 23
  AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
           Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root);
24
  void Run();
25 26 27 28

  DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();

 private:
29 30 31
  Effect ObservedOnStack(Object* value);
  void ObserveTypesAtOsrEntry(IterationStatement* stmt);

32 33 34 35
  static const int kNoVar = INT_MIN;
  typedef v8::internal::Effects<int, kNoVar> Effects;
  typedef v8::internal::NestedEffects<int, kNoVar> Store;

36
  Isolate* isolate_;
37
  Zone* zone_;
38 39 40 41
  Handle<JSFunction> closure_;
  Scope* scope_;
  BailoutId osr_ast_id_;
  FunctionLiteral* root_;
42
  TypeFeedbackOracle oracle_;
43
  Store store_;
44

45
  Zone* zone() const { return zone_; }
46 47
  TypeFeedbackOracle* oracle() { return &oracle_; }

48
  void NarrowType(Expression* e, Bounds b) {
49
    e->set_bounds(Bounds::Both(e->bounds(), b, zone()));
50
  }
51 52
  void NarrowLowerType(Expression* e, Type* t) {
    e->set_bounds(Bounds::NarrowLower(e->bounds(), t, zone()));
53
  }
54

55 56 57 58 59 60
  Effects EnterEffects() {
    store_ = store_.Push();
    return store_.Top();
  }
  void ExitEffects() { store_ = store_.Pop(); }

61 62 63
  int parameter_index(int index) { return -index - 2; }
  int stack_local_index(int index) { return index; }

64
  int variable_index(Variable* var) {
65 66 67
    // Stack locals have the range [0 .. l]
    // Parameters have the range [-1 .. p]
    // We map this to [-p-2 .. -1, 0 .. l]
68 69
    return var->IsStackLocal() ? stack_local_index(var->index()) :
           var->IsParameter() ? parameter_index(var->index()) : kNoVar;
70 71
  }

72 73
  void VisitDeclarations(ZoneList<Declaration*>* declarations) override;
  void VisitStatements(ZoneList<Statement*>* statements) override;
74

75
#define DECLARE_VISIT(type) void Visit##type(type* node) override;
76 77 78 79 80 81
  AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT

  DISALLOW_COPY_AND_ASSIGN(AstTyper);
};

82 83
}  // namespace internal
}  // namespace v8
84

85
#endif  // V8_CRANKSHAFT_TYPING_H_