Skip to content

Commit

Permalink
improve xvlog linting (mshr-h#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshr-h committed Jan 5, 2023
1 parent ccf8d22 commit 76e891e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [1.10.0] - Unreleased

- Added an experimental option for Xilinx xvlog linting.
- `verilog.linting.xvlog.includePath` is to specify include directories.
- \[Caution\] I've only tested on Ubuntu on WSL2 platform. If you find any problems about xvlog linting, please let me know.

## [1.9.0] - 2022-12-29

- Added experimental options for Icarus Verilog linting. [#379](https://github.com/mshr-h/vscode-verilog-hdl-support/issues/379)
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ Use the following settings to configure the extension to your needs.
Choose the linter for you. Possible values are

- `iverilog`
- `xvlog`
- `modelsim`
- `verilator`
- `xvlog`
- `none`

- `verilog.linting.iverilog.arguments` (Default: nothing)
Expand Down Expand Up @@ -153,6 +153,16 @@ Use the following settings to configure the extension to your needs.

must be manually converted.

- `verilog.linting.xvlog.arguments` (Default: nothing)

Add custom arguments to Xilinx xvlog for linting, like `-Wall` . The argument `--nolog` will be added by the linter automatically.

- `verilog.linting.xvlog.includePath` (Default: nothing)

A list of directory paths to use while Xilinx xvlog linting.
All the paths are passed as arguments `-i <directory_path>`.
Paths can be specified either an absolute or a relate to the workspace directory.

- `verilog.ctags.path` (Default: `ctags` )

Path to your installation of Ctags if it isn't already present in your `PATH` environment variable.
Expand Down
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@
"default": "none",
"description": "Select the verilog linter. Possible values are 'iverilog', 'verilator', xvlog' or 'none'."
},
"verilog.linting.xvlog.arguments": {
"scope": "window",
"type": "string",
"default": "",
"description": "Add xvlog arguments here. They will be added to xvlog while linting."
},
"verilog.linting.iverilog.arguments": {
"scope": "window",
"type": "string",
Expand Down Expand Up @@ -327,6 +321,21 @@
"default": false,
"description": "If enabled, run verilator in WSL."
},
"verilog.linting.xvlog.arguments": {
"scope": "window",
"type": "string",
"default": "",
"description": "Add xvlog arguments here. They will be added to xvlog while linting."
},
"verilog.linting.xvlog.includePath": {
"scope": "window",
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"description": "A list of directory paths to use while xvlog linting."
},
"verilog.ctags.path": {
"scope": "window",
"type": "string",
Expand Down Expand Up @@ -502,4 +511,4 @@
"publisherDisplayName": "mshr-h",
"publisherId": "fcf32c99-a624-437b-9f47-9333ea128623"
}
}
}
4 changes: 2 additions & 2 deletions src/linter/BaseLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default abstract class BaseLinter {

// returns absolute path
protected resolvePath(inputPath: string): string {
if (!path || path.isAbsolute(inputPath) || !vscode.workspace.workspaceFolders[0]) {
return '';
if (path.isAbsolute(inputPath)) {
return inputPath;
}
return path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, inputPath);
}
Expand Down
54 changes: 33 additions & 21 deletions src/linter/XvlogLinter.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
import * as vscode from 'vscode';
import { ChildProcess, exec } from 'child_process';
import * as child_process from 'child_process';
import * as path from 'path';
import BaseLinter from './BaseLinter';

export default class XvlogLinter extends BaseLinter {
private xvlogPath: string;
private xvlogArgs: string;
private configuration: vscode.WorkspaceConfiguration;
private linterInstalledPath: string;
private arguments: string;
private includePath: string[];

constructor(diagnosticCollection: vscode.DiagnosticCollection, logger: vscode.LogOutputChannel) {
super('xvlog', diagnosticCollection, logger);
vscode.workspace.onDidChangeConfiguration(() => {
this.getConfig();
this.updateConfig();
});
this.getConfig();
this.updateConfig();
}

private getConfig() {
this.xvlogPath = <string>vscode.workspace.getConfiguration().get('verilog.linting.path');
this.xvlogArgs = <string>(
vscode.workspace.getConfiguration().get('verilog.linting.xvlog.arguments')
private updateConfig() {
this.linterInstalledPath = <string>(
vscode.workspace.getConfiguration().get('verilog.linting.path')
);
this.configuration = vscode.workspace.getConfiguration('verilog.linting.xvlog');
this.arguments = <string>this.configuration.get('arguments');
let path = <string[]>this.configuration.get('includePath');
this.includePath = path.map((includePath: string) => this.resolvePath(includePath));
}

protected lint(doc: vscode.TextDocument) {
this.logger.info('xvlog lint requested');
let svArgs: string = doc.languageId == 'systemverilog' ? '-sv' : ''; //Systemverilog args
let command =
this.xvlogPath + 'xvlog ' + svArgs + ' -nolog ' + this.xvlogArgs + ' "' + doc.fileName + '"';
this.logger.info('Execute command: ' + command);
let binPath: string = path.join(this.linterInstalledPath, 'xvlog');

let process: ChildProcess = exec(command, (_error: Error, stdout: string, _stderr: string) => {
let args: string[] = [];
args.push('-nolog');
if (doc.languageId === 'systemverilog') {
args.push('-sv');
}
args = args.concat(this.includePath.map((path: string) => '-i ' + path));
this.logger.warn(this.includePath.join(' '));
args.push(this.arguments);
args.push(`"${doc.fileName}"`);
let command: string = binPath + ' ' + args.join(' ');

this.logger.info('[xvlog] Execute');
this.logger.info('[xvlog] command: ' + command);

child_process.exec(command, (_error: Error, stdout: string, _stderr: string) => {
let diagnostics: vscode.Diagnostic[] = [];

let lines = stdout.split(/\r?\n/g);
lines.forEach((line) => {
stdout.split(/\r?\n/g).forEach((line) => {
let match = line.match(
/^(ERROR|WARNING):\s+\[(VRFC\b[^\]]*)\]\s+(.*\S)\s+\[(.*):(\d+)\]\s*$/
);
Expand All @@ -46,13 +61,10 @@ export default class XvlogLinter extends BaseLinter {
: vscode.DiagnosticSeverity.Warning;

// Get filename and line number
let filename = match[4];
let _filename = match[4];
let linenoStr = match[5];
let lineno = parseInt(linenoStr) - 1;

// if (filename != doc.fileName) // Check that filename matches
// return;

let diagnostic: vscode.Diagnostic = {
severity: severity,
code: match[2],
Expand Down

0 comments on commit 76e891e

Please sign in to comment.