Rename: ExpressionBuilder => ExpressionCfgBuilder, StatementBuilder =>
StatementCfgBuilder. Review URL: http://codereview.chromium.org/165124 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2646 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
90772fa427
commit
2851185938
97
src/cfg.cc
97
src/cfg.cc
@ -75,7 +75,7 @@ Cfg* Cfg::Build() {
|
||||
BAILOUT("empty function body");
|
||||
}
|
||||
|
||||
StatementBuilder builder;
|
||||
StatementCfgBuilder builder;
|
||||
builder.VisitStatements(body);
|
||||
Cfg* graph = builder.graph();
|
||||
if (graph == NULL) {
|
||||
@ -231,10 +231,12 @@ void ReturnInstr::FastAllocate(TempLocation* temp) {
|
||||
|
||||
|
||||
// The expression builder should not be used for declarations or statements.
|
||||
void ExpressionBuilder::VisitDeclaration(Declaration* decl) { UNREACHABLE(); }
|
||||
void ExpressionCfgBuilder::VisitDeclaration(Declaration* decl) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
#define DEFINE_VISIT(type) \
|
||||
void ExpressionBuilder::Visit##type(type* stmt) { UNREACHABLE(); }
|
||||
void ExpressionCfgBuilder::Visit##type(type* stmt) { UNREACHABLE(); }
|
||||
STATEMENT_NODE_LIST(DEFINE_VISIT)
|
||||
#undef DEFINE_VISIT
|
||||
|
||||
@ -246,28 +248,28 @@ STATEMENT_NODE_LIST(DEFINE_VISIT)
|
||||
return; \
|
||||
} while (false)
|
||||
|
||||
void ExpressionBuilder::VisitFunctionLiteral(FunctionLiteral* expr) {
|
||||
void ExpressionCfgBuilder::VisitFunctionLiteral(FunctionLiteral* expr) {
|
||||
BAILOUT("FunctionLiteral");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitFunctionBoilerplateLiteral(
|
||||
void ExpressionCfgBuilder::VisitFunctionBoilerplateLiteral(
|
||||
FunctionBoilerplateLiteral* expr) {
|
||||
BAILOUT("FunctionBoilerplateLiteral");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitConditional(Conditional* expr) {
|
||||
void ExpressionCfgBuilder::VisitConditional(Conditional* expr) {
|
||||
BAILOUT("Conditional");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitSlot(Slot* expr) {
|
||||
void ExpressionCfgBuilder::VisitSlot(Slot* expr) {
|
||||
BAILOUT("Slot");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitVariableProxy(VariableProxy* expr) {
|
||||
void ExpressionCfgBuilder::VisitVariableProxy(VariableProxy* expr) {
|
||||
Expression* rewrite = expr->var()->rewrite();
|
||||
if (rewrite == NULL || rewrite->AsSlot() == NULL) {
|
||||
BAILOUT("unsupported variable (not a slot)");
|
||||
@ -281,33 +283,34 @@ void ExpressionBuilder::VisitVariableProxy(VariableProxy* expr) {
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitLiteral(Literal* expr) {
|
||||
void ExpressionCfgBuilder::VisitLiteral(Literal* expr) {
|
||||
// Ignore the passed destination.
|
||||
value_ = new Constant(expr->handle());
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitRegExpLiteral(RegExpLiteral* expr) {
|
||||
void ExpressionCfgBuilder::VisitRegExpLiteral(RegExpLiteral* expr) {
|
||||
BAILOUT("RegExpLiteral");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
|
||||
void ExpressionCfgBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
|
||||
BAILOUT("ObjectLiteral");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
|
||||
void ExpressionCfgBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
|
||||
BAILOUT("ArrayLiteral");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitCatchExtensionObject(CatchExtensionObject* expr) {
|
||||
void ExpressionCfgBuilder::VisitCatchExtensionObject(
|
||||
CatchExtensionObject* expr) {
|
||||
BAILOUT("CatchExtensionObject");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitAssignment(Assignment* expr) {
|
||||
void ExpressionCfgBuilder::VisitAssignment(Assignment* expr) {
|
||||
if (expr->op() != Token::ASSIGN && expr->op() != Token::INIT_VAR) {
|
||||
BAILOUT("unsupported compound assignment");
|
||||
}
|
||||
@ -328,7 +331,7 @@ void ExpressionBuilder::VisitAssignment(Assignment* expr) {
|
||||
BAILOUT("unsupported slot lhs (not a parameter or local)");
|
||||
}
|
||||
|
||||
ExpressionBuilder builder;
|
||||
ExpressionCfgBuilder builder;
|
||||
SlotLocation* loc = new SlotLocation(slot->type(), slot->index());
|
||||
builder.Build(expr->value(), loc);
|
||||
if (builder.graph() == NULL) {
|
||||
@ -347,47 +350,47 @@ void ExpressionBuilder::VisitAssignment(Assignment* expr) {
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitThrow(Throw* expr) {
|
||||
void ExpressionCfgBuilder::VisitThrow(Throw* expr) {
|
||||
BAILOUT("Throw");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitProperty(Property* expr) {
|
||||
void ExpressionCfgBuilder::VisitProperty(Property* expr) {
|
||||
BAILOUT("Property");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitCall(Call* expr) {
|
||||
void ExpressionCfgBuilder::VisitCall(Call* expr) {
|
||||
BAILOUT("Call");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitCallEval(CallEval* expr) {
|
||||
void ExpressionCfgBuilder::VisitCallEval(CallEval* expr) {
|
||||
BAILOUT("CallEval");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitCallNew(CallNew* expr) {
|
||||
void ExpressionCfgBuilder::VisitCallNew(CallNew* expr) {
|
||||
BAILOUT("CallNew");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitCallRuntime(CallRuntime* expr) {
|
||||
void ExpressionCfgBuilder::VisitCallRuntime(CallRuntime* expr) {
|
||||
BAILOUT("CallRuntime");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitUnaryOperation(UnaryOperation* expr) {
|
||||
void ExpressionCfgBuilder::VisitUnaryOperation(UnaryOperation* expr) {
|
||||
BAILOUT("UnaryOperation");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitCountOperation(CountOperation* expr) {
|
||||
void ExpressionCfgBuilder::VisitCountOperation(CountOperation* expr) {
|
||||
BAILOUT("CountOperation");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitBinaryOperation(BinaryOperation* expr) {
|
||||
void ExpressionCfgBuilder::VisitBinaryOperation(BinaryOperation* expr) {
|
||||
Token::Value op = expr->op();
|
||||
switch (op) {
|
||||
case Token::COMMA:
|
||||
@ -406,7 +409,7 @@ void ExpressionBuilder::VisitBinaryOperation(BinaryOperation* expr) {
|
||||
case Token::MUL:
|
||||
case Token::DIV:
|
||||
case Token::MOD: {
|
||||
ExpressionBuilder left, right;
|
||||
ExpressionCfgBuilder left, right;
|
||||
left.Build(expr->left(), NULL);
|
||||
if (left.graph() == NULL) {
|
||||
BAILOUT("unsupported left subexpression in binop");
|
||||
@ -445,12 +448,12 @@ void ExpressionBuilder::VisitBinaryOperation(BinaryOperation* expr) {
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitCompareOperation(CompareOperation* expr) {
|
||||
void ExpressionCfgBuilder::VisitCompareOperation(CompareOperation* expr) {
|
||||
BAILOUT("CompareOperation");
|
||||
}
|
||||
|
||||
|
||||
void ExpressionBuilder::VisitThisFunction(ThisFunction* expr) {
|
||||
void ExpressionCfgBuilder::VisitThisFunction(ThisFunction* expr) {
|
||||
BAILOUT("ThisFunction");
|
||||
}
|
||||
|
||||
@ -467,7 +470,7 @@ void ExpressionBuilder::VisitThisFunction(ThisFunction* expr) {
|
||||
#define CHECK_BAILOUT() \
|
||||
if (graph() == NULL) { return; } else {}
|
||||
|
||||
void StatementBuilder::VisitStatements(ZoneList<Statement*>* stmts) {
|
||||
void StatementCfgBuilder::VisitStatements(ZoneList<Statement*>* stmts) {
|
||||
for (int i = 0, len = stmts->length(); i < len; i++) {
|
||||
Visit(stmts->at(i));
|
||||
CHECK_BAILOUT();
|
||||
@ -477,21 +480,21 @@ void StatementBuilder::VisitStatements(ZoneList<Statement*>* stmts) {
|
||||
|
||||
|
||||
// The statement builder should not be used for declarations or expressions.
|
||||
void StatementBuilder::VisitDeclaration(Declaration* decl) { UNREACHABLE(); }
|
||||
void StatementCfgBuilder::VisitDeclaration(Declaration* decl) { UNREACHABLE(); }
|
||||
|
||||
#define DEFINE_VISIT(type) \
|
||||
void StatementBuilder::Visit##type(type* expr) { UNREACHABLE(); }
|
||||
void StatementCfgBuilder::Visit##type(type* expr) { UNREACHABLE(); }
|
||||
EXPRESSION_NODE_LIST(DEFINE_VISIT)
|
||||
#undef DEFINE_VISIT
|
||||
|
||||
|
||||
void StatementBuilder::VisitBlock(Block* stmt) {
|
||||
void StatementCfgBuilder::VisitBlock(Block* stmt) {
|
||||
VisitStatements(stmt->statements());
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitExpressionStatement(ExpressionStatement* stmt) {
|
||||
ExpressionBuilder builder;
|
||||
void StatementCfgBuilder::VisitExpressionStatement(ExpressionStatement* stmt) {
|
||||
ExpressionCfgBuilder builder;
|
||||
builder.Build(stmt->expression(), CfgGlobals::current()->nowhere());
|
||||
if (builder.graph() == NULL) {
|
||||
BAILOUT("unsupported expression in expression statement");
|
||||
@ -501,28 +504,28 @@ void StatementBuilder::VisitExpressionStatement(ExpressionStatement* stmt) {
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitEmptyStatement(EmptyStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitEmptyStatement(EmptyStatement* stmt) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitIfStatement(IfStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitIfStatement(IfStatement* stmt) {
|
||||
BAILOUT("IfStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitContinueStatement(ContinueStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitContinueStatement(ContinueStatement* stmt) {
|
||||
BAILOUT("ContinueStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitBreakStatement(BreakStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitBreakStatement(BreakStatement* stmt) {
|
||||
BAILOUT("BreakStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitReturnStatement(ReturnStatement* stmt) {
|
||||
ExpressionBuilder builder;
|
||||
void StatementCfgBuilder::VisitReturnStatement(ReturnStatement* stmt) {
|
||||
ExpressionCfgBuilder builder;
|
||||
builder.Build(stmt->expression(), NULL);
|
||||
if (builder.graph() == NULL) {
|
||||
BAILOUT("unsupported expression in return statement");
|
||||
@ -534,42 +537,42 @@ void StatementBuilder::VisitReturnStatement(ReturnStatement* stmt) {
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitWithEnterStatement(WithEnterStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitWithEnterStatement(WithEnterStatement* stmt) {
|
||||
BAILOUT("WithEnterStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitWithExitStatement(WithExitStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitWithExitStatement(WithExitStatement* stmt) {
|
||||
BAILOUT("WithExitStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitSwitchStatement(SwitchStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitSwitchStatement(SwitchStatement* stmt) {
|
||||
BAILOUT("SwitchStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitLoopStatement(LoopStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitLoopStatement(LoopStatement* stmt) {
|
||||
BAILOUT("LoopStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitForInStatement(ForInStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitForInStatement(ForInStatement* stmt) {
|
||||
BAILOUT("ForInStatement");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitTryCatch(TryCatch* stmt) {
|
||||
void StatementCfgBuilder::VisitTryCatch(TryCatch* stmt) {
|
||||
BAILOUT("TryCatch");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitTryFinally(TryFinally* stmt) {
|
||||
void StatementCfgBuilder::VisitTryFinally(TryFinally* stmt) {
|
||||
BAILOUT("TryFinally");
|
||||
}
|
||||
|
||||
|
||||
void StatementBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) {
|
||||
void StatementCfgBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) {
|
||||
BAILOUT("DebuggerStatement");
|
||||
}
|
||||
|
||||
|
36
src/cfg.h
36
src/cfg.h
@ -659,7 +659,8 @@ class Cfg : public ZoneObject {
|
||||
};
|
||||
|
||||
|
||||
// An implementation of a set of locations (currently slot locations).
|
||||
// An implementation of a set of locations (currently slot locations), most
|
||||
// of the operations are destructive.
|
||||
class LocationSet BASE_EMBEDDED {
|
||||
public:
|
||||
// Construct an empty location set.
|
||||
@ -669,6 +670,11 @@ class LocationSet BASE_EMBEDDED {
|
||||
uintptr_t parameters() { return parameters_; }
|
||||
uintptr_t locals() { return locals_; }
|
||||
|
||||
// Make this the empty set.
|
||||
void Empty() {
|
||||
parameters_ = locals_ = 0;
|
||||
}
|
||||
|
||||
// Insert an element.
|
||||
void AddElement(SlotLocation* location) {
|
||||
if (location->type() == Slot::PARAMETER) {
|
||||
@ -705,14 +711,14 @@ class LocationSet BASE_EMBEDDED {
|
||||
};
|
||||
|
||||
|
||||
// An ExpressionBuilder traverses an expression and returns an open CFG
|
||||
// An ExpressionCfgBuilder traverses an expression and returns an open CFG
|
||||
// fragment (currently a possibly empty list of instructions represented by
|
||||
// a singleton instruction block) and the expression's value.
|
||||
//
|
||||
// Failure is to build the CFG is indicated by a NULL CFG.
|
||||
class ExpressionBuilder : public AstVisitor {
|
||||
// Failure to build the CFG is indicated by a NULL CFG.
|
||||
class ExpressionCfgBuilder : public AstVisitor {
|
||||
public:
|
||||
ExpressionBuilder() : value_(NULL), graph_(NULL), destination_(NULL) {}
|
||||
ExpressionCfgBuilder() : destination_(NULL), value_(NULL), graph_(NULL) {}
|
||||
|
||||
// Result accessors.
|
||||
Value* value() { return value_; }
|
||||
@ -728,6 +734,7 @@ class ExpressionBuilder : public AstVisitor {
|
||||
void Build(Expression* expr, Location* destination) {
|
||||
value_ = NULL;
|
||||
graph_ = new Cfg();
|
||||
assigned_vars_.Empty();
|
||||
destination_ = destination;
|
||||
Visit(expr);
|
||||
}
|
||||
@ -738,22 +745,22 @@ class ExpressionBuilder : public AstVisitor {
|
||||
#undef DECLARE_VISIT
|
||||
|
||||
private:
|
||||
// State for the visitor. Output parameters.
|
||||
// State for the visitor. Input parameters:
|
||||
Location* destination_;
|
||||
|
||||
// Output parameters:
|
||||
Value* value_;
|
||||
Cfg* graph_;
|
||||
LocationSet assigned_vars_;
|
||||
|
||||
// Input parameters.
|
||||
Location* destination_;
|
||||
};
|
||||
|
||||
|
||||
// A StatementBuilder maintains a CFG fragment accumulator. When it visits
|
||||
// a statement, it concatenates the CFG for the statement to the end of the
|
||||
// accumulator.
|
||||
class StatementBuilder : public AstVisitor {
|
||||
// A StatementCfgBuilder maintains a CFG fragment accumulator. When it
|
||||
// visits a statement, it concatenates the CFG for the statement to the end
|
||||
// of the accumulator.
|
||||
class StatementCfgBuilder : public AstVisitor {
|
||||
public:
|
||||
StatementBuilder() : graph_(new Cfg()) {}
|
||||
StatementCfgBuilder() : graph_(new Cfg()) {}
|
||||
|
||||
Cfg* graph() { return graph_; }
|
||||
|
||||
@ -765,6 +772,7 @@ class StatementBuilder : public AstVisitor {
|
||||
#undef DECLARE_VISIT
|
||||
|
||||
private:
|
||||
// State for the visitor. Input/output parameter:
|
||||
Cfg* graph_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user