Ejemplo n.º 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())
            {
                // 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);
                        MethodCompiler.SetLocalVariableSignature(LocalVariableSignature.Parse(md, row.SignatureBlobIdx));
                    }

                    /* 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;
                }
            }
        }