Skip to main content

Crate hdl_cat_macros

Crate hdl_cat_macros 

Source
Expand description

#[kernel] attribute macro for hdl-cat.

Lifts a Rust function with a restricted body into an IR builder returning a combinational hdl_cat_circuit::CircuitArrow.

§Supported subset

  • Parameter types: bool, Bits<N>, SignedBits<N> (with a literal N).
  • Return type: a single scalar (same constraints as parameters).
  • Body: zero or more let bindings followed by a tail expression.
  • Expressions: identifiers, binary operators (+, -, *, &, |, ^), unary !.

Function bodies outside this subset raise a compile error.

§Example

The macro cannot be doctested from within its own crate because expanded code references hdl_cat_ir, hdl_cat_bits, hdl_cat_circuit, and hdl_cat_error, which aren’t in this crate’s dependency graph. Real doctests live in the umbrella hdl-cat crate’s tests/kernel_macro.rs.

Conceptually:

use hdl_cat_macros::kernel;
use hdl_cat_bits::Bits;

#[kernel]
fn xor_plus_a(a: Bits<8>, b: Bits<8>) -> Bits<8> {
    let x = a ^ b;
    x + a
}

After expansion, xor_plus_a becomes a nullary function returning Result<CircuitArrow<CircuitTensor<Obj<Bits<8>>, Obj<Bits<8>>>, Obj<Bits<8>>>, Error> that builds the IR for the given expression.

Attribute Macros§

kernel
Lift a Rust function into an hdl-cat IR builder.