mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-10 03:07:14 +00:00
144 lines
4.5 KiB
HTML
144 lines
4.5 KiB
HTML
<html><head>
|
|
<title>yosys.js example application</title>
|
|
</head><body onload="document.getElementById('command').focus()">
|
|
<h1>yosys.js example application</h1>
|
|
<div id="tabs"></div>
|
|
<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
|
|
}
|
|
}
|
|
};
|
|
})(),
|
|
};
|
|
|
|
var current_file = "";
|
|
var console_messages = "";
|
|
|
|
function update_tabs() {
|
|
var f, html = "", flist = FS.readdir('.');
|
|
if (current_file == "") {
|
|
html += '<tt>[ <b>Console</b>';
|
|
} else {
|
|
html += '<tt>[ <span onclick="open_file(\'\')">Console</span>';
|
|
}
|
|
for (i in flist) {
|
|
f = flist[i]
|
|
if (f == "." || f == "..")
|
|
continue;
|
|
if (current_file == f) {
|
|
html += ' | <b>' + f + '</b>';
|
|
} else {
|
|
html += ' | <span onclick="open_file(\'' + f + '\')">' + f + '</span>';
|
|
}
|
|
}
|
|
html += ' | <span onclick="open_file(prompt(\'Filename:\'))">new file</span> ]</tt>';
|
|
document.getElementById('tabs').innerHTML = html;
|
|
if (current_file == "") {
|
|
document.getElementById('output').readOnly = true;
|
|
document.getElementById('command').focus();
|
|
} else {
|
|
document.getElementById('output').readOnly = false;
|
|
document.getElementById('output').focus();
|
|
}
|
|
}
|
|
|
|
function open_file(filename)
|
|
{
|
|
if (current_file == "")
|
|
console_messages = document.getElementById('output').value;
|
|
else
|
|
FS.writeFile(current_file, document.getElementById('output').value, {encoding: 'utf8'});
|
|
|
|
if (filename == "") {
|
|
document.getElementById('output').value = console_messages;
|
|
} else {
|
|
try {
|
|
document.getElementById('output').value = FS.readFile(filename, {encoding: 'utf8'});
|
|
} catch (e) {
|
|
document.getElementById('output').value = "";
|
|
FS.writeFile(filename, document.getElementById('output').value, {encoding: 'utf8'});
|
|
}
|
|
}
|
|
|
|
current_file = filename;
|
|
update_tabs()
|
|
}
|
|
|
|
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();
|
|
FS.mkdir('/work')
|
|
FS.chdir('/work')
|
|
update_tabs();
|
|
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 = '';
|
|
|
|
open_file('');
|
|
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();
|
|
update_tabs();
|
|
}
|
|
|
|
window.setTimeout(run_command_bh, 50);
|
|
return false;
|
|
}
|
|
</script>
|
|
<script async type="text/javascript" src="yosys.js"></script>
|
|
</body></html>
|