diff --git a/src/mlang/backend_compilers/bir_to_dgfip_c.ml b/src/mlang/backend_compilers/bir_to_dgfip_c.ml index a9e842d42..accd7d453 100644 --- a/src/mlang/backend_compilers/bir_to_dgfip_c.ml +++ b/src/mlang/backend_compilers/bir_to_dgfip_c.ml @@ -214,9 +214,9 @@ let generate_m_assign (dgfip_flags : Dgfip_options.flags) (Dgfip_varid.gen_access_pos_from_start var_indexes var) let generate_var_def (dgfip_flags : Dgfip_options.flags) - (var_indexes : Dgfip_varid.var_id_map) (var : variable) - (data : variable_data) (fmt : Format.formatter) : unit = - match data.var_definition with + (var_indexes : Dgfip_varid.var_id_map) (var : variable) (def : variable_def) + (fmt : Format.formatter) : unit = + match def with | SimpleVar e -> let se = generate_c_expr e var_indexes in generate_m_assign dgfip_flags var_indexes var None fmt se diff --git a/src/mlang/backend_compilers/bir_to_java.ml b/src/mlang/backend_compilers/bir_to_java.ml index 8f476d405..4b8bfa2a6 100644 --- a/src/mlang/backend_compilers/bir_to_java.ml +++ b/src/mlang/backend_compilers/bir_to_java.ml @@ -173,9 +173,9 @@ let format_local_vars_defs (oc : Format.formatter) Format.fprintf fmt "localVariables[%d] = %s;" lvar.Mir.LocalVariable.id se) oc defs -let generate_var_def (var : variable) (data : variable_data) +let generate_var_def (var : variable) (def : variable_def) (oc : Format.formatter) = - match data.var_definition with + match def with | SimpleVar e -> let se, defs = generate_java_expr e in Format.fprintf oc "%a%s = %s;" format_local_vars_defs defs diff --git a/src/mlang/backend_ir/bir.ml b/src/mlang/backend_ir/bir.ml index ec0befc00..5cf7e2c0f 100644 --- a/src/mlang/backend_ir/bir.ml +++ b/src/mlang/backend_ir/bir.ml @@ -91,8 +91,6 @@ type condition_data = variable Mir.condition_data_ type variable_def = variable Mir.variable_def_ -type variable_data = variable Mir.variable_data_ - type function_name = string type rule_or_verif_code = Rule of stmt list | Verif of stmt @@ -106,7 +104,7 @@ and rule_or_verif = { and stmt = stmt_kind Pos.marked and stmt_kind = - | SAssign of variable * variable_data + | SAssign of variable * variable_def | SConditional of expression * stmt list * stmt list | SVerif of condition_data | SRovCall of rov_id @@ -291,8 +289,8 @@ let get_local_variables (p : program) : unit Mir.LocalVariableMap.t = (fun acc stmt -> match Pos.unmark stmt with | SVerif cond -> get_local_vars_expr acc cond.Mir.cond_expr - | SAssign (_, data) -> ( - match data.Mir.var_definition with + | SAssign (_, def) -> ( + match def with | Mir.SimpleVar e -> get_local_vars_expr acc e | Mir.TableVar (_, defs) -> ( match defs with diff --git a/src/mlang/backend_ir/bir.mli b/src/mlang/backend_ir/bir.mli index a2747440c..189091673 100644 --- a/src/mlang/backend_ir/bir.mli +++ b/src/mlang/backend_ir/bir.mli @@ -32,8 +32,6 @@ type condition_data = variable Mir.condition_data_ type variable_def = variable Mir.variable_def_ -type variable_data = variable Mir.variable_data_ - type function_name = string type rule_or_verif_code = Rule of stmt list | Verif of stmt @@ -47,7 +45,7 @@ and rule_or_verif = { and stmt = stmt_kind Pos.marked and stmt_kind = - | SAssign of variable * variable_data + | SAssign of variable * variable_def | SConditional of expression * stmt list * stmt list | SVerif of condition_data | SRovCall of rov_id diff --git a/src/mlang/backend_ir/bir_interface.ml b/src/mlang/backend_ir/bir_interface.ml index df32a3946..9d01428da 100644 --- a/src/mlang/backend_ir/bir_interface.ml +++ b/src/mlang/backend_ir/bir_interface.ml @@ -259,16 +259,7 @@ let adapt_program_to_function (p : Bir.program) (f : bir_function) : let const_input_stmts = Bir.VariableMap.fold (fun var e acc -> - Pos.same_pos_as - (Bir.SAssign - ( var, - { - Mir.var_typ = None; - Mir.var_io = Regular; - Mir.var_definition = Mir.SimpleVar e; - } )) - e - :: acc) + Pos.same_pos_as (Bir.SAssign (var, Mir.SimpleVar e)) e :: acc) f.func_constant_inputs [] in let unused_input_stmts = @@ -285,31 +276,22 @@ let adapt_program_to_function (p : Bir.program) (f : bir_function) : let pos = Pos.no_pos in ( Bir.SAssign ( Bir.(var_from_mir default_tgv) var, - { - Mir.var_typ = None; - Mir.var_io = Regular; - Mir.var_definition = - begin - match var.Mir.Variable.is_table with - | None -> - Mir.SimpleVar (Mir.Literal Mir.Undefined, pos) - | Some size -> - let idxmap = - let rec loop i acc = - if i < 0 then acc - else - loop (i - 1) - (Mir.IndexMap.add i - (Pos.same_pos_as - (Mir.Literal Mir.Undefined) - var.Mir.Variable.name) - acc) - in - loop (size - 1) Mir.IndexMap.empty - in - Mir.TableVar (size, Mir.IndexTable idxmap) - end; - } ), + match var.Mir.Variable.is_table with + | None -> Mir.SimpleVar (Mir.Literal Mir.Undefined, pos) + | Some size -> + let idxmap = + let rec loop i acc = + if i < 0 then acc + else + loop (i - 1) + (Mir.IndexMap.add i + (Pos.same_pos_as (Mir.Literal Mir.Undefined) + var.Mir.Variable.name) + acc) + in + loop (size - 1) Mir.IndexMap.empty + in + Mir.TableVar (size, Mir.IndexTable idxmap) ), pos ) :: acc | _ -> acc) diff --git a/src/mlang/backend_ir/bir_interpreter.ml b/src/mlang/backend_ir/bir_interpreter.ml index cb295770d..595961e2a 100644 --- a/src/mlang/backend_ir/bir_interpreter.ml +++ b/src/mlang/backend_ir/bir_interpreter.ml @@ -710,7 +710,7 @@ struct let rec evaluate_stmt (p : Bir.program) (ctx : ctx) (stmt : Bir.stmt) (loc : code_location) = match Pos.unmark stmt with - | Bir.SAssign (var, vdata) -> + | Bir.SAssign (var, vdef) -> let value = try Bir.VariableMap.find var ctx.ctx_vars with Not_found -> ( @@ -718,7 +718,7 @@ struct | Some size -> TableVar (size, Array.make size Undefined) | None -> SimpleVar Undefined) in - let res = evaluate_variable p ctx value vdata.var_definition in + let res = evaluate_variable p ctx value vdef in !assign_hook var (fun _ -> var_value_to_var_literal res) loc; { ctx with ctx_vars = Bir.VariableMap.add var res ctx.ctx_vars } | Bir.SConditional (b, t, f) -> ( diff --git a/src/mlang/backend_ir/format_bir.ml b/src/mlang/backend_ir/format_bir.ml index f58efa731..a54c0d9f9 100644 --- a/src/mlang/backend_ir/format_bir.ml +++ b/src/mlang/backend_ir/format_bir.ml @@ -24,10 +24,10 @@ let format_variable_def fmt (vdef : variable_def) = let rec format_stmt fmt (stmt : stmt) = match Pos.unmark stmt with - | SAssign (v, vdata) -> + | SAssign (v, vdef) -> Format.fprintf fmt "%s = %a" (Pos.unmark (var_to_mir v).Mir.Variable.name) - format_variable_def vdata.var_definition + format_variable_def vdef | SConditional (cond, t, []) -> Format.fprintf fmt "if(%a):@\n@[ %a@]@\n" format_expression cond format_stmts t diff --git a/src/mlang/mpp_ir/mpp_ir_to_bir.ml b/src/mlang/mpp_ir/mpp_ir_to_bir.ml index 05b0f3a15..dbe6eb3c0 100644 --- a/src/mlang/mpp_ir/mpp_ir_to_bir.ml +++ b/src/mlang/mpp_ir/mpp_ir_to_bir.ml @@ -189,9 +189,8 @@ let translate_m_code (m_program : Mir_interface.full_program) match var_definition with | InputVar -> None | TableVar _ | SimpleVar _ -> - let vdef = { vdef with var_definition } in Some - ( Bir.SAssign (Bir.(var_from_mir default_tgv) var, vdef), + ( Bir.SAssign (Bir.(var_from_mir default_tgv) var, var_definition), var.Mir.Variable.execution_number.pos ) with Not_found -> None) vars @@ -351,13 +350,7 @@ and translate_mpp_stmt (mpp_program : Mpp_ir.mpp_compute list) [ Pos.same_pos_as (Bir.SAssign - ( new_l, - { - var_definition = - SimpleVar (translate_mpp_expr m_program ctx expr, pos); - var_typ = None; - var_io = Regular; - } )) + (new_l, SimpleVar (translate_mpp_expr m_program ctx expr, pos))) stmt; ] ) | Mpp_ir.Assign (Mbased (var, _), expr) -> @@ -370,12 +363,7 @@ and translate_mpp_stmt (mpp_program : Mpp_ir.mpp_compute list) Pos.same_pos_as (Bir.SAssign ( Bir.(var_from_mir default_tgv) var, - { - var_definition = - SimpleVar (translate_mpp_expr m_program ctx expr, pos); - var_typ = None; - var_io = Mir.Input; - } )) + SimpleVar (translate_mpp_expr m_program ctx expr, pos) )) stmt; ] ) | Mpp_ir.Conditional (e, t, f) -> @@ -394,11 +382,7 @@ and translate_mpp_stmt (mpp_program : Mpp_ir.mpp_compute list) Pos.same_pos_as (Bir.SAssign ( Bir.(var_from_mir default_tgv) var, - { - var_definition = SimpleVar (Mir.Literal Undefined, pos); - var_typ = None; - var_io = Mir.Input; - } )) + SimpleVar (Mir.Literal Undefined, pos) )) stmt; ] ) | Mpp_ir.Delete (Local l) -> @@ -406,13 +390,7 @@ and translate_mpp_stmt (mpp_program : Mpp_ir.mpp_compute list) ( ctx, [ Pos.same_pos_as - (Bir.SAssign - ( var, - { - var_definition = SimpleVar (Mir.Literal Undefined, pos); - var_typ = None; - var_io = Regular; - } )) + (Bir.SAssign (var, SimpleVar (Mir.Literal Undefined, pos))) stmt; ] ) | Mpp_ir.Expr (Call (MppFunction f, args), pos) -> diff --git a/src/mlang/optimizing_ir/dead_code_removal.ml b/src/mlang/optimizing_ir/dead_code_removal.ml index f5ac79dfe..e0f8452f0 100644 --- a/src/mlang/optimizing_ir/dead_code_removal.ml +++ b/src/mlang/optimizing_ir/dead_code_removal.ml @@ -108,7 +108,7 @@ let remove_dead_statements (stmts : block) (id : block_id) used_blocks then let stmt_used_vars = - match var_def.Mir.var_definition with + match var_def with | Mir.SimpleVar e -> Bir.get_used_variables e | Mir.TableVar (_, def) -> ( match def with diff --git a/src/mlang/optimizing_ir/format_oir.ml b/src/mlang/optimizing_ir/format_oir.ml index 54853f14a..2a0d3ac8c 100644 --- a/src/mlang/optimizing_ir/format_oir.ml +++ b/src/mlang/optimizing_ir/format_oir.ml @@ -18,10 +18,10 @@ open Oir let rec format_stmt fmt (stmt : stmt) = match Pos.unmark stmt with - | SAssign (v, vdata) -> + | SAssign (v, vdef) -> Format.fprintf fmt "%s = %a@," (Pos.unmark (Bir.var_to_mir v).Mir.Variable.name) - Format_bir.format_variable_def vdata.var_definition + Format_bir.format_variable_def vdef | SConditional (cond, b1, b2, _) -> Format.fprintf fmt "if(%a) then goto %d else goto %d@," Format_bir.format_expression cond b1 b2 diff --git a/src/mlang/optimizing_ir/inlining.ml b/src/mlang/optimizing_ir/inlining.ml index a7d46d882..5dcdd8a5c 100644 --- a/src/mlang/optimizing_ir/inlining.ml +++ b/src/mlang/optimizing_ir/inlining.ml @@ -251,19 +251,15 @@ let rec inline_in_expr (e : Bir.expression) (ctx : ctx) let inline_in_stmt (stmt : stmt) (ctx : ctx) (current_block : block_id) (current_stmt_pos : int) : stmt * ctx * int = match Pos.unmark stmt with - | SAssign (var, data) -> ( - match data.var_definition with + | SAssign (var, def) -> ( + match def with | InputVar -> (stmt, ctx, current_stmt_pos) | SimpleVar def -> let new_def = inline_in_expr (Pos.unmark def) ctx current_block current_stmt_pos in let new_def = Mir.SimpleVar (Pos.same_pos_as new_def def) in - let new_stmt = - Pos.same_pos_as - (SAssign (var, { data with var_definition = new_def })) - stmt - in + let new_stmt = Pos.same_pos_as (SAssign (var, new_def)) stmt in let new_ctx = add_var_def_to_ctx var new_def current_block current_stmt_pos ctx in @@ -279,11 +275,7 @@ let inline_in_stmt (stmt : stmt) (ctx : ctx) (current_block : block_id) Mir.TableVar (size, IndexGeneric (v, Pos.same_pos_as new_def def)) in - let new_stmt = - Pos.same_pos_as - (SAssign (var, { data with var_definition = new_def })) - stmt - in + let new_stmt = Pos.same_pos_as (SAssign (var, new_def)) stmt in let new_ctx = add_var_def_to_ctx var new_def current_block current_stmt_pos ctx @@ -300,11 +292,7 @@ let inline_in_stmt (stmt : stmt) (ctx : ctx) (current_block : block_id) defs in let new_defs = Mir.TableVar (size, IndexTable new_defs) in - let new_stmt = - Pos.same_pos_as - (SAssign (var, { data with var_definition = new_defs })) - stmt - in + let new_stmt = Pos.same_pos_as (SAssign (var, new_defs)) stmt in let new_ctx = add_var_def_to_ctx var new_defs current_block current_stmt_pos ctx diff --git a/src/mlang/optimizing_ir/oir.ml b/src/mlang/optimizing_ir/oir.ml index ff696db22..e7225e454 100644 --- a/src/mlang/optimizing_ir/oir.ml +++ b/src/mlang/optimizing_ir/oir.ml @@ -21,7 +21,7 @@ module BlockMap = Map.Make (Int) type stmt = stmt_kind Pos.marked and stmt_kind = - | SAssign of Bir.variable * Bir.variable_data + | SAssign of Bir.variable * Bir.variable_def | SConditional of Bir.expression * block_id * block_id * block_id (** The first two block ids are the true and false branch, the third is the join point after *) diff --git a/src/mlang/optimizing_ir/oir.mli b/src/mlang/optimizing_ir/oir.mli index 41fffa900..a90683467 100644 --- a/src/mlang/optimizing_ir/oir.mli +++ b/src/mlang/optimizing_ir/oir.mli @@ -21,7 +21,7 @@ module BlockMap : Map.S with type key = block_id type stmt = stmt_kind Pos.marked and stmt_kind = - | SAssign of Bir.variable * Bir.variable_data + | SAssign of Bir.variable * Bir.variable_def | SConditional of Bir.expression * block_id * block_id * block_id | SVerif of Bir.condition_data | SGoto of block_id diff --git a/src/mlang/optimizing_ir/partial_evaluation.ml b/src/mlang/optimizing_ir/partial_evaluation.ml index d8ffb4a47..4c31691d3 100644 --- a/src/mlang/optimizing_ir/partial_evaluation.ml +++ b/src/mlang/optimizing_ir/partial_evaluation.ml @@ -625,7 +625,7 @@ let partially_evaluate_stmt (stmt : stmt) (block_id : block_id) List.mem (Pos.unmark (Bir.var_to_mir var).name) !Cli.var_info_debug in let new_def, new_ctx = - match def.var_definition with + match def with | InputVar -> (Mir.InputVar, ctx) | SimpleVar e -> if peval_debug then @@ -698,11 +698,7 @@ let partially_evaluate_stmt (stmt : stmt) (block_id : block_id) (TableVar (size, IndexTable (Mir.IndexMap.map fst es')), new_ctx) ) in - let new_stmt = - Pos.same_pos_as - (SAssign (var, { def with var_definition = new_def })) - stmt - in + let new_stmt = Pos.same_pos_as (SAssign (var, new_def)) stmt in (new_stmt :: new_block, new_ctx) | SConditional (e, b1, b2, join) -> ( let new_e, d =