Example #1
0
def _(operand):
    """Parse an immediate operand.

    Immediate operands are simple values such as 0, 0x10, or 0b10101010, or an expression evaluating
    to such a value, such as ord("A").
    """
    return Immediate(operand)
Example #2
0
def _(operand):
    try:
        byte = single(operand)
    except ValueError as ve:
        raise ValueError(
            "Immediate8 string operand must contain an single ASCII character. Got {} in {!r}"
            .format(len(operand), operand)) from ve

    return Immediate(byte)
Example #3
0
def test_immediate_hash(a):
    assert hash(Immediate(a)) == hash(Immediate(a))
Example #4
0
def test_immediate_inequality_different_types(a):
    assert Immediate(a) != object()
Example #5
0
def test_immediate_inequality(a, b):
    assume(a != b)
    assert Immediate(a) != Immediate(b)
Example #6
0
def test_immediate_equality(a):
    assert Immediate(a) == Immediate(a)
Example #7
0
def test_bytes_operand_gives_immediate_value(b):
    assert parse_operand(b) == Immediate(b[0], 1)
Example #8
0
def _(operand):
    unsigned = operand.value.to_bytes(2, byteorder="big", signed=True)
    return Immediate(int.from_bytes(unsigned, byteorder="big", signed=False),
                     2)
Example #9
0
def _(operand):
    return Immediate(operand)
Example #10
0
def test_i16_operand():
    assert parse_operand(I16(-4567)) == Immediate(60969, 2)
Example #11
0
def test_i32_operand():
    assert parse_operand(I32(0x45671234)) == Immediate(0x45671234, 4)
Example #12
0
def test_i8_operand():
    assert parse_operand(I8(-42)) == Immediate(214, 1)
Example #13
0
def test_u16_operand():
    assert parse_operand(U16(0x4567)) == Immediate(0x4567, 2)
Example #14
0
def test_u8_operand():
    assert parse_operand(U8(42)) == Immediate(42, 1)
Example #15
0
def _(operand):
    return Immediate(int.from_bytes(operand, byteorder="big", signed=False),
                     len(operand))
Example #16
0
def test_immediate_value(a):
    assert Immediate(a).value == a
Example #17
0
def _(operand):
    return Immediate(operand.value, 4)
Example #18
0
def test_immediate_repr(a):
    r = repr(Immediate(a))
    assert r.startswith('Immediate')
    assert str(a) in r
    assert check_balanced(r)
Example #19
0
def _(operand):
    return Immediate(
        int.from_bytes(operand.value.to_bytes(4, byteorder="big", signed=True),
                       byteorder="big",
                       signed=False), 4)
Example #20
0
def test_immediate_address_assembly():
    asm = AsmDsl()
    asm(LDA, 0x30)
    assert statements(asm) == (LdA(Immediate(0x30)), )