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()); } }
public CpuEmitter(InjectContext injectContext, MipsMethodEmitter mipsMethodEmitter, IInstructionReader instructionReader) { injectContext.InjectDependencesTo(this); _mipsMethodEmitter = mipsMethodEmitter; _instructionReader = instructionReader; }
public override InstructionStream Mount(IInstructionReader instructionReader, Automata <Lexeme <TToken>, TToken> automata) { var instructionQueue = base.Mount(instructionReader, automata); _instructionReaderPosition = SeekableInstructionReader.Position; return(instructionQueue); }
public override void InitializeComponent() { InstructionReader = new InstructionStreamReader(new PspMemoryStream(PspMemory)); ProcessThread = new Thread(ProcessMain); ProcessThread.Name = "DynarecFunctionCompilerTaskThread"; ProcessThread.IsBackground = true; ProcessThread.Start(); MethodCacheFast.OnClearRange += new Action<uint, uint>(MethodCacheFast_OnClearRange); }
public virtual InstructionStream Mount(IInstructionReader instructionReader, Automata <TInstruction, TOperand> automata) { //Pages = ArrayPool<InstructionPage>.Shared.Rent(PageCapacity); ArrayUtils.Fill(Pages, NullPage); InstructionReader = instructionReader; MountParallel(automata); return(this); }
internal InternalFunctionCompiler(CpuProcessor CpuProcessor, MipsMethodEmitter MipsMethodEmiter, DynarecFunctionCompiler DynarecFunctionCompiler, IInstructionReader InstructionReader, Action<uint> _ExploreNewPcCallback, uint EntryPC, bool DoLog) { this._ExploreNewPcCallback = _ExploreNewPcCallback; this.CpuEmitter = new CpuEmitter(MipsMethodEmiter, InstructionReader, CpuProcessor); this.MipsMethodEmitter = MipsMethodEmiter; this.GlobalInstructionStats = CpuProcessor.GlobalInstructionStats; this.InstructionStats = MipsMethodEmiter.InstructionStats; this.NewInstruction = new Dictionary<string, bool>(); this.DoLog = DoLog; this.CpuProcessor = CpuProcessor; this.DynarecFunctionCompiler = DynarecFunctionCompiler; this.InstructionReader = InstructionReader; this.EntryPC = EntryPC; }
public DynarecFunction CreateFunction(IInstructionReader InstructionReader, uint PC, Action<uint> ExploreNewPcCallback = null, bool DoDebug = false, bool DoLog = false) { DynarecFunction DynarecFunction; //var Stopwatch = new Logger.Stopwatch(); //Stopwatch.Tick(); var MipsMethodEmiter = new MipsMethodEmitter(CpuProcessor, PC, DoDebug, DoLog); var InternalFunctionCompiler = new InternalFunctionCompiler(CpuProcessor, MipsMethodEmiter, this, InstructionReader, ExploreNewPcCallback, PC, DoLog); DynarecFunction = InternalFunctionCompiler.CreateFunction(); //Stopwatch.Tick(); //Console.WriteLine("Function at PC 0x{0:X} generated in {1}", PC, Stopwatch); return DynarecFunction; }
protected override void OnReleased() { CleanPages(); DisposeParallel(); InstructionReader.Dispose(); //ArrayPool<InstructionPage>.Shared.Return(Pages, true); //Pages = null; HeadPage = 0; PageCount = 0; Finished = false; Exception = null; StartPosition = 0; InstructionReader = null; StartInstructionPointer = 0; NullPage.ReferenceCount = int.MaxValue; base.OnReleased(); }
internal InternalFunctionCompiler(InjectContext InjectContext, MipsMethodEmitter MipsMethodEmitter, DynarecFunctionCompiler DynarecFunctionCompiler, IInstructionReader InstructionReader, Action<uint> _ExploreNewPcCallback, uint EntryPC, bool DoLog) { InjectContext.InjectDependencesTo(this); this._ExploreNewPcCallback = _ExploreNewPcCallback; this.MipsMethodEmitter = MipsMethodEmitter; this.CpuEmitter = new CpuEmitter(InjectContext, MipsMethodEmitter, InstructionReader); this.GlobalInstructionStats = CpuProcessor.GlobalInstructionStats; //this.InstructionStats = MipsMethodEmitter.InstructionStats; this.InstructionStats = new Dictionary<string, uint>(); this.NewInstruction = new Dictionary<string, bool>(); this.DoLog = DoLog; this.DynarecFunctionCompiler = DynarecFunctionCompiler; this.InstructionReader = InstructionReader; this.EntryPC = EntryPC; if (!PspMemory.IsAddressValid(EntryPC)) { throw (new InvalidOperationException(String.Format("Trying to get invalid function 0x{0:X8}", EntryPC))); } }
internal void Initialize(IInstructionReader instructionReader, AutomataContext context) { if (ReferenceEquals(context.ProcessField, DummyProcess) == false) { throw new InvalidOperationException("Context is busy"); } _processResources = ProcessResources.ThreadLocalInstance.Value; _executionPathQueueBuilder = _processResources.ExecutionPathGroupBuilderPool.Get().AddReference(); _parallelThreads = _processResources.ThreadListPool.Get().AddReference(); _executionMethods = _automata.GetExecutionMethods(context); Context = context; Context.ProcessField = this; var entryPoint = context.EntryPoint; if (!(entryPoint is FiniteState state)) { return; } var instructionQueue = _processResources.InstructionQueuePool.Get().Mount(instructionReader, _automata); _entryPointSubGraph = _automata.EnsureSubGraph(state); var initNode = _entryPointSubGraph.InitNode; if (initNode.Safe == false) { initNode.MakeSafe(); } _currentThread = new Thread(initNode, instructionQueue, context.CreateContextStateInternal()) { Stack = _processResources.StackPool.Get().AddReference(), ExecutionQueue = _processResources.ExecutionPathPool.Get().AddReference(), PredicateResultQueue = _processResources.PredicateResultPool.Get().AddReference() }; }
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}"); } }
public DynarecFunction CreateFunction(IInstructionReader InstructionReader, uint PC, Action<uint> ExploreNewPcCallback = null, bool DoDebug = false, bool DoLog = false) { 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); return InternalFunctionCompiler.CreateFunction(); } }
public CentralProcessingUnit(IArithmeticLogicUnit arithmeticLogicUnit, IInstructionParser parser, IInstructionReader reader) { ALU = arithmeticLogicUnit; Parser = parser; Reader = reader; }
public CpuEmitter(InjectContext InjectContext, MipsMethodEmitter MipsMethodEmitter, IInstructionReader InstructionReader) { InjectContext.InjectDependencesTo(this); this.MipsMethodEmitter = MipsMethodEmitter; this.InstructionReader = InstructionReader; }
public CpuEmiter(MipsMethodEmiter MipsMethodEmiter, IInstructionReader InstructionReader, CpuProcessor CpuProcessor) { this.MipsMethodEmiter = MipsMethodEmiter; this.InstructionReader = InstructionReader; this.CpuProcessor = CpuProcessor; }
public override void InitializeComponent() { InstructionReader = new InstructionStreamReader(new PspMemoryStream(PspMemory)); MethodCacheFast.OnClearRange += new Action<uint, uint>(MethodCacheFast_OnClearRange); }