mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Slight cleanup to conditional decompilation
This commit is contained in:
@@ -34,11 +34,6 @@ partial class Decompiler
|
|||||||
var dotGraph = ControlFlowAnalyzer.SerializeToGraphviz(controlBlocks);
|
var dotGraph = ControlFlowAnalyzer.SerializeToGraphviz(controlBlocks);
|
||||||
Console.WriteLine(dotGraph);
|
Console.WriteLine(dotGraph);
|
||||||
|
|
||||||
// TODO: Search for loops
|
|
||||||
|
|
||||||
// TODO: Search for branch conditions
|
|
||||||
var collapsedBlocks = controlBlocks.CollapseBlocks();
|
|
||||||
|
|
||||||
Stack<CodeBlockInfo> blockStack = [];
|
Stack<CodeBlockInfo> blockStack = [];
|
||||||
blockStack.Push(new(0, methodBody[^1].Offset, SyntaxKind.Block, null));
|
blockStack.Push(new(0, methodBody[^1].Offset, SyntaxKind.Block, null));
|
||||||
|
|
||||||
@@ -75,8 +70,8 @@ partial class Decompiler
|
|||||||
|
|
||||||
if (jumpToOffsets.Contains(instruction.Offset))
|
if (jumpToOffsets.Contains(instruction.Offset))
|
||||||
{
|
{
|
||||||
// This address is code that will be unconditionally executed. For now,
|
// This address is code that will be unconditionally executed.
|
||||||
// we'll assume that this is the end of IF/ELSE clauses.
|
// For now, we'll assume that this is the end of IF/ELSE clauses.
|
||||||
while (blockStack.Count > 1)
|
while (blockStack.Count > 1)
|
||||||
{
|
{
|
||||||
if (blockStack.Peek().Kind is SyntaxKind.ElseClause)
|
if (blockStack.Peek().Kind is SyntaxKind.ElseClause)
|
||||||
@@ -203,21 +198,16 @@ partial class Decompiler
|
|||||||
case OpCode.JumpIfTruePeek:
|
case OpCode.JumpIfTruePeek:
|
||||||
var jumpToOffset = (uint)instruction.Operands.First().Value;
|
var jumpToOffset = (uint)instruction.Operands.First().Value;
|
||||||
|
|
||||||
// TODO: What about for loops?
|
var isPeek = opCode is OpCode.JumpIfFalsePeek or OpCode.JumpIfTruePeek;
|
||||||
if (instruction.Offset > jumpToOffset)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
var isPeek = opCode is OpCode.JumpIfFalsePeek or OpCode.JumpIfTruePeek or OpCode.JumpIfNullPeek;
|
|
||||||
var jumpCondition = IrisExpression.ToSyntax(isPeek ? stack.Peek() : stack.Pop(), _context);
|
var jumpCondition = IrisExpression.ToSyntax(isPeek ? stack.Peek() : stack.Pop(), _context);
|
||||||
|
|
||||||
if (opCode is OpCode.JumpIfFalse)
|
if (!isPeek)
|
||||||
{
|
{
|
||||||
// JMPF is used to evaluate the branch condition
|
// JMPF is used to evaluate the branch condition
|
||||||
var ifBlock = new CodeBlockInfo(instruction.Offset, jumpToOffset, SyntaxKind.IfStatement, jumpCondition);
|
var ifBlock = new CodeBlockInfo(instruction.Offset, jumpToOffset, SyntaxKind.IfStatement, jumpCondition);
|
||||||
blockStack.Push(ifBlock);
|
blockStack.Push(ifBlock);
|
||||||
}
|
}
|
||||||
else if (opCode is OpCode.JumpIfFalsePeek or OpCode.JumpIfTruePeek)
|
else
|
||||||
{
|
{
|
||||||
// JMPFP and JMPTP are only used to implement short-circuiting
|
// JMPFP and JMPTP are only used to implement short-circuiting
|
||||||
var ifBlock = SimplifyExpression(jumpCondition);
|
var ifBlock = SimplifyExpression(jumpCondition);
|
||||||
@@ -229,10 +219,7 @@ partial class Decompiler
|
|||||||
case OpCode.Jump:
|
case OpCode.Jump:
|
||||||
var jumpOffset = (uint)instruction.Operands.First().Value;
|
var jumpOffset = (uint)instruction.Operands.First().Value;
|
||||||
|
|
||||||
if (jumpOffset > instruction.Offset)
|
if (jumpOffset <= instruction.Offset)
|
||||||
{
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("Loops, ternaries, and null coalescing are not supported at this time");
|
throw new NotImplementedException("Loops, ternaries, and null coalescing are not supported at this time");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user