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:
kmillikin@chromium.org 2009-08-07 10:35:48 +00:00
parent 90772fa427
commit 2851185938
2 changed files with 72 additions and 61 deletions

View File

@ -75,7 +75,7 @@ Cfg* Cfg::Build() {
BAILOUT("empty function body"); BAILOUT("empty function body");
} }
StatementBuilder builder; StatementCfgBuilder builder;
builder.VisitStatements(body); builder.VisitStatements(body);
Cfg* graph = builder.graph(); Cfg* graph = builder.graph();
if (graph == NULL) { if (graph == NULL) {
@ -231,10 +231,12 @@ void ReturnInstr::FastAllocate(TempLocation* temp) {
// The expression builder should not be used for declarations or statements. // 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) \ #define DEFINE_VISIT(type) \
void ExpressionBuilder::Visit##type(type* stmt) { UNREACHABLE(); } void ExpressionCfgBuilder::Visit##type(type* stmt) { UNREACHABLE(); }
STATEMENT_NODE_LIST(DEFINE_VISIT) STATEMENT_NODE_LIST(DEFINE_VISIT)
#undef DEFINE_VISIT #undef DEFINE_VISIT
@ -246,28 +248,28 @@ STATEMENT_NODE_LIST(DEFINE_VISIT)
return; \ return; \
} while (false) } while (false)
void ExpressionBuilder::VisitFunctionLiteral(FunctionLiteral* expr) { void ExpressionCfgBuilder::VisitFunctionLiteral(FunctionLiteral* expr) {
BAILOUT("FunctionLiteral"); BAILOUT("FunctionLiteral");
} }
void ExpressionBuilder::VisitFunctionBoilerplateLiteral( void ExpressionCfgBuilder::VisitFunctionBoilerplateLiteral(
FunctionBoilerplateLiteral* expr) { FunctionBoilerplateLiteral* expr) {
BAILOUT("FunctionBoilerplateLiteral"); BAILOUT("FunctionBoilerplateLiteral");
} }
void ExpressionBuilder::VisitConditional(Conditional* expr) { void ExpressionCfgBuilder::VisitConditional(Conditional* expr) {
BAILOUT("Conditional"); BAILOUT("Conditional");
} }
void ExpressionBuilder::VisitSlot(Slot* expr) { void ExpressionCfgBuilder::VisitSlot(Slot* expr) {
BAILOUT("Slot"); BAILOUT("Slot");
} }
void ExpressionBuilder::VisitVariableProxy(VariableProxy* expr) { void ExpressionCfgBuilder::VisitVariableProxy(VariableProxy* expr) {
Expression* rewrite = expr->var()->rewrite(); Expression* rewrite = expr->var()->rewrite();
if (rewrite == NULL || rewrite->AsSlot() == NULL) { if (rewrite == NULL || rewrite->AsSlot() == NULL) {
BAILOUT("unsupported variable (not a slot)"); 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. // Ignore the passed destination.
value_ = new Constant(expr->handle()); value_ = new Constant(expr->handle());
} }
void ExpressionBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { void ExpressionCfgBuilder::VisitRegExpLiteral(RegExpLiteral* expr) {
BAILOUT("RegExpLiteral"); BAILOUT("RegExpLiteral");
} }
void ExpressionBuilder::VisitObjectLiteral(ObjectLiteral* expr) { void ExpressionCfgBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
BAILOUT("ObjectLiteral"); BAILOUT("ObjectLiteral");
} }
void ExpressionBuilder::VisitArrayLiteral(ArrayLiteral* expr) { void ExpressionCfgBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
BAILOUT("ArrayLiteral"); BAILOUT("ArrayLiteral");
} }
void ExpressionBuilder::VisitCatchExtensionObject(CatchExtensionObject* expr) { void ExpressionCfgBuilder::VisitCatchExtensionObject(
CatchExtensionObject* expr) {
BAILOUT("CatchExtensionObject"); BAILOUT("CatchExtensionObject");
} }
void ExpressionBuilder::VisitAssignment(Assignment* expr) { void ExpressionCfgBuilder::VisitAssignment(Assignment* expr) {
if (expr->op() != Token::ASSIGN && expr->op() != Token::INIT_VAR) { if (expr->op() != Token::ASSIGN && expr->op() != Token::INIT_VAR) {
BAILOUT("unsupported compound assignment"); BAILOUT("unsupported compound assignment");
} }
@ -328,7 +331,7 @@ void ExpressionBuilder::VisitAssignment(Assignment* expr) {
BAILOUT("unsupported slot lhs (not a parameter or local)"); BAILOUT("unsupported slot lhs (not a parameter or local)");
} }
ExpressionBuilder builder; ExpressionCfgBuilder builder;
SlotLocation* loc = new SlotLocation(slot->type(), slot->index()); SlotLocation* loc = new SlotLocation(slot->type(), slot->index());
builder.Build(expr->value(), loc); builder.Build(expr->value(), loc);
if (builder.graph() == NULL) { 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"); BAILOUT("Throw");
} }
void ExpressionBuilder::VisitProperty(Property* expr) { void ExpressionCfgBuilder::VisitProperty(Property* expr) {
BAILOUT("Property"); BAILOUT("Property");
} }
void ExpressionBuilder::VisitCall(Call* expr) { void ExpressionCfgBuilder::VisitCall(Call* expr) {
BAILOUT("Call"); BAILOUT("Call");
} }
void ExpressionBuilder::VisitCallEval(CallEval* expr) { void ExpressionCfgBuilder::VisitCallEval(CallEval* expr) {
BAILOUT("CallEval"); BAILOUT("CallEval");
} }
void ExpressionBuilder::VisitCallNew(CallNew* expr) { void ExpressionCfgBuilder::VisitCallNew(CallNew* expr) {
BAILOUT("CallNew"); BAILOUT("CallNew");
} }
void ExpressionBuilder::VisitCallRuntime(CallRuntime* expr) { void ExpressionCfgBuilder::VisitCallRuntime(CallRuntime* expr) {
BAILOUT("CallRuntime"); BAILOUT("CallRuntime");
} }
void ExpressionBuilder::VisitUnaryOperation(UnaryOperation* expr) { void ExpressionCfgBuilder::VisitUnaryOperation(UnaryOperation* expr) {
BAILOUT("UnaryOperation"); BAILOUT("UnaryOperation");
} }
void ExpressionBuilder::VisitCountOperation(CountOperation* expr) { void ExpressionCfgBuilder::VisitCountOperation(CountOperation* expr) {
BAILOUT("CountOperation"); BAILOUT("CountOperation");
} }
void ExpressionBuilder::VisitBinaryOperation(BinaryOperation* expr) { void ExpressionCfgBuilder::VisitBinaryOperation(BinaryOperation* expr) {
Token::Value op = expr->op(); Token::Value op = expr->op();
switch (op) { switch (op) {
case Token::COMMA: case Token::COMMA:
@ -406,7 +409,7 @@ void ExpressionBuilder::VisitBinaryOperation(BinaryOperation* expr) {
case Token::MUL: case Token::MUL:
case Token::DIV: case Token::DIV:
case Token::MOD: { case Token::MOD: {
ExpressionBuilder left, right; ExpressionCfgBuilder left, right;
left.Build(expr->left(), NULL); left.Build(expr->left(), NULL);
if (left.graph() == NULL) { if (left.graph() == NULL) {
BAILOUT("unsupported left subexpression in binop"); 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"); BAILOUT("CompareOperation");
} }
void ExpressionBuilder::VisitThisFunction(ThisFunction* expr) { void ExpressionCfgBuilder::VisitThisFunction(ThisFunction* expr) {
BAILOUT("ThisFunction"); BAILOUT("ThisFunction");
} }
@ -467,7 +470,7 @@ void ExpressionBuilder::VisitThisFunction(ThisFunction* expr) {
#define CHECK_BAILOUT() \ #define CHECK_BAILOUT() \
if (graph() == NULL) { return; } else {} 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++) { for (int i = 0, len = stmts->length(); i < len; i++) {
Visit(stmts->at(i)); Visit(stmts->at(i));
CHECK_BAILOUT(); CHECK_BAILOUT();
@ -477,21 +480,21 @@ void StatementBuilder::VisitStatements(ZoneList<Statement*>* stmts) {
// The statement builder should not be used for declarations or expressions. // 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) \ #define DEFINE_VISIT(type) \
void StatementBuilder::Visit##type(type* expr) { UNREACHABLE(); } void StatementCfgBuilder::Visit##type(type* expr) { UNREACHABLE(); }
EXPRESSION_NODE_LIST(DEFINE_VISIT) EXPRESSION_NODE_LIST(DEFINE_VISIT)
#undef DEFINE_VISIT #undef DEFINE_VISIT
void StatementBuilder::VisitBlock(Block* stmt) { void StatementCfgBuilder::VisitBlock(Block* stmt) {
VisitStatements(stmt->statements()); VisitStatements(stmt->statements());
} }
void StatementBuilder::VisitExpressionStatement(ExpressionStatement* stmt) { void StatementCfgBuilder::VisitExpressionStatement(ExpressionStatement* stmt) {
ExpressionBuilder builder; ExpressionCfgBuilder builder;
builder.Build(stmt->expression(), CfgGlobals::current()->nowhere()); builder.Build(stmt->expression(), CfgGlobals::current()->nowhere());
if (builder.graph() == NULL) { if (builder.graph() == NULL) {
BAILOUT("unsupported expression in expression statement"); 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. // Nothing to do.
} }
void StatementBuilder::VisitIfStatement(IfStatement* stmt) { void StatementCfgBuilder::VisitIfStatement(IfStatement* stmt) {
BAILOUT("IfStatement"); BAILOUT("IfStatement");
} }
void StatementBuilder::VisitContinueStatement(ContinueStatement* stmt) { void StatementCfgBuilder::VisitContinueStatement(ContinueStatement* stmt) {
BAILOUT("ContinueStatement"); BAILOUT("ContinueStatement");
} }
void StatementBuilder::VisitBreakStatement(BreakStatement* stmt) { void StatementCfgBuilder::VisitBreakStatement(BreakStatement* stmt) {
BAILOUT("BreakStatement"); BAILOUT("BreakStatement");
} }
void StatementBuilder::VisitReturnStatement(ReturnStatement* stmt) { void StatementCfgBuilder::VisitReturnStatement(ReturnStatement* stmt) {
ExpressionBuilder builder; ExpressionCfgBuilder builder;
builder.Build(stmt->expression(), NULL); builder.Build(stmt->expression(), NULL);
if (builder.graph() == NULL) { if (builder.graph() == NULL) {
BAILOUT("unsupported expression in return statement"); 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"); BAILOUT("WithEnterStatement");
} }
void StatementBuilder::VisitWithExitStatement(WithExitStatement* stmt) { void StatementCfgBuilder::VisitWithExitStatement(WithExitStatement* stmt) {
BAILOUT("WithExitStatement"); BAILOUT("WithExitStatement");
} }
void StatementBuilder::VisitSwitchStatement(SwitchStatement* stmt) { void StatementCfgBuilder::VisitSwitchStatement(SwitchStatement* stmt) {
BAILOUT("SwitchStatement"); BAILOUT("SwitchStatement");
} }
void StatementBuilder::VisitLoopStatement(LoopStatement* stmt) { void StatementCfgBuilder::VisitLoopStatement(LoopStatement* stmt) {
BAILOUT("LoopStatement"); BAILOUT("LoopStatement");
} }
void StatementBuilder::VisitForInStatement(ForInStatement* stmt) { void StatementCfgBuilder::VisitForInStatement(ForInStatement* stmt) {
BAILOUT("ForInStatement"); BAILOUT("ForInStatement");
} }
void StatementBuilder::VisitTryCatch(TryCatch* stmt) { void StatementCfgBuilder::VisitTryCatch(TryCatch* stmt) {
BAILOUT("TryCatch"); BAILOUT("TryCatch");
} }
void StatementBuilder::VisitTryFinally(TryFinally* stmt) { void StatementCfgBuilder::VisitTryFinally(TryFinally* stmt) {
BAILOUT("TryFinally"); BAILOUT("TryFinally");
} }
void StatementBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) { void StatementCfgBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) {
BAILOUT("DebuggerStatement"); BAILOUT("DebuggerStatement");
} }

View File

@ -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 { class LocationSet BASE_EMBEDDED {
public: public:
// Construct an empty location set. // Construct an empty location set.
@ -669,6 +670,11 @@ class LocationSet BASE_EMBEDDED {
uintptr_t parameters() { return parameters_; } uintptr_t parameters() { return parameters_; }
uintptr_t locals() { return locals_; } uintptr_t locals() { return locals_; }
// Make this the empty set.
void Empty() {
parameters_ = locals_ = 0;
}
// Insert an element. // Insert an element.
void AddElement(SlotLocation* location) { void AddElement(SlotLocation* location) {
if (location->type() == Slot::PARAMETER) { 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 // fragment (currently a possibly empty list of instructions represented by
// a singleton instruction block) and the expression's value. // a singleton instruction block) and the expression's value.
// //
// Failure is to build the CFG is indicated by a NULL CFG. // Failure to build the CFG is indicated by a NULL CFG.
class ExpressionBuilder : public AstVisitor { class ExpressionCfgBuilder : public AstVisitor {
public: public:
ExpressionBuilder() : value_(NULL), graph_(NULL), destination_(NULL) {} ExpressionCfgBuilder() : destination_(NULL), value_(NULL), graph_(NULL) {}
// Result accessors. // Result accessors.
Value* value() { return value_; } Value* value() { return value_; }
@ -728,6 +734,7 @@ class ExpressionBuilder : public AstVisitor {
void Build(Expression* expr, Location* destination) { void Build(Expression* expr, Location* destination) {
value_ = NULL; value_ = NULL;
graph_ = new Cfg(); graph_ = new Cfg();
assigned_vars_.Empty();
destination_ = destination; destination_ = destination;
Visit(expr); Visit(expr);
} }
@ -738,22 +745,22 @@ class ExpressionBuilder : public AstVisitor {
#undef DECLARE_VISIT #undef DECLARE_VISIT
private: private:
// State for the visitor. Output parameters. // State for the visitor. Input parameters:
Location* destination_;
// Output parameters:
Value* value_; Value* value_;
Cfg* graph_; Cfg* graph_;
LocationSet assigned_vars_; LocationSet assigned_vars_;
// Input parameters.
Location* destination_;
}; };
// A StatementBuilder maintains a CFG fragment accumulator. When it visits // A StatementCfgBuilder maintains a CFG fragment accumulator. When it
// a statement, it concatenates the CFG for the statement to the end of the // visits a statement, it concatenates the CFG for the statement to the end
// accumulator. // of the accumulator.
class StatementBuilder : public AstVisitor { class StatementCfgBuilder : public AstVisitor {
public: public:
StatementBuilder() : graph_(new Cfg()) {} StatementCfgBuilder() : graph_(new Cfg()) {}
Cfg* graph() { return graph_; } Cfg* graph() { return graph_; }
@ -765,6 +772,7 @@ class StatementBuilder : public AstVisitor {
#undef DECLARE_VISIT #undef DECLARE_VISIT
private: private:
// State for the visitor. Input/output parameter:
Cfg* graph_; Cfg* graph_;
}; };