Revision: 3748
Author: [email protected]
Date: Fri Jan 29 07:29:33 2010
Log: Add fast code generator visitor.
It does not yet emit code so there is a flag --print-ir to print the
AST as seen by the code generator.
Review URL: http://codereview.chromium.org/558042
http://code.google.com/p/v8/source/detail?r=3748
Modified:
/branches/bleeding_edge/src/compiler.cc
/branches/bleeding_edge/src/compiler.h
/branches/bleeding_edge/src/fast-codegen.cc
/branches/bleeding_edge/src/fast-codegen.h
/branches/bleeding_edge/src/flag-definitions.h
=======================================
--- /branches/bleeding_edge/src/compiler.cc Fri Jan 29 03:55:40 2010
+++ /branches/bleeding_edge/src/compiler.cc Fri Jan 29 07:29:33 2010
@@ -31,7 +31,6 @@
#include "codegen-inl.h"
#include "compilation-cache.h"
#include "compiler.h"
-#include "data-flow.h"
#include "debug.h"
#include "fast-codegen.h"
#include "full-codegen.h"
@@ -113,10 +112,9 @@
FastCodeGenSyntaxChecker checker;
checker.Check(literal, info);
if (checker.has_supported_syntax()) {
- AstLabeler labeler;
- labeler.Label(literal);
- }
- // Does not yet generate code.
+ // Does not yet generate code.
+ FastCodeGenerator::MakeCode(literal, script, is_eval, info);
+ }
}
return CodeGenerator::MakeCode(literal, script, is_eval, info);
@@ -513,10 +511,9 @@
FastCodeGenSyntaxChecker checker;
checker.Check(literal, &info);
if (checker.has_supported_syntax()) {
- AstLabeler label_nodes;
- label_nodes.Label(literal);
- }
- // Generate no code.
+ // Does not yet generate code.
+ FastCodeGenerator::MakeCode(literal, script, false, &info);
+ }
}
if (!is_compiled) {
=======================================
--- /branches/bleeding_edge/src/compiler.h Fri Jan 29 03:55:40 2010
+++ /branches/bleeding_edge/src/compiler.h Fri Jan 29 07:29:33 2010
@@ -42,7 +42,7 @@
Handle<Object> receiver,
int loop_nesting)
: shared_info_(shared_info),
- receiver_(receiver_),
+ receiver_(receiver),
loop_nesting_(loop_nesting) {
}
=======================================
--- /branches/bleeding_edge/src/fast-codegen.cc Fri Jan 29 03:55:40 2010
+++ /branches/bleeding_edge/src/fast-codegen.cc Fri Jan 29 07:29:33 2010
@@ -27,6 +27,7 @@
#include "v8.h"
+#include "data-flow.h"
#include "fast-codegen.h"
#include "scopes.h"
@@ -51,6 +52,8 @@
void FastCodeGenSyntaxChecker::Check(FunctionLiteral* fun,
CompilationInfo* info) {
+ info_ = info;
+
// We do not specialize if we do not have a receiver.
if (!info->has_receiver()) BAILOUT("No receiver");
@@ -321,5 +324,240 @@
#undef BAILOUT
#undef CHECK_BAILOUT
+
+void FastCodeGenerator::MakeCode(FunctionLiteral* fun,
+ Handle<Script> script,
+ bool is_eval,
+ CompilationInfo* info) {
+ AstLabeler labeler;
+ FastCodeGenerator cgen(script, is_eval);
+ labeler.Label(fun);
+ cgen.Generate(fun, info);
+}
+
+
+void FastCodeGenerator::Generate(FunctionLiteral* fun, CompilationInfo*
info) {
+ ASSERT(function_ == NULL);
+ ASSERT(info_ == NULL);
+ function_ = fun;
+ info_ = info;
+ VisitStatements(fun->body());
+ function_ = NULL;
+ info_ = NULL;
+}
+
+
+void FastCodeGenerator::VisitDeclaration(Declaration* decl) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitBlock(Block* stmt) {
+ VisitStatements(stmt->statements());
+}
+
+
+void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement*
stmt) {
+ Visit(stmt->expression());
+}
+
+
+void FastCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
+ // Nothing to do.
+}
+
+
+void FastCodeGenerator::VisitIfStatement(IfStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitWithExitStatement(WithExitStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitForStatement(ForStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement*
stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitFunctionBoilerplateLiteral(
+ FunctionBoilerplateLiteral* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitConditional(Conditional* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitSlot(Slot* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
+ if (FLAG_print_ir) {
+ ASSERT(expr->var()->is_global() && !expr->var()->is_this());
+ SmartPointer<char> name = expr->name()->ToCString();
+ PrintF("%d: t%d = Global(%s)\n", expr->num(), expr->num(), *name);
+ }
+}
+
+
+void FastCodeGenerator::VisitLiteral(Literal* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitCatchExtensionObject(CatchExtensionObject*
expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitAssignment(Assignment* expr) {
+ // Known to be a simple this property assignment.
+ Visit(expr->value());
+
+ if (FLAG_print_ir) {
+ Property* prop = expr->target()->AsProperty();
+ ASSERT_NOT_NULL(prop);
+ ASSERT_NOT_NULL(prop->obj()->AsVariableProxy());
+ ASSERT(prop->obj()->AsVariableProxy()->var()->is_this());
+ ASSERT(prop->key()->IsPropertyName());
+ Handle<String> key =
+ Handle<String>::cast(prop->key()->AsLiteral()->handle());
+ SmartPointer<char> name = key->ToCString();
+ PrintF("%d: t%d = Store(this, \"%s\", t%d)\n",
+ expr->num(), expr->num(), *name, expr->value()->num());
+ }
+}
+
+
+void FastCodeGenerator::VisitThrow(Throw* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitProperty(Property* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitCall(Call* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitCallNew(CallNew* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
+ UNREACHABLE();
+}
+
+
+void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) {
+ UNREACHABLE();
+}
} } // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/fast-codegen.h Fri Jan 29 03:55:40 2010
+++ /branches/bleeding_edge/src/fast-codegen.h Fri Jan 29 07:29:33 2010
@@ -63,6 +63,40 @@
};
+class FastCodeGenerator: public AstVisitor {
+ public:
+ FastCodeGenerator(Handle<Script> script, bool is_eval)
+ : masm_(NULL),
+ script_(script),
+ is_eval_(is_eval),
+ function_(NULL),
+ info_(NULL) {
+ }
+
+ static void MakeCode(FunctionLiteral* fun,
+ Handle<Script> script,
+ bool is_eval,
+ CompilationInfo* info);
+
+ void Generate(FunctionLiteral* fun, CompilationInfo* info);
+
+ private:
+ // AST node visit functions.
+#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
+ AST_NODE_LIST(DECLARE_VISIT)
+#undef DECLARE_VISIT
+
+ MacroAssembler* masm_;
+ Handle<Script> script_;
+ bool is_eval_;
+
+ FunctionLiteral* function_;
+ CompilationInfo* info_;
+
+ DISALLOW_COPY_AND_ASSIGN(FastCodeGenerator);
+};
+
+
} } // namespace v8::internal
#endif // V8_FAST_CODEGEN_H_
=======================================
--- /branches/bleeding_edge/src/flag-definitions.h Wed Jan 27 07:23:48 2010
+++ /branches/bleeding_edge/src/flag-definitions.h Fri Jan 29 07:29:33 2010
@@ -301,6 +301,7 @@
// compiler.cc
DEFINE_bool(print_builtin_scopes, false, "print scopes for builtins")
DEFINE_bool(print_scopes, false, "print scopes")
+DEFINE_bool(print_ir, false, "print the AST as seen by the backend")
// contexts.cc
DEFINE_bool(trace_contexts, false, "trace contexts operations")
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev