fix fmt_instr

This commit is contained in:
Mylloon 2022-12-09 14:13:19 +01:00
parent 209d8382e2
commit a923bdb6b9
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

43
mips.ml
View file

@ -113,30 +113,25 @@ let fmt_loc = function
;; ;;
let fmt_instr = function let fmt_instr = function
| Label _ -> "" | Label l -> Printf.sprintf "%s:" l
| _ as i -> | Li (r, i) -> Printf.sprintf " li %s, %d" (fmt_reg r) i
Printf.sprintf " " | La (r, a) -> Printf.sprintf " la %s, %s" (fmt_reg r) (fmt_loc a)
^ | Sw (r, a) -> Printf.sprintf " sw %s, %s" (fmt_reg r) (fmt_loc a)
(match i with | Lw (r, a) -> Printf.sprintf " lw %s, %s" (fmt_reg r) (fmt_loc a)
| Label l -> Printf.sprintf "%s:" l | Sb (r, a) -> Printf.sprintf " sb %s, %s" (fmt_reg r) (fmt_loc a)
| Li (r, i) -> Printf.sprintf "li %s, %d" (fmt_reg r) i | Lb (r, a) -> Printf.sprintf " lb %s, %s" (fmt_reg r) (fmt_loc a)
| La (r, a) -> Printf.sprintf "la %s, %s" (fmt_reg r) (fmt_loc a) | Move (rd, rs) -> Printf.sprintf " move %s, %s" (fmt_reg rd) (fmt_reg rs)
| Sw (r, a) -> Printf.sprintf "sw %s, %s" (fmt_reg r) (fmt_loc a) | Neg (r, a) -> Printf.sprintf " neg %s, %s" (fmt_reg r) (fmt_reg a)
| Lw (r, a) -> Printf.sprintf "lw %s, %s" (fmt_reg r) (fmt_loc a) | Addi (rd, rs, i) -> Printf.sprintf " addi %s, %s, %d" (fmt_reg rd) (fmt_reg rs) i
| Sb (r, a) -> Printf.sprintf "sb %s, %s" (fmt_reg r) (fmt_loc a) | Add (rd, rs, rt) ->
| Lb (r, a) -> Printf.sprintf "lb %s, %s" (fmt_reg r) (fmt_loc a) Printf.sprintf " add %s, %s, %s" (fmt_reg rd) (fmt_reg rs) (fmt_reg rt)
| Move (rd, rs) -> Printf.sprintf "move %s, %s" (fmt_reg rd) (fmt_reg rs) | Mul (rd, rs, rt) ->
| Neg (r, a) -> Printf.sprintf "neg %s, %s" (fmt_reg r) (fmt_reg a) Printf.sprintf " mul %s, %s, %s" (fmt_reg rd) (fmt_reg rs) (fmt_reg rt)
| Addi (rd, rs, i) -> Printf.sprintf "addi %s, %s, %d" (fmt_reg rd) (fmt_reg rs) i | Syscall -> Printf.sprintf " syscall"
| Add (rd, rs, rt) -> | B l -> Printf.sprintf " b %s" l
Printf.sprintf "add %s, %s, %s" (fmt_reg rd) (fmt_reg rs) (fmt_reg rt) | Beqz (r, l) -> Printf.sprintf " beqz %s, %s" (fmt_reg r) l
| Mul (rd, rs, rt) -> | Jal l -> Printf.sprintf " jal %s" l
Printf.sprintf "mul %s, %s, %s" (fmt_reg rd) (fmt_reg rs) (fmt_reg rt) | Jr r -> Printf.sprintf " jr %s" (fmt_reg r)
| Syscall -> Printf.sprintf "syscall"
| B l -> Printf.sprintf "b %s" l
| Beqz (r, l) -> Printf.sprintf "beqz %s, %s" (fmt_reg r) l
| Jal l -> Printf.sprintf "jal %s" l
| Jr r -> Printf.sprintf "jr %s" (fmt_reg r))
;; ;;
let fmt_dir = function let fmt_dir = function