Skip to content

Commit 972ab6c

Browse files
committed
Fix round and COMBINE in Pseudo-C
1 parent 88f9260 commit 972ab6c

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

lang/c/pseudoc.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,8 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
15111511
}
15121512
}
15131513

1514-
GetExprTextInternal(destExpr, tokens, settings, precedence);
1514+
if (!destIsSplit)
1515+
GetExprTextInternal(destExpr, tokens, settings, precedence);
15151516
if (assignUpdateOperator.has_value() && assignUpdateSource.has_value())
15161517
tokens.Append(OperationToken, assignUpdateOperator.value());
15171518
else
@@ -1525,7 +1526,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
15251526
appearsDead = false;
15261527
}
15271528

1528-
if (destIsSplit)
1529+
if (!destIsSplit)
15291530
{
15301531
// const auto high = destExpr.GetHighExpr<HLIL_SPLIT>();
15311532
const auto low = destExpr.GetLowExpr<HLIL_SPLIT>();
@@ -2326,7 +2327,20 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
23262327

23272328
case HLIL_ROUND_TO_INT:
23282329
[&]() {
2329-
AppendTwoOperandFunction("round", instr, tokens, settings, false);
2330+
auto src = instr.GetSourceExpr<HLIL_ROUND_TO_INT>();
2331+
string round;
2332+
if (src.size == 4)
2333+
round = "roundf";
2334+
else if (src.size == 8)
2335+
round = "round";
2336+
else if (src.size == 10)
2337+
round = "roundl";
2338+
else
2339+
round = "round" + std::to_string(src.size) + "f";
2340+
tokens.Append(OperationToken, round);
2341+
tokens.AppendOpenParen();
2342+
GetExprTextInternal(src, tokens, settings);
2343+
tokens.AppendCloseParen();
23302344
if (statement)
23312345
tokens.AppendSemicolon();
23322346
}();
@@ -2616,7 +2630,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
26162630
bool hasOffset = offset != 0;
26172631
bool needsOuterParens = precedence > UnaryOperatorPrecedence;
26182632
bool showTypeCasts = !settings || settings->IsOptionSet(ShowTypeCasts);
2619-
2633+
26202634
if (needsOuterParens)
26212635
tokens.AppendOpenParen();
26222636

@@ -2652,7 +2666,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
26522666
}
26532667
else
26542668
{
2655-
GetExprTextInternal(srcExpr, tokens, settings,
2669+
GetExprTextInternal(srcExpr, tokens, settings,
26562670
hasOffset ? AddOperatorPrecedence : UnaryOperatorPrecedence);
26572671
}
26582672

@@ -2854,7 +2868,21 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
28542868
}();
28552869
break;
28562870

2857-
case HLIL_SPLIT: break;
2871+
case HLIL_SPLIT:
2872+
[&]() {
2873+
const auto low = instr.GetLowExpr();
2874+
const auto high = instr.GetHighExpr();
2875+
2876+
tokens.Append(OperationToken, "COMBINE");
2877+
tokens.AppendOpenParen();
2878+
GetExprTextInternal(high, tokens, settings);
2879+
tokens.Append(TextToken, ", ");
2880+
GetExprTextInternal(low, tokens, settings);
2881+
tokens.AppendCloseParen();
2882+
if (statement)
2883+
tokens.AppendSemicolon();
2884+
}();
2885+
break;
28582886
default:
28592887
[&]() {
28602888
char buf[64]{};

0 commit comments

Comments
 (0)