From 13445bad31b60db063d454fefa6d6697889f428d Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Mon, 14 Apr 2025 10:10:42 -0400 Subject: Handle var assign with split src in pseudo C/Rust Fixes issue with absent rhs when the instruction is HLIL_ASSIGN with a source expression of HLIL_SPLIT (var_60.q = r1:r0) --- lang/rust/pseudorust.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'lang/rust/pseudorust.cpp') diff --git a/lang/rust/pseudorust.cpp b/lang/rust/pseudorust.cpp index 300297dc..e3f661fa 100644 --- a/lang/rust/pseudorust.cpp +++ b/lang/rust/pseudorust.cpp @@ -1371,9 +1371,9 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe std::optional assignUpdateOperator; std::optional assignUpdateSource; bool assignUpdateNegate = false; - const auto isSplit = destExpr.operation == HLIL_SPLIT; + const auto destIsSplit = destExpr.operation == HLIL_SPLIT; std::optional assignSignHint; - if (isSplit) + if (destIsSplit) { const auto high = destExpr.GetHighExpr(); const auto low = destExpr.GetLowExpr(); @@ -1389,6 +1389,23 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe tokens.NewLine(); GetExprText(low, tokens, settings, precedence); } + else if (srcExpr.operation == HLIL_SPLIT) + { + const auto high = srcExpr.GetHighExpr(); + const auto low = srcExpr.GetLowExpr(); + GetExprText(destExpr, tokens, settings, precedence); + tokens.Append(OperationToken, " = "); + tokens.AppendOpenParen(); + GetExprText(high, tokens, settings, precedence); + tokens.Append(OperationToken, " << "); + tokens.Append(IntegerToken, std::to_string(low.size * 8)); + tokens.AppendCloseParen(); + tokens.Append(OperationToken, " | "); + GetExprText(low, tokens, settings, precedence); + tokens.AppendSemicolon(); + tokens.NewLine(); + return; + } else { // Check for assignment with an operator on the same variable as the destination @@ -1515,7 +1532,7 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe appearsDead = false; } - if (isSplit) + if (destIsSplit) { // const auto high = destExpr.GetHighExpr(); const auto low = destExpr.GetLowExpr(); @@ -1545,7 +1562,7 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe GetExprText(srcExpr, tokens, settings, AssignmentOperatorPrecedence, InnerExpression, assignSignHint); } - if (isSplit) + if (destIsSplit) tokens.AppendCloseParen(); if (appearsDead) -- cgit v1.3.1