From 89c762edf4417a413b553cb42d1512015c41378c Mon Sep 17 00:00:00 2001 From: "iposva@chromium.org" Date: Fri, 10 Oct 2008 00:00:52 +0000 Subject: [PATCH] Simplify CodeGenerator hierarchy by not using a base class. There is nothing virtual about a CodeGenerator since we either generate code for one platform or for the other. Review URL: http://codereview.chromium.org/6334 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@480 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/codegen-arm.cc | 522 ++++++----------------------------- src/codegen-arm.h | 371 +++++++++++++++++++++++++ src/codegen-ia32.cc | 551 ++++++------------------------------- src/codegen-ia32.h | 385 ++++++++++++++++++++++++++ src/codegen.cc | 94 +++++++ src/codegen.h | 155 +++-------- tools/v8.xcodeproj/project.pbxproj | 6 +- 7 files changed, 1059 insertions(+), 1025 deletions(-) create mode 100644 src/codegen-arm.h create mode 100644 src/codegen-ia32.h diff --git a/src/codegen-arm.cc b/src/codegen-arm.cc index 40173cd..92206dd 100644 --- a/src/codegen-arm.cc +++ b/src/codegen-arm.cc @@ -30,269 +30,15 @@ #include "bootstrapper.h" #include "codegen-inl.h" #include "debug.h" -#include "prettyprinter.h" -#include "scopeinfo.h" #include "scopes.h" #include "runtime.h" namespace v8 { namespace internal { -class ArmCodeGenerator; - - -// ----------------------------------------------------------------------------- -// Reference support - -// A reference is a C++ stack-allocated object that keeps an ECMA -// reference on the execution stack while in scope. For variables -// the reference is empty, indicating that it isn't necessary to -// store state on the stack for keeping track of references to those. -// For properties, we keep either one (named) or two (indexed) values -// on the execution stack to represent the reference. - -enum InitState { CONST_INIT, NOT_CONST_INIT }; -enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; - -class Reference BASE_EMBEDDED { - public: - // The values of the types is important, see size(). - enum Type { ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 }; - Reference(ArmCodeGenerator* cgen, Expression* expression); - ~Reference(); - - Expression* expression() const { return expression_; } - Type type() const { return type_; } - void set_type(Type value) { - ASSERT(type_ == ILLEGAL); - type_ = value; - } - // The size of the reference or -1 if the reference is illegal. - int size() const { return type_; } - - bool is_illegal() const { return type_ == ILLEGAL; } - bool is_slot() const { return type_ == SLOT; } - bool is_property() const { return type_ == NAMED || type_ == KEYED; } - - // Return the name. Only valid for named property references. - Handle GetName(); - - // Generate code to push the value of the reference on top of the - // expression stack. The reference is expected to be already on top of - // the expression stack, and it is left in place with its value above it. - void GetValue(TypeofState typeof_state); - - // Generate code to store the value on top of the expression stack in the - // reference. The reference is expected to be immediately below the value - // on the expression stack. The stored value is left in place (with the - // reference intact below it) to support chained assignments. - void SetValue(InitState init_state); - - private: - ArmCodeGenerator* cgen_; - Expression* expression_; - Type type_; -}; - - -// ------------------------------------------------------------------------- -// Code generation state - -// The state is passed down the AST by the code generator (and back up, in -// the form of the state of the label pair). It is threaded through the -// call stack. Constructing a state implicitly pushes it on the owning code -// generator's stack of states, and destroying one implicitly pops it. - -class CodeGenState BASE_EMBEDDED { - public: - // Create an initial code generator state. Destroying the initial state - // leaves the code generator with a NULL state. - explicit CodeGenState(ArmCodeGenerator* owner); - - // Create a code generator state based on a code generator's current - // state. The new state has its own typeof state and pair of branch - // labels. - CodeGenState(ArmCodeGenerator* owner, - TypeofState typeof_state, - Label* true_target, - Label* false_target); - - // Destroy a code generator state and restore the owning code generator's - // previous state. - ~CodeGenState(); - - TypeofState typeof_state() const { return typeof_state_; } - Label* true_target() const { return true_target_; } - Label* false_target() const { return false_target_; } - - private: - ArmCodeGenerator* owner_; - TypeofState typeof_state_; - Label* true_target_; - Label* false_target_; - CodeGenState* previous_; -}; - - -// ----------------------------------------------------------------------------- -// ArmCodeGenerator - -class ArmCodeGenerator: public CodeGenerator { - public: - static Handle MakeCode(FunctionLiteral* fun, - Handle