Skip to content

Commit 081ef65

Browse files
committed
Merge branch 'main-function-selection-in-bir' into backend-ocaml
2 parents 5fd3baa + b8e0f56 commit 081ef65

6 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/mlang/backend_compilers/bir_to_dgfip_c.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ let rec simpl_dexpr (de : dexpr) : dexpr =
169169
| Done -> Dzero
170170
| Dlit f when f <> 0. -> Dzero
171171
| Dzero -> Done
172-
| _ -> de
172+
| de -> Dunop ("!", de)
173173
end
174174
| Dite (dec, det, dee) -> begin
175175
match (simpl_dexpr dec, simpl_dexpr det, simpl_dexpr dee) with

src/mlang/backend_ir/bir.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ let main_statements_with_context (p : program) : stmt list =
153153
Errors.raise_error
154154
"This Bir program has no context constants and conditions stored"
155155

156-
let main_statements_with_reset (p : program) : stmt list =
156+
let main_statements_with_context_and_tgv_init (p : program) : stmt list =
157157
match p.context with
158158
| Some context ->
159159
context.unused_inputs_init_stmts @ main_statements_with_context p

src/mlang/backend_ir/bir.mli

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ type program_context = {
6262
adhoc_specs_conds_stmts : stmt list;
6363
unused_inputs_init_stmts : stmt list;
6464
}
65+
(** This record allows to store statements generated from the m_spec file
66+
without modifying the [Bir.program] function map. Thus the map reflects the
67+
computation strictly as described in M and MPP.
68+
69+
Bir module public interface can then provide access to the statements
70+
associated with the declared main function either:
71+
72+
- as defined in M source,
73+
- composed with the m_spec constant assignations and conditions,
74+
- composed with an initialisation of the variable dictionnary and the m_spec
75+
features.
76+
77+
Initialisation of the variables at the [Bir] level including unused
78+
variables is necessary to the [Bir.interpreter] but frowned upon in code
79+
generation backends where the data structure size incites to use idiomatic
80+
efficient methods of initialisation instead of resting upon a row of
81+
assignments. *)
6582

6683
type program = {
6784
mpp_functions : mpp_function FunctionMap.t;
@@ -93,7 +110,7 @@ val main_statements : program -> stmt list
93110

94111
val main_statements_with_context : program -> stmt list
95112

96-
val main_statements_with_reset : program -> stmt list
113+
val main_statements_with_context_and_tgv_init : program -> stmt list
97114

98115
val get_all_statements : program -> stmt list
99116

src/mlang/backend_ir/bir_instrumentation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ and get_code_locs_stmts (p : Bir.program) (stmts : Bir.stmt list)
144144
locs
145145

146146
let get_code_locs (p : Bir.program) : code_locs =
147-
get_code_locs_stmts p (Bir.main_statements_with_reset p) []
147+
get_code_locs_stmts p (Bir.main_statements_with_context_and_tgv_init p) []

src/mlang/backend_ir/bir_interpreter.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,19 @@ module Make (N : Bir_number.NumberInterface) = struct
753753
try
754754
let ctx =
755755
evaluate_stmts p ctx
756-
(Bir.main_statements_with_reset p)
756+
(Bir.main_statements_with_context_and_tgv_init p)
757757
[] code_loc_start_value
758+
(* For the interpreter to operate properly, all input variables must be
759+
declared at some point, even if they aren't used as input (either
760+
contextual constants or entered at interpreter prompt). The M program
761+
doesn't include default assignation for non-entered input variables,
762+
so unused inputs are not declared in the main statements.
763+
764+
The use of main_statement_with_context_and_tgv_init ensures every
765+
variable from the TGV dictionnary is assigned to "undefined" by
766+
default, before context statements overload the contextual constants
767+
according to the spec file and interpreter prompt assignements
768+
overload entered variables. *)
758769
in
759770
ctx
760771
with RuntimeError (e, ctx) ->

src/mlang/backend_ir/format_bir.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ let format_rules fmt rules =
7474

7575
let format_program fmt (p : program) =
7676
Format.fprintf fmt "%a%a" format_rules p.rules_and_verifs format_stmts
77-
(Bir.main_statements_with_reset p)
77+
(Bir.main_statements_with_context_and_tgv_init p)

0 commit comments

Comments
 (0)