From 4c7ca4031d431af712bbdd9b0dbc9b3e069280e4 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 9 Dec 2018 23:56:48 +0100 Subject: Ifs --- source/mod_student/translator.ml | 24 ++++++++++++++++++++++-- 1 file 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" -- cgit 1.4.1