Chris's Personal Website

SystemVerilog Module Parser

1. Description

SVModule is set of python scripts/classes to add the ability to a text editor to parse (System)Verilog module declaration and paste it as instance, parameters... It manages module imports, parameters, standard and interface ports.

SVModule has been successfully tested with python 2.7 and 3.3.

2. License

SVModule is distributed under the GPLv3, the complete license description can be found here.

3. Download

If your favorite editor is not supported, download the standalone SVModule scripts and make your own plugin as described in the following sections.

4. Playing with the standalone scripts

Let's start by decompressing standalone scripts distribution.

$ tar xvfj standalone_svmodule_84.tar.bz2 $ cd svmodule

Firstly we have to parse and generate the internal representation in a temporary file ('/tmp/svmodule-dump' under linux):

$ python -c myfile.v

We can now play with the paste-as functions:

$ python -i

The paste-as function will output:

logic_unit #( .add_extra_instr (add_extra_instr), .add_select_instr (add_select_instr) ) logic_unit_inst ( .clk (clk), .enable (enable), .is_signed (is_signed), .opcode1 (opcode1), .opcode2 (opcode2), .cmode (cmode), .op0 (op0), .op1 (op1), .out_en (out_en), .out (out) );

Try the '-h' option to see the full list of paste-as functions.

5. Other text editor integration

The main concept is to declare functions for each action in a plugin flavoured to your editor's needs. For instance:

5.1. Copy function

The copy-module function must look for the module declaration (in the editor text buffer) just above the current cursor position.

Once the cursor is positioned at the beginning of the module, the region between the cursor and the ');' token can be copied in a string. the later can be stored in a temporary text file or just kept in memory as a global variable.

The advantage of storing the module string in a temporary file is to share the module declaration across multiple text editor processes.

5.2. Paste function

The paste-as functions must retrieve the module string and instantiate the SVModulePrinter. Thus, it can call the corresponding 'get' method to obtain the string to be inserted in the current text buffer.

Refers to '' or section 4 to get the list of available 'get' methods.

5.3. Example of integration in emacs

An example of integration is done in 'svmodule/'.

svmodule_emacs uses Pymacs, you must install this wonderful tool using the standard way of your linux distribution or simply following steps here

A basic way to load SVModule is to add the following lines to your '~/.emacs' file:

;;----- SVModule ----- (eval-after-load "pymacs" '(add-to-list 'pymacs-load-path "SVMODULE_INSTALL_DIR")) (pymacs-load "emacs" "svm-") (global-set-key (kbd "M-p M-w") 'svm-copy-module) (global-set-key (kbd "M-p M-r") 'svm-reverse-module) (global-set-key (kbd "M-p M-i") 'svm-paste-as-instance) (global-set-key (kbd "M-p M-m") 'svm-paste-as-module) (global-set-key (kbd "M-p M-g") 'svm-paste-as-packages) (global-set-key (kbd "M-p M-s") 'svm-paste-as-signals) (global-set-key (kbd "M-p M-c") 'svm-paste-as-parameters) (global-set-key (kbd "M-p M-l") 'svm-paste-as-init-latch) (global-set-key (kbd "M-p M-a") 'svm-paste-as-init-wire) (global-set-key (kbd "M-p M-t") 'svm-paste-as-doc-table) ;;--------------------

'SVMODULE_INSTALL_DIR' is the directory where SVModule python codes are located.

6. API description