]> Joshua Wise's Git repositories - snipe.git/blobdiff - trans/tree.sml
Initial import of l2c
[snipe.git] / trans / tree.sml
index 1cfc4eb7670904079027a932209cfd46fa628633..f69cefb8a4026964c6e02062b54212dcd93bb2ab 100644 (file)
@@ -1,4 +1,4 @@
-(* L1 Compiler
+(* L2 Compiler
  * IR Trees
  * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
  * Modified: Alex Vaynberg <alv@andrew.cmu.edu>
@@ -8,15 +8,20 @@
 signature TREE =
 sig
 
-  datatype binop = ADD | SUB | MUL | DIV | MOD
+  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
 
   datatype exp = 
       CONST of Word32.word
     | TEMP of Temp.temp
     | BINOP of binop * exp * exp
+    | UNOP of unop * exp
   and stm =
       MOVE of exp * exp
     | RETURN of exp
+    | LABEL of Label.label
+    | JUMPIFN of exp * Label.label
+    | JUMP of Label.label
 
   type program = stm list
 
@@ -31,15 +36,20 @@ end
 structure Tree :> TREE =
 struct
 
-  datatype binop = ADD | SUB | MUL | DIV | MOD
+  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
 
   datatype exp = 
       CONST of Word32.word
     | TEMP of Temp.temp
     | BINOP of binop * exp * exp
+    | UNOP of unop * exp
   and stm =
       MOVE of exp * exp
     | RETURN of exp
+    | LABEL of Label.label
+    | JUMPIFN of exp * Label.label
+    | JUMP of Label.label
 
   type program = stm list
 
@@ -51,16 +61,41 @@ struct
       | pp_binop MUL = "*"
       | pp_binop DIV = "/"
       | pp_binop MOD = "%"
+      | pp_binop LSH = "<<"
+      | pp_binop RSH = ">>"
+      | pp_binop LOGOR = "||"
+      | pp_binop LOGAND = "&&"
+      | pp_binop BITOR = "|"
+      | pp_binop BITAND = "&"
+      | pp_binop BITXOR = "^"
+      | pp_binop NEQ = "!="
+      | pp_binop EQ = "=="
+      | pp_binop LE = "<="
+      | pp_binop LT = "<"
+      | pp_binop GE = ">="
+      | pp_binop GT = ">"
+    
+    fun pp_unop NEG = "-"
+      | pp_unop BITNOT = "~"
+      | pp_unop BANG = "!"
 
     fun pp_exp (CONST(x)) = Word32Signed.toString x
       | pp_exp (TEMP(t)) = Temp.name t
       | 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 ^ ")"
 
     fun pp_stm (MOVE (e1,e2)) =
          pp_exp e1 ^ "  <--  " ^ pp_exp e2
       | pp_stm (RETURN e) =
          "return " ^ pp_exp e
+      | pp_stm (LABEL l) =
+          Label.name l ^ ":"
+      | pp_stm (JUMP l) = 
+          "jump "^Label.name l
+      | pp_stm (JUMPIFN (e, l)) =
+          "jump "^Label.name l^" if! "^pp_exp e
 
     fun pp_program (nil) = ""
       | pp_program (stm::stms) = pp_stm stm ^ "\n" ^ pp_program stms
This page took 0.024216 seconds and 4 git commands to generate.