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
// @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
@topmodule may take any number ofTimingparameters, and no other parameter types (e.g.,module Top,module Top(t: Timing), ormodule Dual(t_a: Timing, t_b: Timing)). - Non-
@topmodules may take any number of parameters (UInt,Pos,Bool,LogicType,Timing), optionally constrained withwhereinvariants. 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:
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 (
assignandcomb) or only use explicit customClockports emit no__defaultClockport in SystemVerilog or FIRRTL. - Modules that use an implicit-clock
seq { ... }block,Reg(...), or instantiate a submodule requiring__defaultClockautomatically receive an implicitinput logic __defaultClockport wired through the hierarchy. - Modules can also accept explicit
Clock-typed ports (e.g.,input fast_clk: Clock) and clock sequential blocks withseq 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 moduleoutputport is never assigned.undriven_interface_field: An assignable field on a module interface is never assigned or connected viaconnect(...).undriven_submodule_input: An input port (or assignable interface field) on an instantiated submodule is never driven.undriven_logic: A locallogicsignal declared without an initializer is never assigned.