summaryrefslogtreecommitdiff
path: root/misc/yosysjs/yosyswrk.js
blob: 1d77b3d25ddc6288888f498fe5d550c17505f424 (plain)
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
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": [] }]);