Esempio n. 1
0
def process_imm(trace):
    """Process imm to follow RISC-V standard convention"""
    if trace.instr in ['beq', 'bne', 'blt', 'bge', 'bltu', 'bgeu', 'c.beqz',
                       'c.bnez', 'beqz', 'bnez', 'bgez', 'bltz', 'blez',
                       'bgtz', 'c.j', 'j', 'c.jal', 'jal']:
        idx = trace.operand.rfind(',')
        if idx == -1:
            imm = trace.operand
            imm = str(sint_to_hex(int(imm, 16) - int(trace.pc, 16)))
            trace.operand = imm
        else:
            imm = trace.operand[idx + 1:]
            imm = str(sint_to_hex(int(imm, 16) - int(trace.pc, 16)))
            trace.operand = trace.operand[0:idx + 1] + imm
Esempio n. 2
0
def process_imm(instr_name, pc, operands):
    """Process imm to follow RISC-V standard convention"""
    if instr_name not in ['beq', 'bne', 'blt', 'bge', 'bltu', 'bgeu', 'c.beqz',
                          'c.bnez', 'beqz', 'bnez', 'bgez', 'bltz', 'blez',
                          'bgtz', 'c.j', 'j', 'c.jal', 'jal']:
        return operands

    idx = operands.rfind(',')
    if idx == -1:
        imm = operands
        return str(sint_to_hex(int(imm, 16) - int(pc, 16)))

    imm = operands[idx + 1:]
    imm = str(sint_to_hex(int(imm, 16) - int(pc, 16)))
    return operands[0:idx + 1] + imm