2013-05-27 13:59:20 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-05-27 13:59:20 +00:00
|
|
|
|
|
|
|
#ifndef V8_TYPING_H_
|
|
|
|
#define V8_TYPING_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
|
|
|
|
|
|
|
#include "src/allocation.h"
|
|
|
|
#include "src/ast.h"
|
|
|
|
#include "src/compiler.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/effects.h"
|
|
|
|
#include "src/scopes.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/type-info.h"
|
|
|
|
#include "src/types.h"
|
|
|
|
#include "src/zone.h"
|
2013-05-27 13:59:20 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
|
|
class AstTyper: public AstVisitor {
|
|
|
|
public:
|
2013-06-12 17:20:37 +00:00
|
|
|
static void Run(CompilationInfo* info);
|
2013-05-27 13:59:20 +00:00
|
|
|
|
|
|
|
void* operator new(size_t size, Zone* zone) {
|
|
|
|
return zone->New(static_cast<int>(size));
|
|
|
|
}
|
|
|
|
void operator delete(void* pointer, Zone* zone) { }
|
|
|
|
void operator delete(void* pointer) { }
|
|
|
|
|
|
|
|
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit AstTyper(CompilationInfo* info);
|
|
|
|
|
2013-12-18 10:38:58 +00:00
|
|
|
Effect ObservedOnStack(Object* value);
|
|
|
|
void ObserveTypesAtOsrEntry(IterationStatement* stmt);
|
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
static const int kNoVar = INT_MIN;
|
|
|
|
typedef v8::internal::Effects<int, kNoVar> Effects;
|
|
|
|
typedef v8::internal::NestedEffects<int, kNoVar> Store;
|
|
|
|
|
2013-05-27 13:59:20 +00:00
|
|
|
CompilationInfo* info_;
|
|
|
|
TypeFeedbackOracle oracle_;
|
2013-08-06 12:57:23 +00:00
|
|
|
Store store_;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
|
|
|
TypeFeedbackOracle* oracle() { return &oracle_; }
|
|
|
|
|
2013-07-11 11:47:05 +00:00
|
|
|
void NarrowType(Expression* e, Bounds b) {
|
2014-01-21 16:22:52 +00:00
|
|
|
e->set_bounds(Bounds::Both(e->bounds(), b, zone()));
|
2013-06-21 11:10:06 +00:00
|
|
|
}
|
2014-01-21 16:22:52 +00:00
|
|
|
void NarrowLowerType(Expression* e, Type* t) {
|
|
|
|
e->set_bounds(Bounds::NarrowLower(e->bounds(), t, zone()));
|
2013-07-09 11:48:47 +00:00
|
|
|
}
|
2013-06-21 11:10:06 +00:00
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
Effects EnterEffects() {
|
|
|
|
store_ = store_.Push();
|
|
|
|
return store_.Top();
|
|
|
|
}
|
|
|
|
void ExitEffects() { store_ = store_.Pop(); }
|
|
|
|
|
2013-12-18 10:38:58 +00:00
|
|
|
int parameter_index(int index) { return -index - 2; }
|
|
|
|
int stack_local_index(int index) { return index; }
|
|
|
|
|
2013-08-06 12:57:23 +00:00
|
|
|
int variable_index(Variable* var) {
|
2013-12-12 15:19:57 +00:00
|
|
|
// Stack locals have the range [0 .. l]
|
|
|
|
// Parameters have the range [-1 .. p]
|
|
|
|
// We map this to [-p-2 .. -1, 0 .. l]
|
2013-12-18 10:38:58 +00:00
|
|
|
return var->IsStackLocal() ? stack_local_index(var->index()) :
|
|
|
|
var->IsParameter() ? parameter_index(var->index()) : kNoVar;
|
2013-08-06 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 18:31:01 +00:00
|
|
|
void VisitDeclarations(ZoneList<Declaration*>* declarations) OVERRIDE;
|
|
|
|
void VisitStatements(ZoneList<Statement*>* statements) OVERRIDE;
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2014-10-29 18:31:01 +00:00
|
|
|
#define DECLARE_VISIT(type) virtual void Visit##type(type* node) OVERRIDE;
|
2013-05-27 13:59:20 +00:00
|
|
|
AST_NODE_LIST(DECLARE_VISIT)
|
|
|
|
#undef DECLARE_VISIT
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AstTyper);
|
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_TYPING_H_
|