How do I compile and run a VHDL program on Mac with ghdl?

That as they say is a big ask!

There's a version of ghdl for OS X running on Intel processors for versions 10.5, 10.6,10.7 and 10.8 available from ghdl.free.fr (can be downloaded at GHDL for Mac OS X). It's the mcode version (like on Windows), which means it doesn't produce object codes or a standalone executable of a VHDL model with the consequence you can't bind foreign objects (subprograms) to the model.

The elaborated model only exists in memory at run time and the -e elaborate command is superfluous other than an entry in the working library .cf file. In an mcode version of ghdl the -r run command also elaborates. All you are going to see is the work-obj93.cf file for the working directory and any .cf files for pre-analyzed libraries, by default these will show up in /usr/local/ghdl/libraries, the executable ghdl found in /usr/local/bin links to /usr/local/ghdl/translate/ghdldrv/ghdl_mcode, and /usr/local/ghdl is a stripped down tree resulting from the compilation of the ghdl_mcode version.

This version is derived from svn129 (following the ghdl-0.29 release), and contains an i386 binary.

The documentation for ghdl is found in /usr/local/ghdl/doc/, there's the ghdl man page which is linked elsewhere, ghdl.html and ghdl.texi which are the ghdl manual and not linked elsewhere. In ghdl.html you could search for every occurrence of 'Windows' to find reference to the mcode version. As an oversight I didn't think to amend the ghdl manual to include the word mcode wherever Windows appeared and release modified manual.

Where ever 'Windows' appears it should be read as 'Windows or other mcode version'.

In the ghdl manual see 1.3 What is GHDL?, (The Windows(TM) version of GHDL is not based on GCC but on an internal code generator). Also 2.1 The hello world program:

2.1 The hello world program

To illustrate the large purpose of VHDL, here is a commented VHDL "Hello world" program.

 --  Hello world program.
 use std.textio.all; --  Imports the standard textio package.

 --  Defines a design entity, without any ports.
 entity hello_world is
 end hello_world;

 architecture behaviour of hello_world is
 begin
    process
       variable l : line;
    begin
       write (l, String'("Hello world!"));
       writeline (output, l);
       wait;
    end process;
 end behaviour;

Suppose this program is contained in the file hello.vhdl. First, you have to compile the file; this is called analysis of a design file in VHDL terms.

 $ ghdl -a hello.vhdl

This command creates or updates a file work-obj93.cf, which describes the library ‘work’. On GNU/Linux, this command generates a file hello.o, which is the object file corresponding to your VHDL program. The object file is not created on Windows.

Then, you have to build an executable file.

 $ ghdl -e hello_world

The ‘-e’ option means elaborate. With this option, GHDL creates code in order to elaborate a design, with the ‘hello’ entity at the top of the hierarchy.

On GNU/Linux, the result is an executable program called hello which can be run:

 $ ghdl -r hello_world

or directly:

 $ ./hello_world

On Windows, no file is created. The simulation is launched using this command:

 > ghdl -r hello_world

The result of the simulation appears on the screen:

 Hello world!

Saving the source code for the hello_world command to the file hello.vhdl and executing the commands:

david_koontz@Macbook: ghdl -a hello.vhdl

david_koontz@Macbook: ghdl -e hello_world

david_koontz@Macbook: ghdl -r hello_world

Yields:

Hello world!

on standard output (the TTY session in your terminal window).

You'll end up with a work-obj93.cf library configuration file in the current working directory and no other output files. You'll also want to understand the implications of the -r run command (section 3.1.3), with no optional secondary unit passed on the command line VHDL defaults to the last compiled architecture.

Obtaining Tony Bybell's gtkwave gtkwave.app, the documentation is found in /Applications/gtkwave.app/Contents/Resources/doc, both a source .odt file and a PDF file. (You can select an application in the Applications folder and 'Show Package Contents' to navigate to the doc directory).

There's a waveform format unique to ghdl called ghw, which can be invoked with the run command option '--wave=.ghw'. See ghdl manual 4.1 Simulation options. Also see the vcd options in that directory should you choose to use VCD instead.

You should also limit the run time duration with a guard timer should your test bench provide a free running clock. VHDL will only stop executing when either ther are no more scheduled signal updates or execution time maxes out. This is a run command option along the lines of '--stop-time=587200ns'.

The OS X gtkwave.app is sensitive to two file types with extensions .ghw and .gtkw, the first the ghdl waveform dump file, the second gtkwave's configuration file with an OS X suffix allowing invocation of gtkwave by clicking on the gtkw file. The configuration file has to be saved after setting up your wave form display in gtkwave before it exists. See the gtkwave manual. A ghw file can be clicked on and gtkwave has a set of rules used to search for the applicable gtkw file.

There are a couple of advantages to using the ghw file format. The automatic invocation of the gtkwave app by clicking on files is one. Another is that ghdl saves all signal transactions to it's ghw dump file. You can always select more in gtkwave to display more information. While this can be a disadvantage in large models the ghw format allows any type or subtype enumeration literal display.

Joining the GHDL discuss list and posting a question is a good way to attract ghdl expertise attention. (And yes the certificate for gna.org is expired or otherwise invalid). Tony Bybell provides an email contact on the gtkwave web page but exigencies of paid employment limit his availability.


Elaborating the use of ghdl and gtkwave with an example.

The original poster asked for some real examples with command line values. There's a however poor GHDL/GTKWave Tutorial (PDF, 234 KB) that contains an example and used VCD.

I'll list the command lines for a GHDL Waveform format version:

david_koontz@Macbook: ghdl -a CarryRipple.vhd

david_koontz@Macbook: ghdl -a CarryRipple_tb.vhd

david_koontz@Macbook: ghdl -e carryRipple_tb

david_koontz@Macbook: ghdl -r carryRipple_tb --wave=carryRipple_tb.ghw

invoking gtkwave.app can either be done by clicking on the resulting carryRipple_tb.ghw or by using OS X's open command:

david_koontz@Macbook: open -a gtkwave carryRipple_tb.ghw

Gtkwave's SST window (upper left) will display top, expand by clicking the + box. Do the same for the revealed carryripple_tb. Click a. In the signals window select a[3:0] and hit the insert button. Repeat for b.

In the SST window select U0 and then in the signals window select cin hit the insert button then the same for cout.

In the SST window select s, and in the signals window select s[3:0] and hit insert.

And yes getting the source for the two VHDL files from the 'tutorial' was painful. I didn't do it.

You might also note the assignment of 'X' to Cin at 60 ns in the gtkwave display, I did it to show the last values assigned in the testbench.

I wouldn't claim it's a good tutorial, but you're getting what you paid for here. Doing better would have been a bigger ask.

The test bench (carryRipple_tb.vhd) provides stimulous to drive the model (CarryRipple.vhd) during simulation. The model quits executing after the last signal event so no stop time need be passed to the run command ( e.g. --stop-time=587200ns).

There's also a five part GHDL/GTKWave Tutorial on Youtube by Chad Kersey. The resolution isn't so good and it's Linux centric. Part 0 is about installing the two tools. The only real difference in my example is using the ghw waveform format. Most browsers will allow you to see the gtkwave window shot below at full size.

enter image description here

added

There's a recent answer showing a demonstration with a Toggle Flip Flop, showing an error in the original VHDL code, and three possible fixes. It uses configuration declarations to run the various fixed versions. See how to avoid delay in the output of simple process statement in VHDL.


A New Mac OS X gcc version of GHDL

There's a new version of ghdl available from ghdl-updates / Builds / ghdl-0.31 / OSX, a gcc version that includes the mcode verison.

It's only known to run on OS X 10.9 but I think it would run OS X 10.8 if Xcode and it's command line tools were installed - the gcc version currently depends on /usr/bin/as and /usr/bin/ld, which are part of the essentials package installing OS X 10.9 and available by installing Xcode command line tools on OS X 10.8.

Once this version of ghdl is installed, in a terminal you can

info ghdl

Scroll down to Starting with GHDL, hitting carriage return. Scroll down to The hello world program (carriage return), A full adder (carriage return), or Starting with a design (carriage return). The first one is a VHDL hello world program, the second one is a one bit adder with a test bench. The Starting with a design leads you to a download link and directions for a DLX processor simulation.

I'm planning to develop a 10.6 - 10.9 gcc version of ghdl that doesn't depend on Xcode for 10.6 - 10.8, and runs on 10.9. It'll likely be version 0.32 of ghdl.

Tony Bybell's gtkwave.app runs on OS X 10.6 - 10.9 and is available along with it's manual from the GTKWave SourceForge page. The latest version of the application can be downloaded from this link on Sourceforge - gtkwave.zip.

There are several ghdl/gtkwave tutorials available on YouTube, although none are OS X specific, try googling.

ghdl has it's own gtkwave format, GHW which is VHDL friendly and allows you to peer into complex composite types. ghdl-0.33 will likely include support for Tony Bybell's FSB format as well.

The more adventuresome can build ghdl from scratch on OS X, see Instructions for building ghdl-0.31 with gcc4.8.2 on OS X 10.9. Building with gcc4.9.1 would require the ghdl-0.32 release available from the Mercurial archive found here. When released version ghdl-0.32 binaries will also be available from Sourceforge.

The Sourceforge site ghdl-updates is the location for on going ghdl development activity by the author of ghdl, Tristan Gingold.

In addition to joining the ghdl discussion list or perusing it's archives you can file bug reports on the ghdl-updates Tickets page, where you view both open and closed issues.

The development future for ghdl is bright. Future releases are expected to focus on IEEE Std 1076-2008 compliance for the near future. There's also development toward using ghdl as an llvm front end as well as a purely interpretive version to supplant ghdl-mcode.

It's possible with binary releases of ghdl and gtkwave to separate user from developer.

Tags:

Macos

Vhdl

Ghdl