Improved YosysJS WebWorker API

This commit is contained in:
Clifford Wolf 2015-07-04 17:08:44 +02:00
parent 766dd51447
commit c4dde71dca
3 changed files with 51 additions and 10 deletions

View File

@ -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);
</script>
</body></html>

View File

@ -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;
}
}

View File

@ -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]);
}