Skip to content

Commit

Permalink
Fmt: allow Field wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
trdthg committed Jul 25, 2024
1 parent 04dd79f commit fd32b89
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/format_sail.ml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ let rec can_chunks_list_wrap ?(opt = { nest = 0; in_braces = false }) cqs =
let can_wrap_nested =
match c with
| Atom _ | String_literal _ | Delim _ | Opt_delim _ -> true
| Block (_, exps) -> can_chunks_list_wrap ~opt exps
| Block (_, cqs) -> can_chunks_list_wrap ~opt cqs
| Field (cq, id) -> can_chunks_list_wrap ~opt [cq]
| _ -> false
in
if not can_wrap_nested then count := !count + 1;
Expand All @@ -493,16 +494,18 @@ let rec can_chunks_list_wrap ?(opt = { nest = 0; in_braces = false }) cqs =
| Atom _ | String_literal _ -> true
(* unit => (), *)
| Delim _ | Opt_delim _ -> true (* Xs[unsigned(r)], *)
| App (id, chunks) -> can_chunks_list_wrap ~opt:(opt |> nest_add) chunks
| App (id, cqs) -> can_chunks_list_wrap ~opt:(opt |> nest_add) cqs
(* zero_extend(fcsr.bits) *)
| Field (cq, id) -> can_chunks_list_wrap ~opt [cq]
(* (v128 >> shift)[64..0] *)
| Binary (x, op, y) -> can_chunks_list_wrap ~opt [x] && can_chunks_list_wrap ~opt [y]
(* if regval[31..16] then *)
| Index (exp, ix) -> can_chunks_list_wrap ~opt:(opt |> in_braces) [exp] && can_chunks_list_wrap ~opt [ix]
| Index (cq, ix) -> can_chunks_list_wrap ~opt:(opt |> in_braces) [cq] && can_chunks_list_wrap ~opt [ix]
(* if (a > 1) then {1} else {2} *)
| If_then_else (_, i, t, e) ->
can_chunks_list_wrap ~opt [i] && can_chunks_list_wrap ~opt [t] && can_chunks_list_wrap ~opt [e]
(* {{{ Atom }}} *)
| Block (_, exps) -> can_chunks_list_wrap ~opt:(opt |> in_braces) exps
| Block (_, cqs) -> can_chunks_list_wrap ~opt:(opt |> in_braces) cqs
(* case => (), // comment *)
(* then 2 // comment *)
| Comment (_, _, _, _, trailing) -> (not opt.in_braces) && trailing
Expand Down
3 changes: 3 additions & 0 deletions test/format/default/wrap.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function clause ext_read_CSR 0x001 = Some(zero_extend(fcsr[FFLAGS]))
function clause ext_read_CSR 0x002 = Some(zero_extend(fcsr[FRM]))
function clause ext_read_CSR 0x003 = Some(zero_extend(fcsr.bits))
3 changes: 3 additions & 0 deletions test/format/wrap.sail
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function clause ext_read_CSR 0x001 = Some(zero_extend(fcsr[FFLAGS]))
function clause ext_read_CSR 0x002 = Some(zero_extend(fcsr[FRM]))
function clause ext_read_CSR 0x003 = Some(zero_extend(fcsr.bits))

0 comments on commit fd32b89

Please sign in to comment.