Common Intermediate Language и системное программирование в Microsoft.Net. Макаров А.В - 155 стр.

UptoLike

}
break;
case OperandType.ShortInlineVar: /* unsigned int8 */
Result.Add((byte)operand);
break;
case OperandType.InlineVar: /* unsigned int16 */
operands = BitConverter.GetBytes((UInt16)operand);
foreach( byte op in operands )
{
Result.Add(op);
}
break;
case OperandType.ShortInlineR: /* float32 */
operands = BitConverter.GetBytes((Single)operand);
foreach( byte op in operands )
{
Result.Add(op);
}
break;
case OperandType.InlineR: /* float64 */
operands = BitConverter.GetBytes((double)operand);
foreach( byte op in operands )
{
Result.Add(op);
}
break;
case OperandType.InlineSwitch: /* switch */
int[] targets = (int[])ins.Operand;
//Write length of switching table
operands = BitConverter.GetBytes(targets.Length);
int nextOpOffset = dataOffset;
foreach( byte op in operands )
{
Result.Add(op);
nextOpOffset++;
}
nextOpOffset += targets.Length*4;
Исходный код программы CilCodec
297
Result.Add((byte)codeValue);
object operand = ins.Operand;
int dataOffset = ins.Offset + ins.Code.Size;
switch (ins.Code.OperandType)
{
case OperandType.InlineNone: /* None */
break;
case OperandType.ShortInlineBrTarget: /* int8 */
Result.Add((byte)((int)ins.Operand – dataOffset – 1));
break;
case OperandType.InlineI: /* int32 */
byte[] operands = BitConverter.GetBytes((Int32)operand);
foreach( byte op in operands )
{
Result.Add(op);
}
break;
case OperandType.InlineBrTarget: /* int32 */
operands = BitConverter.GetBytes((Int32)operand);
foreach( byte op in operands )
{
Result.Add(op);
}
break;
case OperandType.InlineI8: /* int64 */
operands = BitConverter.GetBytes((Int64)operand);
foreach( byte op in operands )
{
Result.Add(op);
}
break;
case OperandType.ShortInlineI: /* int8 */
operands = BitConverter.GetBytes((sbyte)operand);
foreach( byte op in operands )
{
Result.Add(op);
296
CIL и системное программирование в Microsoft .NET
296                   CIL и системное программирование в Microsoft .NET   Исходный код программы CilCodec                                      297


      Result.Add((byte)codeValue);                                                         }
                                                                                           break;
      object operand = ins.Operand;
      int dataOffset = ins.Offset + ins.Code.Size;                                      case OperandType.ShortInlineVar: /* unsigned int8 */
      switch (ins.Code.OperandType)                                                       Result.Add((byte)operand);
      {                                                                                   break;
        case OperandType.InlineNone: /* None */
          break;                                                                        case OperandType.InlineVar: /* unsigned int16 */
                                                                                          operands = BitConverter.GetBytes((UInt16)operand);
        case OperandType.ShortInlineBrTarget: /* int8 */                                  foreach( byte op in operands )
          Result.Add((byte)((int)ins.Operand – dataOffset – 1));                          {
          break;                                                                            Result.Add(op);
                                                                                          }
        case OperandType.InlineI: /* int32 */                                             break;
          byte[] operands = BitConverter.GetBytes((Int32)operand);
          foreach( byte op in operands )                                                case OperandType.ShortInlineR: /* float32 */
          {                                                                               operands = BitConverter.GetBytes((Single)operand);
            Result.Add(op);                                                               foreach( byte op in operands )
          }                                                                               {
          break;                                                                            Result.Add(op);
                                                                                          }
        case OperandType.InlineBrTarget: /* int32 */                                      break;
          operands = BitConverter.GetBytes((Int32)operand);                             case OperandType.InlineR: /* float64 */
          foreach( byte op in operands )                                                  operands = BitConverter.GetBytes((double)operand);
          {                                                                               foreach( byte op in operands )
            Result.Add(op);                                                               {
          }                                                                                 Result.Add(op);
          break;                                                                          }
                                                                                          break;
        case OperandType.InlineI8: /* int64 */
          operands = BitConverter.GetBytes((Int64)operand);                             case OperandType.InlineSwitch: /* switch */
          foreach( byte op in operands )                                                  int[] targets = (int[])ins.Operand;
          {                                                                               //Write length of switching table
            Result.Add(op);                                                               operands = BitConverter.GetBytes(targets.Length);
          }                                                                               int nextOpOffset = dataOffset;
          break;                                                                          foreach( byte op in operands )
                                                                                          {
        case OperandType.ShortInlineI: /* int8 */                                           Result.Add(op);
          operands = BitConverter.GetBytes((sbyte)operand);                                 nextOpOffset++;
          foreach( byte op in operands )                                                  }
          {                                                                               nextOpOffset += targets.Length*4;
            Result.Add(op);