This is a little thing I did for my UCLA W23 COM SCI M152A: Introductory Digital Design Laboratory course when we first started learning Verilog:
Hey y'all, for those who want to be able to play around with Verilog code in a more familiar editor, here's what I did:
-
Install the Icarus Verilog compiler (the one we used on EDA playground) on your local machine.
-
For Windows, I found one at https://bleyer.org/icarus/. Remember to choose "Add to user PATH" in the installation wizard, or you'll have to do it manually later.
-
For Mac users, you can install it with Homebrew (https://formulae.brew.sh/formula/icarus-verilog):
brew install icarus-verilog
(Disclaimer: I don't actually have a Mac and only tested it on my WSL copy of Homebrew)
-
-
Open up VS Code in whatever folder you want to play around in. Create
testbench.sv
anddesign.sv
, just like in the playground. -
Write your code.
-
Compile the code at the command line with the syntax very similar to GCC:
iverilog [FLAGS] FILENAMES... [-o BINARY_NAME]
:
iverilog -Wall -g2012 design.sv testbench.sv -o a.out
- Run the compiled executable with:
vvp a.out
- If you're familiar with them, you can use scripts or Makefiles to automate the compilation. I also wrote a helper function you can paste straight into your
~/.bashrc
so all you have to do is enterverilog
at the command line and it'll be like you hit the blue play button in the playground. You can also override the default filenames with your own. Here's how you use it:
$ code ~/.bashrc # or whatever editor you use
$ # ...paste my function...
$ source ~/.bashrc # refresh your shell
$ verilog
verilog: iverilog -Wall -g2012 'design.sv' 'testbench.sv' && vvp a.out
1
Exited without error
Example with one of your custom files instead:
$ verilog testbench.sv "my custom adder.sv"
verilog: iverilog -Wall -g2012 'testbench.sv' 'my custom adder.sv' && vvp a.out
1
Exited without error