-
Notifications
You must be signed in to change notification settings - Fork 0
/
yosyswrk.js
63 lines (52 loc) · 1.3 KB
/
yosyswrk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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) {
var request = e.data[0];
var response = { "idx": request.idx, "args": [] };
if (request.mode == "run") {
response["errmsg"] = "";
try {
text_buffer = "";
Module.ccall('run', '', ['string'], [request.cmd]);
} catch (e) {
response.errmsg = Module.ccall('errmsg', 'string', [], []);
}
response.args.push(text_buffer);
response.args.push(response.errmsg);
text_buffer = "";
}
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) { }
}
if (request.mode == "verbose") {
if (request.value)
console.log(text_buffer);
verbose_mode = request.value;
}
postMessage([response]);
}
postMessage([{ "idx": 0, "args": [] }]);