diff options
Diffstat (limited to 'misc/yosysjs/yosyswrk.js')
-rw-r--r-- | misc/yosysjs/yosyswrk.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/misc/yosysjs/yosyswrk.js b/misc/yosysjs/yosyswrk.js new file mode 100644 index 000000000..1d77b3d25 --- /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": [] }]); |