Skip to content

Commit

Permalink
Merge pull request #1 from vengin/master
Browse files Browse the repository at this point in the history
Improved vcom regex parsing, added support for vlog linting
  • Loading branch information
jevogel committed Aug 13, 2018
2 parents da778e7 + e4e735c commit b981b33
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 20 deletions.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
SublimeLinter-contrib-vcom
================================

This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to `vcom`, a VHDL compiler provided with [ModelSim](https://www.mentor.com/products/fv/modelsim/) and QuestaSim which provides a linting mode. It will be used with files that have the “VHDL” syntax.
This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to `vcom`/`vlog` - VHDL/Verilog/SystemVerilog compilers provided with [ModelSim](https://www.mentor.com/products/fv/modelsim/) and QuestaSim which provide a linting mode. `vcom` will be used with "VHDL" files , `vlog` with "Verilog" and "SystemVerilog" files.

## Installation
SublimeLinter must be installed in order to use this plugin.

Please use [Package Control](https://packagecontrol.io) to install the linter plugin.

Before installing this plugin, you must ensure that `vcom` is installed on your system.
Before installing this plugin, you must ensure that `vcom`/`vlog` are installed on your system.

In order for `vcom` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. The docs cover [troubleshooting PATH configuration](http://sublimelinter.readthedocs.io/en/latest/troubleshooting.html#finding-a-linter-executable).
In order for `vcom`/`vlog` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. The docs cover [troubleshooting PATH configuration](http://sublimelinter.readthedocs.io/en/latest/troubleshooting.html#finding-a-linter-executable).

## Settings
- SublimeLinter settings: http://sublimelinter.readthedocs.org/en/latest/settings.html
- Linter settings: http://sublimelinter.readthedocs.org/en/latest/linter_settings.html


## Passing arguments to vcom/vlog
Arguments can be passed in a [linter settings](http://www.sublimelinter.com/en/stable/linter_settings.html#args) file or set in a [project settings](http://www.sublimelinter.com/en/stable/settings.html#project-settings) file:
<ol>
<li>Using linter settings file:

```javascript
{
"linters": {
"vcom": {
"args": ["-check_synthesis", "-2002"],
"working_dir": "$project_path/../sim",
},
}
```
</li>
<li>Alternately, project specific arguments can be set in a project file:
```javascript
"settings":
{
// SublimeLinter-contrib-vcom
"SublimeLinter.linters.vcom.args": ["-check_synthesis", "-2002"],
"SublimeLinter.linters.vcom.working_dir": "$project_path/../sim",
},
```
</li>
</ol>
## Demo
`vcom` for vhdl file:
![vcom_lint_example](https://user-images.githubusercontent.com/41512424/43842022-1b0f35ac-9b2d-11e8-981b-67d98e905fa3.png)
`vlog` for verilog file:
![vlog_lint_example](https://user-images.githubusercontent.com/41512424/43842998-3000ae58-9b2f-11e8-8dff-4023410403c4.png)
142 changes: 126 additions & 16 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,130 @@
import SublimeLinter
from SublimeLinter.lint import Linter
from SublimeLinter.lint import Linter, util
import sublime
import sublime_plugin
import SublimeLinter.lint

def get_SL_version():
"""
Return the major version number of SublimeLinter.
"""
return getattr(SublimeLinter.lint, 'VERSION', 3)

class Vcom(Linter):
cmd = ('vcom', '-2008', '-lint', '-check_synthesis', '${file}', '${args}')
error_stream = SublimeLinter.lint.STREAM_STDOUT

################################################################################
# vcom
################################################################################
class vcom(Linter):
# Arguments can be passed in a linter settings file:
# http://www.sublimelinter.com/en/stable/linter_settings.html#args
# E.g.:
# "linters": {
# "vcom": {
# "args": ["-check_synthesis", "-2002"],
# "working_dir": "d:/tmp/tst/vhdl",
# },
#
# Alternately, project specific arguments can be set in a project file:
# http://www.sublimelinter.com/en/stable/settings.html#project-settings
# E.g.:
#"settings":
# {
# // SublimeLinter-contrib-vcom
# "SublimeLinter.linters.vcom.args": ["-check_synthesis", "-2002"],
# "SublimeLinter.linters.vcom.working_dir": "d:/tmp/tst/vhdl",
# },
#
cmd = ('vcom', '${args}', '${file}')
multiline = False
error_stream = util.STREAM_BOTH

if get_SL_version() == 3:
syntax = ('vhdl')
else:
on_stderr = None # handle stderr via split_match
defaults = {
'selector': 'source.vhdl',
}

# there is a ":" in the filepath under Windows like C:\DIR\FILE
if sublime.platform() == 'windows':
filepath = r'[^:]+:[^:]+'
else:
filepath = r'[^:]+'

# http://www.sublimelinter.com/en/stable/linter_attributes.html#regex-mandatory
# Modified regex:
# 1) Since ModelSim doesn't provide the 'Col' information, we utilize the
# <near> field, when possible (i.e. use a "quoted text" to derive <near>
# field position)
# 2) Note that <code> field isn't used (it can be, but it doesn't really
# serve any meaningful purpose)
# 3) Suppress message "** Error: file(line): VHDL Compiler exiting"
# at the end of any file with errors
regex = (
r'.*'
r'^\*\* ((?P<error>Error)|(?P<warning>Warning)): '
r'.*(?P<file>\w+\.vhd)'
r'\((?P<line>\d+)\): '
r'(near "(?P<near>.+)": )?'
r'\((?P<code>vcom-\d+)\)?'
r'(?P<message>.*)'
r'\*\* ((?P<error>Error)|(?P<warning>Warning)): '
r'(?P<file>.*)'
r'\((?P<line>\d+)\): '
r'(VHDL Compiler exiting)?'
r'(?P<message>([^"]*\"(?P<near>[^"]+)\")?.*)'
.format(filepath)
)
multiline = True
defaults = {
'selector': 'source.vhdl'
}


class SublimeLinterVcomRunTests(sublime_plugin.WindowCommand):
"""
To do unittests, run the following command in ST's console:
window.run_command('sublime_linter_vcom_run_tests')
"""
def run(self):
from .tests.vcom_regex_tests import run_tests
run_tests(vcom.regex)


################################################################################
# vlog
################################################################################
class vlog(Linter):
# refer to description in vcom
cmd = ('vlog', '${args}', '${file}')
multiline = False
error_stream = util.STREAM_BOTH

if get_SL_version() == 3:
syntax = ('verilog', 'systemverilog')
else:
on_stderr = None # handle stderr via split_match
defaults = {
'selector': "source.verilog, source.systemverilog",
}

# there is a ":" in the filepath under Windows like C:\DIR\FILE
if sublime.platform() == 'windows':
filepath = r'[^:]+:[^:]+'
else:
filepath = r'[^:]+'

# http://www.sublimelinter.com/en/stable/linter_attributes.html#regex-mandatory
# Modified regex:
# 1) Since ModelSim doesn't provide the 'Col' information, we utilize the
# <near> field, when possible (i.e. use a single/double quoted text
# to derive <near> field position)
# 2) Note that <code> field isn't used (it can be, but it doesn't really
# serve any meaningful purpose)
regex = (
r'\*\* ((?P<error>Error)|(?P<warning>Warning)): '
r'(\(vlog-\d+\) )?'
r'(?P<file>.*)'
r'\((?P<line>\d+)\): '
r"(?P<message>([^\"]*(?P<quote>['\"])(?P<near>[^'\"]+)(?P=quote))?.*)"
.format(filepath)
)


class SublimeLinterVlogRunTests(sublime_plugin.WindowCommand):
"""
To do unittests, run the following command in ST's console:
window.run_command('sublime_linter_vlog_run_tests')
"""
def run(self):
from .tests.vlog_regex_tests import run_tests
run_tests(vlog.regex)
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"install": "messages/install.txt"
"install": "messages/install.txt",
"1.1.0": "messages/1.1.0.txt"
}
6 changes: 6 additions & 0 deletions messages/1.1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Version 1.1.0
-------------
* Added support for vlog compiler linting
* Improved vcom regex, to derive column position from double quoted text via <near> field
* Added UnitTests to verify vcom/vlog regex
* Updated readme
26 changes: 26 additions & 0 deletions miscellaneous/demo.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module demo (
out , // Output of the counterq
enable , // enable for counter
clk , // clock Input
reset // reset Input
);

// Ports
output [7:0] out;
input enable, clk, reset;

// Internal Variables
reg [7:0] out;
// Generate Warning
parameter TEST = 4294967295;

always @(posedge clk)
if (rest) begin
out <= 8'b0;
end else if (enable) begin
out <= out+1;
end else begin
out <= out;
end

endmodule
24 changes: 24 additions & 0 deletions miscellaneous/demo.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
library ieee;
use ieee.std_logic_1164.all;
--------------------------------------------------------------------------------
entity demo is
port (
aclr : in std_logic;
clk : in std_logic;
d : in std_logic;
q : out std_logic
);
end entity;
--------------------------------------------------------------------------------
architecture beh of demo is
begin

process (clk)
begin
if (aclr = '1') then
q <= '0';
elsif rising_edge(clk) then
q <= dd;
end if;
end process;
end architecture;
Loading

0 comments on commit b981b33

Please sign in to comment.