From 3bee3cfeadcb57833a90c7789333750676f39e81 Mon Sep 17 00:00:00 2001 From: Robert Ou Date: Wed, 15 Nov 2017 03:14:14 -0800 Subject: Mount NODEFS if using emscripten and nodejs Mounts root directory on `/hostfs` and the current working directory on `/hostcwd` --- icebram/icebram.cc | 16 ++++++++++++++++ icemulti/icemulti.cc | 16 ++++++++++++++++ icepack/icepack.cc | 16 ++++++++++++++++ icepll/icepll.cc | 16 ++++++++++++++++ icetime/icetime.cc | 16 ++++++++++++++++ 5 files changed, 80 insertions(+) diff --git a/icebram/icebram.cc b/icebram/icebram.cc index 245a0ab..a796f92 100644 --- a/icebram/icebram.cc +++ b/icebram/icebram.cc @@ -28,6 +28,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + using std::map; using std::pair; using std::vector; @@ -109,6 +113,18 @@ void help(const char *cmd) int main(int argc, char **argv) { +#ifdef __EMSCRIPTEN__ + EM_ASM( + if (ENVIRONMENT_IS_NODE) + { + FS.mkdir('/hostcwd'); + FS.mount(NODEFS, { root: '.' }, '/hostcwd'); + FS.mkdir('/hostfs'); + FS.mount(NODEFS, { root: '/' }, '/hostfs'); + } + ); +#endif + bool verbose = false; bool generate = false; diff --git a/icemulti/icemulti.cc b/icemulti/icemulti.cc index 65ae6b6..4bc0919 100644 --- a/icemulti/icemulti.cc +++ b/icemulti/icemulti.cc @@ -24,6 +24,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + #define log(...) fprintf(stderr, __VA_ARGS__); #define error(...) do { fprintf(stderr, "%s: ", program_short_name); fprintf(stderr, __VA_ARGS__); exit(EXIT_FAILURE); } while (0) @@ -178,6 +182,18 @@ void usage() int main(int argc, char **argv) { +#ifdef __EMSCRIPTEN__ + EM_ASM( + if (ENVIRONMENT_IS_NODE) + { + FS.mkdir('/hostcwd'); + FS.mount(NODEFS, { root: '.' }, '/hostcwd'); + FS.mkdir('/hostfs'); + FS.mount(NODEFS, { root: '/' }, '/hostfs'); + } + ); +#endif + int c; char *endptr = NULL; bool coldboot = false; diff --git a/icepack/icepack.cc b/icepack/icepack.cc index d845ba7..3029c25 100644 --- a/icepack/icepack.cc +++ b/icepack/icepack.cc @@ -34,6 +34,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + #ifdef _WIN32 #define __PRETTY_FUNCTION__ __FUNCTION__ #endif @@ -1338,6 +1342,18 @@ void usage() int main(int argc, char **argv) { +#ifdef __EMSCRIPTEN__ + EM_ASM( + if (ENVIRONMENT_IS_NODE) + { + FS.mkdir('/hostcwd'); + FS.mount(NODEFS, { root: '.' }, '/hostcwd'); + FS.mkdir('/hostfs'); + FS.mount(NODEFS, { root: '/' }, '/hostfs'); + } + ); +#endif + vector parameters; bool unpack_mode = false; bool nosleep_mode = false; diff --git a/icepll/icepll.cc b/icepll/icepll.cc index b123f32..82bf3e3 100644 --- a/icepll/icepll.cc +++ b/icepll/icepll.cc @@ -20,6 +20,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + const char *binstr(int v, int n) { static char buffer[16]; @@ -63,6 +67,18 @@ void help(const char *cmd) int main(int argc, char **argv) { +#ifdef __EMSCRIPTEN__ + EM_ASM( + if (ENVIRONMENT_IS_NODE) + { + FS.mkdir('/hostcwd'); + FS.mount(NODEFS, { root: '.' }, '/hostcwd'); + FS.mkdir('/hostfs'); + FS.mount(NODEFS, { root: '/' }, '/hostfs'); + } + ); +#endif + double f_pllin = 12; double f_pllout = 60; bool simple_feedback = true; diff --git a/icetime/icetime.cc b/icetime/icetime.cc index 0b7cea2..f9e0994 100644 --- a/icetime/icetime.cc +++ b/icetime/icetime.cc @@ -33,6 +33,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + // add this number of ns as estimate for clock distribution mismatch #define GLOBAL_CLK_DIST_JITTER 0.1 @@ -2223,6 +2227,18 @@ void help(const char *cmd) int main(int argc, char **argv) { +#ifdef __EMSCRIPTEN__ + EM_ASM( + if (ENVIRONMENT_IS_NODE) + { + FS.mkdir('/hostcwd'); + FS.mount(NODEFS, { root: '.' }, '/hostcwd'); + FS.mkdir('/hostfs'); + FS.mount(NODEFS, { root: '/' }, '/hostfs'); + } + ); +#endif + bool listnets = false; bool print_timing = false; bool interior_timing = false; -- cgit v1.2.3