summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sexpr-wasm.c9
-rw-r--r--src/wasm-binary-writer.c88
-rw-r--r--src/wasm-binary-writer.h3
3 files changed, 7 insertions, 93 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;