Part 1 · Language Foundations · Intermediate
Packages, Typedefs & Compilation
Hub — packages and imports, compilation units, typedef/parameter discipline, `include vs import, and namespace hygiene at scale.
Overview
Verilog had exactly one shared namespace trick: textual `include. SystemVerilog added packages — real named namespaces holding types, parameters, functions, and classes that compile once and are referenced everywhere. Packages are the difference between a 50-file testbench that compiles in any order and one that breaks whenever a file moves. Every serious verification environment is built on a small number of well-organized packages.
The supporting cast matters just as much: typedef gives names to types so widths change in one place; parameter and localparam carry compile-time constants; and the rules of compilation units decide whether the simulator can even see your definitions. Interviewers use this topic to separate engineers who have built environments from those who have only read about them — "why did you get an undefined-type error and how did you fix it" has a precise answer rooted in compile order.
Sub-topics
Packages & Imports — declaring packages, wildcard vs explicit import, :: scope resolution, export.
Compilation Units & Compile Order — $unit, single vs separate compilation, undefined-type errors.
typedef, parameter & localparam — type naming discipline, constant scoping, type parameters.
`include vs import — textual inclusion vs namespace import, include guards, the hybrid VIP pattern.
Namespace Hygiene at Scale — collision failure modes, import style rules, vendor IP patterns.
PACKAGES & COMPILATION TOPIC MAP
source files (.sv)
│ compile order matters!
▼
┌─────────────────────────────────────────┐
│ compilation unit(s) $unit scope │
│ │
│ package my_pkg; ◄── compile FIRST │
│ typedef / parameter / function / │
│ class definitions │
│ endpackage │
│ │ │
│ │ import my_pkg::*; (namespace) │
│ │ my_pkg::item_t (explicit) │
│ ▼ │
│ module tb; interface bus_if; ... │
└─────────────────────────────────────────┘
▲
│ `include "file.svh" = textual paste
│ (preprocessor, NOT a namespace)Key takeaways
Packages are compiled namespaces; `include is textual paste — they solve different problems.
Compile packages before anything that imports them — compile order is a real dependency graph.
Prefer explicit imports or :: references in shared code; wildcard imports only in leaf scopes.