[passes] linearisation des équations

This commit is contained in:
dsac
2022-12-15 09:13:28 +01:00
parent 73d5ed7726
commit e75d525a6d
6 changed files with 127 additions and 54 deletions

33
src/passes_utils.ml Normal file
View File

@@ -0,0 +1,33 @@
open Ast
(** [node_pass] is an auxiliary function used to write passes: it will iterate
* the function passed as argument on all the nodes of the program *)
let node_pass f ast: t_nodelist option =
Utils.list_map_option f ast
(** [equation_pass] is an auxiliary function used to write passes: it will
* iterate the function passed as argument on all the equations of the
* program *)
let equation_pass (f: t_equation -> t_equation option) ast: t_nodelist option =
let aux (node: t_node): t_node option =
match Utils.list_map_option f node.n_equations with
| None -> None
| Some eqs -> Some {n_name = node.n_name;
n_inputs = node.n_inputs;
n_outputs = node.n_outputs;
n_local_vars = node.n_local_vars;
n_equations = eqs;
n_automata = node.n_automata;
n_inputs_type = node.n_inputs_type;
n_outputs_type = node.n_outputs_type;
}
in
node_pass aux ast
let expression_pass f: t_nodelist -> t_nodelist option =
let aux (patt, expr) =
match f expr with
| None -> None
| Some expr -> Some (patt, expr)
in
equation_pass aux