Exemple #1
0
        public static IEnumerable <AssemblyLine> CompileMethod(MethodDefinition definition, IImmutableDictionary <string, ProcessedType> types, Assembly frameworkAssembly)
        {
            var instructionCompiler = new CilInstructionCompiler(definition, types);
            var instructions        = definition.Body.Instructions;
            var compilationActions  = ProcessInstructions(instructions, types, frameworkAssembly);
            var instructionsToLabel = GetInstructionsToEmitLabelsFor(instructions).ToArray();
            var compiledBody        = new List <AssemblyLine>();
            var compilationContext  = new CompilationContext(instructionCompiler);

            foreach (var action in compilationActions)
            {
                var needLabel = action.ConsumedInstructions.Where(i => instructionsToLabel.Contains(i)).ToArray();
                foreach (var toLabel in needLabel)
                {
                    compiledBody.Add(AssemblyFactory.Label(LabelGenerator.GetFromInstruction(toLabel)));
                }

                compiledBody.AddRange(action.Execute(compilationContext));
            }

            compiledBody = OptimizeMethod(compiledBody).ToList();
            return(compiledBody);
        }
 public CompilationContext(CilInstructionCompiler cilInstructionCompiler)
 {
     CilInstructionCompiler = cilInstructionCompiler;
 }