Commits

Paweł Wieczorek committed 29b9de1

Added calls to TAC, added some code for comparing trees

Comments (0)

Files changed (1)

source/Lang/TAC/AST.ml

  ********************************************************************************************************************)
 
 type atom
-    = ATOM_Variable of label * variable
-    | ATOM_Constant of label * int
+    = ATOM_Variable of variable
+    | ATOM_Constant of int
 
 type arithmetic_expression
     = AEXPR_Atom of label * atom
     | STMT_Label of label * identifier
     | STMT_Assign of label * lvalue * rvalue
     | STMT_Goto of label * identifier
+    | STMT_Call of label * variable option * identifier * atom list
+    | STMT_Return of label * variable option
 
 type statement_block
     = STMTBLOCK_Group of label * statement list
  ********************************************************************************************************************)
 
 let eq_atom atom1 atom2 = match atom1, atom2 with
-    | ATOM_Variable (_, var1)
-    , ATOM_Variable (_, var2) ->
+    | ATOM_Variable (var1)
+    , ATOM_Variable (var2) ->
         var1 = var2
 
-    | ATOM_Constant (_, const1)
-    , ATOM_Constant (_, const2) ->
+    | ATOM_Constant (const1)
+    , ATOM_Constant (const2) ->
         const1 = const2
 
     | _ ->
     | _ ->
         false
 
-let eq_boolean_expression bexpr1 bexpr2 = 
-    Error.not_yet_implemented "eq_boolean_expression"
+let eq_boolean_expression ?(eq_atom=eq_atom) ?(eq_arithmetic_expression=eq_arithmetic_expression) bexpr1 bexpr2 =
+    match bexpr1, bexpr2 with
+    | BEXPR_Constant (_, c1)
+    , BEXPR_Constant (_, c2) ->
+        c1 = c2
+
+    | BEXPR_UnaryOperator(_, op1, atom1)
+    , BEXPR_UnaryOperator(_, op2, atom2)
+    when op1 = op2 ->
+        eq_atom atom1 atom2
+
+    | BEXPR_BinaryOperator(_, op1, atom1a, atom1b)
+    , BEXPR_BinaryOperator(_, op2, atom2a, atom2b)
+    when op1 = op2 ->
+        eq_atom atom1a atom2a && eq_atom atom1b atom2b
 
 let eq_lvalue lval1 lval2 =
     Error.not_yet_implemented "eq_lvalue"