- fun stackoper (X.TEMP temp) =
- if not (isspilled (X.TEMP temp)) then raise ErrorMsg.InternalError "stackoper on unspilled temp?"
- else X.OSIZE (X.sts (Temp.size temp), X.REL (X.REG X.RSP, (X.CONST o Word32.fromInt o stackpos o temptonum) temp))
- | stackoper (X.STACKARG arg) = X.REL (X.REG X.RSP, (X.CONST o Word32.fromInt) (stacksz + 8 + (arg * 8)))
- | stackoper (a as X.REL _) = a
- | stackoper (X.OSIZE (s, oo)) = X.OSIZE (s, stackoper (X.stripsize oo))
- | stackoper _ = raise ErrorMsg.InternalError "stackoper on not temp?"
-
- fun ophit (X.OSIZE (s, oo)) = let val (insns, p) = ophit (X.stripsize oo) in (insns, X.OSIZE (s, p)) end
- | ophit (X.REL(op1, op2)) =
- let
- val t1 = X.stripsize op1
- val (s, t2) = X.sizeoper op2
- in
- if (isspilled t1 andalso isspilled t2) then
- ([X.MOV (X.OSIZE (s, X.REG spillreg1), stackoper t2),
- X.ADD (X.OSIZE (X.Qword, X.REG spillreg1), stackoper t1)],
- X.REL (X.REG spillreg1, X.CONST 0w0))
- else if(isspilled t1) then
- ([X.MOV (X.OSIZE (X.Qword, X.REG spillreg1), stackoper t1)],
- X.REL (X.REG spillreg1, realoper t2))
- else if(isspilled t2) then
- ([X.MOV (X.OSIZE (s, X.REG spillreg1), stackoper t2)],
- X.REL (realoper t1, X.REG spillreg1))
+ fun stackoper (X.TEMP temp, s) =
+ let
+ val base = (X.REG X.RSP, Tm.Quad)
+ val offs = (X.CONST (Word32.fromInt (stackpos (temptonum temp))), Tm.Quad)
+ in
+ if (isspilled (X.TEMP temp, s))
+ then (X.REL (base, offs, 0w1), s)
+ else raise ErrorMsg.InternalError "stackoper on unspilled temp?"
+ end
+ | stackoper (X.STACKARG arg, s) =
+ let
+ val base = (X.REG X.RSP, Tm.Quad)
+ val offs = (X.CONST (Word32.fromInt (stacksz + 8 + (arg * 8))), Tm.Quad)
+ in
+ (X.REL (base, offs, 0w1), s)
+ end
+ | stackoper (a as (X.REL _, s)) = a
+ | stackoper (a as (X.CONST _, s)) = a
+ | stackoper anous = raise ErrorMsg.InternalError ("stackoper on not temp " ^ X.pp_oper anous)
+
+ fun ophit (X.REL(op1, op2, m), s) =
+ if (isspilled op1 andalso isspilled op2) then
+ ([X.MOV ((X.REG spillreg1, Tm.Long), stackoper op2),
+ X.IMUL((X.REG spillreg1, Tm.Quad), (X.CONST m, Tm.Quad)),
+ X.ADD ((X.REG spillreg1, Tm.Quad), stackoper op1)],
+ (X.REL ((X.REG spillreg1, Tm.Quad), (X.CONST 0w0, Tm.Quad), 0w1), s))
+ else if(isspilled op1) then
+ ([X.MOV ((X.REG spillreg1, Tm.Quad), stackoper op1)],
+ (X.REL ((X.REG spillreg1, Tm.Quad), realoper op2, m), s))
+ else if(isspilled op2) then
+ ([X.MOV ((X.REG spillreg1, Tm.Long), stackoper op2)],
+ (X.REL (realoper op1, (X.REG spillreg1, Tm.Quad), m), s))