http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html
Example #1
0
 public CpuEmitter(InjectContext injectContext, MipsMethodEmitter mipsMethodEmitter,
                   IInstructionReader instructionReader)
 {
     injectContext.InjectDependencesTo(this);
     _mipsMethodEmitter = mipsMethodEmitter;
     _instructionReader = instructionReader;
 }
			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;
		}
            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)));
                }
            }
 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();
     }
 }
Example #6
0
 public CpuEmitter(InjectContext InjectContext, MipsMethodEmitter MipsMethodEmitter, IInstructionReader InstructionReader)
 {
     InjectContext.InjectDependencesTo(this);
     this.MipsMethodEmitter = MipsMethodEmitter;
     this.InstructionReader = InstructionReader;
 }