mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-13 04:28:18 +00:00
Added YosysJS.create_worker()
This commit is contained in:
parent
df0163cd2b
commit
358e415918
|
@ -7,7 +7,6 @@
|
||||||
padding:15px; text-align:center;"><span id="popupmsg">Loading...</span></div>
|
padding:15px; text-align:center;"><span id="popupmsg">Loading...</span></div>
|
||||||
</div>
|
</div>
|
||||||
<h1>YosysJS Example Application #02</h1>
|
<h1>YosysJS Example Application #02</h1>
|
||||||
<iframe id="ys" style="width: 800px; height: 100px;"></iframe><p/>
|
|
||||||
<textarea id="code" style="width: 800px; height: 300px;">
|
<textarea id="code" style="width: 800px; height: 300px;">
|
||||||
// borrowed with some modifications from
|
// borrowed with some modifications from
|
||||||
// http://www.ee.ed.ac.uk/~gerard/Teach/Verilog/manual/Example/lrgeEx2/cooley.html
|
// 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..';
|
document.getElementById('popupmsg').textContent = 'Please wait..';
|
||||||
}
|
}
|
||||||
function synth1() {
|
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';
|
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 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';
|
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 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';
|
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 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';
|
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);
|
var ys = YosysJS.create_worker(on_ys_ready);
|
||||||
ys.verbose = true;
|
|
||||||
ys.echo = true;
|
|
||||||
</script>
|
</script>
|
||||||
</body></html>
|
</body></html>
|
||||||
|
|
|
@ -172,7 +172,7 @@ var YosysJS = new function() {
|
||||||
try {
|
try {
|
||||||
mod.ccall('run', '', ['string'], [cmd]);
|
mod.ccall('run', '', ['string'], [cmd]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ys.errmsg = mod.ccall('errmsg', 'string', [], []);;
|
ys.errmsg = mod.ccall('errmsg', 'string', [], []);
|
||||||
}
|
}
|
||||||
return ys.print_buffer;
|
return ys.print_buffer;
|
||||||
}
|
}
|
||||||
|
@ -220,4 +220,80 @@ var YosysJS = new function() {
|
||||||
|
|
||||||
return ys;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
43
misc/yosysjs/yosyswrk.js
Normal file
43
misc/yosysjs/yosyswrk.js
Normal file
|
@ -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": [] }]);
|
Loading…
Reference in a new issue