[ast2C] store old values of variables used in the pre construct

This commit is contained in:
dsac
2022-12-17 16:30:10 +01:00
parent 0da0f58b22
commit bb99a5882b
3 changed files with 47 additions and 5 deletions

View File

@@ -41,7 +41,7 @@ let cp_prototype fmt (node, h): unit =
| None -> failwith "This should not happend!"
| Some nst ->
begin
Format.fprintf fmt "void %s (%s *state, %a);\n"
Format.fprintf fmt "void %s (%s *state, %a)"
node.n_name
nst.nt_name
cp_varlist (snd node.n_inputs)
@@ -49,9 +49,33 @@ let cp_prototype fmt (node, h): unit =
let rec cp_prototypes fmt (nodes, h) =
match nodes with
| [] -> Format.fprintf fmt "\n\n"
| [] -> ()
| node :: nodes ->
Format.fprintf fmt "%a%a"
Format.fprintf fmt "%a;\n%a"
cp_prototype (node, h)
cp_prototypes (nodes, h)
(** The ollowing function prints the code to remember previous values of
* variables used with the pre construct. *)
let cp_prevars fmt (node, h) =
let node_st = Hashtbl.find h node.n_name in
List.iter
(fun v -> (** Note that «dst_array = src_array» should hold. *)
let (src_array, src_idx) = Hashtbl.find node_st.nt_map (v, false) in
let (dst_array, dst_idx) = Hashtbl.find node_st.nt_map (v, true) in
Format.fprintf fmt "\t%s[%d] = %s[%d];\n"
dst_array dst_idx src_array src_idx)
node_st.nt_prevars
let rec cp_node fmt (node, h) =
Format.fprintf fmt "%a\n{\nTODO...\n%a}\n"
cp_prototype (node, h)
cp_prevars (node, h)
let rec cp_nodes fmt (nodes, h) =
match nodes with
| [] -> ()
| node :: nodes ->
Format.fprintf fmt "%a\n%a"
cp_node (node, h)
cp_nodes (nodes, h)