diff --git a/Model/Bytecode/Instructions.cs b/Model/Bytecode/Instructions.cs index bb12534e..06230d5d 100644 --- a/Model/Bytecode/Instructions.cs +++ b/Model/Bytecode/Instructions.cs @@ -199,9 +199,14 @@ public class BranchInstruction : Instruction public bool UnsignedOperands { get; set; } public BranchInstruction(uint label, BranchOperation operation, uint target) + : this(label, operation, $"L_{target:X4}") + { + } + + public BranchInstruction(uint label, BranchOperation operation, string target) : base(label) { - this.Target = string.Format("L_{0:X4}", target); + this.Target = target; this.Operation = operation; } @@ -222,9 +227,14 @@ public class SwitchInstruction : Instruction public IList Targets { get; private set; } public SwitchInstruction(uint label, IEnumerable targets) + : this(label, targets.Select(target => $"L_{target:X4}").ToList()) + { + } + + public SwitchInstruction(uint label, IEnumerable targets) : base(label) { - this.Targets = targets.Select(target => string.Format("L_{0:X4}", target)).ToList(); + this.Targets = targets.ToList(); } public override void Accept(IInstructionVisitor visitor) diff --git a/Model/ExceptionHandlers.cs b/Model/ExceptionHandlers.cs index c7b4be2d..0658a2f9 100644 --- a/Model/ExceptionHandlers.cs +++ b/Model/ExceptionHandlers.cs @@ -35,11 +35,15 @@ public class ProtectedBlock : IExceptionHandlerBlock public string End { get; set; } public IExceptionHandler Handler { get; set; } - public ProtectedBlock(uint start, uint end) + public ProtectedBlock(uint start, uint end) : this($"L_{start:X4}", $"L_{end:X4}") + { + } + + public ProtectedBlock(string start, string end) { this.Kind = ExceptionHandlerBlockKind.Try; - this.Start = string.Format("L_{0:X4}", start); - this.End = string.Format("L_{0:X4}", end); + this.Start = start; + this.End = end; } public override string ToString() @@ -57,11 +61,16 @@ public class FilterExceptionHandler : IExceptionHandler public IType ExceptionType { get; set; } public FilterExceptionHandler(uint filterStart, uint start, uint end, IType exceptionType) + : this($"L_{filterStart:X4}", $"L_{start:X4}", $"L_{end:X4}", exceptionType) + { + } + + public FilterExceptionHandler(string filterStart, string start, string end, IType exceptionType) { this.Kind = ExceptionHandlerBlockKind.Filter; - this.FilterStart = string.Format("L_{0:X4}", filterStart); - this.Start = string.Format("L_{0:X4}", start); - this.End = string.Format("L_{0:X4}", end); + this.FilterStart = filterStart; + this.Start = start; + this.End = end; this.ExceptionType = exceptionType; } @@ -78,11 +87,15 @@ public class CatchExceptionHandler : IExceptionHandler public string End { get; set; } public IType ExceptionType { get; set; } - public CatchExceptionHandler(uint start, uint end, IType exceptionType) + public CatchExceptionHandler(uint start, uint end, IType exceptionType) : this($"L_{start:X4}", $"L_{end:X4}", exceptionType) + { + } + + public CatchExceptionHandler(string start, string end, IType exceptionType) { this.Kind = ExceptionHandlerBlockKind.Catch; - this.Start = string.Format("L_{0:X4}", start); - this.End = string.Format("L_{0:X4}", end); + this.Start = start; + this.End = end; this.ExceptionType = exceptionType; } @@ -98,11 +111,15 @@ public class FaultExceptionHandler : IExceptionHandler public string Start { get; set; } public string End { get; set; } - public FaultExceptionHandler(uint start, uint end) + public FaultExceptionHandler(uint start, uint end) : this($"L_{start:X4}", $"L_{end:X4}") + { + } + + public FaultExceptionHandler(string start, string end) { this.Kind = ExceptionHandlerBlockKind.Fault; - this.Start = string.Format("L_{0:X4}", start); - this.End = string.Format("L_{0:X4}", end); + this.Start = start; + this.End = end; } public override string ToString() @@ -117,11 +134,15 @@ public class FinallyExceptionHandler : IExceptionHandler public string Start { get; set; } public string End { get; set; } - public FinallyExceptionHandler(uint start, uint end) + public FinallyExceptionHandler(uint start, uint end) : this($"L_{start:X4}", $"L_{end:X4}") + { + } + + public FinallyExceptionHandler(string start, string end) { this.Kind = ExceptionHandlerBlockKind.Finally; - this.Start = string.Format("L_{0:X4}", start); - this.End = string.Format("L_{0:X4}", end); + this.Start = start; + this.End = end; } public override string ToString()