public void TestFullJit3() { VirtualMachine virtualMachine = new VirtualMachine(); int value = 1000; virtualMachine.SetRegisterValue(Registers.R1, value); Program testProgram = NiosAssembler.New().AssembleFromLines( "start: call dec", "call body", "bne r0, r1, start", "body: addi r2, r2, 1", "ret", "dec: addi r1, r1, -1", "ret"); FullJITCompiler jitCompiler = new FullJITCompiler(virtualMachine); Instruction[] funcBody = testProgram.GetInstructions(); var jittedProgram = jitCompiler.GenerateProgram( "test_program", funcBody, testProgram.FunctionTable); jitCompiler.RunJittedProgram(jittedProgram); Assert.AreEqual(virtualMachine.GetRegisterValue(Registers.R1), 0); Assert.AreEqual(virtualMachine.GetRegisterValue(Registers.R2), value); }
private MethodInfo CreateProgram(params Instruction[] funcBody) { return(jitCompiler.GenerateProgram( "test_program", funcBody, new Dictionary <uint, int>())); }
public void TestFullJit2() { VirtualMachine virtualMachine = new VirtualMachine(); int value = 15464; int value2 = 435351; uint memAddr = 1024; virtualMachine.SetRegisterValue(Registers.R1, (int)memAddr); virtualMachine.WriteWordToMemory(memAddr, value); virtualMachine.SetRegisterValue(Registers.R3, value2); Program testProgram = NiosAssembler.New().AssembleFromLines( "ldw r2, 0(r1)", "stw r3, 0(r1)"); FullJITCompiler jitCompiler = new FullJITCompiler(virtualMachine); Instruction[] funcBody = testProgram.GetInstructions(); var jittedProgram = jitCompiler.GenerateProgram( "test_program", funcBody, testProgram.FunctionTable); jitCompiler.RunJittedProgram(jittedProgram); Assert.AreEqual(value, virtualMachine.GetRegisterValue(Registers.R2)); Assert.AreEqual(value2, virtualMachine.ReadWordFromMemory(memAddr)); }