Compiler.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using ARMeilleure.CodeGen;
  2. using ARMeilleure.CodeGen.X86;
  3. using ARMeilleure.Diagnostics;
  4. using ARMeilleure.IntermediateRepresentation;
  5. using System;
  6. using System.Runtime.InteropServices;
  7. namespace ARMeilleure.Translation
  8. {
  9. static class Compiler
  10. {
  11. public static T Compile<T>(
  12. ControlFlowGraph cfg,
  13. OperandType[] funcArgTypes,
  14. OperandType funcReturnType,
  15. CompilerOptions options)
  16. {
  17. Logger.StartPass(PassName.Dominance);
  18. Dominance.FindDominators(cfg);
  19. Dominance.FindDominanceFrontiers(cfg);
  20. Logger.EndPass(PassName.Dominance);
  21. Logger.StartPass(PassName.SsaConstruction);
  22. if ((options & CompilerOptions.SsaForm) != 0)
  23. {
  24. Ssa.Construct(cfg);
  25. }
  26. else
  27. {
  28. RegisterToLocal.Rename(cfg);
  29. }
  30. Logger.EndPass(PassName.SsaConstruction, cfg);
  31. CompilerContext cctx = new CompilerContext(cfg, funcArgTypes, funcReturnType, options);
  32. CompiledFunction func = CodeGenerator.Generate(cctx);
  33. IntPtr codePtr = JitCache.Map(func);
  34. return Marshal.GetDelegateForFunctionPointer<T>(codePtr);
  35. }
  36. }
  37. }