Ejemplo n.º 1
0
        /// <summary>
        /// Runs the specified method compiler.
        /// </summary>
        public void Run()
        {
            // Allocate a list of locals
            List <StackOperand> locals = new List <StackOperand> ();

            // Retrieve the calling convention of the method
            ICallingConvention cc = Architecture.GetCallingConvention(MethodCompiler.Method.Signature.CallingConvention);

            Debug.Assert(null != cc, "Failed to retrieve the calling convention of the method.");

            // Iterate all Blocks and collect locals From all Blocks
            foreach (BasicBlock block in BasicBlocks)
            {
                CollectLocalVariables(locals, block);
            }

            // Sort all found locals
            OrderVariables(locals, cc);

            // Now we assign increasing stack offsets to each variable
            _localsSize = LayoutVariables(locals, cc, cc.OffsetOfFirstLocal, 1);
            if (TRACING.TraceInfo == true)
            {
                Trace.WriteLine(String.Format("Stack layout for method {0}", MethodCompiler.Method));
                LogOperands(locals);
            }

            // Layout parameters
            LayoutParameters(MethodCompiler, cc);

            // Create a prologue instruction
            Context prologueCtx = new Context(InstructionSet, FindBlock(-1)).InsertBefore();

            prologueCtx.SetInstruction(IR.Instruction.PrologueInstruction);
            prologueCtx.Other = _localsSize;
            prologueCtx.Label = -1;

            // Create an epilogue instruction
            Context epilogueCtx = new Context(InstructionSet, FindBlock(Int32.MaxValue));

            epilogueCtx.AppendInstruction(IR.Instruction.EpilogueInstruction);
            epilogueCtx.Other = _localsSize;
            epilogueCtx.Label = Int32.MaxValue;
        }