diff --git a/src/ast_to_c.ml b/src/ast_to_c.ml index dbdbd5e..15db7fb 100644 --- a/src/ast_to_c.ml +++ b/src/ast_to_c.ml @@ -236,11 +236,15 @@ let cp_init_aux_nodes fmt (node, h) = | None -> () (** All auxiliary nodes have been initialized *) | Some n -> begin - Format.fprintf fmt "%a\t\tstate->aux_states[%d] = malloc (sizeof (%s));\n\ - \t\t((%s*)(state->aux_states[%d]))->is_init = true;\n" + Format.fprintf fmt "%a\t\tif(!state->is_reset) {\n\ + \t\t\tstate->aux_states[%d] = malloc (sizeof (%s));\n\ + \t\t}\n\ + \t\t((%s*)(state->aux_states[%d]))->is_init = true;\n\ + \t\t((%s*)(state->aux_states[%d]))->is_reset = state->is_reset;\n" aux (node, nst, i-1) (i-1) (Format.asprintf "t_state_%s" n.n_name) (Format.asprintf "t_state_%s" n.n_name) (i-1) + (Format.asprintf "t_state_%s" n.n_name) (i-1) end in let nst = Hashtbl.find h node.in_name in diff --git a/src/cprint.ml b/src/cprint.ml index 759c1c2..3837d2c 100644 --- a/src/cprint.ml +++ b/src/cprint.ml @@ -19,7 +19,7 @@ let cp_node_state fmt (st: node_state) = if st.nt_count_app = 0 then Format.fprintf fmt "typedef struct {%a%a%a\n\ - \tbool is_init;\n\ + \tbool is_init, is_reset;\n\ } %s;\n\n" print_if_any ("int", st.nt_nb_int, "ivars") print_if_any ("bool", st.nt_nb_bool, "bvars") @@ -27,7 +27,7 @@ let cp_node_state fmt (st: node_state) = st.nt_name else Format.fprintf fmt "typedef struct {%a%a%a\n\ - \tbool is_init;\n\ + \tbool is_init, is_reset;\n\ \tvoid* aux_states[%d]; /* stores the states of auxiliary nodes */\n\ } %s;\n\n" print_if_any ("int", st.nt_nb_int, "ivars") @@ -191,10 +191,16 @@ and cp_expression fmt (expr, hloc) = end | CReset (node_name, i, v, b) -> begin - Format.fprintf fmt "\tif (%a) {\n\t\t((t_state_%s*)(state->aux_states[%d]))->is_init = true;\n\t}\n%a\n" + Format.fprintf fmt "\tif (%a) {\n\ + \t\t((t_state_%s*)(state->aux_states[%d]))->is_init = true;\n\ + \t\t((t_state_%s*)(state->aux_states[%d]))->is_reset = true;\n\ + \t}\n\ + %a\n" cp_value (v, hloc) node_name (i - 1) + node_name + (i - 1) cp_block (b, hloc) end | CIf (v, b1, []) ->