Run SystemVerilog on a Mac
Recently, I needed to write, compile, and run some SystemVerilog modules. Being a Mac user, my options were to use simulators like EDA Playground (browser based) or ModelSim — the latter does not even run natively on a Mac. In fact, getting it to work requires installing a virtual machine (VM) on my Mac, a windows or linux operating system in the VM, and then ModelSim. One installation too many! Yikes!!!
Well, let me tell you: I tried both. And while they work just fine, I wanted to run SystemVerilog on my Mac without either. Off I strode in search of how. Welcome Icarus Verilog.
Icarus Verilog helps you simulate and synthesize logic gates. More, it enables you compile and run SystemVerilog modules on a Mac — hassle free. How? I will say, right after I tell you how to install it. Running the snippets below (in your terminal/CLI) will install homebrew, icarus-verilog, and gtkwave. The latter shows you waveforms simulating the gate you have described in your SystemVerilog code. (We will return to this.)
Now let’s write a simple two-input NAND gate which negates the AND gate — it outputs 1 (i.e. True) if either input is 0 (i.e. False); it outputs 0 if both inputs are 1. The SystemVerilog module below describes this.
To view the waveforms, let’s create test cases (called test benches) to validate that the (already described) gate is functioning as we’d expect. The SystemVerilog test bench module below handles this.
Now let’s compile and run the program using the following in your terminal:
iverilog -g2012 -o nand nand_tb.sv nand.sv
Amongst other things, this creates a new file,
nand.vcd, which contains the gate’s waveforms. This is where/why you need gtkwave. (Tada! Told you we will return to this.) If you properly installed gtkwave, double-clicking
nand.vcd will open it in gtkwave. And there you can visualize the gate’s waveforms shown below.
Not so bad eh! Indeed! You can use EDA Playground or ModelSim to write and run your SystemVerilog modules. Or Icarus Verilog. Your choice!