/// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            // Check signature identifier
            if (reader.ReadByte() != 0x07)
            {
                throw new ArgumentException("Token doesn't represent a local variable signature.", "token");
            }

            // Retrieve the number of locals
            int count = reader.ReadCompressedInt32();

            if (count != 0)
            {
                Locals = new VariableSignature[count];
                for (int i = 0; i < count; i++)
                {
                    Locals[i] = new VariableSignature(reader);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            if (plugSystem != null)
            {
                RuntimeMethod plugMethod = plugSystem.GetPlugMethod(this.methodCompiler.Method);

                if (plugMethod != null)
                {
                    SymbolOperand plugSymbol = SymbolOperand.FromMethod(plugMethod);

                    Context ctx = new Context(instructionSet);
                    ctx.AppendInstruction(IR.IRInstruction.Jmp, null, plugSymbol);
                    ctx.Label = -1;
                    basicBlocks.CreateBlock(BasicBlock.PrologueLabel, ctx.Index);

                    return;
                }
            }

            using (Stream code = methodCompiler.GetInstructionStream())
            {
                using (codeReader = new EndianAwareBinaryReader(code, true))
                {
                    MethodHeader header = ReadMethodHeader(codeReader);

                    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);
                        }

                        var declaringType = this.methodCompiler.Method.DeclaringType;
                        var locals = localsSignature.Locals;
                        for (var i = 0; i < locals.Length; ++i)
                        {
                            var local = locals[i];
                            if (local.Type is GenericInstSigType && declaringType is CilGenericType)
                            {
                                var genericInstSigType = local.Type as GenericInstSigType;
                                var genericArguments = methodCompiler.AssemblyCompiler.GenericTypePatcher.CloseGenericArguments((declaringType as CilGenericType).GenericArguments, genericInstSigType.GenericArguments);
                                local = new VariableSignature(locals[i], genericArguments);
                            }
                        }

                        methodCompiler.SetLocalVariableSignature(localsSignature);
                    }

                    /* Decode the instructions */
                    Decode(methodCompiler, header);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            // Check signature identifier
            if (reader.ReadByte() != 0x07)
                throw new ArgumentException("Token doesn't represent a local variable signature.", "token");

            // Retrieve the number of locals
            int count = reader.ReadCompressedInt32();
            if (count != 0)
            {
                Locals = new VariableSignature[count];
                for (int i = 0; i < count; i++)
                {
                    Locals[i] = new VariableSignature(reader);
                }
            }
        }
 private void ApplyGenericArguments(SigType[] genericArguments)
 {
     for (int i = 0; i < locals.Length; i++)
     {
         locals[i] = new VariableSignature(locals[i], genericArguments);
     }
 }