Skip to content

Modules ​

Modules are the fundamental building blocks of hardware hierarchy in Neo. A module declares optional compile-time parameters, an I/O block of directional ports and interfaces, and a body containing internal signals, submodule instantiations, and logic blocks.

Defining and Instantiating Modules ​

neo
// @top marks a module as an entry point for elaboration and code generation.
// Non-@top modules are only emitted when instantiated by a @top hierarchy.
@top
module MyModule(t: Timing) {
  // Inputs and outputs declare a timing annotation and a logic type
  input a(t): Int(32),
  input b(t): Int(32),
  output out(t + 1): Int(32),
} {
  // Instantiate parameterized submodules with `mod`
  mod adder = Adder(32, t);

  // Module instances expose their ports and interfaces as fields
  assign {
    adder.a = a;
    adder.b = b;
    out = adder.out;
  }
}

// Parameterized module using Pos (positive integer >= 1) and Timing
module Adder(width: Pos, t: Timing) {
  input a(t): Int(width),
  input b(t): Int(width),
  output out(t + 1): Int(width),
} {
  assign out = Reg(a + b);
}

@top Modules ​

Modules annotated with @top in the entry file serve as elaboration roots:

  • A @top module may take any number of Timing parameters, and no other parameter types (e.g., module Top, module Top(t: Timing), or module Dual(t_a: Timing, t_b: Timing)).
  • Non-@top modules may take any number of parameters (UInt, Pos, Bool, LogicType, Timing), optionally constrained with where invariants. See Parameterization.

Ports and Default Types ​

Ports inside the I/O block use input or output followed by a name, an optional timing annotation, and an optional : Type:

neo
module Example(t: Timing) {
  input en(t),                 // Omitted type defaults to Bits(1)
  input data(t): Bits(16),
  input mode(*): Bits(2),      // Dynamic (*) timing
  output valid(t),             // Bits(1)
  output result(t): Bits(16),
} {
  // ...
}

If : Type is omitted, Neo defaults the port type to Bits(1). If the timing annotation is omitted, the signal has Constant timing.

Clocks and On-Demand __defaultClock ​

Neo tracks clock usage automatically:

  • Modules that only contain combinational logic (assign and comb) or only use explicit custom Clock ports emit no __defaultClock port in SystemVerilog or FIRRTL.
  • Modules that use an implicit-clock seq { ... } block, Reg(...), or instantiate a submodule requiring __defaultClock automatically receive an implicit input logic __defaultClock port wired through the hierarchy.
  • Modules can also accept explicit Clock-typed ports (e.g., input fast_clk: Clock) and clock sequential blocks with seq fast_clk { ... }. See Timing & Clock Domains.

Monomorphization ​

Because Neo parameters include arbitrary types (LogicType), booleans (Bool), and compile-time expressions, parameters are resolved during elaboration rather than emitted as SystemVerilog parameters. Each unique specialization of a parameterized module is monomorphized into its own concrete hardware module in neo-ir, SystemVerilog, and FIRRTL.

Undriven Sink Warnings ​

At the end of checking each module, Neo checks that all hardware sinks are driven and emits non-fatal warnings if anything is left unconnected:

  • undriven_output: A module output port is never assigned.
  • undriven_interface_field: An assignable field on a module interface is never assigned or connected via connect(...).
  • undriven_submodule_input: An input port (or assignable interface field) on an instantiated submodule is never driven.
  • undriven_logic: A local logic signal declared without an initializer is never assigned.