matt-kempster/m2c

Add option to specify initial value for saved registers

tge-was-taken opened this issue · 0 comments

Add option to specify initial value for saved registers, such as $gp, in order to resolve data accesses through these registers.

Example assembly

glabel fun_2442c8
lw $v1, -0x5750($gp)
lw $v0, 0xa48($v1)
slt $v0, $v0, $a0
jr $ra
sltiu $v0, $v0, 0x1
nop 

mips-to-c output

s32 fun_2442c8(s32 arg0) {
    return (saved_reg_gp->unk-5750->unkA48 < arg0) == 0;
}

If I were to specify the value of $gp as 0x554170, then I'd expect the output to look like this:

s32 fun_2442c8(s32 arg0) {
    return (0x54EA20->unkA48 < arg0) == 0;
}

Ideally, I'd able to declare a variable in the context and bind to the address (with eg a pragma or macro), so the decompiler could use its name and typeinfo to improve the legibility of the code.

Perhaps specifying the value of $gp could be done through a pragma or macro in the context as well.