2 <title>YosysJS Example Application #
01</title>
3 <script type=
"text/javascript" src=
"yosysjs.js"></script>
4 </head><body onload=
"document.getElementById('command').focus()">
5 <h1>YosysJS Example Application #
01</h1>
6 <table width=
"100%"><tr><td><div id=
"tabs"></div></td><td align=
"right"><tt>[
<span onclick=
"load_example()">load example
</span> ]
</tt></td></tr></table>
7 <svg id=
"svg" style=
"display: none; position: absolute; padding: 10px; width: calc(100% - 40px); height: 480px;"></svg>
8 <div><textarea id=
"output" style=
"width: 100%; height: 500px"></textarea></div>
9 <div id=
"wait" style=
"display: block"><br/><b><span id=
"waitmsg">Loading...
</span></b></div>
10 <div id=
"input" style=
"display: none"><form onsubmit=
"window.setTimeout(run_command); return false"><br/><tt><span id=
"prompt">
11 </span></tt><input id=
"command" type=
"text" onkeydown=
"history(event)" style=
"font-family: monospace; font-weight: bold;" size=
"100"></form></div>
12 <script type='text/javascript'
>
13 function print_output(text) {
14 var el = document.getElementById('output');
15 el.value += text +
"\n";
19 var ys = YosysJS.create(
"", function() {
20 print_output(ys.print_buffer);
22 document.getElementById('wait').style.display = 'none';
23 document.getElementById('input').style.display = 'block';
24 document.getElementById('waitmsg').textContent = 'Waiting for yosys.js...';
25 document.getElementById('prompt').textContent = ys.prompt();
33 var history_index =
0;
36 function history(ev) {
37 if (ev.keyCode ==
38) {
38 el = document.getElementById('command');
39 if (history_index == history_log.length)
40 history_bak = el.value
41 if (history_index
> 0)
42 el.value = history_log[--history_index];
44 if (ev.keyCode ==
40) {
45 if (history_index < history_log.length) {
46 el = document.getElementById('command');
47 if (++history_index < history_log.length)
48 el.value = history_log[history_index];
50 el.value = history_bak;
55 var current_file =
"";
56 var console_messages =
"";
59 function update_tabs() {
60 var f, html =
"", flist = ys.read_dir('.');
61 if (current_file ==
"") {
62 html += '
<tt>[
<b>Console
</b>';
64 html += '
<tt>[
<span onclick=
"open_file(\'\')">Console
</span>';
68 if (f ==
"." || f ==
"..")
70 if (current_file == f) {
71 html += ' |
<b>' + f + '
</b>';
73 html += ' |
<span onclick=
"open_file(\'' + f + '\')">' + f + '
</span>';
76 html += ' |
<span onclick=
"open_file(prompt(\'Filename:\'))">new file
</span> ]
</tt>';
77 document.getElementById('tabs').innerHTML = html;
78 if (current_file ==
"" || /\.dot$/.test(current_file)) {
79 var element = document.getElementById('output');
80 element.readOnly = true;
81 element.scrollTop = element.scrollHeight; // focus on bottom
82 document.getElementById('command').focus();
84 document.getElementById('output').readOnly = false;
85 document.getElementById('output').focus();
89 function open_file(filename)
91 if (current_file ==
"")
92 console_messages = document.getElementById('output').value;
93 else if (!/\.dot$/.test(current_file))
94 ys.write_file(current_file, document.getElementById('output').value);
97 document.getElementById('output').value = console_messages;
100 document.getElementById('output').value = ys.read_file(filename);
102 document.getElementById('output').value =
"";
103 ys.write_file(filename, document.getElementById('output').value);
107 if (/\.dot$/.test(filename)) {
108 dot = document.getElementById('output').value;
109 YosysJS.dot_into_svg(dot, 'svg');
110 document.getElementById('svg').style.display = 'block';
111 document.getElementById('output').value = '';
113 document.getElementById('svg').innerHTML = '';
114 document.getElementById('svg').style.display = 'none';
117 current_file = filename;
124 function load_example() {
128 txt +=
"// a simple yosys.js example. run \"script example.ys\
".\n";
130 txt +=
"module example(input clk, input rst, input inc, output reg [3:0] cnt);\n";
131 txt +=
" always @(posedge clk) begin\n";
132 txt +=
" if (rst)\n";
133 txt +=
" cnt <= 0;\n";
134 txt +=
" else if (inc)\n";
135 txt +=
" cnt <= cnt + 1;\n";
137 txt +=
"endmodule\n";
139 ys.write_file('example.v', txt);
142 txt +=
"# a simple yosys.js example. run \"script example.ys\
".\n";
144 txt +=
"design -reset\n";
145 txt +=
"read_verilog example.v\n";
150 ys.write_file('example.ys', txt);
152 open_file('example.ys')
153 document.getElementById('command').focus();
156 function run_command() {
157 var cmd = document.getElementById('command').value;
158 document.getElementById('command').value = '';
159 if (history_log.length ==
0 || history_log[history_log.length-
1] != cmd)
160 history_log.push(cmd);
161 history_index = history_log.length;
163 var show_dot_before =
"";
164 try { show_dot_before = ys.read_file('show.dot'); } catch (e) { }
168 document.getElementById('wait').style.display = 'block';
169 document.getElementById('input').style.display = 'none';
171 function run_command_bh() {
175 ys.write('Caught JavaScript exception. (see JavaScript console for details.)');
178 print_output(ys.print_buffer);
180 document.getElementById('wait').style.display = 'none';
181 document.getElementById('input').style.display = 'block';
182 document.getElementById('prompt').textContent = ys.prompt();
184 var show_dot_after =
"";
185 try { show_dot_after = ys.read_file('show.dot'); } catch (e) { }
187 if (show_dot_before != show_dot_after)
188 open_file('show.dot');
193 window.setTimeout(run_command_bh,
50);