Compiler.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. using PTC;
  10. static class Compiler
  11. {
  12. public static T Compile<T>(
  13. ControlFlowGraph cfg,
  14. OperandType[] argTypes,
  15. OperandType retType,
  16. CompilerOptions options,
  17. PtcInfo ptcInfo = null)
  18. {
  19. CompiledFunction func = Compile(cfg, argTypes, retType, options, ptcInfo);
  20. IntPtr codePtr = JitCache.Map(func);
  21. return Marshal.GetDelegateForFunctionPointer<T>(codePtr);
  22. }
  23. public static CompiledFunction Compile(
  24. ControlFlowGraph cfg,
  25. OperandType[] argTypes,
  26. OperandType retType,
  27. CompilerOptions options,
  28. PtcInfo ptcInfo = null)
  29. {
  30. Logger.StartPass(PassName.Dominance);
  31. if ((options & CompilerOptions.SsaForm) != 0)
  32. {
  33. Dominance.FindDominators(cfg);
  34. Dominance.FindDominanceFrontiers(cfg);
  35. }
  36. Logger.EndPass(PassName.Dominance);
  37. Logger.StartPass(PassName.SsaConstruction);
  38. if ((options & CompilerOptions.SsaForm) != 0)
  39. {
  40. Ssa.Construct(cfg);
  41. }
  42. else
  43. {
  44. RegisterToLocal.Rename(cfg);
  45. }
  46. Logger.EndPass(PassName.SsaConstruction, cfg);
  47. CompilerContext cctx = new CompilerContext(cfg, argTypes, retType, options);
  48. return CodeGenerator.Generate(cctx, ptcInfo);
  49. }
  50. }
  51. }