diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/bytecode/Operands.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/bytecode/Operands.h')
-rw-r--r-- | Source/JavaScriptCore/bytecode/Operands.h | 73 |
1 files changed, 44 insertions, 29 deletions
diff --git a/Source/JavaScriptCore/bytecode/Operands.h b/Source/JavaScriptCore/bytecode/Operands.h index f21e05f5f..102879814 100644 --- a/Source/JavaScriptCore/bytecode/Operands.h +++ b/Source/JavaScriptCore/bytecode/Operands.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. + * Copyright (C) 2011, 2012, 2013, 2015, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,8 +23,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef Operands_h -#define Operands_h +#pragma once #include "CallFrame.h" #include "JSObject.h" @@ -37,32 +36,37 @@ namespace JSC { template<typename T> struct OperandValueTraits; -template<typename T> -struct OperandValueTraits { - static T defaultValue() { return T(); } - static bool isEmptyForDump(const T& value) { return !value; } -}; - enum OperandKind { ArgumentOperand, LocalOperand }; enum OperandsLikeTag { OperandsLike }; -template<typename T, typename Traits = OperandValueTraits<T>> +template<typename T> class Operands { public: Operands() { } explicit Operands(size_t numArguments, size_t numLocals) { - m_arguments.fill(Traits::defaultValue(), numArguments); - m_locals.fill(Traits::defaultValue(), numLocals); + if (WTF::VectorTraits<T>::needsInitialization) { + m_arguments.resize(numArguments); + m_locals.resize(numLocals); + } else { + m_arguments.fill(T(), numArguments); + m_locals.fill(T(), numLocals); + } + } + + explicit Operands(size_t numArguments, size_t numLocals, const T& initialValue) + { + m_arguments.fill(initialValue, numArguments); + m_locals.fill(initialValue, numLocals); } - template<typename U, typename OtherTraits> - explicit Operands(OperandsLikeTag, const Operands<U, OtherTraits>& other) + template<typename U> + explicit Operands(OperandsLikeTag, const Operands<U>& other) { - m_arguments.fill(Traits::defaultValue(), other.numberOfArguments()); - m_locals.fill(Traits::defaultValue(), other.numberOfLocals()); + m_arguments.fill(T(), other.numberOfArguments()); + m_locals.fill(T(), other.numberOfLocals()); } size_t numberOfArguments() const { return m_arguments.size(); } @@ -103,8 +107,21 @@ public: size_t oldSize = m_locals.size(); m_locals.resize(size); + if (!WTF::VectorTraits<T>::needsInitialization) { + for (size_t i = oldSize; i < m_locals.size(); ++i) + m_locals[i] = T(); + } + } + + void ensureLocals(size_t size, const T& ensuredValue) + { + if (size <= m_locals.size()) + return; + + size_t oldSize = m_locals.size(); + m_locals.resize(size); for (size_t i = oldSize; i < m_locals.size(); ++i) - m_locals[i] = Traits::defaultValue(); + m_locals[i] = ensuredValue; } void setLocal(size_t idx, const T& value) @@ -117,19 +134,19 @@ public: T getLocal(size_t idx) { if (idx >= m_locals.size()) - return Traits::defaultValue(); + return T(); return m_locals[idx]; } void setArgumentFirstTime(size_t idx, const T& value) { - ASSERT(m_arguments[idx] == Traits::defaultValue()); + ASSERT(m_arguments[idx] == T()); argument(idx) = value; } void setLocalFirstTime(size_t idx, const T& value) { - ASSERT(idx >= m_locals.size() || m_locals[idx] == Traits::defaultValue()); + ASSERT(idx >= m_locals.size() || m_locals[idx] == T()); setLocal(idx, value); } @@ -149,6 +166,7 @@ public: } const T& operand(int operand) const { return const_cast<const T&>(const_cast<Operands*>(this)->operand(operand)); } + const T& operand(VirtualRegister operand) const { return const_cast<const T&>(const_cast<Operands*>(this)->operand(operand)); } bool hasOperand(int operand) const { @@ -209,6 +227,10 @@ public: return virtualRegisterForArgument(index).offset(); return virtualRegisterForLocal(index - numberOfArguments()).offset(); } + VirtualRegister virtualRegisterForIndex(size_t index) const + { + return VirtualRegister(operandForIndex(index)); + } size_t indexForOperand(int operand) const { if (operandIsArgument(operand)) @@ -240,7 +262,7 @@ public: void clear() { - fill(Traits::defaultValue()); + fill(T()); } bool operator==(const Operands& other) const @@ -252,11 +274,7 @@ public: } void dumpInContext(PrintStream& out, DumpContext* context) const; - - void dump(PrintStream& out) const - { - dumpInContext(out, 0); - } + void dump(PrintStream& out) const; private: Vector<T, 8> m_arguments; @@ -264,6 +282,3 @@ private: }; } // namespace JSC - -#endif // Operands_h - |