| 1 |
(* sparccomp-instr-ext.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2001 Bell Labs, Lucent Technologies |
| 4 |
* |
| 5 |
* compiling a trivial extensions to the Sparc instruction set |
| 6 |
* (UNIMP instruction) |
| 7 |
*) |
| 8 |
signature SPARCCOMP_INSTR_EXT = sig |
| 9 |
structure T : MLTREE |
| 10 |
structure I : SPARCINSTR (* where T = T *) |
| 11 |
where type T.Basis.cond = T.Basis.cond |
| 12 |
and type T.Basis.div_rounding_mode = T.Basis.div_rounding_mode |
| 13 |
and type T.Basis.ext = T.Basis.ext |
| 14 |
and type T.Basis.fcond = T.Basis.fcond |
| 15 |
and type T.Basis.rounding_mode = T.Basis.rounding_mode |
| 16 |
and type T.Constant.const = T.Constant.const |
| 17 |
and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) T.Extension.ccx |
| 18 |
and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) T.Extension.fx |
| 19 |
and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) T.Extension.rx |
| 20 |
and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) T.Extension.sx |
| 21 |
and type T.I.div_rounding_mode = T.I.div_rounding_mode |
| 22 |
and type T.Region.region = T.Region.region |
| 23 |
and type T.ccexp = T.ccexp |
| 24 |
and type T.fexp = T.fexp |
| 25 |
(* and type T.labexp = T.labexp *) |
| 26 |
and type T.mlrisc = T.mlrisc |
| 27 |
and type T.oper = T.oper |
| 28 |
and type T.rep = T.rep |
| 29 |
and type T.rexp = T.rexp |
| 30 |
and type T.stm = T.stm |
| 31 |
structure TS : MLTREE_STREAM (* where T = I.T *) |
| 32 |
where type T.Basis.cond = I.T.Basis.cond |
| 33 |
and type T.Basis.div_rounding_mode = I.T.Basis.div_rounding_mode |
| 34 |
and type T.Basis.ext = I.T.Basis.ext |
| 35 |
and type T.Basis.fcond = I.T.Basis.fcond |
| 36 |
and type T.Basis.rounding_mode = I.T.Basis.rounding_mode |
| 37 |
and type T.Constant.const = I.T.Constant.const |
| 38 |
and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) I.T.Extension.ccx |
| 39 |
and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) I.T.Extension.fx |
| 40 |
and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) I.T.Extension.rx |
| 41 |
and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) I.T.Extension.sx |
| 42 |
and type T.I.div_rounding_mode = I.T.I.div_rounding_mode |
| 43 |
and type T.Region.region = I.T.Region.region |
| 44 |
and type T.ccexp = I.T.ccexp |
| 45 |
and type T.fexp = I.T.fexp |
| 46 |
(* and type T.labexp = I.T.labexp *) |
| 47 |
and type T.mlrisc = I.T.mlrisc |
| 48 |
and type T.oper = I.T.oper |
| 49 |
and type T.rep = I.T.rep |
| 50 |
and type T.rexp = I.T.rexp |
| 51 |
and type T.stm = I.T.stm |
| 52 |
structure CFG : CONTROL_FLOW_GRAPH (* where I = I *) |
| 53 |
where type I.addressing_mode = I.addressing_mode |
| 54 |
and type I.ea = I.ea |
| 55 |
and type I.instr = I.instr |
| 56 |
and type I.instruction = I.instruction |
| 57 |
and type I.operand = I.operand |
| 58 |
|
| 59 |
|
| 60 |
type reducer = |
| 61 |
(I.instruction, I.C.cellset, I.operand, I.addressing_mode, CFG.cfg) TS.reducer |
| 62 |
|
| 63 |
val compileSext : |
| 64 |
reducer |
| 65 |
-> { stm: (T.stm, T.rexp, T.fexp, T.ccexp) SparcInstrExt.sext, |
| 66 |
an: T.an list } |
| 67 |
-> unit |
| 68 |
end |
| 69 |
|
| 70 |
functor SparcCompInstrExt |
| 71 |
(structure I : SPARCINSTR |
| 72 |
structure TS : MLTREE_STREAM (* where T = I.T *) |
| 73 |
where type T.Basis.cond = I.T.Basis.cond |
| 74 |
and type T.Basis.div_rounding_mode = I.T.Basis.div_rounding_mode |
| 75 |
and type T.Basis.ext = I.T.Basis.ext |
| 76 |
and type T.Basis.fcond = I.T.Basis.fcond |
| 77 |
and type T.Basis.rounding_mode = I.T.Basis.rounding_mode |
| 78 |
and type T.Constant.const = I.T.Constant.const |
| 79 |
and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) I.T.Extension.ccx |
| 80 |
and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) I.T.Extension.fx |
| 81 |
and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) I.T.Extension.rx |
| 82 |
and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) I.T.Extension.sx |
| 83 |
and type T.I.div_rounding_mode = I.T.I.div_rounding_mode |
| 84 |
and type T.Region.region = I.T.Region.region |
| 85 |
and type T.ccexp = I.T.ccexp |
| 86 |
and type T.fexp = I.T.fexp |
| 87 |
(* and type T.labexp = I.T.labexp *) |
| 88 |
and type T.mlrisc = I.T.mlrisc |
| 89 |
and type T.oper = I.T.oper |
| 90 |
and type T.rep = I.T.rep |
| 91 |
and type T.rexp = I.T.rexp |
| 92 |
and type T.stm = I.T.stm |
| 93 |
structure CFG : CONTROL_FLOW_GRAPH (* where I = I and P = TS.S.P *) |
| 94 |
where type I.addressing_mode = I.addressing_mode |
| 95 |
and type I.ea = I.ea |
| 96 |
and type I.instr = I.instr |
| 97 |
and type I.instruction = I.instruction |
| 98 |
and type I.operand = I.operand |
| 99 |
where type P.Client.pseudo_op = TS.S.P.Client.pseudo_op |
| 100 |
and type P.T.Basis.cond = TS.S.P.T.Basis.cond |
| 101 |
and type P.T.Basis.div_rounding_mode = TS.S.P.T.Basis.div_rounding_mode |
| 102 |
and type P.T.Basis.ext = TS.S.P.T.Basis.ext |
| 103 |
and type P.T.Basis.fcond = TS.S.P.T.Basis.fcond |
| 104 |
and type P.T.Basis.rounding_mode = TS.S.P.T.Basis.rounding_mode |
| 105 |
and type P.T.Constant.const = TS.S.P.T.Constant.const |
| 106 |
and type ('s,'r,'f,'c) P.T.Extension.ccx = ('s,'r,'f,'c) TS.S.P.T.Extension.ccx |
| 107 |
and type ('s,'r,'f,'c) P.T.Extension.fx = ('s,'r,'f,'c) TS.S.P.T.Extension.fx |
| 108 |
and type ('s,'r,'f,'c) P.T.Extension.rx = ('s,'r,'f,'c) TS.S.P.T.Extension.rx |
| 109 |
and type ('s,'r,'f,'c) P.T.Extension.sx = ('s,'r,'f,'c) TS.S.P.T.Extension.sx |
| 110 |
and type P.T.I.div_rounding_mode = TS.S.P.T.I.div_rounding_mode |
| 111 |
and type P.T.Region.region = TS.S.P.T.Region.region |
| 112 |
and type P.T.ccexp = TS.S.P.T.ccexp |
| 113 |
and type P.T.fexp = TS.S.P.T.fexp |
| 114 |
(* and type P.T.labexp = TS.S.P.T.labexp *) |
| 115 |
and type P.T.mlrisc = TS.S.P.T.mlrisc |
| 116 |
and type P.T.oper = TS.S.P.T.oper |
| 117 |
and type P.T.rep = TS.S.P.T.rep |
| 118 |
and type P.T.rexp = TS.S.P.T.rexp |
| 119 |
and type P.T.stm = TS.S.P.T.stm |
| 120 |
) : SPARCCOMP_INSTR_EXT = |
| 121 |
struct |
| 122 |
structure CFG = CFG |
| 123 |
structure T = TS.T |
| 124 |
structure TS = TS |
| 125 |
structure I = I |
| 126 |
structure C = I.C |
| 127 |
structure X = SparcInstrExt |
| 128 |
|
| 129 |
type stm = (T.stm, T.rexp, T.fexp, T.ccexp) X.sext |
| 130 |
|
| 131 |
type reducer = |
| 132 |
(I.instruction, I.C.cellset, I.operand, I.addressing_mode, CFG.cfg) TS.reducer |
| 133 |
|
| 134 |
fun compileSext reducer { stm: stm, an: T.an list } = let |
| 135 |
val TS.REDUCER { emit, operand, reduceOperand, ... } = reducer |
| 136 |
in |
| 137 |
case stm |
| 138 |
of X.UNIMP i => emit (I.unimp {const22 = i}, an) |
| 139 |
| X.SAVE (r, i, d) => emit(I.save{r=reduceOperand(operand r), i=operand i, d=reduceOperand(operand d)}, an) |
| 140 |
| X.RESTORE (r, i, d) => emit(I.restore{r=reduceOperand(operand r), i=operand i, d=reduceOperand(operand d)}, an) |
| 141 |
end |
| 142 |
end |