]> Joshua Wise's Git repositories - snipe.git/blobdiff - trans/tree.sml
Initial import of l4c
[snipe.git] / trans / tree.sml
index f69cefb8a4026964c6e02062b54212dcd93bb2ab..d3e8c0d1ecc4f5869c0a3b5cdcb57dbceed20cc3 100644 (file)
@@ -1,8 +1,10 @@
-(* L2 Compiler
+(* L3 Compiler
  * IR Trees
  * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
  * Modified: Alex Vaynberg <alv@andrew.cmu.edu>
  * Modified: Frank Pfenning <fp@cs.cmu.edu>
+ * Modified: Joshua Wise <jwise>
+ * Modified: Chris Lu <czl>
  *)
 
 signature TREE =
@@ -11,19 +13,28 @@ sig
   datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE
   datatype unop = NEG | BITNOT | BANG
 
+  type Blarg = int
+
   datatype exp = 
       CONST of Word32.word
     | TEMP of Temp.temp
+    | ARG of Blarg * int (* I am j4cbo *)
     | BINOP of binop * exp * exp
     | UNOP of unop * exp
+    | CALL of Ast.ident * (exp * int) list * int
+    | MEMORY of exp
+    | ALLOC of exp
   and stm =
-      MOVE of exp * exp
-    | RETURN of exp
+      MOVE of exp * exp * int
+    | RETURN of exp * int
+    | EFFECT of exp * int
     | LABEL of Label.label
     | JUMPIFN of exp * Label.label
     | JUMP of Label.label
+  and func =
+      FUNCTION of Ast.ident * stm list
 
-  type program = stm list
+  type program = func list
 
   structure Print :
   sig
@@ -39,23 +50,34 @@ struct
   datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE
   datatype unop = NEG | BITNOT | BANG
 
+  type Blarg = int
+
   datatype exp = 
       CONST of Word32.word
     | TEMP of Temp.temp
+    | ARG of Blarg * int
     | BINOP of binop * exp * exp
     | UNOP of unop * exp
+    | CALL of Ast.ident * (exp * int) list * int
+    | MEMORY of exp
+    | ALLOC of exp
   and stm =
-      MOVE of exp * exp
-    | RETURN of exp
+      MOVE of exp * exp * int
+    | RETURN of exp * int
+    | EFFECT of exp * int
     | LABEL of Label.label
     | JUMPIFN of exp * Label.label
     | JUMP of Label.label
+  and func =
+      FUNCTION of Ast.ident * stm list
 
-  type program = stm list
+  type program = func list
 
   structure Print = 
   struct
 
+    exception Aaaasssssss
+
     fun pp_binop ADD = "+"
       | pp_binop SUB = "-"
       | pp_binop MUL = "*"
@@ -81,15 +103,21 @@ struct
 
     fun pp_exp (CONST(x)) = Word32Signed.toString x
       | pp_exp (TEMP(t)) = Temp.name t
+      | pp_exp (ARG(n, sz)) = "arg#"^Int.toString n
       | pp_exp (BINOP (binop, e1, e2)) =
          "(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")"
       | pp_exp (UNOP (unop, e1)) =
           pp_unop unop ^ "(" ^ pp_exp e1 ^ ")"
+      | pp_exp (CALL (f, l, sz)) =
+          Symbol.name f ^ "(" ^ (String.concatWith ", " (List.map (fn (e, _) => pp_exp e) l)) ^ ")"
+      | pp_exp (MEMORY exp) = "M[" ^ pp_exp exp ^ "]"
+      | pp_exp (ALLOC(e)) = "NEW(" ^ pp_exp e ^ ")"
 
-    fun pp_stm (MOVE (e1,e2)) =
+    fun pp_stm (MOVE (e1,e2, sz)) =
          pp_exp e1 ^ "  <--  " ^ pp_exp e2
-      | pp_stm (RETURN e) =
+      | pp_stm (RETURN (e, sz)) =
          "return " ^ pp_exp e
+      | pp_stm (EFFECT (e, sz)) = pp_exp e
       | pp_stm (LABEL l) =
           Label.name l ^ ":"
       | pp_stm (JUMP l) = 
@@ -98,6 +126,11 @@ struct
           "jump "^Label.name l^" if! "^pp_exp e
 
     fun pp_program (nil) = ""
-      | pp_program (stm::stms) = pp_stm stm ^ "\n" ^ pp_program stms
+      | pp_program (FUNCTION(id, stms)::funcs) =
+          (Symbol.name id) ^
+          "\n{\n" ^
+          (foldr (fn (a,b) => (pp_stm a) ^ "\n" ^ b) "" stms) ^
+          "}\n" ^
+          pp_program funcs
   end
 end
This page took 0.02511 seconds and 4 git commands to generate.