コード例 #1
0
        /// <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;
                }
            }
        }