finish libPick set top function | iverilog simulation

This commit is contained in:
锦恢 2023-04-20 22:40:56 +08:00
parent 7fee932ade
commit 8a4fc5bb70
9 changed files with 98 additions and 33 deletions

View File

@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as child_process from 'child_process';
import { hdlParam } from '../../hdlParser';
@ -53,7 +54,7 @@ class Simulate {
};
let code = hdlFile.readFile(path);
if (!code) {
MainOutput.report('error when read ' + path, ReportType.Error);
MainOutput.report('error when read ' + path, ReportType.Error, true);
return;
}
@ -69,11 +70,14 @@ class Simulate {
// make simulation dir
const defaultSimulationDir = hdlPath.join(opeParam.prjInfo.arch.prjPath, 'simulation', 'icarus');
simConfig.simulationHome = setting.get('function.simulate.simulationHome', '');
if (!simConfig.simulationHome) {
if (!fs.existsSync(simConfig.simulationHome)) {
simConfig.simulationHome = defaultSimulationDir;
}
if (!hdlFile.isDir(simConfig.simulationHome)) {
MainOutput.report('create dir ' + simConfig.simulationHome, ReportType.Info);
hdlDir.mkdir(simConfig.simulationHome);
}
@ -91,7 +95,7 @@ class Simulate {
simConfig.installPath = setting.get('function.simulate.icarus.installPath', '');
if (simConfig.installPath !== '' && !hdlFile.isDir(simConfig.installPath)) {
MainOutput.report(`install path ${simConfig.installPath} is illegal`, ReportType.Error);
MainOutput.report(`install path ${simConfig.installPath} is illegal`, ReportType.Error, true);
return;
}
@ -183,7 +187,7 @@ class IcarusSimulate extends Simulate {
const iverilogPath = simConfig.iverilogPath;
const argu = '-g2012';
const outVvpPath = '"' + hdlPath.join(simConfig.simulationHome, 'out.vvp') + '"';
const mainPath = '"' + path + '"';
const mainPath = '"' + path + '"';
const cmd = `${iverilogPath} ${argu} -o ${outVvpPath} -s ${name} ${mainPath} ${dependenceArgs} ${thirdLibPath}`;
MainOutput.report(cmd, ReportType.Run);
@ -255,7 +259,6 @@ class IcarusSimulate extends Simulate {
}
const runInTerminal = vscode.workspace.getConfiguration().get('function.simulate.runInTerminal');
console.log(runInTerminal);
if (runInTerminal) {
this.execInTerminal(command, cwd);
@ -267,8 +270,6 @@ class IcarusSimulate extends Simulate {
private getAllOtherDependences(path: AbsPath, name: string): AbsPath[] {
const deps = hdlParam.getAllDependences(path, name);
if (deps) {
console.log(deps);
return deps.others;
} else {
MainOutput.report('Fail to get dependences of path: ' + path + ' name: ' + name, ReportType.Warn);
@ -280,7 +281,8 @@ class IcarusSimulate extends Simulate {
const name = hdlModule.name;
const path = hdlModule.path;
if (!hdlParam.isTopModule(path, name, false)) {
MainOutput.report('path: ' + path + ' name: ' + name + ' is not top module');
const warningMsg = name + ' in ' + path + ' is not top module';
MainOutput.report(warningMsg, ReportType.Warn, true);
return;
}
const dependences = this.getAllOtherDependences(path, name);
@ -289,7 +291,8 @@ class IcarusSimulate extends Simulate {
const cwd = hdlPath.resolve(hdlModule.path, '..');
this.exec(simulationCommand, cwd);
} else {
MainOutput.report('Fail to generate command', ReportType.Error);
const errorMsg = 'Fail to generate command';
MainOutput.report(errorMsg, ReportType.Error, true);
return;
}
}
@ -309,7 +312,7 @@ class IcarusSimulate extends Simulate {
const currentFile = hdlParam.getHdlFile(path);
if (!currentFile) {
MainOutput.report('path ' + path + ' is not a hdlFile', ReportType.Error);
MainOutput.report('path ' + path + ' is not a hdlFile', ReportType.Error, true);
return;
}
const items = getSelectItem(currentFile.getAllHdlModules());

View File

@ -58,7 +58,6 @@ async function testbench() {
placeHolder: 'Select a Module to generate testbench'
};
const path = hdlPath.toSlash(uri.fsPath);
console.log(path);
if (!hdlFile.isHDLFile(path)) {
return;

View File

@ -52,27 +52,26 @@ function canExpandable(element: ModuleDataItem) {
class ModuleTreeProvider implements vscode.TreeDataProvider<ModuleDataItem> {
treeEventEmitter: vscode.EventEmitter<ModuleDataItem>;
treeEvent: vscode.Event<ModuleDataItem>;
_onDidChangeTreeData: vscode.EventEmitter<ModuleDataItem>;
onDidChangeTreeData: vscode.Event<ModuleDataItem>;
firstTop: FirstTop;
srcRootItem: ModuleDataItem;
simRootItem: ModuleDataItem;
constructor() {
this.treeEventEmitter = new vscode.EventEmitter<ModuleDataItem>();
this.treeEvent = this.treeEventEmitter.event;
this._onDidChangeTreeData = new vscode.EventEmitter<ModuleDataItem>();
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
this.firstTop = {
src: null,
sim: null,
};
this.srcRootItem = {icon: 'src', type: HdlFileType.Src, name: 'src', range: null, path: '', parent: null};
this.simRootItem = {icon: 'sim', type: HdlFileType.Sim, name: 'sim', range: null, path: '', parent: null};
}
public refresh(element?: ModuleDataItem) {
if (element) {
this.treeEventEmitter.fire(element);
this._onDidChangeTreeData.fire(element);
} else {
// refresh all the root in default
this.refreshSim();
@ -81,13 +80,11 @@ class ModuleTreeProvider implements vscode.TreeDataProvider<ModuleDataItem> {
}
public refreshSrc() {
this.treeEventEmitter.fire(this.srcRootItem);
console.log('enter');
this._onDidChangeTreeData.fire(this.srcRootItem);
}
public refreshSim() {
this.treeEventEmitter.fire(this.simRootItem);
this._onDidChangeTreeData.fire(this.simRootItem);
}
@ -134,10 +131,8 @@ class ModuleTreeProvider implements vscode.TreeDataProvider<ModuleDataItem> {
return treeItem;
}
public getChildren(element?: ModuleDataItem | undefined): vscode.ProviderResult<ModuleDataItem[]> {
public getChildren(element?: ModuleDataItem | undefined): vscode.ProviderResult<ModuleDataItem[]> {
if (element) {
console.log(element);
const name = element.name;
if (name === 'sim' || name === 'src') {
element.parent = null;

View File

@ -40,11 +40,31 @@ class Output {
return this._ignoreTypes.includes(type);
}
public report(message: string | unknown, type: ReportType = ReportType.Info) {
private showInWindows(message: string, type: ReportType = ReportType.Info) {
if (type === ReportType.Warn) {
vscode.window.showWarningMessage(message);
} else if (type === ReportType.Error) {
vscode.window.showErrorMessage(message);
} else {
vscode.window.showInformationMessage(message);
}
}
/**
*
* @param message message
* @param type report type
* @param reportInWindows whether use vscode.windows.<api> to show info
*/
public report(message: string | unknown, type: ReportType = ReportType.Info, reportInWindows: boolean = false) {
if (!this.skipMessage(type) && message) {
this._output.show(true);
const currentTime = this.getCurrentTime();
this._output.appendLine('[' + type + ' - ' + currentTime + '] ' + message);
if (reportInWindows) {
this.showInWindows('' + message, type);
}
}
}
}

View File

@ -44,15 +44,15 @@ const PrjInfoDefaults: PrjInfoMeta = {
device: 'none',
arch: {
prjPath: './prj',
prjPath: '',
hardware: {
src: './user/src',
sim: './user/sim',
data: './user/data'
src: '',
sim: '',
data: ''
},
software: {
src: './user/software/src',
data: './user/software/data'
src: '',
data: ''
}
},
@ -355,7 +355,7 @@ class PrjInfo implements PrjInfoMeta {
const workspacePath = this._workspacePath;
if (arch) {
this.updatePathWisely(this.arch, 'prjPath', arch.prjPath);
this.updatePathWisely(this.arch, 'prjPath', arch.prjPath);
if (arch.hardware) {
this.updatePathWisely(this.arch.hardware, 'src', arch.hardware.src);
this.updatePathWisely(this.arch.hardware, 'sim', arch.hardware.sim);

View File

@ -155,7 +155,6 @@ class LibPick {
if (selectedPath && hdlPath.exist(selectedPath)) {
const userPrjInfo = opeParam.getUserPrjInfo();
console.log(userPrjInfo);
if (selectedPath.includes(this.commonQuickPickItem.path!)) {
// this is a module import from common, use relative path

View File

@ -0,0 +1,17 @@
{
"toolChain": "xilinx",
"prjName": {
"PL": "template"
},
"soc": {
"core": "none"
},
"arch": {
"hardware": {
"sim": "./",
"src": "./"
}
},
"enableShowLog": false,
"device": "none"
}

View File

@ -0,0 +1,6 @@
module hello;
initial begin
$display("hello world");
$finish;
end
endmodule

View File

@ -0,0 +1,26 @@
#! /c/Source/iverilog-install/bin/vvp
:ivl_version "12.0 (devel)" "(s20150603-1110-g18392a46)";
:ivl_delay_selection "TYPICAL";
:vpi_time_precision + 0;
:vpi_module "C:\iverilog\lib\ivl\system.vpi";
:vpi_module "C:\iverilog\lib\ivl\vhdl_sys.vpi";
:vpi_module "C:\iverilog\lib\ivl\vhdl_textio.vpi";
:vpi_module "C:\iverilog\lib\ivl\v2005_math.vpi";
:vpi_module "C:\iverilog\lib\ivl\va_math.vpi";
:vpi_module "C:\iverilog\lib\ivl\v2009.vpi";
S_0000023701252df0 .scope package, "$unit" "$unit" 2 1;
.timescale 0 0;
S_0000023701252f80 .scope module, "hello" "hello" 3 1;
.timescale 0 0;
.scope S_0000023701252f80;
T_0 ;
%vpi_call/w 3 3 "$display", "hello world" {0 0 0};
%vpi_call/w 3 4 "$finish" {0 0 0};
%end;
.thread T_0;
# The file index is used to find the file name in the following table.
:file_names 4;
"N/A";
"<interactive>";
"-";
"e:/Project/Digial-IDE/digital-ide/src/test/vlog/dependence_test/hello.v";