diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-23 12:05:11 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-23 12:05:11 -0800 |
commit | dd48f32a130a4c45d7b2ca0df95f4a27cadd117e (patch) | |
tree | 422dd49879cb37e3d6e6be00f6b216a92406207f /src | |
parent | 253d42efc00510ce7a07e7ab05930ff93bd3c70d (diff) | |
download | binaryen-dd48f32a130a4c45d7b2ca0df95f4a27cadd117e.tar.gz binaryen-dd48f32a130a4c45d7b2ca0df95f4a27cadd117e.tar.bz2 binaryen-dd48f32a130a4c45d7b2ca0df95f4a27cadd117e.zip |
generalize commandline options and add global-base option for s2wasm
Diffstat (limited to 'src')
-rw-r--r-- | src/command-line.h | 21 | ||||
-rw-r--r-- | src/s2wasm-main.cpp | 12 | ||||
-rw-r--r-- | src/s2wasm.h | 6 |
3 files changed, 26 insertions, 13 deletions
diff --git a/src/command-line.h b/src/command-line.h index 63cf09d9f..4b8b12b4c 100644 --- a/src/command-line.h +++ b/src/command-line.h @@ -26,9 +26,12 @@ namespace wasm { struct Options { + // standard options bool debug; std::string infile; std::string outfile; + // extra options + std::map<std::string, const char*> extra; Options() : debug(false) {} }; @@ -37,17 +40,11 @@ bool optionIs(const char *arg, const char *LongOpt, const char *ShortOpt) { } // TODO(jfb) Make this configurable: callers should pass in option handlers. -void processCommandLine(int argc, const char *argv[], Options *options) { +void processCommandLine(int argc, const char *argv[], Options *options, const char *help) { assert(argc > 0 && "expect at least program name as an argument"); for (size_t i = 1, e = argc; i != e; ++i) { if (optionIs(argv[i], "--help", "-h")) { - std::cerr << "s2wasm INFILE\n\n" - "Link .s file into .wast\n\n" - "Optional arguments:\n" - " -n, --help Show this help message and exit\n" - " -d, --debug Print debug information to stderr\n" - " -o, --output Output file (stdout if not specified)\n" - << std::endl; + std::cerr << help; exit(EXIT_SUCCESS); } else if (optionIs(argv[i], "--debug", "-d")) { options->debug = true; @@ -62,6 +59,14 @@ void processCommandLine(int argc, const char *argv[], Options *options) { exit(EXIT_FAILURE); } options->outfile = argv[++i]; + } else if (argv[i][0] == '-' && argv[i][1] == '-') { + size_t j = 2; + std::string name; + while (argv[i][j] && argv[i][j] != '=') { + name += argv[i][j]; + j++; + } + options->extra[name] = argv[i][j] == '=' ? &argv[i][j+1] : "(no value)"; } else { if (options->infile.size()) { std::cerr << "Expected only one input file, got '" << options->infile diff --git a/src/s2wasm-main.cpp b/src/s2wasm-main.cpp index cb60d2a57..86a9737a7 100644 --- a/src/s2wasm-main.cpp +++ b/src/s2wasm-main.cpp @@ -26,7 +26,14 @@ using namespace wasm; int main(int argc, const char *argv[]) { Options options; - processCommandLine(argc, argv, &options); + processCommandLine(argc, argv, &options, + "s2wasm INFILE\n\n" + "Link .s file into .wast\n\n" + "Optional arguments:\n" + " -n, --help Show this help message and exit\n" + " -d, --debug Print debug information to stderr\n" + " -o, --output Output file (stdout if not specified)\n" + " --global-base=N Where to start to place globals\n"); std::string input; { @@ -62,7 +69,8 @@ int main(int argc, const char *argv[]) { if (options.debug) std::cerr << "Parsing and wasming..." << std::endl; AllocatingModule wasm; - S2WasmBuilder s2wasm(wasm, input.c_str(), options.debug); + size_t globalBase = options.extra["global-base"] ? atoi(options.extra["global-base"]) : 1; + S2WasmBuilder s2wasm(wasm, input.c_str(), options.debug, globalBase); if (options.debug) std::cerr << "Emscripten gluing..." << std::endl; std::stringstream meta; diff --git a/src/s2wasm.h b/src/s2wasm.h index b732464d9..467f912bf 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -40,8 +40,8 @@ class S2WasmBuilder { bool debug; public: - S2WasmBuilder(AllocatingModule& wasm, const char* input, bool debug) - : wasm(wasm), allocator(wasm.allocator), debug(debug) { + S2WasmBuilder(AllocatingModule& wasm, const char* input, bool debug, size_t nextStatic) + : wasm(wasm), allocator(wasm.allocator), debug(debug), nextStatic(nextStatic) { s = input; scan(); s = input; @@ -52,7 +52,7 @@ public: private: // state - size_t nextStatic = 1; // location of next static allocation, i.e., the data segment + size_t nextStatic; // location of next static allocation, i.e., the data segment std::map<Name, int32_t> staticAddresses; // name => address struct Addressing { |