X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..2d39b0e377c0896910ee49ae70082ba665faf986:/bytecode/Operands.h diff --git a/bytecode/Operands.h b/bytecode/Operands.h index e7b3e24..f21e05f 100644 --- a/bytecode/Operands.h +++ b/bytecode/Operands.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. + * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,27 +28,26 @@ #include "CallFrame.h" #include "JSObject.h" +#include "VirtualRegister.h" + #include #include namespace JSC { -// argument 0 is 'this'. -inline bool operandIsArgument(int operand) { return operand < 0; } -inline int operandToArgument(int operand) { return -operand + CallFrame::thisArgumentOffset(); } -inline int argumentToOperand(int argument) { return -argument + CallFrame::thisArgumentOffset(); } - template struct OperandValueTraits; template struct OperandValueTraits { static T defaultValue() { return T(); } - static void dump(const T& value, PrintStream& out) { value.dump(out); } + static bool isEmptyForDump(const T& value) { return !value; } }; enum OperandKind { ArgumentOperand, LocalOperand }; -template > +enum OperandsLikeTag { OperandsLike }; + +template> class Operands { public: Operands() { } @@ -59,6 +58,13 @@ public: m_locals.fill(Traits::defaultValue(), numLocals); } + template + explicit Operands(OperandsLikeTag, const Operands& other) + { + m_arguments.fill(Traits::defaultValue(), other.numberOfArguments()); + m_locals.fill(Traits::defaultValue(), other.numberOfLocals()); + } + size_t numberOfArguments() const { return m_arguments.size(); } size_t numberOfLocals() const { return m_locals.size(); } @@ -130,33 +136,47 @@ public: T& operand(int operand) { if (operandIsArgument(operand)) { - int argument = operandToArgument(operand); + int argument = VirtualRegister(operand).toArgument(); return m_arguments[argument]; } - - return m_locals[operand]; + + return m_locals[VirtualRegister(operand).toLocal()]; } - + + T& operand(VirtualRegister virtualRegister) + { + return operand(virtualRegister.offset()); + } + const T& operand(int operand) const { return const_cast(const_cast(this)->operand(operand)); } bool hasOperand(int operand) const { if (operandIsArgument(operand)) return true; - return static_cast(operand) < numberOfLocals(); + return static_cast(VirtualRegister(operand).toLocal()) < numberOfLocals(); + } + bool hasOperand(VirtualRegister reg) const + { + return hasOperand(reg.offset()); } void setOperand(int operand, const T& value) { if (operandIsArgument(operand)) { - int argument = operandToArgument(operand); + int argument = VirtualRegister(operand).toArgument(); m_arguments[argument] = value; return; } - setLocal(operand, value); + setLocal(VirtualRegister(operand).toLocal(), value); } + void setOperand(VirtualRegister virtualRegister, const T& value) + { + setOperand(virtualRegister.offset(), value); + } + size_t size() const { return numberOfArguments() + numberOfLocals(); } const T& at(size_t index) const { @@ -186,26 +206,56 @@ public: int operandForIndex(size_t index) const { if (index < numberOfArguments()) - return argumentToOperand(index); - return index - numberOfArguments(); + return virtualRegisterForArgument(index).offset(); + return virtualRegisterForLocal(index - numberOfArguments()).offset(); + } + size_t indexForOperand(int operand) const + { + if (operandIsArgument(operand)) + return static_cast(VirtualRegister(operand).toArgument()); + return static_cast(VirtualRegister(operand).toLocal()) + numberOfArguments(); + } + size_t indexForOperand(VirtualRegister reg) const + { + return indexForOperand(reg.offset()); } void setOperandFirstTime(int operand, const T& value) { if (operandIsArgument(operand)) { - setArgumentFirstTime(operandToArgument(operand), value); + setArgumentFirstTime(VirtualRegister(operand).toArgument(), value); return; } - setLocalFirstTime(operand, value); + setLocalFirstTime(VirtualRegister(operand).toLocal(), value); } - void clear() + void fill(T value) { for (size_t i = 0; i < m_arguments.size(); ++i) - m_arguments[i] = Traits::defaultValue(); + m_arguments[i] = value; for (size_t i = 0; i < m_locals.size(); ++i) - m_locals[i] = Traits::defaultValue(); + m_locals[i] = value; + } + + void clear() + { + fill(Traits::defaultValue()); + } + + bool operator==(const Operands& other) const + { + ASSERT(numberOfArguments() == other.numberOfArguments()); + ASSERT(numberOfLocals() == other.numberOfLocals()); + + return m_arguments == other.m_arguments && m_locals == other.m_locals; + } + + void dumpInContext(PrintStream& out, DumpContext* context) const; + + void dump(PrintStream& out) const + { + dumpInContext(out, 0); } private: @@ -213,24 +263,6 @@ private: Vector m_locals; }; -template -void dumpOperands(const Operands& operands, PrintStream& out) -{ - for (size_t argument = operands.numberOfArguments(); argument--;) { - if (argument != operands.numberOfArguments() - 1) - out.printf(" "); - out.print("arg", argument, ":"); - Traits::dump(operands.argument(argument), out); - } - out.printf(" : "); - for (size_t local = 0; local < operands.numberOfLocals(); ++local) { - if (local) - out.printf(" "); - out.print("r", local, ":"); - Traits::dump(operands.local(local), out); - } -} - } // namespace JSC #endif // Operands_h