Skip to content

Commit

Permalink
Produce correct ARM assembly code for identifiers starting with $
Browse files Browse the repository at this point in the history
They must be parenthesized in some contexts.
  • Loading branch information
xavierleroy committed Dec 1, 2024
1 parent 7f3102d commit cdfff5e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions arm/TargetPrinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ struct

let symbol = elf_symbol

let symbol_offset = elf_symbol_offset
let symbol_paren oc symb =
let s = extern_atom symb in
if String.length s > 0 && s.[0] = '$'
then fprintf oc "(%s)" s
else fprintf oc "%s" s

let symbol_offset oc (symb, ofs) =
let ofs = camlint64_of_ptrofs ofs in
if ofs = 0L then
symbol_paren oc symb
else
fprintf oc "(%a + %Ld)" symbol symb ofs

let ireg oc r = output_string oc (int_reg_name r)
let freg oc r = output_string oc (float_reg_name r)
Expand Down Expand Up @@ -227,11 +238,11 @@ struct
| Pbne lbl ->
fprintf oc " bne %a\n" print_label lbl
| Pbsymb(id, sg) ->
fprintf oc " b %a\n" symbol id
fprintf oc " b %a\n" symbol_paren id
| Pbreg(r, sg) ->
fprintf oc " bx %a\n" ireg r
| Pblsymb(id, sg) ->
fprintf oc " bl %a\n" symbol id
fprintf oc " bl %a\n" symbol_paren id
| Pblreg(r, sg) ->
fprintf oc " blx %a\n" ireg r
| Pbic(r1, r2, so) ->
Expand Down

0 comments on commit cdfff5e

Please sign in to comment.