summaryrefslogtreecommitdiff
path: root/misc/yosysjs
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2015-06-28 17:47:58 +0200
committerClifford Wolf <clifford@clifford.at>2015-06-28 17:47:58 +0200
commit358e41591891fc74045860b0c3364cb155726b30 (patch)
tree1e5e7dea6ab3f898d17863a126660795bdd088ce /misc/yosysjs
parentdf0163cd2b0dfd7c825f13ecb1c22f4f4d494a3b (diff)
Added YosysJS.create_worker()
Diffstat (limited to 'misc/yosysjs')
-rw-r--r--misc/yosysjs/demo02.html57
-rw-r--r--misc/yosysjs/yosysjs.js78
-rw-r--r--misc/yosysjs/yosyswrk.js43
3 files changed, 145 insertions, 33 deletions
diff --git a/misc/yosysjs/demo02.html b/misc/yosysjs/demo02.html
index d36e223c..a6c4eb96 100644
--- a/misc/yosysjs/demo02.html
+++ b/misc/yosysjs/demo02.html
@@ -7,7 +7,6 @@
padding:15px; text-align:center;"><span id="popupmsg">Loading...</span></div>
</div>
<h1>YosysJS Example Application #02</h1>
- <iframe id="ys" style="width: 800px; height: 100px;"></iframe><p/>
<textarea id="code" style="width: 800px; height: 300px;">
// borrowed with some modifications from
// http://www.ee.ed.ac.uk/~gerard/Teach/Verilog/manual/Example/lrgeEx2/cooley.html
@@ -56,47 +55,41 @@ endmodule
document.getElementById('popupmsg').textContent = 'Please wait..';
}
function synth1() {
- function work() {
- ys.write_file("input.v", document.getElementById('code').value);
- ys.run('design -reset; read_verilog input.v; show -stretch');
- YosysJS.dot_into_svg(ys.read_file('show.dot'), 'svg');
- document.getElementById('popup').style.visibility = 'hidden';
- }
document.getElementById('popup').style.visibility = 'visible';
- window.setTimeout(work, 100);
+ ys.write_file("input.v", document.getElementById('code').value);
+ ys.run('design -reset; read_verilog input.v; show -stretch');
+ ys.read_file('show.dot', (function(text){
+ YosysJS.dot_into_svg(text, 'svg');
+ document.getElementById('popup').style.visibility = 'hidden';
+ }));
}
function synth2() {
- function work() {
- ys.write_file("input.v", document.getElementById('code').value);
- ys.run('design -reset; read_verilog input.v; proc; opt_clean; show -stretch');
- YosysJS.dot_into_svg(ys.read_file('show.dot'), 'svg');
- document.getElementById('popup').style.visibility = 'hidden';
- }
document.getElementById('popup').style.visibility = 'visible';
- window.setTimeout(work, 100);
+ ys.write_file("input.v", document.getElementById('code').value);
+ ys.run('design -reset; read_verilog input.v; proc; opt_clean; show -stretch');
+ ys.read_file('show.dot', (function(text){
+ YosysJS.dot_into_svg(text, 'svg');
+ document.getElementById('popup').style.visibility = 'hidden';
+ }));
}
function synth3() {
- function work() {
- ys.write_file("input.v", document.getElementById('code').value);
- ys.run('design -reset; read_verilog input.v; synth -run coarse; show -stretch');
- YosysJS.dot_into_svg(ys.read_file('show.dot'), 'svg');
- document.getElementById('popup').style.visibility = 'hidden';
- }
document.getElementById('popup').style.visibility = 'visible';
- window.setTimeout(work, 100);
+ ys.write_file("input.v", document.getElementById('code').value);
+ ys.run('design -reset; read_verilog input.v; synth -run coarse; show -stretch');
+ ys.read_file('show.dot', (function(text){
+ YosysJS.dot_into_svg(text, 'svg');
+ document.getElementById('popup').style.visibility = 'hidden';
+ }));
}
function synth4() {
- function work() {
- 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');
- YosysJS.dot_into_svg(ys.read_file('show.dot'), 'svg');
- document.getElementById('popup').style.visibility = 'hidden';
- }
document.getElementById('popup').style.visibility = 'visible';
- window.setTimeout(work, 100);
+ 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.read_file('show.dot', (function(text){
+ YosysJS.dot_into_svg(text, 'svg');
+ document.getElementById('popup').style.visibility = 'hidden';
+ }));
}
- var ys = YosysJS.create('ys', on_ys_ready);
- ys.verbose = true;
- ys.echo = true;
+ var ys = YosysJS.create_worker(on_ys_ready);
</script>
</body></html>
diff --git a/misc/yosysjs/yosysjs.js b/misc/yosysjs/yosysjs.js
index 2c78451d..65ed3049 100644
--- a/misc/yosysjs/yosysjs.js
+++ b/misc/yosysjs/yosysjs.js
@@ -172,7 +172,7 @@ var YosysJS = new function() {
try {
mod.ccall('run', '', ['string'], [cmd]);
} catch (e) {
- ys.errmsg = mod.ccall('errmsg', 'string', [], []);;
+ ys.errmsg = mod.ccall('errmsg', 'string', [], []);
}
return ys.print_buffer;
}
@@ -220,4 +220,80 @@ var YosysJS = new function() {
return ys;
}
+
+ this.create_worker = function(on_ready) {
+ var ys = new Object();
+ ys.YosysJS = this;
+ ys.worker = new Worker('yosyswrk.js');
+ ys.callback_idx = 1;
+ ys.callback_cache = {};
+
+ ys.callback_cache[0] = on_ready;
+ on_ready = null;
+
+ ys.worker.onmessage = function(e) {
+ var response = e.data[0];
+ var callback = ys.callback_cache[response.idx];
+ delete ys.callback_cache[response.idx];
+ if (callback) callback.apply(null, response.args);
+ }
+
+ ys.run = function(cmd, callback) {
+ var request = {
+ "idx": ys.callback_idx,
+ "mode": "run",
+ "cmd": cmd
+ };
+
+ ys.callback_cache[ys.callback_idx++] = callback;
+ ys.worker.postMessage([request]);
+ }
+
+ ys.read_file = function(filename, callback) {
+ var request = {
+ "idx": ys.callback_idx,
+ "mode": "read_file",
+ "filename": filename
+ };
+
+ ys.callback_cache[ys.callback_idx++] = callback;
+ ys.worker.postMessage([request]);
+ }
+
+ ys.write_file = function(filename, text, callback) {
+ var request = {
+ "idx": ys.callback_idx,
+ "mode": "write_file",
+ "filename": filename,
+ "text": text
+ };
+
+ ys.callback_cache[ys.callback_idx++] = callback;
+ ys.worker.postMessage([request]);
+ }
+
+ ys.read_dir = function(dirname, callback) {
+ var request = {
+ "idx": ys.callback_idx,
+ "mode": "read_dir",
+ "dirname": dirname
+ };
+
+ ys.callback_cache[ys.callback_idx++] = callback;
+ ys.worker.postMessage([request]);
+ }
+
+ ys.remove_file = function(filename, callback) {
+ var request = {
+ "idx": ys.callback_idx,
+ "mode": "remove_file",
+ "filename": filename
+ };
+
+ 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
new file mode 100644
index 00000000..1d77b3d2
--- /dev/null
+++ b/misc/yosysjs/yosyswrk.js
@@ -0,0 +1,43 @@
+importScripts('yosys.js');
+
+onmessage = function(e) {
+ var request = e.data[0];
+ var response = { "idx": request.idx, "args": [] };
+
+ if (request.mode == "run") {
+ try {
+ Module.ccall('run', '', ['string'], [request.cmd]);
+ response.args.push("");
+ } catch (e) {
+ response.args.push(mod.ccall('errmsg', 'string', [], []));
+ }
+ }
+
+ if (request.mode == "read_file") {
+ try {
+ response.args.push(FS.readFile(request.filename, {encoding: 'utf8'}));
+ } catch (e) { }
+ }
+
+ if (request.mode == "write_file") {
+ try {
+ FS.writeFile(request.filename, request.text, {encoding: 'utf8'});
+ } catch (e) { }
+ }
+
+ if (request.mode == "read_dir") {
+ try {
+ response.args.push(FS.readdir(request.dirname));
+ } catch (e) { }
+ }
+
+ if (request.mode == "remove_file") {
+ try {
+ FS.unlink(request.filename);
+ } catch (e) { }
+ }
+
+ postMessage([response]);
+}
+
+postMessage([{ "idx": 0, "args": [] }]);