Skip to content

Commit

Permalink
[asl] Improve printing of integer constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
HadrienRenaud committed Jan 24, 2025
1 parent 065f538 commit a5cf0a7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
16 changes: 16 additions & 0 deletions asllib/PP.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ let pp_print_seq ?(pp_sep = pp_print_cut) pp_v ppf v =
in
Seq.iter pp_v v

(* Just to display better error messages ... *)
let nonstandard_constraint_compare c1 c2 =
match (c1, c2) with
| Constraint_Exact _, Constraint_Exact _
| Constraint_Range _, Constraint_Range _ ->
compare c1 c2
| Constraint_Exact e1, Constraint_Range (e3, e4) -> (
match compare e1 e3 with
| 0 -> ( match compare e1 e4 with 0 -> 1 | n -> n)
| n -> n)
| Constraint_Range (e1, e2), Constraint_Exact e3 -> (
match compare e1 e3 with
| 0 -> ( match compare e2 e3 with 0 -> -1 | n -> n)
| n -> n)

let pp_comma f () = fprintf f ",@ "
let pp_comma_list pp_elt f = pp_print_list ~pp_sep:pp_comma pp_elt f

Expand Down Expand Up @@ -224,6 +239,7 @@ and pp_int_constraint f = function
| Constraint_Range (x, y) -> fprintf f "@[<h>%a..%a@]" pp_expr x pp_expr y

and pp_int_constraints f li =
let li = List.sort nonstandard_constraint_compare li in
let pp_max_int_constraint_list = 10 in
if List.length li < pp_max_int_constraint_list then
fprintf f "@[%a@]" (pp_comma_list pp_int_constraint) li
Expand Down
2 changes: 1 addition & 1 deletion asllib/tests/lca.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
$ aslref lca3.asl
File lca3.asl, line 5, characters 2 to 25:
ASL Typing error: a subtype of integer {N} was expected,
provided integer {N, 3}.
provided integer {3, N}.
[1]

$ cat >lca4.asl <<EOF
Expand Down
24 changes: 13 additions & 11 deletions asllib/tests/performance.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Warning: Removing some values that would fail with op DIVRM from constraint
set {0..4} gave {1..4}. Continuing with this constraint set.
File constraint-mul-00.asl, line 10, characters 4 to 6:
ASL Typing error: a subtype of integer {6, 12, 16, 0..4, 8..9} was expected,
ASL Typing error: a subtype of integer {0..4, 6, 8..9, 12, 16} was expected,
provided integer {15}.
[1]

Expand All @@ -14,8 +14,8 @@
set {0..16} gave {1..16}. Continuing with this constraint set.
File constraint-mul-01.asl, line 10, characters 4 to 6:
ASL Typing error: a subtype of
integer {18, 30, 42, 52, 60, 70, 72, 75, 84, 88, ...} was expected,
provided integer {255}.
integer {0..16, 18, 20..22, 24..28, 30, 32..33, 35..36, 39..40, 42,
44..45, ...} was expected, provided integer {255}.
[1]

$ aslref constraint-mul-02.asl
Expand All @@ -24,8 +24,8 @@
set {0..32} gave {1..32}. Continuing with this constraint set.
File constraint-mul-02.asl, line 10, characters 4 to 6:
ASL Typing error: a subtype of
integer {42, 60, 72, 102, 108, 110, 112, 128, 130, 138, ...} was expected,
provided integer {1023}.
integer {0..36, 38..40, 42, 44..46, 48..52, 54..58, 60, 62..66, 68..70, 72,
...} was expected, provided integer {1023}.
[1]

$ aslref constraint-mul-03.asl
Expand All @@ -34,8 +34,8 @@
set {0..64} gave {1..64}. Continuing with this constraint set.
File constraint-mul-03.asl, line 10, characters 4 to 6:
ASL Typing error: a subtype of
integer {72, 102, 108, 138, 150, 180, 192, 198, 200, 212, ...}
was expected, provided integer {4095}.
integer {0..66, 68..70, 72, 74..78, 80..82, 84..88, 90..96, 98..100, 102,
104..106, ...} was expected, provided integer {4095}.
[1]

$ aslref constraint-mul-04.asl
Expand All @@ -44,8 +44,9 @@
set {0..128} gave {1..128}. Continuing with this constraint set.
File constraint-mul-04.asl, line 10, characters 4 to 6:
ASL Typing error: a subtype of
integer {138, 150, 180, 192, 198, 228, 240, 270, 282, 312, ...}
was expected, provided integer {16383}.
integer {0..130, 132..136, 138, 140..148, 150, 152..156, 158..162,
164..166, 168..172, 174..178, ...} was expected,
provided integer {16383}.
[1]

$ aslref constraint-mul-05.asl
Expand All @@ -54,8 +55,9 @@
set {0..256} gave {1..256}. Continuing with this constraint set.
File constraint-mul-05.asl, line 10, characters 4 to 6:
ASL Typing error: a subtype of
integer {270, 282, 312, 348, 420, 432, 462, 522, 570, 600, ...}
was expected, provided integer {65535}.
integer {0..256, 258..262, 264..268, 270, 272..276, 278..280, 282,
284..292, 294..306, 308..310, ...} was expected,
provided integer {65535}.
[1]

$ aslref constraint-mul-06.asl
Expand Down
2 changes: 1 addition & 1 deletion asllib/tests/regressions.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Required tests:
Base values
$ aslref base_values.asl
File base_values.asl, line 5, characters 2 to 28:
ASL Typing error: base value of type integer {N..M, 42} cannot be statically
ASL Typing error: base value of type integer {42, N..M} cannot be statically
determined since it consists of N.
[1]

Expand Down

0 comments on commit a5cf0a7

Please sign in to comment.