diff options
| author | Mark Rowe <mark@vector35.com> | 2025-07-16 18:42:37 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2025-12-11 21:09:38 -0800 |
| commit | 62ded0de7b820f6e25be31254158401ce31a1c87 (patch) | |
| tree | 83ff5d27bc01af2cec331eaf148de80914357420 /mediumlevelilinstruction.h | |
| parent | 290bbcf333679ffa057d57d1b540608e3bec8ada (diff) | |
Use constexpr arrays for metadata about IL instruction operands
This avoids constructing two unordered maps and numerous vectors for
each IL level at library load time for each plug-in that uses the C++
API. Additionally, the arrays allow for more efficient look-ups.
Diffstat (limited to 'mediumlevelilinstruction.h')
| -rw-r--r-- | mediumlevelilinstruction.h | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h index ef1f9017..b3965a63 100644 --- a/mediumlevelilinstruction.h +++ b/mediumlevelilinstruction.h @@ -37,6 +37,10 @@ namespace BinaryNinjaCore namespace BinaryNinja #endif { +#ifdef BINARYNINJACORE_LIBRARY + typedef size_t ExprId; +#endif + class MediumLevelILFunction; template <BNMediumLevelILOperation N> @@ -85,7 +89,7 @@ namespace BinaryNinja /*! \ingroup mediumlevelil */ - enum MediumLevelILOperandType + enum MediumLevelILOperandType : uint8_t { IntegerMediumLevelOperand, ConstantDataMediumLevelOperand, @@ -105,7 +109,7 @@ namespace BinaryNinja /*! \ingroup mediumlevelil */ - enum MediumLevelILOperandUsage + enum MediumLevelILOperandUsage : uint8_t { SourceExprMediumLevelOperandUsage, SourceVariableMediumLevelOperandUsage, @@ -485,12 +489,6 @@ namespace BinaryNinja #endif size_t exprIndex, instructionIndex; - static _STD_UNORDERED_MAP<MediumLevelILOperandUsage, MediumLevelILOperandType> operandTypeForUsage; - static _STD_UNORDERED_MAP<BNMediumLevelILOperation, _STD_VECTOR<MediumLevelILOperandUsage>> - operationOperandUsage; - static _STD_UNORDERED_MAP<BNMediumLevelILOperation, _STD_UNORDERED_MAP<MediumLevelILOperandUsage, size_t>> - operationOperandIndex; - MediumLevelILOperandList GetOperands() const; uint64_t GetRawOperandAsInteger(size_t operand) const; @@ -932,28 +930,28 @@ namespace BinaryNinja typedef value_type reference; const MediumLevelILOperandList* owner; - _STD_VECTOR<MediumLevelILOperandUsage>::const_iterator pos; - bool operator==(const ListIterator& a) const { return pos == a.pos; } - bool operator!=(const ListIterator& a) const { return pos != a.pos; } - bool operator<(const ListIterator& a) const { return pos < a.pos; } + size_t index; + constexpr bool operator==(const ListIterator& a) const { return index == a.index; } + constexpr auto operator<=>(const ListIterator& a) const { return index <=> a.index; } ListIterator& operator++() { - ++pos; + ++index; return *this; } const MediumLevelILOperand operator*(); }; MediumLevelILInstruction m_instr; - const _STD_VECTOR<MediumLevelILOperandUsage>& m_usageList; - const _STD_UNORDERED_MAP<MediumLevelILOperandUsage, size_t>& m_operandIndexMap; + const MediumLevelILOperandUsage* m_usages; + const uint8_t* m_indices; + uint8_t m_count; public: typedef ListIterator const_iterator; MediumLevelILOperandList(const MediumLevelILInstruction& instr, - const _STD_VECTOR<MediumLevelILOperandUsage>& usageList, - const _STD_UNORDERED_MAP<MediumLevelILOperandUsage, size_t>& operandIndexMap); + const MediumLevelILOperandUsage* usages, + const uint8_t* indices, uint8_t count); const_iterator begin() const; const_iterator end() const; |
