| 1 |
(* ppcCompInstrExt.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2004 John Reppy (http://www.cs.uchicago.edu/~jhr) |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* emit code for extensions to the ppc instruction set. |
| 7 |
*) |
| 8 |
|
| 9 |
signature PPCCOMP_INSTR_EXT = |
| 10 |
sig |
| 11 |
structure I : PPCINSTR |
| 12 |
structure TS : MLTREE_STREAM (* where T = I.T *) |
| 13 |
where type T.Basis.cond = I.T.Basis.cond |
| 14 |
and type T.Basis.div_rounding_mode = I.T.Basis.div_rounding_mode |
| 15 |
and type T.Basis.ext = I.T.Basis.ext |
| 16 |
and type T.Basis.fcond = I.T.Basis.fcond |
| 17 |
and type T.Basis.rounding_mode = I.T.Basis.rounding_mode |
| 18 |
and type T.Constant.const = I.T.Constant.const |
| 19 |
and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) I.T.Extension.ccx |
| 20 |
and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) I.T.Extension.fx |
| 21 |
and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) I.T.Extension.rx |
| 22 |
and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) I.T.Extension.sx |
| 23 |
and type T.I.div_rounding_mode = I.T.I.div_rounding_mode |
| 24 |
and type T.Region.region = I.T.Region.region |
| 25 |
and type T.ccexp = I.T.ccexp |
| 26 |
and type T.fexp = I.T.fexp |
| 27 |
(* and type T.labexp = I.T.labexp *) |
| 28 |
and type T.mlrisc = I.T.mlrisc |
| 29 |
and type T.oper = I.T.oper |
| 30 |
and type T.rep = I.T.rep |
| 31 |
and type T.rexp = I.T.rexp |
| 32 |
and type T.stm = I.T.stm |
| 33 |
structure CFG : CONTROL_FLOW_GRAPH (* where I = I and and P = TS.S.P *) |
| 34 |
where type I.addressing_mode = I.addressing_mode |
| 35 |
and type I.ea = I.ea |
| 36 |
and type I.instr = I.instr |
| 37 |
and type I.instruction = I.instruction |
| 38 |
and type I.operand = I.operand |
| 39 |
where type P.Client.pseudo_op = TS.S.P.Client.pseudo_op |
| 40 |
and type P.T.Basis.cond = TS.S.P.T.Basis.cond |
| 41 |
and type P.T.Basis.div_rounding_mode = TS.S.P.T.Basis.div_rounding_mode |
| 42 |
and type P.T.Basis.ext = TS.S.P.T.Basis.ext |
| 43 |
and type P.T.Basis.fcond = TS.S.P.T.Basis.fcond |
| 44 |
and type P.T.Basis.rounding_mode = TS.S.P.T.Basis.rounding_mode |
| 45 |
and type P.T.Constant.const = TS.S.P.T.Constant.const |
| 46 |
and type ('s,'r,'f,'c) P.T.Extension.ccx = ('s,'r,'f,'c) TS.S.P.T.Extension.ccx |
| 47 |
and type ('s,'r,'f,'c) P.T.Extension.fx = ('s,'r,'f,'c) TS.S.P.T.Extension.fx |
| 48 |
and type ('s,'r,'f,'c) P.T.Extension.rx = ('s,'r,'f,'c) TS.S.P.T.Extension.rx |
| 49 |
and type ('s,'r,'f,'c) P.T.Extension.sx = ('s,'r,'f,'c) TS.S.P.T.Extension.sx |
| 50 |
and type P.T.I.div_rounding_mode = TS.S.P.T.I.div_rounding_mode |
| 51 |
and type P.T.Region.region = TS.S.P.T.Region.region |
| 52 |
and type P.T.ccexp = TS.S.P.T.ccexp |
| 53 |
and type P.T.fexp = TS.S.P.T.fexp |
| 54 |
(* and type P.T.labexp = TS.S.P.T.labexp *) |
| 55 |
and type P.T.mlrisc = TS.S.P.T.mlrisc |
| 56 |
and type P.T.oper = TS.S.P.T.oper |
| 57 |
and type P.T.rep = TS.S.P.T.rep |
| 58 |
and type P.T.rexp = TS.S.P.T.rexp |
| 59 |
and type P.T.stm = TS.S.P.T.stm |
| 60 |
|
| 61 |
type reducer = |
| 62 |
(I.instruction, I.C.cellset, I.operand, I.addressing_mode, CFG.cfg) TS.reducer |
| 63 |
|
| 64 |
val compileSext : |
| 65 |
reducer |
| 66 |
-> {stm: (I.T.stm, I.T.rexp, I.T.fexp, I.T.ccexp) PPCInstrExt.sext, |
| 67 |
an: I.T.an list} |
| 68 |
-> unit |
| 69 |
end |
| 70 |
|
| 71 |
functor PPCCompInstrExt ( |
| 72 |
|
| 73 |
structure I : PPCINSTR |
| 74 |
structure TS : MLTREE_STREAM (* where T = I.T *) |
| 75 |
where type T.Basis.cond = I.T.Basis.cond |
| 76 |
and type T.Basis.div_rounding_mode = I.T.Basis.div_rounding_mode |
| 77 |
and type T.Basis.ext = I.T.Basis.ext |
| 78 |
and type T.Basis.fcond = I.T.Basis.fcond |
| 79 |
and type T.Basis.rounding_mode = I.T.Basis.rounding_mode |
| 80 |
and type T.Constant.const = I.T.Constant.const |
| 81 |
and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) I.T.Extension.ccx |
| 82 |
and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) I.T.Extension.fx |
| 83 |
and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) I.T.Extension.rx |
| 84 |
and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) I.T.Extension.sx |
| 85 |
and type T.I.div_rounding_mode = I.T.I.div_rounding_mode |
| 86 |
and type T.Region.region = I.T.Region.region |
| 87 |
and type T.ccexp = I.T.ccexp |
| 88 |
and type T.fexp = I.T.fexp |
| 89 |
(* and type T.labexp = I.T.labexp *) |
| 90 |
and type T.mlrisc = I.T.mlrisc |
| 91 |
and type T.oper = I.T.oper |
| 92 |
and type T.rep = I.T.rep |
| 93 |
and type T.rexp = I.T.rexp |
| 94 |
and type T.stm = I.T.stm |
| 95 |
structure CFG : CONTROL_FLOW_GRAPH (* where P = TS.S.P and I = I *) |
| 96 |
where type P.Client.pseudo_op = TS.S.P.Client.pseudo_op |
| 97 |
and type P.T.Basis.cond = TS.S.P.T.Basis.cond |
| 98 |
and type P.T.Basis.div_rounding_mode = TS.S.P.T.Basis.div_rounding_mode |
| 99 |
and type P.T.Basis.ext = TS.S.P.T.Basis.ext |
| 100 |
and type P.T.Basis.fcond = TS.S.P.T.Basis.fcond |
| 101 |
and type P.T.Basis.rounding_mode = TS.S.P.T.Basis.rounding_mode |
| 102 |
and type P.T.Constant.const = TS.S.P.T.Constant.const |
| 103 |
and type ('s,'r,'f,'c) P.T.Extension.ccx = ('s,'r,'f,'c) TS.S.P.T.Extension.ccx |
| 104 |
and type ('s,'r,'f,'c) P.T.Extension.fx = ('s,'r,'f,'c) TS.S.P.T.Extension.fx |
| 105 |
and type ('s,'r,'f,'c) P.T.Extension.rx = ('s,'r,'f,'c) TS.S.P.T.Extension.rx |
| 106 |
and type ('s,'r,'f,'c) P.T.Extension.sx = ('s,'r,'f,'c) TS.S.P.T.Extension.sx |
| 107 |
and type P.T.I.div_rounding_mode = TS.S.P.T.I.div_rounding_mode |
| 108 |
and type P.T.Region.region = TS.S.P.T.Region.region |
| 109 |
and type P.T.ccexp = TS.S.P.T.ccexp |
| 110 |
and type P.T.fexp = TS.S.P.T.fexp |
| 111 |
(* and type P.T.labexp = TS.S.P.T.labexp *) |
| 112 |
and type P.T.mlrisc = TS.S.P.T.mlrisc |
| 113 |
and type P.T.oper = TS.S.P.T.oper |
| 114 |
and type P.T.rep = TS.S.P.T.rep |
| 115 |
and type P.T.rexp = TS.S.P.T.rexp |
| 116 |
and type P.T.stm = TS.S.P.T.stm |
| 117 |
where type I.addressing_mode = I.addressing_mode |
| 118 |
and type I.ea = I.ea |
| 119 |
and type I.instr = I.instr |
| 120 |
and type I.instruction = I.instruction |
| 121 |
and type I.operand = I.operand |
| 122 |
) : PPCCOMP_INSTR_EXT = struct |
| 123 |
|
| 124 |
structure CFG = CFG |
| 125 |
structure T = TS.T |
| 126 |
structure I = I |
| 127 |
structure C = I.C |
| 128 |
structure X = PPCInstrExt |
| 129 |
structure TS = TS |
| 130 |
|
| 131 |
type stm = (T.stm, T.rexp, T.fexp, T.ccexp) X.sext |
| 132 |
|
| 133 |
type reducer = |
| 134 |
(I.instruction, I.C.cellset, I.operand, I.addressing_mode, CFG.cfg) TS.reducer |
| 135 |
|
| 136 |
fun error msg = MLRiscErrorMsg.error("PPCCompInstrExt", msg) |
| 137 |
|
| 138 |
fun compileSext (reducer : reducer) {stm : stm, an : T.an list} = let |
| 139 |
val TS.REDUCER{ |
| 140 |
reduceRexp, operand, emit, instrStream, addressOf, ... |
| 141 |
} = reducer |
| 142 |
val TS.S.STREAM{emit=emitI, ...} = instrStream |
| 143 |
fun emit' inst = emit(I.INSTR inst, an) |
| 144 |
in |
| 145 |
case stm |
| 146 |
of X.STWU{src, ea} => let |
| 147 |
val (base, disp) = addressOf ea |
| 148 |
in |
| 149 |
emit' (I.ST{ |
| 150 |
st = I.STWU, |
| 151 |
rs = reduceRexp src, |
| 152 |
ra = base, |
| 153 |
d = disp, |
| 154 |
mem = T.Region.memory |
| 155 |
}) |
| 156 |
end |
| 157 |
(* end case *) |
| 158 |
end |
| 159 |
|
| 160 |
end |