public static CompiledFunction Compile( ControlFlowGraph cfg, OperandType[] argTypes, OperandType retType, CompilerOptions options, PtcInfo ptcInfo = null) { Logger.StartPass(PassName.Dominance); if ((options & CompilerOptions.SsaForm) != 0) { Dominance.FindDominators(cfg); Dominance.FindDominanceFrontiers(cfg); } Logger.EndPass(PassName.Dominance); Logger.StartPass(PassName.SsaConstruction); if ((options & CompilerOptions.SsaForm) != 0) { Ssa.Construct(cfg); } else { RegisterToLocal.Rename(cfg); } Logger.EndPass(PassName.SsaConstruction, cfg); CompilerContext cctx = new CompilerContext(cfg, argTypes, retType, options); return(CodeGenerator.Generate(cctx, ptcInfo)); }
internal static TranslatedFunction Translate(IMemoryManager memory, JumpTable jumpTable, ulong address, ExecutionMode mode, bool highCq) { ArmEmitterContext context = new ArmEmitterContext(memory, jumpTable, address, highCq, Aarch32Mode.User); Logger.StartPass(PassName.Decoding); Block[] blocks = Decoder.Decode(memory, address, mode, highCq, singleBlock: false); Logger.EndPass(PassName.Decoding); PreparePool(highCq ? 1 : 0); Logger.StartPass(PassName.Translation); EmitSynchronization(context); if (blocks[0].Address != address) { context.Branch(context.GetLabel(address)); } ControlFlowGraph cfg = EmitAndGetCFG(context, blocks, out Range funcRange); ulong funcSize = funcRange.End - funcRange.Start; Logger.EndPass(PassName.Translation); Logger.StartPass(PassName.RegisterUsage); RegisterUsage.RunPass(cfg, mode); Logger.EndPass(PassName.RegisterUsage); OperandType[] argTypes = new OperandType[] { OperandType.I64 }; CompilerOptions options = highCq ? CompilerOptions.HighCq : CompilerOptions.None; GuestFunction func; if (Ptc.State == PtcState.Disabled) { func = Compiler.Compile <GuestFunction>(cfg, argTypes, OperandType.I64, options); ResetPool(highCq ? 1 : 0); } else { using PtcInfo ptcInfo = new PtcInfo(); func = Compiler.Compile <GuestFunction>(cfg, argTypes, OperandType.I64, options, ptcInfo); ResetPool(highCq ? 1 : 0); Hash128 hash = Ptc.ComputeHash(memory, address, funcSize); Ptc.WriteInfoCodeRelocUnwindInfo(address, funcSize, hash, highCq, ptcInfo); } return(new TranslatedFunction(func, funcSize, highCq)); }
internal static TranslatedFunction Translate(IMemoryManager memory, JumpTable jumpTable, ulong address, ExecutionMode mode, bool highCq) { ArmEmitterContext context = new ArmEmitterContext(memory, jumpTable, (long)address, highCq, Aarch32Mode.User); PrepareOperandPool(highCq); PrepareOperationPool(highCq); Logger.StartPass(PassName.Decoding); Block[] blocks = Decoder.DecodeFunction(memory, address, mode, highCq); Logger.EndPass(PassName.Decoding); Logger.StartPass(PassName.Translation); EmitSynchronization(context); if (blocks[0].Address != address) { context.Branch(context.GetLabel(address)); } ControlFlowGraph cfg = EmitAndGetCFG(context, blocks); Logger.EndPass(PassName.Translation); Logger.StartPass(PassName.RegisterUsage); RegisterUsage.RunPass(cfg, mode, isCompleteFunction: false); Logger.EndPass(PassName.RegisterUsage); OperandType[] argTypes = new OperandType[] { OperandType.I64 }; CompilerOptions options = highCq ? CompilerOptions.HighCq : CompilerOptions.None; GuestFunction func; if (Ptc.State == PtcState.Disabled) { func = Compiler.Compile <GuestFunction>(cfg, argTypes, OperandType.I64, options); } else { using (PtcInfo ptcInfo = new PtcInfo()) { func = Compiler.Compile <GuestFunction>(cfg, argTypes, OperandType.I64, options, ptcInfo); Ptc.WriteInfoCodeReloc((long)address, highCq, ptcInfo); } } ResetOperandPool(highCq); ResetOperationPool(highCq); return(new TranslatedFunction(func, highCq)); }
public static T Compile <T>( ControlFlowGraph cfg, OperandType[] argTypes, OperandType retType, CompilerOptions options, PtcInfo ptcInfo = null) { CompiledFunction func = Compile(cfg, argTypes, retType, options, ptcInfo); IntPtr codePtr = JitCache.Map(func); return(Marshal.GetDelegateForFunctionPointer <T>(codePtr)); }
public CodeGenContext(Stream stream, AllocationResult allocResult, int maxCallArgs, int blocksCount, PtcInfo ptcInfo = null) { _stream = stream; AllocResult = allocResult; Assembler = new Assembler(stream, ptcInfo); CallArgsRegionSize = GetCallArgsRegionSize(allocResult, maxCallArgs, out int xmmSaveRegionSize); XmmSaveRegionSize = xmmSaveRegionSize; _blockOffsets = new long[blocksCount]; _jumps = new List <Jump>(); _ptcInfo = ptcInfo; _ptcDisabled = ptcInfo == null; }