Beispiel #1
0
    def _emit(self, sa, sema_id):
        if not (0 <= sema_id and sema_id <= 15):
            raise AssembleError('Semaphore id must be in range (0..15)')

        null_addr = REGISTERS['null'].addr
        insn = enc.SemaInsn(
            sig=0xE, unpack=4, pm=0, pack=0, cond_add=1, cond_mul=1, sf=0,
            ws=0, waddr_add=null_addr, waddr_mul=null_addr, sa=sa,
            semaphore=sema_id)

        if self.asm.sanity_check:
            insn.verbose = SemaInstr(sa, sema_id)
        self.asm._emit(insn)
    waddr_add=53, waddr_mul=12, op_mul=4, op_add=2, raddr_a=33, raddr_b=53,
    add_a=4, add_b=7, mul_a=6, mul_b=2
    )

SAMPLE_BRANCH_INSN = enc.BranchInsn(
    sig=0xf, cond_br=13, rel=1, reg=0, raddr_a=27, ws=1, waddr_add=53,
    waddr_mul=12, immediate=0x12345678
    )

SAMPLE_LOAD_INSN = enc.LoadInsn(
    sig=0xe, unpack=1, pm=1, pack=2, cond_add=3, cond_mul=4, sf=1, ws=1,
    waddr_add=53, waddr_mul=12, immediate=0x12345678
    )

SAMPLE_SEMA_INSN = enc.SemaInsn(
    sig=0xe, unpack=4, pm=1, pack=2, cond_add=3, cond_mul=4, sf=1, ws=1,
    waddr_add=53, waddr_mul=12, sa=1, semaphore=13
    )

def test_equality():
    assert SAMPLE_ALU_INSN == SAMPLE_ALU_INSN
    assert SAMPLE_ALU_INSN != SAMPLE_BRANCH_INSN

def test_bytes_conversion():
    for sample_insn in [SAMPLE_ALU_INSN, SAMPLE_BRANCH_INSN,
                        SAMPLE_LOAD_INSN, SAMPLE_SEMA_INSN]:
        insn = enc.Insn.from_bytes(sample_insn.to_bytes())
        assert insn == sample_insn

def test_insn_repr():
    assert repr(SAMPLE_ALU_INSN) == (
            'AluInsn(sig=0x0, unpack=0x1, pm=0x1, pack=0x2, '