summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sexpr-wasm.c26
-rw-r--r--src/wasm-interp-sq.c6
-rw-r--r--src/wasm-interp.c22
-rw-r--r--src/wasm-option-parser.c10
-rw-r--r--src/wasm-option-parser.h1
-rw-r--r--src/wasm-wast.c12
6 files changed, 74 insertions, 3 deletions
diff --git a/src/sexpr-wasm.c b/src/sexpr-wasm.c
index 268e8848..2895f3a9 100644
--- a/src/sexpr-wasm.c
+++ b/src/sexpr-wasm.c
@@ -73,6 +73,25 @@ enum {
NUM_FLAGS
};
+static const char s_description[] =
+ " read a file in the wasm s-expression format, check it for errors, and\n"
+ " convert it to the wasm binary format.\n"
+ "\n"
+ "examples:\n"
+ " # parse and typecheck test.wast\n"
+ " $ sexpr-wasm test.wast\n"
+ "\n"
+ " # parse test.wast and write to binary file test.wasm\n"
+ " $ sexpr-wasm test.wast -o test.wasm\n"
+ "\n"
+ " # parse spec-test.wast, and write verbose output to stdout (including\n"
+ " # the meaning of every byte)\n"
+ " $ sexpr-wasm spec-test.wast -v\n"
+ "\n"
+ " # parse spec-test.wast, and write files to spec-test.json. Modules are\n"
+ " # written to spec-test.0.wasm, spec-test.1.wasm, etc.\n"
+ " $ sexpr-wasm spec-test.wast --spec -o spec-test.json\n";
+
static WasmOption s_options[] = {
{FLAG_VERBOSE, 'v', "verbose", NULL, NOPE,
"use multiple times for more info"},
@@ -82,13 +101,15 @@ static WasmOption s_options[] = {
{FLAG_OUTPUT, 'o', "output", "FILE", YEP,
"output file for the generated binary format"},
{FLAG_SPEC, 0, "spec", NULL, NOPE,
- "parse a file with multiple modules and assertions, like the spec tests"},
+ "parse a file with multiple modules and assertions, like the spec "
+ "tests"},
{FLAG_USE_LIBC_ALLOCATOR, 0, "use-libc-allocator", NULL, NOPE,
"use malloc, free, etc. instead of stack allocator"},
{FLAG_NO_CANONICALIZE_LEB128S, 0, "no-canonicalize-leb128s", NULL, NOPE,
"Write all LEB128 sizes as 5-bytes instead of their minimal size"},
{FLAG_NO_REMAP_LOCALS, 0, "no-remap-locals", NULL, NOPE,
- "If set, function locals are written in source order, instead of packing "
+ "If set, function locals are written in source order, instead of "
+ "packing "
"them to reduce size"},
{FLAG_DEBUG_NAMES, 0, "debug-names", NULL, NOPE,
"Write debug names to the generated binary file"},
@@ -151,6 +172,7 @@ static void on_option_error(struct WasmOptionParser* parser,
static void parse_options(int argc, char** argv) {
WasmOptionParser parser;
WASM_ZERO_MEMORY(parser);
+ parser.description = s_description;
parser.options = s_options;
parser.num_options = WASM_ARRAY_SIZE(s_options);
parser.on_option = on_option;
diff --git a/src/wasm-interp-sq.c b/src/wasm-interp-sq.c
index 9635967f..13b460ec 100644
--- a/src/wasm-interp-sq.c
+++ b/src/wasm-interp-sq.c
@@ -92,6 +92,11 @@ enum {
NUM_FLAGS
};
+static const char s_description[] =
+ " read a squirrel file and run it. this squirrel interpreter has\n"
+ " support for reading wasm binary files, via the Wasm.instantiateModule\n"
+ " interface.\n";
+
static WasmOption s_options[] = {
{FLAG_VERBOSE, 'v', "verbose", NULL, NOPE,
"use multiple times for more info"},
@@ -151,6 +156,7 @@ static void on_option_error(struct WasmOptionParser* parser,
static void parse_options(int argc, char** argv) {
WasmOptionParser parser;
WASM_ZERO_MEMORY(parser);
+ parser.description = s_description;
parser.options = s_options;
parser.num_options = WASM_ARRAY_SIZE(s_options);
parser.on_option = on_option;
diff --git a/src/wasm-interp.c b/src/wasm-interp.c
index 07f28c54..82a2ea83 100644
--- a/src/wasm-interp.c
+++ b/src/wasm-interp.c
@@ -66,6 +66,27 @@ enum {
NUM_FLAGS
};
+static const char s_description[] =
+ " read a file in the wasm binary format, and run in it a stack-based\n"
+ " interpreter.\n"
+ "\n"
+ "examples:\n"
+ " # parse binary file test.wasm, and type-check it\n"
+ " $ wasm-interp test.wasm\n"
+ "\n"
+ " # parse test.wasm and run all its exported functions\n"
+ " $ wasm-interp test.wasm --run-all-exports\n"
+ "\n"
+ " # parse test.wasm, run the exported functions and trace the output\n"
+ " $ wasm-interp test.wasm --run-all-exports --trace\n"
+ "\n"
+ " # parse test.json and run the spec tests\n"
+ " $ wasm-interp test.json --spec\n"
+ "\n"
+ " # parse test.wasm and run all its exported functions, setting the\n"
+ " # value stack size to 100 elements\n"
+ " $ wasm-interp test.wasm -V 100 --run-all-exports\n";
+
static WasmOption s_options[] = {
{FLAG_VERBOSE, 'v', "verbose", NULL, NOPE,
"use multiple times for more info"},
@@ -137,6 +158,7 @@ static void on_option_error(struct WasmOptionParser* parser,
static void parse_options(int argc, char** argv) {
WasmOptionParser parser;
WASM_ZERO_MEMORY(parser);
+ parser.description = s_description;
parser.options = s_options;
parser.num_options = WASM_ARRAY_SIZE(s_options);
parser.on_option = on_option;
diff --git a/src/wasm-option-parser.c b/src/wasm-option-parser.c
index b5cd280b..4d9eeabd 100644
--- a/src/wasm-option-parser.c
+++ b/src/wasm-option-parser.c
@@ -160,10 +160,18 @@ void wasm_parse_options(WasmOptionParser* parser,
}
}
+static const char* trim_argv0(const char* argv0) {
+ char* last_slash = strrchr(argv0, '/');
+ if (last_slash)
+ return last_slash + 1;
+ return argv0;
+}
+
void wasm_print_help(WasmOptionParser* parser) {
int i;
/* TODO(binji): do something more generic for filename here */
- printf("usage: %s [options] filename\n", parser->argv0);
+ printf("usage: %s [options] filename\n\n", trim_argv0(parser->argv0));
+ printf("%s\n", parser->description);
printf("options:\n");
const int extra_space = 8;
diff --git a/src/wasm-option-parser.h b/src/wasm-option-parser.h
index ac041ede..86aa5b8b 100644
--- a/src/wasm-option-parser.h
+++ b/src/wasm-option-parser.h
@@ -44,6 +44,7 @@ typedef struct WasmOption {
} WasmOption;
typedef struct WasmOptionParser {
+ const char* description;
WasmOption* options;
int num_options;
WasmOptionCallback on_option;
diff --git a/src/wasm-wast.c b/src/wasm-wast.c
index c47c709d..5f0765f5 100644
--- a/src/wasm-wast.c
+++ b/src/wasm-wast.c
@@ -54,6 +54,17 @@ enum {
NUM_FLAGS
};
+static const char s_description[] =
+ " read a file in the wasm binary format, and convert it to the wasm\n"
+ " s-expression file format.\n"
+ "\n"
+ "examples:\n"
+ " # parse binary file test.wasm and write s-expression file test.wast\n"
+ " $ wasm-wast test.wasm -o test.wast\n"
+ "\n"
+ " # parse test.wasm and write test.wast, using the debug names, if any\n"
+ " $ wasm-wast test.wasm --debug-names -o test.wast\n";
+
static WasmOption s_options[] = {
{FLAG_VERBOSE, 'v', "verbose", NULL, NOPE,
"use multiple times for more info"},
@@ -112,6 +123,7 @@ static void on_option_error(struct WasmOptionParser* parser,
static void parse_options(int argc, char** argv) {
WasmOptionParser parser;
WASM_ZERO_MEMORY(parser);
+ parser.description = s_description;
parser.options = s_options;
parser.num_options = WASM_ARRAY_SIZE(s_options);
parser.on_option = on_option;