cleaning
This commit is contained in:
parent
2f53bdcab8
commit
32b3476451
1 changed files with 29 additions and 45 deletions
74
mips.ml
74
mips.ml
|
@ -1,33 +1,33 @@
|
||||||
type reg =
|
type reg =
|
||||||
| Zero (* Toujours à zéro *)
|
| Zero
|
||||||
| V0 (* Valeurs de retours *)
|
| V0
|
||||||
| V1 (* .................. *)
|
| V1
|
||||||
| A0 (* Premiers arguments des fonctions *)
|
| A0
|
||||||
| A1 (* ................................ *)
|
| A1
|
||||||
| A2 (* ................................ *)
|
| A2
|
||||||
| A3 (* ................................ *)
|
| A3
|
||||||
| T0 (* Registres temporaires *)
|
| T0
|
||||||
| T1 (* ..................... *)
|
| T1
|
||||||
| T2 (* ..................... *)
|
| T2
|
||||||
| T3 (* ..................... *)
|
| T3
|
||||||
| T4 (* ..................... *)
|
| T4
|
||||||
| T5 (* ..................... *)
|
| T5
|
||||||
| T6 (* ..................... *)
|
| T6
|
||||||
| T7 (* ..................... *)
|
| T7
|
||||||
| T8 (* ..................... *)
|
| T8
|
||||||
| T9 (* ..................... *)
|
| T9
|
||||||
| S0 (* Registres sauvegardés *)
|
| S0
|
||||||
| S1 (* ..................... *)
|
| S1
|
||||||
| S2 (* ..................... *)
|
| S2
|
||||||
| S3 (* ..................... *)
|
| S3
|
||||||
| S4 (* ..................... *)
|
| S4
|
||||||
| S5 (* ..................... *)
|
| S5
|
||||||
| S6 (* ..................... *)
|
| S6
|
||||||
| S7 (* ..................... *)
|
| S7
|
||||||
| GP (* Global pointer *)
|
| GP
|
||||||
| SP (* Stack pointer *)
|
| SP
|
||||||
| FP (* Frame pointer *)
|
| FP
|
||||||
| RA (* Adresse de retour *)
|
| RA
|
||||||
|
|
||||||
type label = string
|
type label = string
|
||||||
|
|
||||||
|
@ -41,10 +41,7 @@ type instr =
|
||||||
| La of reg * loc
|
| La of reg * loc
|
||||||
| Sw of reg * loc
|
| Sw of reg * loc
|
||||||
| Lw of reg * loc
|
| Lw of reg * loc
|
||||||
| Sb of reg * loc
|
|
||||||
| Lb of reg * loc
|
|
||||||
| Move of reg * reg
|
| Move of reg * reg
|
||||||
| Neg of reg * reg
|
|
||||||
| Addi of reg * reg * int
|
| Addi of reg * reg * int
|
||||||
| Add of reg * reg * reg
|
| Add of reg * reg * reg
|
||||||
| Mul of reg * reg * reg
|
| Mul of reg * reg * reg
|
||||||
|
@ -53,8 +50,6 @@ type instr =
|
||||||
| Slt of reg * reg * reg
|
| Slt of reg * reg * reg
|
||||||
| Syscall
|
| Syscall
|
||||||
| B of label
|
| B of label
|
||||||
| Beq of reg * reg * label
|
|
||||||
| Bne of reg * reg * label
|
|
||||||
| Beqz of reg * label
|
| Beqz of reg * label
|
||||||
| Jal of label
|
| Jal of label
|
||||||
| J of label
|
| J of label
|
||||||
|
@ -70,12 +65,8 @@ type asm =
|
||||||
|
|
||||||
module Syscall = struct
|
module Syscall = struct
|
||||||
let print_int = 1
|
let print_int = 1
|
||||||
let print_float = 2
|
|
||||||
let print_double = 3
|
|
||||||
let print_str = 4
|
let print_str = 4
|
||||||
let read_int = 5
|
let read_int = 5
|
||||||
let read_float = 6
|
|
||||||
let read_double = 7
|
|
||||||
let read_str = 8
|
let read_str = 8
|
||||||
let sbrk = 9
|
let sbrk = 9
|
||||||
let exit = 10
|
let exit = 10
|
||||||
|
@ -124,10 +115,7 @@ let fmt_instr ?(indent = " ") = function
|
||||||
| La (r, a) -> Printf.sprintf "%sla %s, %s" indent (fmt_reg r) (fmt_loc a)
|
| La (r, a) -> Printf.sprintf "%sla %s, %s" indent (fmt_reg r) (fmt_loc a)
|
||||||
| Sw (r, a) -> Printf.sprintf "%ssw %s, %s" indent (fmt_reg r) (fmt_loc a)
|
| Sw (r, a) -> Printf.sprintf "%ssw %s, %s" indent (fmt_reg r) (fmt_loc a)
|
||||||
| Lw (r, a) -> Printf.sprintf "%slw %s, %s" indent (fmt_reg r) (fmt_loc a)
|
| Lw (r, a) -> Printf.sprintf "%slw %s, %s" indent (fmt_reg r) (fmt_loc a)
|
||||||
| Sb (r, a) -> Printf.sprintf "%ssb %s, %s" indent (fmt_reg r) (fmt_loc a)
|
|
||||||
| Lb (r, a) -> Printf.sprintf "%slb %s, %s" indent (fmt_reg r) (fmt_loc a)
|
|
||||||
| Move (rd, rs) -> Printf.sprintf "%smove %s, %s" indent (fmt_reg rd) (fmt_reg rs)
|
| Move (rd, rs) -> Printf.sprintf "%smove %s, %s" indent (fmt_reg rd) (fmt_reg rs)
|
||||||
| Neg (r, a) -> Printf.sprintf "%sneg %s, %s" indent (fmt_reg r) (fmt_reg a)
|
|
||||||
| Addi (rd, rs, i) ->
|
| Addi (rd, rs, i) ->
|
||||||
Printf.sprintf "%saddi %s, %s, %d" indent (fmt_reg rd) (fmt_reg rs) i
|
Printf.sprintf "%saddi %s, %s, %d" indent (fmt_reg rd) (fmt_reg rs) i
|
||||||
| Add (rd, rs, rt) ->
|
| Add (rd, rs, rt) ->
|
||||||
|
@ -142,10 +130,6 @@ let fmt_instr ?(indent = " ") = function
|
||||||
Printf.sprintf "%sslt %s, %s, %s" indent (fmt_reg rd) (fmt_reg rs) (fmt_reg rt)
|
Printf.sprintf "%sslt %s, %s, %s" indent (fmt_reg rd) (fmt_reg rs) (fmt_reg rt)
|
||||||
| Syscall -> Printf.sprintf "%ssyscall" indent
|
| Syscall -> Printf.sprintf "%ssyscall" indent
|
||||||
| B l -> Printf.sprintf "%sb %s" indent l
|
| B l -> Printf.sprintf "%sb %s" indent l
|
||||||
| Beq (rs, rt, l) ->
|
|
||||||
Printf.sprintf "%sbeq %s, %s, %s" indent (fmt_reg rs) (fmt_reg rt) l
|
|
||||||
| Bne (rs, rt, l) ->
|
|
||||||
Printf.sprintf "%sbne %s, %s, %s" indent (fmt_reg rs) (fmt_reg rt) l
|
|
||||||
| Beqz (r, l) -> Printf.sprintf "%sbeqz %s, %s" indent (fmt_reg r) l
|
| Beqz (r, l) -> Printf.sprintf "%sbeqz %s, %s" indent (fmt_reg r) l
|
||||||
| Jal l -> Printf.sprintf "%sjal %s" indent l
|
| Jal l -> Printf.sprintf "%sjal %s" indent l
|
||||||
| J l -> Printf.sprintf "%sj %s" indent l
|
| J l -> Printf.sprintf "%sj %s" indent l
|
||||||
|
|
Reference in a new issue