123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175open!Core0(** Uses a [valid] bit to indicate the validity of a [value]. Conceptually similar to an
[Option.t]. *)moduletypeWith_valid=sigtype('a,'b)t2=('a,'b)Comb.with_valid2={valid:'a;value:'b}[@@derivingsexp,bin_io,equal~localize,compare~localize,hash]type'at=('a,'a)t2[@@derivingsexp,equal~localize,compare~localize,bin_io,hash]valvalid:('a,'b)t2->'avalvalue:('a,'b)t2->'bvalvalue_with_default:(moduleComb.Swithtypet='a)->'at->default:'a->'avalmap:'at->f:('a->'b)@local->'btvalmap2:'at->'bt->f:('a->'b->'c)@local->'ctvaliter:'at->f:('a->unit)@local->unitvaliter2:'at->'bt->f:('a->'b->unit)@local->unitvalto_list:'at->'alistvalmap_valid:('a,'b)t2->f:('a->'c)->('c,'b)t2(** Applies the provided function to the value, keeping [valid] the same. Semantically
similar to OCaml's [Option.map] *)valmap_value:('a,'b)t2->f:('b->'c)->('a,'c)t2(** Similar to [map_value], but for a function that takes two arguments. The result is
[valid] if both arguments were valid. *)valmap_value2:(moduleComb.Swithtypet='a)->('a,'b)t2->('a,'c)t2->f:('b->'c->'d)@local->('a,'d)t2(** Applies the provided With_valid-returning function to the value. The result is
[valid] if the initial argument was valid, and the value returned by the function is
valid. Semantically similar to [Option.bind] *)valand_then:(moduleComb.Swithtypet='a)->('a,'b)t2->f:('b->('a,'c)t2)@local->('a,'c)t2(** Similar to [and_then], but for a function that takes two arguments. The result is
[valid] if both arguments are valid and the value returned by the function is valid. *)valand_then2:(moduleComb.Swithtypet='a)->('a,'b)t2->('a,'c)t2->f:('b->'c->('a,'d)t2)@local->('a,'d)t2valto_option:(Bits.t,'a)t2->'aoptionvalwave_formats:Wave_format.ttvalport_names_and_widths_dynamic:nbits:int->(string*int)t(** Create a new hardcaml interface with type ['a With_valid.t X.t] *)moduleFields:sigmoduletypeS=sigtype'avaluetypenonrec'at='atvalueincludeInterface.Swithtype'at:='atvalvalue_with_default:(moduleComb.Swithtypet='a)->'at->default:'avalue->'avaluevalvalue:'at->'avalueendmoduleMake(X:Interface.Pre):Swithtype'avalue='aX.tmoduleM(X:T1):sigmoduletypeS=Swithtype'avalue='aX.tend(** Convenient interface to create [module With_valid = ...] using the
[include functor] extension. *)moduleInclude:sigmoduletypeS=sigtype'avaluemoduleWith_valid:Swithtype'avalue='avalueendmoduletypeF=functor(X:Interface.Pre)->Swithtype'avalue:='aX.tmoduleMake(X:Interface.Pre):Swithtype'avalue:='aX.tendend(** Create a new hardcaml interface with type [('a, 'a X.t) With_valid.t2]. *)moduleWrap:sigmoduletypeS=sigtype'avaluetypenonrec'at=('a,'avalue)t2includeInterface.Swithtype'at:='atvalvalue_with_default:(moduleComb.Swithtypet='a)->'at->default:'avalue->'avalueendmoduleMake(X:Interface.Pre):Swithtype'avalue='aX.tmoduleM(X:T1):sigtypenonrec'at=('a,'aX.t)t2moduletypeS=Swithtype'avalue='aX.tend(** Convenient interface to create [module With_valid = ...] using the
[include functor] extension. *)moduleInclude:sigmoduletypeS=sigtype'avaluemoduleWith_valid:Swithtype'avalue='avalueendmoduletypeF=functor(X:Interface.Pre)->Swithtype'avalue:='aX.tmoduleMake(X:Interface.Pre):Swithtype'avalue:='aX.tendendmoduleVector(X:sigvalwidth:intend):Interface.Swithtype'at='at(** Helper functions, similar to those of Of_signal in [Interface.S], to ease usage of
[Signal.t t]. Function types differ from Of_signal where the width of [value] is
needed. *)moduleOf_signal:sig(** Creates a With_valid of wires with a specified [value] width, e.g.
[Of_signal.wires 5] creates a With_valid where [valid] is a 1-bit wire and [value]
is a 5-bit wire. If [named] is true then wires are given their respective
With_valid field names. If [from] is provided the wires are attached to the fields
in [from], and an error is raised if the provided width does not match the [value]
width in [from]. *)valwires:?named:bool(** Default is [false]. *)->?from:Signal.tt(** No default. *)->int->Signal.ttval__ppx_auto_name:Signal.tt->string->Signal.ttend(** Helper functions, similar to those of Of_always in [Interface.S], to ease usage of
[Always.Variable.t t]. Function types differ from Of_always where the width of
[value] is needed. *)moduleOf_always:sig(** Creates a With_valid with wire variables, where [width] specifies the bitwidth of
[value]. E.g., [Of_always.wire (Signal.zero) ~width:5] creates a With_valid where
[valid] is a 1-bit wire variable and [value] is a 5-bit wire variable, both
defaulting to zeros. *)valwire:(int->Signal.t)->width:int->Always.Variable.tt(** Creates a With_valid with register variables, where [width] specicies the bitwidth
of [value]. *)valreg:(width:int->Always.Variable.tt)Signal.with_register_specval__ppx_auto_name:Always.Variable.tt->string->Always.Variable.ttendend