Learning BSV‎ > ‎Getting Started‎ > ‎

Emacs Modes Tips

Generic Discussion

If you use emacs (there are color files for vim/gvim also), the compiler comes with a bsv-mode.el

This is covered in the user manual, but I am adding it here for ease of searching:

First add the directory that contains bsv-mode.el (in your release) to your lisp search path:


    (setq load-path
          (append (list
               (concat (getenv "BLUESPECDIR") "/../util/emacs")
               )
              load-path))

This uses your environment variable BLUESPECDIR to find where the bsv-mode.el is..  Next add these lines
to your init.el to load bsv-mode.el and set it to autoload bsv mode for files with .bsv extention:

   (load "bsv-mode")
   (add-hook 'bsv-mode-hook      `font-lock-fontify-buffer)

And this will get you emacs mode running :)

I also do the following, which in bsv mode allows me to compile the current buffer simply by hitting the "F3" key!  (You can of course, also M-x compile and the like)

   (add-hook 'bsv-mode-hook    `(lambda ()
      (font-lock-fontify-buffer)
      (local-set-key [f3]  'bsv-compile)
      (local-set-key [f4]  'bsv-goto-error-from-compilation-buffer)
      (local-set-key [f5]  'bsv-goto-error)
    ))

Now I add a variable and set my own desired compile options for when I hit F3 and call bsv-compile

    (setq bsc-compile-command  "bsc -u -verilog -elab ")

    (defun bsv-compile ()
      (interactive)
        (let ((file (replace-regexp-in-string "<[0-9]+>$" "" (buffer-name))))
           (compile (concat bsc-compile-command " " file))))


My exact settings:


In reality, I use a slightly more complete default compile.  Here is the exact lisp code I use (including all the options I use).  These are largely personal preferences, but here they are non the less:

   (setq bsc-compile-command  "bsc -u -verilog \
                                   -keep-fires -aggressive-conditions \
                                   -O -opt-undetermined-vals -unspecified-to x \
                                   -vdir obj -bdir obj -simdir obj -p obj:lib:+ ")

These options are all described in the user guide - but here is why I use them:

 -u                        => build dependent files before compiling this file
 -verilog -v95         => generate verilog 95 output (since there are a few rare tools that don't read v2k)
 -keep-fires           => for debugging verilog, it's always hand to see the exact "CAN_FIRE" and "WILL_FIRE" signals...
 -aggressive-condiions => more detail in the user guide, helps prevent rules from not firing when paths not executed in a rule a not ready
 -O                       => turn on some internal optimizations
 -opt-undermined-vals  => optimize values not needed or known... (such as inputs to registers when they are not loaded, etc)
 -unspecified-to x     => by default, unspecified values are AAAAA, but x works better with dc_shell, at the risk of x in your simulations (which is bad anyway)
 -vdir obj -bdir obj -simdir obj => dump various object files to "obj" directory
 -p obj:lib:+          => search for input files and .bo files in obj directory first, then lib (which I commonly use), then + (the builtin default libraries path)


Since I tend to like to dump all my object/generated files to "obj" (so clean is pretty quick - just "rm -fR obj"), modify my compile code slightly to make sure the obj directory exists:

  (defun bsv-compile ()
    (interactive)
    ;; always create "obj" since I often dump files there
    (if (not (file-exists-p "obj"))
        (make-directory "obj"))
    ;; remove <1> from duplicate buffer
    (let ((file (replace-regexp-in-string "<[0-9]+>$" "" (buffer-name))))
      (compile (concat bsc-compile-command " " file))))

Comments