SCM Repository
Annotation of /trunk/src/compiler/translate/translate.sml
Parent Directory
|
Revision Log
Revision 189 - (view) (download)
1 : | jhr | 137 | (* translate.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | jhr | 176 | * Translate Simple-AST code into the IL representation. |
7 : | jhr | 137 | *) |
8 : | |||
9 : | structure Translate : sig | ||
10 : | |||
11 : | jhr | 176 | val translate : Simple.program -> HighIL.program |
12 : | jhr | 137 | |
13 : | end = struct | ||
14 : | |||
15 : | jhr | 176 | structure S = Simple |
16 : | jhr | 137 | structure VMap = Var.Map |
17 : | jhr | 189 | structure VSet = Var.Set |
18 : | jhr | 168 | structure IL = HighIL |
19 : | jhr | 137 | |
20 : | jhr | 176 | fun lookup env x = (case VMap.find x |
21 : | of SOME x' => x' | ||
22 : | | NONE => raise Fail(concat[ | ||
23 : | "no binding for ", Var.toString x, " in environment" | ||
24 : | ]) | ||
25 : | (* end case *)) | ||
26 : | |||
27 : | jhr | 189 | (* create a new instance of a variable *) |
28 : | fun newVar x = IL.newVar (Var.nameOf x) | ||
29 : | |||
30 : | jhr | 168 | (* expression translation *) |
31 : | jhr | 188 | fun cvtExpr (env, lhs, exp) = (case exp |
32 : | of S.E_Var x => [(lhs, IL.VAR(lookup env x))] | ||
33 : | | S.E_Lit lit => [(lhs, IL.LIT lit)] | ||
34 : | jhr | 176 | | S.E_Tuple xs => raise Fail "E_Tuple not implemeted" |
35 : | jhr | 188 | | S.E_Apply(f, tyArgs, args, ty) => let |
36 : | val args' = List.map (lookup env) args | ||
37 : | in | ||
38 : | TranslateBasis.translate (lhs, f, tyArgs, args') | ||
39 : | end | ||
40 : | | S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))] | ||
41 : | jhr | 176 | (* end case *)) |
42 : | jhr | 168 | |
43 : | jhr | 189 | (* convert a statement, where env is the mapping from Simple AST variables to |
44 : | * their current SSA name, assigned is the set of AST variables assigned to | ||
45 : | * in the current context, and stm is the statement to convert. | ||
46 : | *) | ||
47 : | and cvtStmt (env, assigned, stm, preStms, k) = (case stm | ||
48 : | jhr | 176 | of S.S_Block stms => |
49 : | jhr | 189 | | S.S_Assign(x, e) => let |
50 : | val x' = newVar x | ||
51 : | val stms = cvtExp(env, x', e) | ||
52 : | val assigned = VSet.add(assigned, x) | ||
53 : | val env = VMap.insert(env, x, x') | ||
54 : | in | ||
55 : | k (env, assigned, stm::preStms) | ||
56 : | end | ||
57 : | jhr | 176 | | S.S_IfThenElse(x, s1, s2) => |
58 : | | S.S_New(name, xs) => | ||
59 : | | S.S_Die => | ||
60 : | | S.S_Stabilize => | ||
61 : | jhr | 168 | (* end case *)) |
62 : | |||
63 : | jhr | 176 | fun translate (S.Program{globals, globaInit, actors}) = ?? |
64 : | |||
65 : | jhr | 137 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |