Using Emacs to Debug Verilog Compiles in Mentor Questa

There are a series of articles on Sigasi on their Verilog IDE compared to Emacs.  I was intrigued by their description of using Emacs to debug Verilog compilations.

Let’s assume you have installed ModelSim and configured Emacs accordingly (I won’t go into that). Syntax checking would go something like this:

Write some interesting code:
- Trigger a ModelSim build (usually, this can be done with a key combination, like CTRL-C, CTRL-K)
- The list of errors shows up at the bottom of your screen. For each error:
- Go to the error location in the code (key combination: CTRL-X `)
- Read the context; you have been typing for a while, so you need to think a bit before you figure out the problem.
- Fix the error
— Sigasi

I hadn't used Emacs to compile and parse errors for Mentor Questa before and decided to see what that would be like.

The description above from Sigasi is somewhat complete.  But, Emacs can do a little better for standard languages than having to enter in line numbers to navigate around compile errors out of the box.  (I am using Emacs 24 for this write up.)  The built in Emacs compilation mode is not terrible and at least gives a starting point for compiling and debugging standard languages and custom ones.

Mentor Questa Support is Not Built in to Emacs - Of Course!

It turns out if you are doing something a little more mainstream like debugging C out of the box, Emacs is all set up.  Emacs will know how to compile the file you are using and will have the regular expressions to parse the log messages so you can quickly jump to the offending file and be transported to the right line.

Unfortunately, Verilog is not so mainstream (and no standard compiler doesn't help).  To make Emacs understand how the simulator works and spits out errors involves extending Emacs to know how to launch your Verilog simulator and how to interpret the console messages.  This is how to do it.

The Short Answer

The short answer is add the following lines to your ~/.emacs.d/init.el file (without the numbers in front of the lines) and then close Emacs and restart:

1 (require 'compile)
2
3 (add-to-list 'compilation-error-regexp-alist
4 '("^\\*\\\* Error: \\(.*?\\)(\\(.*?\\)):" 1 2))
5
6 (setq compile-command "qverilog +cover covmerge1.sv -R -coverage")
7 (setq compilation-context-lines 10)
8 (setq compilation-scroll-output t)
9 (setq compilation-auto-jump-to-first-error t)

Break Down

I'll break it down to explain what these lines mean.

Line 1-4 lines are taken from an explanation on the Emacs Wiki titled Creating Your Own Compile Error Regexp which is pretty good at giving you ideas on how to tell Emacs how to interpret how Mentor Questa spits out error lines in its log.  Line 1 is needed because before you add to the emacs compile list you need to load it.

A typical Mentor Questa line for an error during compilation is below.  The line starts with some "**" and the word "Error".  Then there is a file name with the line number in quotes.  The regular expression entered in on line 3-4 pass the values for the file name (1) and line number (2) as the pieces that Emacs will use to help you debug.

Example Error Line in Mentor Questa

** Error: covmerge1.sv(22): 'it' is an unknown type.

Line 6 is a convenience to have the compile command be autofilled in for you.  I put in the example Mentor Questa qverilog line, but in reality your project will have a custom compile script.  Just make sure it is in non-gui mode so Emacs can launch and intercept the streaming text output.  You might even want to have a "-buildonly" type switch if you only want to debug compilation problems and not simulation problems.

If you are lucky and have a project that uses Make files, you might not even have to include this line since Emacs uses "make -k" as the default compile command.

Line 7-9 deal with more convenience features like leaving some context between messages, scrolling the compile output, and jumping to the first error.

Now How Do I Use It

Once you have the lines above in your ~/.emacs.d/init.el file and restart emacs you can start following the standard directions from Emacs on working with Compilation Mode which has a lot more detail.

Here is my super short recipe to get started:

  1. Open emacs in the directory you will want to run your compile in - GUI mode for Emacs will be a little easier to work with but not necessary
  2. Run the command compile from emacs: ALT-x compile
  3. Customize the compile line to your needs and press Enter
  4. Your Emacs screen will now be split into two panes switch to the compilation window
  5. In the compilation window, you can find that error lines will have a left fringe that tells you Emacs detected an error from the regexp.  Navigate to that line and press Enter.
  6. You will be transported to the file and line number that had the error to fix in the other frame
  7. Repeat from step 4

What it Looks Like

In the example below, I took the file covmerge1.sv from a previous post and changed "bit clk" to "it clk" a syntax violation.  We can see the below "compilation" window lists off a series of lines with errors in them - all cascading from its first detected error on line 22.

emacs_compile.png

The regular expression I have for Mentor Questa to detect errors is certainly not complete.  It could be extended to recognize Fatal errors or other types of errors in code and simulation.  Or even to interpret your style of UVM errors.

It is possible to debug compile and simulation errors as well with this method.