diff --git a/draft.json b/draft.json new file mode 100644 index 0000000..283b3d5 --- /dev/null +++ b/draft.json @@ -0,0 +1,169 @@ +{ + "content": { + "error": [], + "symbols": [ + { + "name": "Main", + "range": { + "end": { + "character": 0, + "line": 31 + }, + "start": { + "character": 0, + "line": 10 + } + }, + "type": "module" + }, + { + "name": "a", + "range": { + "end": { + "character": 17, + "line": 11 + }, + "start": { + "character": 16, + "line": 11 + } + }, + "type": "input" + }, + { + "name": "b", + "range": { + "end": { + "character": 17, + "line": 12 + }, + "start": { + "character": 16, + "line": 12 + } + }, + "type": "input" + }, + { + "name": "c", + "range": { + "end": { + "character": 11, + "line": 13 + }, + "start": { + "character": 10, + "line": 13 + } + }, + "type": "input" + }, + { + "name": "Qus", + "range": { + "end": { + "character": 14, + "line": 14 + }, + "start": { + "character": 11, + "line": 14 + } + }, + "type": "output" + }, + { + "name": "Qs", + "range": { + "end": { + "character": 18, + "line": 14 + }, + "start": { + "character": 16, + "line": 14 + } + }, + "type": "output" + }, + { + "name": "`main_o", + "range": { + "end": { + "character": 27, + "line": 14 + }, + "start": { + "character": 20, + "line": 14 + } + }, + "type": "output" + }, + { + "name": "dependence_1", + "range": { + "end": { + "character": 1, + "line": 22 + }, + "start": { + "character": 0, + "line": 17 + } + }, + "type": "dependence_1" + }, + { + "name": "dependence_2", + "range": { + "end": { + "character": 1, + "line": 29 + }, + "start": { + "character": 0, + "line": 24 + } + }, + "type": "dependence_2" + } + ] + }, + "languageId": "verilog", + "macro": { + "defines": [ + { + "name": "main_o", + "range": { + "end": { + "character": 19, + "line": 9 + }, + "start": { + "character": 1, + "line": 9 + } + }, + "value": "out" + } + ], + "error": [], + "includes": [ + { + "path": "child_1.v", + "range": { + "end": { + "character": 9, + "line": 8 + }, + "start": { + "character": 1, + "line": 8 + } + } + } + ], + "invalid": [] + } + } \ No newline at end of file diff --git a/draft2.json b/draft2.json new file mode 100644 index 0000000..b719be3 --- /dev/null +++ b/draft2.json @@ -0,0 +1,201 @@ +{ + "content": { + "error": [], + "modules": [ + { + "instances": [ + { + "instparams": null, + "instports": { + "end": { + "character": 10, + "line": 21 + }, + "start": { + "character": 4, + "line": 18 + } + }, + "name": "dependence_1", + "range": { + "end": { + "character": 0, + "line": 22 + }, + "start": { + "character": 13, + "line": 17 + } + }, + "type": "dependence_1" + }, + { + "instparams": null, + "instports": { + "end": { + "character": 9, + "line": 28 + }, + "start": { + "character": 4, + "line": 25 + } + }, + "name": "dependence_2", + "range": { + "end": { + "character": 0, + "line": 29 + }, + "start": { + "character": 13, + "line": 24 + } + }, + "type": "dependence_2" + } + ], + "name": "Main", + "params": [], + "ports": [ + { + "name": "a", + "range": { + "end": { + "character": 17, + "line": 11 + }, + "start": { + "character": 16, + "line": 11 + } + }, + "type": "input", + "width": "[3:0]" + }, + { + "name": "b", + "range": { + "end": { + "character": 17, + "line": 12 + }, + "start": { + "character": 16, + "line": 12 + } + }, + "type": "input", + "width": "[2:0]" + }, + { + "name": "c", + "range": { + "end": { + "character": 11, + "line": 13 + }, + "start": { + "character": 10, + "line": 13 + } + }, + "type": "input", + "width": "Unknown" + }, + { + "name": "Qus", + "range": { + "end": { + "character": 14, + "line": 14 + }, + "start": { + "character": 11, + "line": 14 + } + }, + "type": "output", + "width": "Unknown" + }, + { + "name": "Qs", + "range": { + "end": { + "character": 18, + "line": 14 + }, + "start": { + "character": 16, + "line": 14 + } + }, + "type": "output", + "width": "Unknown" + }, + { + "name": "`main_o", + "range": { + "end": { + "character": 27, + "line": 14 + }, + "start": { + "character": 20, + "line": 14 + } + }, + "type": "output", + "width": "Unknown" + } + ], + "range": { + "end": { + "character": 0, + "line": 31 + }, + "start": { + "character": 0, + "line": 10 + } + } + } + ] + }, + "languageId": "verilog", + "macro": { + "defines": [ + { + "name": "main_o", + "range": { + "end": { + "character": 19, + "line": 9 + }, + "start": { + "character": 1, + "line": 9 + } + }, + "value": "out" + } + ], + "error": [], + "includes": [ + { + "path": "child_1.v", + "range": { + "end": { + "character": 9, + "line": 8 + }, + "start": { + "character": 1, + "line": 8 + } + } + } + ], + "invalid": [] + } + } \ No newline at end of file diff --git a/src/global/prjInfo.ts b/src/global/prjInfo.ts index 63e23d4..cf3a0c5 100644 --- a/src/global/prjInfo.ts +++ b/src/global/prjInfo.ts @@ -100,6 +100,7 @@ interface RawPrjInfo extends RawPrjInfoMeta { library?: Library }; + function toSlash(path: Path): Path { return path.replace(/\\/g,"\/"); } diff --git a/src/hdlFs/file.ts b/src/hdlFs/file.ts index a8a9210..4477822 100644 --- a/src/hdlFs/file.ts +++ b/src/hdlFs/file.ts @@ -5,7 +5,7 @@ import { AbsPath, RelPath } from '../global'; import { HdlLangID } from '../global/enum'; import { verilogExts, vhdlExts, systemVerilogExts, hdlExts } from '../global/lang'; import * as hdlPath from './path'; -import { HdlFileType } from '../hdlParser/base/common'; +import { HdlFileType } from '../hdlParser/common'; import { opeParam } from '../global'; /** @@ -62,7 +62,7 @@ function isSystemVerilogFile(path: AbsPath): boolean { return false; } const ext = hdlPath.extname(path, false); - return systemVerilogExts.includes(path); + return systemVerilogExts.includes(ext); } function isHDLFile(path: AbsPath): boolean { @@ -101,18 +101,12 @@ function pickFileRecursive(path: AbsPath | AbsPath[] | Set, ignores?: A if (subHdlFiles.length > 0) { hdlFiles.push(...subHdlFiles); } - } else if ( - (condition && condition(filePath)) - || (condition === undefined) - ) { + } else if (!condition || condition(filePath)) { hdlFiles.push(filePath); } } return hdlFiles; - } else if ( - (condition && condition(path)) - || (condition === undefined) - ) { + } else if (!condition || condition(path)) { return [path]; } else { return []; @@ -344,6 +338,27 @@ function isHasValue(obj: any, attr: string, value: any): boolean{ return true; } +function* walk(path: AbsPath | RelPath, condition?: (filePath: AbsPath) => boolean): Generator { + if (isFile(path)) { + if (!condition || condition(path)) { + yield path; + } + } else { + for (const file of fs.readdirSync(path)) { + const filePath = hdlPath.join(path, file); + if (isDir(filePath)) { + for (const targetPath of walk(filePath, condition)) { + yield targetPath; + } + } else if (isFile(filePath)) { + if (!condition || condition(filePath)) { + yield filePath; + } + } + } + } +} + export { isFile, isDir, @@ -364,5 +379,6 @@ export { isHasValue, copyFile, removeFile, - moveFile + moveFile, + walk }; \ No newline at end of file diff --git a/src/hdlParser/base/common.ts b/src/hdlParser/common.ts similarity index 90% rename from src/hdlParser/base/common.ts rename to src/hdlParser/common.ts index ff94339..ebdd34b 100644 --- a/src/hdlParser/base/common.ts +++ b/src/hdlParser/common.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { AbsPath, RelPath } from '../../global'; +import { AbsPath, RelPath } from '../global'; interface Position { // row/line of the cursor, index from 0 @@ -32,6 +32,11 @@ enum HdlFileType { RemoteLib = 'remote_lib' }; enum InstModPathStatus {Current, Include, Others, Unknown}; +enum SymbolType { + Module = 'module', + Input = 'input', + Output = 'output' +}; interface Error { severity: number @@ -95,6 +100,13 @@ interface RawHdlModule { range: Range }; + +interface RawSymbol { + name: string + type: SymbolType + range: Range +}; + interface InstModPathSearchResult { path: AbsPath status: InstModPathStatus @@ -123,5 +135,6 @@ export { RawHdlInstance, RawHdlModule, InstModPathSearchResult, - HdlDependence + HdlDependence, + RawSymbol }; \ No newline at end of file diff --git a/src/hdlParser/base/core.ts b/src/hdlParser/core.ts similarity index 99% rename from src/hdlParser/base/core.ts rename to src/hdlParser/core.ts index f0b3fe9..6c93ad3 100644 --- a/src/hdlParser/base/core.ts +++ b/src/hdlParser/core.ts @@ -1,8 +1,8 @@ -import { AbsPath } from '../../global'; -import { HdlLangID } from '../../global/enum'; +import { AbsPath } from '../global'; +import { HdlLangID } from '../global/enum'; import * as common from './common'; -import { hdlFile, hdlPath } from '../../hdlFs'; +import { hdlFile, hdlPath } from '../hdlFs'; class HdlParam { private readonly topModules : Set = new Set(); diff --git a/src/hdlParser/parser/index.d.ts b/src/hdlParser/parser/index.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/hdlParser/parser/index.js b/src/hdlParser/parser/index.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/hdlParser/util.ts b/src/hdlParser/util.ts new file mode 100644 index 0000000..69b297f --- /dev/null +++ b/src/hdlParser/util.ts @@ -0,0 +1,5 @@ +import { vlogAll, vlogFast } from '../../wasm/hdlParser'; + +function hello(path: string) { + vlogAll(path); +} \ No newline at end of file diff --git a/src/manager/PL/xilinx.ts b/src/manager/PL/xilinx.ts index edafb74..952f206 100644 --- a/src/manager/PL/xilinx.ts +++ b/src/manager/PL/xilinx.ts @@ -5,7 +5,7 @@ import * as fspath from 'path'; import * as fs from 'fs'; import { AbsPath, opeParam, PrjInfo } from '../../global'; -import { hdlParam } from '../../hdlParser/base/core'; +import { hdlParam } from '../../hdlParser/core'; import { hdlFile, hdlDir, hdlPath } from '../../hdlFs'; import { PropertySchema } from '../../global/propertySchema'; diff --git a/test.js b/test.js index 7538665..6d8dc92 100644 --- a/test.js +++ b/test.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); -const sysvlog_build = require('./src/hdlParser/parser/parser'); +const sysvlog_build = require('./wasm/hdlParser/parser'); const COMMON_PATH = path.resolve('./lib/common/Driver'); diff --git a/vsixmake.js b/vsixmake.js index 9de2a05..3c4bc39 100644 --- a/vsixmake.js +++ b/vsixmake.js @@ -1,17 +1,17 @@ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); -const HDLFile = require('./src/HDLfilesys/operation/files'); -const hdlPath = require('./src/HDLfilesys/operation/path'); +const hdlFile = require('./src/hdlFs/file'); +const hdlPath = require('./src/hdlFs/path'); const PACKAGE_PATH = './package.json'; const SAVE_FOLDER = 'dist'; const WEBPACK_OUT_FOLDER = 'out'; function changeMain(path) { - const packageJS = HDLFile.pullJsonInfo(PACKAGE_PATH); + const packageJS = hdlFile.pullJsonInfo(PACKAGE_PATH); packageJS.main = path; - HDLFile.pushJsonInfo(PACKAGE_PATH, packageJS); + hdlFile.pushJsonInfo(PACKAGE_PATH, packageJS); } function findVsix() { @@ -36,7 +36,7 @@ execSync('code --uninstall-extension sterben.digital-ide'); const vsix = findVsix(); const targetPath = path.join(SAVE_FOLDER, vsix); -HDLFile.moveFile(vsix, targetPath, true); +hdlFile.moveFile(vsix, targetPath, true); hdlPath.deleteFolder(WEBPACK_OUT_FOLDER); const vsixPath = hdlPath.join(SAVE_FOLDER, vsix); diff --git a/src/hdlParser/parser/.gitignore b/wasm/hdlParser/.gitignore similarity index 100% rename from src/hdlParser/parser/.gitignore rename to wasm/hdlParser/.gitignore diff --git a/wasm/hdlParser/index.d.ts b/wasm/hdlParser/index.d.ts new file mode 100644 index 0000000..fbc8140 --- /dev/null +++ b/wasm/hdlParser/index.d.ts @@ -0,0 +1,27 @@ +import { RawHdlModule, Macro, RawSymbol } from '../../src/hdlParser/common'; +import { HdlLangID } from '../../src/global/enum'; + +type AbsPath = string; +type RelPath = string; +type Path = AbsPath | RelPath; + +interface Fast { + content: { + error : string[] + modules: RawHdlModule[] + } + languageId: HdlLangID + macro: Macro +} + +interface All { + content: { + error: string[] + symbols: RawSymbol[] + } + languageId: HdlLangID + macro: Macro +} + +export function vlogFast(path: AbsPath): Promise; +export function vlogAll(path: AbsPath): Promise; \ No newline at end of file diff --git a/wasm/hdlParser/index.js b/wasm/hdlParser/index.js new file mode 100644 index 0000000..8f2254c --- /dev/null +++ b/wasm/hdlParser/index.js @@ -0,0 +1,38 @@ +const hdlParser = require('./parser'); + +const _hdlParser = { + module: null, + tempPath: '/home/hdl_parser', + + async acquire() { + const module = this.module; + if (module) { + return module; + } else { + const _m = await hdlParser(); + this.module = _m; + return _m; + } + } +}; + +async function vlogFast(path) { + const wasmModule = await _hdlParser.acquire(); + const source = fs.readFileSync(path, 'utf-8'); + wasmModule.FS.writeFile(_hdlParser.tempPath, source, { encoding: 'utf8' }); + const res = wasmModule.ccall('vlog_fast', 'string', ['string'], [_hdlParser.tempPath]); + return JSON.parse(res); +} + +async function vlogAll(path) { + const wasmModule = await _hdlParser.acquire(); + const source = fs.readFileSync(path, 'utf-8'); + wasmModule.FS.writeFile(_hdlParser.tempPath, source, { encoding: 'utf8' }); + const res = wasmModule.ccall('vlog_all', 'string', ['string'], [_hdlParser.tempPath]); + return JSON.parse(res); +} + +module.exports = { + vlogFast, + vlogAll +}; \ No newline at end of file