Compiler.cs 1.5 KB

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