Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /trunk/src/compiler/IL/ssa-pp-fn.sml
ViewVC logotype

Diff of /trunk/src/compiler/IL/ssa-pp-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 198, Mon Aug 2 21:26:57 2010 UTC revision 267, Wed Aug 11 04:40:44 2010 UTC
# Line 8  Line 8 
8    
9  functor SSAPPFn (IL : SSA) : sig  functor SSAPPFn (IL : SSA) : sig
10    
11        val output : TextIO.outstream * IL.program -> unit
12    
13    end = struct    end = struct
14    
15        structure Op = IL.Op
16        structure Var = IL.Var
17    
18        fun indent (outS, i) = TextIO.output(outS, StringCvt.padLeft #" " i "")
19        fun incIndent (outS, i) = (outS, i+2)
20        fun pr ((outS, _), s) = TextIO.output(outS, s)
21        fun prl (out, l) = pr(out, concat l)
22    
23        fun ppRHS (out, IL.VAR x) = pr(out, Var.toString x)
24          | ppRHS (out, IL.LIT lit) = pr(out, Literal.toString lit)
25          | ppRHS (out, IL.OP(rator, [])) = pr(out, Op.toString rator)
26          | ppRHS (out, IL.OP(rator, args)) = prl (out, [
27                Op.toString rator, "(", String.concatWith "," (List.map Var.toString args), ")"
28              ])
29          | ppRHS (out, IL.CONS xs) =
30              prl (out, ["[", String.concatWith "," (List.map Var.toString xs), "]"])
31    
32        fun labelOf (IL.STM{id, ...}) = "L"^Stamp.toString id
33    
34        fun ppStmt (out, stm as IL.STM{id, kind, next, ...}) = let
35              val out1 = incIndent out
36              fun prPhi (y, xs) = (
37                    indent out1;
38                    prl (out1, [
39                        Var.toString y, " = phi(",
40                        String.concatWith "," (List.map Var.toString xs), ")\n"
41                      ]))
42              in
43                indent out;
44                prl (out, [
45                    IL.Stmt.toString stm, "(", IL.Node.toString(IL.Stmt.entry stm), "):  # preds = [",
46                    String.concatWith "," (List.map IL.Node.toString (IL.Node.preds(IL.Stmt.entry stm))),
47                    "]\n"
48                  ]);
49                case kind
50                 of IL.S_SIMPLE(IL.ND{kind, ...}) => (case kind
51                       of IL.NULL => raise Fail "unexpected S_SIMPLE with NULL node"
52                        | IL.ENTRY _ => (indent out1; pr(out1, "entry;\n"))
53                        | IL.JOIN{phis, ...} => List.app prPhi (!phis)
54                        | IL.COND _ => raise Fail "unexpected S_SIMPLE with COND node"
55                        | IL.BLOCK{body=ref [], ...} => (indent out1; pr (out, "empty;\n"))
56                        | IL.BLOCK{body, ...} => (
57                            List.app
58                              (fn (y, rhs) => (
59                                  indent out1;
60                                  prl(out1, [Var.toString y, " = "]); ppRHS(out1, rhs); pr(out1, ";\n"))
61                              ) (!body))
62                        | IL.NEW{actor, args, ...} => (
63                            indent out1;
64                            prl (out1, [
65                                "new ", Atom.toString actor, "(",
66                                String.concatWith "," (List.map Var.toString args), ");\n"
67                              ]))
68                        | IL.DIE _ => (indent out1; pr(out1, "die;\n"))
69                        | IL.STABILIZE _ => (indent out1; pr(out1, "stabilize;\n"))
70                        | IL.EXIT _ => (indent out1; pr(out1, "exit;\n"))
71                      (* end case *))
72                  | IL.S_IF{cond=IL.ND{kind=IL.COND{cond, ...}, ...}, thenBranch, elseBranch} => (
73                      indent out1;  prl(out1, ["if ", Var.toString cond, " then\n"]);
74                      ppStmt (incIndent out1, thenBranch);
75                      indent out1; pr(out1, "else\n");
76                      ppStmt (incIndent out1, elseBranch);
77                      indent out1; pr(out1, "endif;\n"))
78                  | IL.S_LOOP _ => raise Fail "LOOP"
79                (* end case *);
80                ppNext (out, next)
81              end
82    
83        and ppNext (out, NONE) = ()
84          | ppNext (out, SOME stm) = ppStmt (out, stm)
85    
86        fun ppMethod (out, IL.Method{name, stateIn, stateOut, body}) = let
87              val out1 = incIndent out
88              fun prVars xs = List.app (fn x => prl(out, [" ", Var.toString x])) xs
89              in
90                indent out; prl(out, ["method ", Atom.toString name, "\n"]);
91                indent out1; pr(out1, "state in: "); prVars stateIn; pr(out1, "\n");
92                ppStmt (incIndent out1, body);
93                indent out1; pr(out1, "state out:"); prVars stateOut; pr(out1, "\n");
94                indent out; prl(out, ["end ", Atom.toString name, "\n"])
95              end
96    
97        and ppActor (out, IL.Actor{name, params, state, stateInit, methods}) = let
98              val out1 = incIndent out
99              fun prVars xs = List.app (fn x => prl(out, [" ", Var.toString x])) xs
100              in
101                indent out;
102                prl(out, [
103                    "actor ", Atom.toString name, " (",
104                    String.concatWith "," (List.map Var.toString params), ")\n"
105                  ]);
106                indent out1; pr(out1, "state: "); prVars state; pr(out1, "\n");
107                ppStmt (incIndent out1, stateInit);
108                List.app (fn m => ppMethod(out1, m)) methods;
109                indent out; prl(out, ["end ", Atom.toString name, "\n"])
110              end
111    
112        fun output (outS, IL.Program{globals, globalInit, actors}) = let
113              val out = (outS, 0)
114              val out1 = incIndent out
115              in
116                pr (out, "## globals\n");
117                List.app (fn x => (indent out1; prl(out1, ["global ", Var.toString x, "\n"]))) globals;
118                pr (out, "## global initialization\n");
119                ppStmt (out1, globalInit);
120                pr (out, "## actors\n");
121                List.app (fn actor => ppActor(out1, actor)) actors;
122                pr (out, "## end program")
123              end
124    
125    end    end

Legend:
Removed from v.198  
changed lines
  Added in v.267

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0