summaryrefslogtreecommitdiff
path: root/src/asm2wasm-main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/asm2wasm-main.cpp')
-rw-r--r--src/asm2wasm-main.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/asm2wasm-main.cpp b/src/asm2wasm-main.cpp
index aa914c168..56e8a417f 100644
--- a/src/asm2wasm-main.cpp
+++ b/src/asm2wasm-main.cpp
@@ -29,6 +29,9 @@ using namespace cashew;
using namespace wasm;
int main(int argc, const char *argv[]) {
+ bool opts = true;
+ bool imprecise = false;
+
Options options("asm2wasm", "Translate asm.js files to .wast files");
options
.add("--output", "-o", "Output file (stdout if not specified)",
@@ -41,6 +44,18 @@ int main(int argc, const char *argv[]) {
[](Options *o, const std::string &argument) {
o->extra["mapped globals"] = argument;
})
+ .add("--total-memory", "-m", "Total memory size", Options::Arguments::One,
+ [](Options *o, const std::string &argument) {
+ o->extra["total memory"] = argument;
+ })
+ .add("--no-opts", "-n", "Disable optimization passes", Options::Arguments::Zero,
+ [&opts](Options *o, const std::string &) {
+ opts = false;
+ })
+ .add("--imprecise", "-i", "Imprecise optimizations", Options::Arguments::Zero,
+ [&imprecise](Options *o, const std::string &) {
+ imprecise = true;
+ })
.add_positional("INFILE", Options::Arguments::One,
[](Options *o, const std::string &argument) {
o->extra["infile"] = argument;
@@ -51,6 +66,15 @@ int main(int argc, const char *argv[]) {
const char *mappedGlobals =
mg_it == options.extra.end() ? nullptr : mg_it->second.c_str();
+ const auto &tm_it = options.extra.find("total memory");
+ size_t totalMemory =
+ tm_it == options.extra.end() ? 16 * 1024 * 1024 : atoi(tm_it->second.c_str());
+ if (totalMemory & ~Memory::kPageMask) {
+ std::cerr << "Error: total memory size " << totalMemory <<
+ " is not a multiple of the 64k wasm page size\n";
+ exit(EXIT_FAILURE);
+ }
+
Asm2WasmPreProcessor pre;
auto input(
read_file<std::vector<char>>(options.extra["infile"], options.debug));
@@ -67,13 +91,14 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "wasming..." << std::endl;
AllocatingModule wasm;
- wasm.memory.initial = wasm.memory.max =
- 16 * 1024 * 1024; // we would normally receive this from the compiler
- Asm2WasmBuilder asm2wasm(wasm, pre.memoryGrowth, options.debug);
+ wasm.memory.initial = wasm.memory.max = totalMemory / Memory::kPageSize;
+ Asm2WasmBuilder asm2wasm(wasm, pre.memoryGrowth, options.debug, imprecise);
asm2wasm.processAsm(asmjs);
- if (options.debug) std::cerr << "optimizing..." << std::endl;
- asm2wasm.optimize();
+ if (opts) {
+ if (options.debug) std::cerr << "optimizing..." << std::endl;
+ asm2wasm.optimize();
+ }
if (options.debug) std::cerr << "printing..." << std::endl;
Output output(options.extra["output"], options.debug);