+ | munch_cond (T.BINOP(T.GT, T.TEMP t, T.CONST n)) = ([X.CMP(X.TEMP t, X.CONST n)], X.G, X.LE)
+ | munch_cond (T.BINOP(T.GT, T.CONST n, T.TEMP t)) = ([X.CMP(X.TEMP t, X.CONST n)], X.L, X.GE)
+ | munch_cond (T.BINOP(T.GT, e1, T.CONST n)) =
+ let val t = X.TEMP (Temp.new ("const gt")) in (munch_exp t e1 @ [X.CMP(t, X.CONST n)], X.G, X.LE) end
+ | munch_cond (T.BINOP(T.GT, T.CONST n, e1)) =
+ let val t = X.TEMP (Temp.new ("const gt")) in (munch_exp t e1 @ [X.CMP(t, X.CONST n)], X.L, X.GE) end
+ | munch_cond (T.BINOP(T.GT, e1, T.TEMP t)) =
+ let val t1 = X.TEMP (Temp.new ("const gt")) in (munch_exp t1 e1 @ [X.CMP(t1, X.TEMP t)], X.G, X.LE) end
+ | munch_cond (T.BINOP(T.GT, T.TEMP t, e1)) =
+ let val t1 = X.TEMP (Temp.new ("const gt")) in (munch_exp t1 e1 @ [X.CMP(t1, X.TEMP t)], X.L, X.GE) end
+ | munch_cond (T.BINOP(T.GT, e1, e2)) =
+ let
+ val t1 = X.TEMP (Temp.new ("var gt 1"))
+ val t2 = X.TEMP (Temp.new ("var gt 2"))
+ in
+ (munch_exp t1 e1 @ munch_exp t2 e2 @
+ [X.CMP(t1, t2)], X.G, X.LE)
+ end
+ | munch_cond (T.BINOP(T.GE, T.TEMP t, T.CONST n)) = ([X.CMP(X.TEMP t, X.CONST n)], X.GE, X.L)
+ | munch_cond (T.BINOP(T.GE, T.CONST n, T.TEMP t)) = ([X.CMP(X.TEMP t, X.CONST n)], X.LE, X.G)
+ | munch_cond (T.BINOP(T.GE, e1, T.CONST n)) =
+ let val t = X.TEMP (Temp.new ("const ge")) in (munch_exp t e1 @ [X.CMP(t, X.CONST n)], X.GE, X.L) end
+ | munch_cond (T.BINOP(T.GE, T.CONST n, e1)) =
+ let val t = X.TEMP (Temp.new ("const ge")) in (munch_exp t e1 @ [X.CMP(t, X.CONST n)], X.LE, X.G) end
+ | munch_cond (T.BINOP(T.GE, e1, T.TEMP t)) =
+ let val t1 = X.TEMP (Temp.new ("const ge")) in (munch_exp t1 e1 @ [X.CMP(t1, X.TEMP t)], X.GE, X.L) end
+ | munch_cond (T.BINOP(T.GE, T.TEMP t, e1)) =
+ let val t1 = X.TEMP (Temp.new ("const ge")) in (munch_exp t1 e1 @ [X.CMP(t1, X.TEMP t)], X.LE, X.G) end
+ | munch_cond (T.BINOP(T.GE, e1, e2)) =
+ let
+ val t1 = X.TEMP (Temp.new ("var ge 1"))
+ val t2 = X.TEMP (Temp.new ("var ge 2"))
+ in
+ (munch_exp t1 e1 @ munch_exp t2 e2 @
+ [X.CMP(t1, t2)], X.GE, X.L)
+ end
+ | munch_cond (T.BINOP(T.LOGOR, e1, e2)) =
+ let
+ val (insn1, pos1, neg1) = munch_cond e1
+ val (insn2, pos2, neg2) = munch_cond e2
+ val t1 = X.TEMP (Temp.new("logor c 1"))
+ val t2 = X.TEMP (Temp.new("logor c 2"))
+ val l = Label.new ()
+ in
+ if (effect e2 orelse (length insn2 > 10))
+ then ((insn1) @
+ [X.SETcc (pos1, t1), X.Jcc (pos1, l)] @
+ (insn2) @
+ [X.SETcc (pos2, t1), X.LABEL l, X.SIZE (X.Byte, X.TEST (t1, t1))],
+ X.NE, X.E)
+ else (insn1 @ [X.SETcc (pos1, t1)] @ insn2 @ [X.SETcc (pos2, t2), X.SIZE(X.Byte, X.OR(t1, t2))], X.NE, X.E)
+ end
+ | munch_cond (T.BINOP(T.LOGAND, e1, e2)) =
+ let
+ val (insn1, pos1, neg1) = munch_cond e1
+ val (insn2, pos2, neg2) = munch_cond e2
+ val t1 = X.TEMP (Temp.new("logand c 1"))
+ val t2 = X.TEMP (Temp.new("logand c 2"))
+ val l = Label.new ()
+ in
+ if (effect e2 orelse (length insn2 > 10))
+ then ((insn1) @
+ [X.SETcc (pos1, t1), X.Jcc (neg1, l)] @
+ (insn2) @
+ [X.SETcc (pos2, t1), X.LABEL l, X.SIZE (X.Byte, X.TEST (t1, t1))],
+ X.NE, X.E)
+ else (insn1 @ [X.SETcc (pos1, t1)] @ insn2 @ [X.SETcc (pos2, t2), X.SIZE(X.Byte, X.AND(t1, t2))], X.NE, X.E)
+ end
+ | munch_cond e =
+ let
+ val t = X.TEMP (Temp.new ("munch c"))
+ in
+ (munch_exp t e @ [ X.TEST (t,t) ], X.NE, X.E)
+ end