Beispiel #1
0
def test_multiple_lines():
    parse("""
; infinite loop
label:
always.jump label
    """)
    assert True
Beispiel #2
0
def test_multiple_lines2():
    parse("""
link sub
halt

sub:
jump
    """)
    assert True
Beispiel #3
0
        exit(1)


    if len(sys.argv) < 3:
        print ("FILE argument is missing")
        exit(2)

    if sys.argv[1] in ('run', 'load', 'disasm'):
        wc = load_hex(m, sys.argv[2])

    if sys.argv[1] == 'run':
        m.run()
        exit(0)

    if sys.argv[1] == 'asm':
        tokens = parse(open(sys.argv[2]).readlines())
        for token in tokens:
            print ('%04x' % token.asm(), end='')
        print ('')
        exit(0)

    if sys.argv[1] == 'disasm':
        while m.PC.get() < wc:
            try:
                # TODO: make this optional
                # print ("%04x: " % m.PC.get(), end='')
                w = m._fetch()
                insn = m._decode(w)
                print (insn)

            except InvalidInstruction:
Beispiel #4
0
def test_complete_line():
    res = parse("jump: always.jump jump ; jump")
    assert str(res[0]) == "Label: jump"
    assert str(res[1]) == "Instruction: always.jump jump"
Beispiel #5
0
def test_empty():
    parse("")
    assert True
Beispiel #6
0
def test_operand_hexadecimal():
    res = parse("jump deadbeefh")
    assert str(res[0]) == "Instruction: always.jump 3735928559"
Beispiel #7
0
def test_comment():
    res = parse("; foo")
    assert str(res[0]) == "Comment: foo"
Beispiel #8
0
def test_operand_octal():
    res = parse("jump 0770o")
    assert str(res[0]) == "Instruction: always.jump 504"
Beispiel #9
0
def test_operand_decimal():
    res = parse("jump -9999d")
    assert str(res[0]) == "Instruction: always.jump -9999"
Beispiel #10
0
def test_operand_binary():
    res = parse("jump 0101_0110b")
    assert str(res[0]) == "Instruction: always.jump 86"
Beispiel #11
0
def test_operand_label():
    res = parse("jump foo")
    assert str(res[0]) == "Instruction: always.jump foo"
Beispiel #12
0
def test_condition():
    res = parse("safe.halt")
    assert str(res[0]) == "Instruction: safe.halt"
Beispiel #13
0
def test_mnemonic():
    res = parse("halt")
    assert str(res[0]) == "Instruction: always.halt"
Beispiel #14
0
def test_label():
    res = parse("foo:")
    assert str(res[0]) == "Label: foo"