123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141open!Core0(** An enumerated type (generally a variant type with no arguments) which should derive
[compare, enumerate, sexp_of, variants]. *)moduletypeCases=sigtypet[@@derivingcompare~localize,enumerate,sexp_of]end(** Functions to project an [Cases] type into and out of hardcaml bit vectors
representated as an interface. *)moduletypeS_enum=sigmoduleCases:TincludeInterface.Svalof_enum:(moduleComb.Swithtypet='a)->Cases.t->'atvalto_enum:Bits.tt->Cases.tOr_error.tvalto_enum_exn:Bits.tt->Cases.tval(==:):(moduleComb.Swithtypet='a)->'at->'at->'avalmatch_:(moduleComb.Swithtypet='a)->?default:'a->'at->(Cases.t*'a)list->'avalto_raw:'at->'atype'aouter:='atmoduleOf_signal:sigincludemoduletypeofOf_signal(** @inline *)(** Tests for equality between two enums. For writing conditional statements based on
the value of the enum, consider using [match_] below, or [Of_always.match_]
instead *)val(==:):t->t->Signal.t(** Create an Cases value from a statically known value. *)valof_enum:Cases.t->Signal.touter(** Creates a Cases value from a raw value. Note that this only performs a check
widths, and does not generate circuitry to validate that the input is valid. See
documentation on Casess for more information. *)valof_raw:Signal.t->Signal.touter(** Multiplex on an enum value. If there are unhandled cases, a [default] needs to be
specified. *)valmatch_:?default:Signal.t->Signal.touter->(Cases.t*Signal.t)list->Signal.t(** Convenient wrapper around [eq x (of_enum Foo)] *)valis:t->Cases.t->Signal.tendmoduleOf_bits:sigincludemoduletypeofOf_bits(** @inline *)valis:t->Cases.t->Bits.tval(==:):t->t->Bits.tvalof_enum:Cases.t->Bits.toutervalof_raw:Bits.t->Bits.toutervalmatch_:?default:Bits.t->Bits.touter->(Cases.t*Bits.t)list->Bits.tendmoduleOf_always:sigincludemoduletypeofOf_always(** @inline *)(** Performs a "pattern match" on a [Signal.t t], and "executes" the branch that
matches the signal value. Semantics similar to [switch] in verilog. *)valmatch_:?default:Always.tlist->Signal.tt->(Cases.t*Always.tlist)list->Always.tendmoduleMake_comb(X:Comb.S):sigincludemoduletypeofMake_comb(X)(** @inline *)valis:t->Cases.t->combval(==:):t->t->combvalof_enum:Cases.t->comboutervalof_raw:comb->comboutervalmatch_:?default:comb->combouter->(Cases.t*comb)list->combend(** Set an input port in simulation to a concrete Cases value. *)valsim_set:Bits.treft->Cases.t->unit(** Similar to [sim_set], but operates on raw [Bits.t] instead. *)valsim_set_raw:Bits.treft->Bits.t->unit(** Read an output port from simulation to a concreate Cases value. Returns [Ok enum]
when the [Bits.t] value can be parsed, and [Error _] when the value is unhandled. *)valsim_get:Bits.treft->Cases.tOr_error.t(** Equivalent to [ok_exn (sim_get x)] *)valsim_get_exn:Bits.treft->Cases.t(** Similar to [sim_get], but operates on raw [Bits.t] instead. This doesn't return
[_ Or_error.t]. Undefined values will be returned as it is. *)valsim_get_raw:Bits.treft->Bits.tvalunwrap:'at->'amoduleUnsafe:sigvalwrap:'a->'atendend(** Binary and onehot selectors for [Casess]. *)moduletypeS_enums=sigmoduleCases:TmoduleBinary:S_enumwithmoduleCases:=CasesmoduleOne_hot:S_enumwithmoduleCases:=CasesendmoduletypeEnum=sigmoduletypeCases=CasesmoduletypeS_enum=S_enummoduletypeS_enums=S_enums(** Constructs a hardcaml interface which represents hardware for the given [Enum] as an
abstract [Interface], using a Binary internal representation. *)moduleMake_binary(Cases:Cases):S_enumwithmoduleCases:=Cases(** Similar to [Make_binary], but using a one hot representation internally. *)moduleMake_one_hot(Cases:Cases):S_enumwithmoduleCases:=Cases(** [Make_enums] is semantically similar to:
{[
module Binary = Make_binary (Cases)
module One_hot = Make_one_host (Cases)
]} *)moduleMake_enums(Cases:Cases):S_enumswithmoduleCases:=Casesend