public override T Execute <T>(params object[] args) { bool showGui = this.ShowGUI; SPEEmulator.SPEProcessor spe; SPEEmulatorTestApp.Simulator sx = null; if (showGui) { // Run program sx = new SPEEmulatorTestApp.Simulator(new string[] { m_elf }); sx.StartAndPause(); spe = sx.SPE; } else { spe = new SPEEmulator.SPEProcessor(); spe.LoadELF(m_elf); m_workingEvent = new System.Threading.ManualResetEvent(false); } SPEEmulator.EndianBitConverter conv = new SPEEmulator.EndianBitConverter(spe.LS); SPEObjectManager manager = new SPEObjectManager(conv); Dictionary <uint, int> transferedObjects = base.LoadInitialArguments(conv, manager, args); spe.RegisterCallbackHandler(SPEJITCompiler.STOP_METHOD_CALL & 0xff, spe_callback); if (showGui) { System.Windows.Forms.Application.Run(sx); } else { m_exitCode = 0; m_workingEvent.Reset(); spe.SPEStopped += new SPEEmulator.StatusEventDelegate(spe_SPEStopped); spe.Exit += new SPEEmulator.ExitEventDelegate(spe_Exit); spe.Start(); m_workingEvent.WaitOne(); spe.SPEStopped -= new SPEEmulator.StatusEventDelegate(spe_SPEStopped); spe.Exit -= new SPEEmulator.ExitEventDelegate(spe_Exit); Console.WriteLine("Executed {0} instructions while running function {1}", spe.SPU.InstructionsExecuted, m_loadedMethod.DeclaringType.FullName + "::" + m_loadedMethod.Name); if (m_exitCode != SPEJITCompiler.STOP_SUCCESSFULL) { throw new Exception("Invalid exitcode: " + m_exitCode); } } spe.UnregisterCallbackHandler(SPEJITCompiler.STOP_METHOD_CALL & 0xff); return(base.FinalizeAndReturn <T>(conv, manager, transferedObjects, args)); }
void spe_SPEStopped(SPEEmulator.SPEProcessor sender) { m_workingEvent.Set(); }
void spe_Exit(SPEEmulator.SPEProcessor sender, uint exitcode) { m_exitCode = exitcode; }