- | transform (X.MOVL (dest, src)) =
- if (isspilled dest)
- then
- unspill (src, spillreg1) @
- [ X.MOVL(
- realoper dest handle Spilled => stackoper dest,
- realoper src handle Spilled => X.REG spillreg1)]
- else
- [ X.MOVL(
- realoper dest handle Spilled => raise ErrorMsg.InternalError "But we said that wasn't spilled?",
- realoper src handle Spilled => stackoper src)]
- | transform (X.SUBL (dest, src)) =
- unspill (src, spillreg1) @
- [ X.SUBL(
- realoper dest handle Spilled => stackoper dest,
- realoper src handle Spilled => X.REG spillreg1)]
- | transform (X.IMUL (dest, src)) =
- unspill (dest, spillreg1) @
- [ X.IMUL(
- realoper dest handle Spilled => X.REG spillreg1,
- realoper src handle Spilled => stackoper src)] @
- spill (dest, spillreg1)
- | transform (X.IMUL3 (dest, src, const)) =
- [ X.IMUL3(
- realoper dest handle Spilled => X.REG spillreg1,
- realoper src handle Spilled => stackoper src,
- const)] @
- spill (dest, spillreg1)
- | transform (X.ADDL (dest, src)) = (* You can have either operand spilled, but not both. Pick one. *)
- if (isspilled dest)
- then
- unspill (src, spillreg1) @
- [ X.ADDL(
- realoper dest handle Spilled => stackoper dest,
- realoper src handle Spilled => X.REG spillreg1)]
- else
- [ X.ADDL(
- realoper dest handle Spilled => raise ErrorMsg.InternalError "But we said that wasn't spilled?",
- realoper src handle Spilled => stackoper src)]
- | transform (X.IDIVL (src)) = [ X.IDIVL(realoper src handle Spilled => stackoper src)]
- | transform (X.NEG (src)) = [ X.NEG(realoper src handle Spilled => stackoper src)]
- | transform (X.NOTL (src)) = [ X.NOTL(realoper src handle Spilled => stackoper src)]
- | transform (X.SALL (dest, shft)) =
- [ X.SALL (
- realoper dest handle Spilled => stackoper dest,
- shft)]
- | transform (X.SARL (dest, shft)) =
- [ X.SARL (
- realoper dest handle Spilled => stackoper dest,
- shft)]
- | transform (X.CLTD) = [ X.CLTD ]
- | transform (X.ANDL (dest, src)) =
- unspill (src, spillreg1) @
- [ X.ANDL(
- realoper dest handle Spilled => stackoper dest,
- realoper src handle Spilled => X.REG spillreg1)]
- | transform (X.ORL (dest, src)) =
- unspill (src, spillreg1) @
- [ X.ORL(
- realoper dest handle Spilled => stackoper dest,
- realoper src handle Spilled => X.REG spillreg1)]
- | transform (X.XORL (dest, src)) =
- unspill (src, spillreg1) @
- [ X.XORL(
- realoper dest handle Spilled => stackoper dest,
- realoper src handle Spilled => X.REG spillreg1)]
- | transform (X.CMPL (op1, op2)) =
- unspill (op2, spillreg1) @
- [ X.CMPL(
- realoper op1 handle Spilled => stackoper op1,
- realoper op2 handle Spilled => X.REG spillreg1)]
- | transform (X.TEST (op1, op2)) =
- unspill (op2, spillreg1) @
- [ X.TEST(
- realoper op1 handle Spilled => stackoper op1,
- realoper op2 handle Spilled => X.REG spillreg1)]
- | transform (X.SETNE (src)) = [ X.SETNE(realoper src handle Spilled => stackoper src)]
- | transform (X.SETE (src)) = [ X.SETE(realoper src handle Spilled => stackoper src)]
- | transform (X.SETLE (src)) = [ X.SETLE(realoper src handle Spilled => stackoper src)]
- | transform (X.SETL (src)) = [ X.SETL(realoper src handle Spilled => stackoper src)]
- | transform (X.SETGE (src)) = [ X.SETGE(realoper src handle Spilled => stackoper src)]
- | transform (X.SETG (src)) = [ X.SETG(realoper src handle Spilled => stackoper src)]
- | transform (X.MOVZBL (dest, src)) =
- [ X.MOVZBL(
- realoper dest handle Spilled => X.REG spillreg1,
- realoper src handle Spilled => stackoper src)]
- @ spill (dest, spillreg1)
- | transform (X.RET) = epilogue @ [X.RET]
- | transform (X.LABEL l) = [ X.LABEL l ]
- | transform (X.JMP l) = [ X.JMP l ]
- | transform (X.JE l) = [ X.JE l]
- | transform (X.JNE l) = [ X.JNE l]
-(* | transform _ = raise ErrorMsg.InternalError ("Unimplemented transform")*)
+ | transform (X.LABEL l) = [X.LABEL l]
+ | transform (X.LIVEIGN a) = transform a
+
+ (* god the special cases are going to suck *)
+ | transform (X.INSN (pred, X.MOVLIT (op1, w))) =
+ [ X.INSN (pred, X.MOVLIT (real_op1 op1, w)) ] @
+ (if isspilled op1
+ then map (fn i => X.INSN (pred, i)) (spill (op1, spillreg1))
+ else [])
+ | transform (X.INSN (pred, X.MOVSYM (op1, w))) =
+ [ X.INSN (pred, X.MOVSYM (real_op1 op1, w)) ] @
+ (if isspilled op1
+ then map (fn i => X.INSN (pred, i)) (spill (op1, spillreg1))
+ else [])
+ | transform (X.INSN (pred, X.MOVSTR (op1, w))) =
+ [ X.INSN (pred, X.MOVSTR (real_op1 op1, w)) ] @
+ (if isspilled op1
+ then map (fn i => X.INSN (pred, i)) (spill (op1, spillreg1))
+ else [])
+ | transform (X.INSN (pred, X.MOVLBL (op1, w))) =
+ [ X.INSN (pred, X.MOVLBL (real_op1 op1, w)) ] @
+ (if isspilled op1
+ then map (fn i => X.INSN (pred, i)) (spill (op1, spillreg1))
+ else [])
+
+ (* and here comes the boilerplate *)
+ | transform (X.INSN (pred, X.LDR (op1, op2))) = whack_insn (pred, X.LDR, op1, op2)
+ | transform (X.INSN (pred, X.STO (op1, op2))) = whack_insn (pred, X.STO, op1, op2)
+ | transform (X.INSN (pred, X.MOV (op1, op2))) = whack_insn (pred, X.MOV, op1, op2)
+ | transform (X.INSN (pred, X.MOVS (op1, op2))) = whack_insn (pred, X.MOVS, op1, op2)
+ | transform (X.INSN (pred, X.ADD (op1, op2))) = whack_insn (pred, X.ADD, op1, op2)
+ | transform (X.INSN (pred, X.ADDS (op1, op2))) = whack_insn (pred, X.ADDS, op1, op2)
+ | transform (X.INSN (pred, X.SUB (op1, op2))) = whack_insn (pred, X.SUB, op1, op2)
+ | transform (X.INSN (pred, X.SUBS (op1, op2))) = whack_insn (pred, X.SUBS, op1, op2)
+ | transform (X.INSN (pred, X.AND (op1, op2))) = whack_insn (pred, X.AND, op1, op2)
+ | transform (X.INSN (pred, X.ANDS (op1, op2))) = whack_insn (pred, X.ANDS, op1, op2)
+ | transform (X.INSN (pred, X.NOT (op1, op2))) = whack_insn (pred, X.NOT, op1, op2)
+ | transform (X.INSN (pred, X.NOTS (op1, op2))) = whack_insn (pred, X.NOTS, op1, op2)
+ | transform (X.INSN (pred, X.PUSH (op1, op2))) = if isspilled op2
+ then raise ErrorMsg.InternalError "PUSH on spilled op2 is not possible"
+ else [ X.INSN (pred, X.PUSH (real_ops (op1, op2))) ]
+ | transform (X.INSN (pred, X.POP (X.REG X.SP, X.REG X.PC))) = [ X.INSN (pred, X.MOVLBL (X.REG X.PC, endlbl)) ] (* optimize epilogue? *)
+ | transform (X.INSN (pred, X.POP (op1, op2))) = if isspilled op2
+ then raise ErrorMsg.InternalError "POP on spilled op2 is not possible"
+ else [ X.INSN (pred, X.POP (real_ops (op1, op2))) ]
+ | transform (X.INSN (pred, X.CALL (op1, op2, i))) = if isspilled op2
+ then raise ErrorMsg.InternalError "CALL on spilled op2 is not possible"
+ else [ X.INSN (pred, X.CALL ((fn (x, y) => (x, y, i)) (real_ops (op1, op2)))) ]
+ | transform (X.INSN (pred, X.SHR (op1, op2))) = whack_insn (pred, X.SHR, op1, op2)
+ | transform (X.INSN (pred, X.SHL (op1, op2))) = whack_insn (pred, X.SHL, op1, op2)
+ (*| transform _ = raise ErrorMsg.InternalError "unimplemented"*)