完成 netlist 的构建
This commit is contained in:
parent
67aaa39dfe
commit
e26d717dfe
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ resources/dide-viewer/view/*
|
||||
resources/dide-lsp/server/*
|
||||
resources/dide-lsp/static/*
|
||||
resources/dide-netlist/static/*
|
||||
resources/dide-netlist/view/*
|
Binary file not shown.
0
script/.gitignore → scripts/.gitignore
vendored
0
script/.gitignore → scripts/.gitignore
vendored
@ -66,15 +66,10 @@ def modify_vsix():
|
||||
# move public
|
||||
copy_dir('./resources/public', os.path.join(extract_folder, 'extension', 'resources', 'public'))
|
||||
|
||||
# move wasm
|
||||
copy_dir('./resources/netlist/resources/kernel', os.path.join(extract_folder, 'extension', 'resources', 'kernel'))
|
||||
|
||||
|
||||
# webview
|
||||
copy_dir('./resources/netlist/view', os.path.join(extract_folder, 'extension', 'resources', 'netlist', 'view'))
|
||||
copy_dir('./resources/dide-netlist/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-netlist', 'view'))
|
||||
copy_dir('./resources/dide-viewer/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-viewer', 'view'))
|
||||
|
||||
|
||||
# remake
|
||||
target_path = os.path.join('dist', vsix_path)
|
||||
zip_dir(extract_folder, target_path)
|
107
scripts/vscode-package.py
Normal file
107
scripts/vscode-package.py
Normal file
@ -0,0 +1,107 @@
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
from colorama import Fore, Style
|
||||
from typing import List, Union
|
||||
from collections import namedtuple
|
||||
|
||||
Command = namedtuple(typename='Command', field_names=['name', 'cmd'])
|
||||
|
||||
class CommandPipe:
|
||||
def __init__(self) -> None:
|
||||
self.pipes: List[Command] = []
|
||||
|
||||
def add_command(self, name: str, cmd: str):
|
||||
command = Command(name, cmd)
|
||||
self.pipes.append(command)
|
||||
|
||||
def run(self):
|
||||
for i, p in enumerate(self.pipes):
|
||||
progress = int((i + 1) / len(self.pipes) * 100)
|
||||
space_prefix = ' ' if progress < 100 else ''
|
||||
print(Fore.GREEN, f'[{space_prefix}{progress}%]', Style.RESET_ALL, p.name)
|
||||
if callable(p.cmd):
|
||||
p.cmd()
|
||||
elif isinstance(p.cmd, str):
|
||||
os.system(p.cmd)
|
||||
print('Done! :D')
|
||||
|
||||
|
||||
def remove_folder(name: str):
|
||||
if os.path.exists(name):
|
||||
shutil.rmtree(name)
|
||||
|
||||
def copy_dir(src, dist):
|
||||
if os.path.exists(dist):
|
||||
shutil.rmtree(dist)
|
||||
shutil.copytree(src, dist)
|
||||
|
||||
def copy_file(src, dist):
|
||||
if os.path.exists(dist):
|
||||
os.remove(dist)
|
||||
dirname = os.path.dirname(dist)
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
shutil.copyfile(src, dist)
|
||||
|
||||
def modify_vsix():
|
||||
vsix_filter = filter(lambda file: file.endswith('.vsix'), os.listdir('.'))
|
||||
vsix_file = list(vsix_filter)
|
||||
if len(vsix_file) == 0:
|
||||
print(Fore.RED, 'no .vsix is detected', Style.RESET_ALL)
|
||||
exit()
|
||||
vsix_path = vsix_file[0]
|
||||
if not os.path.exists('dist'):
|
||||
os.mkdir('dist')
|
||||
|
||||
dist_path = os.path.join('dist', vsix_path.replace('.vsix', '.zip'))
|
||||
shutil.move(vsix_path, dist_path)
|
||||
|
||||
extract_folder = os.path.join('dist', 'digital-ide-temp')
|
||||
with zipfile.ZipFile(dist_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(extract_folder)
|
||||
|
||||
os.remove(dist_path)
|
||||
|
||||
# move public
|
||||
copy_dir('./resources/public', os.path.join(extract_folder, 'extension', 'resources', 'public'))
|
||||
|
||||
# webview
|
||||
copy_dir('./resources/dide-netlist/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-netlist', 'view'))
|
||||
copy_dir('./resources/dide-viewer/view', os.path.join(extract_folder, 'extension', 'resources', 'dide-viewer', 'view'))
|
||||
|
||||
# remake
|
||||
target_path = os.path.join('dist', vsix_path)
|
||||
zip_dir(extract_folder, target_path)
|
||||
|
||||
|
||||
|
||||
def zip_dir(dirpath, outFullName):
|
||||
zip = zipfile.ZipFile(outFullName, "w", zipfile.ZIP_DEFLATED)
|
||||
for path, _, filenames in os.walk(dirpath):
|
||||
fpath = path.replace(dirpath, '')
|
||||
for filename in filenames:
|
||||
zip.write(os.path.join(path, filename), os.path.join(fpath, filename))
|
||||
zip.close()
|
||||
|
||||
def install_extension():
|
||||
vsix_filter = filter(lambda file: file.endswith('.vsix'), os.listdir('dist'))
|
||||
vsix_files = list(vsix_filter)
|
||||
if len(vsix_files) == 0:
|
||||
print(Fore.RED, 'no .vsix is detected in dist', Style.RESET_ALL)
|
||||
exit()
|
||||
|
||||
vsix_path = os.path.join('dist', vsix_files[0])
|
||||
os.system('code --install-extension ' + vsix_path)
|
||||
|
||||
pipe = CommandPipe()
|
||||
pipe.add_command('uninstall original extension', 'code --uninstall-extension sterben.fpga-support')
|
||||
pipe.add_command('compile typescript', 'tsc -p ./ --outDir out-js')
|
||||
pipe.add_command('webpack', 'webpack --mode production')
|
||||
pipe.add_command('make vsix installer', 'vsce package')
|
||||
pipe.add_command('modify vsix installer', lambda : modify_vsix())
|
||||
pipe.add_command('remove out-js', lambda : remove_folder('out-js'))
|
||||
pipe.add_command('remove out', lambda : remove_folder('out'))
|
||||
pipe.add_command('install', lambda : install_extension())
|
||||
|
||||
pipe.run()
|
@ -10,6 +10,8 @@ import { defaultMacro, doFastApi } from '../../hdlParser/util';
|
||||
import { HdlFile } from '../../hdlParser/core';
|
||||
import { t } from '../../i18n';
|
||||
import { HdlLangID } from '../../global/enum';
|
||||
import { getIconConfig } from '../../hdlFs/icons';
|
||||
import { PathSet } from '../../global/util';
|
||||
|
||||
type SynthMode = 'before' | 'after' | 'RTL';
|
||||
|
||||
@ -28,7 +30,7 @@ class Netlist {
|
||||
}
|
||||
|
||||
public async open(uri: vscode.Uri, moduleName: string) {
|
||||
const prjFiles = [];
|
||||
const pathset = new PathSet();
|
||||
const path = hdlPath.toSlash(uri.fsPath);
|
||||
|
||||
let moduleFile = hdlParam.getHdlFile(path);
|
||||
@ -58,12 +60,13 @@ class Netlist {
|
||||
const hdlDependence = hdlParam.getAllDependences(path, hdlModule.name);
|
||||
if (hdlDependence) {
|
||||
// include 宏在后续会被正确处理,所以只需要处理 others 即可
|
||||
prjFiles.push(...hdlDependence.others);
|
||||
hdlDependence.others.forEach(path => pathset.add(path));
|
||||
}
|
||||
}
|
||||
prjFiles.push(path);
|
||||
pathset.add(path);
|
||||
|
||||
const prjFiles = [...pathset.files];
|
||||
|
||||
console.log('enter', moduleName);
|
||||
console.log(prjFiles);
|
||||
console.log(opeParam.prjInfo.prjPath);
|
||||
|
||||
@ -95,6 +98,8 @@ class Netlist {
|
||||
});
|
||||
const exitCode = wasi.start(instance);
|
||||
});
|
||||
|
||||
this.create(moduleName);
|
||||
}
|
||||
|
||||
private getSynthMode(): SynthMode {
|
||||
@ -145,11 +150,11 @@ class Netlist {
|
||||
|
||||
private makeWasi(target: string) {
|
||||
// 创建日志文件路径
|
||||
const logFilePath = hdlPath.join(opeParam.workspacePath, 'wasi_log.txt');
|
||||
hdlFile.removeFile(logFilePath);
|
||||
|
||||
// const logFilePath = hdlPath.join(opeParam.workspacePath, 'wasi_log.txt');
|
||||
// hdlFile.removeFile(logFilePath);
|
||||
// 创建可写流,将标准输出和标准错误重定向到日志文件
|
||||
const logFd = fs.openSync(logFilePath, 'a');
|
||||
// const logFd = fs.openSync(logFilePath, 'a');
|
||||
|
||||
return new WASI({
|
||||
version: 'preview1',
|
||||
args: [
|
||||
@ -163,8 +168,10 @@ class Netlist {
|
||||
['/' + this.libName]: opeParam.prjInfo.libCommonPath
|
||||
},
|
||||
stdin: process.stdin.fd,
|
||||
stdout: logFd,
|
||||
stderr: logFd,
|
||||
stdout: process.stdout.fd,
|
||||
stderr: process.stderr.fd,
|
||||
// stdout: logFd,
|
||||
// stderr: logFd,
|
||||
env: process.env
|
||||
});
|
||||
}
|
||||
@ -180,7 +187,7 @@ class Netlist {
|
||||
return wasm;
|
||||
}
|
||||
|
||||
private create() {
|
||||
private create(moduleName: string) {
|
||||
// Create panel
|
||||
this.panel = vscode.window.createWebviewPanel(
|
||||
'Netlist',
|
||||
@ -205,7 +212,21 @@ class Netlist {
|
||||
|
||||
const previewHtml = this.getWebviewContent();
|
||||
if (this.panel && previewHtml) {
|
||||
this.panel.webview.html = previewHtml;
|
||||
const netlistPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-netlist', 'view');
|
||||
const netlistPayloadFolder = hdlPath.join(opeParam.prjInfo.prjPath, 'netlist');
|
||||
const targetJson = hdlPath.join(netlistPayloadFolder, moduleName + '.json');
|
||||
const skinPath= hdlPath.join(netlistPath, 'dide.skin');
|
||||
|
||||
const graph = this.panel.webview.asWebviewUri(vscode.Uri.file(targetJson)).toString();
|
||||
const skin = this.panel.webview.asWebviewUri(vscode.Uri.file(skinPath)).toString();
|
||||
this.panel.iconPath = getIconConfig('view');
|
||||
|
||||
let preprocessHtml = previewHtml
|
||||
.replace('test.json', graph)
|
||||
.replace('test.module', moduleName)
|
||||
.replace('dide.skin', skin);
|
||||
|
||||
this.panel.webview.html = preprocessHtml;
|
||||
} else {
|
||||
YosysOutput.report('preview html in <Netlist.create> is empty', {
|
||||
level: ReportType.Warn
|
||||
@ -218,7 +239,7 @@ class Netlist {
|
||||
}
|
||||
|
||||
public getWebviewContent() {
|
||||
const netlistPath = hdlPath.join(opeParam.extensionPath, 'resources', 'netlist', 'view');
|
||||
const netlistPath = hdlPath.join(opeParam.extensionPath, 'resources', 'dide-netlist', 'view');
|
||||
const htmlIndexPath = hdlPath.join(netlistPath, 'index.html');
|
||||
|
||||
const html = hdlFile.readFile(htmlIndexPath)?.replace(/(<link.+?href="|<script.+?src="|<img.+?src=")(.+?)"/g, (m, $1, $2) => {
|
@ -222,7 +222,7 @@ function getViewLaunchFiles(context: vscode.ExtensionContext, uri: vscode.Uri, p
|
||||
return { vcd, view, wasm, vcdjs, worker, root };
|
||||
} else if (entryPath.endsWith('.view')) {
|
||||
const buffer = fs.readFileSync(entryPath);
|
||||
const recoverJson = BSON.deserialize(buffer);
|
||||
const recoverJson = BSON.deserialize(new Uint8Array(buffer));
|
||||
if (recoverJson.originVcdFile) {
|
||||
const vcdPath = recoverJson.originVcdFile;
|
||||
if (!fs.existsSync(vcdPath)) {
|
||||
|
@ -13,7 +13,7 @@ import * as tool from './tool';
|
||||
|
||||
// special function
|
||||
import * as FSM from './fsm';
|
||||
import * as Netlist from './netlist';
|
||||
import * as Netlist from './dide-netlist';
|
||||
import * as WaveView from './dide-viewer';
|
||||
import { ModuleDataItem } from './treeView/tree';
|
||||
import { downloadLsp } from './lsp-client';
|
||||
|
Loading…
x
Reference in New Issue
Block a user