diff options
| author | Mark Rowe <mark@vector35.com> | 2026-06-03 21:25:55 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2026-06-04 14:31:09 -0700 |
| commit | d592ed6dafbb134553bf3a0b8ee70ff7f2049aba (patch) | |
| tree | 1bfe7e335e5b4e21371cde4bf8858c6439bc3f18 /lang | |
| parent | 9987102015875991813200116558306851763009 (diff) | |
Add bswap, popcnt, clz, ctz, cls, and rbit instructions
Diffstat (limited to 'lang')
| -rw-r--r-- | lang/c/pseudoc.cpp | 79 | ||||
| -rw-r--r-- | lang/rust/pseudorust.cpp | 27 |
2 files changed, 106 insertions, 0 deletions
diff --git a/lang/c/pseudoc.cpp b/lang/c/pseudoc.cpp index 35966230..dc37100e 100644 --- a/lang/c/pseudoc.cpp +++ b/lang/c/pseudoc.cpp @@ -2411,6 +2411,85 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H }(); break; + case HLIL_BSWAP: + [&]() { + auto src = instr.GetSourceExpr<HLIL_BSWAP>(); + string name; + if (src.size == 2) + name = "__builtin_bswap16"; + else if (src.size == 4) + name = "__builtin_bswap32"; + else if (src.size == 8) + name = "__builtin_bswap64"; + else + name = "__builtin_bswap"; + tokens.Append(OperationToken, name); + tokens.AppendOpenParen(); + GetExprTextInternal(src, tokens, settings); + tokens.AppendCloseParen(); + if (statement) + tokens.AppendSemicolon(); + }(); + break; + + case HLIL_POPCNT: + [&]() { + auto src = instr.GetSourceExpr<HLIL_POPCNT>(); + tokens.Append(OperationToken, src.size > 4 ? "__builtin_popcountll" : "__builtin_popcount"); + tokens.AppendOpenParen(); + GetExprTextInternal(src, tokens, settings); + tokens.AppendCloseParen(); + if (statement) + tokens.AppendSemicolon(); + }(); + break; + + case HLIL_CLZ: + [&]() { + auto src = instr.GetSourceExpr<HLIL_CLZ>(); + tokens.Append(OperationToken, src.size > 4 ? "__builtin_clzll" : "__builtin_clz"); + tokens.AppendOpenParen(); + GetExprTextInternal(src, tokens, settings); + tokens.AppendCloseParen(); + if (statement) + tokens.AppendSemicolon(); + }(); + break; + + case HLIL_CTZ: + [&]() { + auto src = instr.GetSourceExpr<HLIL_CTZ>(); + tokens.Append(OperationToken, src.size > 4 ? "__builtin_ctzll" : "__builtin_ctz"); + tokens.AppendOpenParen(); + GetExprTextInternal(src, tokens, settings); + tokens.AppendCloseParen(); + if (statement) + tokens.AppendSemicolon(); + }(); + break; + + case HLIL_RBIT: + [&]() { + tokens.Append(OperationToken, "__rbit"); + tokens.AppendOpenParen(); + GetExprTextInternal(instr.GetSourceExpr<HLIL_RBIT>(), tokens, settings); + tokens.AppendCloseParen(); + if (statement) + tokens.AppendSemicolon(); + }(); + break; + + case HLIL_CLS: + [&]() { + tokens.Append(OperationToken, "__cls"); + tokens.AppendOpenParen(); + GetExprTextInternal(instr.GetSourceExpr<HLIL_CLS>(), tokens, settings); + tokens.AppendCloseParen(); + if (statement) + tokens.AppendSemicolon(); + }(); + break; + case HLIL_FLOAT_CONV: [&]() { const auto srcExpr = instr.GetSourceExpr<HLIL_FLOAT_CONV>(); diff --git a/lang/rust/pseudorust.cpp b/lang/rust/pseudorust.cpp index 2e233550..de1acae1 100644 --- a/lang/rust/pseudorust.cpp +++ b/lang/rust/pseudorust.cpp @@ -2428,6 +2428,33 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe }(); break; + case HLIL_BSWAP: + case HLIL_POPCNT: + case HLIL_CLZ: + case HLIL_CTZ: + case HLIL_RBIT: + case HLIL_CLS: + [&]() { + const char* method; + switch (instr.operation) + { + case HLIL_BSWAP: method = "swap_bytes"; break; + case HLIL_POPCNT: method = "count_ones"; break; + case HLIL_CLZ: method = "leading_zeros"; break; + case HLIL_CTZ: method = "trailing_zeros"; break; + case HLIL_RBIT: method = "reverse_bits"; break; + default: method = "leading_sign_bits"; break; + } + GetExprText(instr.GetSourceExpr(), tokens, settings, MemberAndFunctionOperatorPrecedence); + tokens.Append(TextToken, "."); + tokens.Append(OperationToken, method); + tokens.AppendOpenParen(); + tokens.AppendCloseParen(); + if (exprType != InnerExpression) + tokens.AppendSemicolon(); + }(); + break; + case HLIL_FLOAT_CONV: [&]() { const auto srcExpr = instr.GetSourceExpr<HLIL_FLOAT_CONV>(); |
