From e09a6b172526c53d70bae1a2ff88d5f10163ef6c Mon Sep 17 00:00:00 2001 From: uless Date: Thu, 5 Mar 2020 12:52:32 +0800 Subject: [PATCH] Fix OpCodes with 'Br' and 'Brtrue'. --- src/Ray.Core/Core/Grains/ObserverGrain.cs | 20 +++++--------------- src/Ray.Core/Snapshot/SnapshotHandler.cs | 13 ++----------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/Ray.Core/Core/Grains/ObserverGrain.cs b/src/Ray.Core/Core/Grains/ObserverGrain.cs index 4c874c2..369b4b1 100644 --- a/src/Ray.Core/Core/Grains/ObserverGrain.cs +++ b/src/Ray.Core/Core/Grains/ObserverGrain.cs @@ -67,9 +67,9 @@ public ObserverGrain() if (!sortList.Contains(item)) sortList.Add(item); } - var declare_1 = ilGen.DeclareLocal(typeof(Task)); var defaultLabel = ilGen.DefineLabel(); var lastLable = ilGen.DefineLabel(); + var declare_1 = ilGen.DeclareLocal(typeof(Task)); foreach (var item in sortList) { ilGen.Emit(OpCodes.Ldarg_1); @@ -110,15 +110,9 @@ public ObserverGrain() ilGen.Emit(OpCodes.Ldloc_3); } } - if (item.DeclareLocal.LocalIndex > 0 && item.DeclareLocal.LocalIndex < 255) - ilGen.Emit(OpCodes.Brtrue_S, item.Lable); - else - ilGen.Emit(OpCodes.Brtrue, item.Lable); + ilGen.Emit(OpCodes.Brtrue, item.Lable); } - if (declare_1.LocalIndex > 0 && declare_1.LocalIndex <= 255) - ilGen.Emit(OpCodes.Br_S, defaultLabel); - else - ilGen.Emit(OpCodes.Br, defaultLabel); + ilGen.Emit(OpCodes.Br, defaultLabel); foreach (var item in sortList) { ilGen.MarkLabel(item.Lable); @@ -145,10 +139,7 @@ public ObserverGrain() { ilGen.Emit(OpCodes.Stloc, declare_1); } - if (declare_1.LocalIndex > 0 && declare_1.LocalIndex <= 255) - ilGen.Emit(OpCodes.Br_S, lastLable); - else - ilGen.Emit(OpCodes.Br, lastLable); + ilGen.Emit(OpCodes.Br, lastLable); } ilGen.MarkLabel(defaultLabel); ilGen.Emit(OpCodes.Ldarg_0); @@ -157,13 +148,12 @@ public ObserverGrain() if (declare_1.LocalIndex > 0 && declare_1.LocalIndex <= 255) { ilGen.Emit(OpCodes.Stloc_S, declare_1); - ilGen.Emit(OpCodes.Br_S, lastLable); } else { ilGen.Emit(OpCodes.Stloc, declare_1); - ilGen.Emit(OpCodes.Br, lastLable); } + ilGen.Emit(OpCodes.Br, lastLable); //last ilGen.MarkLabel(lastLable); if (declare_1.LocalIndex > 0 && declare_1.LocalIndex <= 255) diff --git a/src/Ray.Core/Snapshot/SnapshotHandler.cs b/src/Ray.Core/Snapshot/SnapshotHandler.cs index 8360edd..fb2d97f 100644 --- a/src/Ray.Core/Snapshot/SnapshotHandler.cs +++ b/src/Ray.Core/Snapshot/SnapshotHandler.cs @@ -57,7 +57,6 @@ public SnapshotHandler() sortList.Add(item); } var defaultLabel = ilGen.DefineLabel(); - var maxLocalIndex = 0; foreach (var item in sortList) { ilGen.Emit(OpCodes.Ldarg_2); @@ -98,17 +97,9 @@ public SnapshotHandler() ilGen.Emit(OpCodes.Ldloc_3); } } - if (item.DeclareLocal.LocalIndex > 0 && item.DeclareLocal.LocalIndex < 255) - ilGen.Emit(OpCodes.Brtrue_S, item.Lable); - else - ilGen.Emit(OpCodes.Brtrue, item.Lable); - if (item.DeclareLocal.LocalIndex > maxLocalIndex) - maxLocalIndex = item.DeclareLocal.LocalIndex; + ilGen.Emit(OpCodes.Brtrue, item.Lable); } - if (maxLocalIndex > 0 && maxLocalIndex < 255) - ilGen.Emit(OpCodes.Br_S, defaultLabel); - else - ilGen.Emit(OpCodes.Br, defaultLabel); + ilGen.Emit(OpCodes.Br, defaultLabel); foreach (var item in sortList) { ilGen.MarkLabel(item.Lable);