def test_memory_reference_unpacking(): p = Program() p.inst( AND("ro", ("ro", 1)), MOVE("ro", ("ro", 1)), CONVERT("ro", ("ro", 1)), IOR("ro", ("ro", 1)), XOR("ro", ("ro", 1)), ADD("ro", ("ro", 1)), SUB("ro", ("ro", 1)), MUL("ro", ("ro", 1)), DIV("ro", ("ro", 1)), EXCHANGE("ro", ("ro", 1)), ) assert (p.out() == "AND ro[0] ro[1]\n" "MOVE ro[0] ro[1]\n" "CONVERT ro[0] ro[1]\n" "IOR ro[0] ro[1]\n" "XOR ro[0] ro[1]\n" "ADD ro[0] ro[1]\n" "SUB ro[0] ro[1]\n" "MUL ro[0] ro[1]\n" "DIV ro[0] ro[1]\n" "EXCHANGE ro[0] ro[1]\n")
def test_binary_classicals(): p = Program() # OR is deprecated in favor of IOR with pytest.warns(UserWarning): p.inst(OR(MemoryReference("ro", 1), MemoryReference("ro", 0))) p.inst( AND(MemoryReference("ro", 0), MemoryReference("ro", 1)), MOVE(MemoryReference("ro", 0), MemoryReference("ro", 1)), CONVERT(MemoryReference("ro", 0), MemoryReference("ro", 1)), IOR(MemoryReference("ro", 0), MemoryReference("ro", 1)), XOR(MemoryReference("ro", 0), MemoryReference("ro", 1)), ADD(MemoryReference("ro", 0), MemoryReference("ro", 1)), SUB(MemoryReference("ro", 0), MemoryReference("ro", 1)), MUL(MemoryReference("ro", 0), MemoryReference("ro", 1)), DIV(MemoryReference("ro", 0), MemoryReference("ro", 1)), EXCHANGE(MemoryReference("ro", 0), MemoryReference("ro", 1)), ) assert (p.out() == "IOR ro[0] ro[1]\n" "AND ro[0] ro[1]\n" "MOVE ro[0] ro[1]\n" "CONVERT ro[0] ro[1]\n" "IOR ro[0] ro[1]\n" "XOR ro[0] ro[1]\n" "ADD ro[0] ro[1]\n" "SUB ro[0] ro[1]\n" "MUL ro[0] ro[1]\n" "DIV ro[0] ro[1]\n" "EXCHANGE ro[0] ro[1]\n")
def test_classical(): parse_equals("MOVE ro[0] 1", MOVE(MemoryReference("ro", 0), 1)) parse_equals("MOVE ro[0] 0", MOVE(MemoryReference("ro", 0), 0)) parse_equals("NOT ro[0]", NOT(MemoryReference("ro", 0))) parse_equals("AND ro[0] 1", AND(MemoryReference("ro", 0), 1)) parse_equals("IOR ro[0] 1", IOR(MemoryReference("ro", 0), 1)) parse_equals("MOVE ro[0] 1", MOVE(MemoryReference("ro", 0), 1)) parse_equals("XOR ro[0] 1", XOR(MemoryReference("ro", 0), 1)) parse_equals("ADD mem[0] 1.2", ADD(MemoryReference("mem", 0), 1.2)) parse_equals("SUB mem[0] 1.2", SUB(MemoryReference("mem", 0), 1.2)) parse_equals("MUL mem[0] 1.2", MUL(MemoryReference("mem", 0), 1.2)) parse_equals("DIV mem[0] 1.2", DIV(MemoryReference("mem", 0), 1.2)) parse_equals("ADD mem[0] -1.2", ADD(MemoryReference("mem", 0), -1.2)) parse_equals("SUB mem[0] -1.2", SUB(MemoryReference("mem", 0), -1.2)) parse_equals("MUL mem[0] -1.2", MUL(MemoryReference("mem", 0), -1.2)) parse_equals("DIV mem[0] -1.2", DIV(MemoryReference("mem", 0), -1.2)) parse_equals( "EQ comp[1] ro[3] ro[2]", EQ(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "LT comp[1] ro[3] ro[2]", LT(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "LE comp[1] ro[3] ro[2]", LE(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "GT comp[1] ro[3] ro[2]", GT(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "GE comp[1] ro[3] ro[2]", GE(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals("EQ comp[1] ro[3] 0", EQ(MemoryReference("comp", 1), MemoryReference("ro", 3), 0)) parse_equals("LT comp[1] ro[3] 1", LT(MemoryReference("comp", 1), MemoryReference("ro", 3), 1)) parse_equals("LE comp[1] ro[3] 2", LE(MemoryReference("comp", 1), MemoryReference("ro", 3), 2)) parse_equals("GT comp[1] ro[3] 3", GT(MemoryReference("comp", 1), MemoryReference("ro", 3), 3)) parse_equals("GE comp[1] ro[3] 4", GE(MemoryReference("comp", 1), MemoryReference("ro", 3), 4)) parse_equals( "EQ comp[1] ro[3] 0.0", EQ(MemoryReference("comp", 1), MemoryReference("ro", 3), 0.0) ) parse_equals( "LT comp[1] ro[3] 1.1", LT(MemoryReference("comp", 1), MemoryReference("ro", 3), 1.1) ) parse_equals( "LE comp[1] ro[3] 2.2", LE(MemoryReference("comp", 1), MemoryReference("ro", 3), 2.2) ) parse_equals( "GT comp[1] ro[3] 3.3", GT(MemoryReference("comp", 1), MemoryReference("ro", 3), 3.3) ) parse_equals( "GE comp[1] ro[3] 4.4", GE(MemoryReference("comp", 1), MemoryReference("ro", 3), 4.4) )
def test_binary_classicals(): p = Program() p.inst(AND(Addr(0), Addr(1)), OR(Addr(1), Addr(0)), MOVE(Addr(0), Addr(1)), CONVERT(Addr(0), Addr(1)), IOR(Addr(0), Addr(1)), XOR(Addr(0), Addr(1)), ADD(Addr(0), Addr(1)), SUB(Addr(0), Addr(1)), MUL(Addr(0), Addr(1)), DIV(Addr(0), Addr(1)), EXCHANGE(Addr(0), Addr(1))) assert p.out() == 'AND ro[0] ro[1]\n' \ 'IOR ro[0] ro[1]\n' \ 'MOVE ro[0] ro[1]\n' \ 'CONVERT ro[0] ro[1]\n' \ 'IOR ro[0] ro[1]\n' \ 'XOR ro[0] ro[1]\n' \ 'ADD ro[0] ro[1]\n' \ 'SUB ro[0] ro[1]\n'\ 'MUL ro[0] ro[1]\n' \ 'DIV ro[0] ro[1]\n' \ 'EXCHANGE ro[0] ro[1]\n'
def test_memory_reference_unpacking(): p = Program() p.inst(AND("ro", ("ro", 1)), MOVE("ro", ("ro", 1)), CONVERT("ro", ("ro", 1)), IOR("ro", ("ro", 1)), XOR("ro", ("ro", 1)), ADD("ro", ("ro", 1)), SUB("ro", ("ro", 1)), MUL("ro", ("ro", 1)), DIV("ro", ("ro", 1)), EXCHANGE("ro", ("ro", 1))) assert p.out() == 'AND ro[0] ro[1]\n' \ 'MOVE ro[0] ro[1]\n' \ 'CONVERT ro[0] ro[1]\n' \ 'IOR ro[0] ro[1]\n' \ 'XOR ro[0] ro[1]\n' \ 'ADD ro[0] ro[1]\n' \ 'SUB ro[0] ro[1]\n'\ 'MUL ro[0] ro[1]\n' \ 'DIV ro[0] ro[1]\n' \ 'EXCHANGE ro[0] ro[1]\n'
def test_binary_classicals(): p = Program() p.inst(AND(MemoryReference("ro", 0), MemoryReference("ro", 1)), OR(MemoryReference("ro", 1), MemoryReference("ro", 0)), MOVE(MemoryReference("ro", 0), MemoryReference("ro", 1)), CONVERT(MemoryReference("ro", 0), MemoryReference("ro", 1)), IOR(MemoryReference("ro", 0), MemoryReference("ro", 1)), XOR(MemoryReference("ro", 0), MemoryReference("ro", 1)), ADD(MemoryReference("ro", 0), MemoryReference("ro", 1)), SUB(MemoryReference("ro", 0), MemoryReference("ro", 1)), MUL(MemoryReference("ro", 0), MemoryReference("ro", 1)), DIV(MemoryReference("ro", 0), MemoryReference("ro", 1)), EXCHANGE(MemoryReference("ro", 0), MemoryReference("ro", 1))) assert p.out() == 'AND ro[0] ro[1]\n' \ 'IOR ro[0] ro[1]\n' \ 'MOVE ro[0] ro[1]\n' \ 'CONVERT ro[0] ro[1]\n' \ 'IOR ro[0] ro[1]\n' \ 'XOR ro[0] ro[1]\n' \ 'ADD ro[0] ro[1]\n' \ 'SUB ro[0] ro[1]\n'\ 'MUL ro[0] ro[1]\n' \ 'DIV ro[0] ro[1]\n' \ 'EXCHANGE ro[0] ro[1]\n'