From 8a4fc5bb702246b2760fccdc450843a514e089e3 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Thu, 20 Apr 2023 22:40:56 +0800 Subject: [PATCH] finish libPick set top function | iverilog simulation --- src/function/sim/simulate.ts | 23 +++++++++------- src/function/sim/testbench.ts | 1 - src/function/treeView/tree.ts | 21 ++++++--------- src/global/outputChannel.ts | 22 +++++++++++++++- src/global/prjInfo.ts | 14 +++++----- src/manager/libPick.ts | 1 - .../dependence_test/.vscode/property.json | 17 ++++++++++++ src/test/vlog/dependence_test/hello.v | 6 +++++ .../dependence_test/simulation/icarus/out.vvp | 26 +++++++++++++++++++ 9 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 src/test/vlog/dependence_test/.vscode/property.json create mode 100644 src/test/vlog/dependence_test/hello.v create mode 100644 src/test/vlog/dependence_test/simulation/icarus/out.vvp diff --git a/src/function/sim/simulate.ts b/src/function/sim/simulate.ts index 84bf9d9..b208d0d 100644 --- a/src/function/sim/simulate.ts +++ b/src/function/sim/simulate.ts @@ -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()); diff --git a/src/function/sim/testbench.ts b/src/function/sim/testbench.ts index 01d25b9..87e989c 100644 --- a/src/function/sim/testbench.ts +++ b/src/function/sim/testbench.ts @@ -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; diff --git a/src/function/treeView/tree.ts b/src/function/treeView/tree.ts index 6874433..7807115 100644 --- a/src/function/treeView/tree.ts +++ b/src/function/treeView/tree.ts @@ -52,27 +52,26 @@ function canExpandable(element: ModuleDataItem) { class ModuleTreeProvider implements vscode.TreeDataProvider { - treeEventEmitter: vscode.EventEmitter; - treeEvent: vscode.Event; + _onDidChangeTreeData: vscode.EventEmitter; + onDidChangeTreeData: vscode.Event; firstTop: FirstTop; srcRootItem: ModuleDataItem; simRootItem: ModuleDataItem; constructor() { - this.treeEventEmitter = new vscode.EventEmitter(); - this.treeEvent = this.treeEventEmitter.event; + this._onDidChangeTreeData = new vscode.EventEmitter(); + 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 { } 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 { return treeItem; } - public getChildren(element?: ModuleDataItem | undefined): vscode.ProviderResult { + public getChildren(element?: ModuleDataItem | undefined): vscode.ProviderResult { if (element) { - console.log(element); - const name = element.name; if (name === 'sim' || name === 'src') { element.parent = null; diff --git a/src/global/outputChannel.ts b/src/global/outputChannel.ts index d28cefa..64141aa 100644 --- a/src/global/outputChannel.ts +++ b/src/global/outputChannel.ts @@ -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. 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); + } } } } diff --git a/src/global/prjInfo.ts b/src/global/prjInfo.ts index 2d05300..0535ecd 100644 --- a/src/global/prjInfo.ts +++ b/src/global/prjInfo.ts @@ -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); diff --git a/src/manager/libPick.ts b/src/manager/libPick.ts index 046055e..a5c13fa 100644 --- a/src/manager/libPick.ts +++ b/src/manager/libPick.ts @@ -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 diff --git a/src/test/vlog/dependence_test/.vscode/property.json b/src/test/vlog/dependence_test/.vscode/property.json new file mode 100644 index 0000000..276c76f --- /dev/null +++ b/src/test/vlog/dependence_test/.vscode/property.json @@ -0,0 +1,17 @@ +{ + "toolChain": "xilinx", + "prjName": { + "PL": "template" + }, + "soc": { + "core": "none" + }, + "arch": { + "hardware": { + "sim": "./", + "src": "./" + } + }, + "enableShowLog": false, + "device": "none" +} \ No newline at end of file diff --git a/src/test/vlog/dependence_test/hello.v b/src/test/vlog/dependence_test/hello.v new file mode 100644 index 0000000..92f23ac --- /dev/null +++ b/src/test/vlog/dependence_test/hello.v @@ -0,0 +1,6 @@ +module hello; + initial begin + $display("hello world"); + $finish; + end +endmodule \ No newline at end of file diff --git a/src/test/vlog/dependence_test/simulation/icarus/out.vvp b/src/test/vlog/dependence_test/simulation/icarus/out.vvp new file mode 100644 index 0000000..fc9706e --- /dev/null +++ b/src/test/vlog/dependence_test/simulation/icarus/out.vvp @@ -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"; + ""; + "-"; + "e:/Project/Digial-IDE/digital-ide/src/test/vlog/dependence_test/hello.v";