aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/synth36
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-11-23 07:55:07 +0100
committerTristan Gingold <tgingold@free.fr>2022-11-23 07:55:07 +0100
commit81295dc08948e0cf103b4597580ed95a9cc25813 (patch)
treec78d18a8b447390bbb0b21a4c46c025b31a4f453 /testsuite/synth/synth
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": [] }]);