-
Notifications
You must be signed in to change notification settings - Fork 18
/
process.js
executable file
·76 lines (71 loc) · 2.46 KB
/
process.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
"use strict";
const fs = require('fs');
const argv = require('minimist')(
process.argv.slice(2),
{boolean: ["optimize", "yosys_out", "yosys_output", "html", "no_io_ui", "tmpdir", "noindent", "fsmexpand"],
string: ["fsm"],
default: {fsm: true}}
);
const util = require('util');
function read_files(l) {
const ret = {};
for (const name of l) {
ret[name] = fs.readFileSync(name);
};
return ret;
}
const header = `<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script type="text/javascript" src="main.js"></script>
<title></title>
</head>
<body>`;
if (argv._.length === 0) {
console.error('No Verilog files passed!');
process.exit(1);
}
const yosys2digitaljs = require('./dist/index.js');
const opts = {};
if (argv.optimize) opts.optimize = true;
if (argv.fsm) opts.fsm = argv.fsm;
if (argv.fsmexpand) opts.fsmexpand = true;
if (argv.lint) opts.lint = true;
if (argv.propagation !== undefined) opts.propagation = Number(argv.propagation);
const result = argv.tmpdir ? yosys2digitaljs.process_files(read_files(argv._), opts) : yosys2digitaljs.process(argv._, null, opts);
result.then(res => {
if (argv.html) {
console.log(header);
console.log('<div id="paper"></div><script>const circuit = new digitaljs.Circuit(');
};
if (argv.yosys_out) {
console.log('/*');
console.log(res.yosys_stdout);
console.log('*/');
}
if (argv.yosys_output) {
console.log('/*');
console.log(util.inspect(res.yosys_output, {showHidden: false, depth: null, colors: process.stdout.isTTY && process.stdout.hasColors()}));
console.log('*/');
}
if (opts.lint && res.lint && res.lint.length) {
console.log('/*');
for (const lint of res.lint) {
console.log(`${lint.type} ${lint.file}:${lint.line}:${lint.column} ${lint.message}`);
}
console.log('*/');
}
const output = res.output;
if (!argv.no_io_ui) yosys2digitaljs.io_ui(output);
console.log(JSON.stringify(output, null, argv.noindent ? 0 : 2));
if (argv.html) {
console.log(');const paper = circuit.displayOn($(\'#paper\'));circuit.start();</script></body></html>');
};
})
.catch(res => {
console.error('Yosys failed!');
console.error(util.inspect(res, {showHidden: false, depth: null, colors: process.stdout.isTTY && process.stdout.hasColors()}));
process.exit(1);
});