/// <summary> /// Decodes the specified instruction. /// </summary> /// <param name="ctx">The context.</param> /// <param name="decoder">The instruction decoder, which holds the code stream.</param> public override void Decode(Context ctx, IInstructionDecoder decoder) { // Decode base classes first base.Decode(ctx, decoder); SigType type; object value; // Opcode specific handling switch (_opcode) { case OpCode.Ldc_i4: { int i; decoder.Decode(out i); type = new SigType(CilElementType.I4); value = i; } break; case OpCode.Ldc_i4_s: { sbyte sb; decoder.Decode(out sb); type = new SigType(CilElementType.I4); value = sb; } break; case OpCode.Ldc_i8: { long l; decoder.Decode(out l); type = new SigType(CilElementType.I8); value = l; } break; case OpCode.Ldc_r4: { float f; decoder.Decode(out f); type = new SigType(CilElementType.R4); value = f; } break; case OpCode.Ldc_r8: { double d; decoder.Decode(out d); type = new SigType(CilElementType.R8); value = d; } break; case OpCode.Ldnull: ctx.Result = ConstantOperand.GetNull(); return; case OpCode.Ldc_i4_0: ctx.Result = ConstantOperand.FromValue(0); return; case OpCode.Ldc_i4_1: ctx.Result = ConstantOperand.FromValue(1); return; case OpCode.Ldc_i4_2: ctx.Result = ConstantOperand.FromValue(2); return; case OpCode.Ldc_i4_3: ctx.Result = ConstantOperand.FromValue(3); return; case OpCode.Ldc_i4_4: ctx.Result = ConstantOperand.FromValue(4); return; case OpCode.Ldc_i4_5: ctx.Result = ConstantOperand.FromValue(5); return; case OpCode.Ldc_i4_6: ctx.Result = ConstantOperand.FromValue(6); return; case OpCode.Ldc_i4_7: ctx.Result = ConstantOperand.FromValue(7); return; case OpCode.Ldc_i4_8: ctx.Result = ConstantOperand.FromValue(8); return; case OpCode.Ldc_i4_m1: ctx.Result = ConstantOperand.FromValue(-1); return; default: throw new NotImplementedException(); } ctx.Result = new ConstantOperand(type, value); ctx.Ignore = true; }
/// <summary> /// Decodes the specified instruction. /// </summary> /// <param name="ctx">The context.</param> /// <param name="decoder">The instruction decoder, which holds the code stream.</param> public override void Decode(Context ctx, IInstructionDecoder decoder) { // Decode base classes first base.Decode(ctx, decoder); ConstantOperand constantValueOperand; // Opcode specific handling switch (opcode) { case OpCode.Ldc_i4: { int i = decoder.DecodeInt(); constantValueOperand = new ConstantOperand(new SigType(CilElementType.I4), i); } break; case OpCode.Ldc_i4_s: { sbyte sb = decoder.DecodeSByte(); constantValueOperand = new ConstantOperand(new SigType(CilElementType.I4), sb); } break; case OpCode.Ldc_i8: { long l = decoder.DecodeLong(); constantValueOperand = new ConstantOperand(new SigType(CilElementType.I8), l); } break; case OpCode.Ldc_r4: { float f = decoder.DecodeFloat(); constantValueOperand = new ConstantOperand(new SigType(CilElementType.R4), f); } break; case OpCode.Ldc_r8: { double d = decoder.DecodeDouble(); constantValueOperand = new ConstantOperand(new SigType(CilElementType.R8), d); } break; case OpCode.Ldnull: constantValueOperand = ConstantOperand.GetNull(); break; case OpCode.Ldc_i4_0: constantValueOperand = ConstantOperand.FromValue(0); break; case OpCode.Ldc_i4_1: constantValueOperand = ConstantOperand.FromValue(1); break; case OpCode.Ldc_i4_2: constantValueOperand = ConstantOperand.FromValue(2); break; case OpCode.Ldc_i4_3: constantValueOperand = ConstantOperand.FromValue(3); break; case OpCode.Ldc_i4_4: constantValueOperand = ConstantOperand.FromValue(4); break; case OpCode.Ldc_i4_5: constantValueOperand = ConstantOperand.FromValue(5); break; case OpCode.Ldc_i4_6: constantValueOperand = ConstantOperand.FromValue(6); break; case OpCode.Ldc_i4_7: constantValueOperand = ConstantOperand.FromValue(7); break; case OpCode.Ldc_i4_8: constantValueOperand = ConstantOperand.FromValue(8); break; case OpCode.Ldc_i4_m1: constantValueOperand = ConstantOperand.FromValue(-1); break; default: throw new System.NotImplementedException(); } ctx.Operand1 = constantValueOperand; ctx.Result = decoder.Compiler.CreateTemporary(constantValueOperand.Type); }