Skip to content

Commit 8d506f3

Browse files
Merge branch 'main' into dependabot/npm_and_yarn/npm_and_yarn-b6386884ef
2 parents 249fecf + e77c076 commit 8d506f3

File tree

5 files changed

+89
-14
lines changed

5 files changed

+89
-14
lines changed

.github/workflows/static.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Simple workflow for deploying static content to GitHub Pages
2+
name: Deploy static content to Pages
3+
4+
on:
5+
# Runs on pushes targeting the default branch
6+
push:
7+
branches: ["main"]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
# Single deploy job since we're just deploying
26+
deploy:
27+
environment:
28+
name: github-pages
29+
url: ${{ steps.deployment.outputs.page_url }}
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
- name: Setup Pages
35+
uses: actions/configure-pages@v5
36+
- name: Upload artifact
37+
uses: actions/upload-pages-artifact@v3
38+
with:
39+
# Upload entire repository
40+
path: '.'
41+
- name: Deploy to GitHub Pages
42+
id: deployment
43+
uses: actions/deploy-pages@v4

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yosys2digitaljs",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "Export Yosys netlists to a logic simulator",
55
"main": "dist/index",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ namespace Digitaljs {
175175

176176
namespace Yosys {
177177

178-
export type BitChar = '0' | '1' | 'x';
178+
export const ConstChars = ["0", "1", "x", "z"] as const;
179179

180-
export type Bit = number | '0' | '1' | 'x';
180+
export type BitChar = (typeof ConstChars)[number];
181+
182+
export type Bit = number | BitChar;
181183

182184
export type BitVector = Bit[];
183185

@@ -404,7 +406,7 @@ function yosys_to_digitaljs(data: Yosys.Output, portmaps: Portmaps, options: Con
404406

405407
function yosys_to_digitaljs_mod(name: string, mod: Yosys.Module, portmaps: Portmaps, options: ConvertOptions = {}): Digitaljs.Module {
406408
function constbit(bit: Bit) {
407-
return bit == '0' || bit == '1' || bit == 'x';
409+
return (Yosys.ConstChars as readonly string[]).includes(bit.toString());
408410
}
409411
const nets = new HashMap<Net, NetInfo>();
410412
const netnames = new HashMap<Net, string[]>();
@@ -434,8 +436,6 @@ function yosys_to_digitaljs_mod(name: string, mod: Yosys.Module, portmaps: Portm
434436
const net = get_net(k);
435437
if(net.source !== undefined) {
436438
// multiple sources driving one net, disallowed in digitaljs
437-
console.log(k);
438-
console.log(net);
439439
throw Error('Multiple sources driving net: ' + net.name);
440440
}
441441
net.source = { id: d, port: p };
@@ -1170,17 +1170,41 @@ function yosys_to_digitaljs_mod(name: string, mod: Yosys.Module, portmaps: Portm
11701170
return mout;
11711171
}
11721172

1173-
function escape_filename(cmd: string): string {
1174-
return '"' + cmd.replace(/(["\s'$`\\])/g,'\\$1') + '"';
1173+
function ansi_c_escape_contents(cmd: string): string {
1174+
function func(ch: string) {
1175+
if (ch == '\t') return '\\t';
1176+
if (ch == '\r') return '\\r';
1177+
if (ch == '\n') return '\\n';
1178+
return '\\x' + ch.charCodeAt(0).toString(16).padStart(2, '0');
1179+
}
1180+
return cmd.replace(/(["'\\])/g,'\\$1')
1181+
.replace(/[\x00-\x1F\x7F-\x9F]/g, func);
1182+
}
1183+
1184+
function ansi_c_escape(cmd: string): string {
1185+
return '"' + ansi_c_escape_contents(cmd) + '"';
1186+
}
1187+
1188+
function shell_escape_contents(cmd: string): string {
1189+
return cmd.replace(/(["\r\n$`\\])/g,'\\$1');
11751190
}
1176-
1191+
1192+
function shell_escape(cmd: string): string {
1193+
return '"' + shell_escape_contents(cmd) + '"';
1194+
}
1195+
1196+
function process_filename(filename: string): string {
1197+
const flags = /\.sv$/.test(filename) ? " -sv" : "";
1198+
return "read_verilog" + flags + " " + ansi_c_escape(filename);
1199+
}
1200+
11771201
const verilator_re = /^%(Warning|Error)[^:]*: ([^:]*):([0-9]+):([0-9]+): (.*)$/;
11781202

11791203
export async function verilator_lint(filenames: string[], dirname?: string, options: Options = {}): Promise<LintMessage[]> {
11801204
try {
11811205
const output: LintMessage[] = [];
11821206
const verilator_result: {stdout: string, stderr: string} = await promisify(child_process.exec)(
1183-
'verilator -lint-only -Wall -Wno-DECLFILENAME -Wno-UNOPT -Wno-UNOPTFLAT ' + filenames.map(escape_filename).join(' '),
1207+
'timeout -k10s 40s verilator -lint-only -Wall -Wno-DECLFILENAME -Wno-UNOPT -Wno-UNOPTFLAT ' + filenames.map(shell_escape).join(' '),
11841208
{maxBuffer: 1000000, cwd: dirname || null, timeout: options.timeout || 60000})
11851209
.catch(exc => exc);
11861210
for (const line of verilator_result.stderr.split('\n')) {
@@ -1222,8 +1246,9 @@ export async function process(filenames: string[], dirname?: string, options: Op
12221246
const tmpjson = await tmp.tmpName({ postfix: '.json' });
12231247
let obj = undefined;
12241248
const yosys_result: {stdout: string, stderr: string, killed?: boolean, code?: number} = await promisify(child_process.exec)(
1225-
'yosys -p "hierarchy -auto-top; proc' + optimize_simp + fsmpass + '; memory -nomap; wreduce -memx' +
1226-
optimize + '" -o "' + tmpjson + '" ' + filenames.map(escape_filename).join(' '),
1249+
'timeout -k10s 40s yosys -p "' + shell_escape_contents(filenames.map(process_filename).join('; ')) +
1250+
'; hierarchy -auto-top; proc' + optimize_simp + fsmpass + '; memory -nomap; wreduce -memx' +
1251+
optimize + '" -o "' + tmpjson + '"',
12271252
{maxBuffer: 1000000, cwd: dirname || null, timeout: options.timeout || 60000})
12281253
.catch(exc => exc);
12291254
try {

tests/z.sv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// high impedance state
2+
module sourceZ(
3+
output out
4+
);
5+
assign out = 1'bZ;
6+
7+
endmodule

0 commit comments

Comments
 (0)