aboutsummaryrefslogtreecommitdiffstats
path: root/misc/yosys.html
blob: 29d89e6fe73e9b9cf62e423d064290a25d40b507 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html><head>
	<title>yosys.js example application</title>
</head><body onload="document.getElementById('command').focus()">
	<h1>yosys.js example application</h1>
	<div><textarea id="output" style="width: 100%" rows="30" cols="100"></textarea></div>
	<div id="wait" style="display: block"><br/><b><span id="waitmsg">Loading...</span></b></div>
	<div id="input" style="display: none"><form onsubmit="window.setTimeout(run_command); return false"><tt><span id="prompt">
			</span></tt><input id="command" type="text" style="font-family: monospace; font-weight: bold;" size="100"></form></div>
	<script type='text/javascript'>
		var got_log_messages = false;

		var Module = {
			print: (function() {
				var element = document.getElementById('output');
				if (element) element.value = ''; // clear browser cache
				return function(text) {
					if (!got_log_messages) {
						window.setTimeout(startup, 50);
						got_log_messages = true;
					}
					if (element && typeof(text) != "number") {
						element.value += text + "\n";
						element.scrollTop = element.scrollHeight; // focus on bottom
					}
				};
			})(),
			printErr: (function() {
				var element = document.getElementById('output');
				if (element) element.value = ''; // clear browser cache
				return function(text) {
					if (element && typeof(text) != "number") {
						console.log(text);
						if (got_log_messages) {
							element.value += text + "\n";
							element.scrollTop = element.scrollHeight; // focus on bottom
						}
					}
				};
			})(),
		};

		function startup() {
			document.getElementById('wait').style.display = 'none';
			document.getElementById('input').style.display = 'block';
			document.getElementById('waitmsg').innerText = 'Waiting for yosys.js...';
			document.getElementById('prompt').innerText = yosys_prompt();
			document.getElementById('command').focus();
			console.log('yosys.js loaded.');
		}

		function yosys_command(cmd) {
			Module.ccall('run', '', ['string'], [cmd])
		}

		function yosys_prompt() {
			return Module.ccall('prompt', 'string', [], [])
		}

		function run_command() {
			var cmd = document.getElementById('command').value;
			document.getElementById('command').value = '';
			Module.print(yosys_prompt() + cmd);
			document.getElementById('wait').style.display = 'block';
			document.getElementById('input').style.display = 'none';

			function run_command_bh() {
				try {
					yosys_command(cmd);
				} catch (e) {
					Module.print('Caught JavaScript exception. (see JavaScript console for details.)');
					console.log(e);
				}
				document.getElementById('wait').style.display = 'none';
				document.getElementById('input').style.display = 'block';
				document.getElementById('prompt').innerText = yosys_prompt();
				document.getElementById('command').focus();
			}

			window.setTimeout(run_command_bh, 50);
			return false;
		}
	</script>
	<script async type="text/javascript" src="yosys.js"></script>
</body></html>