From d2d71f93f04eca8e8b3ba41739714ecbaaba9ffb Mon Sep 17 00:00:00 2001 From: merry Date: Mon, 14 Feb 2022 21:48:28 +0000 Subject: [PATCH] Use index to handle IfThenBlockState --- ARMeilleure/Instructions/InstEmitFlow32.cs | 2 +- ARMeilleure/Translation/ArmEmitterContext.cs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ARMeilleure/Instructions/InstEmitFlow32.cs b/ARMeilleure/Instructions/InstEmitFlow32.cs index f6d7e23bb..add66a425 100644 --- a/ARMeilleure/Instructions/InstEmitFlow32.cs +++ b/ARMeilleure/Instructions/InstEmitFlow32.cs @@ -105,7 +105,7 @@ namespace ARMeilleure.Instructions { OpCodeT16IfThen op = (OpCodeT16IfThen)context.CurrOp; - context.IfThenBlockState = op.IfThenBlockConds; + context.SetIfThenBlockState(op.IfThenBlockConds); } } } \ No newline at end of file diff --git a/ARMeilleure/Translation/ArmEmitterContext.cs b/ARMeilleure/Translation/ArmEmitterContext.cs index 2383b5c42..3c0dcae14 100644 --- a/ARMeilleure/Translation/ArmEmitterContext.cs +++ b/ARMeilleure/Translation/ArmEmitterContext.cs @@ -55,9 +55,10 @@ namespace ARMeilleure.Translation public bool HighCq { get; } public Aarch32Mode Mode { get; } - public bool IsInIfThenBlock { get { return IfThenBlockState != null && IfThenBlockState.Length > 0; } } - public Condition CurrentIfThenBlockCond { get { return IfThenBlockState[0]; } } - public Condition[] IfThenBlockState { get; set; } + private int _ifThenBlockStateIndex = 0; + private Condition[] _ifThenBlockState = { }; + public bool IsInIfThenBlock => _ifThenBlockStateIndex < _ifThenBlockState.Length; + public Condition CurrentIfThenBlockCond => _ifThenBlockState[_ifThenBlockStateIndex]; public ArmEmitterContext( IMemoryManager memory, @@ -202,11 +203,17 @@ namespace ARMeilleure.Translation return default; } + public void SetIfThenBlockState(Condition[] state) + { + _ifThenBlockState = state; + _ifThenBlockStateIndex = 0; + } + public void AdvanceIfThenBlockState() { if (IsInIfThenBlock) { - IfThenBlockState = IfThenBlockState.Skip(1).ToArray(); + _ifThenBlockStateIndex++; } } }