diff options
Diffstat (limited to 'src/ast-writer.c')
-rw-r--r-- | src/ast-writer.c | 310 |
1 files changed, 155 insertions, 155 deletions
diff --git a/src/ast-writer.c b/src/ast-writer.c index 220eb532..c50ce640 100644 --- a/src/ast-writer.c +++ b/src/ast-writer.c @@ -55,13 +55,13 @@ typedef enum NextChar { } NextChar; typedef struct Context { - WasmAllocator* allocator; - WasmStream stream; - WasmResult result; + WabtAllocator* allocator; + WabtStream stream; + WabtResult result; int indent; NextChar next_char; int depth; - WasmStringSliceVector index_to_name; + WabtStringSliceVector index_to_name; int func_index; int global_index; @@ -87,22 +87,22 @@ static void write_indent(Context* ctx) { static size_t s_indent_len = sizeof(s_indent) - 1; size_t indent = ctx->indent; while (indent > s_indent_len) { - wasm_write_data(&ctx->stream, s_indent, s_indent_len, NULL); + wabt_write_data(&ctx->stream, s_indent, s_indent_len, NULL); indent -= s_indent_len; } if (indent > 0) { - wasm_write_data(&ctx->stream, s_indent, indent, NULL); + wabt_write_data(&ctx->stream, s_indent, indent, NULL); } } static void write_next_char(Context* ctx) { switch (ctx->next_char) { case NEXT_CHAR_SPACE: - wasm_write_data(&ctx->stream, " ", 1, NULL); + wabt_write_data(&ctx->stream, " ", 1, NULL); break; case NEXT_CHAR_NEWLINE: case NEXT_CHAR_FORCE_NEWLINE: - wasm_write_data(&ctx->stream, "\n", 1, NULL); + wabt_write_data(&ctx->stream, "\n", 1, NULL); write_indent(ctx); break; @@ -117,19 +117,19 @@ static void write_data_with_next_char(Context* ctx, const void* src, size_t size) { write_next_char(ctx); - wasm_write_data(&ctx->stream, src, size, NULL); + wabt_write_data(&ctx->stream, src, size, NULL); } -static void WASM_PRINTF_FORMAT(2, 3) +static void WABT_PRINTF_FORMAT(2, 3) writef(Context* ctx, const char* format, ...) { - WASM_SNPRINTF_ALLOCA(buffer, length, format); + WABT_SNPRINTF_ALLOCA(buffer, length, format); /* default to following space */ write_data_with_next_char(ctx, buffer, length); ctx->next_char = NEXT_CHAR_SPACE; } static void write_putc(Context* ctx, char c) { - wasm_write_data(&ctx->stream, &c, 1, NULL); + wabt_write_data(&ctx->stream, &c, 1, NULL); } static void write_puts(Context* ctx, const char* s, NextChar next_char) { @@ -146,7 +146,7 @@ static void write_puts_newline(Context* ctx, const char* s) { write_puts(ctx, s, NEXT_CHAR_NEWLINE); } -static void write_newline(Context* ctx, WasmBool force) { +static void write_newline(Context* ctx, WabtBool force) { if (ctx->next_char == NEXT_CHAR_FORCE_NEWLINE) write_next_char(ctx); ctx->next_char = force ? NEXT_CHAR_FORCE_NEWLINE : NEXT_CHAR_NEWLINE; @@ -182,22 +182,22 @@ static void write_close_space(Context* ctx) { } static void write_string_slice(Context* ctx, - const WasmStringSlice* str, + const WabtStringSlice* str, NextChar next_char) { - writef(ctx, PRIstringslice, WASM_PRINTF_STRING_SLICE_ARG(*str)); + writef(ctx, PRIstringslice, WABT_PRINTF_STRING_SLICE_ARG(*str)); ctx->next_char = next_char; } -static WasmBool write_string_slice_opt(Context* ctx, - const WasmStringSlice* str, +static WabtBool write_string_slice_opt(Context* ctx, + const WabtStringSlice* str, NextChar next_char) { if (str->start) write_string_slice(ctx, str, next_char); - return str->start ? WASM_TRUE : WASM_FALSE; + return str->start ? WABT_TRUE : WABT_FALSE; } static void write_string_slice_or_index(Context* ctx, - const WasmStringSlice* str, + const WabtStringSlice* str, uint32_t index, NextChar next_char) { if (str->start) @@ -227,14 +227,14 @@ static void write_quoted_data(Context* ctx, const void* data, size_t length) { } static void write_quoted_string_slice(Context* ctx, - const WasmStringSlice* str, + const WabtStringSlice* str, NextChar next_char) { write_quoted_data(ctx, str->start, str->length); ctx->next_char = next_char; } -static void write_var(Context* ctx, const WasmVar* var, NextChar next_char) { - if (var->type == WASM_VAR_TYPE_INDEX) { +static void write_var(Context* ctx, const WabtVar* var, NextChar next_char) { + if (var->type == WABT_VAR_TYPE_INDEX) { writef(ctx, "%" PRId64, var->index); ctx->next_char = next_char; } else { @@ -242,8 +242,8 @@ static void write_var(Context* ctx, const WasmVar* var, NextChar next_char) { } } -static void write_br_var(Context* ctx, const WasmVar* var, NextChar next_char) { - if (var->type == WASM_VAR_TYPE_INDEX) { +static void write_br_var(Context* ctx, const WabtVar* var, NextChar next_char) { + if (var->type == WABT_VAR_TYPE_INDEX) { writef(ctx, "%" PRId64 " (;@%" PRId64 ";)", var->index, ctx->depth - var->index - 1); ctx->next_char = next_char; @@ -252,14 +252,14 @@ static void write_br_var(Context* ctx, const WasmVar* var, NextChar next_char) { } } -static void write_type(Context* ctx, WasmType type, NextChar next_char) { - const char* type_name = wasm_get_type_name(type); +static void write_type(Context* ctx, WabtType type, NextChar next_char) { + const char* type_name = wabt_get_type_name(type); assert(type_name != NULL); write_puts(ctx, type_name, next_char); } static void write_types(Context* ctx, - const WasmTypeVector* types, + const WabtTypeVector* types, const char* name) { if (types->size) { size_t i; @@ -273,20 +273,20 @@ static void write_types(Context* ctx, } static void write_func_sig_space(Context* ctx, - const WasmFuncSignature* func_sig) { + const WabtFuncSignature* func_sig) { write_types(ctx, &func_sig->param_types, "param"); write_types(ctx, &func_sig->result_types, "result"); } -static void write_expr_list(Context* ctx, const WasmExpr* first); +static void write_expr_list(Context* ctx, const WabtExpr* first); -static void write_expr(Context* ctx, const WasmExpr* expr); +static void write_expr(Context* ctx, const WabtExpr* expr); static void write_begin_block(Context* ctx, - const WasmBlock* block, + const WabtBlock* block, const char* text) { write_puts_space(ctx, text); - WasmBool has_label = + WabtBool has_label = write_string_slice_opt(ctx, &block->label, NEXT_CHAR_SPACE); write_types(ctx, &block->sig, NULL); if (!has_label) @@ -299,35 +299,35 @@ static void write_begin_block(Context* ctx, static void write_end_block(Context* ctx) { dedent(ctx); ctx->depth--; - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_END)); + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_END)); } static void write_block(Context* ctx, - const WasmBlock* block, + const WabtBlock* block, const char* start_text) { write_begin_block(ctx, block, start_text); write_expr_list(ctx, block->first); write_end_block(ctx); } -static void write_const(Context* ctx, const WasmConst* const_) { +static void write_const(Context* ctx, const WabtConst* const_) { switch (const_->type) { - case WASM_TYPE_I32: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_I32_CONST)); + case WABT_TYPE_I32: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_I32_CONST)); writef(ctx, "%d", (int32_t)const_->u32); write_newline(ctx, NO_FORCE_NEWLINE); break; - case WASM_TYPE_I64: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_I64_CONST)); + case WABT_TYPE_I64: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_I64_CONST)); writef(ctx, "%" PRId64, (int64_t)const_->u64); write_newline(ctx, NO_FORCE_NEWLINE); break; - case WASM_TYPE_F32: { - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_F32_CONST)); + case WABT_TYPE_F32: { + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_F32_CONST)); char buffer[128]; - wasm_write_float_hex(buffer, 128, const_->f32_bits); + wabt_write_float_hex(buffer, 128, const_->f32_bits); write_puts_space(ctx, buffer); float f32; memcpy(&f32, &const_->f32_bits, sizeof(f32)); @@ -336,10 +336,10 @@ static void write_const(Context* ctx, const WasmConst* const_) { break; } - case WASM_TYPE_F64: { - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_F64_CONST)); + case WABT_TYPE_F64: { + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_F64_CONST)); char buffer[128]; - wasm_write_double_hex(buffer, 128, const_->f64_bits); + wabt_write_double_hex(buffer, 128, const_->f64_bits); write_puts_space(ctx, buffer); double f64; memcpy(&f64, &const_->f64_bits, sizeof(f64)); @@ -354,28 +354,28 @@ static void write_const(Context* ctx, const WasmConst* const_) { } } -static void write_expr(Context* ctx, const WasmExpr* expr) { +static void write_expr(Context* ctx, const WabtExpr* expr) { switch (expr->type) { - case WASM_EXPR_TYPE_BINARY: - write_puts_newline(ctx, wasm_get_opcode_name(expr->binary.opcode)); + case WABT_EXPR_TYPE_BINARY: + write_puts_newline(ctx, wabt_get_opcode_name(expr->binary.opcode)); break; - case WASM_EXPR_TYPE_BLOCK: - write_block(ctx, &expr->block, wasm_get_opcode_name(WASM_OPCODE_BLOCK)); + case WABT_EXPR_TYPE_BLOCK: + write_block(ctx, &expr->block, wabt_get_opcode_name(WABT_OPCODE_BLOCK)); break; - case WASM_EXPR_TYPE_BR: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_BR)); + case WABT_EXPR_TYPE_BR: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_BR)); write_br_var(ctx, &expr->br.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_BR_IF: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_BR_IF)); + case WABT_EXPR_TYPE_BR_IF: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_BR_IF)); write_br_var(ctx, &expr->br_if.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_BR_TABLE: { - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_BR_TABLE)); + case WABT_EXPR_TYPE_BR_TABLE: { + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_BR_TABLE)); size_t i; for (i = 0; i < expr->br_table.targets.size; ++i) write_br_var(ctx, &expr->br_table.targets.data[i], NEXT_CHAR_SPACE); @@ -383,53 +383,53 @@ static void write_expr(Context* ctx, const WasmExpr* expr) { break; } - case WASM_EXPR_TYPE_CALL: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_CALL)); + case WABT_EXPR_TYPE_CALL: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_CALL)); write_var(ctx, &expr->call.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_CALL_INDIRECT: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_CALL_INDIRECT)); + case WABT_EXPR_TYPE_CALL_INDIRECT: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_CALL_INDIRECT)); write_var(ctx, &expr->call_indirect.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_COMPARE: - write_puts_newline(ctx, wasm_get_opcode_name(expr->compare.opcode)); + case WABT_EXPR_TYPE_COMPARE: + write_puts_newline(ctx, wabt_get_opcode_name(expr->compare.opcode)); break; - case WASM_EXPR_TYPE_CONST: + case WABT_EXPR_TYPE_CONST: write_const(ctx, &expr->const_); break; - case WASM_EXPR_TYPE_CONVERT: - write_puts_newline(ctx, wasm_get_opcode_name(expr->convert.opcode)); + case WABT_EXPR_TYPE_CONVERT: + write_puts_newline(ctx, wabt_get_opcode_name(expr->convert.opcode)); break; - case WASM_EXPR_TYPE_DROP: - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_DROP)); + case WABT_EXPR_TYPE_DROP: + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_DROP)); break; - case WASM_EXPR_TYPE_GET_GLOBAL: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_GET_GLOBAL)); + case WABT_EXPR_TYPE_GET_GLOBAL: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_GET_GLOBAL)); write_var(ctx, &expr->get_global.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_GET_LOCAL: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_GET_LOCAL)); + case WABT_EXPR_TYPE_GET_LOCAL: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_GET_LOCAL)); write_var(ctx, &expr->get_local.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_GROW_MEMORY: - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_GROW_MEMORY)); + case WABT_EXPR_TYPE_GROW_MEMORY: + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_GROW_MEMORY)); break; - case WASM_EXPR_TYPE_IF: + case WABT_EXPR_TYPE_IF: write_begin_block(ctx, &expr->if_.true_, - wasm_get_opcode_name(WASM_OPCODE_IF)); + wabt_get_opcode_name(WABT_OPCODE_IF)); write_expr_list(ctx, expr->if_.true_.first); if (expr->if_.false_) { dedent(ctx); - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_ELSE)); + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_ELSE)); indent(ctx); write_newline(ctx, FORCE_NEWLINE); write_expr_list(ctx, expr->if_.false_); @@ -437,65 +437,65 @@ static void write_expr(Context* ctx, const WasmExpr* expr) { write_end_block(ctx); break; - case WASM_EXPR_TYPE_LOAD: - write_puts_space(ctx, wasm_get_opcode_name(expr->load.opcode)); + case WABT_EXPR_TYPE_LOAD: + write_puts_space(ctx, wabt_get_opcode_name(expr->load.opcode)); if (expr->load.offset) writef(ctx, "offset=%" PRIu64, expr->load.offset); - if (!wasm_is_naturally_aligned(expr->load.opcode, expr->load.align)) + if (!wabt_is_naturally_aligned(expr->load.opcode, expr->load.align)) writef(ctx, "align=%u", expr->load.align); write_newline(ctx, NO_FORCE_NEWLINE); break; - case WASM_EXPR_TYPE_LOOP: - write_block(ctx, &expr->loop, wasm_get_opcode_name(WASM_OPCODE_LOOP)); + case WABT_EXPR_TYPE_LOOP: + write_block(ctx, &expr->loop, wabt_get_opcode_name(WABT_OPCODE_LOOP)); break; - case WASM_EXPR_TYPE_CURRENT_MEMORY: - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_CURRENT_MEMORY)); + case WABT_EXPR_TYPE_CURRENT_MEMORY: + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_CURRENT_MEMORY)); break; - case WASM_EXPR_TYPE_NOP: - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_NOP)); + case WABT_EXPR_TYPE_NOP: + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_NOP)); break; - case WASM_EXPR_TYPE_RETURN: - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_RETURN)); + case WABT_EXPR_TYPE_RETURN: + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_RETURN)); break; - case WASM_EXPR_TYPE_SELECT: - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_SELECT)); + case WABT_EXPR_TYPE_SELECT: + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_SELECT)); break; - case WASM_EXPR_TYPE_SET_GLOBAL: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_SET_GLOBAL)); + case WABT_EXPR_TYPE_SET_GLOBAL: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_SET_GLOBAL)); write_var(ctx, &expr->set_global.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_SET_LOCAL: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_SET_LOCAL)); + case WABT_EXPR_TYPE_SET_LOCAL: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_SET_LOCAL)); write_var(ctx, &expr->set_local.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_STORE: - write_puts_space(ctx, wasm_get_opcode_name(expr->store.opcode)); + case WABT_EXPR_TYPE_STORE: + write_puts_space(ctx, wabt_get_opcode_name(expr->store.opcode)); if (expr->store.offset) writef(ctx, "offset=%" PRIu64, expr->store.offset); - if (!wasm_is_naturally_aligned(expr->store.opcode, expr->store.align)) + if (!wabt_is_naturally_aligned(expr->store.opcode, expr->store.align)) writef(ctx, "align=%u", expr->store.align); write_newline(ctx, NO_FORCE_NEWLINE); break; - case WASM_EXPR_TYPE_TEE_LOCAL: - write_puts_space(ctx, wasm_get_opcode_name(WASM_OPCODE_TEE_LOCAL)); + case WABT_EXPR_TYPE_TEE_LOCAL: + write_puts_space(ctx, wabt_get_opcode_name(WABT_OPCODE_TEE_LOCAL)); write_var(ctx, &expr->tee_local.var, NEXT_CHAR_NEWLINE); break; - case WASM_EXPR_TYPE_UNARY: - write_puts_newline(ctx, wasm_get_opcode_name(expr->unary.opcode)); + case WABT_EXPR_TYPE_UNARY: + write_puts_newline(ctx, wabt_get_opcode_name(expr->unary.opcode)); break; - case WASM_EXPR_TYPE_UNREACHABLE: - write_puts_newline(ctx, wasm_get_opcode_name(WASM_OPCODE_UNREACHABLE)); + case WABT_EXPR_TYPE_UNREACHABLE: + write_puts_newline(ctx, wabt_get_opcode_name(WABT_OPCODE_UNREACHABLE)); break; default: @@ -505,13 +505,13 @@ static void write_expr(Context* ctx, const WasmExpr* expr) { } } -static void write_expr_list(Context* ctx, const WasmExpr* first) { - const WasmExpr* expr; +static void write_expr_list(Context* ctx, const WabtExpr* first) { + const WabtExpr* expr; for (expr = first; expr; expr = expr->next) write_expr(ctx, expr); } -static void write_init_expr(Context* ctx, const WasmExpr* expr) { +static void write_init_expr(Context* ctx, const WabtExpr* expr) { if (expr) { write_puts(ctx, "(", NEXT_CHAR_NONE); write_expr(ctx, expr); @@ -523,10 +523,10 @@ static void write_init_expr(Context* ctx, const WasmExpr* expr) { static void write_type_bindings(Context* ctx, const char* prefix, - const WasmFunc* func, - const WasmTypeVector* types, - const WasmBindingHash* bindings) { - wasm_make_type_binding_reverse_mapping(ctx->allocator, types, bindings, + const WabtFunc* func, + const WabtTypeVector* types, + const WabtBindingHash* bindings) { + wabt_make_type_binding_reverse_mapping(ctx->allocator, types, bindings, &ctx->index_to_name); /* named params/locals must be specified by themselves, but nameless @@ -534,22 +534,22 @@ static void write_type_bindings(Context* ctx, * (param $foo i32) * (param i32 i64 f32) */ - WasmBool is_open = WASM_FALSE; + WabtBool is_open = WABT_FALSE; size_t i; for (i = 0; i < types->size; ++i) { if (!is_open) { write_open_space(ctx, prefix); - is_open = WASM_TRUE; + is_open = WABT_TRUE; } - const WasmStringSlice* name = &ctx->index_to_name.data[i]; - WasmBool has_name = name->start != NULL; + const WabtStringSlice* name = &ctx->index_to_name.data[i]; + WabtBool has_name = name->start != NULL; if (has_name) write_string_slice(ctx, name, NEXT_CHAR_SPACE); write_type(ctx, types->data[i], NEXT_CHAR_SPACE); if (has_name) { write_close_space(ctx); - is_open = WASM_FALSE; + is_open = WABT_FALSE; } } if (is_open) @@ -557,12 +557,12 @@ static void write_type_bindings(Context* ctx, } static void write_func(Context* ctx, - const WasmModule* module, - const WasmFunc* func) { + const WabtModule* module, + const WabtFunc* func) { write_open_space(ctx, "func"); write_string_slice_or_index(ctx, &func->name, ctx->func_index++, NEXT_CHAR_SPACE); - if (wasm_decl_has_func_type(&func->decl)) { + if (wabt_decl_has_func_type(&func->decl)) { write_open_space(ctx, "type"); write_var(ctx, &func->decl.type_var, NEXT_CHAR_NONE); write_close_space(ctx); @@ -581,7 +581,7 @@ static void write_func(Context* ctx, write_close_newline(ctx); } -static void write_begin_global(Context* ctx, const WasmGlobal* global) { +static void write_begin_global(Context* ctx, const WabtGlobal* global) { write_open_space(ctx, "global"); write_string_slice_or_index(ctx, &global->name, ctx->global_index++, NEXT_CHAR_SPACE); @@ -594,19 +594,19 @@ static void write_begin_global(Context* ctx, const WasmGlobal* global) { } } -static void write_global(Context* ctx, const WasmGlobal* global) { +static void write_global(Context* ctx, const WabtGlobal* global) { write_begin_global(ctx, global); write_init_expr(ctx, global->init_expr); write_close_newline(ctx); } -static void write_limits(Context* ctx, const WasmLimits* limits) { +static void write_limits(Context* ctx, const WabtLimits* limits) { writef(ctx, "%" PRIu64, limits->initial); if (limits->has_max) writef(ctx, "%" PRIu64, limits->max); } -static void write_table(Context* ctx, const WasmTable* table) { +static void write_table(Context* ctx, const WabtTable* table) { write_open_space(ctx, "table"); write_string_slice_or_index(ctx, &table->name, ctx->table_index++, NEXT_CHAR_SPACE); @@ -615,7 +615,7 @@ static void write_table(Context* ctx, const WasmTable* table) { write_close_newline(ctx); } -static void write_elem_segment(Context* ctx, const WasmElemSegment* segment) { +static void write_elem_segment(Context* ctx, const WabtElemSegment* segment) { write_open_space(ctx, "elem"); write_init_expr(ctx, segment->offset); size_t i; @@ -624,7 +624,7 @@ static void write_elem_segment(Context* ctx, const WasmElemSegment* segment) { write_close_newline(ctx); } -static void write_memory(Context* ctx, const WasmMemory* memory) { +static void write_memory(Context* ctx, const WabtMemory* memory) { write_open_space(ctx, "memory"); write_string_slice_or_index(ctx, &memory->name, ctx->memory_index++, NEXT_CHAR_SPACE); @@ -632,23 +632,23 @@ static void write_memory(Context* ctx, const WasmMemory* memory) { write_close_newline(ctx); } -static void write_data_segment(Context* ctx, const WasmDataSegment* segment) { +static void write_data_segment(Context* ctx, const WabtDataSegment* segment) { write_open_space(ctx, "data"); write_init_expr(ctx, segment->offset); write_quoted_data(ctx, segment->data, segment->size); write_close_newline(ctx); } -static void write_import(Context* ctx, const WasmImport* import) { +static void write_import(Context* ctx, const WabtImport* import) { write_open_space(ctx, "import"); write_quoted_string_slice(ctx, &import->module_name, NEXT_CHAR_SPACE); write_quoted_string_slice(ctx, &import->field_name, NEXT_CHAR_SPACE); switch (import->kind) { - case WASM_EXTERNAL_KIND_FUNC: + case WABT_EXTERNAL_KIND_FUNC: write_open_space(ctx, "func"); write_string_slice_or_index(ctx, &import->func.name, ctx->func_index++, NEXT_CHAR_SPACE); - if (wasm_decl_has_func_type(&import->func.decl)) { + if (wabt_decl_has_func_type(&import->func.decl)) { write_open_space(ctx, "type"); write_var(ctx, &import->func.decl.type_var, NEXT_CHAR_NONE); write_close_space(ctx); @@ -658,39 +658,39 @@ static void write_import(Context* ctx, const WasmImport* import) { write_close_space(ctx); break; - case WASM_EXTERNAL_KIND_TABLE: + case WABT_EXTERNAL_KIND_TABLE: write_table(ctx, &import->table); break; - case WASM_EXTERNAL_KIND_MEMORY: + case WABT_EXTERNAL_KIND_MEMORY: write_memory(ctx, &import->memory); break; - case WASM_EXTERNAL_KIND_GLOBAL: + case WABT_EXTERNAL_KIND_GLOBAL: write_begin_global(ctx, &import->global); write_close_space(ctx); break; - case WASM_NUM_EXTERNAL_KINDS: + case WABT_NUM_EXTERNAL_KINDS: assert(0); break; } write_close_newline(ctx); } -static void write_export(Context* ctx, const WasmExport* export) { +static void write_export(Context* ctx, const WabtExport* export) { static const char* s_kind_names[] = {"func", "table", "memory", "global"}; - WASM_STATIC_ASSERT(WASM_ARRAY_SIZE(s_kind_names) == WASM_NUM_EXTERNAL_KINDS); + WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(s_kind_names) == WABT_NUM_EXTERNAL_KINDS); write_open_space(ctx, "export"); write_quoted_string_slice(ctx, &export->name, NEXT_CHAR_SPACE); - assert(export->kind < WASM_ARRAY_SIZE(s_kind_names)); + assert(export->kind < WABT_ARRAY_SIZE(s_kind_names)); write_open_space(ctx, s_kind_names[export->kind]); write_var(ctx, &export->var, NEXT_CHAR_SPACE); write_close_space(ctx); write_close_newline(ctx); } -static void write_func_type(Context* ctx, const WasmFuncType* func_type) { +static void write_func_type(Context* ctx, const WabtFuncType* func_type) { write_open_space(ctx, "type"); write_string_slice_or_index(ctx, &func_type->name, ctx->func_type_index++, NEXT_CHAR_SPACE); @@ -700,45 +700,45 @@ static void write_func_type(Context* ctx, const WasmFuncType* func_type) { write_close_newline(ctx); } -static void write_start_function(Context* ctx, const WasmVar* start) { +static void write_start_function(Context* ctx, const WabtVar* start) { write_open_space(ctx, "start"); write_var(ctx, start, NEXT_CHAR_NONE); write_close_newline(ctx); } -static void write_module(Context* ctx, const WasmModule* module) { +static void write_module(Context* ctx, const WabtModule* module) { write_open_newline(ctx, "module"); - const WasmModuleField* field; + const WabtModuleField* field; for (field = module->first_field; field != NULL; field = field->next) { switch (field->type) { - case WASM_MODULE_FIELD_TYPE_FUNC: + case WABT_MODULE_FIELD_TYPE_FUNC: write_func(ctx, module, &field->func); break; - case WASM_MODULE_FIELD_TYPE_GLOBAL: + case WABT_MODULE_FIELD_TYPE_GLOBAL: write_global(ctx, &field->global); break; - case WASM_MODULE_FIELD_TYPE_IMPORT: + case WABT_MODULE_FIELD_TYPE_IMPORT: write_import(ctx, &field->import); break; - case WASM_MODULE_FIELD_TYPE_EXPORT: + case WABT_MODULE_FIELD_TYPE_EXPORT: write_export(ctx, &field->export_); break; - case WASM_MODULE_FIELD_TYPE_TABLE: + case WABT_MODULE_FIELD_TYPE_TABLE: write_table(ctx, &field->table); break; - case WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT: + case WABT_MODULE_FIELD_TYPE_ELEM_SEGMENT: write_elem_segment(ctx, &field->elem_segment); break; - case WASM_MODULE_FIELD_TYPE_MEMORY: + case WABT_MODULE_FIELD_TYPE_MEMORY: write_memory(ctx, &field->memory); break; - case WASM_MODULE_FIELD_TYPE_DATA_SEGMENT: + case WABT_MODULE_FIELD_TYPE_DATA_SEGMENT: write_data_segment(ctx, &field->data_segment); break; - case WASM_MODULE_FIELD_TYPE_FUNC_TYPE: + case WABT_MODULE_FIELD_TYPE_FUNC_TYPE: write_func_type(ctx, &field->func_type); break; - case WASM_MODULE_FIELD_TYPE_START: + case WABT_MODULE_FIELD_TYPE_START: write_start_function(ctx, &field->start); break; } @@ -748,17 +748,17 @@ static void write_module(Context* ctx, const WasmModule* module) { write_next_char(ctx); } -WasmResult wasm_write_ast(WasmAllocator* allocator, - WasmWriter* writer, - const WasmModule* module) { +WabtResult wabt_write_ast(WabtAllocator* allocator, + WabtWriter* writer, + const WabtModule* module) { Context ctx; - WASM_ZERO_MEMORY(ctx); + WABT_ZERO_MEMORY(ctx); ctx.allocator = allocator; - ctx.result = WASM_OK; - wasm_init_stream(&ctx.stream, writer, NULL); + ctx.result = WABT_OK; + wabt_init_stream(&ctx.stream, writer, NULL); write_module(&ctx, module); /* the memory for the actual string slice is shared with the module, so we * only need to free the vector */ - wasm_destroy_string_slice_vector(allocator, &ctx.index_to_name); + wabt_destroy_string_slice_vector(allocator, &ctx.index_to_name); return ctx.result; } |