package hardcaml_waveterm

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file display_rule.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
open Base

type t =
  | Default
  | Regexp of
      { re : (Re.re[@sexp.opaque])
      ; wave_format : Hardcaml.Wave_format.t option
      ; alignment : Text_alignment.t
      }
  | Names of
      { names : Port_name.t list
      ; wave_format : Hardcaml.Wave_format.t option
      ; alignment : Text_alignment.t
      }
  | Custom of (Port.t -> Hardcaml.Wave_format.t option)
  | Custom_with_alignment of
      (Port.t -> (Hardcaml.Wave_format.t * Text_alignment.t) option)
[@@deriving sexp_of]

let default = Default

let port_name_is_one_of ?(alignment = Text_alignment.Left) ?wave_format names =
  Names { names = List.map names ~f:Port_name.of_string; wave_format; alignment }
;;

let port_name_is ?alignment ?wave_format name =
  port_name_is_one_of [ name ] ?wave_format ?alignment
;;

let port_name_matches ?(alignment = Text_alignment.Left) ?wave_format re =
  Regexp { re; wave_format; alignment }
;;

let custom ~f = Custom f
let custom_with_alignment ~f = Custom_with_alignment f

module type States = sig
  type t [@@deriving sexp_of, enumerate]
end

let states_binary ?alignment (module States : States) name =
  let states =
    List.map States.all ~f:(fun state -> Sexp.to_string_hum (States.sexp_of_t state))
  in
  port_name_is ?alignment name ~wave_format:(Index states)
;;

let states_onehot ?alignment (module States : States) name =
  let states =
    Array.of_list_map States.all ~f:(fun state ->
      Sexp.to_string_hum (States.sexp_of_t state))
  in
  let open Hardcaml in
  port_name_is
    ?alignment
    name
    ~wave_format:
      (Custom (fun b -> Bits.onehot_to_binary b |> Bits.to_int |> Array.get states))
;;

let states ?(onehot = false) ?alignment (module States : States) name =
  if onehot
  then states_onehot ?alignment (module States) name
  else states_binary ?alignment (module States) name
;;
OCaml

Innovation. Community. Security.