Compiler.cs 1.8 KB

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