Mount NODEFS if using emscripten and nodejs

Mounts root directory on `/hostfs` and the current working directory on
`/hostcwd`
This commit is contained in:
Robert Ou 2017-11-15 03:14:14 -08:00
parent 9b0603c4bc
commit 3bee3cfead
5 changed files with 80 additions and 0 deletions

View File

@ -28,6 +28,10 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
using std::map; using std::map;
using std::pair; using std::pair;
using std::vector; using std::vector;
@ -109,6 +113,18 @@ void help(const char *cmd)
int main(int argc, char **argv) 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 verbose = false;
bool generate = false; bool generate = false;

View File

@ -24,6 +24,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#define log(...) fprintf(stderr, __VA_ARGS__); #define log(...) fprintf(stderr, __VA_ARGS__);
#define error(...) do { fprintf(stderr, "%s: ", program_short_name); fprintf(stderr, __VA_ARGS__); exit(EXIT_FAILURE); } while (0) #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) 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; int c;
char *endptr = NULL; char *endptr = NULL;
bool coldboot = false; bool coldboot = false;

View File

@ -34,6 +34,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#ifdef _WIN32 #ifdef _WIN32
#define __PRETTY_FUNCTION__ __FUNCTION__ #define __PRETTY_FUNCTION__ __FUNCTION__
#endif #endif
@ -1338,6 +1342,18 @@ void usage()
int main(int argc, char **argv) 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<string> parameters; vector<string> parameters;
bool unpack_mode = false; bool unpack_mode = false;
bool nosleep_mode = false; bool nosleep_mode = false;

View File

@ -20,6 +20,10 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
const char *binstr(int v, int n) const char *binstr(int v, int n)
{ {
static char buffer[16]; static char buffer[16];
@ -63,6 +67,18 @@ void help(const char *cmd)
int main(int argc, char **argv) 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_pllin = 12;
double f_pllout = 60; double f_pllout = 60;
bool simple_feedback = true; bool simple_feedback = true;

View File

@ -33,6 +33,10 @@
#include <map> #include <map>
#include <set> #include <set>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
// add this number of ns as estimate for clock distribution mismatch // add this number of ns as estimate for clock distribution mismatch
#define GLOBAL_CLK_DIST_JITTER 0.1 #define GLOBAL_CLK_DIST_JITTER 0.1
@ -2223,6 +2227,18 @@ void help(const char *cmd)
int main(int argc, char **argv) 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 listnets = false;
bool print_timing = false; bool print_timing = false;
bool interior_timing = false; bool interior_timing = false;