Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tilk/yosys2digitaljs
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Aug 3, 2019
2 parents c267738 + 8c6e4fe commit e702587
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
47 changes: 29 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,34 @@ function yosys_to_simcir_mod(name, mod, portmaps) {
async function process(filenames, dirname) {
const tmpjson = await tmp.tmpName({ postfix: '.json' });
const yosys_result = await promisify(child_process.exec)(
'yosys -p "hierarchy; proc; fsm; memory -nomap" -o "' + tmpjson + '" ' + filenames.join(' '),
{maxBuffer: 1000000, cwd: dirname || null});
const obj = JSON.parse(fs.readFileSync(tmpjson, 'utf8'));
await promisify(fs.unlink)(tmpjson);
const portmaps = order_ports(obj);
const out = yosys_to_simcir(obj, portmaps);
const toporder = topsort(module_deps(obj));
toporder.pop();
const toplevel = toporder.pop();
const output = out[toplevel];
'yosys -p "hierarchy; proc; fsm; memory -nomap; dff2dffe; wreduce -memx; opt -full" -o "' + tmpjson + '" ' + filenames.join(' '),
{maxBuffer: 1000000, cwd: dirname || null})
.catch(exc => exc);
try {
if (yosys_result instanceof Error) throw yosys_result;
const obj = JSON.parse(fs.readFileSync(tmpjson, 'utf8'));
await promisify(fs.unlink)(tmpjson);
const portmaps = order_ports(obj);
const out = yosys_to_simcir(obj, portmaps);
const toporder = topsort(module_deps(obj));
toporder.pop();
const toplevel = toporder.pop();
const output = out[toplevel];
output.subcircuits = {};
for (const x of toporder) output.subcircuits[x] = out[x];
return {
output: output,
yosys_stdout: yosys_result.stdout,
yosys_stderr: yosys_result.stderr
};
} catch (exc) {
exc.yosys_stdout = yosys_result.stdout;
exc.yosys_stderr = yosys_result.stderr;
throw exc;
}
}

function io_ui(output) {
for (const [name, dev] of Object.entries(output.devices)) {
// use clock for clocky named inputs
if (dev.celltype == '$input' && dev.bits == 1 && (dev.label == 'clk' || dev.label == 'clock')) {
Expand All @@ -663,14 +681,6 @@ async function process(filenames, dirname) {
if (dev.celltype == '$output')
dev.celltype = dev.bits == 1 ? '$lamp' : '$numdisplay';
}
output.subcircuits = {};
for (const x of toporder) output.subcircuits[x] = out[x];
return {
status: true,
output: output,
yosys_stdout: yosys_result.stdout,
yosys_stderr: yosys_result.stderr
};
}

async function process_files(data) {
Expand Down Expand Up @@ -705,4 +715,5 @@ async function process_sv(text) {
exports.process = process;
exports.process_files = process_files;
exports.process_sv = process_sv;
exports.io_ui = io_ui;

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yosys2digitaljs",
"version": "0.0.9",
"version": "0.1.1",
"description": "Export Yosys netlists to a logic simulator",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions process.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

const fs = require('fs');
const argv = require('minimist')(process.argv.slice(2));
const argv = require('minimist')(process.argv.slice(2), {boolean: true});

function read_files(l) {
const ret = {};
Expand Down Expand Up @@ -37,7 +37,9 @@ result.then(res => {
console.log(res.yosys_stdout);
console.log('*/');
}
console.log(JSON.stringify(res.output, null, argv.noindent ? 0 : 2));
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>');
};
Expand Down

0 comments on commit e702587

Please sign in to comment.