File: mdl-gen-insnprops.sml

package info (click to toggle)
mlton 20210117%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,464 kB
  • sloc: ansic: 27,682; sh: 4,455; asm: 3,569; lisp: 2,879; makefile: 2,347; perl: 1,169; python: 191; pascal: 68; javascript: 7
file content (145 lines) | stat: -rw-r--r-- 4,400 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
(*
 * Generate the <arch>Props functor.
 * This structure extracts information about the instruction set.
 *)

functor MDLGenInsnProps(RTLComp : MDL_RTL_COMP) : MDL_GEN_MODULE2 =
struct

   structure RTLComp  = RTLComp
   structure Comp     = RTLComp.Comp
   structure Ast      = Comp.Ast
   structure M        = RTLComp.MLRiscTypes

   open Ast Comp.Util

   val typeDefs = 
       $ ["(* classify instructions *)",
          "datatype kind = IK_JUMP   (* branches, including returns *)",
          "  | IK_NOP    (* no ops *)",
          "  | IK_INSTR  (* normal instructions *)",
          "  | IK_COPY   (* parallel copy *)",
          "  | IK_CALL   (* call instructions *)",
          "  | IK_PHI    (* A phi node (SSA) *)",
          "  | IK_SINK   (* A sink node (SSA) *)",
          "  | IK_SOURCE (* A source node (SSA) *)",
          "",
          "datatype target = LABELLED of Label.label",
          "                | FALLTHROUGH" ,
          "                | ESCAPES",
          "",
          "exception NegateCondtional",
          ""
         ]

   val funDefs = 
       $ ["fun getAnnotations(I.ANNOTATION{i,a}) =",
          "    let val (i,an) = getAnnotations i in (i,a::an) end",
          "  | getAnnotations i = (i,[])",
          "fun annotate(i,a) = I.ANNOTATION{i=i,a=a}"
         ]
 
   fun gen compiled_rtls =
   let val md      = RTLComp.md compiled_rtls

       (* name of the structure/signature *)
       val strName = Comp.strname md "Props"  
       val sigName = "INSN_PROPERTIES"

       (* The instructions *)
       val instructions = Comp.instructions md

       (* Arguments to the instruction functor *)
       val args =
           ["I : "^Comp.signame md "INSTR"
           ]

       (* Function that determines the type of an instruction *)
       val instrKind  = DUMMYfun "instrKind"

       (* Functions for dealing with parallel copies *)
       val moveInstr  = DUMMYfun "moveInstr"
       val moveTmpR   = DUMMYfun "moveTmpR"
       val moveDstSrc = DUMMYfun "moveDstSrc"

       val nop        = DUMMYfun "nop"
       val jump       = DUMMYfun "jump"

       val loadImmed  = DUMMYfun "loadImmed"

       val branchTargets = DUMMYfun "branchTargets"
       val setTargets    = DUMMYfun "setTargets"

       val negateConditional  = DUMMYfun "negateConditional"
       val immedRange    = DUMMYfun "immedRange"
       val loadOperand   = DUMMYfun "loadOperand"

       val eqOpn         = DUMMYfun "eqOpn"
       val hashOpn       = DUMMYfun "hashOpn"

       fun mkDefUse(cellKind as CELLdecl{id, ...}) = 
       let val {get, decl} = M.getOpnd
                [("int", M.IGNORE),
                 ("int32", M.IGNORE),
                 ("intinf", M.IGNORE),
                 ("word", M.IGNORE),
                 ("word32", M.IGNORE),
                 ("label", M.IGNORE),
                 ("cells", M.MULTI "x"),
                 ("cell", M.CONV "x"),
                 ("cellset", M.MULTI("C.cellSet.get C."^id^" x")),
                 ("operand", M.IGNORE) (* XXX *)
                ]

           fun defUse(x,exp,L) = 
               if M.ofCellKind(exp,cellKind) then SOME(get(x,exp,L))
               else NONE

       in  RTLComp.mkDefUseQuery compiled_rtls 
             {name="defUse"^id,
              decls=[decl],
              args=[["instr"]],
              namedArguments=false,
              def=defUse,
              use=defUse
             }
       end

       val defUseFuns = SEQdecl(Comp.forallUserCellKinds md mkDefUse)
       val defUse     = Comp.mkQueryByCellKind md "defUse"

       (* The functor *)
       val strBody = 
           [$ ["structure I  = I",
               "structure C  = I.C",
               "structure LE = LabelExp",
               "",
               "exception NegateConditional",
               ""
              ],
            Comp.errorHandler md "Props",
            typeDefs,
            instrKind,
            moveInstr,
            moveTmpR,
            moveDstSrc,
            nop,
            jump,
            loadImmed,
            branchTargets,
            setTargets,
            negateConditional,
            immedRange,
            loadOperand,
            eqOpn,
            hashOpn,
            defUseFuns,
            defUse,
            funDefs
           ]

   in  Comp.codegen md "instructions/Props2"
         [Comp.mkFct md "Props2" args sigName strBody
         ]
   end
end