/// <summary> /// Initializes a new instance of the <see cref="LocalVariableSignature"/> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="token">The token.</param> /// <param name="genericArguments">The generic arguments.</param> public LocalVariableSignature(LocalVariableSignature signature, SigType[] genericArguments) : base(signature.Token) { locals = new VariableSignature[signature.locals.Length]; for (int i = 0; i < signature.locals.Length; i++) locals[i] = new VariableSignature(signature.locals[i], genericArguments); }
/// <summary> /// Parses the specified provider. /// </summary> /// <param name="provider">The provider.</param> /// <param name="token">The token.</param> /// <returns></returns> public static LocalVariableSignature Parse(IMetadataProvider provider, TokenTypes token) { byte[] buffer; int index = 0; provider.Read(token, out buffer); LocalVariableSignature sig = new LocalVariableSignature(); sig.ParseSignature(buffer, ref index); Debug.Assert(index == buffer.Length, @"Signature parser didn't complete."); return sig; }
/// <summary> /// Initializes a new instance of the <see cref="LocalVariableSignature"/> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="token">The token.</param> /// <param name="genericArguments">The generic arguments.</param> public LocalVariableSignature(LocalVariableSignature signature, SigType[] genericArguments) : base(signature.Token) { locals = new VariableSignature[signature.locals.Length]; for (int i = 0; i < signature.locals.Length; i++) { locals[i] = new VariableSignature(signature.locals[i], genericArguments); } }
/// <summary> /// Parses the specified provider. /// </summary> /// <param name="provider">The provider.</param> /// <param name="token">The token.</param> /// <returns></returns> public static LocalVariableSignature Parse(IMetadataProvider provider, TokenTypes token) { byte[] buffer; int index = 0; provider.Read(token, out buffer); LocalVariableSignature sig = new LocalVariableSignature(); sig.ParseSignature(buffer, ref index); Debug.Assert(index == buffer.Length, @"Signature parser didn't complete."); return(sig); }
/// <summary> /// Performs stage specific processing on the compiler context. /// </summary> public void Run() { // The size of the code in bytes MethodHeader header = new MethodHeader(); using (Stream code = methodCompiler.GetInstructionStream()) { // Initialize the instruction, setting the initialize size the same as the code stream methodCompiler.InstructionSet = new InstructionSet((int)code.Length); // update the base class InstructionSet = methodCompiler.InstructionSet; using (BinaryReader reader = new BinaryReader(code)) { codeReader = reader; //Debug.WriteLine("Decoding " + methodCompiler.Method.ToString()); ReadMethodHeader(reader, ref header); if (header.localsSignature != 0) { StandAloneSigRow row = methodCompiler.Method.MetadataModule.Metadata.ReadStandAloneSigRow(header.localsSignature); LocalVariableSignature localsSignature = new LocalVariableSignature(methodCompiler.Method.MetadataModule.Metadata, row.SignatureBlobIdx); if (methodCompiler.Method.DeclaringType is CilGenericType) { localsSignature.ApplyGenericType((methodCompiler.Method.DeclaringType as CilGenericType).GenericArguments); } methodCompiler.SetLocalVariableSignature(localsSignature); } /* Decode the instructions */ Decode(methodCompiler, ref header); // When we leave, the operand stack must only contain the locals... //Debug.Assert(_operandStack.Count == _method.Locals.Count); codeReader = null; } } }
/// <summary> /// Performs stage specific processing on the compiler context. /// </summary> public void Run() { using (Stream code = methodCompiler.GetInstructionStream()) { // Initialize the instruction methodCompiler.InstructionSet = new InstructionSet(256); // update the base class InstructionSet = methodCompiler.InstructionSet; using (codeReader = new BinaryReader(code)) { // The size of the code in bytes MethodHeader header = new MethodHeader(); ReadMethodHeader(codeReader, ref header); if (header.localsSignature.RID != 0) { StandAloneSigRow row = methodCompiler.Method.Module.MetadataModule.Metadata.ReadStandAloneSigRow(header.localsSignature); LocalVariableSignature localsSignature; if (methodCompiler.Method.DeclaringType is CilGenericType) { localsSignature = new LocalVariableSignature(methodCompiler.Method.Module.MetadataModule.Metadata, row.SignatureBlobIdx, (methodCompiler.Method.DeclaringType as CilGenericType).GenericArguments); } else { localsSignature = new LocalVariableSignature(methodCompiler.Method.Module.MetadataModule.Metadata, row.SignatureBlobIdx); } methodCompiler.SetLocalVariableSignature(localsSignature); } /* Decode the instructions */ Decode(methodCompiler, ref header); // When we leave, the operand stack must only contain the locals... //Debug.Assert(_operandStack.Count == _method.Locals.Count); } } }
/// <summary> /// Sets the signature of local variables in the method. /// </summary> /// <param name="localVariableSignature">The local variable signature of the _method.</param> public void SetLocalVariableSignature(LocalVariableSignature localVariableSignature) { if (localVariableSignature == null) throw new ArgumentNullException(@"localVariableSignature"); _localsSig = localVariableSignature; int count = _localsSig.Types.Length; this._locals = new List<Operand>(count); for (int index = 0; index < count; index++) this._locals.Add(null); _nextStackSlot = _locals.Count + 1; }
/// <summary> /// Sets the signature of local variables in the method. /// </summary> /// <param name="localVariableSignature">The local variable signature of the _method.</param> public void SetLocalVariableSignature(LocalVariableSignature localVariableSignature) { if (localVariableSignature == null) throw new ArgumentNullException(@"localVariableSignature"); _localsSig = localVariableSignature; _locals = new List<Operand>(new Operand[_localsSig.Types.Length]); _nextStackSlot = _locals.Count + 1; }
// NOT USED //private void ScheduleDependencyForCompilation(SigType signatureType) //{ // RuntimeType runtimeType = null; // TypeSigType typeSigType = signatureType as TypeSigType; // if (typeSigType != null) // { // runtimeType = moduleTypeSystem.GetType(typeSigType.Token); // } // else // { // GenericInstSigType genericSignatureType = signatureType as GenericInstSigType; // if (genericSignatureType != null) // { // RuntimeType genericType = moduleTypeSystem.GetType(genericSignatureType.BaseType.Token); // Console.WriteLine(@"Loaded generic type {0}", genericType.FullName); // runtimeType = new CilGenericType(moduleTypeSystem, genericType, genericSignatureType); // } // } // if (runtimeType != null) // { // compilationScheduler.ScheduleTypeForCompilation(runtimeType); // } //} /// <summary> /// Sets the signature of local variables in the method. /// </summary> /// <param name="localVariableSignature">The local variable signature of the _method.</param> public void SetLocalVariableSignature(LocalVariableSignature localVariableSignature) { if (localVariableSignature == null) throw new ArgumentNullException(@"localVariableSignature"); localsSig = localVariableSignature; int count = localsSig.Locals.Length; locals = new Operand[count]; nextStackSlot = locals.Length + 1; }
/// <summary> /// Parses the specified provider. /// </summary> /// <param name="provider">The provider.</param> /// <param name="token">The token.</param> /// <returns></returns> public static LocalVariableSignature Parse(ISignatureContext context, IMetadataProvider provider, TokenTypes token) { var signature = new LocalVariableSignature(); signature.LoadSignature(context, provider, token); return signature; }
/// <summary> /// Performs stage specific processing on the compiler context. /// </summary> public void Run() { // The size of the code in bytes MethodHeader header = new MethodHeader(); using (Stream code = MethodCompiler.GetInstructionStream()) { // Initalize the instruction, setting the initalize size to 10 times the code stream MethodCompiler.InstructionSet = new InstructionSet((int)code.Length * 10); // update the base class InstructionSet = MethodCompiler.InstructionSet; using (BinaryReader reader = new BinaryReader(code)) { _compiler = MethodCompiler; _method = MethodCompiler.Method; _codeReader = reader; ReadMethodHeader(reader, ref header); //Debug.WriteLine("Decoding " + compiler.Method.ToString()); if (0 != header.localsSignature) { StandAloneSigRow row; IMetadataProvider md = _method.Module.Metadata; md.Read(header.localsSignature, out row); LocalVariableSignature localsSignature = new LocalVariableSignature(); localsSignature.LoadSignature(this._method, md, row.SignatureBlobIdx); this.MethodCompiler.SetLocalVariableSignature(localsSignature); } /* Decode the instructions */ Decode(MethodCompiler, ref header); // When we leave, the operand stack must only contain the locals... //Debug.Assert(_operandStack.Count == _method.Locals.Count); _codeReader = null; _compiler = null; } } }