Beispiel #1
0
        protected override void Run()
        {
            if (!MethodCompiler.IsCILDecodeRequired)
            {
                return;
            }

            // No CIL decoding if this is a linker generated method
            Debug.Assert(!Method.IsCompilerGenerated);

            if (!Method.HasImplementation)
            {
                //if (DelegatePatcher.PatchDelegate(MethodCompiler))
                //	return;

                MethodCompiler.Stop();
                return;
            }

            if (CompilerOptions.EnableStatistics)
            {
                counts = new int[CILInstruction.MaxOpCodeValue];
            }

            MethodCompiler.SetLocalVariables(Method.LocalVariables);

            // Create the prologue block
            var prologue = CreateNewBlock(BasicBlock.PrologueLabel);

            BasicBlocks.AddHeadBlock(prologue);

            var jmpNode = new InstructionNode()
            {
                Label = BasicBlock.PrologueLabel,
                Block = prologue
            };

            prologue.First.Insert(jmpNode);

            // Create starting block
            var startBlock = CreateNewBlock(0);

            jmpNode.SetInstruction(IRInstruction.Jmp, startBlock);

            DecodeInstructionTargets();

            DecodeProtectedRegionTargets();

            /* Decode the instructions */
            DecodeInstructions();

            foreach (var block in BasicBlocks)
            {
                if (!block.HasPreviousBlocks && !block.IsHeadBlock)
                {
                    // block was targeted (probably by an leave instruction within a protected region)
                    BasicBlocks.AddHeadBlock(block);
                }
            }

            // This makes it easier to review --- it's not necessary
            BasicBlocks.OrderByLabel();
        }
Beispiel #2
0
        protected override void Run()
        {
            // No CIL decoding if this is a linker generated method
            if (MethodCompiler.Method.IsLinkerGenerated)
            {
                return;
            }

            var plugMethod = MethodCompiler.Compiler.PlugSystem.GetPlugMethod(MethodCompiler.Method);

            if (plugMethod != null)
            {
                var plugSymbol = Operand.CreateSymbolFromMethod(TypeSystem, plugMethod);
                var context    = CreateNewBlockContext(-1);
                context.AppendInstruction(IRInstruction.Jmp, null, plugSymbol);
                BasicBlocks.AddHeaderBlock(context.Block);
                return;
            }

            if (MethodCompiler.Method.Code.Count == 0)
            {
                if (DelegatePatcher.PatchDelegate(MethodCompiler))
                {
                    return;
                }

                MethodCompiler.Stop();
                return;
            }

            MethodCompiler.SetLocalVariables(MethodCompiler.Method.LocalVariables);

            // Create the prologue block
            var prologue = CreateNewBlock(BasicBlock.PrologueLabel);

            BasicBlocks.AddHeaderBlock(prologue);

            var jmpNode = new InstructionNode();

            jmpNode.Label = BasicBlock.PrologueLabel;
            jmpNode.Block = prologue;
            prologue.First.Insert(jmpNode);

            // Create starting block
            var startBlock = CreateNewBlock(0);

            jmpNode.SetInstruction(IRInstruction.Jmp, startBlock);

            DecodeInstructionTargets();

            DecodeProtectedRegionTargets();

            /* Decode the instructions */
            DecodeInstructions();

            foreach (var block in BasicBlocks)
            {
                if (!block.HasPreviousBlocks && !BasicBlocks.HeadBlocks.Contains(block))
                {
                    // block was targeted (probably by an leave instruction within a protected region)
                    BasicBlocks.AddHeaderBlock(block);
                }
            }

            // This makes it easier to review --- it's not necessary
            BasicBlocks.OrderByLabel();
        }
Beispiel #3
0
 protected override void Run()
 {
     MethodCompiler.Stop();
 }