summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sexpr-wasm.c9
-rw-r--r--src/wasm-binary-writer.c88
-rw-r--r--src/wasm-binary-writer.h3
-rw-r--r--test/dump/basic.txt4
-rw-r--r--test/dump/debug-names-no-remap.txt96
-rw-r--r--test/dump/debug-names.txt46
-rw-r--r--test/dump/getlocal-param.txt34
-rw-r--r--test/dump/getlocal.txt53
-rw-r--r--test/dump/grow-memory.txt2
-rw-r--r--test/dump/no-canonicalize.txt8
-rw-r--r--test/dump/no-remap-locals.txt80
-rw-r--r--test/dump/setlocal-param.txt71
-rw-r--r--test/dump/setlocal.txt100
-rw-r--r--test/help/sexpr-wasm.txt1
-rw-r--r--test/roundtrip/generate-local-names.txt8
15 files changed, 179 insertions, 424 deletions
diff --git a/src/sexpr-wasm.c b/src/sexpr-wasm.c
index 62eca561..266119b8 100644
--- a/src/sexpr-wasm.c
+++ b/src/sexpr-wasm.c
@@ -66,7 +66,6 @@ enum {
FLAG_SPEC,
FLAG_USE_LIBC_ALLOCATOR,
FLAG_NO_CANONICALIZE_LEB128S,
- FLAG_NO_REMAP_LOCALS,
FLAG_DEBUG_NAMES,
FLAG_NO_CHECK,
FLAG_NO_CHECK_ASSERT_INVALID,
@@ -107,10 +106,6 @@ static WasmOption s_options[] = {
"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 "
- "them to reduce size"},
{FLAG_DEBUG_NAMES, 0, "debug-names", NULL, NOPE,
"Write debug names to the generated binary file"},
{FLAG_NO_CHECK, 0, "no-check", NULL, NOPE,
@@ -156,10 +151,6 @@ static void on_option(struct WasmOptionParser* parser,
s_write_binary_options.canonicalize_lebs = WASM_FALSE;
break;
- case FLAG_NO_REMAP_LOCALS:
- s_write_binary_options.remap_locals = WASM_FALSE;
- break;
-
case FLAG_DEBUG_NAMES:
s_write_binary_options.write_debug_names = WASM_TRUE;
break;
diff --git a/src/wasm-binary-writer.c b/src/wasm-binary-writer.c
index 8b699089..b27ced8b 100644
--- a/src/wasm-binary-writer.c
+++ b/src/wasm-binary-writer.c
@@ -69,9 +69,6 @@ typedef struct Context {
size_t last_section_offset;
size_t last_section_leb_size_guess;
-
- uint32_t* remapped_locals; /* from unpacked -> packed index */
- uint32_t* reverse_remapped_locals; /* from packed -> unpacked index */
} Context;
static void write_header(Context* ctx, const char* name, int index) {
@@ -295,60 +292,6 @@ static void pop_label(Context* ctx, const WasmLabel* label) {
pop_unused_label(ctx, label);
}
-static void remap_locals(Context* ctx,
- const WasmModule* module,
- const WasmFunc* func) {
- uint32_t i;
- uint32_t num_params = wasm_get_num_params(module, func);
- uint32_t num_locals = func->local_types.size;
- uint32_t num_params_and_locals = num_params + num_locals;
- ctx->remapped_locals = wasm_realloc(ctx->allocator, ctx->remapped_locals,
- num_params_and_locals * sizeof(uint32_t),
- WASM_DEFAULT_ALIGN);
-
- ctx->reverse_remapped_locals = wasm_realloc(
- ctx->allocator, ctx->reverse_remapped_locals,
- num_params_and_locals * sizeof(uint32_t), WASM_DEFAULT_ALIGN);
-
- if (!ctx->options->remap_locals) {
- /* just pass the index straight through */
- for (i = 0; i < num_params_and_locals; ++i)
- ctx->remapped_locals[i] = i;
- for (i = 0; i < num_params_and_locals; ++i)
- ctx->reverse_remapped_locals[i] = i;
- return;
- }
-
- uint32_t max[WASM_NUM_TYPES];
- WASM_ZERO_MEMORY(max);
- for (i = 0; i < num_locals; ++i) {
- WasmType type = func->local_types.data[i];
- max[type]++;
- }
-
- /* params don't need remapping */
- for (i = 0; i < num_params; ++i) {
- ctx->remapped_locals[i] = i;
- ctx->reverse_remapped_locals[i] = i;
- }
-
- uint32_t start[WASM_NUM_TYPES];
- start[WASM_TYPE_I32] = num_params;
- start[WASM_TYPE_I64] = start[WASM_TYPE_I32] + max[WASM_TYPE_I32];
- start[WASM_TYPE_F32] = start[WASM_TYPE_I64] + max[WASM_TYPE_I64];
- start[WASM_TYPE_F64] = start[WASM_TYPE_F32] + max[WASM_TYPE_F32];
-
- uint32_t seen[WASM_NUM_TYPES];
- WASM_ZERO_MEMORY(seen);
- for (i = 0; i < num_locals; ++i) {
- WasmType type = func->local_types.data[i];
- uint32_t unpacked_index = num_params + i;
- uint32_t packed_index = start[type] + seen[type]++;
- ctx->remapped_locals[unpacked_index] = packed_index;
- ctx->reverse_remapped_locals[packed_index] = unpacked_index;
- }
-}
-
static void write_expr_list(Context* ctx,
const WasmModule* module,
const WasmFunc* func,
@@ -490,8 +433,7 @@ static void write_expr(Context* ctx,
case WASM_EXPR_TYPE_GET_LOCAL: {
int index = wasm_get_local_index_by_var(func, &expr->get_local.var);
write_opcode(&ctx->stream, WASM_OPCODE_GET_LOCAL);
- write_u32_leb128(&ctx->stream, ctx->remapped_locals[index],
- "remapped local index");
+ write_u32_leb128(&ctx->stream, index, "local index");
break;
}
case WASM_EXPR_TYPE_GROW_MEMORY:
@@ -567,8 +509,7 @@ static void write_expr(Context* ctx,
int index = wasm_get_local_index_by_var(func, &expr->get_local.var);
write_expr(ctx, module, func, expr->set_local.expr);
write_opcode(&ctx->stream, WASM_OPCODE_SET_LOCAL);
- write_u32_leb128(&ctx->stream, ctx->remapped_locals[index],
- "remapped local index");
+ write_u32_leb128(&ctx->stream, index, "local index");
break;
}
case WASM_EXPR_TYPE_STORE: {
@@ -618,8 +559,6 @@ static void write_func_locals(Context* ctx,
const WasmModule* module,
const WasmFunc* func,
const WasmTypeVector* local_types) {
- remap_locals(ctx, module, func);
-
if (local_types->size == 0) {
write_u32_leb128(&ctx->stream, 0, "local decl count");
return;
@@ -629,8 +568,7 @@ static void write_func_locals(Context* ctx,
#define FIRST_LOCAL_INDEX (num_params)
#define LAST_LOCAL_INDEX (num_params + local_types->size)
-#define GET_LOCAL_TYPE(x) \
- (local_types->data[ctx->reverse_remapped_locals[x] - num_params])
+#define GET_LOCAL_TYPE(x) (local_types->data[x - num_params])
/* loop through once to count the number of local declaration runs */
WasmType current_type = GET_LOCAL_TYPE(FIRST_LOCAL_INDEX);
@@ -843,14 +781,13 @@ static void write_module(Context* ctx, const WasmModule* module) {
write_u32_leb128(&ctx->stream, num_params_and_locals, "num locals");
if (num_params_and_locals) {
- remap_locals(ctx, module, func);
wasm_make_type_binding_reverse_mapping(
ctx->allocator, &func->decl.sig.param_types, &func->param_bindings,
&index_to_name);
size_t j;
for (j = 0; j < num_params; ++j) {
WasmStringSlice name = index_to_name.data[j];
- wasm_snprintf(desc, sizeof(desc), "remapped local name %" PRIzd, j);
+ wasm_snprintf(desc, sizeof(desc), "local name %" PRIzd, j);
write_str(&ctx->stream, name.start, name.length, WASM_PRINT_CHARS,
desc);
}
@@ -859,10 +796,8 @@ static void write_module(Context* ctx, const WasmModule* module) {
ctx->allocator, &func->local_types, &func->local_bindings,
&index_to_name);
for (j = 0; j < num_locals; ++j) {
- WasmStringSlice name =
- index_to_name.data[ctx->reverse_remapped_locals[num_params + j] -
- num_params];
- wasm_snprintf(desc, sizeof(desc), "remapped local name %" PRIzd,
+ WasmStringSlice name = index_to_name.data[j];
+ wasm_snprintf(desc, sizeof(desc), "local name %" PRIzd,
num_params + j);
write_str(&ctx->stream, name.start, name.length, WASM_PRINT_CHARS,
desc);
@@ -895,11 +830,6 @@ static void write_commands(Context* ctx, const WasmScript* script) {
}
}
-static void cleanup_context(Context* ctx) {
- wasm_free(ctx->allocator, ctx->remapped_locals);
- wasm_free(ctx->allocator, ctx->reverse_remapped_locals);
-}
-
WasmResult wasm_write_binary_module(WasmAllocator* allocator,
WasmWriter* writer,
const WasmModule* module,
@@ -910,10 +840,7 @@ WasmResult wasm_write_binary_module(WasmAllocator* allocator,
ctx.options = options;
ctx.log_stream = options->log_stream;
wasm_init_stream(&ctx.stream, writer, ctx.log_stream);
-
write_module(&ctx, module);
-
- cleanup_context(&ctx);
return ctx.stream.result;
}
@@ -927,9 +854,6 @@ WasmResult wasm_write_binary_script(WasmAllocator* allocator,
ctx.options = options;
ctx.log_stream = options->log_stream;
wasm_init_stream(&ctx.stream, writer, ctx.log_stream);
-
write_commands(&ctx, script);
-
- cleanup_context(&ctx);
return ctx.stream.result;
}
diff --git a/src/wasm-binary-writer.h b/src/wasm-binary-writer.h
index b799d20e..37a029f2 100644
--- a/src/wasm-binary-writer.h
+++ b/src/wasm-binary-writer.h
@@ -26,12 +26,11 @@ struct WasmWriter;
struct WasmStream;
#define WASM_WRITE_BINARY_OPTIONS_DEFAULT \
- { NULL, WASM_TRUE, WASM_TRUE, WASM_FALSE }
+ { NULL, WASM_TRUE, WASM_FALSE }
typedef struct WasmWriteBinaryOptions {
struct WasmStream* log_stream;
WasmBool canonicalize_lebs;
- WasmBool remap_locals;
WasmBool write_debug_names;
} WasmWriteBinaryOptions;
diff --git a/test/dump/basic.txt b/test/dump/basic.txt
index 2ed93bf1..b8224dd4 100644
--- a/test/dump/basic.txt
+++ b/test/dump/basic.txt
@@ -67,9 +67,9 @@
000004c: 02 ; alignment
000004d: 00 ; store offset
000004e: 14 ; OPCODE_GET_LOCAL
-000004f: 00 ; remapped local index
+000004f: 00 ; local index
0000050: 14 ; OPCODE_GET_LOCAL
-0000051: 01 ; remapped local index
+0000051: 01 ; local index
0000052: 40 ; OPCODE_I32_ADD
000003f: 13 ; FIXUP func body size
000003d: 15 ; FIXUP section size
diff --git a/test/dump/debug-names-no-remap.txt b/test/dump/debug-names-no-remap.txt
deleted file mode 100644
index 87d8befb..00000000
--- a/test/dump/debug-names-no-remap.txt
+++ /dev/null
@@ -1,96 +0,0 @@
-;;; FLAGS: -dv --debug-names --no-remap-locals
-(module
- ;; compare to test/dump/debug-names.txt
- (func $F1 (param $F1P0 i32)
- (local $F1L1 f32)
- (local $F1L2 i32)
- (local i32))
-
- (func $F2 (param $F2P0 f32)
- (local $F2L1 f64)
- (local i64)
- (local $F2L3 i64)))
-(;; STDOUT ;;;
-0000000: 0061 736d ; WASM_BINARY_MAGIC
-0000004: 0b00 0000 ; WASM_BINARY_VERSION
-; section "type"
-0000008: 04 ; string length
-0000009: 7479 7065 ; section id: "type"
-000000d: 00 ; section size (guess)
-000000e: 02 ; num types
-; type 0
-000000f: 40 ; function form
-0000010: 01 ; num params
-0000011: 01 ; param type
-0000012: 00 ; num results
-; type 1
-0000013: 40 ; function form
-0000014: 01 ; num params
-0000015: 03 ; param type
-0000016: 00 ; num results
-000000d: 09 ; FIXUP section size
-; section "function"
-0000017: 08 ; string length
-0000018: 6675 6e63 7469 6f6e ; section id: "function"
-0000020: 00 ; section size (guess)
-0000021: 02 ; num functions
-0000022: 00 ; function 0 signature index
-0000023: 01 ; function 1 signature index
-0000020: 03 ; FIXUP section size
-; section "code"
-0000024: 04 ; string length
-0000025: 636f 6465 ; section id: "code"
-0000029: 00 ; section size (guess)
-000002a: 02 ; num functions
-; function body 0
-000002b: 00 ; func body size (guess)
-000002c: 02 ; local decl count
-000002d: 01 ; local type count
-000002e: 03 ; WASM_TYPE_F32
-000002f: 02 ; local type count
-0000030: 01 ; WASM_TYPE_I32
-000002b: 05 ; FIXUP func body size
-; function body 1
-0000031: 00 ; func body size (guess)
-0000032: 02 ; local decl count
-0000033: 01 ; local type count
-0000034: 04 ; WASM_TYPE_F64
-0000035: 02 ; local type count
-0000036: 02 ; WASM_TYPE_I64
-0000031: 05 ; FIXUP func body size
-0000029: 0d ; FIXUP section size
-; section "name"
-0000037: 04 ; string length
-0000038: 6e61 6d65 ; section id: "name"
-000003c: 00 ; section size (guess)
-000003d: 02 ; num functions
-000003e: 03 ; string length
-000003f: 2446 31 $F1 ; func name 0
-0000042: 04 ; num locals
-0000043: 05 ; string length
-0000044: 2446 3150 30 $F1P0 ; remapped local name 0
-0000049: 05 ; string length
-000004a: 2446 314c 31 $F1L1 ; remapped local name 1
-000004f: 05 ; string length
-0000050: 2446 314c 32 $F1L2 ; remapped local name 2
-0000055: 00 ; string length
-0000056: 03 ; string length
-0000057: 2446 32 $F2 ; func name 1
-000005a: 04 ; num locals
-000005b: 05 ; string length
-000005c: 2446 3250 30 $F2P0 ; remapped local name 0
-0000061: 05 ; string length
-0000062: 2446 324c 31 $F2L1 ; remapped local name 1
-0000067: 00 ; string length
-0000068: 05 ; string length
-0000069: 2446 324c 33 $F2L3 ; remapped local name 3
-000003c: 31 ; FIXUP section size
-;; dump
-0000000: 0061 736d 0b00 0000 0474 7970 6509 0240
-0000010: 0101 0040 0103 0008 6675 6e63 7469 6f6e
-0000020: 0302 0001 0463 6f64 650d 0205 0201 0302
-0000030: 0105 0201 0402 0204 6e61 6d65 3102 0324
-0000040: 4631 0405 2446 3150 3005 2446 314c 3105
-0000050: 2446 314c 3200 0324 4632 0405 2446 3250
-0000060: 3005 2446 324c 3100 0524 4632 4c33
-;;; STDOUT ;;)
diff --git a/test/dump/debug-names.txt b/test/dump/debug-names.txt
index 795a2425..11ef5552 100644
--- a/test/dump/debug-names.txt
+++ b/test/dump/debug-names.txt
@@ -44,18 +44,18 @@
; function body 0
000002b: 00 ; func body size (guess)
000002c: 02 ; local decl count
-000002d: 02 ; local type count
-000002e: 01 ; WASM_TYPE_I32
-000002f: 01 ; local type count
-0000030: 03 ; WASM_TYPE_F32
+000002d: 01 ; local type count
+000002e: 03 ; WASM_TYPE_F32
+000002f: 02 ; local type count
+0000030: 01 ; WASM_TYPE_I32
000002b: 05 ; FIXUP func body size
; function body 1
0000031: 00 ; func body size (guess)
0000032: 02 ; local decl count
-0000033: 02 ; local type count
-0000034: 02 ; WASM_TYPE_I64
-0000035: 01 ; local type count
-0000036: 04 ; WASM_TYPE_F64
+0000033: 01 ; local type count
+0000034: 04 ; WASM_TYPE_F64
+0000035: 02 ; local type count
+0000036: 02 ; WASM_TYPE_I64
0000031: 05 ; FIXUP func body size
0000029: 0d ; FIXUP section size
; section "name"
@@ -67,29 +67,29 @@
000003f: 2446 31 $F1 ; func name 0
0000042: 04 ; num locals
0000043: 05 ; string length
-0000044: 2446 3150 30 $F1P0 ; remapped local name 0
+0000044: 2446 3150 30 $F1P0 ; local name 0
0000049: 05 ; string length
-000004a: 2446 314c 32 $F1L2 ; remapped local name 1
-000004f: 00 ; string length
-0000050: 05 ; string length
-0000051: 2446 314c 31 $F1L1 ; remapped local name 3
+000004a: 2446 314c 31 $F1L1 ; local name 1
+000004f: 05 ; string length
+0000050: 2446 314c 32 $F1L2 ; local name 2
+0000055: 00 ; string length
0000056: 03 ; string length
0000057: 2446 32 $F2 ; func name 1
000005a: 04 ; num locals
000005b: 05 ; string length
-000005c: 2446 3250 30 $F2P0 ; remapped local name 0
-0000061: 00 ; string length
-0000062: 05 ; string length
-0000063: 2446 324c 33 $F2L3 ; remapped local name 2
+000005c: 2446 3250 30 $F2P0 ; local name 0
+0000061: 05 ; string length
+0000062: 2446 324c 31 $F2L1 ; local name 1
+0000067: 00 ; string length
0000068: 05 ; string length
-0000069: 2446 324c 31 $F2L1 ; remapped local name 3
+0000069: 2446 324c 33 $F2L3 ; local name 3
000003c: 31 ; FIXUP section size
;; dump
0000000: 0061 736d 0b00 0000 0474 7970 6509 0240
0000010: 0101 0040 0103 0008 6675 6e63 7469 6f6e
-0000020: 0302 0001 0463 6f64 650d 0205 0202 0101
-0000030: 0305 0202 0201 0404 6e61 6d65 3102 0324
-0000040: 4631 0405 2446 3150 3005 2446 314c 3200
-0000050: 0524 4631 4c31 0324 4632 0405 2446 3250
-0000060: 3000 0524 4632 4c33 0524 4632 4c31
+0000020: 0302 0001 0463 6f64 650d 0205 0201 0302
+0000030: 0105 0201 0402 0204 6e61 6d65 3102 0324
+0000040: 4631 0405 2446 3150 3005 2446 314c 3105
+0000050: 2446 314c 3200 0324 4632 0405 2446 3250
+0000060: 3005 2446 324c 3100 0524 4632 4c33
;;; STDOUT ;;)
diff --git a/test/dump/getlocal-param.txt b/test/dump/getlocal-param.txt
index c993c293..eb8454f3 100644
--- a/test/dump/getlocal-param.txt
+++ b/test/dump/getlocal-param.txt
@@ -41,30 +41,32 @@
0000026: 01 ; num functions
; function body 0
0000027: 00 ; func body size (guess)
-0000028: 03 ; local decl count
+0000028: 04 ; local decl count
0000029: 01 ; local type count
-000002a: 01 ; WASM_TYPE_I32
+000002a: 02 ; WASM_TYPE_I64
000002b: 01 ; local type count
-000002c: 02 ; WASM_TYPE_I64
-000002d: 02 ; local type count
-000002e: 03 ; WASM_TYPE_F32
-000002f: 14 ; OPCODE_GET_LOCAL
-0000030: 00 ; remapped local index
+000002c: 03 ; WASM_TYPE_F32
+000002d: 01 ; local type count
+000002e: 01 ; WASM_TYPE_I32
+000002f: 01 ; local type count
+0000030: 03 ; WASM_TYPE_F32
0000031: 14 ; OPCODE_GET_LOCAL
-0000032: 01 ; remapped local index
+0000032: 00 ; local index
0000033: 14 ; OPCODE_GET_LOCAL
-0000034: 03 ; remapped local index
+0000034: 01 ; local index
0000035: 14 ; OPCODE_GET_LOCAL
-0000036: 04 ; remapped local index
+0000036: 02 ; local index
0000037: 14 ; OPCODE_GET_LOCAL
-0000038: 02 ; remapped local index
+0000038: 03 ; local index
0000039: 14 ; OPCODE_GET_LOCAL
-000003a: 05 ; remapped local index
-0000027: 13 ; FIXUP func body size
-0000025: 15 ; FIXUP section size
+000003a: 04 ; local index
+000003b: 14 ; OPCODE_GET_LOCAL
+000003c: 05 ; local index
+0000027: 15 ; FIXUP func body size
+0000025: 17 ; FIXUP section size
;; dump
0000000: 0061 736d 0b00 0000 0474 7970 6506 0140
0000010: 0201 0300 0866 756e 6374 696f 6e02 0100
-0000020: 0463 6f64 6515 0113 0301 0101 0202 0314
-0000030: 0014 0114 0314 0414 0214 05
+0000020: 0463 6f64 6517 0115 0401 0201 0301 0101
+0000030: 0314 0014 0114 0214 0314 0414 05
;;; STDOUT ;;)
diff --git a/test/dump/getlocal.txt b/test/dump/getlocal.txt
index dc47609f..00c0766c 100644
--- a/test/dump/getlocal.txt
+++ b/test/dump/getlocal.txt
@@ -41,36 +41,43 @@
0000024: 01 ; num functions
; function body 0
0000025: 00 ; func body size (guess)
-0000026: 04 ; local decl count
-0000027: 02 ; local type count
-0000028: 01 ; WASM_TYPE_I32
-0000029: 02 ; local type count
-000002a: 02 ; WASM_TYPE_I64
-000002b: 02 ; local type count
-000002c: 03 ; WASM_TYPE_F32
+0000026: 07 ; local decl count
+0000027: 01 ; local type count
+0000028: 04 ; WASM_TYPE_F64
+0000029: 01 ; local type count
+000002a: 03 ; WASM_TYPE_F32
+000002b: 01 ; local type count
+000002c: 02 ; WASM_TYPE_I64
000002d: 02 ; local type count
-000002e: 04 ; WASM_TYPE_F64
-000002f: 14 ; OPCODE_GET_LOCAL
-0000030: 06 ; remapped local index
-0000031: 14 ; OPCODE_GET_LOCAL
-0000032: 04 ; remapped local index
-0000033: 14 ; OPCODE_GET_LOCAL
-0000034: 02 ; remapped local index
+000002e: 01 ; WASM_TYPE_I32
+000002f: 01 ; local type count
+0000030: 03 ; WASM_TYPE_F32
+0000031: 01 ; local type count
+0000032: 04 ; WASM_TYPE_F64
+0000033: 01 ; local type count
+0000034: 02 ; WASM_TYPE_I64
0000035: 14 ; OPCODE_GET_LOCAL
-0000036: 00 ; remapped local index
+0000036: 00 ; local index
0000037: 14 ; OPCODE_GET_LOCAL
-0000038: 01 ; remapped local index
+0000038: 01 ; local index
0000039: 14 ; OPCODE_GET_LOCAL
-000003a: 05 ; remapped local index
+000003a: 02 ; local index
000003b: 14 ; OPCODE_GET_LOCAL
-000003c: 07 ; remapped local index
+000003c: 03 ; local index
000003d: 14 ; OPCODE_GET_LOCAL
-000003e: 03 ; remapped local index
-0000025: 19 ; FIXUP func body size
-0000023: 1b ; FIXUP section size
+000003e: 04 ; local index
+000003f: 14 ; OPCODE_GET_LOCAL
+0000040: 05 ; local index
+0000041: 14 ; OPCODE_GET_LOCAL
+0000042: 06 ; local index
+0000043: 14 ; OPCODE_GET_LOCAL
+0000044: 07 ; local index
+0000025: 1f ; FIXUP func body size
+0000023: 21 ; FIXUP section size
;; dump
0000000: 0061 736d 0b00 0000 0474 7970 6504 0140
0000010: 0000 0866 756e 6374 696f 6e02 0100 0463
-0000020: 6f64 651b 0119 0402 0102 0202 0302 0414
-0000030: 0614 0414 0214 0014 0114 0514 0714 03
+0000020: 6f64 6521 011f 0701 0401 0301 0202 0101
+0000030: 0301 0401 0214 0014 0114 0214 0314 0414
+0000040: 0514 0614 07
;;; STDOUT ;;)
diff --git a/test/dump/grow-memory.txt b/test/dump/grow-memory.txt
index 45486c93..0cbb63a7 100644
--- a/test/dump/grow-memory.txt
+++ b/test/dump/grow-memory.txt
@@ -41,7 +41,7 @@
0000031: 00 ; func body size (guess)
0000032: 00 ; local decl count
0000033: 14 ; OPCODE_GET_LOCAL
-0000034: 00 ; remapped local index
+0000034: 00 ; local index
0000035: 39 ; OPCODE_GROW_MEMORY
0000031: 04 ; FIXUP func body size
000002f: 06 ; FIXUP section size
diff --git a/test/dump/no-canonicalize.txt b/test/dump/no-canonicalize.txt
index c6c95217..4efd17c2 100644
--- a/test/dump/no-canonicalize.txt
+++ b/test/dump/no-canonicalize.txt
@@ -89,9 +89,9 @@
0000086: 0000 0000 00 ; func body size (guess)
000008b: 00 ; local decl count
000008c: 14 ; OPCODE_GET_LOCAL
-000008d: 00 ; remapped local index
+000008d: 00 ; local index
000008e: 14 ; OPCODE_GET_LOCAL
-000008f: 01 ; remapped local index
+000008f: 01 ; local index
0000090: 17 ; OPCODE_CALL_INDIRECT
0000091: 01 ; call_indirect arity
0000092: 01 ; signature index
@@ -100,7 +100,7 @@
0000093: 0000 0000 00 ; func body size (guess)
0000098: 00 ; local decl count
0000099: 14 ; OPCODE_GET_LOCAL
-000009a: 00 ; remapped local index
+000009a: 00 ; local index
000009b: 10 ; OPCODE_I32_CONST
000009c: 01 ; i32 literal
000009d: 40 ; OPCODE_I32_ADD
@@ -109,7 +109,7 @@
000009e: 0000 0000 00 ; func body size (guess)
00000a3: 00 ; local decl count
00000a4: 14 ; OPCODE_GET_LOCAL
-00000a5: 00 ; remapped local index
+00000a5: 00 ; local index
00000a6: 10 ; OPCODE_I32_CONST
00000a7: 02 ; i32 literal
00000a8: 42 ; OPCODE_I32_MUL
diff --git a/test/dump/no-remap-locals.txt b/test/dump/no-remap-locals.txt
deleted file mode 100644
index 32931c9e..00000000
--- a/test/dump/no-remap-locals.txt
+++ /dev/null
@@ -1,80 +0,0 @@
-;;; FLAGS: -dv --no-remap-locals
-(module
- (func
- ;; compare with test/dump/getlocal.txt
- (local f64 f32 i64 i32 i32 f32 f64 i64)
- (get_local 0)
- (get_local 1)
- (get_local 2)
- (get_local 3)
- (get_local 4)
- (get_local 5)
- (get_local 6)
- (get_local 7)))
-(;; STDOUT ;;;
-0000000: 0061 736d ; WASM_BINARY_MAGIC
-0000004: 0b00 0000 ; WASM_BINARY_VERSION
-; section "type"
-0000008: 04 ; string length
-0000009: 7479 7065 ; section id: "type"
-000000d: 00 ; section size (guess)
-000000e: 01 ; num types
-; type 0
-000000f: 40 ; function form
-0000010: 00 ; num params
-0000011: 00 ; num results
-000000d: 04 ; FIXUP section size
-; section "function"
-0000012: 08 ; string length
-0000013: 6675 6e63 7469 6f6e ; section id: "function"
-000001b: 00 ; section size (guess)
-000001c: 01 ; num functions
-000001d: 00 ; function 0 signature index
-000001b: 02 ; FIXUP section size
-; section "code"
-000001e: 04 ; string length
-000001f: 636f 6465 ; section id: "code"
-0000023: 00 ; section size (guess)
-0000024: 01 ; num functions
-; function body 0
-0000025: 00 ; func body size (guess)
-0000026: 07 ; local decl count
-0000027: 01 ; local type count
-0000028: 04 ; WASM_TYPE_F64
-0000029: 01 ; local type count
-000002a: 03 ; WASM_TYPE_F32
-000002b: 01 ; local type count
-000002c: 02 ; WASM_TYPE_I64
-000002d: 02 ; local type count
-000002e: 01 ; WASM_TYPE_I32
-000002f: 01 ; local type count
-0000030: 03 ; WASM_TYPE_F32
-0000031: 01 ; local type count
-0000032: 04 ; WASM_TYPE_F64
-0000033: 01 ; local type count
-0000034: 02 ; WASM_TYPE_I64
-0000035: 14 ; OPCODE_GET_LOCAL
-0000036: 00 ; remapped local index
-0000037: 14 ; OPCODE_GET_LOCAL
-0000038: 01 ; remapped local index
-0000039: 14 ; OPCODE_GET_LOCAL
-000003a: 02 ; remapped local index
-000003b: 14 ; OPCODE_GET_LOCAL
-000003c: 03 ; remapped local index
-000003d: 14 ; OPCODE_GET_LOCAL
-000003e: 04 ; remapped local index
-000003f: 14 ; OPCODE_GET_LOCAL
-0000040: 05 ; remapped local index
-0000041: 14 ; OPCODE_GET_LOCAL
-0000042: 06 ; remapped local index
-0000043: 14 ; OPCODE_GET_LOCAL
-0000044: 07 ; remapped local index
-0000025: 1f ; FIXUP func body size
-0000023: 21 ; FIXUP section size
-;; dump
-0000000: 0061 736d 0b00 0000 0474 7970 6504 0140
-0000010: 0000 0866 756e 6374 696f 6e02 0100 0463
-0000020: 6f64 6521 011f 0701 0401 0301 0202 0101
-0000030: 0301 0401 0214 0014 0114 0214 0314 0414
-0000040: 0514 0614 07
-;;; STDOUT ;;)
diff --git a/test/dump/setlocal-param.txt b/test/dump/setlocal-param.txt
index e33c3925..099e3050 100644
--- a/test/dump/setlocal-param.txt
+++ b/test/dump/setlocal-param.txt
@@ -41,43 +41,46 @@
0000026: 01 ; num functions
; function body 0
0000027: 00 ; func body size (guess)
-0000028: 03 ; local decl count
+0000028: 04 ; local decl count
0000029: 01 ; local type count
-000002a: 01 ; WASM_TYPE_I32
+000002a: 02 ; WASM_TYPE_I64
000002b: 01 ; local type count
-000002c: 02 ; WASM_TYPE_I64
-000002d: 02 ; local type count
-000002e: 03 ; WASM_TYPE_F32
-000002f: 10 ; OPCODE_I32_CONST
-0000030: 00 ; i32 literal
-0000031: 15 ; OPCODE_SET_LOCAL
-0000032: 00 ; remapped local index
-0000033: 13 ; OPCODE_F32_CONST
-0000034: 0000 0000 ; f32 literal
-0000038: 15 ; OPCODE_SET_LOCAL
-0000039: 01 ; remapped local index
-000003a: 11 ; OPCODE_I64_CONST
-000003b: 00 ; i64 literal
-000003c: 15 ; OPCODE_SET_LOCAL
-000003d: 03 ; remapped local index
-000003e: 13 ; OPCODE_F32_CONST
-000003f: 0000 0000 ; f32 literal
-0000043: 15 ; OPCODE_SET_LOCAL
-0000044: 04 ; remapped local index
-0000045: 10 ; OPCODE_I32_CONST
-0000046: 00 ; i32 literal
-0000047: 15 ; OPCODE_SET_LOCAL
-0000048: 02 ; remapped local index
-0000049: 13 ; OPCODE_F32_CONST
-000004a: 0000 0000 ; f32 literal
-000004e: 15 ; OPCODE_SET_LOCAL
-000004f: 05 ; remapped local index
-0000027: 28 ; FIXUP func body size
-0000025: 2a ; FIXUP section size
+000002c: 03 ; WASM_TYPE_F32
+000002d: 01 ; local type count
+000002e: 01 ; WASM_TYPE_I32
+000002f: 01 ; local type count
+0000030: 03 ; WASM_TYPE_F32
+0000031: 10 ; OPCODE_I32_CONST
+0000032: 00 ; i32 literal
+0000033: 15 ; OPCODE_SET_LOCAL
+0000034: 00 ; local index
+0000035: 13 ; OPCODE_F32_CONST
+0000036: 0000 0000 ; f32 literal
+000003a: 15 ; OPCODE_SET_LOCAL
+000003b: 01 ; local index
+000003c: 11 ; OPCODE_I64_CONST
+000003d: 00 ; i64 literal
+000003e: 15 ; OPCODE_SET_LOCAL
+000003f: 02 ; local index
+0000040: 13 ; OPCODE_F32_CONST
+0000041: 0000 0000 ; f32 literal
+0000045: 15 ; OPCODE_SET_LOCAL
+0000046: 03 ; local index
+0000047: 10 ; OPCODE_I32_CONST
+0000048: 00 ; i32 literal
+0000049: 15 ; OPCODE_SET_LOCAL
+000004a: 04 ; local index
+000004b: 13 ; OPCODE_F32_CONST
+000004c: 0000 0000 ; f32 literal
+0000050: 15 ; OPCODE_SET_LOCAL
+0000051: 05 ; local index
+0000027: 2a ; FIXUP func body size
+0000025: 2c ; FIXUP section size
;; dump
0000000: 0061 736d 0b00 0000 0474 7970 6506 0140
0000010: 0201 0300 0866 756e 6374 696f 6e02 0100
-0000020: 0463 6f64 652a 0128 0301 0101 0202 0310
-0000030: 0015 0013 0000 0000 1501 1100 1503 1300
-0000040: 0000 0015 0410 0015 0213 0000 0000 1505
+0000020: 0463 6f64 652c 012a 0401 0201 0301 0101
+0000030: 0310 0015 0013 0000 0000 1501 1100 1502
+0000040: 1300 0000 0015 0310 0015 0413 0000 0000
+0000050: 1505
;;; STDOUT ;;)
diff --git a/test/dump/setlocal.txt b/test/dump/setlocal.txt
index 07291393..65e433d6 100644
--- a/test/dump/setlocal.txt
+++ b/test/dump/setlocal.txt
@@ -41,55 +41,61 @@
0000024: 01 ; num functions
; function body 0
0000025: 00 ; func body size (guess)
-0000026: 04 ; local decl count
-0000027: 02 ; local type count
-0000028: 01 ; WASM_TYPE_I32
-0000029: 02 ; local type count
-000002a: 02 ; WASM_TYPE_I64
-000002b: 02 ; local type count
-000002c: 03 ; WASM_TYPE_F32
+0000026: 07 ; local decl count
+0000027: 01 ; local type count
+0000028: 04 ; WASM_TYPE_F64
+0000029: 01 ; local type count
+000002a: 03 ; WASM_TYPE_F32
+000002b: 01 ; local type count
+000002c: 02 ; WASM_TYPE_I64
000002d: 02 ; local type count
-000002e: 04 ; WASM_TYPE_F64
-000002f: 12 ; OPCODE_F64_CONST
-0000030: 0000 0000 0000 0000 ; f64 literal
-0000038: 15 ; OPCODE_SET_LOCAL
-0000039: 06 ; remapped local index
-000003a: 13 ; OPCODE_F32_CONST
-000003b: 0000 0000 ; f32 literal
-000003f: 15 ; OPCODE_SET_LOCAL
-0000040: 04 ; remapped local index
-0000041: 11 ; OPCODE_I64_CONST
-0000042: 00 ; i64 literal
-0000043: 15 ; OPCODE_SET_LOCAL
-0000044: 02 ; remapped local index
-0000045: 10 ; OPCODE_I32_CONST
-0000046: 00 ; i32 literal
-0000047: 15 ; OPCODE_SET_LOCAL
-0000048: 00 ; remapped local index
-0000049: 10 ; OPCODE_I32_CONST
-000004a: 00 ; i32 literal
-000004b: 15 ; OPCODE_SET_LOCAL
-000004c: 01 ; remapped local index
-000004d: 13 ; OPCODE_F32_CONST
-000004e: 0000 0000 ; f32 literal
-0000052: 15 ; OPCODE_SET_LOCAL
-0000053: 05 ; remapped local index
-0000054: 12 ; OPCODE_F64_CONST
-0000055: 0000 0000 0000 0000 ; f64 literal
-000005d: 15 ; OPCODE_SET_LOCAL
-000005e: 07 ; remapped local index
-000005f: 11 ; OPCODE_I64_CONST
-0000060: 00 ; i64 literal
-0000061: 15 ; OPCODE_SET_LOCAL
-0000062: 03 ; remapped local index
-0000025: 3d ; FIXUP func body size
-0000023: 3f ; FIXUP section size
+000002e: 01 ; WASM_TYPE_I32
+000002f: 01 ; local type count
+0000030: 03 ; WASM_TYPE_F32
+0000031: 01 ; local type count
+0000032: 04 ; WASM_TYPE_F64
+0000033: 01 ; local type count
+0000034: 02 ; WASM_TYPE_I64
+0000035: 12 ; OPCODE_F64_CONST
+0000036: 0000 0000 0000 0000 ; f64 literal
+000003e: 15 ; OPCODE_SET_LOCAL
+000003f: 00 ; local index
+0000040: 13 ; OPCODE_F32_CONST
+0000041: 0000 0000 ; f32 literal
+0000045: 15 ; OPCODE_SET_LOCAL
+0000046: 01 ; local index
+0000047: 11 ; OPCODE_I64_CONST
+0000048: 00 ; i64 literal
+0000049: 15 ; OPCODE_SET_LOCAL
+000004a: 02 ; local index
+000004b: 10 ; OPCODE_I32_CONST
+000004c: 00 ; i32 literal
+000004d: 15 ; OPCODE_SET_LOCAL
+000004e: 03 ; local index
+000004f: 10 ; OPCODE_I32_CONST
+0000050: 00 ; i32 literal
+0000051: 15 ; OPCODE_SET_LOCAL
+0000052: 04 ; local index
+0000053: 13 ; OPCODE_F32_CONST
+0000054: 0000 0000 ; f32 literal
+0000058: 15 ; OPCODE_SET_LOCAL
+0000059: 05 ; local index
+000005a: 12 ; OPCODE_F64_CONST
+000005b: 0000 0000 0000 0000 ; f64 literal
+0000063: 15 ; OPCODE_SET_LOCAL
+0000064: 06 ; local index
+0000065: 11 ; OPCODE_I64_CONST
+0000066: 00 ; i64 literal
+0000067: 15 ; OPCODE_SET_LOCAL
+0000068: 07 ; local index
+0000025: 43 ; FIXUP func body size
+0000023: 45 ; FIXUP section size
;; dump
0000000: 0061 736d 0b00 0000 0474 7970 6504 0140
0000010: 0000 0866 756e 6374 696f 6e02 0100 0463
-0000020: 6f64 653f 013d 0402 0102 0202 0302 0412
-0000030: 0000 0000 0000 0000 1506 1300 0000 0015
-0000040: 0411 0015 0210 0015 0010 0015 0113 0000
-0000050: 0000 1505 1200 0000 0000 0000 0015 0711
-0000060: 0015 03
+0000020: 6f64 6545 0143 0701 0401 0301 0202 0101
+0000030: 0301 0401 0212 0000 0000 0000 0000 1500
+0000040: 1300 0000 0015 0111 0015 0210 0015 0310
+0000050: 0015 0413 0000 0000 1505 1200 0000 0000
+0000060: 0000 0015 0611 0015 07
;;; STDOUT ;;)
diff --git a/test/help/sexpr-wasm.txt b/test/help/sexpr-wasm.txt
index 0a2968c9..47bcd8f0 100644
--- a/test/help/sexpr-wasm.txt
+++ b/test/help/sexpr-wasm.txt
@@ -29,7 +29,6 @@ options:
--spec parse a file with multiple modules and assertions, like the spec tests
--use-libc-allocator use malloc, free, etc. instead of stack allocator
--no-canonicalize-leb128s Write all LEB128 sizes as 5-bytes instead of their minimal size
- --no-remap-locals If set, function locals are written in source order, instead of packing them to reduce size
--debug-names Write debug names to the generated binary file
--no-check Don't check for invalid modules
--no-check-assert-invalid Don't run the assert_invalid checks
diff --git a/test/roundtrip/generate-local-names.txt b/test/roundtrip/generate-local-names.txt
index c1713ba2..badab629 100644
--- a/test/roundtrip/generate-local-names.txt
+++ b/test/roundtrip/generate-local-names.txt
@@ -16,17 +16,17 @@
(module
(type $t0 (func (param i32 f32)))
(func $f0 (type $t0) (param $p0 i32) (param $p1 f32)
- (local $l0 i64) (local $l1 f64)
+ (local $l0 f64) (local $l1 i64)
(get_local $p0)
(get_local $p1)
- (get_local $l1)
(get_local $l0)
+ (get_local $l1)
(set_local $p0
(i32.const 1))
(set_local $p1
(f32.const 0x1p+0))
- (set_local $l1
- (f64.const 0x1p+0))
(set_local $l0
+ (f64.const 0x1p+0))
+ (set_local $l1
(i64.const 1))))
;;; STDOUT ;;)