diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-04-05 16:44:06 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-15 23:01:27 -0400 |
commit | 44346e249c62f7360b086a5b678262b8b7a9483c (patch) | |
tree | e8f1aee6cf892b4d2fe20744546c08676ef8cabf | |
parent | 379fb0df97a05af0de480c1a1edffd9762bfa9f4 (diff) | |
download | roux-44346e249c62f7360b086a5b678262b8b7a9483c.tar.gz |
fix code emitting for x = y op x
-rw-r--r-- | lo2.ml | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lo2.ml b/lo2.ml index 169258e..4b978f4 100644 --- a/lo2.ml +++ b/lo2.ml @@ -521,8 +521,14 @@ let codegen (p: mprog): string = for i = 0 to Array.length is - 1 do match is.(i) with | { ri_res = l; ri_ins = `Bop (l1, op, l2) } -> - if l1 <> l then - move l l1; + let l2 = + if l1 = l then l2 else + if l2 = l then begin + move (LReg (-1)) l; + move l l1; + LReg (-1) + end else + (move l l1; l2) in begin match op with | Add -> begin match l2 with @@ -662,7 +668,7 @@ let oneshot () = let _ = if Array.length Sys.argv > 1 && Sys.argv.(1) = "test" then let oc = open_out "t.o" in - nregs := 3; + nregs := 2; let s = pspill |> regalloc |> movgen |> codegen in Elf.barebones_elf oc "f" s; close_out oc; |