| 1 |
|
| 2 |
structure LLV = |
| 3 |
struct |
| 4 |
|
| 5 |
datatype place = P of int |
| 6 |
|
| 7 |
datatype info = Info1 | Info2 | Info3 |
| 8 |
|
| 9 |
datatype 'a tr = TR of 'a exp * info | K of 'a -> int |
| 10 |
and 'a exp = SWITCH_I of ('a, int) switch |
| 11 |
| SWITCH_S of ('a, string) switch |
| 12 |
| STRING of string * 'a |
| 13 |
and ('a,'c) switch = SWITCH of 'a tr * ('c * 'a tr) list |
| 14 |
|
| 15 |
datatype 'a pgm = PGM of string * 'a tr |
| 16 |
|
| 17 |
type mulexp = place exp |
| 18 |
and multrip = place tr |
| 19 |
type mulexp_llv = (place*int) exp |
| 20 |
and trip_llv = (place*int) tr |
| 21 |
|
| 22 |
fun llv(tr: multrip as TR(e,Info1)) : trip_llv = |
| 23 |
let |
| 24 |
val e' = llvExp e |
| 25 |
in |
| 26 |
TR(e',Info2) |
| 27 |
end |
| 28 |
|
| 29 |
and llvExp(e: mulexp) : mulexp_llv = |
| 30 |
let |
| 31 |
fun llv_switch(SWITCH(e,branches)) = |
| 32 |
(* Note: e is trivial *) |
| 33 |
let val branches' = map (fn (c,e) => (c,llv e)) branches |
| 34 |
in |
| 35 |
SWITCH(llv e, branches') |
| 36 |
end |
| 37 |
in |
| 38 |
case e of |
| 39 |
SWITCH_I(switch) => |
| 40 |
let val switch' = llv_switch switch |
| 41 |
in SWITCH_I(switch') |
| 42 |
end |
| 43 |
| SWITCH_S(switch) => |
| 44 |
let val switch' = llv_switch switch |
| 45 |
in SWITCH_S(switch') |
| 46 |
end |
| 47 |
| STRING(s,place) => STRING(s, (place, 5)) |
| 48 |
end |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
val llv = fn (PGM (label,expression)) => |
| 53 |
let |
| 54 |
val tr' = llv expression |
| 55 |
in |
| 56 |
PGM(label, tr') |
| 57 |
end |
| 58 |
|
| 59 |
end |
| 60 |
|
| 61 |
|