Disable mallocs when reseting

This commit is contained in:
Benjamin Loison 2022-12-20 15:39:33 +01:00
parent 4303dcd0e4
commit 88c145a527
2 changed files with 15 additions and 5 deletions

View File

@ -236,11 +236,15 @@ let cp_init_aux_nodes fmt (node, h) =
| None -> () (** All auxiliary nodes have been initialized *) | None -> () (** All auxiliary nodes have been initialized *)
| Some n -> | Some n ->
begin begin
Format.fprintf fmt "%a\t\tstate->aux_states[%d] = malloc (sizeof (%s));\n\ Format.fprintf fmt "%a\t\tif(!state->is_reset) {\n\
\t\t((%s*)(state->aux_states[%d]))->is_init = true;\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) aux (node, nst, i-1)
(i-1) (Format.asprintf "t_state_%s" n.n_name) (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)
(Format.asprintf "t_state_%s" n.n_name) (i-1)
end end
in in
let nst = Hashtbl.find h node.in_name in let nst = Hashtbl.find h node.in_name in

View File

@ -19,7 +19,7 @@ let cp_node_state fmt (st: node_state) =
if st.nt_count_app = 0 if st.nt_count_app = 0
then then
Format.fprintf fmt "typedef struct {%a%a%a\n\ Format.fprintf fmt "typedef struct {%a%a%a\n\
\tbool is_init;\n\ \tbool is_init, is_reset;\n\
} %s;\n\n" } %s;\n\n"
print_if_any ("int", st.nt_nb_int, "ivars") print_if_any ("int", st.nt_nb_int, "ivars")
print_if_any ("bool", st.nt_nb_bool, "bvars") print_if_any ("bool", st.nt_nb_bool, "bvars")
@ -27,7 +27,7 @@ let cp_node_state fmt (st: node_state) =
st.nt_name st.nt_name
else else
Format.fprintf fmt "typedef struct {%a%a%a\n\ 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\ \tvoid* aux_states[%d]; /* stores the states of auxiliary nodes */\n\
} %s;\n\n" } %s;\n\n"
print_if_any ("int", st.nt_nb_int, "ivars") print_if_any ("int", st.nt_nb_int, "ivars")
@ -191,10 +191,16 @@ and cp_expression fmt (expr, hloc) =
end end
| CReset (node_name, i, v, b) -> | CReset (node_name, i, v, b) ->
begin 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) cp_value (v, hloc)
node_name node_name
(i - 1) (i - 1)
node_name
(i - 1)
cp_block (b, hloc) cp_block (b, hloc)
end end
| CIf (v, b1, []) -> | CIf (v, b1, []) ->