Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Circuit builder monad
Instances For
Create initial circuit state
Equations
- Sparkle.IR.Builder.CircuitM.init topModuleName = { counter := 0, module := Sparkle.IR.AST.Module.empty topModuleName, design := Sparkle.IR.AST.Design.empty topModuleName, usedNames := [] }
Instances For
Get the current module
Equations
- Sparkle.IR.Builder.CircuitM.getModule = do let s ← get pure s.module
Instances For
Set the module
Equations
- Sparkle.IR.Builder.CircuitM.setModule m = modify fun (s : Sparkle.IR.Builder.CircuitState) => { counter := s.counter, module := m, design := s.design, usedNames := s.usedNames }
Instances For
Get the current design
Equations
- Sparkle.IR.Builder.CircuitM.getDesign = do let s ← get pure s.design
Instances For
Add a completed module to the design
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generate a fresh wire name.
When named=true (user let-bindings), produces _gen_{hint} — stable across recompilations.
When named=false (compiler intermediates), produces _tmp_{hint}_{counter} — numbered.
The hint is stripped of any Lean macro-hygiene suffix
(...__@_...__hygCtx__hyg_N) so the resulting wire name is
a valid Verilog identifier.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Sanitize a name to be a valid Verilog identifier
Equations
Instances For
Reserve a specific name (for input/output ports)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create a new wire with the given type. Returns the unique name of the wire.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emit a continuous assignment statement. lhs := rhs
Note: Mux validation is performed at Verilog generation time. Always use: .op .mux [cond, thenVal, elseVal] (exactly 3 arguments)
Equations
- Sparkle.IR.Builder.CircuitM.emitAssign lhs rhs = do let m ← Sparkle.IR.Builder.CircuitM.getModule Sparkle.IR.Builder.CircuitM.setModule (m.addStmt (Sparkle.IR.AST.Stmt.assign lhs rhs))
Instances For
Emit a register statement (D flip-flop). Returns the name of the output wire.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emit a synchronous memory (RAM/BRAM) primitive. Returns the name of the read data output wire.
Parameters:
- hint: Base name for the memory instance
- addrWidth: Address width (memory size = 2^addrWidth)
- dataWidth: Data width (width of each memory word)
- clock: Clock signal name
- writeAddr: Write address expression
- writeData: Write data expression
- writeEnable: Write enable expression
- readAddr: Read address expression
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emit a memory with combinational (same-cycle) read. Returns the name of the read data output wire.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add an input port to the module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add an output port to the module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run the circuit builder and extract the final module.
Equations
- Sparkle.IR.Builder.CircuitM.run moduleName builder = match StateT.run builder (Sparkle.IR.Builder.CircuitM.init moduleName) with | (result, finalState) => (finalState.module, result)
Instances For
Run the circuit builder and return only the module.
Equations
- Sparkle.IR.Builder.CircuitM.runModule moduleName builder = (Sparkle.IR.Builder.CircuitM.run moduleName builder).fst
Instances For
Run the circuit builder and return the full design.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Example: Building a simple half adder
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create an SRAM primitive module (single-port synchronous RAM)
Parameters:
- name: Module name (e.g., "SRAM_256x32")
- addrWidth: Address width in bits (depth = 2^addrWidth)
- dataWidth: Data width in bits
Interface:
- Inputs: clk, we (write enable), addr, din (data in)
- Outputs: dout (data out)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create a dual-port SRAM primitive module
Parameters:
- name: Module name (e.g., "SRAM_DP_256x32")
- addrWidth: Address width in bits (depth = 2^addrWidth)
- dataWidth: Data width in bits
Interface:
- Inputs: clk, we, raddr (read addr), waddr (write addr), din
- Outputs: dout
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create a clock gating cell primitive
Parameters:
- name: Module name (e.g., "CKGT_X2" for a 2x drive strength clock gate)
Interface:
- Inputs: clk (clock in), en (enable)
- Outputs: clk_out (gated clock)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create a ROM primitive module
Parameters:
- name: Module name (e.g., "ROM_512x16")
- addrWidth: Address width in bits (depth = 2^addrWidth)
- dataWidth: Data width in bits
Interface:
- Inputs: clk, addr
- Outputs: dout
Equations
- One or more equations did not get rendered due to their size.