mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Remove dead control block code
This commit is contained in:
@@ -39,14 +39,6 @@ partial class Decompiler
|
|||||||
Stack<CodeBlockInfo> blockStack = [];
|
Stack<CodeBlockInfo> blockStack = [];
|
||||||
blockStack.Push(new(0, methodBody[^1].Offset));
|
blockStack.Push(new(0, methodBody[^1].Offset));
|
||||||
|
|
||||||
HashSet<uint> jumpFalseToOffsets = new(methodBody
|
|
||||||
.Where(i => i.OpCode is OpCode.JumpIfFalse)
|
|
||||||
.Select(i => (uint)i.Operands.First().Value));
|
|
||||||
|
|
||||||
HashSet<uint> jumpToOffsets = new(methodBody
|
|
||||||
.Where(i => i.OpCode is OpCode.Jump)
|
|
||||||
.Select(i => (uint)i.Operands.First().Value));
|
|
||||||
|
|
||||||
HashSet<uint> foreachLoopHeadOffsets = [];
|
HashSet<uint> foreachLoopHeadOffsets = [];
|
||||||
|
|
||||||
Dictionary<string, TypeSchema> scopedLocals = [];
|
Dictionary<string, TypeSchema> scopedLocals = [];
|
||||||
@@ -66,49 +58,9 @@ partial class Decompiler
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine($"END: Finalizing {currentBlock}");
|
|
||||||
currentBlock.FinalizeBlock(blockStack.Peek());
|
currentBlock.FinalizeBlock(blockStack.Peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (jumpToOffsets.Contains(instruction.Offset) && TryPeekBlock<ElseBlockInfo>(out _))
|
|
||||||
//{
|
|
||||||
// // This address marks the end of the affirmative branch of an IF clause.
|
|
||||||
// // If multiple blocks lead to this address, then we're outside of the IF clause entirely.
|
|
||||||
// // Otherwise, it's probably the start of an ELSE clause.
|
|
||||||
|
|
||||||
// while (blockStack.Count > 1)
|
|
||||||
// {
|
|
||||||
// var currentBlock = blockStack.Pop();
|
|
||||||
|
|
||||||
// if (currentBlock.AdditionalInfo is not (ElseBlockInfo))
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// if (currentBlock.EndOffset is uint.MaxValue)
|
|
||||||
// currentBlock = currentBlock with { EndOffset = instruction.Offset };
|
|
||||||
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"JMP: Finalizing ELSE {currentBlock}");
|
|
||||||
// currentBlock.FinalizeBlock(blockStack.Peek());
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if (!foreachLoopHeadOffsets.Contains(instruction.Offset) && cfa.IsAlwaysExecuted(instruction.Offset))
|
|
||||||
//{
|
|
||||||
// while (blockStack.Count > 1)
|
|
||||||
// {
|
|
||||||
// var currentBlock = blockStack.Pop();
|
|
||||||
// if (currentBlock.EndOffset is uint.MaxValue)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (currentBlock.EndOffset != instruction.Offset || currentBlock.AdditionalInfo is not (IfBlockInfo or ElseBlockInfo))
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"Always exec'ed: Automatically finalizing {currentBlock}");
|
|
||||||
// currentBlock.FinalizeBlock(blockStack.Peek());
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
var opCode = instruction.OpCode;
|
var opCode = instruction.OpCode;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -355,13 +307,7 @@ partial class Decompiler
|
|||||||
{
|
{
|
||||||
// End of loop
|
// End of loop
|
||||||
|
|
||||||
if (foreachLoopHeadOffsets.Contains(jumpOffset))
|
if (!foreachLoopHeadOffsets.Contains(jumpOffset))
|
||||||
{
|
|
||||||
//var currentBlock = blockStack.Pop() with { EndOffset = instruction.Offset };
|
|
||||||
//System.Diagnostics.Debug.WriteLine($"JMP: Finalizing loop {currentBlock}");
|
|
||||||
//currentBlock.FinalizeBlock(blockStack.Peek());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("For and while loops are not supported at this time.");
|
throw new NotImplementedException("For and while loops are not supported at this time.");
|
||||||
}
|
}
|
||||||
@@ -377,10 +323,6 @@ partial class Decompiler
|
|||||||
.First()
|
.First()
|
||||||
.Offset;
|
.Offset;
|
||||||
|
|
||||||
//var currentBlock = blockStack.Pop() with { EndOffset = instruction.Offset };
|
|
||||||
//System.Diagnostics.Debug.WriteLine($"JMP: Finalizing presumed IF {currentBlock}");
|
|
||||||
//currentBlock.FinalizeBlock(blockStack.Peek());
|
|
||||||
|
|
||||||
var elseBlock = new CodeBlockInfo(instruction.Offset, elseBlockEndOffset, new ElseBlockInfo());
|
var elseBlock = new CodeBlockInfo(instruction.Offset, elseBlockEndOffset, new ElseBlockInfo());
|
||||||
blockStack.Push(elseBlock);
|
blockStack.Push(elseBlock);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user