mirror of
https://github.com/patchzyy/wiicompiled
synced 2026-09-11 17:31:29 -04:00
25c69ae28e
* fix: Kamek LR-continuation hook discovery and dispatch * test: cover branching Kamek LR continuations * review fix * another review fix fix: get the new tests to pass test: expose LR restore and loop continuation regressions * Update translator/src/Translator.Core/Mods/ContinuationPlanner.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * test: cover continuation regressions from the new path-sensitive planner * Update translator/src/Translator.Core/Mods/ContinuationPlanner.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * test: cover continuation regressions from the new path-sensitive planner * fix: preserve LR continuation analysis across large handlers and clobbers * fix: track LR-relative r1 across update-form stack stores * Harden LR-relative continuation test coverage * Fix LR/SP continuation state tracking --------- Co-authored-by: patchzyy <64382339+patchzyy@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
64 lines
2.6 KiB
C#
64 lines
2.6 KiB
C#
using Translator.Core.Analysis.Ssa;
|
|
using Translator.Core.Analysis.Representation;
|
|
using Translator.Core.CodeGen;
|
|
using Translator.Core.Ir;
|
|
using Translator.Core.Representation;
|
|
using Xunit;
|
|
|
|
namespace Translator.Tests;
|
|
|
|
// This binary-free code-generation regression must run in the default suite.
|
|
public class LrContinuationCodeGenTests
|
|
{
|
|
[Fact]
|
|
public void CodeGenerator_DispatchesGuestCallLrContinuationWithoutMarkingTargetNonReturning()
|
|
{
|
|
var function = new IrFunction(
|
|
"lr_continuation_call",
|
|
"0x800E591C",
|
|
new[]
|
|
{
|
|
new IrBasicBlock("0x800E591C", new IrInstruction[]
|
|
{
|
|
new IrAssign("lr", IrValue.Imm(unchecked((int)0x800E5920u))),
|
|
new IrCall(string.Empty, "0x8179AC3C", Array.Empty<IrValue>()),
|
|
new IrAssign("r3", IrValue.Imm(8)),
|
|
new IrReturn(null)
|
|
}),
|
|
new IrBasicBlock("0x800E5934", new IrInstruction[]
|
|
{
|
|
new IrAssign("r3", IrValue.Imm(1)),
|
|
new IrReturn(null)
|
|
})
|
|
});
|
|
|
|
var types = new RepresentationEnvironment(new Dictionary<string, ValueRepresentation>
|
|
{
|
|
["lr"] = ValueRepresentation.UInt32,
|
|
["r3"] = ValueRepresentation.UInt32
|
|
});
|
|
var signature = new FunctionAbiClassification("lr_continuation_call", ValueRepresentation.Void);
|
|
|
|
var ssa = new SsaTransformer().Convert(function);
|
|
var code = new CxxLinearCodeGenerator().Emit(
|
|
0x800E591C,
|
|
ssa,
|
|
signature,
|
|
types,
|
|
lrContinuationCallTargets: new HashSet<uint> { 0x8179AC3Cu });
|
|
|
|
var callIndex = code.IndexOf("InvokeDirectCpu<0x8179AC3Cu>(ctx);", StringComparison.Ordinal);
|
|
var fallthroughGuardIndex = code.IndexOf("if (ctx->lr != 0x800E5920u)", callIndex, StringComparison.Ordinal);
|
|
var localCaseIndex = code.IndexOf("case 0x800E5934u:", fallthroughGuardIndex, StringComparison.Ordinal);
|
|
var returnIndex = code.IndexOf("return;", localCaseIndex, StringComparison.Ordinal);
|
|
var fallthroughAssignmentIndex = code.IndexOf("r3 = 8;", callIndex, StringComparison.Ordinal);
|
|
|
|
Assert.True(callIndex >= 0);
|
|
Assert.True(fallthroughGuardIndex > callIndex);
|
|
Assert.True(localCaseIndex > fallthroughGuardIndex);
|
|
Assert.True(returnIndex > localCaseIndex);
|
|
Assert.True(fallthroughAssignmentIndex > returnIndex, code);
|
|
Assert.Contains("goto loc_800E5934;", code);
|
|
}
|
|
}
|