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)); }
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()); }
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); }
// 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); }
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)); }
object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context) { return(context.ResolveString(reader.ReadInt())); }
protected virtual void WriteDump(Context.IOperandReaderContext context, Stream stream) { Dump.InstructionReaderDump.Write(stream, context); }
protected virtual IEnumerable <IInstruction> GetInstructions(IBinaryReader binaryReader, Context.IOperandReaderContext context) { int index = 0; while (binaryReader.CanRead()) { yield return(new Instruction(index++, binaryReader, context)); } }
protected virtual IEnumerable <IMetadataItem> GetMetadata(Context.IOperandReaderContext context) { return(context.GetMetadata()); }
protected virtual string GetName(Context.IOperandReaderContext context) { return((context.Type == Context.OperandReaderContextType.Method) ? context.Name : context.Name + "(" + context.Type.ToString() + ")"); }
IILReader CreateInstructionReader(IBinaryReader binaryReader, Context.IOperandReaderContext context) { return(new InstructionReader(binaryReader, context)); }
protected override IEnumerable <IInstruction> GetInstructions(IBinaryReader binaryReader, Context.IOperandReaderContext context) { yield break; }
protected override IEnumerable <IMetadataItem> GetMetadata(Context.IOperandReaderContext context) { yield break; }
protected override string GetName(Context.IOperandReaderContext context) { return(string.Empty); }
object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context) { return(context[reader.ReadShort()]); }
object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context) { return(null); }
object IOperandReader.Read(IBinaryReader reader, Context.IOperandReaderContext context) { return(reader.ReadFloat()); }
protected override void WriteDump(Context.IOperandReaderContext context, Stream stream) { /* do nothing */ }