summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-12-09 23:56:48 +0100
committerPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-12-09 23:56:48 +0100
commit4c7ca4031d431af712bbdd9b0dbc9b3e069280e4 (patch)
tree7f534d2a7fae212af718cae99d9456b7e6decf4b /source
parentTranslate: Basic expressions and statements (diff)
Ifs
Diffstat (limited to 'source')
-rw-r--r--source/mod_student/translator.ml24
1 files changed, 22 insertions, 2 deletions
diff --git a/source/mod_student/translator.ml b/source/mod_student/translator.ml
index 6831038..c755cdb 100644
--- a/source/mod_student/translator.ml
+++ b/source/mod_student/translator.ml
@@ -202,7 +202,20 @@ module Make() = struct
| Ast.EXPR_Bool {value=false; _} ->
set_jump current_bb else_bb;
allocate_block ()
-
+ | Ast.EXPR_Binop {op=Ast.BINOP_And;lhs;rhs;_} ->
+ let current_bb = translate_condition env current_bb else_bb lhs in
+ let current_bb = translate_condition env current_bb else_bb rhs in
+ current_bb
+
+
+
+ | Ast.EXPR_Binop {op=Ast.BINOP_Or;lhs;rhs;_} ->
+ let bb = allocate_block() in
+ let current_bb = translate_condition env current_bb bb lhs in
+ let current_bb = translate_condition env bb else_bb in
+ bb
+
+
(* Zaimplementuj dodatkowe przypadki *)
| e ->
@@ -243,7 +256,14 @@ module Make() = struct
append_instruction current_bb @@ I_Move (my_reg, reg);
current_bb, (Environment.add_var id my_reg env)
| STMT_Call call ->
- translate_call env current_bb call []
+ translate_call env current_bb call []
+ | STMT_If {cond;then_branch;else_branch;_} ->
+ let end_bb =allocate_block() in
+ let else_bb = allocate_block() in
+ let current_bb = translate_condition env current_bb else_bb cond in
+ set_jump current_bb end_bb;
+ set_jump else_bb end_bb;
+ end_bb,env
| _ ->
failwith "not yet implemented"