diff options
| author | Glenn Smith <glenn@vector35.com> | 2024-06-10 19:00:58 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2024-06-10 19:00:58 -0400 |
| commit | 7064468986827633023933435608630110377820 (patch) | |
| tree | 0043113cf273007ba8883807d71d248d7d90b9c1 /highlevelilinstruction.cpp | |
| parent | 9879389091766176705999562870003860338879 (diff) | |
Add fmt formatters for IL instructions
Diffstat (limited to 'highlevelilinstruction.cpp')
| -rw-r--r-- | highlevelilinstruction.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index 3c838c1a..3626dd54 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -3262,3 +3262,55 @@ ExprId HighLevelILFunction::FloatCompareUnordered(size_t size, ExprId a, ExprId { return AddExprWithLocation(HLIL_FCMP_UO, loc, size, a, b); } + + +fmt::format_context::iterator fmt::formatter<HighLevelILInstruction>::format(const HighLevelILInstruction& obj, format_context& ctx) const +{ + if (!obj.function) + return fmt::format_to(ctx.out(), "<uninit>"); + + vector<InstructionTextToken> tokens; + Ref<DisassemblySettings> settings = new DisassemblySettings(); + vector<DisassemblyTextLine> lines = obj.function->GetExprText(obj, settings); + if (!lines.empty()) + { + if (presentation == '?') + { + fmt::format_to(ctx.out(), "{} ", obj.operation); + fmt::format_to(ctx.out(), "@ {:#x} ", obj.address); + if (obj.exprIndex != BN_INVALID_EXPR && (obj.exprIndex & 0xffff000000000000) == 0) + { + fmt::format_to(ctx.out(), "[expr {}] ", obj.exprIndex); + } + if (obj.instructionIndex != BN_INVALID_EXPR && (obj.instructionIndex & 0xffff000000000000) == 0) + { + fmt::format_to(ctx.out(), "[instr {}] ", obj.instructionIndex); + } + Ref<Type> type = obj.GetType(); + if (type) + { + fmt::format_to(ctx.out(), "[type: {}] ", type->GetString()); + } + } + + bool first = true; + for (auto& line: lines) + { + if (!first) + { + fmt::format_to(ctx.out(), " ; "); + } + first = false; + + for (auto& token: line.tokens) + { + fmt::format_to(ctx.out(), "{}", token.text); + } + } + } + else + { + fmt::format_to(ctx.out(), "???"); + } + return ctx.out(); +} |
