示例#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);
        }
示例#2
0
        private IEnumerable <AssemblyLine> Brtrue(Instruction instruction)
        {
            yield return(PLA());

            yield return(BNE(LabelGenerator.GetFromInstruction((Instruction)instruction.Operand)));
        }
示例#3
0
 private IEnumerable <AssemblyLine> Br(Instruction instruction)
 {
     yield return(JMP(LabelGenerator.GetFromInstruction((Instruction)instruction.Operand)));
 }