typing.h 2.27 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
#include "src/ast/ast-type-bounds.h"
10
#include "src/ast/ast-types.h"
11
#include "src/ast/ast.h"
12
#include "src/ast/variables.h"
13
#include "src/effects.h"
14
#include "src/type-info.h"
15
#include "src/zone/zone.h"
16 17 18 19

namespace v8 {
namespace internal {

20 21
class DeclarationScope;
class Isolate;
22 23
class FunctionLiteral;

24
class AstTyper final : public AstVisitor<AstTyper> {
25
 public:
26
  AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
27
           DeclarationScope* scope, BailoutId osr_ast_id, FunctionLiteral* root,
28
           AstTypeBounds* bounds);
29
  void Run();
30 31 32 33

  DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();

 private:
34 35 36
  Effect ObservedOnStack(Object* value);
  void ObserveTypesAtOsrEntry(IterationStatement* stmt);

37 38 39 40
  static const int kNoVar = INT_MIN;
  typedef v8::internal::Effects<int, kNoVar> Effects;
  typedef v8::internal::NestedEffects<int, kNoVar> Store;

41
  Isolate* isolate_;
42
  Zone* zone_;
43
  Handle<JSFunction> closure_;
44
  DeclarationScope* scope_;
45 46
  BailoutId osr_ast_id_;
  FunctionLiteral* root_;
47
  TypeFeedbackOracle oracle_;
48
  Store store_;
49
  AstTypeBounds* bounds_;
50

51
  Zone* zone() const { return zone_; }
52 53
  TypeFeedbackOracle* oracle() { return &oracle_; }

54 55
  void NarrowType(Expression* e, AstBounds b) {
    bounds_->set(e, AstBounds::Both(bounds_->get(e), b, zone()));
56
  }
57 58
  void NarrowLowerType(Expression* e, AstType* t) {
    bounds_->set(e, AstBounds::NarrowLower(bounds_->get(e), t, zone()));
59
  }
60

61 62 63 64 65 66
  Effects EnterEffects() {
    store_ = store_.Push();
    return store_.Top();
  }
  void ExitEffects() { store_ = store_.Pop(); }

67 68 69
  int parameter_index(int index) { return -index - 2; }
  int stack_local_index(int index) { return index; }

70
  int variable_index(Variable* var);
71

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

75
#define DECLARE_VISIT(type) void Visit##type(type* node);
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_