// Copyright 2006-2008 Google Inc. All Rights Reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef V8_CODEGEN_H_ #include "ast.h" #include "code-stubs.h" #include "runtime.h" #define V8_CODEGEN_H_ namespace v8 { namespace internal { // Use lazy compilation; defaults to true. // NOTE: Do not remove non-lazy compilation until we can properly // install extensions with lazy compilation enabled. At the // moment, this doesn't work for the extensions in Google3, // and we can only run the tests with --nolazy. DECLARE_bool(lazy); // Forward declaration. class CodeGenerator; // Deferred code objects are small pieces of code that are compiled // out of line. They are used to defer the compilation of uncommon // paths thereby avoiding expensive jumps around uncommon code parts. class DeferredCode: public ZoneObject { public: explicit DeferredCode(CodeGenerator* generator); virtual ~DeferredCode() { } virtual void Generate() = 0; MacroAssembler* masm() const { return masm_; } CodeGenerator* generator() const { return generator_; } Label* enter() { return &enter_; } Label* exit() { return &exit_; } int position() const { return position_; } bool position_is_statement() const { return position_is_statement_; } #ifdef DEBUG void set_comment(const char* comment) { comment_ = comment; } const char* comment() const { return comment_; } #else inline void set_comment(const char* comment) { } const char* comment() const { return ""; } #endif protected: // The masm_ field is manipulated when compiling stubs with the // BEGIN_STUB and END_STUB macros. For that reason, it cannot be // constant. MacroAssembler* masm_; private: CodeGenerator* const generator_; Label enter_; Label exit_; int position_; bool position_is_statement_; #ifdef DEBUG const char* comment_; #endif DISALLOW_COPY_AND_ASSIGN(DeferredCode); }; // A superclass for gode generators. The implementations of methods // declared in this class are partially in codegen.c and partially in // codegen_.c. class CodeGenerator: public Visitor { public: CodeGenerator(bool is_eval, Handle