From: Clifford Wolf Date: Sat, 4 Jul 2015 15:08:44 +0000 (+0200) Subject: Improved YosysJS WebWorker API X-Git-Tag: yosys-0.6~232 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c4dde71dcaffa2b1414817cd4ff4885c12d1defd;p=yosys.git Improved YosysJS WebWorker API --- diff --git a/misc/yosysjs/demo02.html b/misc/yosysjs/demo02.html index a6c4eb96b..9191db98d 100644 --- a/misc/yosysjs/demo02.html +++ b/misc/yosysjs/demo02.html @@ -54,42 +54,50 @@ endmodule document.getElementById('popup').style.visibility = 'hidden'; document.getElementById('popupmsg').textContent = 'Please wait..'; } + function handle_run_errors(logmsg, errmsg) { + if (errmsg != "") { + window.alert(errmsg); + document.getElementById('popup').style.visibility = 'hidden'; + } + } function synth1() { document.getElementById('popup').style.visibility = 'visible'; ys.write_file("input.v", document.getElementById('code').value); - ys.run('design -reset; read_verilog input.v; show -stretch'); + ys.run('design -reset; read_verilog input.v; show -stretch', handle_run_errors); ys.read_file('show.dot', (function(text){ - YosysJS.dot_into_svg(text, 'svg'); + console.log(ys.errmsg); + if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg'); document.getElementById('popup').style.visibility = 'hidden'; })); } function synth2() { document.getElementById('popup').style.visibility = 'visible'; ys.write_file("input.v", document.getElementById('code').value); - ys.run('design -reset; read_verilog input.v; proc; opt_clean; show -stretch'); + ys.run('design -reset; read_verilog input.v; proc; opt_clean; show -stretch', handle_run_errors); ys.read_file('show.dot', (function(text){ - YosysJS.dot_into_svg(text, 'svg'); + if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg'); document.getElementById('popup').style.visibility = 'hidden'; })); } function synth3() { document.getElementById('popup').style.visibility = 'visible'; ys.write_file("input.v", document.getElementById('code').value); - ys.run('design -reset; read_verilog input.v; synth -run coarse; show -stretch'); + ys.run('design -reset; read_verilog input.v; synth -run coarse; show -stretch', handle_run_errors); ys.read_file('show.dot', (function(text){ - YosysJS.dot_into_svg(text, 'svg'); + if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg'); document.getElementById('popup').style.visibility = 'hidden'; })); } function synth4() { document.getElementById('popup').style.visibility = 'visible'; ys.write_file("input.v", document.getElementById('code').value); - ys.run('design -reset; read_verilog input.v; synth -run coarse; synth -run fine; show -stretch'); + ys.run('design -reset; read_verilog input.v; synth -run coarse; synth -run fine; show -stretch', handle_run_errors); ys.read_file('show.dot', (function(text){ - YosysJS.dot_into_svg(text, 'svg'); + if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg'); document.getElementById('popup').style.visibility = 'hidden'; })); } var ys = YosysJS.create_worker(on_ys_ready); + ys.verbose(true); diff --git a/misc/yosysjs/yosysjs.js b/misc/yosysjs/yosysjs.js index 9723386f9..eabc0ec50 100644 --- a/misc/yosysjs/yosysjs.js +++ b/misc/yosysjs/yosysjs.js @@ -227,6 +227,7 @@ var YosysJS = new function() { ys.worker = new Worker('yosyswrk.js'); ys.callback_idx = 1; ys.callback_cache = {}; + ys.errmsg = ""; ys.callback_cache[0] = on_ready; on_ready = null; @@ -235,6 +236,7 @@ var YosysJS = new function() { var response = e.data[0]; var callback = ys.callback_cache[response.idx]; delete ys.callback_cache[response.idx]; + if ("errmsg" in response) ys.errmsg = response.errmsg; if (callback) callback.apply(null, response.args); } @@ -294,6 +296,17 @@ var YosysJS = new function() { ys.worker.postMessage([request]); } + ys.verbose = function(value, callback) { + var request = { + "idx": ys.callback_idx, + "mode": "verbose", + "value": value + }; + + ys.callback_cache[ys.callback_idx++] = callback; + ys.worker.postMessage([request]); + } + return ys; } } diff --git a/misc/yosysjs/yosyswrk.js b/misc/yosysjs/yosyswrk.js index 1d77b3d25..b6173439f 100644 --- a/misc/yosysjs/yosyswrk.js +++ b/misc/yosysjs/yosyswrk.js @@ -1,3 +1,13 @@ +var Module = {}; +var verbose_mode = false; +var text_buffer = ""; + +Module["printErr"] = Module["print"] = function(text) { + if (verbose_mode) + console.log(text); + text_buffer += text + "\n"; +} + importScripts('yosys.js'); onmessage = function(e) { @@ -5,12 +15,16 @@ onmessage = function(e) { var response = { "idx": request.idx, "args": [] }; if (request.mode == "run") { + response["errmsg"] = ""; try { + text_buffer = ""; Module.ccall('run', '', ['string'], [request.cmd]); - response.args.push(""); } catch (e) { - response.args.push(mod.ccall('errmsg', 'string', [], [])); + response.errmsg = Module.ccall('errmsg', 'string', [], []); } + response.args.push(text_buffer); + response.args.push(response.errmsg); + text_buffer = ""; } if (request.mode == "read_file") { @@ -37,6 +51,12 @@ onmessage = function(e) { } catch (e) { } } + if (request.mode == "verbose") { + if (request.value) + console.log(text_buffer); + verbose_mode = request.value; + } + postMessage([response]); }