X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..93a3786624b2768d89bfa27e46598dc64e2fb70a:/bytecode/Operands.h diff --git a/bytecode/Operands.h b/bytecode/Operands.h index a05159f..e7b3e24 100644 --- a/bytecode/Operands.h +++ b/bytecode/Operands.h @@ -28,7 +28,7 @@ #include "CallFrame.h" #include "JSObject.h" -#include "ScopeChain.h" +#include #include namespace JSC { @@ -43,9 +43,11 @@ template struct OperandValueTraits; template struct OperandValueTraits { static T defaultValue() { return T(); } - static void dump(const T& value, FILE* out) { value.dump(out); } + static void dump(const T& value, PrintStream& out) { value.dump(out); } }; +enum OperandKind { ArgumentOperand, LocalOperand }; + template > class Operands { public: @@ -66,6 +68,28 @@ public: T& local(size_t idx) { return m_locals[idx]; } const T& local(size_t idx) const { return m_locals[idx]; } + template + size_t sizeFor() const + { + if (operandKind == ArgumentOperand) + return numberOfArguments(); + return numberOfLocals(); + } + template + T& atFor(size_t idx) + { + if (operandKind == ArgumentOperand) + return argument(idx); + return local(idx); + } + template + const T& atFor(size_t idx) const + { + if (operandKind == ArgumentOperand) + return argument(idx); + return local(idx); + } + void ensureLocals(size_t size) { if (size <= m_locals.size()) @@ -115,6 +139,13 @@ public: 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(); + } + void setOperand(int operand, const T& value) { if (operandIsArgument(operand)) { @@ -126,6 +157,49 @@ public: setLocal(operand, value); } + size_t size() const { return numberOfArguments() + numberOfLocals(); } + const T& at(size_t index) const + { + if (index < numberOfArguments()) + return m_arguments[index]; + return m_locals[index - numberOfArguments()]; + } + T& at(size_t index) + { + if (index < numberOfArguments()) + return m_arguments[index]; + return m_locals[index - numberOfArguments()]; + } + const T& operator[](size_t index) const { return at(index); } + T& operator[](size_t index) { return at(index); } + + bool isArgument(size_t index) const { return index < numberOfArguments(); } + bool isVariable(size_t index) const { return !isArgument(index); } + int argumentForIndex(size_t index) const + { + return index; + } + int variableForIndex(size_t index) const + { + return index - m_arguments.size(); + } + int operandForIndex(size_t index) const + { + if (index < numberOfArguments()) + return argumentToOperand(index); + return index - numberOfArguments(); + } + + void setOperandFirstTime(int operand, const T& value) + { + if (operandIsArgument(operand)) { + setArgumentFirstTime(operandToArgument(operand), value); + return; + } + + setLocalFirstTime(operand, value); + } + void clear() { for (size_t i = 0; i < m_arguments.size(); ++i) @@ -140,17 +214,19 @@ private: }; template -void dumpOperands(Operands& operands, FILE* out) +void dumpOperands(const Operands& operands, PrintStream& out) { - for (size_t argument = 0; argument < operands.numberOfArguments(); ++argument) { - if (argument) - fprintf(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); } - fprintf(out, " : "); + out.printf(" : "); for (size_t local = 0; local < operands.numberOfLocals(); ++local) { if (local) - fprintf(out, " "); + out.printf(" "); + out.print("r", local, ":"); Traits::dump(operands.local(local), out); } }