diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binary-writer.c | 6 | ||||
-rw-r--r-- | src/binary.c | 23 | ||||
-rw-r--r-- | src/binary.h | 12 |
3 files changed, 36 insertions, 5 deletions
diff --git a/src/binary-writer.c b/src/binary-writer.c index c71ea75a..7d89792c 100644 --- a/src/binary-writer.c +++ b/src/binary-writer.c @@ -36,10 +36,6 @@ #define ALLOC_FAILURE \ fprintf(stderr, "%s:%d: allocation failed\n", __FILE__, __LINE__) -#define V(NAME, code) [code] = #NAME, -static const char* s_section_name[] = {WASM_FOREACH_BINARY_SECTION(V)}; -#undef V - typedef struct Context { WasmAllocator* allocator; WasmStream stream; @@ -228,7 +224,7 @@ static void begin_known_section(Context* ctx, assert(ctx->last_section_leb_size_guess == 0); char desc[100]; wasm_snprintf(desc, sizeof(desc), "section \"%s\" (%u)", - s_section_name[section_code], section_code); + wasm_get_section_name(section_code), section_code); write_header(ctx, desc, PRINT_HEADER_NO_INDEX); wasm_write_u8(&ctx->stream, section_code, "section code"); ctx->last_section_leb_size_guess = leb_size_guess; diff --git a/src/binary.c b/src/binary.c new file mode 100644 index 00000000..40542ed8 --- /dev/null +++ b/src/binary.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "binary.h" + +const char* g_wasm_section_name[] = { +#define V(NAME, code) #NAME, + WASM_FOREACH_BINARY_SECTION(V) +#undef V +}; diff --git a/src/binary.h b/src/binary.h index 632cd3e0..e2164780 100644 --- a/src/binary.h +++ b/src/binary.h @@ -17,11 +17,14 @@ #ifndef WASM_BINARY_H_ #define WASM_BINARY_H_ +#include "common.h" + #define WASM_BINARY_MAGIC 0x6d736100 #define WASM_BINARY_VERSION 0x0d #define WASM_BINARY_LIMITS_HAS_MAX_FLAG 0x1 #define WASM_BINARY_SECTION_NAME "name" +#define WASM_BINARY_SECTION_RELOC "reloc" #define WASM_FOREACH_BINARY_SECTION(V) \ V(CUSTOM, 0) \ @@ -46,4 +49,13 @@ typedef enum WasmBinarySection { } WasmBinarySection; /* clang-format on */ +WASM_EXTERN_C_BEGIN +extern const char* g_wasm_section_name[]; + +static WASM_INLINE const char* wasm_get_section_name(WasmBinarySection sec) { + assert(sec < WASM_NUM_BINARY_SECTIONS); + return g_wasm_section_name[sec]; +} +WASM_EXTERN_C_END + #endif /* WASM_BINARY_H_ */ |