| Index: src/ia32/safe-codegen-ia32.h
|
| ===================================================================
|
| --- src/ia32/safe-codegen-ia32.h (revision 0)
|
| +++ src/ia32/safe-codegen-ia32.h (revision 0)
|
| @@ -0,0 +1,129 @@
|
| +// Copyright 2010 the V8 project authors. 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_SAFE_CODEGEN_IA32_H_
|
| +#define V8_SAFE_CODEGEN_IA32_H_
|
| +
|
| +#include "v8.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| +class SafeSyntaxChecker: public AstVisitor {
|
| + public:
|
| + SafeSyntaxChecker()
|
| + : has_supported_syntax_(true),
|
| + xmm_stack_height_(0),
|
| + num_operations_(0),
|
| + has_constant_float_(false) {}
|
| + bool Check(Expression* expression) {
|
| + Visit(expression);
|
| + CHECK(!has_supported_syntax() || xmm_stack_height_ == 1);
|
| + return has_supported_syntax() &&
|
| + num_operations_ > 1;
|
| + }
|
| +
|
| + private:
|
| + bool has_supported_syntax() { return has_supported_syntax_; }
|
| + static const int MAX_XMM_STACK_HEIGHT = 8;
|
| + // AST node visit functions.
|
| +#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
|
| + AST_NODE_LIST(DECLARE_VISIT)
|
| +#undef DECLARE_VISIT
|
| +
|
| + bool has_supported_syntax_;
|
| + int xmm_stack_height_;
|
| + int num_operations_;
|
| + bool has_constant_float_;
|
| + DISALLOW_COPY_AND_ASSIGN(SafeSyntaxChecker);
|
| +};
|
| +
|
| +
|
| +class SafeGenerator: public AstVisitor {
|
| + public:
|
| +
|
| + SafeGenerator(MacroAssembler* masm,
|
| + JumpTarget* unsafe_target,
|
| + CodeGenerator* cgen,
|
| + Result* scratch,
|
| + Result* final_result)
|
| + : masm_(masm),
|
| + unsafe_target_(unsafe_target),
|
| + cgen_(cgen),
|
| + scratch_(scratch),
|
| + final_result_(final_result),
|
| + xmm_stack_height_(0) {}
|
| +
|
| +
|
| + Result Generate(Expression* expr);
|
| + private:
|
| + MacroAssembler* masm() { return masm_; }
|
| +
|
| + // AST node visit functions.
|
| +#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
|
| + AST_NODE_LIST(DECLARE_VISIT)
|
| +#undef DECLARE_VISIT
|
| +
|
| + static const int kMinUnspilledXMMRegisters = 4;
|
| + static const int kNumXMMRegisters = 8;
|
| +
|
| + MacroAssembler* masm_;
|
| + JumpTarget* unsafe_target_;
|
| + CodeGenerator* cgen_;
|
| + Result* scratch_;
|
| + Result* final_result_;
|
| +
|
| + // Implement a stack from the XMM registers (keeping the top up-to-8 elements
|
| + // of the stack in registers).
|
| + // Next xmm register to use.
|
| + int xmm_stack_height_;
|
| + // Operations on the XMM "stack".
|
| + void PushXMM(Handle<HeapNumber> value);
|
| + void PushXMM(Handle<Smi> literal);
|
| + void PushXMM(Slot* variable);
|
| +
|
| + void StoreXMM(Register heapNumber);
|
| + // Utility functions.
|
| + void FreeStackTop() {
|
| + ASSERT(xmm_stack_height_ > 0);
|
| + xmm_stack_height_--;
|
| + }
|
| +
|
| + XMMRegister AllocateStackElement() {
|
| + xmm_stack_height_++;
|
| + return XMMStackElement(0);
|
| + }
|
| +
|
| + XMMRegister XMMStackElement(int offset_from_top);
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SafeGenerator);
|
| +};
|
| +
|
| +
|
| +} } // namespace v8::internal
|
| +
|
| +#endif // V8_SAFE_CODEGEN_IA32_H_
|
|
|