package hardcaml

  1. Overview
  2. Docs
On This Page
  1. Unsafe Operations
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Hardcaml.ConstantSource

Representation of variable width Constants and conversion to/from OCaml types.

Sourcetype t
Sourceval compare : t -> t -> Base.Int.t
Sourceval sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
Sourcemodule Signedness : sig ... end
Sourceval empty : t
Sourceval create : Base.Int.t -> t

create n create a n bit constant, initialized to hold all 0s.

Sourceval width : t -> Base.Int.t

Bit width of constant

Sourceval to_binary_string : t -> Base.String.t

Convert a constant to a string of '1' and '0' chars.

Sourceval to_binary_string_hum : t -> Base.String.t

Same as to_binary_string but adds '_'s every chars

Sourceval to_int : t -> Base.Int.t

Convert constant to an int. Bits above Int.num_bits are dropped.

Sourceval to_int32 : t -> Base.Int32.t

Convert constant to an int32. Bits above Int32.num_bits are dropped.

Sourceval to_int64 : t -> Base.Int64.t

Convert constant to an int64. Bits above Int64.num_bits are dropped.

Sourceval to_int64_array : t -> Base.Int64.t Base.Array.t

Convert to array of int64s

Sourceval to_z : t -> Z.t

Convert to an unsigned arbitrary precision integer.

Sourceval to_hex_string : signedness:Signedness.t -> t -> Base.String.t

Convert to a hex encoded string.

Sourceval of_binary_string : Base.String.t -> t

Convert a string containing '1' and '0' characters to a constant. Width is inferred from the strings length.

Sourceval of_binary_string_hum : Base.String.t -> t

Same as of_binary_string but allow '_' chars

Sourceval of_int : width:Base.Int.t -> Base.Int.t -> t

Create a constant from the given int value.

Sourceval of_int32 : width:Base.Int.t -> Base.Int32.t -> t

Create a constant from the given int32 value

Sourceval of_int64 : width:Base.Int.t -> Base.Int64.t -> t

Create a constant from the given int64 value

Sourceval of_int64_array : width:Base.Int.t -> Base.Int64.t Base.Array.t -> t

Create from an array of int64s

Sourceval of_z : width:Base.Int.t -> Z.t -> t

Convert from an arbitrary precision integer.

Sourceval of_hex_string : signedness:Signedness.t -> width:Base.Int.t -> Base.String.t -> t

Create from a hex encoded string.

Sourceval int_of_hex_char : Base.Char.t -> Base.Int.t

Utility conversion functions to/from hex chars

Sourceval hex_char_of_int : Base.Int.t -> Base.Char.t
Sourcemodule type Bit = sig ... end
Sourcemodule Make_bit_list (Bit : Bit) : sig ... end

Create constant conversion functions from lists of some inner Bit.t type.

Sourceval of_bit_list : Base.Int.t Base.List.t -> t
Sourceval to_bit_list : t -> Base.Int.t Base.List.t

Unsafe Operations

Sourceval unsafe_to_bytes : t -> Base.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.

Sourceval unsafe_of_bytes : width:Base.Int.t -> Base.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 fit width bits or an exception is raised.