示例#1
0
        /// <summary>
        /// Transcript given instructions in context of given method.
        /// Transcription is processed by given emitter.
        /// </summary>
        /// <param name="method">Context method of transcription</param>
        /// <param name="instructions">Transcripted instructions</param>
        /// <param name="emitter">Emitter where transcription is emitted</param>
        internal static void Transcript(TypeMethodInfo method, IEnumerable <CILInstruction> instructions, EmitterBase emitter)
        {
            E           = emitter;
            Method      = method;
            LocalTmpVar = E.GetTemporaryVariable("local");

            //prepare labels table
            Labels.Clear();
            foreach (var instruction in instructions)
            {
                var labelName = string.Format("L_0x{0:x4}", instruction.Address);
                Labels.Add(instruction.Address, E.CreateLabel(labelName));
            }

            foreach (var instruction in instructions)
            {
                Instruction = instruction;
                E.SetLabel(Labels[instruction.Address]);

                var block = E.StartNewInfoBlock();
                block.Comment = "\n---" + Instruction.ToString();

                Action transcriptor;
                if (_transcriptors.TryGetValue(Name, out transcriptor))
                {
                    transcriptor();
                }
                else
                {
                    unknownInstruction();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Generate header with instructions providing compiler environment.
        /// </summary>
        private void compilerPreparations()
        {
            E.StartNewInfoBlock().Comment = "===Compiler initialization===";

            prepareStack();

            if (_methodInfo.HasThis)
            {
                E.AssignArgument("this", _methodInfo.DeclaringType, 0);
            }

            //generate argument assigns
            for (uint i = 0; i < _methodInfo.Parameters.Length; ++i)
            {
                var arg = _methodInfo.Parameters[i];
                E.AssignArgument(arg.Name, arg.Type, i + 1); //argument 0 is always this object

                //TODO declare arguments
            }
        }