Module Hardcaml.Constant
Representation of variable width Constants and conversion to/from OCaml types.
type t
= Hardcaml__.Bits0.t
val compare : t -> t -> Hardcaml__.Import.int
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
module Signedness : sig ... end
val empty : t
val create : Hardcaml__.Import.int -> t
create n
create an
bit constant, initialized to hold all0
s.
val width : t -> Hardcaml__.Import.int
Bit width of constant
val to_binary_string : t -> Hardcaml__.Import.string
Convert a constant to a string of
'1'
and'0'
chars.
val to_binary_string_hum : t -> Hardcaml__.Import.string
Same as
to_binary_string
but adds'_'
s every chars
val to_int : t -> Hardcaml__.Import.int
Convert constant to an
int
. Bits aboveInt.num_bits
are dropped.
val to_int32 : t -> Hardcaml__.Import.int32
Convert constant to an
int32
. Bits aboveInt32.num_bits
are dropped.
val to_int64 : t -> Hardcaml__.Import.int64
Convert constant to an
int64
. Bits aboveInt64.num_bits
are dropped.
val to_int64_array : t -> Hardcaml__.Import.int64 Hardcaml__.Import.array
Convert to array of int64s
val to_z : t -> Hardcaml__.Zarith.Z.t
Convert to an unsigned arbitrary precision integer.
val to_hex_string : signedness:Signedness.t -> t -> Hardcaml__.Import.string
Convert to a hex encoded string.
val of_binary_string : Hardcaml__.Import.string -> t
Convert a string containing
'1'
and'0'
characters to a constant. Width is inferred from the strings length.
val of_binary_string_hum : Hardcaml__.Import.string -> t
Same as
of_binary_string
but allow'_'
chars
val of_int : width:Hardcaml__.Import.int -> Hardcaml__.Import.int -> t
Create a constant from the given
int
value.
val of_int32 : width:Hardcaml__.Import.int -> Hardcaml__.Import.int32 -> t
Create a constant from the given
int32
value
val of_int64 : width:Hardcaml__.Import.int -> Hardcaml__.Import.int64 -> t
Create a constant from the given
int64
value
val of_int64_array : width:Hardcaml__.Import.int -> Hardcaml__.Import.int64 Hardcaml__.Import.array -> t
Create from an array of
int64
s
val of_z : width:Hardcaml__.Import.int -> Hardcaml__.Zarith.Z.t -> t
Convert from an arbitrary precision integer.
val of_hex_string : signedness:Signedness.t -> width:Hardcaml__.Import.int -> Hardcaml__.Import.string -> t
Create from a hex encoded string.
val int_of_hex_char : Hardcaml__.Import.char -> Hardcaml__.Import.int
Utility conversion functions to/from hex chars
val hex_char_of_int : Hardcaml__.Import.int -> Hardcaml__.Import.char
module type Bit = sig ... end
module Make_bit_list : functor (Bit : Bit) -> sig ... end
Create constant conversion functions from lists of some inner
Bit.t
type.
val of_bit_list : Hardcaml__.Import.int Hardcaml__.Import.list -> t
val to_bit_list : t -> Hardcaml__.Import.int Hardcaml__.Import.list
val pp : Hardcaml__.Import.Formatter.t -> t -> Hardcaml__.Import.unit
Unsafe Operations
val unsafe_to_bytes : t -> Hardcaml__.Import.Bytes.t
Return the underlying
Bytes.t
representation of the constant. We label as unsafe as the output bytes are not copied. Mutating them should be done with care.
val unsafe_of_bytes : width:Hardcaml__.Import.int -> Hardcaml__.Import.Bytes.t -> t
Construct a constant from the given
Bytes.t
. We label as unsafe as the input bytes are not copied. Mutating them should be done with care.The length of the given
Bytes.t
must be rounded up to 64 bits and be the correct size of fitwidth
bits or an exception is raised.