Documentation

Sparkle.IR.Builder

State for circuit building

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[reducible, inline]

      Circuit builder monad

      Equations
      Instances For

        Create initial circuit state

        Equations
        Instances For

          Set the module

          Equations
          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

                  Check if a name is already used

                  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
                        Instances For
                          def Sparkle.IR.Builder.CircuitM.emitRegister (hint clock reset : String) (input : AST.Expr) (initValue : Int) (ty : «Type».HWType) (named : Bool := false) (resetKind : «Type».ResetKind := «Type».ResetKind.asynchronous) :

                          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
                            def Sparkle.IR.Builder.CircuitM.emitMemory (hint : String) (addrWidth dataWidth : Nat) (clock : String) (writeAddr writeData writeEnable readAddr : AST.Expr) (named : Bool := false) :

                            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
                              def Sparkle.IR.Builder.CircuitM.emitMemoryComboRead (hint : String) (addrWidth dataWidth : Nat) (clock : String) (writeAddr writeData writeEnable readAddr : AST.Expr) (named : Bool := false) :

                              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
                                def Sparkle.IR.Builder.CircuitM.emitInstance (moduleName instName : String) (connections : List (String × AST.Expr)) :

                                Emit a module instantiation.

                                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
                                      def Sparkle.IR.Builder.CircuitM.run {α : Type} (moduleName : String) (builder : CircuitM α) :

                                      Run the circuit builder and extract the final module.

                                      Equations
                                      Instances For

                                        Run the circuit builder and return only the module.

                                        Equations
                                        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
                                              def Sparkle.IR.Builder.mkSRAMPrimitive (name : String) (addrWidth dataWidth : Nat) :

                                              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
                                                def Sparkle.IR.Builder.mkSRAMDualPortPrimitive (name : String) (addrWidth dataWidth : Nat) :

                                                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
                                                    def Sparkle.IR.Builder.mkROMPrimitive (name : String) (addrWidth dataWidth : Nat) :

                                                    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.
                                                    Instances For