private static string ToPTX(this ControlFlowInstruction cfi, BasicBlock following) { JumpInstruction jump = cfi as JumpInstruction; JumpIfInstruction jumpif = cfi as JumpIfInstruction; switch (cfi.OpCode) { case IROpCodes.JMP: return(jump.Target == following ? "" : "bra.uni " + jump.Target.Label + ";\n"); case IROpCodes.JT: return("setp.ne." + jumpif.Flag.DataType.ToPTX() + " %p, 0, " + jumpif.Flag + ";\n" + "@%p bra.uni " + jump.Target.Label + ";\n" + (jumpif.Next == following ? "" : "bra.uni " + jumpif.Next.Label + ";\n")); case IROpCodes.JF: return("setp.eq." + jumpif.Flag.DataType.ToPTX() + " %p, 0, " + jumpif.Flag + ";\n" + "@%p bra.uni " + jump.Target.Label + ";\n" + (jumpif.Next == following ? "" : "bra.uni " + jumpif.Next.Label + ";\n")); case IROpCodes.RET: return("ret;\n"); default: throw new NotSupportedException(cfi.OpCode.ToString()); } }
public void ConstructorTest() { JumpInstruction target = new JumpInstruction(); // TODO: Implement code to verify target Assert.Inconclusive("TODO: Implement code to verify target"); }
private void ProcessJumpOperation(JumpInstruction instruction, ref long instructionPointer, long[] memory) { var value = GetParameterValue(instruction.Value, memory); bool setInstructionPointer; switch (instruction.OpCode) { case OpCode.JumpIfTrue: setInstructionPointer = value != 0; break; case OpCode.JumpIfFalse: setInstructionPointer = value == 0; break; default: throw new ArgumentOutOfRangeException(nameof(instruction.OpCode)); } if (setInstructionPointer) { instructionPointer = GetParameterValue(instruction.InstructionPointer, memory); } else { instructionPointer += 3; } }
private void GetTernaryExpression() { GetUnaryExpression(); if (_lexer.LookAheadToken().Type == Token.EType.QUESTIONMARK) { var trueBlock = new InstructionBlock(); var falseBlock = new InstructionBlock(); var exitBlock = new InstructionBlock(); var exitJump = new JumpInstruction(exitBlock); var conditionalJump = new ConditionalJumpInstruction(trueBlock, falseBlock); _compilerEnvironment.AddInstruction(conditionalJump); _lexer.Expect(Token.EType.QUESTIONMARK); _compilerEnvironment.SetCurrentBlock(trueBlock); GetUnaryExpression(); _compilerEnvironment.AddInstruction(exitJump); _lexer.Expect(Token.EType.COLON); _compilerEnvironment.SetCurrentBlock(falseBlock); GetUnaryExpression(); _compilerEnvironment.AddInstruction(exitJump); _compilerEnvironment.SetCurrentBlock(exitBlock); } }
public void Execute_Quits() { var eof = new JumpInstruction(); eof.Execute(ExecutionEnvironment); Assert.That(ExecutionEnvironment.Terminated, Is.True); }
private bool ExecuteInstruction(JumpInstruction instruction) { if (instruction.CompareValue > 0) { index += instruction.JumpValue - 1; } return(true); }
public void ConstructorTest1() { int target_target1 = 0; // TODO: Initialize to an appropriate value JumpInstruction target2 = new JumpInstruction(target_target1); // TODO: Implement code to verify target Assert.Inconclusive("TODO: Implement code to verify target"); }
public void AcceptTest() { JumpInstruction target = new JumpInstruction(); IVisitor visitor = null; // TODO: Initialize to an appropriate value target.Accept(visitor); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public void ResultShouldBe(string input, string target, string source, JumpInstruction.Operations operation, JumpInstruction.Conditions condition, int operationValue, int conditionValue) { var result = JumpInstruction.Parse(input); Assert.AreEqual(target, result.TargetRegister); Assert.AreEqual(source, result.ConditionRegister); Assert.AreEqual(operation, result.Operation); Assert.AreEqual(condition, result.Condition); Assert.AreEqual(operationValue, result.OperationValue); Assert.AreEqual(conditionValue, result.ConditionValue); }
public void TargetTest() { JumpInstruction target = new JumpInstruction(); int val = 0; // TODO: Assign to an appropriate value for the property target.Target = val; Assert.AreEqual(val, target.Target, "Composestar.StarLight.Entities.WeaveSpec.Instructions.Jump.Target was not set cor" + "rectly."); Assert.Inconclusive("Verify the correctness of this test method."); }
public void move_by_jump_amount_when_integer() { var nonZeroNumber = Any.NonZeroNumber(); var jumpDistance = Any.JumpDistance(); var computer = new MockComputerBuilder() .Build(); var initialPosition = computer[AdventOfCodeLibrary.Instructions.Computer.InstructionPointer]; var instruction = new JumpInstruction(1, jumpDistance); instruction.Execute(computer); Assert.AreEqual(initialPosition + jumpDistance - 1, computer[AdventOfCodeLibrary.Instructions.Computer.InstructionPointer]); }
public void JumpTest(int programCounterInitial, int address) { var instruction = new JumpInstruction(); var instructionModel = new InstructionModel() { Type = instruction.Type, Data = address, }; var context = new InstructionExecutionContext(new bool[0], programCounterInitial, instructionModel); var result = instruction.Execute(context); Assert.Equal(address, result.ProgramCounter); }
public void stay_for_zero_value_registry() { var register = Any.Register(); var jumpDistance = Any.JumpDistance(); AdventOfCodeLibrary.Instructions.Computer computer = new MockComputerBuilder() .WithDefaultRegisterValue(register, 0) .Build(); var initialPosition = computer[AdventOfCodeLibrary.Instructions.Computer.InstructionPointer]; var instruction = new JumpInstruction(register, jumpDistance); instruction.Execute(computer); Assert.AreEqual(initialPosition, computer[AdventOfCodeLibrary.Instructions.Computer.InstructionPointer]); }
public void move_by_jump_amount_when_register_non_zero() { var register = Any.Register(); var registerValue = Any.RegisterValue() + 1; var jumpDistance = Any.JumpDistance(); AdventOfCodeLibrary.Instructions.Computer computer = new MockComputerBuilder() .WithDefaultRegisterValue(register, registerValue) .Build(); var initialPosition = computer[AdventOfCodeLibrary.Instructions.Computer.InstructionPointer]; var instruction = new JumpInstruction(register, jumpDistance); instruction.Execute(computer); Assert.AreEqual(initialPosition + jumpDistance - 1, computer[AdventOfCodeLibrary.Instructions.Computer.InstructionPointer]); }
public void execute_all_with_jump() { var instructions = new IInstruction[6]; instructions[0] = new CopyValueToRegisterInstruction('a', 41); instructions[1] = new IncrementInstruction('a'); instructions[2] = new IncrementInstruction('a'); instructions[3] = new DecrementInstruction('a'); instructions[4] = new JumpInstruction('a', 2); instructions[5] = new DecrementInstruction('a'); var computer = new MockComputerBuilder() .WithInstructions(instructions) .Build(); computer.ExecuteAll(); Assert.AreEqual(42, computer['a']); }
public override Address GenerateCode(List <Instruction> instructions) { Condition.GenerateCode(instructions); Label trueLabel = new Label(); instructions.Add(new LabelInstruction(trueLabel)); IfBody.GenerateCode(instructions); JumpInstruction doneJump = new JumpInstruction(null); NextInstructionsToBackpatch.Add(doneJump); instructions.Add(doneJump); Label falseLabel = new Label(); instructions.Add(new LabelInstruction(falseLabel)); ElseBody.GenerateCode(instructions); ElseBody.NextInstructionsToBackpatch.AddRange(NextInstructionsToBackpatch); Condition.Backpatch(trueLabel, falseLabel); return(base.GenerateCode(instructions)); }
public void JumpInstruction__Largest(string[] input, int expectedResult) { JumpInstruction jumpInstruction = new JumpInstruction(input); Assert.Equal(expectedResult, jumpInstruction.CalcLargest()); }
public void SetupBase() { Result = JumpInstruction.Parse(Instruction); }
public virtual void VisitJumpInstruction(JumpInstruction instruction) { DefaultVisitInstruction(instruction); }