Skip to content

Commit

Permalink
Support "la $reg, (SYMBOL)"
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlindholm committed Aug 14, 2024
1 parent 58bf355 commit 76808d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions m2c/asm_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,18 @@ def expect(n: str) -> str:
value = constant_fold(rhs, defines)
else:
# Address mode.
assert top_level
rhs = replace_bare_reg(rhs, arch, reg_formatter)
if rhs == AsmLiteral(0):
rhs = Register("zero")
assert isinstance(rhs, Register)
value = constant_fold(value or AsmLiteral(0), defines)
value = AsmAddressMode(value, rhs)
if isinstance(rhs, AsmGlobalSymbol):
# Global symbols may be parenthesized.
assert value is None
value = constant_fold(rhs, defines)
else:
assert top_level
assert isinstance(rhs, Register)
value = constant_fold(value or AsmLiteral(0), defines)
value = AsmAddressMode(value, rhs)
elif tok == '"':
# Quoted global symbol.
expect('"')
Expand Down
2 changes: 2 additions & 0 deletions tests/end_to_end/weird-asm/test-out.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Warning: missing "jr $ra" in last block (jumptarget_label).

extern ? some_symbol;

s32 test(void) {
return 0x1233FFFF * 2;
}
1 change: 1 addition & 0 deletions tests/end_to_end/weird-asm/test.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ b jumptarget_label
li $two, 2 # fictive register names are (currently) fine
jlabel jumptarget_label
multu $v0, $v0, $two # multiply by two, ps2-style
la $v1, (some_symbol)
addiu $sp, $sp, 0x34

func_other:
Expand Down

0 comments on commit 76808d5

Please sign in to comment.