RTL Studio Open IDE

Wiki Verilog language Headers and macros

Headers and macros

include, define, and why localparam usually beats a global macro.

.vh / .svh headers plus `include share constants. Prefer localparam / package over a pile of `define.

flowchart LR
  vh["defs.vh"] --> inc["`include"]
  inc --> m1[module_a]
  inc --> m2[module_b]
// defs.vh
`ifndef DEFS_VH
`define DEFS_VH
localparam int WIDTH = 8;
`endif

Guard headers. Textual macros have no scope — a typo becomes a global surprise.

Wrong vs right

Wrong — magic numbers and unguarded macros:

`define W 8
assign y = x + `W;

Right — typed constants in a package or localparam, include only at the files that need them.

See also