summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile11
-rw-r--r--kernel/driver.cc28
-rw-r--r--misc/yosys.html60
-rw-r--r--passes/techmap/Makefile.inc2
5 files changed, 99 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 841b0ffa..f48aeac5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,13 +13,13 @@
/abc
/yosys
/yosys.exe
+/yosys.js
/yosys.html
/yosys-abc
/yosys-abc.exe
/yosys-config
/yosys-filterlib
/yosys-filterlib.exe
-/yosys-filterlib.html
/kernel/version_*.cc
/share
/libyosys
diff --git a/Makefile b/Makefile
index 502d2c20..775fce1a 100644
--- a/Makefile
+++ b/Makefile
@@ -95,9 +95,10 @@ CXXFLAGS += -std=gnu++0x -Os
else ifeq ($(CONFIG),emcc)
CXX = emcc
-CXXFLAGS := -std=c++11 $(filter-out -ggdb,$(CXXFLAGS))
+CXXFLAGS := -std=c++11 $(filter-out -fPIC,$(filter-out -ggdb,$(CXXFLAGS)))
EMCCFLAGS := -Os -Wno-warn-absolute-paths
-EMCCFLAGS += --memory-init-file 0
+EMCCFLAGS += --memory-init-file 0 -s NO_EXIT_RUNTIME=1
+EMCCFLAGS += -s EXPORTED_FUNCTIONS="['_main','_run','_prompt']"
# https://github.com/kripken/emscripten/blob/master/src/settings.js
# EMCCFLAGS += -s ALLOW_MEMORY_GROWTH=1
# EMCCFLAGS += -s DISABLE_EXCEPTION_CATCHING=0
@@ -108,7 +109,11 @@ EMCCFLAGS += --memory-init-file 0
CXXFLAGS += $(EMCCFLAGS)
LDFLAGS += $(EMCCFLAGS)
LDLIBS =
-EXE = .html
+EXE = .js
+
+EXTRA_TARGETS += yosys.html
+yosys.html: misc/yosys.html
+ $(P) cp misc/yosys.html yosys.html
else ifeq ($(CONFIG),mxe)
CXX = /usr/local/src/mxe/usr/bin/i686-pc-mingw32-gcc
diff --git a/kernel/driver.cc b/kernel/driver.cc
index 116df542..6df7cf2e 100644
--- a/kernel/driver.cc
+++ b/kernel/driver.cc
@@ -72,6 +72,32 @@ int getopt(int argc, char **argv, const char *optstring)
USING_YOSYS_NAMESPACE
+#ifdef EMSCRIPTEN
+
+extern "C" int main(int, char**);
+extern "C" void run(const char*);
+extern "C" const char *prompt();
+
+int main(int, char**)
+{
+ log_files.push_back(stdout);
+ log_error_stderr = true;
+ yosys_banner();
+ yosys_setup();
+}
+
+void run(const char *command)
+{
+ run_pass(command);
+}
+
+const char *prompt()
+{
+ return create_prompt(yosys_get_design(), 0);
+}
+
+#else /* EMSCRIPTEN */
+
int main(int argc, char **argv)
{
std::string frontend_command = "auto";
@@ -440,3 +466,5 @@ int main(int argc, char **argv)
return 0;
}
+#endif /* EMSCRIPTEN */
+
diff --git a/misc/yosys.html b/misc/yosys.html
new file mode 100644
index 00000000..c82bc187
--- /dev/null
+++ b/misc/yosys.html
@@ -0,0 +1,60 @@
+<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">Loading...</textarea></div>
+ <div><form onsubmit="return run_command()"><tt><span id="prompt"><br/>yosys&gt; </span></tt><input id="command" type="text" 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) {
+ 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
+ }
+ }
+ };
+ })(),
+ command: (function(cmd) {
+ Module.ccall('run', '', ['string'], [cmd])
+ }),
+ prompt: (function(cmd) {
+ return Module.ccall('prompt', 'string', [], [])
+ })
+ };
+ function run_command() {
+ var cmd = document.getElementById('command').value;
+ document.getElementById('command').value = '';
+ Module.print(Module.prompt() + cmd);
+ try {
+ Module.command(cmd);
+ } catch (e) {
+ Module.print('Caught JavaScript exception. (see JavaScript console for details.)');
+ console.log(e);
+ }
+ document.getElementById('command').focus();
+ document.getElementById('prompt').innerText = Module.prompt();
+ return false;
+ }
+ </script>
+ <script async type="text/javascript" src="yosys.js"></script>
+ </body>
+</html>
diff --git a/passes/techmap/Makefile.inc b/passes/techmap/Makefile.inc
index d8a43316..6b6846e2 100644
--- a/passes/techmap/Makefile.inc
+++ b/passes/techmap/Makefile.inc
@@ -24,9 +24,11 @@ passes/techmap/techmap.inc: techlibs/common/techmap.v
passes/techmap/techmap.o: passes/techmap/techmap.inc
+ifneq ($(CONFIG),emcc)
TARGETS += yosys-filterlib$(EXE)
EXTRA_OBJS += passes/techmap/filterlib.o
yosys-filterlib$(EXE): passes/techmap/filterlib.o
$(P) $(CXX) -o yosys-filterlib$(EXE) $(LDFLAGS) $^ $(LDLIBS)
+endif