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
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
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";
return 0;
}
+#endif /* EMSCRIPTEN */
+
--- /dev/null
+<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> </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>