Exemple #1
0
        /// <summary>
        /// Decodes the instruction stream of the reader and populates the compiler.
        /// </summary>
        /// <param name="compiler">The compiler to populate.</param>
        /// <exception cref="InvalidMetadataException"></exception>
        private void Decode(BaseMethodCompiler compiler)
        {
            // Create context
            Context context = new Context(InstructionSet);

            // Prefix instruction
            bool prefix = false;

            for (int i = 0; i < MethodCompiler.Method.Code.Count; i++)
            {
                MosaInstruction instr = MethodCompiler.Method.Code[i];
                var op = (OpCode)instr.OpCode;

                BaseCILInstruction instruction = CILInstruction.Get(op);

                if (instruction == null)
                {
                    throw new InvalidMetadataException();
                }

                // Create and initialize the corresponding instruction
                context.AppendInstruction(instruction);
                context.Label = instr.Offset;
                context.HasPrefix = prefix;
                this.instruction = instr;
                instruction.Decode(context, this);

                Debug.Assert(context.Instruction != null);

                prefix = (instruction is PrefixInstruction);
            }
        }