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); }
private IEnumerable <AssemblyLine> Brtrue(Instruction instruction) { yield return(PLA()); yield return(BNE(LabelGenerator.GetFromInstruction((Instruction)instruction.Operand))); }
private IEnumerable <AssemblyLine> Br(Instruction instruction) { yield return(JMP(LabelGenerator.GetFromInstruction((Instruction)instruction.Operand))); }