Skip to content

Commit c54d583

Browse files
committed
Fix round and single-operand uses of COMBINE in Pseudo-C
1 parent 72020bd commit c54d583

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

lang/c/pseudoc.cpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,6 @@ void PseudoCFunction::AppendTwoOperand(const string& operand, const HighLevelILI
274274
break;
275275
}
276276

277-
if (leftExpr.operation == HLIL_SPLIT)
278-
{
279-
const auto low = leftExpr.GetLowExpr();
280-
const auto high = leftExpr.GetHighExpr();
281-
282-
emitter.Append(OperationToken, "COMBINE");
283-
emitter.AppendOpenParen();
284-
GetExprTextInternal(high, emitter, settings);
285-
emitter.Append(TextToken, ", ");
286-
GetExprTextInternal(low, emitter, settings);
287-
emitter.AppendCloseParen();
288-
}
289-
290-
291277
if (!settings || settings->IsOptionSet(ShowTypeCasts))
292278
{
293279
if (leftExpr.operation == HLIL_VAR && (operand == " + " || operand == " - "))
@@ -1511,7 +1497,8 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
15111497
}
15121498
}
15131499

1514-
GetExprTextInternal(destExpr, tokens, settings, precedence);
1500+
if (!destIsSplit)
1501+
GetExprTextInternal(destExpr, tokens, settings, precedence);
15151502
if (assignUpdateOperator.has_value() && assignUpdateSource.has_value())
15161503
tokens.Append(OperationToken, assignUpdateOperator.value());
15171504
else
@@ -2326,7 +2313,20 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
23262313

23272314
case HLIL_ROUND_TO_INT:
23282315
[&]() {
2329-
AppendTwoOperandFunction("round", instr, tokens, settings, false);
2316+
auto src = instr.GetSourceExpr<HLIL_ROUND_TO_INT>();
2317+
string round;
2318+
if (src.size == 4)
2319+
round = "roundf";
2320+
else if (src.size == 8)
2321+
round = "round";
2322+
else if (src.size == 10)
2323+
round = "roundl";
2324+
else
2325+
round = "round" + std::to_string(src.size) + "f";
2326+
tokens.Append(OperationToken, round);
2327+
tokens.AppendOpenParen();
2328+
GetExprTextInternal(src, tokens, settings);
2329+
tokens.AppendCloseParen();
23302330
if (statement)
23312331
tokens.AppendSemicolon();
23322332
}();
@@ -2616,7 +2616,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
26162616
bool hasOffset = offset != 0;
26172617
bool needsOuterParens = precedence > UnaryOperatorPrecedence;
26182618
bool showTypeCasts = !settings || settings->IsOptionSet(ShowTypeCasts);
2619-
2619+
26202620
if (needsOuterParens)
26212621
tokens.AppendOpenParen();
26222622

@@ -2652,7 +2652,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
26522652
}
26532653
else
26542654
{
2655-
GetExprTextInternal(srcExpr, tokens, settings,
2655+
GetExprTextInternal(srcExpr, tokens, settings,
26562656
hasOffset ? AddOperatorPrecedence : UnaryOperatorPrecedence);
26572657
}
26582658

@@ -2854,7 +2854,21 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
28542854
}();
28552855
break;
28562856

2857-
case HLIL_SPLIT: break;
2857+
case HLIL_SPLIT:
2858+
[&]() {
2859+
const auto low = instr.GetLowExpr();
2860+
const auto high = instr.GetHighExpr();
2861+
2862+
tokens.Append(OperationToken, "COMBINE");
2863+
tokens.AppendOpenParen();
2864+
GetExprTextInternal(high, tokens, settings);
2865+
tokens.Append(TextToken, ", ");
2866+
GetExprTextInternal(low, tokens, settings);
2867+
tokens.AppendCloseParen();
2868+
if (statement)
2869+
tokens.AppendSemicolon();
2870+
}();
2871+
break;
28582872
default:
28592873
[&]() {
28602874
char buf[64]{};

0 commit comments

Comments
 (0)