summaryrefslogtreecommitdiff
path: root/src/wasm-binary-reader-ast.c
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2016-07-06 15:25:09 -0700
committerGitHub <noreply@github.com>2016-07-06 15:25:09 -0700
commitb487574ba29dd85c64be6aa1406b58084b14b8b4 (patch)
tree68141591b2004bfa860b107777f6bc695a18c30f /src/wasm-binary-reader-ast.c
parent35600ece919c127db39e625be103a149746fb7b1 (diff)
downloadwabt-b487574ba29dd85c64be6aa1406b58084b14b8b4.tar.gz
wabt-b487574ba29dd85c64be6aa1406b58084b14b8b4.tar.bz2
wabt-b487574ba29dd85c64be6aa1406b58084b14b8b4.zip
functions have an implicit block scope (#91)
`(func (br 0))` is valid, because the function introduces an implicit block scope. This change also updates the testsuite (which has tests for this behavior).
Diffstat (limited to 'src/wasm-binary-reader-ast.c')
-rw-r--r--src/wasm-binary-reader-ast.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/wasm-binary-reader-ast.c b/src/wasm-binary-reader-ast.c
index 97e3fd5b..b29c06e8 100644
--- a/src/wasm-binary-reader-ast.c
+++ b/src/wasm-binary-reader-ast.c
@@ -68,13 +68,15 @@ static const char* s_opcode_name[] = {WASM_FOREACH_OPCODE(V)};
#endif
typedef enum LabelType {
+ LABEL_TYPE_FUNC,
LABEL_TYPE_BLOCK,
LABEL_TYPE_IF,
LABEL_TYPE_ELSE,
LABEL_TYPE_LOOP,
} LabelType;
-static const char* s_label_type_name[] = {"block", "if", "else", "loop"};
+static const char* s_label_type_name[] = {"func", "block", "if", "else",
+ "loop"};
typedef struct LabelNode {
LabelType type;
@@ -421,12 +423,14 @@ static WasmResult begin_function_body(uint32_t index, void* user_data) {
ctx->current_func = ctx->module->funcs.data[index];
ctx->expr_stack_size = 0;
LOGF("func %d\n", index);
+ push_label(ctx, LABEL_TYPE_FUNC, NULL);
return WASM_OK;
}
static WasmResult end_function_body(uint32_t index, void* user_data) {
Context* ctx = user_data;
pop_into_expr_list(ctx, NULL, &ctx->current_func->first_expr);
+ CHECK_RESULT(pop_label(ctx));
ctx->current_func = NULL;
return WASM_OK;
}
@@ -1092,7 +1096,8 @@ static WasmBinaryReader s_binary_reader = {
};
static void wasm_destroy_label_node(WasmAllocator* allocator, LabelNode* node) {
- wasm_destroy_expr(allocator, node->expr);
+ if (node->expr)
+ wasm_destroy_expr(allocator, node->expr);
}
WasmResult wasm_read_binary_ast(struct WasmAllocator* allocator,