mirror of
https://github.com/YosysHQ/yosys
synced 2026-06-07 09:30:55 +00:00
commit
017c99be5b
16 changed files with 6 additions and 962 deletions
|
|
@ -1,12 +0,0 @@
|
||||||
.editorconfig
|
|
||||||
.gitignore
|
|
||||||
.gitmodules
|
|
||||||
.github
|
|
||||||
.git
|
|
||||||
Dockerfile
|
|
||||||
README.md
|
|
||||||
manual
|
|
||||||
guidelines
|
|
||||||
CodeOfConduct
|
|
||||||
.travis
|
|
||||||
.travis.yml
|
|
||||||
|
|
@ -1079,11 +1079,7 @@ RTLIL::Const AstNode::realAsConst(int width)
|
||||||
{
|
{
|
||||||
double v = round(realvalue);
|
double v = round(realvalue);
|
||||||
RTLIL::Const result;
|
RTLIL::Const result;
|
||||||
#ifdef EMSCRIPTEN
|
|
||||||
if (!isfinite(v)) {
|
|
||||||
#else
|
|
||||||
if (!std::isfinite(v)) {
|
if (!std::isfinite(v)) {
|
||||||
#endif
|
|
||||||
result = std::vector<RTLIL::State>(width, RTLIL::State::Sx);
|
result = std::vector<RTLIL::State>(width, RTLIL::State::Sx);
|
||||||
} else {
|
} else {
|
||||||
bool is_negative = v < 0;
|
bool is_negative = v < 0;
|
||||||
|
|
|
||||||
|
|
@ -4621,11 +4621,7 @@ struct ReadPass : public Pass {
|
||||||
if (use_verific) {
|
if (use_verific) {
|
||||||
args[0] = "verific";
|
args[0] = "verific";
|
||||||
} else {
|
} else {
|
||||||
#if !defined(__wasm)
|
|
||||||
args[0] = "read_verilog_file_list";
|
args[0] = "read_verilog_file_list";
|
||||||
#else
|
|
||||||
cmd_error(args, 1, "Command files are not supported on this platform.\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
Pass::call(design, args);
|
Pass::call(design, args);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(__wasm)
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "verilog_frontend.h"
|
#include "verilog_frontend.h"
|
||||||
#include "verilog_lexer.h"
|
#include "verilog_lexer.h"
|
||||||
|
|
@ -709,8 +707,6 @@ struct VerilogDefines : public Pass {
|
||||||
}
|
}
|
||||||
} VerilogDefines;
|
} VerilogDefines;
|
||||||
|
|
||||||
#if !defined(__wasm)
|
|
||||||
|
|
||||||
static void parse_file_list(const std::string &file_list_path, RTLIL::Design *design, bool relative_to_file_list_path)
|
static void parse_file_list(const std::string &file_list_path, RTLIL::Design *design, bool relative_to_file_list_path)
|
||||||
{
|
{
|
||||||
std::ifstream flist(file_list_path);
|
std::ifstream flist(file_list_path);
|
||||||
|
|
@ -790,6 +786,4 @@ struct VerilogFileList : public Pass {
|
||||||
}
|
}
|
||||||
} VerilogFilelist;
|
} VerilogFilelist;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
YOSYS_NAMESPACE_END
|
YOSYS_NAMESPACE_END
|
||||||
|
|
|
||||||
|
|
@ -70,75 +70,6 @@ namespace py = pybind11;
|
||||||
|
|
||||||
USING_YOSYS_NAMESPACE
|
USING_YOSYS_NAMESPACE
|
||||||
|
|
||||||
#ifdef EMSCRIPTEN
|
|
||||||
# include <sys/stat.h>
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <emscripten.h>
|
|
||||||
|
|
||||||
extern "C" int main(int, char**);
|
|
||||||
extern "C" void run(const char*);
|
|
||||||
extern "C" const char *errmsg();
|
|
||||||
extern "C" const char *prompt();
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
EM_ASM(
|
|
||||||
if (ENVIRONMENT_IS_NODE)
|
|
||||||
{
|
|
||||||
FS.mkdir('/hostcwd');
|
|
||||||
FS.mount(NODEFS, { root: '.' }, '/hostcwd');
|
|
||||||
FS.mkdir('/hostfs');
|
|
||||||
FS.mount(NODEFS, { root: '/' }, '/hostfs');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
mkdir("/work", 0777);
|
|
||||||
chdir("/work");
|
|
||||||
log_files.push_back(stdout);
|
|
||||||
log_error_stderr = true;
|
|
||||||
yosys_banner();
|
|
||||||
yosys_setup();
|
|
||||||
#ifdef YOSYS_ENABLE_PYTHON
|
|
||||||
py::object sys = py::module_::import("sys");
|
|
||||||
sys.attr("path").attr("append")(proc_self_dirname());
|
|
||||||
sys.attr("path").attr("append")(proc_share_dirname());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc == 2)
|
|
||||||
{
|
|
||||||
// Run the first argument as a script file
|
|
||||||
run_frontend(argv[1], "script");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void run(const char *command)
|
|
||||||
{
|
|
||||||
int selSize = GetSize(yosys_get_design()->selection_stack);
|
|
||||||
try {
|
|
||||||
log_last_error = "Internal error (see JavaScript console for details)";
|
|
||||||
run_pass(command);
|
|
||||||
log_last_error = "";
|
|
||||||
} catch (...) {
|
|
||||||
while (GetSize(yosys_get_design()->selection_stack) > selSize)
|
|
||||||
yosys_get_design()->pop_selection();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *errmsg()
|
|
||||||
{
|
|
||||||
return log_last_error.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *prompt()
|
|
||||||
{
|
|
||||||
const char *p = create_prompt(yosys_get_design(), 0);
|
|
||||||
while (*p == '\n') p++;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* EMSCRIPTEN */
|
|
||||||
|
|
||||||
#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
|
#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
|
||||||
int yosys_history_offset = 0;
|
int yosys_history_offset = 0;
|
||||||
std::string yosys_history_file;
|
std::string yosys_history_file;
|
||||||
|
|
@ -781,5 +712,3 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* EMSCRIPTEN */
|
|
||||||
|
|
|
||||||
|
|
@ -335,9 +335,6 @@ void log_suppressed() {
|
||||||
[[noreturn]]
|
[[noreturn]]
|
||||||
static void log_error_with_prefix(std::string_view prefix, std::string str)
|
static void log_error_with_prefix(std::string_view prefix, std::string str)
|
||||||
{
|
{
|
||||||
#ifdef EMSCRIPTEN
|
|
||||||
auto backup_log_files = log_files;
|
|
||||||
#endif
|
|
||||||
int bak_log_make_debug = log_make_debug;
|
int bak_log_make_debug = log_make_debug;
|
||||||
log_make_debug = 0;
|
log_make_debug = 0;
|
||||||
log_suppressed();
|
log_suppressed();
|
||||||
|
|
@ -378,10 +375,7 @@ static void log_error_with_prefix(std::string_view prefix, std::string str)
|
||||||
if (e && atoi(e))
|
if (e && atoi(e))
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
#ifdef EMSCRIPTEN
|
#if defined(_MSC_VER)
|
||||||
log_files = backup_log_files;
|
|
||||||
throw 0;
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
#else
|
#else
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
|
|
@ -679,9 +673,7 @@ void log_check_expected()
|
||||||
log_warn_regexes.clear();
|
log_warn_regexes.clear();
|
||||||
log("Expected %s pattern '%s' found !!!\n", kind, pattern);
|
log("Expected %s pattern '%s' found !!!\n", kind, pattern);
|
||||||
yosys_shutdown();
|
yosys_shutdown();
|
||||||
#ifdef EMSCRIPTEN
|
#if defined(_MSC_VER)
|
||||||
throw 0;
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
_exit(0);
|
_exit(0);
|
||||||
#else
|
#else
|
||||||
_Exit(0);
|
_Exit(0);
|
||||||
|
|
|
||||||
|
|
@ -550,7 +550,7 @@ std::string proc_self_dirname()
|
||||||
shortpath[--i] = 0;
|
shortpath[--i] = 0;
|
||||||
return shortpath;
|
return shortpath;
|
||||||
}
|
}
|
||||||
#elif defined(EMSCRIPTEN) || defined(__wasm)
|
#elif defined(__wasm)
|
||||||
std::string proc_self_dirname()
|
std::string proc_self_dirname()
|
||||||
{
|
{
|
||||||
return "/";
|
return "/";
|
||||||
|
|
@ -588,7 +588,7 @@ std::string proc_self_dirname(void)
|
||||||
#error "Don't know how to determine process executable base path!"
|
#error "Don't know how to determine process executable base path!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(EMSCRIPTEN) || defined(__wasm)
|
#if defined(__wasm)
|
||||||
void init_share_dirname()
|
void init_share_dirname()
|
||||||
{
|
{
|
||||||
yosys_share_dirname = "/share/";
|
yosys_share_dirname = "/share/";
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
mv config.h config.h.bak
|
mv config.h config.h.bak
|
||||||
rm -f *.txt *.cc *.h
|
rm -f *.txt *.cc *.h
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
rm -f LICENSE *.cc *.h
|
rm -f LICENSE *.cc *.h
|
||||||
git clone --depth 1 https://github.com/niklasso/minisat minisat_upstream
|
git clone --depth 1 https://github.com/niklasso/minisat minisat_upstream
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
vcxsrc="$1"
|
|
||||||
yosysver="$2"
|
|
||||||
|
|
||||||
rm -rf YosysVS-Tpl-v2.zip YosysVS
|
|
||||||
wget https://github.com/YosysHQ/yosys/releases/download/resources/YosysVS-Tpl-v2.zip
|
|
||||||
wget https://github.com/YosysHQ/yosys/releases/download/resources/zlib-1.2.11.tar.gz
|
|
||||||
|
|
||||||
unzip YosysVS-Tpl-v2.zip
|
|
||||||
rm -f YosysVS-Tpl-v2.zip
|
|
||||||
tar xvfz zlib-1.2.11.tar.gz
|
|
||||||
|
|
||||||
mv YosysVS "$vcxsrc"
|
|
||||||
mkdir -p "$vcxsrc"/yosys
|
|
||||||
mkdir -p "$vcxsrc"/yosys/libs/zlib
|
|
||||||
mv zlib-1.2.11/* "$vcxsrc"/yosys/libs/zlib/.
|
|
||||||
rm -rf zlib-1.2.11
|
|
||||||
pushd "$vcxsrc"/yosys
|
|
||||||
ls libs/zlib/*.c | sed 's,.*:,,; s,//*,/,g; s,/[^/]*/\.\./,/,g; y, \\,\n\n,;' | grep '^[^/]' >> ../../srcfiles.txt
|
|
||||||
|
|
||||||
if [ -f "/usr/include/FlexLexer.h" ] ; then
|
|
||||||
mkdir -p libs/flex
|
|
||||||
cp /usr/include/FlexLexer.h libs/flex/FlexLexer.h
|
|
||||||
ls libs/flex/*.h >> ../../srcfiles.txt
|
|
||||||
fi
|
|
||||||
sed -i '\#libs/../kernel/yosys.h#d' ../../srcfiles.txt
|
|
||||||
|
|
||||||
popd
|
|
||||||
{
|
|
||||||
n=$(grep -B999 '<ItemGroup>' "$vcxsrc"/YosysVS/YosysVS.vcxproj | wc -l)
|
|
||||||
head -n$n "$vcxsrc"/YosysVS/YosysVS.vcxproj
|
|
||||||
egrep '\.(h|hh|hpp|inc)$' srcfiles.txt | sed 's,.*,<ClInclude Include="../yosys/&" />,'
|
|
||||||
egrep -v '\.(h|hh|hpp|inc)$' srcfiles.txt | sed 's,.*,<ClCompile Include="../yosys/&" />,'
|
|
||||||
tail -n +$((n+1)) "$vcxsrc"/YosysVS/YosysVS.vcxproj
|
|
||||||
} > "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
|
||||||
|
|
||||||
sed -i 's,</AdditionalIncludeDirectories>,</AdditionalIncludeDirectories>\n <LanguageStandard>stdcpp20</LanguageStandard>\n <AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
|
||||||
sed -i 's,<PreprocessorDefinitions>,<PreprocessorDefinitions>YOSYS_ENABLE_THREADS;,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
|
||||||
if [ -f "/usr/include/FlexLexer.h" ] ; then
|
|
||||||
sed -i 's,</AdditionalIncludeDirectories>,;..\\yosys\\libs\\flex</AdditionalIncludeDirectories>,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new
|
|
||||||
fi
|
|
||||||
mv "$vcxsrc"/YosysVS/YosysVS.vcxproj.new "$vcxsrc"/YosysVS/YosysVS.vcxproj
|
|
||||||
|
|
||||||
mkdir -p "$vcxsrc"/yosys
|
|
||||||
tar -cf - -T srcfiles.txt | tar -xf - -C "$vcxsrc"/yosys
|
|
||||||
cp -r share "$vcxsrc"/
|
|
||||||
|
|
||||||
cat > "$vcxsrc"/readme-git.txt << EOT
|
|
||||||
Want to use a git working copy for the yosys source code?
|
|
||||||
Open "Git Bash" in this directory and run:
|
|
||||||
|
|
||||||
mv yosys yosys.bak
|
|
||||||
git clone https://github.com/YosysHQ/yosys.git yosys
|
|
||||||
cd yosys
|
|
||||||
git checkout -B main $(git rev-parse HEAD | cut -c1-10)
|
|
||||||
unzip ../genfiles.zip
|
|
||||||
EOT
|
|
||||||
|
|
||||||
cat > "$vcxsrc"/readme-abc.txt << EOT
|
|
||||||
Yosys is using "ABC" for gate-level optimizations and technology
|
|
||||||
mapping. Download yosys-win32-mxebin-$yosysver.zip and copy the
|
|
||||||
following files from it into this directory:
|
|
||||||
|
|
||||||
pthreadVC2.dll
|
|
||||||
yosys-abc.exe
|
|
||||||
EOT
|
|
||||||
|
|
||||||
sed -i 's/$/\r/; s/\r\r*/\r/g;' "$vcxsrc"/YosysVS/YosysVS.vcxproj "$vcxsrc"/readme-git.txt "$vcxsrc"/readme-abc.txt
|
|
||||||
|
|
||||||
|
|
@ -1,197 +0,0 @@
|
||||||
<html><head>
|
|
||||||
<title>YosysJS Example Application #01</title>
|
|
||||||
<script type="text/javascript" src="yosysjs.js"></script>
|
|
||||||
</head><body onload="document.getElementById('command').focus()">
|
|
||||||
<h1>YosysJS Example Application #01</h1>
|
|
||||||
<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>
|
|
||||||
<svg id="svg" style="display: none; position: absolute; padding: 10px; width: calc(100% - 40px); height: 480px;"></svg>
|
|
||||||
<div><textarea id="output" style="width: 100%; height: 500px"></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"><br/><tt><span id="prompt">
|
|
||||||
</span></tt><input id="command" type="text" onkeydown="history(event)" style="font-family: monospace; font-weight: bold;" size="100"></form></div>
|
|
||||||
<script type='text/javascript'>
|
|
||||||
function print_output(text) {
|
|
||||||
var el = document.getElementById('output');
|
|
||||||
el.value += text + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
YosysJS.load_viz();
|
|
||||||
var ys = YosysJS.create("", function() {
|
|
||||||
print_output(ys.print_buffer);
|
|
||||||
|
|
||||||
document.getElementById('wait').style.display = 'none';
|
|
||||||
document.getElementById('input').style.display = 'block';
|
|
||||||
document.getElementById('waitmsg').textContent = 'Waiting for yosys.js...';
|
|
||||||
document.getElementById('prompt').textContent = ys.prompt();
|
|
||||||
|
|
||||||
update_tabs();
|
|
||||||
});
|
|
||||||
|
|
||||||
ys.echo = true;
|
|
||||||
|
|
||||||
var history_log = [];
|
|
||||||
var history_index = 0;
|
|
||||||
var history_bak = "";
|
|
||||||
|
|
||||||
function history(ev) {
|
|
||||||
if (ev.keyCode == 38) {
|
|
||||||
el = document.getElementById('command');
|
|
||||||
if (history_index == history_log.length)
|
|
||||||
history_bak = el.value
|
|
||||||
if (history_index > 0)
|
|
||||||
el.value = history_log[--history_index];
|
|
||||||
}
|
|
||||||
if (ev.keyCode == 40) {
|
|
||||||
if (history_index < history_log.length) {
|
|
||||||
el = document.getElementById('command');
|
|
||||||
if (++history_index < history_log.length)
|
|
||||||
el.value = history_log[history_index];
|
|
||||||
else
|
|
||||||
el.value = history_bak;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var current_file = "";
|
|
||||||
var console_messages = "";
|
|
||||||
var svg_cache = { };
|
|
||||||
|
|
||||||
function update_tabs() {
|
|
||||||
var f, html = "", flist = ys.read_dir('.');
|
|
||||||
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 == "" || /\.dot$/.test(current_file)) {
|
|
||||||
var element = document.getElementById('output');
|
|
||||||
element.readOnly = true;
|
|
||||||
element.scrollTop = element.scrollHeight; // focus on bottom
|
|
||||||
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 if (!/\.dot$/.test(current_file))
|
|
||||||
ys.write_file(current_file, document.getElementById('output').value);
|
|
||||||
|
|
||||||
if (filename == "") {
|
|
||||||
document.getElementById('output').value = console_messages;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
document.getElementById('output').value = ys.read_file(filename);
|
|
||||||
} catch (e) {
|
|
||||||
document.getElementById('output').value = "";
|
|
||||||
ys.write_file(filename, document.getElementById('output').value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (/\.dot$/.test(filename)) {
|
|
||||||
dot = document.getElementById('output').value;
|
|
||||||
YosysJS.dot_into_svg(dot, 'svg');
|
|
||||||
document.getElementById('svg').style.display = 'block';
|
|
||||||
document.getElementById('output').value = '';
|
|
||||||
} else {
|
|
||||||
document.getElementById('svg').innerHTML = '';
|
|
||||||
document.getElementById('svg').style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
current_file = filename;
|
|
||||||
update_tabs()
|
|
||||||
}
|
|
||||||
|
|
||||||
function startup() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function load_example() {
|
|
||||||
open_file('')
|
|
||||||
|
|
||||||
var txt = "";
|
|
||||||
txt += "// a simple yosys.js example. run \"script example.ys\".\n";
|
|
||||||
txt += "\n";
|
|
||||||
txt += "module example(input clk, input rst, input inc, output reg [3:0] cnt);\n";
|
|
||||||
txt += " always @(posedge clk) begin\n";
|
|
||||||
txt += " if (rst)\n";
|
|
||||||
txt += " cnt <= 0;\n";
|
|
||||||
txt += " else if (inc)\n";
|
|
||||||
txt += " cnt <= cnt + 1;\n";
|
|
||||||
txt += " end\n";
|
|
||||||
txt += "endmodule\n";
|
|
||||||
txt += "\n";
|
|
||||||
ys.write_file('example.v', txt);
|
|
||||||
|
|
||||||
var txt = "";
|
|
||||||
txt += "# a simple yosys.js example. run \"script example.ys\".\n";
|
|
||||||
txt += "\n";
|
|
||||||
txt += "design -reset\n";
|
|
||||||
txt += "read_verilog example.v\n";
|
|
||||||
txt += "proc\n";
|
|
||||||
txt += "opt\n";
|
|
||||||
txt += "show\n";
|
|
||||||
txt += "\n";
|
|
||||||
ys.write_file('example.ys', txt);
|
|
||||||
|
|
||||||
open_file('example.ys')
|
|
||||||
document.getElementById('command').focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_command() {
|
|
||||||
var cmd = document.getElementById('command').value;
|
|
||||||
document.getElementById('command').value = '';
|
|
||||||
if (history_log.length == 0 || history_log[history_log.length-1] != cmd)
|
|
||||||
history_log.push(cmd);
|
|
||||||
history_index = history_log.length;
|
|
||||||
|
|
||||||
var show_dot_before = "";
|
|
||||||
try { show_dot_before = ys.read_file('show.dot'); } catch (e) { }
|
|
||||||
|
|
||||||
open_file('');
|
|
||||||
|
|
||||||
document.getElementById('wait').style.display = 'block';
|
|
||||||
document.getElementById('input').style.display = 'none';
|
|
||||||
|
|
||||||
function run_command_bh() {
|
|
||||||
try {
|
|
||||||
ys.run(cmd);
|
|
||||||
} catch (e) {
|
|
||||||
ys.write('Caught JavaScript exception. (see JavaScript console for details.)');
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
print_output(ys.print_buffer);
|
|
||||||
|
|
||||||
document.getElementById('wait').style.display = 'none';
|
|
||||||
document.getElementById('input').style.display = 'block';
|
|
||||||
document.getElementById('prompt').textContent = ys.prompt();
|
|
||||||
|
|
||||||
var show_dot_after = "";
|
|
||||||
try { show_dot_after = ys.read_file('show.dot'); } catch (e) { }
|
|
||||||
|
|
||||||
if (show_dot_before != show_dot_after)
|
|
||||||
open_file('show.dot');
|
|
||||||
|
|
||||||
update_tabs();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.setTimeout(run_command_bh, 50);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body></html>
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
<html><head>
|
|
||||||
<title>YosysJS Example Application #02</title>
|
|
||||||
<script type="text/javascript" src="yosysjs.js"></script>
|
|
||||||
</head><body>
|
|
||||||
<div id="popup" style="position: fixed; left: 0; top: 0; width:100%; height:100%; text-align:center; z-index: 1000;"><div
|
|
||||||
style="width:300px; margin: 200px auto; background-color: #88f; border:3px dashed #000;
|
|
||||||
padding:15px; text-align:center;"><span id="popupmsg">Loading...</span></div>
|
|
||||||
</div>
|
|
||||||
<h1>YosysJS Example Application #02</h1>
|
|
||||||
<textarea id="code" style="width: 800px; height: 300px;">
|
|
||||||
// borrowed with some modifications from
|
|
||||||
// http://www.ee.ed.ac.uk/~gerard/Teach/Verilog/manual/Example/lrgeEx2/cooley.html
|
|
||||||
module up3down5(clock, data_in, up, down, carry_out, borrow_out, count_out, parity_out);
|
|
||||||
|
|
||||||
input [8:0] data_in;
|
|
||||||
input clock, up, down;
|
|
||||||
|
|
||||||
output reg [8:0] count_out;
|
|
||||||
output reg carry_out, borrow_out, parity_out;
|
|
||||||
|
|
||||||
reg [9:0] cnt_up, cnt_dn;
|
|
||||||
reg [8:0] count_nxt;
|
|
||||||
|
|
||||||
always @(posedge clock)
|
|
||||||
begin
|
|
||||||
cnt_dn = count_out - 3'b 101;
|
|
||||||
cnt_up = count_out + 2'b 11;
|
|
||||||
|
|
||||||
case ({up,down})
|
|
||||||
2'b 00 : count_nxt = data_in;
|
|
||||||
2'b 01 : count_nxt = cnt_dn;
|
|
||||||
2'b 10 : count_nxt = cnt_up;
|
|
||||||
2'b 11 : count_nxt = count_out;
|
|
||||||
default : count_nxt = 9'bX;
|
|
||||||
endcase
|
|
||||||
|
|
||||||
parity_out <= ^count_nxt;
|
|
||||||
carry_out <= up & cnt_up[9];
|
|
||||||
borrow_out <= down & cnt_dn[9];
|
|
||||||
count_out <= count_nxt;
|
|
||||||
end
|
|
||||||
|
|
||||||
endmodule
|
|
||||||
</textarea><p/>
|
|
||||||
<input type="button" value="Before Behavioral Synth" onclick="synth1()">
|
|
||||||
<input type="button" value="After Behavioral Synth" onclick="synth2()">
|
|
||||||
<input type="button" value="After RTL Synth" onclick="synth3()">
|
|
||||||
<input type="button" value="After Gate-Level Synth" onclick="synth4()"><p/>
|
|
||||||
<svg id="svg" width="800"></svg>
|
|
||||||
</td></tr></table>
|
|
||||||
<script type="text/javascript">
|
|
||||||
YosysJS.load_viz();
|
|
||||||
function on_ys_ready() {
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
document.getElementById('popupmsg').textContent = 'Please wait..';
|
|
||||||
}
|
|
||||||
function handle_run_errors(logmsg, errmsg) {
|
|
||||||
if (errmsg != "") {
|
|
||||||
window.alert(errmsg);
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function synth1() {
|
|
||||||
document.getElementById('popup').style.visibility = 'visible';
|
|
||||||
ys.write_file("input.v", document.getElementById('code').value);
|
|
||||||
ys.run('design -reset; read_verilog input.v; show -stretch', handle_run_errors);
|
|
||||||
ys.read_file('show.dot', (function(text){
|
|
||||||
console.log(ys.errmsg);
|
|
||||||
if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg');
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
function synth2() {
|
|
||||||
document.getElementById('popup').style.visibility = 'visible';
|
|
||||||
ys.write_file("input.v", document.getElementById('code').value);
|
|
||||||
ys.run('design -reset; read_verilog input.v; proc; opt_clean; show -stretch', handle_run_errors);
|
|
||||||
ys.read_file('show.dot', (function(text){
|
|
||||||
if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg');
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
function synth3() {
|
|
||||||
document.getElementById('popup').style.visibility = 'visible';
|
|
||||||
ys.write_file("input.v", document.getElementById('code').value);
|
|
||||||
ys.run('design -reset; read_verilog input.v; synth -run coarse; show -stretch', handle_run_errors);
|
|
||||||
ys.read_file('show.dot', (function(text){
|
|
||||||
if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg');
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
function synth4() {
|
|
||||||
document.getElementById('popup').style.visibility = 'visible';
|
|
||||||
ys.write_file("input.v", document.getElementById('code').value);
|
|
||||||
ys.run('design -reset; read_verilog input.v; synth -run coarse; synth -run fine; show -stretch', handle_run_errors);
|
|
||||||
ys.read_file('show.dot', (function(text){
|
|
||||||
if (ys.errmsg == "") YosysJS.dot_into_svg(text, 'svg');
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
var ys = YosysJS.create_worker(on_ys_ready);
|
|
||||||
ys.verbose(true);
|
|
||||||
</script>
|
|
||||||
</body></html>
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
<html><head>
|
|
||||||
<title>YosysJS Example Application #02</title>
|
|
||||||
<script type="text/javascript" src="yosysjs.js"></script>
|
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/wavedrom/2.8.1/skins/default.min.js" ></script>
|
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/wavedrom/2.8.1/wavedrom.min.js"></script>
|
|
||||||
<style type="text/css">
|
|
||||||
.noedit { color: #666; }
|
|
||||||
</style>
|
|
||||||
<script id="golden_verilog" type="text/plain">
|
|
||||||
module ref(input clk, reset, input [7:0] A, output reg [7:0] Y);
|
|
||||||
always @(posedge clk) begin
|
|
||||||
if (reset)
|
|
||||||
Y <= 0;
|
|
||||||
else
|
|
||||||
Y <= ((Y << 5) + Y) ^ A;
|
|
||||||
end
|
|
||||||
endmodule
|
|
||||||
</script>
|
|
||||||
</head><body>
|
|
||||||
<div id="popup" style="position: fixed; left: 0; top: 0; width:100%; height:100%; text-align:center; z-index: 1000;
|
|
||||||
background-color: rgba(100, 100, 100, 0.5);"><div style="width:300px; margin: 200px auto; background-color: #88f;
|
|
||||||
border:3px dashed #000; padding:15px; text-align:center;"><span id="popupmsg">Loading...</span></div>
|
|
||||||
</div>
|
|
||||||
<h1>YosysJS Example Application #03</h1>
|
|
||||||
<b>Your mission:</b> Create a behavioral Verilog model for the following circuit:
|
|
||||||
<p/>
|
|
||||||
<div id="main" style="visibility: hidden">
|
|
||||||
<svg id="schem" width="800"></svg>
|
|
||||||
<p/>
|
|
||||||
<pre id="code" style="width: 800px; border:2px solid #000; padding: 0.5em;"><span class="noedit">module top(input clk, reset, input [7:0] A, output reg [7:0] Y);
|
|
||||||
always @(posedge clock) begin</span><span class="edit" contenteditable="true">
|
|
||||||
Y <= A | {4{reset}};
|
|
||||||
</span><span class="noedit">end
|
|
||||||
endmodule</span></pre><p/>
|
|
||||||
<input type="button" value="Check Model" onclick="check_model()"> <span id="checkmessage"></span>
|
|
||||||
<p/>
|
|
||||||
<p id="wave"> </p>
|
|
||||||
</div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
function on_ys_ready() {
|
|
||||||
ys.write_file('golden.v', document.getElementById('golden_verilog').textContent);
|
|
||||||
ys.run('echo on; read_verilog golden.v; proc;;');
|
|
||||||
ys.run('show -notitle -width -stretch');
|
|
||||||
YosysJS.dot_into_svg(ys.read_file('show.dot'), 'schem');
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
document.getElementById('popupmsg').textContent = 'Please wait..';
|
|
||||||
document.getElementById('main').style.visibility = 'visible';
|
|
||||||
}
|
|
||||||
function check_model() {
|
|
||||||
function work() {
|
|
||||||
ys.remove_file('wave.json');
|
|
||||||
ys.write_file('code.v', document.getElementById('code').textContent);
|
|
||||||
ys.errmsg = '';
|
|
||||||
ys.run('design -reset; read_verilog code.v; hierarchy -top top; proc; opt; flatten; hierarchy; ' +
|
|
||||||
'read_verilog golden.v; proc; miter -equiv -ignore_gold_x -make_outputs -flatten ref top miter; ' +
|
|
||||||
'hierarchy -top miter; clean -purge; sat -set-init-undef -seq 8 -dump_json wave.json -show-ports ' +
|
|
||||||
'-max_undef -prove trigger 0 miter');
|
|
||||||
w = document.getElementById('wave')
|
|
||||||
if (ys.errmsg) {
|
|
||||||
w.innerHTML = '<b><pre>ERROR: ' + ys.errmsg.replace('&', '&').replace('<', '<').replace('>', '>') + '</pre></b>';
|
|
||||||
} else {
|
|
||||||
wdata = ys.read_file('wave.json');
|
|
||||||
if (wdata) {
|
|
||||||
wdata = JSON.parse(wdata);
|
|
||||||
function wsignal(signame, newname) {
|
|
||||||
for (i = 0; i < wdata["signal"].length; i++)
|
|
||||||
if (wdata["signal"][i].name == signame) {
|
|
||||||
if (newname)
|
|
||||||
wdata["signal"][i].name = newname;
|
|
||||||
return wdata["signal"][i];
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
wdata2 = {
|
|
||||||
"signal" : [
|
|
||||||
{ name: 'clk', wave: 'P........' },
|
|
||||||
wsignal("trigger"),
|
|
||||||
{},
|
|
||||||
[ "Inputs", wsignal("in_reset", "reset"), wsignal("in_A", "A") ],
|
|
||||||
{},
|
|
||||||
[ "Y Output", wsignal("gold_Y", "Ref"), wsignal("gate_Y", "UUT") ],
|
|
||||||
],
|
|
||||||
"config" : wdata["config"]
|
|
||||||
};
|
|
||||||
wdata2 = JSON.stringify(wdata2)
|
|
||||||
w.innerHTML = '<b>The model did not pass verification:</b><p/>' +
|
|
||||||
'<script type="WaveDrom">' + wdata2 + '<\/script>';
|
|
||||||
WaveDrom.ProcessAll();
|
|
||||||
} else {
|
|
||||||
w.innerHTML = '<b>Congratulations! The model did pass verification.</b><p/>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
document.getElementById('popup').style.visibility = 'hidden';
|
|
||||||
}
|
|
||||||
document.getElementById('popup').style.visibility = 'visible';
|
|
||||||
window.setTimeout(work, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
YosysJS.load_viz();
|
|
||||||
var ys = YosysJS.create('', on_ys_ready);
|
|
||||||
ys.logprint = true;
|
|
||||||
</script>
|
|
||||||
</body></html>
|
|
||||||
|
|
@ -1,312 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
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": [] }]);
|
|
||||||
|
|
@ -158,7 +158,6 @@ struct ExecPass : public Pass {
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
#ifndef EMSCRIPTEN
|
|
||||||
FILE *f = popen(cmd.c_str(), "r");
|
FILE *f = popen(cmd.c_str(), "r");
|
||||||
if (f == nullptr)
|
if (f == nullptr)
|
||||||
log_cmd_error("errno %d after popen() returned NULL.\n", errno);
|
log_cmd_error("errno %d after popen() returned NULL.\n", errno);
|
||||||
|
|
@ -183,7 +182,6 @@ struct ExecPass : public Pass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status = pclose(f);
|
status = pclose(f);
|
||||||
#endif
|
|
||||||
|
|
||||||
if(WIFEXITED(status)) {
|
if(WIFEXITED(status)) {
|
||||||
retval = WEXITSTATUS(status);
|
retval = WEXITSTATUS(status);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue