aboutsummaryrefslogtreecommitdiffstats
path: root/misc/yosysjs/yosyswrk.js
blob: b6173439f15a4fd6f5700fdceffa1e4ef82245e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Err
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": [] }]);