Wax_wasm.Cond_specializeSourceSpecialization of conditional annotations against user-supplied variable bindings (the -D/--define CLI option).
Conditional annotations (@if <cond> ...) are normally preserved verbatim (see Cond_solver for their path-sensitive validation). Given values for some condition variables, this module partially evaluates the conditions:
A mapping from condition-variable names to values.
parse_define s parses one -D/--define argument, either "name" or "name=value". A bare name binds a boolean true. Otherwise the value kind is inferred: "true"/"false" is a boolean, N.N.N (three non-negative integers) a version, and anything else a string. Returns Error msg on a malformed argument (an empty variable name).
Build bindings from name/value pairs. On a duplicate name, the last entry wins.
eval ctx env c partially evaluates c under env. Unbound variables are left in the residual; bound ones are substituted and the condition is constant-folded. Reports an error diagnostic (and leaves the offending sub-condition residual) when a variable is set to a value of a kind incompatible with how the condition uses it.
val module_ :
Wax_utils.Diagnostic.context ->
bindings ->
Ast.location Ast.Text.module_ ->
Ast.location Ast.Text.module_ * (int * int) listSplice out and simplify every conditional annotation in a WAT module according to eval. Returns the specialized module and the half-open byte ranges of the branches that were removed, for dropping their comments (see Wax_utils.Trivia.drop_in_ranges). With empty bindings this is the identity (no conditional is determined, so all are kept unchanged) and no range is produced.