diff --git a/index.js b/index.js index a0eee8f..98481b5 100755 --- a/index.js +++ b/index.js @@ -2,13 +2,13 @@ "use strict"; const tmp = require('tmp'); -const shell = require('shelljs'); +const child_process = require('child_process'); const assert = require('assert'); const topsort = require('topsort'); const fs = require('fs'); -const dagre = require('dagre'); const HashMap = require('hashmap'); const bigInt = require('big-integer'); +const {promisify} = require('util'); const ltr2bit = { '1': 1, @@ -587,64 +587,15 @@ function yosys_to_simcir_mod(name, mod, portmaps) { return mout; } -function layout_circuit(circ) { - const g = new dagre.graphlib.Graph(); - const devmap = {}; - let maxx = 0, maxy = 0; - - g.setGraph({rankdir: 'RL'}); - g.setDefaultEdgeLabel(function() { return {}; }); - - for (const dev of circ.devices) { - g.setNode(dev.id, { - id: dev.id, - width: 32, - height: 32 - }); - devmap[dev.id] = dev; - } - - for (const conn of circ.connectors) { - g.setEdge(conn.from.id, conn.to.id); - } - - dagre.layout(g); - - for (const nname of g.nodes()) { - const node = g.node(nname); - devmap[node.id].x = node.x; - devmap[node.id].y = node.y; - maxx = Math.max(maxx, node.x); - maxy = Math.max(maxy, node.y); - //console.log(nname + ":" + JSON.stringify(node)); - } - - circ.width = maxx + 256; - circ.height = maxy + 64; -} - -function layout_circuits(circs) { - for (const name in circs) { - layout_circuit(circs[name]); - } -} - -function process(filenames) { - const tmpjson = tmp.tmpNameSync({ postfix: '.json' }); - const yosys_result = shell.exec( +async function process(filenames) { + const tmpjson = await promisify(tmp.tmpName)({ postfix: '.json' }); + const yosys_result = await promisify(child_process.exec)( 'yosys -p "hierarchy; proc; fsm; memory -nomap" -o "' + tmpjson + '" ' + filenames.join(' '), - {silent: true}); - if (yosys_result.code !== 0) { - return { - status: false, - yosys_stdout: yosys_result.stdout - }; - } + {maxBuffer: 1000000}); const obj = JSON.parse(fs.readFileSync(tmpjson, 'utf8')); - shell.rm(tmpjson); + await promisify(fs.unlink)(tmpjson); const portmaps = order_ports(obj); const out = yosys_to_simcir(obj, portmaps); - //layout_circuits(out); const toporder = topsort(module_deps(obj)); toporder.pop(); const toplevel = toporder.pop(); @@ -660,16 +611,17 @@ function process(filenames) { return { status: true, output: output, - yosys_stdout: yosys_result.stdout + yosys_stdout: yosys_result.stdout, + yosys_stderr: yosys_result.stderr }; } -function process_sv(text) { - const tmpsv = tmp.fileSync({ postfix: '.sv' }); - fs.writeSync(tmpsv.fd, text); - fs.closeSync(tmpsv.fd); - const ret = process([tmpsv.name]); - shell.rm(tmpsv.name); +async function process_sv(text) { + const tmpsv = await promisify(tmp.fileSync)({ postfix: '.sv' }); + await promisify(fs.writeSync)(tmpsv.fd, text); + await promisify(fs.closeSync)(tmpsv.fd); + const ret = await process([tmpsv.name]); + await promisify(fs.unlink)(tmpsv.name); return ret; } diff --git a/package-lock.json b/package-lock.json index d0ec408..22dfd47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,156 +4,26 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, "big-integer": { "version": "1.6.34", "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.34.tgz", "integrity": "sha512-+w6B0Uo0ZvTSzDkXjoBCTNK0oe+aVL+yPi7kwGZm8hd8+Nj1AFPoxoq1Bl/mEu/G/ivOkUc1LRqVR0XeWFUzuA==" }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - } - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "dagre": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/dagre/-/dagre-0.8.2.tgz", - "integrity": "sha1-dVt59NVJnWPPdMM2j7CK3ZPs6v4=", - "requires": { - "graphlib": "2.1.5", - "lodash": "4.17.10" - } - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "graphlib": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/graphlib/-/graphlib-2.1.5.tgz", - "integrity": "sha1-av4a/MUUhVXseZ5JkFZ5W9aTjIc=", - "requires": { - "lodash": "4.17.10" - } - }, "hashmap": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/hashmap/-/hashmap-2.3.0.tgz", "integrity": "sha1-sT+2XafIul49uPwbjFuh0ASdryI=" }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "interpret": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.1.0.tgz", - "integrity": "sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=" - }, - "lodash": { - "version": "4.17.10", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", - "integrity": "sha1-G3eTz3JZ6jj7NmHU04syYK+K5Oc=" - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "1.1.11" - } - }, "minimist": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1.0.2" - } - }, "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, - "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" - }, - "rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", - "requires": { - "resolve": "1.8.1" - } - }, - "resolve": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", - "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", - "requires": { - "path-parse": "1.0.6" - } - }, - "shelljs": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.2.tgz", - "integrity": "sha512-pRXeNrCA2Wd9itwhvLp5LZQvPJ0wU6bcjaTMywHHGX5XWhVN2nzSu7WV0q+oUY7mGK3mgSkDDzP3MgjqdyIgbQ==", - "requires": { - "glob": "7.1.2", - "interpret": "1.1.0", - "rechoir": "0.6.2" - } - }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -166,11 +36,6 @@ "version": "0.0.2", "resolved": "https://registry.npmjs.org/topsort/-/topsort-0.0.2.tgz", "integrity": "sha1-Ll4O6KFDlBfxAdW5stA15iAmMyE=" - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } } } diff --git a/package.json b/package.json index c301149..76a9845 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yosys2digitaljs", - "version": "0.0.1", + "version": "0.0.2", "description": "Export Yosys netlists to a logic simulator", "main": "index.js", "scripts": { @@ -10,10 +10,8 @@ "license": "BSD-2-Clause", "dependencies": { "big-integer": "^1.6.34", - "dagre": "^0.8.0", "hashmap": "^2.3.0", "minimist": "^1.2.0", - "shelljs": "^0.8.2", "tmp": "0.0.33", "topsort": "^0.0.2" }, diff --git a/process.js b/process.js index e301299..ac5428a 100755 --- a/process.js +++ b/process.js @@ -2,7 +2,6 @@ "use strict"; const argv = require('minimist')(process.argv.slice(2)); -const shell = require('shelljs'); const header = ` @@ -15,25 +14,27 @@ const header = ` if (argv._.length === 0) { console.error('No Verilog files passed!'); - shell.exit(1); + process.exit(1); } -const res = require('./index.js').process(argv._); -if (!res.status) { +require('./index.js').process(argv._) +.then(res => { + if (argv.html) { + console.log(header); + console.log('
'); + }; +}) +.catch(res => { console.error('Yosys failed!'); - console.error(res.yosys_stdout); - shell.exit(1); -} -if (argv.html) { - console.log(header); - console.log('
'); -}; + console.error(res.stderr); + process.exit(1); +});