Minor fixes to JMP statements

This commit is contained in:
Yoshi Askharoun
2025-09-21 21:25:27 -05:00
parent d72d868bec
commit d29a7ab839
3 changed files with 13 additions and 7 deletions
+2 -2
View File
@@ -130,10 +130,10 @@ public static class ControlFlowAnalyzer
sb.AppendLine($" >];");
if (block.NextOffset is not uint.MaxValue)
sb.AppendLine($" {nodeId} -> {block.NextOffset};");
sb.AppendLine($" {nodeId}:s -> {block.NextOffset}:n;");
if (block.BranchTargetOffset is not uint.MaxValue)
sb.AppendLine($" {nodeId} -> {block.BranchTargetOffset} [color=red];");
sb.AppendLine($" {nodeId}:s -> {block.BranchTargetOffset}:n [color=red];");
}
sb.AppendLine("}");
+6 -5
View File
@@ -32,7 +32,7 @@ partial class Decompiler
var controlBlocks = ControlFlowAnalyzer.CreateGraph(methodBody);
var dotGraph = ControlFlowAnalyzer.SerializeToGraphviz(controlBlocks);
//Console.WriteLine(dotGraph);
Console.WriteLine(dotGraph);
Stack<CodeBlockInfo> blockStack = [];
blockStack.Push(new(0, methodBody[^1].Offset, SyntaxKind.Block, null));
@@ -101,7 +101,7 @@ partial class Decompiler
var symbolRef = export.SymbolReferenceTable[writeSymbolIndex];
var symbolIdentifierExpr = IrisExpression.ToSyntax(symbolRef);
var newSymbolValueExpr = IrisExpression.ToSyntax(newSymbolValue, _context);
var newSymbolValueExpr = SimplifyExpression(IrisExpression.ToSyntax(newSymbolValue, _context), true);
StatementSyntax symbolWriteExpr;
@@ -175,14 +175,15 @@ partial class Decompiler
var isPeek = opCode is OpCode.JumpIfFalsePeek or OpCode.JumpIfTruePeek or OpCode.JumpIfNullPeek;
var rawJumpCondition = IrisExpression.ToSyntax(isPeek ? stack.Peek() : stack.Pop(), _context);
// TODO: Invert jump condition when decompiling to blocks instead of gotos
var jumpCondition = opCode switch
{
OpCode.JumpIfFalse or
OpCode.JumpIfFalsePeek => rawJumpCondition,
OpCode.JumpIfFalsePeek => LogicalNotOf(rawJumpCondition),
OpCode.JumpIfTruePeek => LogicalNotOf(rawJumpCondition),
OpCode.JumpIfTruePeek => rawJumpCondition,
OpCode.JumpIfNullPeek => BinaryExpression(SyntaxKind.ExclamationEqualsToken,
OpCode.JumpIfNullPeek => BinaryExpression(SyntaxKind.EqualsEqualsToken,
rawJumpCondition,
LiteralExpression(SyntaxKind.NullLiteralExpression)),
+5
View File
@@ -57,6 +57,11 @@ internal record IrisObject(object Object, TypeSchema Type)
if (property is not null)
return property.PropertyType;
}
else if (expr is CastExpressionSyntax castExpr)
{
var castTargetName = QualifiedTypeName.Parse(castExpr.Type.ToString());
return ctx.GetImportedType(castTargetName);
}
return null;
}