More emscripten stuff, Added example app

This commit is contained in:
Clifford Wolf 2015-02-15 12:09:30 +01:00
parent 86819cc9f8
commit 3216f9420e
5 changed files with 99 additions and 4 deletions

2
.gitignore vendored
View File

@ -13,13 +13,13 @@
/abc /abc
/yosys /yosys
/yosys.exe /yosys.exe
/yosys.js
/yosys.html /yosys.html
/yosys-abc /yosys-abc
/yosys-abc.exe /yosys-abc.exe
/yosys-config /yosys-config
/yosys-filterlib /yosys-filterlib
/yosys-filterlib.exe /yosys-filterlib.exe
/yosys-filterlib.html
/kernel/version_*.cc /kernel/version_*.cc
/share /share
/libyosys /libyosys

View File

@ -95,9 +95,10 @@ CXXFLAGS += -std=gnu++0x -Os
else ifeq ($(CONFIG),emcc) else ifeq ($(CONFIG),emcc)
CXX = 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 := -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 # https://github.com/kripken/emscripten/blob/master/src/settings.js
# EMCCFLAGS += -s ALLOW_MEMORY_GROWTH=1 # EMCCFLAGS += -s ALLOW_MEMORY_GROWTH=1
# EMCCFLAGS += -s DISABLE_EXCEPTION_CATCHING=0 # EMCCFLAGS += -s DISABLE_EXCEPTION_CATCHING=0
@ -108,7 +109,11 @@ EMCCFLAGS += --memory-init-file 0
CXXFLAGS += $(EMCCFLAGS) CXXFLAGS += $(EMCCFLAGS)
LDFLAGS += $(EMCCFLAGS) LDFLAGS += $(EMCCFLAGS)
LDLIBS = 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) else ifeq ($(CONFIG),mxe)
CXX = /usr/local/src/mxe/usr/bin/i686-pc-mingw32-gcc CXX = /usr/local/src/mxe/usr/bin/i686-pc-mingw32-gcc

View File

@ -72,6 +72,32 @@ int getopt(int argc, char **argv, const char *optstring)
USING_YOSYS_NAMESPACE 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) int main(int argc, char **argv)
{ {
std::string frontend_command = "auto"; std::string frontend_command = "auto";
@ -440,3 +466,5 @@ int main(int argc, char **argv)
return 0; return 0;
} }
#endif /* EMSCRIPTEN */

60
misc/yosys.html Normal file
View File

@ -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>

View File

@ -24,9 +24,11 @@ passes/techmap/techmap.inc: techlibs/common/techmap.v
passes/techmap/techmap.o: passes/techmap/techmap.inc passes/techmap/techmap.o: passes/techmap/techmap.inc
ifneq ($(CONFIG),emcc)
TARGETS += yosys-filterlib$(EXE) TARGETS += yosys-filterlib$(EXE)
EXTRA_OBJS += passes/techmap/filterlib.o EXTRA_OBJS += passes/techmap/filterlib.o
yosys-filterlib$(EXE): passes/techmap/filterlib.o yosys-filterlib$(EXE): passes/techmap/filterlib.o
$(P) $(CXX) -o yosys-filterlib$(EXE) $(LDFLAGS) $^ $(LDLIBS) $(P) $(CXX) -o yosys-filterlib$(EXE) $(LDFLAGS) $^ $(LDLIBS)
endif