| 1 |
(* |
| 2 |
* Generate the <arch>Props functor. |
| 3 |
* This structure extracts information about the instruction set. |
| 4 |
*) |
| 5 |
|
| 6 |
functor MDLGenInsnProps(RTLComp : MDL_RTL_COMP) : MDL_GEN_MODULE2 = |
| 7 |
struct |
| 8 |
|
| 9 |
structure RTLComp = RTLComp |
| 10 |
structure Comp = RTLComp.Comp |
| 11 |
structure Ast = Comp.Ast |
| 12 |
structure M = RTLComp.MLRiscTypes |
| 13 |
|
| 14 |
open Ast Comp.Util |
| 15 |
|
| 16 |
val typeDefs = |
| 17 |
$ ["(* classify instructions *)", |
| 18 |
"datatype kind = IK_JUMP (* branches, including returns *)", |
| 19 |
" | IK_NOP (* no ops *)", |
| 20 |
" | IK_INSTR (* normal instructions *)", |
| 21 |
" | IK_COPY (* parallel copy *)", |
| 22 |
" | IK_CALL (* call instructions *)", |
| 23 |
" | IK_PHI (* A phi node (SSA) *)", |
| 24 |
" | IK_SINK (* A sink node (SSA) *)", |
| 25 |
" | IK_SOURCE (* A source node (SSA) *)", |
| 26 |
"", |
| 27 |
"datatype target = LABELLED of Label.label", |
| 28 |
" | FALLTHROUGH" , |
| 29 |
" | ESCAPES", |
| 30 |
"", |
| 31 |
"exception NegateCondtional", |
| 32 |
"" |
| 33 |
] |
| 34 |
|
| 35 |
val funDefs = |
| 36 |
$ ["fun getAnnotations(I.ANNOTATION{i,a}) =", |
| 37 |
" let val (i,an) = getAnnotations i in (i,a::an) end", |
| 38 |
" | getAnnotations i = (i,[])", |
| 39 |
"fun annotate(i,a) = I.ANNOTATION{i=i,a=a}" |
| 40 |
] |
| 41 |
|
| 42 |
fun gen compiled_rtls = |
| 43 |
let val md = RTLComp.md compiled_rtls |
| 44 |
|
| 45 |
(* name of the structure/signature *) |
| 46 |
val strName = Comp.strname md "Props" |
| 47 |
val sigName = "INSN_PROPERTIES" |
| 48 |
|
| 49 |
(* The instructions *) |
| 50 |
val instructions = Comp.instructions md |
| 51 |
|
| 52 |
(* Arguments to the instruction functor *) |
| 53 |
val args = |
| 54 |
["I : "^Comp.signame md "INSTR" |
| 55 |
] |
| 56 |
|
| 57 |
(* Function that determines the type of an instruction *) |
| 58 |
val instrKind = DUMMYfun "instrKind" |
| 59 |
|
| 60 |
(* Functions for dealing with parallel copies *) |
| 61 |
val moveInstr = DUMMYfun "moveInstr" |
| 62 |
val moveTmpR = DUMMYfun "moveTmpR" |
| 63 |
val moveDstSrc = DUMMYfun "moveDstSrc" |
| 64 |
|
| 65 |
val nop = DUMMYfun "nop" |
| 66 |
val jump = DUMMYfun "jump" |
| 67 |
|
| 68 |
val loadImmed = DUMMYfun "loadImmed" |
| 69 |
|
| 70 |
val branchTargets = DUMMYfun "branchTargets" |
| 71 |
val setTargets = DUMMYfun "setTargets" |
| 72 |
|
| 73 |
val negateConditional = DUMMYfun "negateConditional" |
| 74 |
val immedRange = DUMMYfun "immedRange" |
| 75 |
val loadOperand = DUMMYfun "loadOperand" |
| 76 |
|
| 77 |
val eqOpn = DUMMYfun "eqOpn" |
| 78 |
val hashOpn = DUMMYfun "hashOpn" |
| 79 |
|
| 80 |
fun mkDefUse(cellKind as CELLdecl{id, ...}) = |
| 81 |
let val {get, decl} = M.getOpnd |
| 82 |
[("int", M.IGNORE), |
| 83 |
("int32", M.IGNORE), |
| 84 |
("intinf", M.IGNORE), |
| 85 |
("word", M.IGNORE), |
| 86 |
("word32", M.IGNORE), |
| 87 |
("label", M.IGNORE), |
| 88 |
("cells", M.MULTI "x"), |
| 89 |
("cell", M.CONV "x"), |
| 90 |
("cellset", M.MULTI("C.cellSet.get C."^id^" x")), |
| 91 |
("operand", M.IGNORE) (* XXX *) |
| 92 |
] |
| 93 |
|
| 94 |
fun defUse(x,exp,L) = |
| 95 |
if M.ofCellKind(exp,cellKind) then SOME(get(x,exp,L)) |
| 96 |
else NONE |
| 97 |
|
| 98 |
in RTLComp.mkDefUseQuery compiled_rtls |
| 99 |
{name="defUse"^id, |
| 100 |
decls=[decl], |
| 101 |
args=[["instr"]], |
| 102 |
namedArguments=false, |
| 103 |
def=defUse, |
| 104 |
use=defUse |
| 105 |
} |
| 106 |
end |
| 107 |
|
| 108 |
val defUseFuns = SEQdecl(Comp.forallUserCellKinds md mkDefUse) |
| 109 |
val defUse = Comp.mkQueryByCellKind md "defUse" |
| 110 |
|
| 111 |
(* The functor *) |
| 112 |
val strBody = |
| 113 |
[$ ["structure I = I", |
| 114 |
"structure C = I.C", |
| 115 |
"structure LE = LabelExp", |
| 116 |
"", |
| 117 |
"exception NegateConditional", |
| 118 |
"" |
| 119 |
], |
| 120 |
Comp.errorHandler md "Props", |
| 121 |
typeDefs, |
| 122 |
instrKind, |
| 123 |
moveInstr, |
| 124 |
moveTmpR, |
| 125 |
moveDstSrc, |
| 126 |
nop, |
| 127 |
jump, |
| 128 |
loadImmed, |
| 129 |
branchTargets, |
| 130 |
setTargets, |
| 131 |
negateConditional, |
| 132 |
immedRange, |
| 133 |
loadOperand, |
| 134 |
eqOpn, |
| 135 |
hashOpn, |
| 136 |
defUseFuns, |
| 137 |
defUse, |
| 138 |
funDefs |
| 139 |
] |
| 140 |
|
| 141 |
in Comp.codegen md "instructions/Props2" |
| 142 |
[Comp.mkFct md "Props2" args sigName strBody |
| 143 |
] |
| 144 |
end |
| 145 |
end |