Skip to content

Commit

Permalink
Fmt: allow Vector_update nowrap
Browse files Browse the repository at this point in the history
  • Loading branch information
trdthg committed Jul 29, 2024
1 parent 2051108 commit 7b606a1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 292 deletions.
14 changes: 13 additions & 1 deletion src/lib/chunk_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ let rec prerr_chunk indent = function
Queue.iter (prerr_chunk (indent ^ " ")) exp;
Printf.eprintf "%s with:" indent;
List.iter (fun exp -> Queue.iter (prerr_chunk (indent ^ " ")) exp) exps
| Vector_updates (_exp, _updates) -> Printf.eprintf "%sVector_updates:\n" indent
| Vector_updates (exp, updates) ->
Printf.eprintf "%sVector_updates:\n" indent;
Queue.iter (prerr_chunk (indent ^ " ")) exp;
Printf.eprintf "%s with:\n" indent;
List.iter (prerr_chunk (indent ^ " ")) updates
| Index (exp, ix) ->
Printf.eprintf "%sIndex:\n" indent;
List.iter
Expand Down Expand Up @@ -952,6 +956,14 @@ let rec chunk_exp comments chunks (E_aux (aux, l)) =
let i_chunks = rec_chunk_exp i in
pop_comments ~spacer:false comments i_chunks keywords.then_loc;
let t_chunks = rec_chunk_exp t in
if if_format.then_brace then ignore (pop_comments_until_loc_end comments t_chunks keywords.then_loc);
(*
no place to put comment between then_end and else_start
if foo
then {} /* comment */
else {}
*)
ignore (pop_trailing_comment comments t_chunks (ending_line_num keywords.then_loc));
(match keywords.else_loc with Some l -> pop_comments comments t_chunks l | None -> ());
let e_chunks = rec_chunk_exp e in
Expand Down
6 changes: 5 additions & 1 deletion src/lib/format_sail.ml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ module PPrintWrapper = struct
group (opening ^^ nest n (b ^^ contents) ^^ b ^^ closing)

let group_indent n doc = group (nest n doc)

let prefix_hardline h n b contents =
let b = if h then hardline else break b in
group (nest n (b ^^ contents))
Expand Down Expand Up @@ -485,7 +486,7 @@ let rec check_chunks_nowrap ?(opt = default_opt) cqs =
else (
non_delim_count := !non_delim_count + 1;
(* strict rule, for nested chunks *)
let check_no_wrap c =
let rec check_no_wrap c =
match c with
| Atom _ | String_literal _ ->
(* Atom *)
Expand Down Expand Up @@ -518,6 +519,9 @@ let rec check_chunks_nowrap ?(opt = default_opt) cqs =
| Struct_update (exps, fexps) ->
(* struct { variety = AV_exclusive } *)
check_chunks_nowrap ~opt [exps] && check_chunks_nowrap ~opt fexps
| Vector_updates (cq, cs) ->
(* [foo with a = 1, b = 2] *)
check_chunks_nowrap ~opt [cq] && List.fold_left (fun res c -> res && check_no_wrap c) true cs
| Tuple (_, _, _, cqs) -> (* (1, 2) *) check_chunks_nowrap ~opt cqs
| _ -> false
in
Expand Down
13 changes: 9 additions & 4 deletions test/format/default/demo.sail
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
function init_pmp () -> unit = {
assert(sys_pmp_count() == 0 | sys_pmp_count() == 16 | sys_pmp_count() == 64, "sys_pmp_count() must be 0, 16, or 64");

function rX r = match r {
_ =>
//
Xs[unsigned(r)],
foreach (i from 0 to 63) {
// On reset the PMP register's A and L bits are set to 0 unless the plaform
// mandates a different value.
pmpcfg_n[i] = [pmpcfg_n[i] with
A = pmpAddrMatchType_to_bits(OFF), L = 0b0
]
}
}
28 changes: 0 additions & 28 deletions test/format/default/function_quant.sail

This file was deleted.

257 changes: 0 additions & 257 deletions test/format/default/pat_exps.sail

This file was deleted.

15 changes: 15 additions & 0 deletions test/format/default/wrap.expect
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ let a = if i + rs1_val < VLMAX then { 1 } else { 2 }
function clause execute SINVAL_VMA(rs1, rs2) = {
execute(SFENCE_VMA(rs1, rs2))
}

function init_pmp () -> unit = {
assert(sys_pmp_count() == 0 | sys_pmp_count() == 16 | sys_pmp_count() == 64, "sys_pmp_count() must be 0, 16, or 64");

foreach (i from 0 to 63) {
// On reset the PMP register's A and L bits are set to 0 unless the plaform
// mandates a different value.
pmpcfg_n[i] = [pmpcfg_n[i] with
A = pmpAddrMatchType_to_bits(OFF), L = 0b0
]
}
}

register mtimecmp : bits(64) // memory-mapped internal clint register.
function not_implemented message = throw Error_not_implemented(message)
Loading

0 comments on commit 7b606a1

Please sign in to comment.