aboutsummaryrefslogtreecommitdiffstats
path: root/misc/yosysjs/yosysjs.js
blob: ea98c9b51704d3f03fd4abd9d1a750a1be394b64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#ifndef LINUX_IFX_MODEM_H
#define LINUX_IFX_MODEM_H

struct ifx_modem_platform_data {
	unsigned short rst_out;		/* modem reset out */
	unsigned short pwr_on;		/* power on */
	unsigned short rst_pmu;		/* reset modem */
	unsigned short tx_pwr;		/* modem power threshold */
	unsigned short srdy;		/* SRDY */
	unsigned short mrdy;		/* MRDY */
	unsigned char modem_type;	/* Modem type */
	unsigned long max_hz;		/* max SPI frequency */
	unsigned short use_dma:1;	/* spi protocol driver supplies
					   dma-able addrs */
};
#define IFX_MODEM_6160	1
#define IFX_MODEM_6260	2

#endif
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
var YosysJS = new function() {
	this.script_element = document.currentScript;
	this.viz_element = undefined;
	this.viz_ready = true;

	this.url_prefix = this.script_element.src.replace(/[^/]+$/, '')

	this.load_viz = function() {
		if (this.viz_element)
			return;

		this.viz_element = document.createElement('iframe')
		this.viz_element.style.display = 'none'
		document.body.appendChild(this.viz_element);

		this.viz_element.contentWindow.document.open();
		this.viz_element.contentWindow.document.write('<script type="text/javascript" onload="viz_ready = true;" src="' + this.url_prefix + 'viz.js"></' + 'script>');
		this.viz_element.contentWindow.document.close();

		var that = this;
		function check_viz_ready() {
			if (that.viz_element.contentWindow.viz_ready) {
				console.log("YosysJS: Successfully loaded Viz.");
				that.viz_ready = true;
			} else
				window.setTimeout(check_viz_ready, 100);
		}

		this.viz_ready = false;
		window.setTimeout(check_viz_ready, 100);
	}

	this.dot_to_svg = function(dot_text) {
		return this.viz_element.contentWindow.Viz(dot_text, "svg");
	}

	this.dot_into_svg = function(dot_text, svg_element) {
		if (typeof(svg_element) == 'string' && svg_element != "")
			svg_element = document.getElementById(svg_element);
		svg_element.innerHTML = this.dot_to_svg(dot_text);
		c = svg_element.firstChild;
		while (c) {
			if (c.tagName == 'svg') {
				while (c.firstChild)
					svg_element.appendChild(c.firstChild);
				svg_element.setAttribute('viewBox', c.getAttribute('viewBox'));
				// svg_element.removeChild(c);
				break;
			}
			c = c.nextSibling;
		}
	}

	this.create = function(reference_element, on_ready) {
		var ys = new Object();
		ys.YosysJS = this;
		ys.init_script = "";
		ys.ready = false;
		ys.verbose = false;
		ys.logprint = false;
		ys.echo = false;
		ys.errmsg = "";

		if (typeof(reference_element) == 'string' && reference_element != "")
			reference_element = document.getElementById(reference_element);

		if (reference_element) {
			if (reference_element.tagName == 'textarea')
				ys.init_script = reference_element.value;

			if (reference_element.tagName == 'iframe') {
				ys.iframe_element = reference_element;
			} else {
				ys.iframe_element = document.createElement('iframe');
				ys.iframe_element.id = reference_element.id;
				for (i in reference_element.style)
					ys.iframe_element.style[i] = reference_element.style[i];
				reference_element.parentNode.insertBefore(ys.iframe_element, reference_element);
				reference_element.parentNode.removeChild(reference_element);
			}
		} else {
			ys.iframe_element = document.createElement('iframe');
			ys.iframe_element.style.display = 'none';
			document.body.appendChild(ys.iframe_element);
		}

		ys.print_buffer = "";
		ys.last_line_empty = false;
		ys.got_normal_log_message = false;
		ys.window = ys.iframe_element.contentWindow;

		var doc = ys.window.document;
		var mod = ys.window.Module = {
			print: function(text) {
				if (typeof(text) == 'number')
					return;
				ys.print_buffer += text + "\n";
				ys.got_normal_log_message = true;
				if (ys.logprint)
					console.log(text);
				if (ys.verbose) {
					ys.last_line_empty = text == "";
					if (text == "") {
						span = doc.createElement('br');
					} else {
						span = doc.createElement('span');
						span.textContent = text + "\n";
						span.style.fontFamily = 'monospace';
						span.style.whiteSpace = 'pre';
					}
					doc.firstChild.appendChild(span);
					if (doc.body)
						ys.window.scrollTo(0, doc.body.scrollHeight);
					else
						ys.window.scrollBy(0, 100);
				}
				ys.ready = true;
			},
			printErr: function(text) {
				if (typeof(text) == 'number')
					return;
				if (ys.logprint)
					console.log(text);
				if (ys.got_normal_log_message) {
					ys.print_buffer += text + "\n";
					ys.last_line_empty = text == "";
					if (text == "") {
						span = doc.createElement('br');
					} else {
						span = doc.createElement('span');
						span.textContent = text + "\n";
						span.style.fontFamily = 'monospace';
						span.style.whiteSpace = 'pre';
						span.style.color = 'red';
					}
					doc.firstChild.appendChild(span);
					if (doc.body)
						ys.window.scrollTo(0, doc.body.scrollHeight);
					else
						ys.window.scrollBy(0, 100);
				} else
				if (!ys.logprint)
					console.log(text);
			},
		};

		ys.write = function(text) {
			ys.print_buffer += text + "\n";
			ys.last_line_empty = text == "";
			span = doc.createElement('span');
			span.textContent = text + "\n";
			span.style.fontFamily = 'monospace';
			span.style.whiteSpace = 'pre';
			doc.firstChild.appendChild(span);
			if (doc.body)
				ys.window.scrollTo(0, doc.body.scrollHeight);
			else
				ys.window.scrollBy(0, 100);
		}

		ys.prompt = function() {
			return mod.ccall('prompt', 'string', [], [])
		}

		ys.run = function(cmd) {
			ys.print_buffer = "";
			if (ys.echo) {
				if (!ys.last_line_empty)
					ys.write("");
				ys.write(ys.prompt() + cmd);
			}
			try {
				mod.ccall('run', '', ['string'], [cmd]);
			} catch (e) {
				ys.errmsg = mod.ccall('errmsg', 'string', [], []);
			}
			return ys.print_buffer;
		}

		ys.read_file = function(filename) {
			try {
				return ys.window.FS.readFile(filename, {encoding: 'utf8'});
			} catch (e) {
				return "";
			}
		}

		ys.write_file = function(filename, text) {
			return ys.window.FS.writeFile(filename, text, {encoding: 'utf8'});
		}

		ys.read_dir = function(dirname) {
			return ys.window.FS.readdir(dirname);
		}

		ys.remove_file = function(filename) {
			try {
				ys.window.FS.unlink(filename);
			} catch (e) { }
		}

		doc.open();
		doc.write('<script type="text/javascript" src="' + this.url_prefix + 'yosys.js"></' + 'script>');
		doc.close();

		if (on_ready || ys.init_script) {
			function check_ready() {
				if (ys.ready && ys.YosysJS.viz_ready) {
					if (ys.init_script) {
						ys.write_file("/script.ys", ys.init_script);
						ys.run("script /script.ys");
					}
					if (on_ready)
						on_ready(ys);
				} else
					window.setTimeout(check_ready, 100);
			}
			window.setTimeout(check_ready, 100);
		}

		return ys;
	}

	this.create_worker = function(on_ready) {
		var ys = new Object();
		ys.YosysJS = this;
		ys.worker = new Worker(this.url_prefix + 'yosyswrk.js');
		ys.callback_idx = 1;
		ys.callback_cache = {};
		ys.errmsg = "";

		ys.callback_cache[0] = on_ready;
		on_ready = null;

		ys.worker.onmessage = function(e) {
			var response = e.data[0];
			var callback = ys.callback_cache[response.idx];
			delete ys.callback_cache[response.idx];
			if ("errmsg" in response) ys.errmsg = response.errmsg;
			if (callback) callback.apply(null, response.args);
		}

		ys.run = function(cmd, callback) {
			var request = {
				"idx": ys.callback_idx,
				"mode": "run",
				"cmd": cmd
			};

			ys.callback_cache[ys.callback_idx++] = callback;
			ys.worker.postMessage([request]);
		}

		ys.read_file = function(filename, callback) {
			var request = {
				"idx": ys.callback_idx,
				"mode": "read_file",
				"filename": filename
			};

			ys.callback_cache[ys.callback_idx++] = callback;
			ys.worker.postMessage([request]);
		}

		ys.write_file = function(filename, text, callback) {
			var request = {
				"idx": ys.callback_idx,
				"mode": "write_file",
				"filename": filename,
				"text": text
			};

			ys.callback_cache[ys.callback_idx++] = callback;
			ys.worker.postMessage([request]);
		}

		ys.read_dir = function(dirname, callback) {
			var request = {
				"idx": ys.callback_idx,
				"mode": "read_dir",
				"dirname": dirname
			};

			ys.callback_cache[ys.callback_idx++] = callback;
			ys.worker.postMessage([request]);
		}

		ys.remove_file = function(filename, callback) {
			var request = {
				"idx": ys.callback_idx,
				"mode": "remove_file",
				"filename": filename
			};

			ys.callback_cache[ys.callback_idx++] = callback;
			ys.worker.postMessage([request]);
		}

		ys.verbose = function(value, callback) {
			var request = {
				"idx": ys.callback_idx,
				"mode": "verbose",
				"value": value
			};

			ys.callback_cache[ys.callback_idx++] = callback;
			ys.worker.postMessage([request]);
		}

		return ys;
	}
}