public DynarecFunction CreateFunction( IInstructionReader instructionReader, uint pc, Action <uint> exploreNewPcCallback = null, bool doDebug = false, bool doLog = false, bool checkValidAddress = true ) { switch (pc) { case SpecialCpu.ReturnFromFunction: return(new DynarecFunction() { AstNode = new AstNodeStmEmpty(), EntryPc = pc, Name = "SpecialCpu.ReturnFromFunction", InstructionStats = new Dictionary <string, uint>(), Delegate = cpuThreadState => { if (cpuThreadState == null) { return; } throw new SpecialCpu.ReturnFromFunctionException(); } }); default: var mipsMethodEmiter = new MipsMethodEmitter(CpuProcessor, pc, doDebug, doLog); var internalFunctionCompiler = new InternalFunctionCompiler(InjectContext, mipsMethodEmiter, this, instructionReader, exploreNewPcCallback, pc, doLog, checkValidAddress: checkValidAddress); return(internalFunctionCompiler.CreateFunction()); } }
internal InternalFunctionCompiler(InjectContext injectContext, MipsMethodEmitter mipsMethodEmitter, DynarecFunctionCompiler dynarecFunctionCompiler, IInstructionReader instructionReader, Action <uint> exploreNewPcCallback, uint entryPc, bool doLog, bool checkValidAddress = true) { injectContext.InjectDependencesTo(this); _exploreNewPcCallback = exploreNewPcCallback; _mipsMethodEmitter = mipsMethodEmitter; _cpuEmitter = new CpuEmitter(injectContext, mipsMethodEmitter, instructionReader); _globalInstructionStats = _cpuProcessor.GlobalInstructionStats; //this.InstructionStats = MipsMethodEmitter.InstructionStats; _instructionStats = new Dictionary <string, uint>(); _newInstruction = new Dictionary <string, bool>(); _doLog = doLog; _dynarecFunctionCompiler = dynarecFunctionCompiler; _instructionReader = instructionReader; _entryPc = entryPc; if (checkValidAddress && !PspMemory.IsAddressValid(entryPc)) { throw new InvalidOperationException($"Trying to get invalid function 0x{entryPc:X8}"); } }