public MethodCacheInfo GetForPC(uint PC) { if (MethodMapping.ContainsKey(PC)) { return MethodMapping[PC]; } else { return MethodMapping[PC] = new MethodCacheInfo() { MethodCache = this, StaticField = ILInstanceHolder.TAlloc<Action<CpuThreadState>>(GetGeneratorForPC(PC)), }; } }
public MethodCacheInfo GetForPc(uint pc) { if (_methodMapping.ContainsKey(pc)) { return(_methodMapping[pc]); } else { var delegateGeneratorForPc = GeneratorIlInstance.GenerateDelegate <Action <CpuThreadState> >( "MethodCache.DynamicCreateNewFunction", Ast.Statements( Ast.Statement(Ast.CallInstance(Ast.CpuThreadStateExpr, (Action <MethodCacheInfo, uint>)CpuThreadState.Methods._MethodCacheInfo_SetInternal, Ast.GetMethodCacheInfoAtPc(pc), pc)), Ast.Statement(Ast.TailCall(Ast.CallInstance(Ast.GetMethodCacheInfoAtPc(pc), (Action <CpuThreadState>)MethodCacheInfo.Methods.CallDelegate, Ast.CpuThreadStateExpr))), Ast.Return() )); return(_methodMapping[pc] = new MethodCacheInfo(this, delegateGeneratorForPc, pc)); } }
public void _MethodCacheInfo_SetInternal(CpuThreadState cpuThreadState, MethodCacheInfo methodCacheInfo, uint pc) { methodCacheInfo.SetDynarecFunction(_methodCompilerThread.GetDynarecFunctionForPc(pc)); }
internal void Free(MethodCacheInfo methodCacheInfo) => _methodMapping.Remove(methodCacheInfo.EntryPc);
/// <summary> /// /// </summary> /// <param name="PC"></param> /// <returns></returns> public MethodCacheInfo GetForPC(uint PC) { if (MethodMapping.ContainsKey(PC)) { return MethodMapping[PC]; } else { var DelegateGeneratorForPC = GeneratorILInstance.GenerateDelegate<Action<CpuThreadState>>("MethodCache.DynamicCreateNewFunction", ast.Statements( ast.Statement(ast.CallInstance(ast.CpuThreadState, (Action<MethodCacheInfo, uint>)CpuThreadState.Methods._MethodCacheInfo_SetInternal, ast.GetMethodCacheInfoAtPC(PC), PC)), ast.Statement(ast.TailCall(ast.CallInstance(ast.GetMethodCacheInfoAtPC(PC), (Action<CpuThreadState>)MethodCacheInfo.Methods.CallDelegate, ast.CpuThreadState))), ast.Return() )); return MethodMapping[PC] = new MethodCacheInfo(this, DelegateGeneratorForPC, PC); } }
internal void Free(MethodCacheInfo MethodCacheInfo) { MethodMapping.Remove(MethodCacheInfo.EntryPC); }
public void _MethodCacheInfo_SetInternal(CpuThreadState CpuThreadState, MethodCacheInfo MethodCacheInfo, uint PC) { MethodCacheInfo.SetDynarecFunction(MethodCompilerThread.GetDynarecFunctionForPC(PC)); }
public void _MethodCacheInfo_SetInternal(MethodCacheInfo MethodCacheInfo, uint PC) { Console.Write("Creating function for PC=0x{0:X8}...", PC); var Stopwatch = new Logger.Stopwatch(); var DynarecFunction = CpuProcessor.DynarecFunctionCompiler.CreateFunction(new InstructionStreamReader(new PspMemoryStream(Memory)), PC); if (DynarecFunction.EntryPC != PC) throw(new Exception("Unexpected error")); var AstGenerationTime = Stopwatch.Tick(); DynarecFunction.Delegate(null); var LinkingTime = Stopwatch.Tick(); Console.WriteLine("({0}): Ast: {1}ms, Link: {2}ms", (DynarecFunction.MaxPC - DynarecFunction.MinPC) / 4, (int)AstGenerationTime.TotalMilliseconds, (int)LinkingTime.TotalMilliseconds); //DynarecFunction.AstNode = DynarecFunction.AstNode.Optimize(CpuProcessor); #if DEBUG_FUNCTION_CREATION CpuProcessor.DebugFunctionCreation = true; #endif if (CpuProcessor.DebugFunctionCreation) { Console.WriteLine("-------------------------------------"); Console.WriteLine("Created function for PC=0x{0:X8}", PC); Console.WriteLine("-------------------------------------"); this.DumpRegistersCpu(Console.Out); Console.WriteLine("-------------------------------------"); Console.WriteLine(DynarecFunction.AstNode.ToCSharpString()); Console.WriteLine("-------------------------------------"); } MethodCacheInfo.AstTree = DynarecFunction.AstNode; MethodCacheInfo.StaticField.Value = DynarecFunction.Delegate; MethodCacheInfo.EntryPC = DynarecFunction.EntryPC; MethodCacheInfo.MinPC = DynarecFunction.MinPC; MethodCacheInfo.MaxPC = DynarecFunction.MaxPC; }
/// <summary> /// /// </summary> /// <param name="MethodCacheInfo"></param> /// <param name="PC"></param> public void _MethodCacheInfo_SetInternal(MethodCacheInfo MethodCacheInfo, uint PC) { MethodCache._MethodCacheInfo_SetInternal(this, MethodCacheInfo, PC); }