Oh VHDL, you make my life so wonderful. I just want to be able to enable or disable different debugging features at compile time. But no, there’s no real preprocessor support in the VHDL world.
So my solution was to write a wrapper script that fakes out GCC into using its preprocessor and then generating a new VHDL file. It takes two files as input: the
prj file you would use for XST and a
config file that has a bunch of key=value pairs that get passed as directives for the GCC preprocessor.
For each file, it then invokes the following magic:
gcc -Dwhatever=whatever -traditional-cpp -E -x c -P -C file.vhd
This causes GCC to treat the VHDL file as just a generic C file and only processes the standard preprocessor directives like
It then saves the result to a new file. So if you were processing
file.vhd, it would generate (by default)
file.gen.vhd. It stores these files in the same directory as their pre-preprocessed versions.
Finally it creates a new
prj file that you should pass into XST.
So, it’s super easy to use. All you need to do is run
vhd-preproc.py -p /path/to/project.prj -c /path/to/config and all your files will be preprocessed.