Compiler.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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>(ControlFlowGraph cfg, OperandType[] argTypes, OperandType retType, CompilerOptions options)
  12. {
  13. CompiledFunction func = CompileAndGetCf(cfg, argTypes, retType, options);
  14. IntPtr codePtr = JitCache.Map(func);
  15. return Marshal.GetDelegateForFunctionPointer<T>(codePtr);
  16. }
  17. public static CompiledFunction CompileAndGetCf(ControlFlowGraph cfg, OperandType[] argTypes, OperandType retType, CompilerOptions options)
  18. {
  19. Logger.StartPass(PassName.Dominance);
  20. Dominance.FindDominators(cfg);
  21. Dominance.FindDominanceFrontiers(cfg);
  22. Logger.EndPass(PassName.Dominance);
  23. Logger.StartPass(PassName.SsaConstruction);
  24. if ((options & CompilerOptions.SsaForm) != 0)
  25. {
  26. Ssa.Construct(cfg);
  27. }
  28. else
  29. {
  30. RegisterToLocal.Rename(cfg);
  31. }
  32. Logger.EndPass(PassName.SsaConstruction, cfg);
  33. CompilerContext cctx = new CompilerContext(cfg, argTypes, retType, options);
  34. return CodeGenerator.Generate(cctx);
  35. }
  36. }
  37. }