diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-04-10 18:01:22 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-15 23:01:27 -0400 |
commit | df642dc07aa157c03b8979ad3701c659411ae70d (patch) | |
tree | bb83a5472ada9949f13f319a9be1eeacec0acc75 /lo2.ml | |
parent | dd20e7c180e91f1587d94bd9878485d55bfee137 (diff) | |
download | roux-df642dc07aa157c03b8979ad3701c659411ae70d.tar.gz |
generate code for the division
Diffstat (limited to 'lo2.ml')
-rw-r--r-- | lo2.ml | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lo2.ml b/lo2.ml index e284988..4595c99 100644 --- a/lo2.ml +++ b/lo2.ml @@ -524,7 +524,7 @@ let codegen (p: mprog): string = match is.(i) with | { ri_res = l; ri_ins = `Bop (l1, op, l2) } -> let l2 = - if l1 = l then l2 else + if l1 = l || op = Div then l2 else if l2 = l then begin move (LReg (-1)) l; move l l1; @@ -544,8 +544,12 @@ let codegen (p: mprog): string = | LReg _ -> oins 0x29 (regn l2) (regn l) | _ -> assert false end + | Div -> + move (LReg (-1)) l1; + outb 0x99; (* cltd *) + oins 0xf7 7 (regn l2); + move l (LReg (-1)); (* quotient in rax *) | Mul -> failwith "Mul not implemented" - | Div -> failwith "Div not implemented" | CLe -> failwith "CLe not implemented" | CEq -> failwith "CEq not implemented" end @@ -670,7 +674,7 @@ let oneshot () = let _ = if Array.length Sys.argv > 1 && Sys.argv.(1) = "test" then let oc = open_out "t.o" in - nregs := 2; + nregs := 3; let s = psum |> regalloc |> movgen |> codegen in Elf.barebones_elf oc "f" s; close_out oc; |