- [ X.SUB (X.OSIZE (X.Qword, X.REG X.RSP), X.CONST (Word32.fromInt stackb)),
- X.CALL (name, nargs),
- X.ADD (X.OSIZE (X.Qword, X.REG X.RSP), X.CONST (Word32.fromInt stackb)),
- X.MOV (d, X.OSIZE (X.sts rsz, X.REG X.EAX)) ] (* Finally! *)
- end
-(* | munch_exp d (T.BINOP(T.ADD, e1, T.CONST 0w0)) = munch_exp d e1
- | munch_exp d (T.BINOP(T.ADD, T.CONST 0w0, e1)) = munch_exp d e1
- | munch_exp d (T.BINOP(T.ADD, e1, T.CONST n)) = (munch_exp d e1) @ [X.ADD(d, X.CONST n)]
- | munch_exp d (T.BINOP(T.ADD, T.CONST n, e1)) = (munch_exp d e1) @ [X.ADD(d, X.CONST n)]
- | munch_exp d (T.BINOP(T.ADD, e1, T.TEMP t)) = (munch_exp d e1) @ [X.ADD(d, X.TEMP t)]
- | munch_exp d (T.BINOP(T.ADD, T.TEMP t, e2)) = (munch_exp d e2) @ [X.ADD(d, X.TEMP t)] *)
- | munch_exp d (T.BINOP(T.ADD, e1, e2)) =
- let
- val t1 = X.TEMP (Temp.new ("add") 4)
- in
- (munch_exp d e1) @ (munch_exp t1 e2) @ [X.ADD(d, t1)]
- end
-(* | munch_exp d (T.BINOP(T.SUB, T.CONST 0w0, e1)) = (munch_exp d e1) @ [X.NEG d]
- | munch_exp d (T.BINOP(T.SUB, e1, T.CONST 0w0)) = munch_exp d e1
- | munch_exp d (T.BINOP(T.SUB, e1, T.CONST(n))) = (munch_exp d e1) @ [X.SUB(d, X.CONST n)]
- | munch_exp d (T.BINOP(T.SUB, e1, T.TEMP t)) = (munch_exp d e1) @ [X.SUB(d, X.TEMP t)] *)
- | munch_exp d (T.BINOP(T.SUB, e1, e2)) =
- let
- val t1 = X.TEMP (Temp.new ("sub") 4)
- in
- (munch_exp d e1) @ (munch_exp t1 e2) @ [X.SUB(d, t1)]
- end
- | munch_exp d (T.BINOP(T.MUL, T.TEMP t, T.CONST n)) = [X.IMUL3(d, X.TEMP t, n)]
- | munch_exp d (T.BINOP(T.MUL, T.CONST n, T.TEMP t)) = [X.IMUL3(d, X.TEMP t, n)]
-(*
- | munch_exp d (T.BINOP(T.MUL, e1, T.CONST 0w1)) = munch_exp d e1
- | munch_exp d (T.BINOP(T.MUL, T.CONST 0w1, e1)) = munch_exp d e1
- | munch_exp d (T.BINOP(T.MUL, e1, T.CONST n)) = (munch_exp d e1) @ [X.IMUL(d, X.CONST n)]
- | munch_exp d (T.BINOP(T.MUL, T.CONST n, e1)) = (munch_exp d e1) @ [X.IMUL(d, X.CONST n)] *)
- | munch_exp d (T.BINOP(T.MUL, e1, e2)) =
- let
- val t1 = X.TEMP (Temp.new ("mul") 4)
- in
- (munch_exp d e1) @ (munch_exp t1 e2) @ [X.IMUL(d, t1)]
- end
- | munch_exp d (T.BINOP(T.DIV, e1, e2)) =
- let
- val t1 = X.TEMP (Temp.new ("div") 4)
- in
- (munch_exp t1 e1) @ (munch_exp d e2) @
- [X.MOV (X.REG X.EAX, t1), X.CLTD, X.IDIV d, X.MOV (d, X.REG X.EAX)]
- end
- | munch_exp d (T.BINOP(T.MOD, e1, e2)) =
- let
- val t1 = X.TEMP (Temp.new ("mod") 4)
- in
- (munch_exp t1 e1) @ (munch_exp d e2) @
- [X.MOV (X.REG X.EAX, t1), X.CLTD, X.IDIV d, X.MOV (d, X.REG X.EDX)]
- end
- | munch_exp d (T.BINOP(T.LSH, e1, T.CONST n)) = (munch_exp d e1) @ [X.SAL (d, X.CONST (n mod 0w32))]
- | munch_exp d (T.BINOP(T.LSH, e1, T.TEMP t)) = (munch_exp d e1) @ [X.MOV (X.REG X.ECX, X.TEMP t), X.SAL (d, X.REG X.ECX)]
- | munch_exp d (T.BINOP(T.LSH, e1, e2)) =
- let
- val t = X.TEMP (Temp.new ("lsh") 4)
- in
- (munch_exp d e1) @ (munch_exp t e2) @ [X.MOV (X.REG X.ECX, t), X.SAL (d, X.REG X.ECX)]
- end
- | munch_exp d (T.BINOP(T.RSH, e1, T.CONST n)) = (munch_exp d e1) @ [X.SAR (d, X.CONST (n mod 0w32))]
- | munch_exp d (T.BINOP(T.RSH, e1, T.TEMP t)) = (munch_exp d e1) @ [X.MOV (X.REG X.ECX, X.TEMP t), X.SAR (d, X.REG X.ECX)]
- | munch_exp d (T.BINOP(T.RSH, e1, e2)) =
- let
- val t = X.TEMP (Temp.new ("rsh") 4)
- in
- (munch_exp d e1) @ (munch_exp t e2) @ [X.MOV (X.REG X.ECX, t), X.SAR (d, X.REG X.ECX)]
- end
- | munch_exp d (T.BINOP(T.BITAND, T.CONST n, e1)) = (munch_exp d e1) @ [X.AND (d, X.CONST n)]
- | munch_exp d (T.BINOP(T.BITAND, e1, T.CONST n)) = (munch_exp d e1) @ [X.AND (d, X.CONST n)]
- | munch_exp d (T.BINOP(T.BITAND, T.TEMP t, e1)) = (munch_exp d e1) @ [X.AND (d, X.TEMP t)]
- | munch_exp d (T.BINOP(T.BITAND, e1, T.TEMP t)) = (munch_exp d e1) @ [X.AND (d, X.TEMP t)]
- | munch_exp d (T.BINOP(T.BITAND, e1, e2)) =
- let
- val t1 = X.TEMP (Temp.new ("bitand") 4)
- in
- (munch_exp d e1) @ (munch_exp t1 e2) @ [X.AND(d, t1)]
- end
- | munch_exp d (T.BINOP(T.BITOR, T.CONST n, e1)) = (munch_exp d e1) @ [X.OR (d, X.CONST n)]
- | munch_exp d (T.BINOP(T.BITOR, e1, T.CONST n)) = (munch_exp d e1) @ [X.OR (d, X.CONST n)]
- | munch_exp d (T.BINOP(T.BITOR, T.TEMP t, e1)) = (munch_exp d e1) @ [X.OR (d, X.TEMP t)]
- | munch_exp d (T.BINOP(T.BITOR, e1, T.TEMP t)) = (munch_exp d e1) @ [X.OR (d, X.TEMP t)]
- | munch_exp d (T.BINOP(T.BITOR, e1, e2)) =
- let
- val t1 = X.TEMP (Temp.new ("bitor") 4)
- in
- (munch_exp d e1) @ (munch_exp t1 e2) @ [X.OR(d, t1)]