remove J instr
This commit is contained in:
parent
fa95a3f071
commit
122c244abc
4 changed files with 8 additions and 5 deletions
|
@ -68,7 +68,7 @@ let rec compile_instr info = function
|
||||||
@ compile_expr info.env e
|
@ compile_expr info.env e
|
||||||
@ [ Beqz (V0, "endwhile" ^ uniq) ]
|
@ [ Beqz (V0, "endwhile" ^ uniq) ]
|
||||||
@ cb.asm
|
@ cb.asm
|
||||||
@ [ J ("while" ^ uniq) ]
|
@ [ B ("while" ^ uniq) ]
|
||||||
@ [ Label ("endwhile" ^ uniq) ]
|
@ [ Label ("endwhile" ^ uniq) ]
|
||||||
; cnt = cb.cnt
|
; cnt = cb.cnt
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let alpha = ['a'-'z' 'A'-'Z']
|
let alpha = ['a'-'z' 'A'-'Z']
|
||||||
let num = '-'? ['0'-'9']
|
let num = ['0'-'9']
|
||||||
let bool = "true" | "false"
|
let bool = "true" | "false"
|
||||||
let ident = alpha (alpha | num | '-' | '_')*
|
let ident = alpha (alpha | num | '-' | '_')*
|
||||||
|
|
||||||
|
|
2
mips.ml
2
mips.ml
|
@ -58,7 +58,6 @@ type instr =
|
||||||
| Beq of reg * reg * label
|
| Beq of reg * reg * label
|
||||||
| Beqz of reg * label
|
| Beqz of reg * label
|
||||||
| Jal of label
|
| Jal of label
|
||||||
| J of label
|
|
||||||
| Jr of reg
|
| Jr of reg
|
||||||
|
|
||||||
type directive = Asciiz of string
|
type directive = Asciiz of string
|
||||||
|
@ -150,7 +149,6 @@ let fmt_instr ?(indent = " ") = function
|
||||||
Printf.sprintf "%sbeq %s, %s, %s" indent (fmt_reg rs) (fmt_reg rt) l
|
Printf.sprintf "%sbeq %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
|
|
||||||
| Jr r -> Printf.sprintf "%sjr %s" indent (fmt_reg r)
|
| Jr r -> Printf.sprintf "%sjr %s" indent (fmt_reg r)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
%token Ladd Lsub Lmul Ldiv Lseq Lsge Lsgt Lsle Lslt Lsne
|
%token Ladd Lsub Lmul Ldiv Lseq Lsge Lsgt Lsle Lslt Lsne
|
||||||
%token Lif Lelse Lwhile
|
%token Lif Lelse Lwhile
|
||||||
|
|
||||||
%left Ladd Lsub Lmul Ldiv Lbigger Lseq Lsge Lsgt Lsle Lslt Lsne
|
%left Ladd Lsub Lmul Ldiv Lseq Lsge Lsgt Lsle Lslt Lsne
|
||||||
|
|
||||||
%left Lbracedeb Lparfin Lbracefin Lreturn
|
%left Lbracedeb Lparfin Lbracefin Lreturn
|
||||||
%left Ltype Lbool Lint Lvar Lstr
|
%left Ltype Lbool Lint Lvar Lstr
|
||||||
|
@ -131,6 +131,11 @@ instr:
|
||||||
}
|
}
|
||||||
|
|
||||||
expr:
|
expr:
|
||||||
|
/* -int */
|
||||||
|
| Lsub ; n = Lint {
|
||||||
|
Val { value = Int (-n) ; pos = $startpos(n) }
|
||||||
|
}
|
||||||
|
|
||||||
/* int */
|
/* int */
|
||||||
| n = Lint {
|
| n = Lint {
|
||||||
Val { value = Int (n) ; pos = $startpos(n) }
|
Val { value = Int (n) ; pos = $startpos(n) }
|
||||||
|
|
Reference in a new issue