Debian Codegraph @

lib/mlrisc-lib/MLRISC/gc-safety/gc-type-system.sml

raw
1 (*
2 * This signature describes the interface to a gc type system.
3 * This encapsulates everything dealing with GC safety analysis
4 * into one single signature.
5 *)
6 functor GCTypeSystem
7 (structure GC : GC_TYPE
8 structure RTL : MLTREE_RTL
9 val isRecoverable : GC.gctype -> bool
10 ) : GC_TYPE_SYSTEM =
11 struct
12 structure GC = GC
13 structure RTL = RTL
14 structure T = RTL.T
15
16 fun error msg = MLRiscErrorMsg.error("GCTypeSystem",msg)
17
18 fun typeOf lookup =
19 let fun T(T.REG(t,r)) = lookup r
20 | T(T.LI i) = GC.CONST i
21 | T(T.CONST c) = GC.INT
22 | T(T.LABEL l) = GC.INT
23 | T(T.NEG(t,a)) = unaryArith(t,a)
24 | T(T.ADD(t,a,b)) = GC.ADD(t,T a,T b)
25 | T(T.SUB(t,a,b)) = GC.SUB(t,T a,T b)
26 | T(T.MULS(t,a,b)) = binaryArith(t,a,b)
27 | T(T.DIVS(t,a,b)) = binaryArith(t,a,b)
28 | T(T.QUOTS(t,a,b)) = binaryArith(t,a,b)
29 | T(T.REMS(t,a,b)) = binaryArith(t,a,b)
30 | T(T.MULU(t,a,b)) = binaryArith(t,a,b)
31 | T(T.DIVU(t,a,b)) = binaryArith(t,a,b)
32 | T(T.REMU(t,a,b)) = binaryArith(t,a,b)
33 | T(T.NEGT(t,a)) = unaryArith(t,a)
34 | T(T.ADDT(t,a,b)) = binaryArith(t,a,b)
35 | T(T.SUBT(t,a,b)) = binaryArith(t,a,b)
36 | T(T.MULT(t,a,b)) = binaryArith(t,a,b)
37 | T(T.DIVT(t,a,b)) = binaryArith(t,a,b)
38 | T(T.REMT(t,a,b)) = binaryArith(t,a,b)
39 | T(T.QUOTT(t,a,b)) = binaryArith(t,a,b)
40 | T(T.ANDB(t,a,b)) = binaryArith(t,a,b)
41 | T(T.ORB(t,a,b)) = binaryArith(t,a,b)
42 | T(T.XORB(t,a,b)) = binaryArith(t,a,b)
43 | T(T.SLL(t,a,b)) = binaryArith(t,a,b)
44 | T(T.SRA(t,a,b)) = binaryArith(t,a,b)
45 | T(T.SRL(t,a,b)) = binaryArith(t,a,b)
46 | T(T.NOTB(t,a)) = unaryArith(t,a)
47 | T(T.LOAD(t,ea,_)) = GC.TOP
48 | T(T.COND(t,a,b,c)) = GC.TOP
49 | T(T.SX _) = GC.TOP
50 | T(T.ZX _) = GC.TOP
51 | T(T.PRED(e, _)) = T e
52 (*| T(T.REXT(t,RTL.OP(misc_op,es))) = GC.INT
53 | T(T.REXT(t,RTL.FETCH(RTL.AGG(_,_,RTL.CELL(k,ty,e,_))))) = GC.TOP*)
54 | T(e) = error("typeOf: "^ RTL.expToString e)
55
56 and binaryArith(t,a,b) =
57 let val ta = T(a)
58 val tb = T(b)
59 in GC.join(ta,tb) end
60
61 and unaryArith(t,a) = T(a)
62 in T
63 end
64
65 (*
66 * Compute the effect
67 *)
68 fun effectOf{lookup, update} {action, dst, src, effect} =
69 let fun err() = error("effectOf: "^ RTL.rtlToString action)
70
71 (* Note the parallel copy semantics! *)
72 fun copy(dst, src, e) =
73 let fun upd([], [], e) = e
74 | upd(d::dst,t::tys,e) = upd(dst, tys, update(d, t, e))
75 | upd _ = error "copy"
76 in upd(dst, map lookup src, e) end
77
78 fun E(T.COPY _,e) = copy(dst,src,e)
79 | E(T.RTL{e=s,...},e) = E(s,e)
80 | E(T.REGION(s,_),e) = E(s,e)
81 | E(T.SEQ [],e) = e
82 | E(T.JMP _, e) = e
83 | E(T.CALL _,e) = e
84 | E(T.RET _,e) = e
85 | E(T.MV(t,x,exp), e) = update(x, typeOf lookup exp, e)
86 | E(T.IF(x,y,z), e) = e
87 | E(T.STORE _, e) = e
88 (*| E(T.EXT(RTL.ASSIGN(loc,exp)),e) =
89 let val t = typeOf lookup exp
90 in case loc of
91 RTL.AGG(_,_,RTL.CELL("FP",_,T.REG(_,x),_)) =>
92 update(x, GC.REAL64, e)
93 | RTL.AGG(_,_,RTL.CELL(_,_,T.REG(_,x),_)) =>
94 update(x, GC.TOP, e)
95 | RTL.AGG(_,_,_) => e
96 end
97 | E(T.EXT(RTL.PAR(a,b)), e) = E(b,E(a,e))*)
98 | E(rtl, e) = err()
99 in E(action, effect) end
100
101 val isRecoverable = isRecoverable
102 end