yosys/misc/yosysjs/yosyswrk.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-07-04 10:08:44 -05:00
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";
}
2015-06-28 10:47:58 -05:00
importScripts('yosys.js');
onmessage = function(e) {
var request = e.data[0];
var response = { "idx": request.idx, "args": [] };
if (request.mode == "run") {
2015-07-04 10:08:44 -05:00
response["errmsg"] = "";
2015-06-28 10:47:58 -05:00
try {
2015-07-04 10:08:44 -05:00
text_buffer = "";
2015-06-28 10:47:58 -05:00
Module.ccall('run', '', ['string'], [request.cmd]);
} catch (e) {
2015-07-04 10:08:44 -05:00
response.errmsg = Module.ccall('errmsg', 'string', [], []);
2015-06-28 10:47:58 -05:00
}
2015-07-04 10:08:44 -05:00
response.args.push(text_buffer);
response.args.push(response.errmsg);
text_buffer = "";
2015-06-28 10:47:58 -05:00
}
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) { }
}
2015-07-04 10:08:44 -05:00
if (request.mode == "verbose") {
if (request.value)
console.log(text_buffer);
verbose_mode = request.value;
}
2015-06-28 10:47:58 -05:00
postMessage([response]);
}
postMessage([{ "idx": 0, "args": [] }]);