示例#1
0
 public InstructionReader(IBinaryReader binaryReader, Context.IOperandReaderContext context)
 {
     name         = new LazyRef <string>(() => GetName(context));
     metadata     = new LazyRef <IEnumerable <IMetadataItem> >(() => GetMetadata(context));
     instructions = new LazyRef <IInstruction[]>(() => GetInstructions(binaryReader, context).ToArray());
     writeDump    = new LazyRef <Action <Stream> >(() => (stream) => WriteDump(context, stream));
 }
示例#2
0
        public static object ReadArg(IBinaryReader binaryReader, Context.IOperandReaderContext context, OperandType operandType)
        {
            IOperandReader reader;

            if (argumentReadersCache.TryGetValue(operandType, out reader))
            {
                return(reader.Read(binaryReader, context));
            }
            throw new System.NotSupportedException(operandType.ToString());
        }
示例#3
0
        object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context)
        {
            int casesCount = reader.ReadInt();

            int[] labelOffsets = new int[casesCount];
            for (int i = 0; i < labelOffsets.Length; i++)
            {
                labelOffsets[i] = reader.ReadInt();
            }
            return(labelOffsets);
        }
示例#4
0
 //
 public static void Write(System.IO.Stream stream, Context.IOperandReaderContext context)
 {
     // type
     stream.Write(new byte[] { (byte)context.Type }, 0, 1);
     // name
     byte[] nameBytes = null;
     DumpHelper.GetBytes(ref nameBytes, context.Name);
     DumpHelper.Write(nameBytes.Length, stream);
     // IL
     byte[] ILBytes = context.GetIL();
     DumpHelper.Write(ILBytes.Length, stream);
     // context data
     stream.Write(nameBytes, 0, nameBytes.Length);
     stream.Write(ILBytes, 0, ILBytes.Length);
     // meta
     DumpHelper.WriteMedatataItems(stream, context.GetMetadata());
     // body
     context.Dump(stream);
 }
示例#5
0
            internal Instruction(int index, IBinaryReader binaryReader, Context.IOperandReaderContext context)
            {
                this.Index  = index;
                this.Offset = binaryReader.Offset;
                this.OpCode = OpCodeReader.ReadOpCode(binaryReader);
                // Operand
                bool argumentAware = OperandReader.IsArgumentAware(OpCode);

                if (argumentAware)
                {
                    this.Operand = OperandReader.ReadArg(binaryReader, context, OpCode.OperandType);
                    argIndex     = OperandReader.GetArgIndex(OpCode, binaryReader);
                    if (argIndex.Value > 0)
                    {
                        this.rawOperand = context[(short)(argIndex.Value - 1), true];
                    }
                    else
                    {
                        this.rawOperand = context.This;
                    }
                }
                bool localAware = OperandReader.IsLocalAware(OpCode);

                if (localAware)
                {
                    this.Operand = OperandReader.Read(binaryReader, context, OpCode.OperandType);
                    locIndex     = OperandReader.GetLocalIndex(OpCode, binaryReader);
                    if (Operand == null)
                    {
                        this.rawOperand = context[locIndex.Value, false];
                    }
                }
                if (!localAware && !argumentAware)
                {
                    this.Operand = OperandReader.Read(binaryReader, context, OpCode.OperandType);
                }
                //
                int size = binaryReader.Offset - Offset;

                this.bytes = new LazyRef <byte[]>(() => binaryReader.Read(Offset, size));
            }
示例#6
0
 object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context)
 {
     return(context.ResolveString(reader.ReadInt()));
 }
示例#7
0
 protected virtual void WriteDump(Context.IOperandReaderContext context, Stream stream)
 {
     Dump.InstructionReaderDump.Write(stream, context);
 }
示例#8
0
        protected virtual IEnumerable <IInstruction> GetInstructions(IBinaryReader binaryReader, Context.IOperandReaderContext context)
        {
            int index = 0;

            while (binaryReader.CanRead())
            {
                yield return(new Instruction(index++, binaryReader, context));
            }
        }
示例#9
0
 protected virtual IEnumerable <IMetadataItem> GetMetadata(Context.IOperandReaderContext context)
 {
     return(context.GetMetadata());
 }
示例#10
0
 protected virtual string GetName(Context.IOperandReaderContext context)
 {
     return((context.Type == Context.OperandReaderContextType.Method) ? context.Name :
            context.Name + "(" + context.Type.ToString() + ")");
 }
示例#11
0
 IILReader CreateInstructionReader(IBinaryReader binaryReader, Context.IOperandReaderContext context)
 {
     return(new InstructionReader(binaryReader, context));
 }
示例#12
0
 protected override IEnumerable <IInstruction> GetInstructions(IBinaryReader binaryReader, Context.IOperandReaderContext context)
 {
     yield break;
 }
示例#13
0
 protected override IEnumerable <IMetadataItem> GetMetadata(Context.IOperandReaderContext context)
 {
     yield break;
 }
示例#14
0
 protected override string GetName(Context.IOperandReaderContext context)
 {
     return(string.Empty);
 }
示例#15
0
 object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context)
 {
     return(context[reader.ReadShort()]);
 }
示例#16
0
 object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context)
 {
     return(null);
 }
示例#17
0
 object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context)
 {
     return(reader.ReadFloat());
 }
示例#18
0
 protected override void WriteDump(Context.IOperandReaderContext context, Stream stream)
 {
     /* do nothing */
 }