Compiler.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using ARMeilleure.CodeGen;
  2. using ARMeilleure.CodeGen.Optimizations;
  3. using ARMeilleure.CodeGen.X86;
  4. using ARMeilleure.Diagnostics;
  5. using ARMeilleure.IntermediateRepresentation;
  6. namespace ARMeilleure.Translation
  7. {
  8. static class Compiler
  9. {
  10. public static CompiledFunction Compile(
  11. ControlFlowGraph cfg,
  12. OperandType[] argTypes,
  13. OperandType retType,
  14. CompilerOptions options)
  15. {
  16. CompilerContext cctx = new(cfg, argTypes, retType, options);
  17. if (options.HasFlag(CompilerOptions.Optimize))
  18. {
  19. Logger.StartPass(PassName.TailMerge);
  20. TailMerge.RunPass(cctx);
  21. Logger.EndPass(PassName.TailMerge, cfg);
  22. }
  23. if (options.HasFlag(CompilerOptions.SsaForm))
  24. {
  25. Logger.StartPass(PassName.Dominance);
  26. Dominance.FindDominators(cfg);
  27. Dominance.FindDominanceFrontiers(cfg);
  28. Logger.EndPass(PassName.Dominance);
  29. Logger.StartPass(PassName.SsaConstruction);
  30. Ssa.Construct(cfg);
  31. Logger.EndPass(PassName.SsaConstruction, cfg);
  32. }
  33. else
  34. {
  35. Logger.StartPass(PassName.RegisterToLocal);
  36. RegisterToLocal.Rename(cfg);
  37. Logger.EndPass(PassName.RegisterToLocal, cfg);
  38. }
  39. return CodeGenerator.Generate(cctx);
  40. }
  41. }
  42. }