diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sexpr-wasm.c | 5 | ||||
-rw-r--r-- | src/wasm-binary-writer.c | 977 | ||||
-rw-r--r-- | src/wasm-check.c | 86 | ||||
-rw-r--r-- | src/wasm-lexer.c | 648 | ||||
-rw-r--r-- | src/wasm-lexer.l | 188 | ||||
-rw-r--r-- | src/wasm-parser.c | 368 | ||||
-rw-r--r-- | src/wasm-parser.y | 8 | ||||
-rw-r--r-- | src/wasm.h | 204 |
8 files changed, 1812 insertions, 672 deletions
diff --git a/src/sexpr-wasm.c b/src/sexpr-wasm.c index c0e20d3f..be3c920f 100644 --- a/src/sexpr-wasm.c +++ b/src/sexpr-wasm.c @@ -180,6 +180,11 @@ int main(int argc, char** argv) { if (result == WASM_OK) { result |= wasm_check_script(&parser.script); + + if (result == WASM_OK) { + WasmBinaryWriter writer; + result |= wasm_write_binary(&writer, &parser.script); + } } return result; diff --git a/src/wasm-binary-writer.c b/src/wasm-binary-writer.c new file mode 100644 index 00000000..760b4ee7 --- /dev/null +++ b/src/wasm-binary-writer.c @@ -0,0 +1,977 @@ +#include <assert.h> +#include <ctype.h> +#include <memory.h> +#include <stdint.h> +#include <stdio.h> + +#include "wasm.h" +#include "wasm-internal.h" + +#define DEFAULT_MEMORY_EXPORT 1 +#define DUMP_OCTETS_PER_LINE 16 +#define DUMP_OCTETS_PER_GROUP 2 + +#define SEGMENT_SIZE 13 +#define SEGMENT_OFFSET_OFFSET 4 + +#define IMPORT_SIZE 7 +#define IMPORT_NAME_OFFSET 3 + +#define FUNC_NAME_OFFSET 3 + +typedef enum WasmSectionType { + WASM_SECTION_MEMORY = 0, + WASM_SECTION_SIGNATURES = 1, + WASM_SECTION_FUNCTIONS = 2, + WASM_SECTION_GLOBALS = 3, + WASM_SECTION_DATA_SEGMENTS = 4, + WASM_SECTION_FUNCTION_TABLE = 5, + WASM_SECTION_END = 6, +} WasmSectionType; + +enum { + WASM_FUNCTION_FLAG_NAME = 1, + WASM_FUNCTION_FLAG_IMPORT = 2, + WASM_FUNCTION_FLAG_LOCALS = 4, + WASM_FUNCTION_FLAG_EXPORT = 8, +}; +typedef uint8_t WasmFunctionFlags; + +typedef enum WasmTypeV8 { + WASM_TYPE_V8_VOID, + WASM_TYPE_V8_I32, + WASM_TYPE_V8_I64, + WASM_TYPE_V8_F32, + WASM_TYPE_V8_F64, + WASM_NUM_V8_TYPES, +} WasmTypeV8; + +#define FOREACH_OPCODE(V) \ + V(NOP, 0x00) \ + V(BLOCK, 0x01) \ + V(LOOP, 0x02) \ + V(IF, 0x03) \ + V(IF_THEN, 0x04) \ + V(SELECT, 0x05) \ + V(BR, 0x06) \ + V(BR_IF, 0x07) \ + V(TABLESWITCH, 0x08) \ + V(RETURN, 0x14) \ + V(UNREACHABLE, 0x15) \ + V(I8_CONST, 0x09) \ + V(I32_CONST, 0x0a) \ + V(I64_CONST, 0x0b) \ + V(F64_CONST, 0x0c) \ + V(F32_CONST, 0x0d) \ + V(GET_LOCAL, 0x0e) \ + V(SET_LOCAL, 0x0f) \ + V(LOAD_GLOBAL, 0x10) \ + V(STORE_GLOBAL, 0x11) \ + V(CALL_FUNCTION, 0x12) \ + V(CALL_INDIRECT, 0x13) \ + V(I32_LOAD_MEM8_S, 0x20) \ + V(I32_LOAD_MEM8_U, 0x21) \ + V(I32_LOAD_MEM16_S, 0x22) \ + V(I32_LOAD_MEM16_U, 0x23) \ + V(I64_LOAD_MEM8_S, 0x24) \ + V(I64_LOAD_MEM8_U, 0x25) \ + V(I64_LOAD_MEM16_S, 0x26) \ + V(I64_LOAD_MEM16_U, 0x27) \ + V(I64_LOAD_MEM32_S, 0x28) \ + V(I64_LOAD_MEM32_U, 0x29) \ + V(I32_LOAD_MEM, 0x2a) \ + V(I64_LOAD_MEM, 0x2b) \ + V(F32_LOAD_MEM, 0x2c) \ + V(F64_LOAD_MEM, 0x2d) \ + V(I32_STORE_MEM8, 0x2e) \ + V(I32_STORE_MEM16, 0x2f) \ + V(I64_STORE_MEM8, 0x30) \ + V(I64_STORE_MEM16, 0x31) \ + V(I64_STORE_MEM32, 0x32) \ + V(I32_STORE_MEM, 0x33) \ + V(I64_STORE_MEM, 0x34) \ + V(F32_STORE_MEM, 0x35) \ + V(F64_STORE_MEM, 0x36) \ + V(MEMORY_SIZE, 0x3b) \ + V(RESIZE_MEM_L, 0x39) \ + V(RESIZE_MEM_H, 0x3a) \ + V(I32_ADD, 0x40) \ + V(I32_SUB, 0x41) \ + V(I32_MUL, 0x42) \ + V(I32_DIV_S, 0x43) \ + V(I32_DIV_U, 0x44) \ + V(I32_REM_S, 0x45) \ + V(I32_REM_U, 0x46) \ + V(I32_AND, 0x47) \ + V(I32_OR, 0x48) \ + V(I32_XOR, 0x49) \ + V(I32_SHL, 0x4a) \ + V(I32_SHR_U, 0x4b) \ + V(I32_SHR_S, 0x4c) \ + V(I32_EQ, 0x4d) \ + V(I32_NE, 0x4e) \ + V(I32_LT_S, 0x4f) \ + V(I32_LE_S, 0x50) \ + V(I32_LT_U, 0x51) \ + V(I32_LE_U, 0x52) \ + V(I32_GT_S, 0x53) \ + V(I32_GE_S, 0x54) \ + V(I32_GT_U, 0x55) \ + V(I32_GE_U, 0x56) \ + V(I32_CLZ, 0x57) \ + V(I32_CTZ, 0x58) \ + V(I32_POPCNT, 0x59) \ + V(BOOL_NOT, 0x5a) \ + V(I64_ADD, 0x5b) \ + V(I64_SUB, 0x5c) \ + V(I64_MUL, 0x5d) \ + V(I64_DIV_S, 0x5e) \ + V(I64_DIV_U, 0x5f) \ + V(I64_REM_S, 0x60) \ + V(I64_REM_U, 0x61) \ + V(I64_AND, 0x62) \ + V(I64_OR, 0x63) \ + V(I64_XOR, 0x64) \ + V(I64_SHL, 0x65) \ + V(I64_SHR_U, 0x66) \ + V(I64_SHR_S, 0x67) \ + V(I64_EQ, 0x68) \ + V(I64_NE, 0x69) \ + V(I64_LT_S, 0x6a) \ + V(I64_LE_S, 0x6b) \ + V(I64_LT_U, 0x6c) \ + V(I64_LE_U, 0x6d) \ + V(I64_GT_S, 0x6e) \ + V(I64_GE_S, 0x6f) \ + V(I64_GT_U, 0x70) \ + V(I64_GE_U, 0x71) \ + V(I64_CLZ, 0x72) \ + V(I64_CTZ, 0x73) \ + V(I64_POPCNT, 0x74) \ + V(F32_ADD, 0x75) \ + V(F32_SUB, 0x76) \ + V(F32_MUL, 0x77) \ + V(F32_DIV, 0x78) \ + V(F32_MIN, 0x79) \ + V(F32_MAX, 0x7a) \ + V(F32_ABS, 0x7b) \ + V(F32_NEG, 0x7c) \ + V(F32_COPYSIGN, 0x7d) \ + V(F32_CEIL, 0x7e) \ + V(F32_FLOOR, 0x7f) \ + V(F32_TRUNC, 0x80) \ + V(F32_NEAREST_INT, 0x81) \ + V(F32_SQRT, 0x82) \ + V(F32_EQ, 0x83) \ + V(F32_NE, 0x84) \ + V(F32_LT, 0x85) \ + V(F32_LE, 0x86) \ + V(F32_GT, 0x87) \ + V(F32_GE, 0x88) \ + V(F64_ADD, 0x89) \ + V(F64_SUB, 0x8a) \ + V(F64_MUL, 0x8b) \ + V(F64_DIV, 0x8c) \ + V(F64_MIN, 0x8d) \ + V(F64_MAX, 0x8e) \ + V(F64_ABS, 0x8f) \ + V(F64_NEG, 0x90) \ + V(F64_COPYSIGN, 0x91) \ + V(F64_CEIL, 0x92) \ + V(F64_FLOOR, 0x93) \ + V(F64_TRUNC, 0x94) \ + V(F64_NEAREST_INT, 0x95) \ + V(F64_SQRT, 0x96) \ + V(F64_EQ, 0x97) \ + V(F64_NE, 0x98) \ + V(F64_LT, 0x99) \ + V(F64_LE, 0x9a) \ + V(F64_GT, 0x9b) \ + V(F64_GE, 0x9c) \ + V(I32_SCONVERT_F32, 0x9d) \ + V(I32_SCONVERT_F64, 0x9e) \ + V(I32_UCONVERT_F32, 0x9f) \ + V(I32_UCONVERT_F64, 0xa0) \ + V(I32_CONVERT_I64, 0xa1) \ + V(I64_SCONVERT_F32, 0xa2) \ + V(I64_SCONVERT_F64, 0xa3) \ + V(I64_UCONVERT_F32, 0xa4) \ + V(I64_UCONVERT_F64, 0xa5) \ + V(I64_SCONVERT_I32, 0xa6) \ + V(I64_UCONVERT_I32, 0xa7) \ + V(F32_SCONVERT_I32, 0xa8) \ + V(F32_UCONVERT_I32, 0xa9) \ + V(F32_SCONVERT_I64, 0xaa) \ + V(F32_UCONVERT_I64, 0xab) \ + V(F32_CONVERT_F64, 0xac) \ + V(F32_REINTERPRET_I32, 0xad) \ + V(F64_SCONVERT_I32, 0xae) \ + V(F64_UCONVERT_I32, 0xaf) \ + V(F64_SCONVERT_I64, 0xb0) \ + V(F64_UCONVERT_I64, 0xb1) \ + V(F64_CONVERT_F32, 0xb2) \ + V(F64_REINTERPRET_I64, 0xb3) \ + V(I32_REINTERPRET_F32, 0xb4) \ + V(I64_REINTERPRET_F64, 0xb5) + +typedef enum WasmOpcode { +#define V(name, code) WASM_OPCODE_##name = code, + FOREACH_OPCODE(V) +#undef V +} WasmOpcode; + +#define V(name, code) [code] = "OPCODE_" #name, +static const char* s_opcode_names[] = { + FOREACH_OPCODE(V) +}; +#undef V + +static uint8_t s_binary_opcodes[] = { + WASM_OPCODE_F32_ADD, WASM_OPCODE_F32_COPYSIGN, WASM_OPCODE_F32_DIV, + WASM_OPCODE_F32_MAX, WASM_OPCODE_F32_MIN, WASM_OPCODE_F32_MUL, + WASM_OPCODE_F32_SUB, WASM_OPCODE_F64_ADD, WASM_OPCODE_F64_COPYSIGN, + WASM_OPCODE_F64_DIV, WASM_OPCODE_F64_MAX, WASM_OPCODE_F64_MIN, + WASM_OPCODE_F64_MUL, WASM_OPCODE_F64_SUB, WASM_OPCODE_I32_ADD, + WASM_OPCODE_I32_AND, WASM_OPCODE_I32_DIV_S, WASM_OPCODE_I32_DIV_U, + WASM_OPCODE_I32_MUL, WASM_OPCODE_I32_OR, WASM_OPCODE_I32_REM_S, + WASM_OPCODE_I32_REM_U, WASM_OPCODE_I32_SHL, WASM_OPCODE_I32_SHR_S, + WASM_OPCODE_I32_SHR_U, WASM_OPCODE_I32_SUB, WASM_OPCODE_I32_XOR, + WASM_OPCODE_I64_ADD, WASM_OPCODE_I64_AND, WASM_OPCODE_I64_DIV_S, + WASM_OPCODE_I64_DIV_U, WASM_OPCODE_I64_MUL, WASM_OPCODE_I64_OR, + WASM_OPCODE_I64_REM_S, WASM_OPCODE_I64_REM_U, WASM_OPCODE_I64_SHL, + WASM_OPCODE_I64_SHR_S, WASM_OPCODE_I64_SHR_U, WASM_OPCODE_I64_SUB, + WASM_OPCODE_I64_XOR, +}; + +static uint8_t s_compare_opcodes[] = { + WASM_OPCODE_F32_EQ, WASM_OPCODE_F32_GE, WASM_OPCODE_F32_GT, + WASM_OPCODE_F32_LE, WASM_OPCODE_F32_LT, WASM_OPCODE_F32_NE, + WASM_OPCODE_F64_EQ, WASM_OPCODE_F64_GE, WASM_OPCODE_F64_GT, + WASM_OPCODE_F64_LE, WASM_OPCODE_F64_LT, WASM_OPCODE_F64_NE, + WASM_OPCODE_I32_EQ, WASM_OPCODE_I32_GE_S, WASM_OPCODE_I32_GE_U, + WASM_OPCODE_I32_GT_S, WASM_OPCODE_I32_GT_U, WASM_OPCODE_I32_LE_S, + WASM_OPCODE_I32_LE_U, WASM_OPCODE_I32_LT_S, WASM_OPCODE_I32_LT_U, + WASM_OPCODE_I32_NE, WASM_OPCODE_I64_EQ, WASM_OPCODE_I64_GE_S, + WASM_OPCODE_I64_GE_U, WASM_OPCODE_I64_GT_S, WASM_OPCODE_I64_GT_U, + WASM_OPCODE_I64_LE_S, WASM_OPCODE_I64_LE_U, WASM_OPCODE_I64_LT_S, + WASM_OPCODE_I64_LT_U, WASM_OPCODE_I64_NE, +}; + +static uint8_t s_convert_opcodes[] = { + WASM_OPCODE_F32_SCONVERT_I32, WASM_OPCODE_F32_SCONVERT_I64, + WASM_OPCODE_F32_UCONVERT_I32, WASM_OPCODE_F32_UCONVERT_I64, + WASM_OPCODE_F32_CONVERT_F64, WASM_OPCODE_F64_SCONVERT_I32, + WASM_OPCODE_F64_SCONVERT_I64, WASM_OPCODE_F64_UCONVERT_I32, + WASM_OPCODE_F64_UCONVERT_I64, WASM_OPCODE_F64_CONVERT_F32, + WASM_OPCODE_I32_SCONVERT_F32, WASM_OPCODE_I32_SCONVERT_F64, + WASM_OPCODE_I32_UCONVERT_F32, WASM_OPCODE_I32_UCONVERT_F64, + WASM_OPCODE_I32_CONVERT_I64, WASM_OPCODE_I64_SCONVERT_I32, + WASM_OPCODE_I64_UCONVERT_I32, WASM_OPCODE_I64_SCONVERT_F32, + WASM_OPCODE_I64_SCONVERT_F64, WASM_OPCODE_I64_UCONVERT_F32, + WASM_OPCODE_I64_UCONVERT_F64, +}; + +static uint8_t s_mem_opcodes[] = { + WASM_OPCODE_F32_LOAD_MEM, + WASM_OPCODE_F32_STORE_MEM, + WASM_OPCODE_F64_LOAD_MEM, + WASM_OPCODE_F64_STORE_MEM, + WASM_OPCODE_I32_LOAD_MEM, + WASM_OPCODE_I32_LOAD_MEM8_S, + WASM_OPCODE_I32_LOAD_MEM8_U, + WASM_OPCODE_I32_LOAD_MEM16_S, + WASM_OPCODE_I32_LOAD_MEM16_U, + WASM_OPCODE_I32_STORE_MEM, + WASM_OPCODE_I32_STORE_MEM8, + WASM_OPCODE_I32_STORE_MEM16, + WASM_OPCODE_I64_LOAD_MEM, + WASM_OPCODE_I64_LOAD_MEM8_S, + WASM_OPCODE_I64_LOAD_MEM8_U, + WASM_OPCODE_I64_LOAD_MEM16_S, + WASM_OPCODE_I64_LOAD_MEM16_U, + WASM_OPCODE_I64_LOAD_MEM32_S, + WASM_OPCODE_I64_LOAD_MEM32_U, + WASM_OPCODE_I64_STORE_MEM, + WASM_OPCODE_I64_STORE_MEM8, + WASM_OPCODE_I64_STORE_MEM16, + WASM_OPCODE_I64_STORE_MEM32, +}; + +static uint8_t s_unary_opcodes[] = { + WASM_OPCODE_F32_ABS, WASM_OPCODE_F32_CEIL, + WASM_OPCODE_F32_FLOOR, WASM_OPCODE_F32_NEAREST_INT, + WASM_OPCODE_F32_NEG, WASM_OPCODE_F32_SQRT, + WASM_OPCODE_F32_TRUNC, WASM_OPCODE_F64_ABS, + WASM_OPCODE_F64_CEIL, WASM_OPCODE_F64_FLOOR, + WASM_OPCODE_F64_NEAREST_INT, WASM_OPCODE_F64_NEG, + WASM_OPCODE_F64_SQRT, WASM_OPCODE_F64_TRUNC, + WASM_OPCODE_I32_CLZ, WASM_OPCODE_I32_CTZ, + WASM_OPCODE_BOOL_NOT, WASM_OPCODE_I32_POPCNT, + WASM_OPCODE_I64_CLZ, WASM_OPCODE_I64_CTZ, + WASM_OPCODE_I64_POPCNT, +}; + +typedef struct WasmWriteContext { + WasmBinaryWriter* writer; + size_t offset; + int verbose; + + int* import_sig_indexes; + int* func_sig_indexes; + int* remapped_locals; + size_t* func_offsets; +} WasmWriteContext; + +DECLARE_VECTOR(func_signature, WasmFuncSignature); +DEFINE_VECTOR(func_signature, WasmFuncSignature); + +static uint32_t log_two_u32(uint32_t x) { + if (!x) + return 0; + return sizeof(unsigned int) * 8 - __builtin_clz(x - 1); +} + +static WasmTypeV8 wasm_type_to_v8_type(WasmType type) { + switch (type) { + case WASM_TYPE_VOID: + return WASM_TYPE_V8_VOID; + case WASM_TYPE_I32: + return WASM_TYPE_V8_I32; + case WASM_TYPE_I64: + return WASM_TYPE_V8_I64; + case WASM_TYPE_F32: + return WASM_TYPE_V8_F32; + case WASM_TYPE_F64: + return WASM_TYPE_V8_F64; + default: + FATAL("v8-native does not support type %d\n", type); + } +} + +static void dump_memory(const void* start, + size_t size, + size_t offset, + int print_chars, + const char* desc) { + /* mimic xxd output */ + const uint8_t* p = start; + const uint8_t* end = p + size; + while (p < end) { + const uint8_t* line = p; + const uint8_t* line_end = p + DUMP_OCTETS_PER_LINE; + printf("%07x: ", (int)((void*)p - start + offset)); + while (p < line_end) { + int i; + for (i = 0; i < DUMP_OCTETS_PER_GROUP; ++i, ++p) { + if (p < end) { + printf("%02x", *p); + } else { + putchar(' '); + putchar(' '); + } + } + putchar(' '); + } + + putchar(' '); + p = line; + int i; + for (i = 0; i < DUMP_OCTETS_PER_LINE && p < end; ++i, ++p) + if (print_chars) + printf("%c", isprint(*p) ? *p : '.'); + /* if there are multiple lines, only print the desc on the last one */ + if (p >= end && desc) + printf(" ; %s", desc); + putchar('\n'); + } +} + +static void print_header(WasmWriteContext* ctx, const char* name, int index) { + if (1 || ctx->verbose) + printf("; %s %d\n", name, index); +} + +static void out_data(WasmWriteContext* ctx, + size_t offset, + const void* src, + size_t size, + const char* desc) { + if (ctx->writer->log_writes) + dump_memory(src, size, offset, 0, desc); + if (ctx->writer->write_data) + ctx->writer->write_data(offset, src, size, ctx->writer->user_data); +} + +/* TODO(binji): endianness */ +#define OUT_TYPE(name, ctype) \ + static void out_##name(WasmWriteContext* ctx, ctype value, \ + const char* desc) { \ + out_data(ctx, ctx->offset, &value, sizeof(value), desc); \ + ctx->offset += sizeof(value); \ + } + +OUT_TYPE(u8, uint8_t) +OUT_TYPE(u16, uint16_t) +OUT_TYPE(u32, uint32_t) +OUT_TYPE(u64, uint64_t) +OUT_TYPE(f32, float) +OUT_TYPE(f64, double) + +#undef OUT_TYPE + +#define OUT_AT_TYPE(name, ctype) \ + static void out_##name##_at(WasmWriteContext* ctx, uint32_t offset, \ + ctype value, const char* desc) { \ + out_data(ctx, offset, &value, sizeof(value), desc); \ + } + +OUT_AT_TYPE(u8, uint8_t) +OUT_AT_TYPE(u16, uint16_t) +OUT_AT_TYPE(u32, uint32_t) + +#undef OUT_AT_TYPE + +/* returns the number of bytes written */ +static int out_leb128_at(WasmWriteContext* ctx, + size_t offset, + uint32_t value, + const char* desc) { + uint8_t data[5]; /* max 5 bytes */ + int i = 0; + do { + assert(i < 5); + data[i] = value & 0x7f; + value >>= 7; + if (value) + data[i] |= 0x80; + ++i; + } while (value); + out_data(ctx, offset, data, i, desc); + return i; +} + +static void out_leb128(WasmWriteContext* ctx, + uint32_t value, + const char* desc) { + ctx->offset += out_leb128_at(ctx, ctx->offset, value, desc); +} + +static void out_str(WasmWriteContext* ctx, + const char* s, + size_t length, + const char* desc) { + out_data(ctx, ctx->offset, s, length, desc); + ctx->offset += length; + out_u8(ctx, 0, "\\0"); +} + +static void out_opcode(WasmWriteContext* ctx, uint8_t opcode) { + out_u8(ctx, opcode, s_opcode_names[opcode]); +} + +static uint8_t binary_opcode(WasmBinaryOp* op) { + assert(op->op_type >= 0 && op->op_type < ARRAY_SIZE(s_binary_opcodes)); + return s_binary_opcodes[op->op_type]; +} + +static uint8_t compare_opcode(WasmCompareOp* op) { + assert(op->op_type >= 0 && op->op_type < ARRAY_SIZE(s_compare_opcodes)); + return s_compare_opcodes[op->op_type]; +} + +static uint8_t convert_opcode(WasmConvertOp* op) { + assert(op->op_type >= 0 && op->op_type < ARRAY_SIZE(s_convert_opcodes)); + return s_convert_opcodes[op->op_type]; +} + +static uint8_t mem_opcode(WasmMemOp* op) { + assert(op->op_type >= 0 && op->op_type < ARRAY_SIZE(s_mem_opcodes)); + return s_mem_opcodes[op->op_type]; +} + +static uint8_t unary_opcode(WasmUnaryOp* op) { + assert(op->op_type >= 0 && op->op_type < ARRAY_SIZE(s_unary_opcodes)); + return s_unary_opcodes[op->op_type]; +} + +static int find_func_signature(WasmFuncSignatureVector* sigs, + WasmType result_type, + WasmTypeVector* param_types) { + int i; + for (i = 0; i < sigs->size; ++i) { + WasmFuncSignature* sig2 = &sigs->data[i]; + if (sig2->result_type != result_type) + continue; + if (sig2->param_types.size != param_types->size) + continue; + int j; + for (j = 0; j < param_types->size; ++j) { + if (sig2->param_types.data[j] != param_types->data[j]) + break; + } + if (j == param_types->size) + return i; + } + return -1; +} + +static void get_func_signatures(WasmWriteContext* ctx, + WasmModule* module, + WasmFuncSignatureVector* sigs) { + /* function types are not deduped; we don't want the signature index to match + if they were specified separately in the source */ + int i; + for (i = 0; i < module->func_types.size; ++i) { + WasmFuncType* func_type = module->func_types.data[i]; + WasmFuncSignature* sig = wasm_append_func_signature(sigs); + sig->result_type = func_type->sig.result_type; + wasm_extend_types(&sig->param_types, &func_type->sig.param_types); + } + + ctx->import_sig_indexes = + realloc(ctx->import_sig_indexes, module->imports.size * sizeof(int)); + for (i = 0; i < module->imports.size; ++i) { + WasmImport* import = module->imports.data[i]; + int index; + if (import->import_type == WASM_IMPORT_HAS_FUNC_SIGNATURE) { + index = find_func_signature(sigs, import->func_sig.result_type, + &import->func_sig.param_types); + if (index == -1) { + index = sigs->size; + WasmFuncSignature* sig = wasm_append_func_signature(sigs); + sig->result_type = import->func_sig.result_type; + wasm_extend_types(&sig->param_types, &import->func_sig.param_types); + } + } else { + assert(import->import_type == WASM_IMPORT_HAS_TYPE); + WasmFuncType* func_type = + wasm_get_func_type_by_var(module, &import->type_var); + assert(func_type); + index = find_func_signature(sigs, func_type->sig.result_type, + &func_type->sig.param_types); + assert(index != -1); + } + + ctx->import_sig_indexes[i] = index; + } + + ctx->func_sig_indexes = + realloc(ctx->func_sig_indexes, module->funcs.size * sizeof(int)); + for (i = 0; i < module->funcs.size; ++i) { + WasmFunc* func = module->funcs.data[i]; + int index; + if (func->flags & WASM_FUNC_FLAG_HAS_SIGNATURE) { + index = find_func_signature(sigs, func->result_type, &func->params.types); + if (index == -1) { + index = sigs->size; + WasmFuncSignature* sig = wasm_append_func_signature(sigs); + sig->result_type = func->result_type; + wasm_extend_types(&sig->param_types, &func->params.types); + } + } else { + assert(func->flags & WASM_FUNC_FLAG_HAS_FUNC_TYPE); + WasmFuncType* func_type = + wasm_get_func_type_by_var(module, &func->type_var); + assert(func_type); + index = find_func_signature(sigs, func_type->sig.result_type, + &func_type->sig.param_types); + assert(index != -1); + } + + ctx->func_sig_indexes[i] = index; + } +} + +static void remap_locals(WasmWriteContext* ctx, WasmFunc* func) { + ctx->remapped_locals = + realloc(ctx->remapped_locals, func->locals.types.size * sizeof(int)); + + int max[WASM_NUM_V8_TYPES] = {}; + int i; + for (i = 0; i < func->locals.types.size; ++i) { + WasmType type = func->locals.types.data[i]; + max[wasm_type_to_v8_type(type)]++; + } + + /* Args don't need remapping */ + for (i = 0; i < func->params.types.size; ++i) + ctx->remapped_locals[i] = i; + + int start[WASM_NUM_V8_TYPES]; + start[WASM_TYPE_V8_I32] = func->params.types.size; + start[WASM_TYPE_V8_I64] = start[WASM_TYPE_V8_I32] + max[WASM_TYPE_V8_I32]; + start[WASM_TYPE_V8_F32] = start[WASM_TYPE_V8_I64] + max[WASM_TYPE_V8_I64]; + start[WASM_TYPE_V8_F64] = start[WASM_TYPE_V8_F32] + max[WASM_TYPE_V8_F32]; + + int seen[WASM_NUM_V8_TYPES] = {}; + for (i = 0; i < func->locals.types.size; ++i) { + WasmType type = func->locals.types.data[i]; + WasmTypeV8 v8_type = wasm_type_to_v8_type(type); + ctx->remapped_locals[i] = start[v8_type] + seen[v8_type]++; + } +} + +static WasmResult write_expr_list(WasmWriteContext* ctx, + WasmModule* module, + WasmFunc* func, + WasmExprPtrVector* exprs); + +static WasmResult write_expr(WasmWriteContext* ctx, + WasmModule* module, + WasmFunc* func, + WasmExpr* expr) { + WasmResult result = WASM_OK; + switch (expr->type) { + case WASM_EXPR_TYPE_BINARY: + out_opcode(ctx, binary_opcode(&expr->binary.op)); + result |= write_expr(ctx, module, func, expr->binary.left); + result |= write_expr(ctx, module, func, expr->binary.right); + break; + case WASM_EXPR_TYPE_BLOCK: + out_opcode(ctx, WASM_OPCODE_BLOCK); + out_u8(ctx, expr->block.exprs.size, "num expressions"); + result |= write_expr_list(ctx, module, func, &expr->block.exprs); + break; + case WASM_EXPR_TYPE_BR: + break; + case WASM_EXPR_TYPE_BR_IF: + break; + case WASM_EXPR_TYPE_CALL: + break; + case WASM_EXPR_TYPE_CALL_IMPORT: + break; + case WASM_EXPR_TYPE_CALL_INDIRECT: + break; + case WASM_EXPR_TYPE_CAST: + break; + case WASM_EXPR_TYPE_COMPARE: + out_opcode(ctx, compare_opcode(&expr->compare.op)); + result |= write_expr(ctx, module, func, expr->compare.left); + result |= write_expr(ctx, module, func, expr->compare.right); + break; + case WASM_EXPR_TYPE_CONST: + switch (expr->const_.type) { + case WASM_TYPE_I32: { + int32_t i32; + memcpy(&i32, &expr->const_.u32, sizeof(i32)); + if (i32 >= -128 && i32 <= 127) { + out_opcode(ctx, WASM_OPCODE_I8_CONST); + out_u8(ctx, expr->const_.u32, "u8 literal"); + } else { + out_opcode(ctx, WASM_OPCODE_I32_CONST); + out_u32(ctx, expr->const_.u32, "u32 literal"); + } + break; + } + case WASM_TYPE_I64: + out_opcode(ctx, WASM_OPCODE_I64_CONST); + out_u64(ctx, expr->const_.u64, "u64 literal"); + break; + case WASM_TYPE_F32: + out_opcode(ctx, WASM_OPCODE_F32_CONST); + out_f32(ctx, expr->const_.f32, "f32 literal"); + break; + case WASM_TYPE_F64: + out_opcode(ctx, WASM_OPCODE_F64_CONST); + out_f64(ctx, expr->const_.f64, "f64 literal"); + break; + default: + assert(0); + } + break; + case WASM_EXPR_TYPE_CONVERT: + out_opcode(ctx, convert_opcode(&expr->convert.op)); + result |= write_expr(ctx, module, func, expr->convert.expr); + break; + case WASM_EXPR_TYPE_GET_LOCAL: + break; + case WASM_EXPR_TYPE_GROW_MEMORY: + break; + case WASM_EXPR_TYPE_HAS_FEATURE: + break; + case WASM_EXPR_TYPE_IF: + out_opcode(ctx, WASM_OPCODE_IF); + result |= write_expr(ctx, module, func, expr->if_.cond); + result |= write_expr(ctx, module, func, expr->if_.true_); + break; + case WASM_EXPR_TYPE_IF_ELSE: + out_opcode(ctx, WASM_OPCODE_IF_THEN); + result |= write_expr(ctx, module, func, expr->if_else.cond); + result |= write_expr(ctx, module, func, expr->if_else.true_); + result |= write_expr(ctx, module, func, expr->if_else.false_); + break; + case WASM_EXPR_TYPE_LABEL: + out_opcode(ctx, WASM_OPCODE_BLOCK); + out_u8(ctx, 1, "num expressions"); + result |= write_expr(ctx, module, func, expr->label.expr); + break; + case WASM_EXPR_TYPE_LOAD: + out_opcode(ctx, mem_opcode(&expr->load.op)); + result |= write_expr(ctx, module, func, expr->load.addr); + break; + case WASM_EXPR_TYPE_LOAD_EXTEND: + break; + case WASM_EXPR_TYPE_LOAD_GLOBAL: + break; + case WASM_EXPR_TYPE_LOOP: + out_opcode(ctx, WASM_OPCODE_LOOP); + result |= write_expr(ctx, module, func, expr->label.expr); + break; + case WASM_EXPR_TYPE_MEMORY_SIZE: + out_opcode(ctx, WASM_OPCODE_MEMORY_SIZE); + break; + case WASM_EXPR_TYPE_NOP: + out_opcode(ctx, WASM_OPCODE_NOP); + break; + case WASM_EXPR_TYPE_PAGE_SIZE: + break; + case WASM_EXPR_TYPE_RETURN: + out_opcode(ctx, WASM_OPCODE_RETURN); + if (expr->return_.expr) + result |= write_expr(ctx, module, func, expr->return_.expr); + break; + case WASM_EXPR_TYPE_SELECT: + break; + case WASM_EXPR_TYPE_SET_LOCAL: + break; + case WASM_EXPR_TYPE_STORE: + break; + case WASM_EXPR_TYPE_STORE_GLOBAL: + break; + case WASM_EXPR_TYPE_STORE_WRAP: + break; + case WASM_EXPR_TYPE_TABLESWITCH: + break; + case WASM_EXPR_TYPE_UNARY: + out_opcode(ctx, unary_opcode(&expr->unary.op)); + result |= write_expr(ctx, module, func, expr->unary.expr); + break; + case WASM_EXPR_TYPE_UNREACHABLE: + out_opcode(ctx, WASM_OPCODE_UNREACHABLE); + break; + } + return result; +} + +static WasmResult write_expr_list(WasmWriteContext* ctx, + WasmModule* module, + WasmFunc* func, + WasmExprPtrVector* exprs) { + WasmResult result = WASM_OK; + int i; + for (i = 0; i < exprs->size; ++i) + result |= write_expr(ctx, module, func, exprs->data[i]); + return result; +} + +static WasmResult write_func(WasmWriteContext* ctx, + WasmModule* module, + WasmFunc* func) { + return write_expr_list(ctx, module, func, &func->exprs); +} + +static WasmResult write_module(WasmWriteContext* ctx, WasmModule* module) { + WasmResult result = WASM_OK; + int i; + + size_t segments_offset; + if (module->memory) { + out_u8(ctx, WASM_SECTION_MEMORY, "WASM_SECTION_MEMORY"); + out_u8(ctx, log_two_u32(module->memory->initial_size), "min mem size log 2"); + out_u8(ctx, log_two_u32(module->memory->max_size), "max mem size log 2"); + out_u8(ctx, DEFAULT_MEMORY_EXPORT, "export mem"); + + if (module->memory->segments.size) { + out_u8(ctx, WASM_SECTION_DATA_SEGMENTS, "WASM_SECTION_DATA_SEGMENTS"); + out_leb128(ctx, module->memory->segments.size, "num data segments"); + segments_offset = ctx->offset; + for (i = 0; i < module->memory->segments.size; ++i) { + WasmSegment* segment = &module->memory->segments.data[i]; + print_header(ctx, "segment header", i); + out_u32(ctx, segment->addr, "segment address"); + out_u32(ctx, 0, "segment data offset"); + out_u32(ctx, segment->size, "segment size"); + out_u8(ctx, 1, "segment init"); + } + } + } else { + /* TODO(binji): remove? */ + out_u8(ctx, WASM_SECTION_MEMORY, "WASM_SECTION_MEMORY"); + out_u8(ctx, 0, "min mem size log 2"); + out_u8(ctx, 0, "max mem size log 2"); + out_u8(ctx, DEFAULT_MEMORY_EXPORT, "export mem"); + } + + if (module->globals.types.size) { + out_u8(ctx, WASM_SECTION_GLOBALS, "WASM_SECTION_GLOBALS"); + out_leb128(ctx, module->globals.types.size, "num globals"); + for (i = 0; i < module->globals.types.size; ++i) { + WasmType global_type = module->globals.types.data[i]; + print_header(ctx, "global header", i); + const uint8_t global_type_codes[WASM_NUM_V8_TYPES] = {-1, 4, 6, 8, 9}; + out_u32(ctx, 0, "global name offset"); + out_u8(ctx, global_type_codes[wasm_type_to_v8_type(global_type)], + "global mem type"); + out_u8(ctx, 0, "export global"); + } + } + + WasmFuncSignatureVector sigs = {}; + get_func_signatures(ctx, module, &sigs); + if (sigs.size) { + out_u8(ctx, WASM_SECTION_SIGNATURES, "WASM_SECTION_SIGNATURES"); + out_leb128(ctx, sigs.size, "num signatures"); + for (i = 0; i < sigs.size; ++i) { + WasmFuncSignature* sig = &sigs.data[i]; + print_header(ctx, "signature", i); + out_u8(ctx, sig->param_types.size, "num params"); + out_u8(ctx, wasm_type_to_v8_type(sig->result_type), "result_type"); + int j; + for (j = 0; j < sig->param_types.size; ++j) + out_u8(ctx, wasm_type_to_v8_type(sig->param_types.data[j]), + "param type"); + } + } + + size_t imports_offset; + int num_funcs = module->imports.size + module->funcs.size; + if (num_funcs) { + out_u8(ctx, WASM_SECTION_FUNCTIONS, "WASM_SECTION_FUNCTIONS"); + out_leb128(ctx, num_funcs, "num functions"); + + imports_offset = ctx->offset; + for (i = 0; i < module->imports.size; ++i) { + // WasmImport* import = module->imports.data[i]; + print_header(ctx, "import header", i); + WasmFunctionFlags flags = + WASM_FUNCTION_FLAG_NAME | WASM_FUNCTION_FLAG_IMPORT; + out_u8(ctx, flags, "import flags"); + out_u16(ctx, ctx->import_sig_indexes[i], "import signature index"); + out_u32(ctx, 0, "import name offset"); + } + + ctx->func_offsets = + realloc(ctx->func_offsets, module->funcs.size * sizeof(size_t)); + for (i = 0; i < module->funcs.size; ++i) { + WasmFunc* func = module->funcs.data[i]; + print_header(ctx, "function", i); + ctx->func_offsets[i] = ctx->offset; + int is_exported = wasm_func_is_exported(module, func); + /* TODO(binji): remove? */ + int has_name = 1; /* is_exported */ + int has_locals = func->locals.types.size > 0; + uint8_t flags = 0; + if (has_name) + flags |= WASM_FUNCTION_FLAG_NAME; + if (is_exported) + flags |= WASM_FUNCTION_FLAG_NAME | WASM_FUNCTION_FLAG_EXPORT; + if (has_locals) + flags |= WASM_FUNCTION_FLAG_LOCALS; + out_u8(ctx, flags, "func flags"); + out_u16(ctx, ctx->func_sig_indexes[i], "func signature index"); + if (has_name) + out_u32(ctx, 0, "func name offset"); + if (has_locals) { + remap_locals(ctx, func); + int num_locals[WASM_NUM_V8_TYPES] = {}; + int j; + for (j = 0; j < func->locals.types.size; ++j) + num_locals[wasm_type_to_v8_type(func->locals.types.data[j])]++; + + out_u16(ctx, num_locals[WASM_TYPE_V8_I32], "num local i32"); + out_u16(ctx, num_locals[WASM_TYPE_V8_I64], "num local i64"); + out_u16(ctx, num_locals[WASM_TYPE_V8_F32], "num local f32"); + out_u16(ctx, num_locals[WASM_TYPE_V8_F64], "num local f64"); + } + + size_t func_body_offset = ctx->offset; + out_u16(ctx, 0, "func body size"); + write_func(ctx, module, func); + int func_size = ctx->offset - func_body_offset - sizeof(uint16_t); + out_u16_at(ctx, func_body_offset, func_size, "FIXUP func body size"); + } + } + + if (module->table && module->table->size) { + out_u8(ctx, WASM_SECTION_FUNCTION_TABLE, "WASM_SECTION_FUNCTION_TABLE"); + out_leb128(ctx, module->table->size, "num function table entries"); + for (i = 0; i < module->table->size; ++i) { + int index = wasm_get_func_index_by_var(module, &module->table->data[i]); + assert(index >= 0 && index < module->funcs.size); + out_u16(ctx, index, "function table entry"); + } + } + + out_u8(ctx, WASM_SECTION_END, "WASM_SECTION_END"); + + /* output segment data */ + size_t offset; + if (module->memory) { + offset = segments_offset; + for (i = 0; i < module->memory->segments.size; ++i) { + print_header(ctx, "segment data", i); + WasmSegment* segment = &module->memory->segments.data[i]; + out_u32_at(ctx, offset + SEGMENT_OFFSET_OFFSET, ctx->offset, + "FIXUP segment data offset"); + out_data(ctx, ctx->offset, segment->data, segment->size, "segment data"); + ctx->offset += segment->size; + offset += SEGMENT_SIZE; + } + } + + /* output import names */ + offset = imports_offset; + for (i = 0; i < module->imports.size; ++i) { + print_header(ctx, "import", i); + WasmImport* import = module->imports.data[i]; + out_u32_at(ctx, offset + IMPORT_NAME_OFFSET, ctx->offset, + "FIXUP import name offset"); + out_str(ctx, import->name.start, import->name.length, "import name"); + offset += IMPORT_SIZE; + } + + /* output exported func names */ + for (i = 0; i < module->exports.size; ++i) { + print_header(ctx, "export", i); + WasmExport* export = module->exports.data[i]; + int func_index = wasm_get_func_index_by_var(module, &export->var); + assert(func_index >= 0 && func_index < module->funcs.size); + offset = ctx->func_offsets[func_index]; + out_u32_at(ctx, offset + FUNC_NAME_OFFSET, ctx->offset, + "FIXUP func name offset"); + out_str(ctx, export->name.start, export->name.length, "export name"); + } + + return result; +} + +static WasmResult write_command(WasmWriteContext* ctx, WasmCommand* command) { + switch (command->type) { + case WASM_COMMAND_TYPE_MODULE: + return write_module(ctx, &command->module); +#if 0 + case WASM_COMMAND_TYPE_INVOKE: + return write_invoke(writer, &command->invoke, WASM_TYPE_VOID); + case WASM_COMMAND_TYPE_ASSERT_RETURN: + return write_invoke(writer, &command->assert_return.invoke, + command->assert_return.expected.type); + case WASM_COMMAND_TYPE_ASSERT_RETURN_NAN: + return write_invoke(writer, &command->assert_return_nan.invoke, + WASM_TYPE_F32 | WASM_TYPE_F64); + case WASM_COMMAND_TYPE_ASSERT_TRAP: + return write_invoke(writer, &command->assert_trap.invoke, WASM_TYPE_VOID); +#endif + default: + break; + } +} + +WasmResult wasm_write_binary(WasmBinaryWriter* writer, WasmScript* script) { + WasmWriteContext ctx = {}; + ctx.writer = writer; + WasmResult result = WASM_OK; + int i; + for (i = 0; i < script->commands.size; ++i) + result |= write_command(&ctx, &script->commands.data[i]); + return result; +} diff --git a/src/wasm-check.c b/src/wasm-check.c index edcc84e6..c3c69876 100644 --- a/src/wasm-check.c +++ b/src/wasm-check.c @@ -78,29 +78,64 @@ static int get_index_from_var(WasmBindingVector* bindings, WasmVar* var) { return var->index; } -#define DEFINE_GET_ITEM_BY_NAME(NAME, TYPE) \ - static TYPE##Ptr get_##NAME##_by_name(WasmBindingVector* bindings, \ - TYPE##PtrVector* items, \ - WasmStringSlice* name) { \ - int index = find_binding_index_by_name(bindings, name); \ - if (index == -1) \ - return NULL; \ - return items->data[index]; \ - } -DEFINE_GET_ITEM_BY_NAME(func, WasmFunc) -DEFINE_GET_ITEM_BY_NAME(func_type, WasmFuncType) -DEFINE_GET_ITEM_BY_NAME(export, WasmExport) - -#define DEFINE_GET_ITEM_BY_VAR(NAME, TYPE) \ - static TYPE##Ptr get_##NAME##_by_var(WasmBindingVector* bindings, \ - TYPE##PtrVector* items, WasmVar* var) { \ - int index = get_index_from_var(bindings, var); \ - if (index < 0 || index >= items->size) \ - return NULL; \ - return items->data[index]; \ +static WasmExportPtr get_export_by_name(WasmModule* module, + WasmStringSlice* name) { + int index = find_binding_index_by_name(&module->export_bindings, name); + if (index == -1) + return NULL; + return module->exports.data[index]; +} + +int wasm_func_is_exported(WasmModule* module, WasmFunc* func) { + int i; + for (i = 0; i < module->exports.size; ++i) { + WasmExport* export = module->exports.data[i]; + if (export->var.type == WASM_VAR_TYPE_NAME) { + if (string_slices_are_equal(&export->var.name, &func->name)) + return 1; + } else { + assert(export->var.type == WASM_VAR_TYPE_INDEX); + int index = export->var.index; + if (index >= 0 && index < module->funcs.size && + module->funcs.data[index] == func) + return 1; + } } -DEFINE_GET_ITEM_BY_VAR(func, WasmFunc) -DEFINE_GET_ITEM_BY_VAR(func_type, WasmFuncType) + return 0; +} + +int wasm_get_func_index_by_var(WasmModule* module, WasmVar* var) { + return get_index_from_var(&module->func_bindings, var); +} + +int wasm_get_func_type_index_by_var(WasmModule* module, WasmVar* var) { + return get_index_from_var(&module->func_type_bindings, var); +} + +int wasm_get_import_index_by_var(WasmModule* module, WasmVar* var) { + return get_index_from_var(&module->import_bindings, var); +} + +WasmFuncPtr wasm_get_func_by_var(WasmModule* module, WasmVar* var) { + int index = get_index_from_var(&module->func_bindings, var); + if (index < 0 || index >= module->funcs.size) + return NULL; + return module->funcs.data[index]; +} + +WasmFuncTypePtr wasm_get_func_type_by_var(WasmModule* module, WasmVar* var) { + int index = get_index_from_var(&module->func_type_bindings, var); + if (index < 0 || index >= module->func_types.size) + return NULL; + return module->func_types.data[index]; +} + +WasmImportPtr wasm_get_import_by_var(WasmModule* module, WasmVar* var) { + int index = get_index_from_var(&module->import_bindings, var); + if (index < 0 || index >= module->imports.size) + return NULL; + return module->imports.data[index]; +} static WasmResult check_duplicate_bindings(WasmCheckContext* ctx, WasmBindingVector* bindings, @@ -881,17 +916,14 @@ static WasmResult check_invoke(WasmCheckContext* ctx, return WASM_ERROR; } - WasmExport* export = - get_export_by_name(&ctx->last_module->export_bindings, - &ctx->last_module->exports, &invoke->name); + WasmExport* export = get_export_by_name(ctx->last_module, &invoke->name); if (!export) { print_error(ctx, &invoke->loc, "unknown function export \"%.*s\"", invoke->name.length, invoke->name.start); return WASM_ERROR; } - WasmFunc* func = get_func_by_var(&ctx->last_module->func_bindings, - &ctx->last_module->funcs, &export->var); + WasmFunc* func = wasm_get_func_by_var(ctx->last_module, &export->var); if (!func) { /* this error will have already been reported, just skip it */ return WASM_ERROR; diff --git a/src/wasm-lexer.c b/src/wasm-lexer.c index bf5f1707..907fe549 100644 --- a/src/wasm-lexer.c +++ b/src/wasm-lexer.c @@ -1223,6 +1223,9 @@ typedef struct WasmScannerExtra { yylloc->last_column = extra->column; \ } +#define WASM_SIGN_S WASM_SIGNED +#define WASM_SIGN_U WASM_UNSIGNED + #define TEXT \ yylval->text.start = yytext; \ yylval->text.length = yyleng @@ -1231,35 +1234,26 @@ typedef struct WasmScannerExtra { yylval->text.length = yyleng - offset #define TYPE(type_) yylval->type = WASM_TYPE_##type_ #define TYPE_STRUCT(struct_, type_) yylval->struct_.type = WASM_TYPE_##type_ -#define SIGN(struct_, sign_) \ - yylval->struct_.sign = sign_ ? WASM_SIGNED : WASM_UNSIGNED -#define MEMOP(type_, size_) \ - TYPE_STRUCT(mem, type_); \ +#define MEMOP(type_, name, size_) \ + TYPE_STRUCT(mem, type_); \ + yylval->mem.op_type = WASM_MEM_OP_TYPE_##type_##_##name; \ + yylval->mem.size = WASM_MEM_SIZE_##size_ +#define MEMOPSIGN(type_, name, size_, sign_) \ + TYPE_STRUCT(mem, type_); \ + yylval->mem.op_type = WASM_MEM_OP_TYPE_##type_##_##name##size_##_##sign_; \ yylval->mem.size = WASM_MEM_SIZE_##size_ -#define MEMOPSIGN(type_, size_, sign_) \ - MEMOP(type_, size_); \ - SIGN(mem, sign_) -#define UNOP(type_, name) \ - TYPE_STRUCT(unary, type_); \ - yylval->unary.op_type = WASM_UNARY_OP_TYPE_##name +#define UNOP(type_, name) TYPE_STRUCT(unary, type_); \ + yylval->unary.op_type = WASM_UNARY_OP_TYPE_##type_##_##name #define BINOP(type_, name) \ TYPE_STRUCT(binary, type_); \ - yylval->binary.op_type = WASM_BINARY_OP_TYPE_##name -#define BINOPSIGN(type_, name, sign_) \ - BINOP(type_, name); \ - SIGN(binary, sign_) + yylval->binary.op_type = WASM_BINARY_OP_TYPE_##type_##_##name #define CMPOP(type_, name) \ TYPE_STRUCT(compare, type_); \ - yylval->compare.op_type = WASM_COMPARE_OP_TYPE_##name -#define CMPOPSIGN(type_, name, sign_) \ - CMPOP(type_, name); \ - SIGN(compare, sign_) -#define CONVTYPE(type_, type2_) \ - TYPE_STRUCT(convert, type_); \ + yylval->compare.op_type = WASM_COMPARE_OP_TYPE_##type_##_##name +#define CONVTYPE(type_, name, type2_) \ + TYPE_STRUCT(convert, type_); \ + yylval->convert.op_type = WASM_CONVERT_OP_TYPE_##type_##_##name##_##type2_; \ yylval->convert.type2 = WASM_TYPE_##type2_ -#define CONVTYPESIGN(type_, type2_, sign_) \ - CONVTYPE(type_, type2_); \ - SIGN(convert, sign_) #define CASTTYPE(type_, type2_) \ TYPE_STRUCT(cast, type_); \ yylval->cast.type2 = WASM_TYPE_##type2_ @@ -1269,7 +1263,7 @@ typedef struct WasmScannerExtra { -#line 1273 "src/wasm-lexer.c" +#line 1267 "src/wasm-lexer.c" #define INITIAL 0 #define LINE_COMMENT 1 @@ -1553,10 +1547,10 @@ YY_DECL } { -#line 108 "src/wasm-lexer.l" +#line 102 "src/wasm-lexer.l" -#line 1560 "src/wasm-lexer.c" +#line 1554 "src/wasm-lexer.c" while ( 1 ) /* loops until end-of-file is reached */ { @@ -1627,1141 +1621,1141 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 110 "src/wasm-lexer.l" +#line 104 "src/wasm-lexer.l" { return TOK(LPAR); } YY_BREAK case 2: YY_RULE_SETUP -#line 111 "src/wasm-lexer.l" +#line 105 "src/wasm-lexer.l" { return TOK(RPAR); } YY_BREAK case 3: YY_RULE_SETUP -#line 112 "src/wasm-lexer.l" +#line 106 "src/wasm-lexer.l" { TEXT; return TOK(INT); } YY_BREAK case 4: YY_RULE_SETUP -#line 113 "src/wasm-lexer.l" +#line 107 "src/wasm-lexer.l" { TEXT; return TOK(FLOAT); } YY_BREAK case 5: YY_RULE_SETUP -#line 114 "src/wasm-lexer.l" +#line 108 "src/wasm-lexer.l" { TEXT; return TOK(TEXT); } YY_BREAK case 6: YY_RULE_SETUP -#line 115 "src/wasm-lexer.l" +#line 109 "src/wasm-lexer.l" { BEGIN(BAD_TEXT); } YY_BREAK case 7: YY_RULE_SETUP -#line 116 "src/wasm-lexer.l" +#line 110 "src/wasm-lexer.l" {} YY_BREAK case 8: /* rule 8 can match eol */ YY_RULE_SETUP -#line 117 "src/wasm-lexer.l" +#line 111 "src/wasm-lexer.l" { BEGIN(INITIAL); RESET_COLUMN(yyscanner); yyerror(yylloc, &yyscanner, parser, "newline in string"); } YY_BREAK case YY_STATE_EOF(BAD_TEXT): -#line 121 "src/wasm-lexer.l" +#line 115 "src/wasm-lexer.l" { yyerror(yylloc, &yyscanner, parser, "unexpected EOF"); return TOK(EOF); } YY_BREAK case 9: YY_RULE_SETUP -#line 123 "src/wasm-lexer.l" +#line 117 "src/wasm-lexer.l" { yyerror(yylloc, &yyscanner, parser, "bad escape \"%.*s\"", yyleng, yytext); } YY_BREAK case 10: YY_RULE_SETUP -#line 125 "src/wasm-lexer.l" +#line 119 "src/wasm-lexer.l" { BEGIN(INITIAL); TEXT; return TOK(TEXT); } YY_BREAK case 11: /* rule 11 can match eol */ YY_RULE_SETUP -#line 126 "src/wasm-lexer.l" +#line 120 "src/wasm-lexer.l" { yyerror(yylloc, &yyscanner, parser, "illegal character in string"); } YY_BREAK case 12: YY_RULE_SETUP -#line 128 "src/wasm-lexer.l" +#line 122 "src/wasm-lexer.l" { TYPE(I32); return TOK(VALUE_TYPE); } YY_BREAK case 13: YY_RULE_SETUP -#line 129 "src/wasm-lexer.l" +#line 123 "src/wasm-lexer.l" { TYPE(I64); return TOK(VALUE_TYPE); } YY_BREAK case 14: YY_RULE_SETUP -#line 130 "src/wasm-lexer.l" +#line 124 "src/wasm-lexer.l" { TYPE(F32); return TOK(VALUE_TYPE); } YY_BREAK case 15: YY_RULE_SETUP -#line 131 "src/wasm-lexer.l" +#line 125 "src/wasm-lexer.l" { TYPE(F64); return TOK(VALUE_TYPE); } YY_BREAK case 16: YY_RULE_SETUP -#line 132 "src/wasm-lexer.l" +#line 126 "src/wasm-lexer.l" { return TOK(NOP); } YY_BREAK case 17: YY_RULE_SETUP -#line 133 "src/wasm-lexer.l" +#line 127 "src/wasm-lexer.l" { return TOK(BLOCK); } YY_BREAK case 18: YY_RULE_SETUP -#line 134 "src/wasm-lexer.l" +#line 128 "src/wasm-lexer.l" { return TOK(IF); } YY_BREAK case 19: YY_RULE_SETUP -#line 135 "src/wasm-lexer.l" +#line 129 "src/wasm-lexer.l" { return TOK(IF_ELSE); } YY_BREAK case 20: YY_RULE_SETUP -#line 136 "src/wasm-lexer.l" +#line 130 "src/wasm-lexer.l" { return TOK(LOOP); } YY_BREAK case 21: YY_RULE_SETUP -#line 137 "src/wasm-lexer.l" +#line 131 "src/wasm-lexer.l" { return TOK(LABEL); } YY_BREAK case 22: YY_RULE_SETUP -#line 138 "src/wasm-lexer.l" +#line 132 "src/wasm-lexer.l" { return TOK(BR); } YY_BREAK case 23: YY_RULE_SETUP -#line 139 "src/wasm-lexer.l" +#line 133 "src/wasm-lexer.l" { return TOK(BR_IF); } YY_BREAK case 24: YY_RULE_SETUP -#line 140 "src/wasm-lexer.l" +#line 134 "src/wasm-lexer.l" { return TOK(TABLESWITCH); } YY_BREAK case 25: YY_RULE_SETUP -#line 141 "src/wasm-lexer.l" +#line 135 "src/wasm-lexer.l" { return TOK(CASE); } YY_BREAK case 26: YY_RULE_SETUP -#line 142 "src/wasm-lexer.l" +#line 136 "src/wasm-lexer.l" { return TOK(CALL); } YY_BREAK case 27: YY_RULE_SETUP -#line 143 "src/wasm-lexer.l" +#line 137 "src/wasm-lexer.l" { return TOK(CALL_IMPORT); } YY_BREAK case 28: YY_RULE_SETUP -#line 144 "src/wasm-lexer.l" +#line 138 "src/wasm-lexer.l" { return TOK(CALL_INDIRECT); } YY_BREAK case 29: YY_RULE_SETUP -#line 145 "src/wasm-lexer.l" +#line 139 "src/wasm-lexer.l" { return TOK(RETURN); } YY_BREAK case 30: YY_RULE_SETUP -#line 146 "src/wasm-lexer.l" +#line 140 "src/wasm-lexer.l" { return TOK(GET_LOCAL); } YY_BREAK case 31: YY_RULE_SETUP -#line 147 "src/wasm-lexer.l" +#line 141 "src/wasm-lexer.l" { return TOK(SET_LOCAL); } YY_BREAK case 32: YY_RULE_SETUP -#line 148 "src/wasm-lexer.l" -{ MEMOP(I32, 32); return TOK(LOAD); } +#line 142 "src/wasm-lexer.l" +{ MEMOP(I32, LOAD, 32); return TOK(LOAD); } YY_BREAK case 33: YY_RULE_SETUP -#line 149 "src/wasm-lexer.l" -{ MEMOP(I64, 64); return TOK(LOAD); } +#line 143 "src/wasm-lexer.l" +{ MEMOP(I64, LOAD, 64); return TOK(LOAD); } YY_BREAK case 34: YY_RULE_SETUP -#line 150 "src/wasm-lexer.l" -{ MEMOP(F32, 32); return TOK(LOAD); } +#line 144 "src/wasm-lexer.l" +{ MEMOP(F32, LOAD, 32); return TOK(LOAD); } YY_BREAK case 35: YY_RULE_SETUP -#line 151 "src/wasm-lexer.l" -{ MEMOP(F64, 64); return TOK(LOAD); } +#line 145 "src/wasm-lexer.l" +{ MEMOP(F64, LOAD, 64); return TOK(LOAD); } YY_BREAK case 36: YY_RULE_SETUP -#line 152 "src/wasm-lexer.l" -{ MEMOP(I32, 32); return TOK(STORE); } +#line 146 "src/wasm-lexer.l" +{ MEMOP(I32, STORE, 32); return TOK(STORE); } YY_BREAK case 37: YY_RULE_SETUP -#line 153 "src/wasm-lexer.l" -{ MEMOP(I64, 64); return TOK(STORE); } +#line 147 "src/wasm-lexer.l" +{ MEMOP(I64, STORE, 64); return TOK(STORE); } YY_BREAK case 38: YY_RULE_SETUP -#line 154 "src/wasm-lexer.l" -{ MEMOP(F32, 32); return TOK(STORE); } +#line 148 "src/wasm-lexer.l" +{ MEMOP(F32, STORE, 32); return TOK(STORE); } YY_BREAK case 39: YY_RULE_SETUP -#line 155 "src/wasm-lexer.l" -{ MEMOP(F64, 64); return TOK(STORE); } +#line 149 "src/wasm-lexer.l" +{ MEMOP(F64, STORE, 64); return TOK(STORE); } YY_BREAK case 40: YY_RULE_SETUP -#line 156 "src/wasm-lexer.l" -{ MEMOPSIGN(I32, 8, 1); return TOK(LOAD_EXTEND); } +#line 150 "src/wasm-lexer.l" +{ MEMOPSIGN(I32, LOAD, 8, S); return TOK(LOAD_EXTEND); } YY_BREAK case 41: YY_RULE_SETUP -#line 157 "src/wasm-lexer.l" -{ MEMOPSIGN(I64, 8, 1); return TOK(LOAD_EXTEND); } +#line 151 "src/wasm-lexer.l" +{ MEMOPSIGN(I64, LOAD, 8, S); return TOK(LOAD_EXTEND); } YY_BREAK case 42: YY_RULE_SETUP -#line 158 "src/wasm-lexer.l" -{ MEMOPSIGN(I32, 8, 0); return TOK(LOAD_EXTEND); } +#line 152 "src/wasm-lexer.l" +{ MEMOPSIGN(I32, LOAD, 8, U); return TOK(LOAD_EXTEND); } YY_BREAK case 43: YY_RULE_SETUP -#line 159 "src/wasm-lexer.l" -{ MEMOPSIGN(I64, 8, 0); return TOK(LOAD_EXTEND); } +#line 153 "src/wasm-lexer.l" +{ MEMOPSIGN(I64, LOAD, 8, U); return TOK(LOAD_EXTEND); } YY_BREAK case 44: YY_RULE_SETUP -#line 160 "src/wasm-lexer.l" -{ MEMOPSIGN(I32, 16, 1); return TOK(LOAD_EXTEND); } +#line 154 "src/wasm-lexer.l" +{ MEMOPSIGN(I32, LOAD, 16, S); return TOK(LOAD_EXTEND); } YY_BREAK case 45: YY_RULE_SETUP -#line 161 "src/wasm-lexer.l" -{ MEMOPSIGN(I64, 16, 1); return TOK(LOAD_EXTEND); } +#line 155 "src/wasm-lexer.l" +{ MEMOPSIGN(I64, LOAD, 16, S); return TOK(LOAD_EXTEND); } YY_BREAK case 46: YY_RULE_SETUP -#line 162 "src/wasm-lexer.l" -{ MEMOPSIGN(I32, 16, 0); return TOK(LOAD_EXTEND); } +#line 156 "src/wasm-lexer.l" +{ MEMOPSIGN(I32, LOAD, 16, U); return TOK(LOAD_EXTEND); } YY_BREAK case 47: YY_RULE_SETUP -#line 163 "src/wasm-lexer.l" -{ MEMOPSIGN(I64, 16, 0); return TOK(LOAD_EXTEND); } +#line 157 "src/wasm-lexer.l" +{ MEMOPSIGN(I64, LOAD, 16, U); return TOK(LOAD_EXTEND); } YY_BREAK case 48: YY_RULE_SETUP -#line 164 "src/wasm-lexer.l" -{ MEMOPSIGN(I64, 32, 1); return TOK(LOAD_EXTEND); } +#line 158 "src/wasm-lexer.l" +{ MEMOPSIGN(I64, LOAD, 32, S); return TOK(LOAD_EXTEND); } YY_BREAK case 49: YY_RULE_SETUP -#line 165 "src/wasm-lexer.l" -{ MEMOPSIGN(I64, 32, 0); return TOK(LOAD_EXTEND); } +#line 159 "src/wasm-lexer.l" +{ MEMOPSIGN(I64, LOAD, 32, U); return TOK(LOAD_EXTEND); } YY_BREAK case 50: YY_RULE_SETUP -#line 166 "src/wasm-lexer.l" -{ MEMOP(I32, 8); return TOK(STORE_WRAP); } +#line 160 "src/wasm-lexer.l" +{ MEMOP(I32, STORE, 8); return TOK(STORE_WRAP); } YY_BREAK case 51: YY_RULE_SETUP -#line 167 "src/wasm-lexer.l" -{ MEMOP(I64, 8); return TOK(STORE_WRAP); } +#line 161 "src/wasm-lexer.l" +{ MEMOP(I64, STORE, 8); return TOK(STORE_WRAP); } YY_BREAK case 52: YY_RULE_SETUP -#line 168 "src/wasm-lexer.l" -{ MEMOP(I32, 16); return TOK(STORE_WRAP); } +#line 162 "src/wasm-lexer.l" +{ MEMOP(I32, STORE, 16); return TOK(STORE_WRAP); } YY_BREAK case 53: YY_RULE_SETUP -#line 169 "src/wasm-lexer.l" -{ MEMOP(I64, 16); return TOK(STORE_WRAP); } +#line 163 "src/wasm-lexer.l" +{ MEMOP(I64, STORE, 16); return TOK(STORE_WRAP); } YY_BREAK case 54: YY_RULE_SETUP -#line 170 "src/wasm-lexer.l" -{ MEMOP(I64, 32); return TOK(STORE_WRAP); } +#line 164 "src/wasm-lexer.l" +{ MEMOP(I64, STORE, 32); return TOK(STORE_WRAP); } YY_BREAK case 55: YY_RULE_SETUP -#line 171 "src/wasm-lexer.l" +#line 165 "src/wasm-lexer.l" { TEXT_AT(7); return TOK(OFFSET); } YY_BREAK case 56: YY_RULE_SETUP -#line 172 "src/wasm-lexer.l" +#line 166 "src/wasm-lexer.l" { TEXT_AT(6); return TOK(ALIGN); } YY_BREAK case 57: YY_RULE_SETUP -#line 173 "src/wasm-lexer.l" +#line 167 "src/wasm-lexer.l" { TYPE(I32); return TOK(CONST); } YY_BREAK case 58: YY_RULE_SETUP -#line 174 "src/wasm-lexer.l" +#line 168 "src/wasm-lexer.l" { TYPE(I64); return TOK(CONST); } YY_BREAK case 59: YY_RULE_SETUP -#line 175 "src/wasm-lexer.l" +#line 169 "src/wasm-lexer.l" { TYPE(F32); return TOK(CONST); } YY_BREAK case 60: YY_RULE_SETUP -#line 176 "src/wasm-lexer.l" +#line 170 "src/wasm-lexer.l" { TYPE(F64); return TOK(CONST); } YY_BREAK case 61: YY_RULE_SETUP -#line 177 "src/wasm-lexer.l" +#line 171 "src/wasm-lexer.l" { UNOP(I32, NOT); return TOK(UNARY); } YY_BREAK case 62: YY_RULE_SETUP -#line 178 "src/wasm-lexer.l" +#line 172 "src/wasm-lexer.l" { UNOP(I32, CLZ); return TOK(UNARY); } YY_BREAK case 63: YY_RULE_SETUP -#line 179 "src/wasm-lexer.l" +#line 173 "src/wasm-lexer.l" { UNOP(I64, CLZ); return TOK(UNARY); } YY_BREAK case 64: YY_RULE_SETUP -#line 180 "src/wasm-lexer.l" +#line 174 "src/wasm-lexer.l" { UNOP(I32, CTZ); return TOK(UNARY); } YY_BREAK case 65: YY_RULE_SETUP -#line 181 "src/wasm-lexer.l" +#line 175 "src/wasm-lexer.l" { UNOP(I64, CTZ); return TOK(UNARY); } YY_BREAK case 66: YY_RULE_SETUP -#line 182 "src/wasm-lexer.l" +#line 176 "src/wasm-lexer.l" { UNOP(I32, POPCNT); return TOK(UNARY); } YY_BREAK case 67: YY_RULE_SETUP -#line 183 "src/wasm-lexer.l" +#line 177 "src/wasm-lexer.l" { UNOP(I64, POPCNT); return TOK(UNARY); } YY_BREAK case 68: YY_RULE_SETUP -#line 184 "src/wasm-lexer.l" +#line 178 "src/wasm-lexer.l" { UNOP(F32, NEG); return TOK(UNARY); } YY_BREAK case 69: YY_RULE_SETUP -#line 185 "src/wasm-lexer.l" +#line 179 "src/wasm-lexer.l" { UNOP(F64, NEG); return TOK(UNARY); } YY_BREAK case 70: YY_RULE_SETUP -#line 186 "src/wasm-lexer.l" +#line 180 "src/wasm-lexer.l" { UNOP(F32, ABS); return TOK(UNARY); } YY_BREAK case 71: YY_RULE_SETUP -#line 187 "src/wasm-lexer.l" +#line 181 "src/wasm-lexer.l" { UNOP(F64, ABS); return TOK(UNARY); } YY_BREAK case 72: YY_RULE_SETUP -#line 188 "src/wasm-lexer.l" +#line 182 "src/wasm-lexer.l" { UNOP(F32, SQRT); return TOK(UNARY); } YY_BREAK case 73: YY_RULE_SETUP -#line 189 "src/wasm-lexer.l" +#line 183 "src/wasm-lexer.l" { UNOP(F64, SQRT); return TOK(UNARY); } YY_BREAK case 74: YY_RULE_SETUP -#line 190 "src/wasm-lexer.l" +#line 184 "src/wasm-lexer.l" { UNOP(F32, CEIL); return TOK(UNARY); } YY_BREAK case 75: YY_RULE_SETUP -#line 191 "src/wasm-lexer.l" +#line 185 "src/wasm-lexer.l" { UNOP(F64, CEIL); return TOK(UNARY); } YY_BREAK case 76: YY_RULE_SETUP -#line 192 "src/wasm-lexer.l" +#line 186 "src/wasm-lexer.l" { UNOP(F32, FLOOR); return TOK(UNARY); } YY_BREAK case 77: YY_RULE_SETUP -#line 193 "src/wasm-lexer.l" +#line 187 "src/wasm-lexer.l" { UNOP(F64, FLOOR); return TOK(UNARY); } YY_BREAK case 78: YY_RULE_SETUP -#line 194 "src/wasm-lexer.l" +#line 188 "src/wasm-lexer.l" { UNOP(F32, TRUNC); return TOK(UNARY); } YY_BREAK case 79: YY_RULE_SETUP -#line 195 "src/wasm-lexer.l" +#line 189 "src/wasm-lexer.l" { UNOP(F64, TRUNC); return TOK(UNARY); } YY_BREAK case 80: YY_RULE_SETUP -#line 196 "src/wasm-lexer.l" +#line 190 "src/wasm-lexer.l" { UNOP(F32, NEAREST); return TOK(UNARY); } YY_BREAK case 81: YY_RULE_SETUP -#line 197 "src/wasm-lexer.l" +#line 191 "src/wasm-lexer.l" { UNOP(F64, NEAREST); return TOK(UNARY); } YY_BREAK case 82: YY_RULE_SETUP -#line 198 "src/wasm-lexer.l" +#line 192 "src/wasm-lexer.l" { BINOP(I32, ADD); return TOK(BINARY); } YY_BREAK case 83: YY_RULE_SETUP -#line 199 "src/wasm-lexer.l" +#line 193 "src/wasm-lexer.l" { BINOP(I64, ADD); return TOK(BINARY); } YY_BREAK case 84: YY_RULE_SETUP -#line 200 "src/wasm-lexer.l" +#line 194 "src/wasm-lexer.l" { BINOP(I32, SUB); return TOK(BINARY); } YY_BREAK case 85: YY_RULE_SETUP -#line 201 "src/wasm-lexer.l" +#line 195 "src/wasm-lexer.l" { BINOP(I64, SUB); return TOK(BINARY); } YY_BREAK case 86: YY_RULE_SETUP -#line 202 "src/wasm-lexer.l" +#line 196 "src/wasm-lexer.l" { BINOP(I32, MUL); return TOK(BINARY); } YY_BREAK case 87: YY_RULE_SETUP -#line 203 "src/wasm-lexer.l" +#line 197 "src/wasm-lexer.l" { BINOP(I64, MUL); return TOK(BINARY); } YY_BREAK case 88: YY_RULE_SETUP -#line 204 "src/wasm-lexer.l" -{ BINOPSIGN(I32, DIV, 1); return TOK(BINARY); } +#line 198 "src/wasm-lexer.l" +{ BINOP(I32, DIV_S); return TOK(BINARY); } YY_BREAK case 89: YY_RULE_SETUP -#line 205 "src/wasm-lexer.l" -{ BINOPSIGN(I64, DIV, 1); return TOK(BINARY); } +#line 199 "src/wasm-lexer.l" +{ BINOP(I64, DIV_S); return TOK(BINARY); } YY_BREAK case 90: YY_RULE_SETUP -#line 206 "src/wasm-lexer.l" -{ BINOPSIGN(I32, DIV, 0); return TOK(BINARY); } +#line 200 "src/wasm-lexer.l" +{ BINOP(I32, DIV_U); return TOK(BINARY); } YY_BREAK case 91: YY_RULE_SETUP -#line 207 "src/wasm-lexer.l" -{ BINOPSIGN(I64, DIV, 0); return TOK(BINARY); } +#line 201 "src/wasm-lexer.l" +{ BINOP(I64, DIV_U); return TOK(BINARY); } YY_BREAK case 92: YY_RULE_SETUP -#line 208 "src/wasm-lexer.l" -{ BINOPSIGN(I32, REM, 1); return TOK(BINARY); } +#line 202 "src/wasm-lexer.l" +{ BINOP(I32, REM_S); return TOK(BINARY); } YY_BREAK case 93: YY_RULE_SETUP -#line 209 "src/wasm-lexer.l" -{ BINOPSIGN(I64, REM, 1); return TOK(BINARY); } +#line 203 "src/wasm-lexer.l" +{ BINOP(I64, REM_S); return TOK(BINARY); } YY_BREAK case 94: YY_RULE_SETUP -#line 210 "src/wasm-lexer.l" -{ BINOPSIGN(I32, REM, 0); return TOK(BINARY); } +#line 204 "src/wasm-lexer.l" +{ BINOP(I32, REM_U); return TOK(BINARY); } YY_BREAK case 95: YY_RULE_SETUP -#line 211 "src/wasm-lexer.l" -{ BINOPSIGN(I64, REM, 0); return TOK(BINARY); } +#line 205 "src/wasm-lexer.l" +{ BINOP(I64, REM_U); return TOK(BINARY); } YY_BREAK case 96: YY_RULE_SETUP -#line 212 "src/wasm-lexer.l" +#line 206 "src/wasm-lexer.l" { BINOP(I32, AND); return TOK(BINARY); } YY_BREAK case 97: YY_RULE_SETUP -#line 213 "src/wasm-lexer.l" +#line 207 "src/wasm-lexer.l" { BINOP(I64, AND); return TOK(BINARY); } YY_BREAK case 98: YY_RULE_SETUP -#line 214 "src/wasm-lexer.l" +#line 208 "src/wasm-lexer.l" { BINOP(I32, OR); return TOK(BINARY); } YY_BREAK case 99: YY_RULE_SETUP -#line 215 "src/wasm-lexer.l" +#line 209 "src/wasm-lexer.l" { BINOP(I64, OR); return TOK(BINARY); } YY_BREAK case 100: YY_RULE_SETUP -#line 216 "src/wasm-lexer.l" +#line 210 "src/wasm-lexer.l" { BINOP(I32, XOR); return TOK(BINARY); } YY_BREAK case 101: YY_RULE_SETUP -#line 217 "src/wasm-lexer.l" +#line 211 "src/wasm-lexer.l" { BINOP(I64, XOR); return TOK(BINARY); } YY_BREAK case 102: YY_RULE_SETUP -#line 218 "src/wasm-lexer.l" +#line 212 "src/wasm-lexer.l" { BINOP(I32, SHL); return TOK(BINARY); } YY_BREAK case 103: YY_RULE_SETUP -#line 219 "src/wasm-lexer.l" +#line 213 "src/wasm-lexer.l" { BINOP(I64, SHL); return TOK(BINARY); } YY_BREAK case 104: YY_RULE_SETUP -#line 220 "src/wasm-lexer.l" -{ BINOPSIGN(I32, SHR, 1); return TOK(BINARY); } +#line 214 "src/wasm-lexer.l" +{ BINOP(I32, SHR_S); return TOK(BINARY); } YY_BREAK case 105: YY_RULE_SETUP -#line 221 "src/wasm-lexer.l" -{ BINOPSIGN(I64, SHR, 1); return TOK(BINARY); } +#line 215 "src/wasm-lexer.l" +{ BINOP(I64, SHR_S); return TOK(BINARY); } YY_BREAK case 106: YY_RULE_SETUP -#line 222 "src/wasm-lexer.l" -{ BINOPSIGN(I32, SHR, 0); return TOK(BINARY); } +#line 216 "src/wasm-lexer.l" +{ BINOP(I32, SHR_U); return TOK(BINARY); } YY_BREAK case 107: YY_RULE_SETUP -#line 223 "src/wasm-lexer.l" -{ BINOPSIGN(I64, SHR, 0); return TOK(BINARY); } +#line 217 "src/wasm-lexer.l" +{ BINOP(I64, SHR_U); return TOK(BINARY); } YY_BREAK case 108: YY_RULE_SETUP -#line 224 "src/wasm-lexer.l" +#line 218 "src/wasm-lexer.l" { BINOP(F32, ADD); return TOK(BINARY); } YY_BREAK case 109: YY_RULE_SETUP -#line 225 "src/wasm-lexer.l" +#line 219 "src/wasm-lexer.l" { BINOP(F64, ADD); return TOK(BINARY); } YY_BREAK case 110: YY_RULE_SETUP -#line 226 "src/wasm-lexer.l" +#line 220 "src/wasm-lexer.l" { BINOP(F32, SUB); return TOK(BINARY); } YY_BREAK case 111: YY_RULE_SETUP -#line 227 "src/wasm-lexer.l" +#line 221 "src/wasm-lexer.l" { BINOP(F64, SUB); return TOK(BINARY); } YY_BREAK case 112: YY_RULE_SETUP -#line 228 "src/wasm-lexer.l" +#line 222 "src/wasm-lexer.l" { BINOP(F32, MUL); return TOK(BINARY); } YY_BREAK case 113: YY_RULE_SETUP -#line 229 "src/wasm-lexer.l" +#line 223 "src/wasm-lexer.l" { BINOP(F64, MUL); return TOK(BINARY); } YY_BREAK case 114: YY_RULE_SETUP -#line 230 "src/wasm-lexer.l" +#line 224 "src/wasm-lexer.l" { BINOP(F32, DIV); return TOK(BINARY); } YY_BREAK case 115: YY_RULE_SETUP -#line 231 "src/wasm-lexer.l" +#line 225 "src/wasm-lexer.l" { BINOP(F64, DIV); return TOK(BINARY); } YY_BREAK case 116: YY_RULE_SETUP -#line 232 "src/wasm-lexer.l" +#line 226 "src/wasm-lexer.l" { BINOP(F32, MIN); return TOK(BINARY); } YY_BREAK case 117: YY_RULE_SETUP -#line 233 "src/wasm-lexer.l" +#line 227 "src/wasm-lexer.l" { BINOP(F64, MIN); return TOK(BINARY); } YY_BREAK case 118: YY_RULE_SETUP -#line 234 "src/wasm-lexer.l" +#line 228 "src/wasm-lexer.l" { BINOP(F32, MAX); return TOK(BINARY); } YY_BREAK case 119: YY_RULE_SETUP -#line 235 "src/wasm-lexer.l" +#line 229 "src/wasm-lexer.l" { BINOP(F64, MAX); return TOK(BINARY); } YY_BREAK case 120: YY_RULE_SETUP -#line 236 "src/wasm-lexer.l" +#line 230 "src/wasm-lexer.l" { BINOP(F32, COPYSIGN); return TOK(BINARY); } YY_BREAK case 121: YY_RULE_SETUP -#line 237 "src/wasm-lexer.l" +#line 231 "src/wasm-lexer.l" { BINOP(F64, COPYSIGN); return TOK(BINARY); } YY_BREAK case 122: YY_RULE_SETUP -#line 238 "src/wasm-lexer.l" +#line 232 "src/wasm-lexer.l" { CMPOP(I32, EQ); return TOK(COMPARE); } YY_BREAK case 123: YY_RULE_SETUP -#line 239 "src/wasm-lexer.l" +#line 233 "src/wasm-lexer.l" { CMPOP(I64, EQ); return TOK(COMPARE); } YY_BREAK case 124: YY_RULE_SETUP -#line 240 "src/wasm-lexer.l" -{ CMPOP(I32, EQ); return TOK(COMPARE); } +#line 234 "src/wasm-lexer.l" +{ CMPOP(I32, NE); return TOK(COMPARE); } YY_BREAK case 125: YY_RULE_SETUP -#line 241 "src/wasm-lexer.l" -{ CMPOP(I64, EQ); return TOK(COMPARE); } +#line 235 "src/wasm-lexer.l" +{ CMPOP(I64, NE); return TOK(COMPARE); } YY_BREAK case 126: YY_RULE_SETUP -#line 242 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, LT, 1); return TOK(COMPARE); } +#line 236 "src/wasm-lexer.l" +{ CMPOP(I32, LT_S); return TOK(COMPARE); } YY_BREAK case 127: YY_RULE_SETUP -#line 243 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, LT, 1); return TOK(COMPARE); } +#line 237 "src/wasm-lexer.l" +{ CMPOP(I64, LT_S); return TOK(COMPARE); } YY_BREAK case 128: YY_RULE_SETUP -#line 244 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, LT, 0); return TOK(COMPARE); } +#line 238 "src/wasm-lexer.l" +{ CMPOP(I32, LT_U); return TOK(COMPARE); } YY_BREAK case 129: YY_RULE_SETUP -#line 245 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, LT, 0); return TOK(COMPARE); } +#line 239 "src/wasm-lexer.l" +{ CMPOP(I64, LT_U); return TOK(COMPARE); } YY_BREAK case 130: YY_RULE_SETUP -#line 246 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, LE, 1); return TOK(COMPARE); } +#line 240 "src/wasm-lexer.l" +{ CMPOP(I32, LE_S); return TOK(COMPARE); } YY_BREAK case 131: YY_RULE_SETUP -#line 247 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, LE, 1); return TOK(COMPARE); } +#line 241 "src/wasm-lexer.l" +{ CMPOP(I64, LE_S); return TOK(COMPARE); } YY_BREAK case 132: YY_RULE_SETUP -#line 248 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, LE, 0); return TOK(COMPARE); } +#line 242 "src/wasm-lexer.l" +{ CMPOP(I32, LE_U); return TOK(COMPARE); } YY_BREAK case 133: YY_RULE_SETUP -#line 249 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, LE, 0); return TOK(COMPARE); } +#line 243 "src/wasm-lexer.l" +{ CMPOP(I64, LE_U); return TOK(COMPARE); } YY_BREAK case 134: YY_RULE_SETUP -#line 250 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, GT, 1); return TOK(COMPARE); } +#line 244 "src/wasm-lexer.l" +{ CMPOP(I32, GT_S); return TOK(COMPARE); } YY_BREAK case 135: YY_RULE_SETUP -#line 251 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, GT, 1); return TOK(COMPARE); } +#line 245 "src/wasm-lexer.l" +{ CMPOP(I64, GT_S); return TOK(COMPARE); } YY_BREAK case 136: YY_RULE_SETUP -#line 252 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, GT, 0); return TOK(COMPARE); } +#line 246 "src/wasm-lexer.l" +{ CMPOP(I32, GT_U); return TOK(COMPARE); } YY_BREAK case 137: YY_RULE_SETUP -#line 253 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, GT, 0); return TOK(COMPARE); } +#line 247 "src/wasm-lexer.l" +{ CMPOP(I64, GT_U); return TOK(COMPARE); } YY_BREAK case 138: YY_RULE_SETUP -#line 254 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, GE, 1); return TOK(COMPARE); } +#line 248 "src/wasm-lexer.l" +{ CMPOP(I32, GE_S); return TOK(COMPARE); } YY_BREAK case 139: YY_RULE_SETUP -#line 255 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, GE, 1); return TOK(COMPARE); } +#line 249 "src/wasm-lexer.l" +{ CMPOP(I64, GE_S); return TOK(COMPARE); } YY_BREAK case 140: YY_RULE_SETUP -#line 256 "src/wasm-lexer.l" -{ CMPOPSIGN(I32, GE, 0); return TOK(COMPARE); } +#line 250 "src/wasm-lexer.l" +{ CMPOP(I32, GE_U); return TOK(COMPARE); } YY_BREAK case 141: YY_RULE_SETUP -#line 257 "src/wasm-lexer.l" -{ CMPOPSIGN(I64, GE, 0); return TOK(COMPARE); } +#line 251 "src/wasm-lexer.l" +{ CMPOP(I64, GE_U); return TOK(COMPARE); } YY_BREAK case 142: YY_RULE_SETUP -#line 258 "src/wasm-lexer.l" +#line 252 "src/wasm-lexer.l" { CMPOP(F32, EQ); return TOK(COMPARE); } YY_BREAK case 143: YY_RULE_SETUP -#line 259 "src/wasm-lexer.l" +#line 253 "src/wasm-lexer.l" { CMPOP(F64, EQ); return TOK(COMPARE); } YY_BREAK case 144: YY_RULE_SETUP -#line 260 "src/wasm-lexer.l" +#line 254 "src/wasm-lexer.l" { CMPOP(F32, NE); return TOK(COMPARE); } YY_BREAK case 145: YY_RULE_SETUP -#line 261 "src/wasm-lexer.l" +#line 255 "src/wasm-lexer.l" { CMPOP(F64, NE); return TOK(COMPARE); } YY_BREAK case 146: YY_RULE_SETUP -#line 262 "src/wasm-lexer.l" +#line 256 "src/wasm-lexer.l" { CMPOP(F32, LT); return TOK(COMPARE); } YY_BREAK case 147: YY_RULE_SETUP -#line 263 "src/wasm-lexer.l" +#line 257 "src/wasm-lexer.l" { CMPOP(F64, LT); return TOK(COMPARE); } YY_BREAK case 148: YY_RULE_SETUP -#line 264 "src/wasm-lexer.l" +#line 258 "src/wasm-lexer.l" { CMPOP(F32, LE); return TOK(COMPARE); } YY_BREAK case 149: YY_RULE_SETUP -#line 265 "src/wasm-lexer.l" +#line 259 "src/wasm-lexer.l" { CMPOP(F64, LE); return TOK(COMPARE); } YY_BREAK case 150: YY_RULE_SETUP -#line 266 "src/wasm-lexer.l" +#line 260 "src/wasm-lexer.l" { CMPOP(F32, GT); return TOK(COMPARE); } YY_BREAK case 151: YY_RULE_SETUP -#line 267 "src/wasm-lexer.l" +#line 261 "src/wasm-lexer.l" { CMPOP(F64, GT); return TOK(COMPARE); } YY_BREAK case 152: YY_RULE_SETUP -#line 268 "src/wasm-lexer.l" +#line 262 "src/wasm-lexer.l" { CMPOP(F32, GE); return TOK(COMPARE); } YY_BREAK case 153: YY_RULE_SETUP -#line 269 "src/wasm-lexer.l" +#line 263 "src/wasm-lexer.l" { CMPOP(F64, GE); return TOK(COMPARE); } YY_BREAK case 154: YY_RULE_SETUP -#line 270 "src/wasm-lexer.l" -{ CONVTYPESIGN(I64, I32, 1); return TOK(CONVERT); } +#line 264 "src/wasm-lexer.l" +{ CONVTYPE(I64, EXTEND_S, I32); return TOK(CONVERT); } YY_BREAK case 155: YY_RULE_SETUP -#line 271 "src/wasm-lexer.l" -{ CONVTYPESIGN(I64, I32, 0); return TOK(CONVERT); } +#line 265 "src/wasm-lexer.l" +{ CONVTYPE(I64, EXTEND_U, I32); return TOK(CONVERT); } YY_BREAK case 156: YY_RULE_SETUP -#line 272 "src/wasm-lexer.l" -{ CONVTYPE(I32, I64); return TOK(CONVERT); } +#line 266 "src/wasm-lexer.l" +{ CONVTYPE(I32, WRAP, I64); return TOK(CONVERT); } YY_BREAK case 157: YY_RULE_SETUP -#line 273 "src/wasm-lexer.l" -{ CONVTYPESIGN(I32, F32, 1); return TOK(CONVERT); } +#line 267 "src/wasm-lexer.l" +{ CONVTYPE(I32, TRUNC_S, F32); return TOK(CONVERT); } YY_BREAK case 158: YY_RULE_SETUP -#line 274 "src/wasm-lexer.l" -{ CONVTYPESIGN(I64, F32, 1); return TOK(CONVERT); } +#line 268 "src/wasm-lexer.l" +{ CONVTYPE(I64, TRUNC_S, F32); return TOK(CONVERT); } YY_BREAK case 159: YY_RULE_SETUP -#line 275 "src/wasm-lexer.l" -{ CONVTYPESIGN(I32, F64, 1); return TOK(CONVERT); } +#line 269 "src/wasm-lexer.l" +{ CONVTYPE(I32, TRUNC_S, F64); return TOK(CONVERT); } YY_BREAK case 160: YY_RULE_SETUP -#line 276 "src/wasm-lexer.l" -{ CONVTYPESIGN(I64, F64, 1); return TOK(CONVERT); } +#line 270 "src/wasm-lexer.l" +{ CONVTYPE(I64, TRUNC_S, F64); return TOK(CONVERT); } YY_BREAK case 161: YY_RULE_SETUP -#line 277 "src/wasm-lexer.l" -{ CONVTYPESIGN(I32, F32, 0); return TOK(CONVERT); } +#line 271 "src/wasm-lexer.l" +{ CONVTYPE(I32, TRUNC_U, F32); return TOK(CONVERT); } YY_BREAK case 162: YY_RULE_SETUP -#line 278 "src/wasm-lexer.l" -{ CONVTYPESIGN(I64, F32, 0); return TOK(CONVERT); } +#line 272 "src/wasm-lexer.l" +{ CONVTYPE(I64, TRUNC_U, F32); return TOK(CONVERT); } YY_BREAK case 163: YY_RULE_SETUP -#line 279 "src/wasm-lexer.l" -{ CONVTYPESIGN(I32, F64, 0); return TOK(CONVERT); } +#line 273 "src/wasm-lexer.l" +{ CONVTYPE(I32, TRUNC_U, F64); return TOK(CONVERT); } YY_BREAK case 164: YY_RULE_SETUP -#line 280 "src/wasm-lexer.l" -{ CONVTYPESIGN(I64, F64, 0); return TOK(CONVERT); } +#line 274 "src/wasm-lexer.l" +{ CONVTYPE(I64, TRUNC_U, F64); return TOK(CONVERT); } YY_BREAK case 165: YY_RULE_SETUP -#line 281 "src/wasm-lexer.l" -{ CONVTYPESIGN(F32, I32, 1); return TOK(CONVERT); } +#line 275 "src/wasm-lexer.l" +{ CONVTYPE(F32, CONVERT_S, I32); return TOK(CONVERT); } YY_BREAK case 166: YY_RULE_SETUP -#line 282 "src/wasm-lexer.l" -{ CONVTYPESIGN(F64, I32, 1); return TOK(CONVERT); } +#line 276 "src/wasm-lexer.l" +{ CONVTYPE(F64, CONVERT_S, I32); return TOK(CONVERT); } YY_BREAK case 167: YY_RULE_SETUP -#line 283 "src/wasm-lexer.l" -{ CONVTYPESIGN(F32, I64, 1); return TOK(CONVERT); } +#line 277 "src/wasm-lexer.l" +{ CONVTYPE(F32, CONVERT_S, I64); return TOK(CONVERT); } YY_BREAK case 168: YY_RULE_SETUP -#line 284 "src/wasm-lexer.l" -{ CONVTYPESIGN(F64, I64, 1); return TOK(CONVERT); } +#line 278 "src/wasm-lexer.l" +{ CONVTYPE(F64, CONVERT_S, I64); return TOK(CONVERT); } YY_BREAK case 169: YY_RULE_SETUP -#line 285 "src/wasm-lexer.l" -{ CONVTYPESIGN(F32, I32, 0); return TOK(CONVERT); } +#line 279 "src/wasm-lexer.l" +{ CONVTYPE(F32, CONVERT_U, I32); return TOK(CONVERT); } YY_BREAK case 170: YY_RULE_SETUP -#line 286 "src/wasm-lexer.l" -{ CONVTYPESIGN(F64, I32, 0); return TOK(CONVERT); } +#line 280 "src/wasm-lexer.l" +{ CONVTYPE(F64, CONVERT_U, I32); return TOK(CONVERT); } YY_BREAK case 171: YY_RULE_SETUP -#line 287 "src/wasm-lexer.l" -{ CONVTYPESIGN(F32, I64, 0); return TOK(CONVERT); } +#line 281 "src/wasm-lexer.l" +{ CONVTYPE(F32, CONVERT_U, I64); return TOK(CONVERT); } YY_BREAK case 172: YY_RULE_SETUP -#line 288 "src/wasm-lexer.l" -{ CONVTYPESIGN(F64, I64, 0); return TOK(CONVERT); } +#line 282 "src/wasm-lexer.l" +{ CONVTYPE(F64, CONVERT_U, I64); return TOK(CONVERT); } YY_BREAK case 173: YY_RULE_SETUP -#line 289 "src/wasm-lexer.l" -{ CONVTYPE(F64, F32); return TOK(CONVERT); } +#line 283 "src/wasm-lexer.l" +{ CONVTYPE(F64, PROMOTE, F32); return TOK(CONVERT); } YY_BREAK case 174: YY_RULE_SETUP -#line 290 "src/wasm-lexer.l" -{ CONVTYPE(F32, F64); return TOK(CONVERT); } +#line 284 "src/wasm-lexer.l" +{ CONVTYPE(F32, DEMOTE, F64); return TOK(CONVERT); } YY_BREAK case 175: YY_RULE_SETUP -#line 291 "src/wasm-lexer.l" +#line 285 "src/wasm-lexer.l" { CASTTYPE(F32, I32); return TOK(CAST); } YY_BREAK case 176: YY_RULE_SETUP -#line 292 "src/wasm-lexer.l" +#line 286 "src/wasm-lexer.l" { CASTTYPE(I32, F32); return TOK(CAST); } YY_BREAK case 177: YY_RULE_SETUP -#line 293 "src/wasm-lexer.l" +#line 287 "src/wasm-lexer.l" { CASTTYPE(F64, I64); return TOK(CAST); } YY_BREAK case 178: YY_RULE_SETUP -#line 294 "src/wasm-lexer.l" +#line 288 "src/wasm-lexer.l" { CASTTYPE(I64, F64); return TOK(CAST); } YY_BREAK case 179: YY_RULE_SETUP -#line 295 "src/wasm-lexer.l" +#line 289 "src/wasm-lexer.l" { TYPE(I32); return TOK(SELECT); } YY_BREAK case 180: YY_RULE_SETUP -#line 296 "src/wasm-lexer.l" +#line 290 "src/wasm-lexer.l" { TYPE(I64); return TOK(SELECT); } YY_BREAK case 181: YY_RULE_SETUP -#line 297 "src/wasm-lexer.l" +#line 291 "src/wasm-lexer.l" { TYPE(F32); return TOK(SELECT); } YY_BREAK case 182: YY_RULE_SETUP -#line 298 "src/wasm-lexer.l" +#line 292 "src/wasm-lexer.l" { TYPE(F64); return TOK(SELECT); } YY_BREAK case 183: YY_RULE_SETUP -#line 299 "src/wasm-lexer.l" +#line 293 "src/wasm-lexer.l" { return TOK(UNREACHABLE); } YY_BREAK case 184: YY_RULE_SETUP -#line 300 "src/wasm-lexer.l" +#line 294 "src/wasm-lexer.l" { return TOK(MEMORY_SIZE); } YY_BREAK case 185: YY_RULE_SETUP -#line 301 "src/wasm-lexer.l" +#line 295 "src/wasm-lexer.l" { return TOK(GROW_MEMORY); } YY_BREAK case 186: YY_RULE_SETUP -#line 302 "src/wasm-lexer.l" +#line 296 "src/wasm-lexer.l" { return TOK(HAS_FEATURE); } YY_BREAK case 187: YY_RULE_SETUP -#line 303 "src/wasm-lexer.l" +#line 297 "src/wasm-lexer.l" { return TOK(TYPE); } YY_BREAK case 188: YY_RULE_SETUP -#line 304 "src/wasm-lexer.l" +#line 298 "src/wasm-lexer.l" { return TOK(FUNC); } YY_BREAK case 189: YY_RULE_SETUP -#line 305 "src/wasm-lexer.l" +#line 299 "src/wasm-lexer.l" { return TOK(PARAM); } YY_BREAK case 190: YY_RULE_SETUP -#line 306 "src/wasm-lexer.l" +#line 300 "src/wasm-lexer.l" { return TOK(RESULT); } YY_BREAK case 191: YY_RULE_SETUP -#line 307 "src/wasm-lexer.l" +#line 301 "src/wasm-lexer.l" { return TOK(LOCAL); } YY_BREAK case 192: YY_RULE_SETUP -#line 308 "src/wasm-lexer.l" +#line 302 "src/wasm-lexer.l" { return TOK(MODULE); } YY_BREAK case 193: YY_RULE_SETUP -#line 309 "src/wasm-lexer.l" +#line 303 "src/wasm-lexer.l" { return TOK(MEMORY); } YY_BREAK case 194: YY_RULE_SETUP -#line 310 "src/wasm-lexer.l" +#line 304 "src/wasm-lexer.l" { return TOK(SEGMENT); } YY_BREAK case 195: YY_RULE_SETUP -#line 311 "src/wasm-lexer.l" +#line 305 "src/wasm-lexer.l" { return TOK(IMPORT); } YY_BREAK case 196: YY_RULE_SETUP -#line 312 "src/wasm-lexer.l" +#line 306 "src/wasm-lexer.l" { return TOK(EXPORT); } YY_BREAK case 197: YY_RULE_SETUP -#line 313 "src/wasm-lexer.l" +#line 307 "src/wasm-lexer.l" { return TOK(TABLE); } YY_BREAK case 198: YY_RULE_SETUP -#line 314 "src/wasm-lexer.l" +#line 308 "src/wasm-lexer.l" { return TOK(ASSERT_INVALID); } YY_BREAK case 199: YY_RULE_SETUP -#line 315 "src/wasm-lexer.l" +#line 309 "src/wasm-lexer.l" { return TOK(ASSERT_RETURN); } YY_BREAK case 200: YY_RULE_SETUP -#line 316 "src/wasm-lexer.l" +#line 310 "src/wasm-lexer.l" { return TOK(ASSERT_RETURN_NAN); } YY_BREAK case 201: YY_RULE_SETUP -#line 317 "src/wasm-lexer.l" +#line 311 "src/wasm-lexer.l" { return TOK(ASSERT_TRAP); } YY_BREAK case 202: YY_RULE_SETUP -#line 318 "src/wasm-lexer.l" +#line 312 "src/wasm-lexer.l" { return TOK(INVOKE); } YY_BREAK case 203: YY_RULE_SETUP -#line 319 "src/wasm-lexer.l" +#line 313 "src/wasm-lexer.l" { TEXT; return TOK(VAR); } YY_BREAK case 204: YY_RULE_SETUP -#line 321 "src/wasm-lexer.l" +#line 315 "src/wasm-lexer.l" { return TOK(BR); } YY_BREAK case 205: YY_RULE_SETUP -#line 322 "src/wasm-lexer.l" +#line 316 "src/wasm-lexer.l" { return TOK(GLOBAL); } YY_BREAK case 206: YY_RULE_SETUP -#line 323 "src/wasm-lexer.l" +#line 317 "src/wasm-lexer.l" { return TOK(LOAD_GLOBAL); } YY_BREAK case 207: YY_RULE_SETUP -#line 324 "src/wasm-lexer.l" +#line 318 "src/wasm-lexer.l" { return TOK(STORE_GLOBAL); } YY_BREAK case 208: YY_RULE_SETUP -#line 325 "src/wasm-lexer.l" +#line 319 "src/wasm-lexer.l" { return TOK(PAGE_SIZE); } YY_BREAK case 209: YY_RULE_SETUP -#line 327 "src/wasm-lexer.l" +#line 321 "src/wasm-lexer.l" { BEGIN(LINE_COMMENT); } YY_BREAK case 210: /* rule 210 can match eol */ YY_RULE_SETUP -#line 328 "src/wasm-lexer.l" +#line 322 "src/wasm-lexer.l" { RESET_COLUMN(yyscanner); BEGIN(INITIAL); } YY_BREAK case YY_STATE_EOF(LINE_COMMENT): -#line 329 "src/wasm-lexer.l" +#line 323 "src/wasm-lexer.l" { return TOK(EOF); } YY_BREAK case 211: YY_RULE_SETUP -#line 330 "src/wasm-lexer.l" +#line 324 "src/wasm-lexer.l" YY_BREAK case 212: YY_RULE_SETUP -#line 331 "src/wasm-lexer.l" +#line 325 "src/wasm-lexer.l" { BEGIN(BLOCK_COMMENT); COMMENT_NESTING(yyscanner) = 1; } YY_BREAK case 213: YY_RULE_SETUP -#line 332 "src/wasm-lexer.l" +#line 326 "src/wasm-lexer.l" { COMMENT_NESTING(yyscanner)++; } YY_BREAK case 214: YY_RULE_SETUP -#line 333 "src/wasm-lexer.l" +#line 327 "src/wasm-lexer.l" { if (--COMMENT_NESTING(yyscanner) == 0) BEGIN(INITIAL); } YY_BREAK case 215: /* rule 215 can match eol */ YY_RULE_SETUP -#line 334 "src/wasm-lexer.l" +#line 328 "src/wasm-lexer.l" { RESET_COLUMN(yyscanner); } YY_BREAK case YY_STATE_EOF(BLOCK_COMMENT): -#line 335 "src/wasm-lexer.l" +#line 329 "src/wasm-lexer.l" { yyerror(yylloc, &yyscanner, parser, "unexpected EOF"); return TOK(EOF); } YY_BREAK case 216: YY_RULE_SETUP -#line 338 "src/wasm-lexer.l" +#line 332 "src/wasm-lexer.l" YY_BREAK case 217: /* rule 217 can match eol */ YY_RULE_SETUP -#line 339 "src/wasm-lexer.l" +#line 333 "src/wasm-lexer.l" { RESET_COLUMN(yyscanner); } YY_BREAK case 218: YY_RULE_SETUP -#line 340 "src/wasm-lexer.l" +#line 334 "src/wasm-lexer.l" YY_BREAK case YY_STATE_EOF(INITIAL): -#line 341 "src/wasm-lexer.l" +#line 335 "src/wasm-lexer.l" { return TOK(EOF); } YY_BREAK case 219: YY_RULE_SETUP -#line 342 "src/wasm-lexer.l" +#line 336 "src/wasm-lexer.l" { yyerror(yylloc, &yyscanner, parser, "unexpected token \"%.*s\"", yyleng, yytext); } YY_BREAK case 220: YY_RULE_SETUP -#line 344 "src/wasm-lexer.l" +#line 338 "src/wasm-lexer.l" { yyerror(yylloc, &yyscanner, parser, "unexpected char"); } YY_BREAK case 221: YY_RULE_SETUP -#line 347 "src/wasm-lexer.l" +#line 341 "src/wasm-lexer.l" ECHO; YY_BREAK -#line 2765 "src/wasm-lexer.c" +#line 2759 "src/wasm-lexer.c" case YY_END_OF_BUFFER: { @@ -3947,7 +3941,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 346 "src/wasm-lexer.l" +#line 340 "src/wasm-lexer.l" diff --git a/src/wasm-lexer.l b/src/wasm-lexer.l index fbc598f7..f57c9c19 100644 --- a/src/wasm-lexer.l +++ b/src/wasm-lexer.l @@ -28,6 +28,9 @@ typedef struct WasmScannerExtra { yylloc->last_column = extra->column; \ } +#define WASM_SIGN_S WASM_SIGNED +#define WASM_SIGN_U WASM_UNSIGNED + #define TEXT \ yylval->text.start = yytext; \ yylval->text.length = yyleng @@ -36,35 +39,26 @@ typedef struct WasmScannerExtra { yylval->text.length = yyleng - offset #define TYPE(type_) yylval->type = WASM_TYPE_##type_ #define TYPE_STRUCT(struct_, type_) yylval->struct_.type = WASM_TYPE_##type_ -#define SIGN(struct_, sign_) \ - yylval->struct_.sign = sign_ ? WASM_SIGNED : WASM_UNSIGNED -#define MEMOP(type_, size_) \ - TYPE_STRUCT(mem, type_); \ +#define MEMOP(type_, name, size_) \ + TYPE_STRUCT(mem, type_); \ + yylval->mem.op_type = WASM_MEM_OP_TYPE_##type_##_##name; \ + yylval->mem.size = WASM_MEM_SIZE_##size_ +#define MEMOPSIGN(type_, name, size_, sign_) \ + TYPE_STRUCT(mem, type_); \ + yylval->mem.op_type = WASM_MEM_OP_TYPE_##type_##_##name##size_##_##sign_; \ yylval->mem.size = WASM_MEM_SIZE_##size_ -#define MEMOPSIGN(type_, size_, sign_) \ - MEMOP(type_, size_); \ - SIGN(mem, sign_) -#define UNOP(type_, name) \ - TYPE_STRUCT(unary, type_); \ - yylval->unary.op_type = WASM_UNARY_OP_TYPE_##name +#define UNOP(type_, name) TYPE_STRUCT(unary, type_); \ + yylval->unary.op_type = WASM_UNARY_OP_TYPE_##type_##_##name #define BINOP(type_, name) \ TYPE_STRUCT(binary, type_); \ - yylval->binary.op_type = WASM_BINARY_OP_TYPE_##name -#define BINOPSIGN(type_, name, sign_) \ - BINOP(type_, name); \ - SIGN(binary, sign_) + yylval->binary.op_type = WASM_BINARY_OP_TYPE_##type_##_##name #define CMPOP(type_, name) \ TYPE_STRUCT(compare, type_); \ - yylval->compare.op_type = WASM_COMPARE_OP_TYPE_##name -#define CMPOPSIGN(type_, name, sign_) \ - CMPOP(type_, name); \ - SIGN(compare, sign_) -#define CONVTYPE(type_, type2_) \ - TYPE_STRUCT(convert, type_); \ + yylval->compare.op_type = WASM_COMPARE_OP_TYPE_##type_##_##name +#define CONVTYPE(type_, name, type2_) \ + TYPE_STRUCT(convert, type_); \ + yylval->convert.op_type = WASM_CONVERT_OP_TYPE_##type_##_##name##_##type2_; \ yylval->convert.type2 = WASM_TYPE_##type2_ -#define CONVTYPESIGN(type_, type2_, sign_) \ - CONVTYPE(type_, type2_); \ - SIGN(convert, sign_) #define CASTTYPE(type_, type2_) \ TYPE_STRUCT(cast, type_); \ yylval->cast.type2 = WASM_TYPE_##type2_ @@ -145,29 +139,29 @@ NAME \${ATOM} "return" { return TOK(RETURN); } "get_local" { return TOK(GET_LOCAL); } "set_local" { return TOK(SET_LOCAL); } -"i32.load" { MEMOP(I32, 32); return TOK(LOAD); } -"i64.load" { MEMOP(I64, 64); return TOK(LOAD); } -"f32.load" { MEMOP(F32, 32); return TOK(LOAD); } -"f64.load" { MEMOP(F64, 64); return TOK(LOAD); } -"i32.store" { MEMOP(I32, 32); return TOK(STORE); } -"i64.store" { MEMOP(I64, 64); return TOK(STORE); } -"f32.store" { MEMOP(F32, 32); return TOK(STORE); } -"f64.store" { MEMOP(F64, 64); return TOK(STORE); } -"i32.load8_s" { MEMOPSIGN(I32, 8, 1); return TOK(LOAD_EXTEND); } -"i64.load8_s" { MEMOPSIGN(I64, 8, 1); return TOK(LOAD_EXTEND); } -"i32.load8_u" { MEMOPSIGN(I32, 8, 0); return TOK(LOAD_EXTEND); } -"i64.load8_u" { MEMOPSIGN(I64, 8, 0); return TOK(LOAD_EXTEND); } -"i32.load16_s" { MEMOPSIGN(I32, 16, 1); return TOK(LOAD_EXTEND); } -"i64.load16_s" { MEMOPSIGN(I64, 16, 1); return TOK(LOAD_EXTEND); } -"i32.load16_u" { MEMOPSIGN(I32, 16, 0); return TOK(LOAD_EXTEND); } -"i64.load16_u" { MEMOPSIGN(I64, 16, 0); return TOK(LOAD_EXTEND); } -"i64.load32_s" { MEMOPSIGN(I64, 32, 1); return TOK(LOAD_EXTEND); } -"i64.load32_u" { MEMOPSIGN(I64, 32, 0); return TOK(LOAD_EXTEND); } -"i32.store8" { MEMOP(I32, 8); return TOK(STORE_WRAP); } -"i64.store8" { MEMOP(I64, 8); return TOK(STORE_WRAP); } -"i32.store16" { MEMOP(I32, 16); return TOK(STORE_WRAP); } -"i64.store16" { MEMOP(I64, 16); return TOK(STORE_WRAP); } -"i64.store32" { MEMOP(I64, 32); return TOK(STORE_WRAP); } +"i32.load" { MEMOP(I32, LOAD, 32); return TOK(LOAD); } +"i64.load" { MEMOP(I64, LOAD, 64); return TOK(LOAD); } +"f32.load" { MEMOP(F32, LOAD, 32); return TOK(LOAD); } +"f64.load" { MEMOP(F64, LOAD, 64); return TOK(LOAD); } +"i32.store" { MEMOP(I32, STORE, 32); return TOK(STORE); } +"i64.store" { MEMOP(I64, STORE, 64); return TOK(STORE); } +"f32.store" { MEMOP(F32, STORE, 32); return TOK(STORE); } +"f64.store" { MEMOP(F64, STORE, 64); return TOK(STORE); } +"i32.load8_s" { MEMOPSIGN(I32, LOAD, 8, S); return TOK(LOAD_EXTEND); } +"i64.load8_s" { MEMOPSIGN(I64, LOAD, 8, S); return TOK(LOAD_EXTEND); } +"i32.load8_u" { MEMOPSIGN(I32, LOAD, 8, U); return TOK(LOAD_EXTEND); } +"i64.load8_u" { MEMOPSIGN(I64, LOAD, 8, U); return TOK(LOAD_EXTEND); } +"i32.load16_s" { MEMOPSIGN(I32, LOAD, 16, S); return TOK(LOAD_EXTEND); } +"i64.load16_s" { MEMOPSIGN(I64, LOAD, 16, S); return TOK(LOAD_EXTEND); } +"i32.load16_u" { MEMOPSIGN(I32, LOAD, 16, U); return TOK(LOAD_EXTEND); } +"i64.load16_u" { MEMOPSIGN(I64, LOAD, 16, U); return TOK(LOAD_EXTEND); } +"i64.load32_s" { MEMOPSIGN(I64, LOAD, 32, S); return TOK(LOAD_EXTEND); } +"i64.load32_u" { MEMOPSIGN(I64, LOAD, 32, U); return TOK(LOAD_EXTEND); } +"i32.store8" { MEMOP(I32, STORE, 8); return TOK(STORE_WRAP); } +"i64.store8" { MEMOP(I64, STORE, 8); return TOK(STORE_WRAP); } +"i32.store16" { MEMOP(I32, STORE, 16); return TOK(STORE_WRAP); } +"i64.store16" { MEMOP(I64, STORE, 16); return TOK(STORE_WRAP); } +"i64.store32" { MEMOP(I64, STORE, 32); return TOK(STORE_WRAP); } "offset="{DIGITS} { TEXT_AT(7); return TOK(OFFSET); } "align="{DIGITS} { TEXT_AT(6); return TOK(ALIGN); } "i32.const" { TYPE(I32); return TOK(CONST); } @@ -201,14 +195,14 @@ NAME \${ATOM} "i64.sub" { BINOP(I64, SUB); return TOK(BINARY); } "i32.mul" { BINOP(I32, MUL); return TOK(BINARY); } "i64.mul" { BINOP(I64, MUL); return TOK(BINARY); } -"i32.div_s" { BINOPSIGN(I32, DIV, 1); return TOK(BINARY); } -"i64.div_s" { BINOPSIGN(I64, DIV, 1); return TOK(BINARY); } -"i32.div_u" { BINOPSIGN(I32, DIV, 0); return TOK(BINARY); } -"i64.div_u" { BINOPSIGN(I64, DIV, 0); return TOK(BINARY); } -"i32.rem_s" { BINOPSIGN(I32, REM, 1); return TOK(BINARY); } -"i64.rem_s" { BINOPSIGN(I64, REM, 1); return TOK(BINARY); } -"i32.rem_u" { BINOPSIGN(I32, REM, 0); return TOK(BINARY); } -"i64.rem_u" { BINOPSIGN(I64, REM, 0); return TOK(BINARY); } +"i32.div_s" { BINOP(I32, DIV_S); return TOK(BINARY); } +"i64.div_s" { BINOP(I64, DIV_S); return TOK(BINARY); } +"i32.div_u" { BINOP(I32, DIV_U); return TOK(BINARY); } +"i64.div_u" { BINOP(I64, DIV_U); return TOK(BINARY); } +"i32.rem_s" { BINOP(I32, REM_S); return TOK(BINARY); } +"i64.rem_s" { BINOP(I64, REM_S); return TOK(BINARY); } +"i32.rem_u" { BINOP(I32, REM_U); return TOK(BINARY); } +"i64.rem_u" { BINOP(I64, REM_U); return TOK(BINARY); } "i32.and" { BINOP(I32, AND); return TOK(BINARY); } "i64.and" { BINOP(I64, AND); return TOK(BINARY); } "i32.or" { BINOP(I32, OR); return TOK(BINARY); } @@ -217,10 +211,10 @@ NAME \${ATOM} "i64.xor" { BINOP(I64, XOR); return TOK(BINARY); } "i32.shl" { BINOP(I32, SHL); return TOK(BINARY); } "i64.shl" { BINOP(I64, SHL); return TOK(BINARY); } -"i32.shr_s" { BINOPSIGN(I32, SHR, 1); return TOK(BINARY); } -"i64.shr_s" { BINOPSIGN(I64, SHR, 1); return TOK(BINARY); } -"i32.shr_u" { BINOPSIGN(I32, SHR, 0); return TOK(BINARY); } -"i64.shr_u" { BINOPSIGN(I64, SHR, 0); return TOK(BINARY); } +"i32.shr_s" { BINOP(I32, SHR_S); return TOK(BINARY); } +"i64.shr_s" { BINOP(I64, SHR_S); return TOK(BINARY); } +"i32.shr_u" { BINOP(I32, SHR_U); return TOK(BINARY); } +"i64.shr_u" { BINOP(I64, SHR_U); return TOK(BINARY); } "f32.add" { BINOP(F32, ADD); return TOK(BINARY); } "f64.add" { BINOP(F64, ADD); return TOK(BINARY); } "f32.sub" { BINOP(F32, SUB); return TOK(BINARY); } @@ -237,24 +231,24 @@ NAME \${ATOM} "f64.copysign" { BINOP(F64, COPYSIGN); return TOK(BINARY); } "i32.eq" { CMPOP(I32, EQ); return TOK(COMPARE); } "i64.eq" { CMPOP(I64, EQ); return TOK(COMPARE); } -"i32.ne" { CMPOP(I32, EQ); return TOK(COMPARE); } -"i64.ne" { CMPOP(I64, EQ); return TOK(COMPARE); } -"i32.lt_s" { CMPOPSIGN(I32, LT, 1); return TOK(COMPARE); } -"i64.lt_s" { CMPOPSIGN(I64, LT, 1); return TOK(COMPARE); } -"i32.lt_u" { CMPOPSIGN(I32, LT, 0); return TOK(COMPARE); } -"i64.lt_u" { CMPOPSIGN(I64, LT, 0); return TOK(COMPARE); } -"i32.le_s" { CMPOPSIGN(I32, LE, 1); return TOK(COMPARE); } -"i64.le_s" { CMPOPSIGN(I64, LE, 1); return TOK(COMPARE); } -"i32.le_u" { CMPOPSIGN(I32, LE, 0); return TOK(COMPARE); } -"i64.le_u" { CMPOPSIGN(I64, LE, 0); return TOK(COMPARE); } -"i32.gt_s" { CMPOPSIGN(I32, GT, 1); return TOK(COMPARE); } -"i64.gt_s" { CMPOPSIGN(I64, GT, 1); return TOK(COMPARE); } -"i32.gt_u" { CMPOPSIGN(I32, GT, 0); return TOK(COMPARE); } -"i64.gt_u" { CMPOPSIGN(I64, GT, 0); return TOK(COMPARE); } -"i32.ge_s" { CMPOPSIGN(I32, GE, 1); return TOK(COMPARE); } -"i64.ge_s" { CMPOPSIGN(I64, GE, 1); return TOK(COMPARE); } -"i32.ge_u" { CMPOPSIGN(I32, GE, 0); return TOK(COMPARE); } -"i64.ge_u" { CMPOPSIGN(I64, GE, 0); return TOK(COMPARE); } +"i32.ne" { CMPOP(I32, NE); return TOK(COMPARE); } +"i64.ne" { CMPOP(I64, NE); return TOK(COMPARE); } +"i32.lt_s" { CMPOP(I32, LT_S); return TOK(COMPARE); } +"i64.lt_s" { CMPOP(I64, LT_S); return TOK(COMPARE); } +"i32.lt_u" { CMPOP(I32, LT_U); return TOK(COMPARE); } +"i64.lt_u" { CMPOP(I64, LT_U); return TOK(COMPARE); } +"i32.le_s" { CMPOP(I32, LE_S); return TOK(COMPARE); } +"i64.le_s" { CMPOP(I64, LE_S); return TOK(COMPARE); } +"i32.le_u" { CMPOP(I32, LE_U); return TOK(COMPARE); } +"i64.le_u" { CMPOP(I64, LE_U); return TOK(COMPARE); } +"i32.gt_s" { CMPOP(I32, GT_S); return TOK(COMPARE); } +"i64.gt_s" { CMPOP(I64, GT_S); return TOK(COMPARE); } +"i32.gt_u" { CMPOP(I32, GT_U); return TOK(COMPARE); } +"i64.gt_u" { CMPOP(I64, GT_U); return TOK(COMPARE); } +"i32.ge_s" { CMPOP(I32, GE_S); return TOK(COMPARE); } +"i64.ge_s" { CMPOP(I64, GE_S); return TOK(COMPARE); } +"i32.ge_u" { CMPOP(I32, GE_U); return TOK(COMPARE); } +"i64.ge_u" { CMPOP(I64, GE_U); return TOK(COMPARE); } "f32.eq" { CMPOP(F32, EQ); return TOK(COMPARE); } "f64.eq" { CMPOP(F64, EQ); return TOK(COMPARE); } "f32.ne" { CMPOP(F32, NE); return TOK(COMPARE); } @@ -267,27 +261,27 @@ NAME \${ATOM} "f64.gt" { CMPOP(F64, GT); return TOK(COMPARE); } "f32.ge" { CMPOP(F32, GE); return TOK(COMPARE); } "f64.ge" { CMPOP(F64, GE); return TOK(COMPARE); } -"i64.extend_s/i32" { CONVTYPESIGN(I64, I32, 1); return TOK(CONVERT); } -"i64.extend_u/i32" { CONVTYPESIGN(I64, I32, 0); return TOK(CONVERT); } -"i32.wrap/i64" { CONVTYPE(I32, I64); return TOK(CONVERT); } -"i32.trunc_s/f32" { CONVTYPESIGN(I32, F32, 1); return TOK(CONVERT); } -"i64.trunc_s/f32" { CONVTYPESIGN(I64, F32, 1); return TOK(CONVERT); } -"i32.trunc_s/f64" { CONVTYPESIGN(I32, F64, 1); return TOK(CONVERT); } -"i64.trunc_s/f64" { CONVTYPESIGN(I64, F64, 1); return TOK(CONVERT); } -"i32.trunc_u/f32" { CONVTYPESIGN(I32, F32, 0); return TOK(CONVERT); } -"i64.trunc_u/f32" { CONVTYPESIGN(I64, F32, 0); return TOK(CONVERT); } -"i32.trunc_u/f64" { CONVTYPESIGN(I32, F64, 0); return TOK(CONVERT); } -"i64.trunc_u/f64" { CONVTYPESIGN(I64, F64, 0); return TOK(CONVERT); } -"f32.convert_s/i32" { CONVTYPESIGN(F32, I32, 1); return TOK(CONVERT); } -"f64.convert_s/i32" { CONVTYPESIGN(F64, I32, 1); return TOK(CONVERT); } -"f32.convert_s/i64" { CONVTYPESIGN(F32, I64, 1); return TOK(CONVERT); } -"f64.convert_s/i64" { CONVTYPESIGN(F64, I64, 1); return TOK(CONVERT); } -"f32.convert_u/i32" { CONVTYPESIGN(F32, I32, 0); return TOK(CONVERT); } -"f64.convert_u/i32" { CONVTYPESIGN(F64, I32, 0); return TOK(CONVERT); } -"f32.convert_u/i64" { CONVTYPESIGN(F32, I64, 0); return TOK(CONVERT); } -"f64.convert_u/i64" { CONVTYPESIGN(F64, I64, 0); return TOK(CONVERT); } -"f64.promote/f32" { CONVTYPE(F64, F32); return TOK(CONVERT); } -"f32.demote/f64" { CONVTYPE(F32, F64); return TOK(CONVERT); } +"i64.extend_s/i32" { CONVTYPE(I64, EXTEND_S, I32); return TOK(CONVERT); } +"i64.extend_u/i32" { CONVTYPE(I64, EXTEND_U, I32); return TOK(CONVERT); } +"i32.wrap/i64" { CONVTYPE(I32, WRAP, I64); return TOK(CONVERT); } +"i32.trunc_s/f32" { CONVTYPE(I32, TRUNC_S, F32); return TOK(CONVERT); } +"i64.trunc_s/f32" { CONVTYPE(I64, TRUNC_S, F32); return TOK(CONVERT); } +"i32.trunc_s/f64" { CONVTYPE(I32, TRUNC_S, F64); return TOK(CONVERT); } +"i64.trunc_s/f64" { CONVTYPE(I64, TRUNC_S, F64); return TOK(CONVERT); } +"i32.trunc_u/f32" { CONVTYPE(I32, TRUNC_U, F32); return TOK(CONVERT); } +"i64.trunc_u/f32" { CONVTYPE(I64, TRUNC_U, F32); return TOK(CONVERT); } +"i32.trunc_u/f64" { CONVTYPE(I32, TRUNC_U, F64); return TOK(CONVERT); } +"i64.trunc_u/f64" { CONVTYPE(I64, TRUNC_U, F64); return TOK(CONVERT); } +"f32.convert_s/i32" { CONVTYPE(F32, CONVERT_S, I32); return TOK(CONVERT); } +"f64.convert_s/i32" { CONVTYPE(F64, CONVERT_S, I32); return TOK(CONVERT); } +"f32.convert_s/i64" { CONVTYPE(F32, CONVERT_S, I64); return TOK(CONVERT); } +"f64.convert_s/i64" { CONVTYPE(F64, CONVERT_S, I64); return TOK(CONVERT); } +"f32.convert_u/i32" { CONVTYPE(F32, CONVERT_U, I32); return TOK(CONVERT); } +"f64.convert_u/i32" { CONVTYPE(F64, CONVERT_U, I32); return TOK(CONVERT); } +"f32.convert_u/i64" { CONVTYPE(F32, CONVERT_U, I64); return TOK(CONVERT); } +"f64.convert_u/i64" { CONVTYPE(F64, CONVERT_U, I64); return TOK(CONVERT); } +"f64.promote/f32" { CONVTYPE(F64, PROMOTE, F32); return TOK(CONVERT); } +"f32.demote/f64" { CONVTYPE(F32, DEMOTE, F64); return TOK(CONVERT); } "f32.reinterpret/i32" { CASTTYPE(F32, I32); return TOK(CAST); } "i32.reinterpret/f32" { CASTTYPE(I32, F32); return TOK(CAST); } "f64.reinterpret/i64" { CASTTYPE(F64, I64); return TOK(CAST); } diff --git a/src/wasm-parser.c b/src/wasm-parser.c index fa196432..6d1d4688 100644 --- a/src/wasm-parser.c +++ b/src/wasm-parser.c @@ -566,15 +566,15 @@ static const yytype_uint16 yyrline[] = 436, 443, 448, 456, 461, 471, 474, 479, 487, 492, 502, 505, 506, 510, 515, 521, 528, 536, 545, 553, 560, 567, 574, 580, 587, 595, 602, 608, 615, 621, - 625, 630, 635, 641, 648, 656, 663, 669, 676, 682, - 687, 693, 700, 706, 710, 714, 719, 725, 732, 740, - 747, 753, 760, 766, 771, 777, 784, 790, 795, 801, - 806, 810, 815, 821, 828, 834, 839, 845, 850, 854, - 859, 865, 870, 873, 877, 882, 882, 893, 902, 903, - 907, 917, 928, 932, 939, 943, 950, 958, 965, 976, - 983, 987, 998, 999, 1006, 1013, 1020, 1027, 1034, 1041, - 1050, 1114, 1115, 1121, 1126, 1133, 1139, 1148, 1149, 1153, - 1162, 1163, 1166, 1167, 1171 + 626, 632, 637, 643, 650, 658, 665, 671, 678, 684, + 689, 695, 702, 708, 713, 717, 722, 728, 735, 743, + 750, 756, 763, 769, 774, 780, 787, 793, 798, 804, + 809, 813, 818, 824, 831, 837, 842, 848, 853, 857, + 862, 868, 873, 877, 882, 888, 888, 899, 908, 909, + 913, 923, 934, 938, 945, 949, 956, 964, 971, 982, + 989, 993, 1004, 1005, 1012, 1019, 1026, 1033, 1040, 1047, + 1056, 1120, 1121, 1127, 1132, 1139, 1145, 1154, 1155, 1159, + 1168, 1169, 1172, 1173, 1177 }; #endif @@ -2463,7 +2463,7 @@ yyreduce: case 82: #line 506 "src/wasm-parser.y" /* yacc.c:1646 */ { - (yyval.func).flags = 0; + (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[0].text); } #line 2470 "src/wasm-parser.c" /* yacc.c:1646 */ @@ -2663,45 +2663,47 @@ yyreduce: case 99: #line 621 "src/wasm-parser.y" /* yacc.c:1646 */ { + (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-1].text); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2670 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2671 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 100: -#line 625 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 626 "src/wasm-parser.y" /* yacc.c:1646 */ { + (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-2].text); (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2680 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2682 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 101: -#line 630 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 632 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-1].text); (yyval.func).params = (yyvsp[0].type_bindings); } -#line 2690 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2692 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 102: -#line 635 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 637 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-2].text); (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).result_type = (yyvsp[0].type); } -#line 2701 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2703 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 103: -#line 641 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 643 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-3].text); @@ -2709,11 +2711,11 @@ yyreduce: (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2713 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2715 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 104: -#line 648 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 650 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-4].text); @@ -2722,11 +2724,11 @@ yyreduce: (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2726 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2728 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 105: -#line 656 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 658 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-3].text); @@ -2734,22 +2736,22 @@ yyreduce: (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2738 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2740 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 106: -#line 663 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 665 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-2].text); (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2749 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2751 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 107: -#line 669 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 671 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-3].text); @@ -2757,43 +2759,43 @@ yyreduce: (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2761 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2763 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 108: -#line 676 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 678 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-2].text); (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2772 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2774 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 109: -#line 682 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 684 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-1].text); (yyval.func).result_type = (yyvsp[0].type); } -#line 2782 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2784 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 110: -#line 687 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 689 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-2].text); (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2793 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2795 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 111: -#line 693 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 695 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-3].text); @@ -2801,61 +2803,62 @@ yyreduce: (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2805 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2807 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 112: -#line 700 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 702 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-2].text); (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2816 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2818 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 113: -#line 706 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 708 "src/wasm-parser.y" /* yacc.c:1646 */ { + (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).name = (yyvsp[-1].text); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2825 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2828 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 114: -#line 710 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 713 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; (yyval.func).type_var = (yyvsp[0].var); } -#line 2834 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2837 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 115: -#line 714 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 717 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-1].var); (yyval.func).params = (yyvsp[0].type_bindings); } -#line 2844 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2847 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 116: -#line 719 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 722 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-2].var); (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).result_type = (yyvsp[0].type); } -#line 2855 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2858 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 117: -#line 725 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 728 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-3].var); @@ -2863,11 +2866,11 @@ yyreduce: (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2867 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2870 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 118: -#line 732 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 735 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-4].var); @@ -2876,11 +2879,11 @@ yyreduce: (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2880 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2883 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 119: -#line 740 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 743 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-3].var); @@ -2888,22 +2891,22 @@ yyreduce: (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2892 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2895 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 120: -#line 747 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 750 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-2].var); (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2903 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2906 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 121: -#line 753 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 756 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-3].var); @@ -2911,43 +2914,43 @@ yyreduce: (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2915 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2918 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 122: -#line 760 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 763 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-2].var); (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2926 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2929 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 123: -#line 766 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 769 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-1].var); (yyval.func).result_type = (yyvsp[0].type); } -#line 2936 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2939 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 124: -#line 771 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 774 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-2].var); (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2947 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2950 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 125: -#line 777 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 780 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-3].var); @@ -2955,83 +2958,83 @@ yyreduce: (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2959 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2962 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 126: -#line 784 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 787 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).type_var = (yyvsp[-2].var); (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2970 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2973 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 127: -#line 790 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 793 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; (yyval.func).type_var = (yyvsp[-1].var); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 2980 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2983 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 128: -#line 795 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 798 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; (yyval.func).type_var = (yyvsp[-2].var); (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 2991 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 2994 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 129: -#line 801 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 804 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; (yyval.func).type_var = (yyvsp[-1].var); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3001 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3004 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 130: -#line 806 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 809 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[0].type_bindings); } -#line 3010 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3013 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 131: -#line 810 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 813 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).result_type = (yyvsp[0].type); } -#line 3020 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3023 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 132: -#line 815 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 818 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[-2].type_bindings); (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 3031 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3034 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 133: -#line 821 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 824 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[-3].type_bindings); @@ -3039,135 +3042,138 @@ yyreduce: (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3043 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3046 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 134: -#line 828 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 831 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[-2].type_bindings); (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3054 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3057 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 135: -#line 834 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 837 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 3064 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3067 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 136: -#line 839 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 842 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[-2].type_bindings); (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3075 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3078 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 137: -#line 845 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 848 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).params = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3085 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3088 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 138: -#line 850 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 853 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).result_type = (yyvsp[0].type); } -#line 3094 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3097 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 139: -#line 854 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 857 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 3104 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3107 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 140: -#line 859 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 862 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).result_type = (yyvsp[-2].type); (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3115 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3118 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 141: -#line 865 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 868 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).result_type = (yyvsp[-1].type); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3125 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3128 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 142: -#line 870 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 873 "src/wasm-parser.y" /* yacc.c:1646 */ { + (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).locals = (yyvsp[0].type_bindings); } -#line 3133 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3137 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 143: -#line 873 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 877 "src/wasm-parser.y" /* yacc.c:1646 */ { + (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).locals = (yyvsp[-1].type_bindings); (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3142 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3147 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 144: -#line 877 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 882 "src/wasm-parser.y" /* yacc.c:1646 */ { + (yyval.func).flags = WASM_FUNC_FLAG_HAS_SIGNATURE; (yyval.func).exprs = (yyvsp[0].exprs); } -#line 3150 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3156 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 145: -#line 882 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 888 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.func)); } -#line 3156 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3162 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 146: -#line 882 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 888 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[-1].func); (yyval.func).loc = (yylsp[-3]); extend_type_bindings(&(yyval.func).params_and_locals, &(yyval.func).params); extend_type_bindings(&(yyval.func).params_and_locals, &(yyval.func).locals); } -#line 3167 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3173 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 147: -#line 893 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 899 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.segment).loc = (yylsp[-3]); if (!read_int32((yyvsp[-2].text).start, (yyvsp[-2].text).start + (yyvsp[-2].text).length, &(yyval.segment).addr, 0)) @@ -3175,23 +3181,23 @@ yyreduce: (yyvsp[-2].text).length, (yyvsp[-2].text).start); dup_string_contents(&(yyvsp[-1].text), &(yyval.segment).data, &(yyval.segment).size); } -#line 3179 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3185 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 148: -#line 902 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 908 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.segments)); } -#line 3185 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3191 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 149: -#line 903 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 909 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.segments) = (yyvsp[-1].segments); *wasm_append_segment(&(yyval.segments)) = (yyvsp[0].segment); } -#line 3191 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3197 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 150: -#line 907 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 913 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.memory).loc = (yylsp[-4]); if (!read_int32((yyvsp[-3].text).start, (yyvsp[-3].text).start + (yyvsp[-3].text).length, &(yyval.memory).initial_size, 0)) @@ -3202,11 +3208,11 @@ yyreduce: (yyvsp[-2].text).length, (yyvsp[-2].text).start); (yyval.memory).segments = (yyvsp[-1].segments); } -#line 3206 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3212 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 151: -#line 917 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 923 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.memory).loc = (yylsp[-3]); if (!read_int32((yyvsp[-2].text).start, (yyvsp[-2].text).start + (yyvsp[-2].text).length, &(yyval.memory).initial_size, 0)) @@ -3215,35 +3221,35 @@ yyreduce: (yyval.memory).max_size = (yyval.memory).initial_size; (yyval.memory).segments = (yyvsp[-1].segments); } -#line 3219 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3225 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 152: -#line 928 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 934 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.func_type)); (yyval.func_type).sig = (yyvsp[-2].func_sig); } -#line 3228 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3234 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 153: -#line 932 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 938 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.func_type).name = (yyvsp[-5].text); (yyval.func_type).sig = (yyvsp[-2].func_sig); } -#line 3237 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3243 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 154: -#line 939 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 945 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.vars) = (yyvsp[-1].vars); } -#line 3243 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3249 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 155: -#line 943 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 949 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.import)); (yyval.import).import_type = WASM_IMPORT_HAS_TYPE; @@ -3251,11 +3257,11 @@ yyreduce: DUPTEXT((yyval.import).func_name, (yyvsp[-2].text)); (yyval.import).type_var = (yyvsp[-1].var); } -#line 3255 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3261 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 156: -#line 950 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 956 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.import)); (yyval.import).import_type = WASM_IMPORT_HAS_TYPE; @@ -3264,11 +3270,11 @@ yyreduce: DUPTEXT((yyval.import).func_name, (yyvsp[-2].text)); (yyval.import).type_var = (yyvsp[-1].var); } -#line 3268 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3274 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 157: -#line 958 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 964 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.import)); (yyval.import).import_type = WASM_IMPORT_HAS_FUNC_SIGNATURE; @@ -3276,11 +3282,11 @@ yyreduce: DUPTEXT((yyval.import).func_name, (yyvsp[-2].text)); (yyval.import).func_sig = (yyvsp[-1].func_sig); } -#line 3280 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3286 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 158: -#line 965 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 971 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.import)); (yyval.import).import_type = WASM_IMPORT_HAS_FUNC_SIGNATURE; @@ -3289,29 +3295,29 @@ yyreduce: DUPTEXT((yyval.import).func_name, (yyvsp[-2].text)); (yyval.import).func_sig = (yyvsp[-1].func_sig); } -#line 3293 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3299 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 159: -#line 976 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 982 "src/wasm-parser.y" /* yacc.c:1646 */ { DUPQUOTEDTEXT((yyval.export).name, (yyvsp[-2].text)); (yyval.export).var = (yyvsp[-1].var); } -#line 3302 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3308 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 160: -#line 983 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 989 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.type_bindings)); (yyval.type_bindings).types = (yyvsp[-1].types); } -#line 3311 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3317 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 161: -#line 987 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 993 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.type_bindings)); WasmBinding* binding = wasm_append_binding(&(yyval.type_bindings).bindings); @@ -3320,17 +3326,17 @@ yyreduce: binding->index = 0; *wasm_append_type(&(yyval.type_bindings).types) = (yyvsp[-1].type); } -#line 3324 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3330 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 162: -#line 998 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1004 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.module_fields)); } -#line 3330 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3336 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 163: -#line 999 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1005 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); WasmModuleField* field = wasm_append_module_field(&(yyval.module_fields)); @@ -3338,11 +3344,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_FUNC; field->func = (yyvsp[0].func); } -#line 3342 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3348 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 164: -#line 1006 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1012 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); WasmModuleField* field = wasm_append_module_field(&(yyval.module_fields)); @@ -3350,11 +3356,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_IMPORT; field->import = (yyvsp[0].import); } -#line 3354 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3360 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 165: -#line 1013 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1019 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); WasmModuleField* field = wasm_append_module_field(&(yyval.module_fields)); @@ -3362,11 +3368,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_EXPORT; field->export = (yyvsp[0].export); } -#line 3366 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3372 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 166: -#line 1020 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1026 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); WasmModuleField* field = wasm_append_module_field(&(yyval.module_fields)); @@ -3374,11 +3380,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_TABLE; field->table = (yyvsp[0].vars); } -#line 3378 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3384 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 167: -#line 1027 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1033 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); WasmModuleField* field = wasm_append_module_field(&(yyval.module_fields)); @@ -3386,11 +3392,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_FUNC_TYPE; field->func_type = (yyvsp[0].func_type); } -#line 3390 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3396 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 168: -#line 1034 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1040 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); WasmModuleField* field = wasm_append_module_field(&(yyval.module_fields)); @@ -3398,11 +3404,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_MEMORY; field->memory = (yyvsp[0].memory); } -#line 3402 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3408 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 169: -#line 1041 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1047 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); WasmModuleField* field = wasm_append_module_field(&(yyval.module_fields)); @@ -3410,11 +3416,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_GLOBAL; field->global = (yyvsp[0].type_bindings); } -#line 3414 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3420 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 170: -#line 1050 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1056 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.module).loc = (yylsp[-2]); (yyval.module).fields = (yyvsp[-1].module_fields); @@ -3473,38 +3479,38 @@ yyreduce: } } } -#line 3477 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3483 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 171: -#line 1114 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1120 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.command).type = WASM_COMMAND_TYPE_MODULE; (yyval.command).module = (yyvsp[0].module); } -#line 3483 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3489 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 172: -#line 1115 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1121 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.command).type = WASM_COMMAND_TYPE_INVOKE; (yyval.command).invoke.loc = (yylsp[-3]); DUPQUOTEDTEXT((yyval.command).invoke.name, (yyvsp[-2].text)); (yyval.command).invoke.args = (yyvsp[-1].consts); } -#line 3494 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3500 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 173: -#line 1121 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1127 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.command).type = WASM_COMMAND_TYPE_ASSERT_INVALID; (yyval.command).assert_invalid.module = (yyvsp[-2].module); (yyval.command).assert_invalid.text = (yyvsp[-1].text); } -#line 3504 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3510 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 174: -#line 1126 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1132 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.command).type = WASM_COMMAND_TYPE_ASSERT_RETURN; (yyval.command).assert_return.invoke.loc = (yylsp[-5]); @@ -3512,22 +3518,22 @@ yyreduce: (yyval.command).assert_return.invoke.args = (yyvsp[-3].consts); (yyval.command).assert_return.expected = (yyvsp[-1].const_); } -#line 3516 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3522 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 175: -#line 1133 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1139 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.command).type = WASM_COMMAND_TYPE_ASSERT_RETURN_NAN; (yyval.command).assert_return_nan.invoke.loc = (yylsp[-4]); DUPQUOTEDTEXT((yyval.command).assert_return_nan.invoke.name, (yyvsp[-3].text)); (yyval.command).assert_return_nan.invoke.args = (yyvsp[-2].consts); } -#line 3527 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3533 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 176: -#line 1139 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1145 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.command).type = WASM_COMMAND_TYPE_ASSERT_TRAP; (yyval.command).assert_trap.invoke.loc = (yylsp[-5]); @@ -3535,23 +3541,23 @@ yyreduce: (yyval.command).assert_trap.invoke.args = (yyvsp[-3].consts); (yyval.command).assert_trap.text = (yyvsp[-1].text); } -#line 3539 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3545 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 177: -#line 1148 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1154 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.commands)); } -#line 3545 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3551 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 178: -#line 1149 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1155 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.commands) = (yyvsp[-1].commands); *wasm_append_command(&(yyval.commands)) = (yyvsp[0].command); } -#line 3551 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3557 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 179: -#line 1153 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1159 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.const_).loc = (yylsp[-2]); if (!read_const((yyvsp[-2].type), (yyvsp[-1].text).start, (yyvsp[-1].text).start + (yyvsp[-1].text).length, &(yyval.const_))) @@ -3559,35 +3565,35 @@ yyreduce: (yyvsp[-1].text).length, (yyvsp[-1].text).start); free((char*)(yyvsp[-1].text).start); } -#line 3563 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3569 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 180: -#line 1162 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1168 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.const_).type = WASM_TYPE_VOID; } -#line 3569 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3575 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 182: -#line 1166 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1172 "src/wasm-parser.y" /* yacc.c:1646 */ { ZEROMEM((yyval.consts)); } -#line 3575 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3581 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 183: -#line 1167 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1173 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.consts) = (yyvsp[-1].consts); *wasm_append_const(&(yyval.consts)) = (yyvsp[0].const_); } -#line 3581 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3587 "src/wasm-parser.c" /* yacc.c:1646 */ break; case 184: -#line 1171 "src/wasm-parser.y" /* yacc.c:1646 */ +#line 1177 "src/wasm-parser.y" /* yacc.c:1646 */ { (yyval.script).commands = (yyvsp[0].commands); parser->script = (yyval.script); } -#line 3587 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3593 "src/wasm-parser.c" /* yacc.c:1646 */ break; -#line 3591 "src/wasm-parser.c" /* yacc.c:1646 */ +#line 3597 "src/wasm-parser.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -3822,7 +3828,7 @@ yyreturn: #endif return yyresult; } -#line 1174 "src/wasm-parser.y" /* yacc.c:1906 */ +#line 1180 "src/wasm-parser.y" /* yacc.c:1906 */ DEFINE_VECTOR(type, WasmType) diff --git a/src/wasm-parser.y b/src/wasm-parser.y index 22e60cb0..b1562b15 100644 --- a/src/wasm-parser.y +++ b/src/wasm-parser.y @@ -504,7 +504,7 @@ type_use : func_info : /* empty */ {} | bind_var { - $$.flags = 0; + $$.flags = WASM_FUNC_FLAG_HAS_SIGNATURE; $$.name = $1; } | bind_var type_use { @@ -619,10 +619,12 @@ func_info : $$.exprs = $3; } | bind_var local_list { + $$.flags = WASM_FUNC_FLAG_HAS_SIGNATURE; $$.name = $1; $$.locals = $2; } | bind_var local_list non_empty_expr_list { + $$.flags = WASM_FUNC_FLAG_HAS_SIGNATURE; $$.name = $1; $$.locals = $2; $$.exprs = $3; @@ -704,6 +706,7 @@ func_info : $$.exprs = $3; } | bind_var non_empty_expr_list { + $$.flags = WASM_FUNC_FLAG_HAS_SIGNATURE; $$.name = $1; $$.exprs = $2; } @@ -868,13 +871,16 @@ func_info : $$.exprs = $2; } | local_list { + $$.flags = WASM_FUNC_FLAG_HAS_SIGNATURE; $$.locals = $1; } | local_list non_empty_expr_list { + $$.flags = WASM_FUNC_FLAG_HAS_SIGNATURE; $$.locals = $1; $$.exprs = $2; } | non_empty_expr_list { + $$.flags = WASM_FUNC_FLAG_HAS_SIGNATURE; $$.exprs = $1; } ; @@ -47,50 +47,158 @@ typedef enum WasmMemSize { WASM_MEM_SIZE_64 = 64, } WasmMemSize; -typedef enum WasmSigned { - WASM_SIGNED, - WASM_UNSIGNED, -} WasmSigned; - typedef enum WasmUnaryOpType { - WASM_UNARY_OP_TYPE_NOT, - WASM_UNARY_OP_TYPE_CLZ, - WASM_UNARY_OP_TYPE_CTZ, - WASM_UNARY_OP_TYPE_POPCNT, - WASM_UNARY_OP_TYPE_NEG, - WASM_UNARY_OP_TYPE_ABS, - WASM_UNARY_OP_TYPE_SQRT, - WASM_UNARY_OP_TYPE_CEIL, - WASM_UNARY_OP_TYPE_FLOOR, - WASM_UNARY_OP_TYPE_TRUNC, - WASM_UNARY_OP_TYPE_NEAREST, + WASM_UNARY_OP_TYPE_F32_ABS, + WASM_UNARY_OP_TYPE_F32_CEIL, + WASM_UNARY_OP_TYPE_F32_FLOOR, + WASM_UNARY_OP_TYPE_F32_NEAREST, + WASM_UNARY_OP_TYPE_F32_NEG, + WASM_UNARY_OP_TYPE_F32_SQRT, + WASM_UNARY_OP_TYPE_F32_TRUNC, + WASM_UNARY_OP_TYPE_F64_ABS, + WASM_UNARY_OP_TYPE_F64_CEIL, + WASM_UNARY_OP_TYPE_F64_FLOOR, + WASM_UNARY_OP_TYPE_F64_NEAREST, + WASM_UNARY_OP_TYPE_F64_NEG, + WASM_UNARY_OP_TYPE_F64_SQRT, + WASM_UNARY_OP_TYPE_F64_TRUNC, + WASM_UNARY_OP_TYPE_I32_CLZ, + WASM_UNARY_OP_TYPE_I32_CTZ, + WASM_UNARY_OP_TYPE_I32_NOT, + WASM_UNARY_OP_TYPE_I32_POPCNT, + WASM_UNARY_OP_TYPE_I64_CLZ, + WASM_UNARY_OP_TYPE_I64_CTZ, + WASM_UNARY_OP_TYPE_I64_POPCNT, } WasmUnaryOpType; typedef enum WasmBinaryOpType { - WASM_BINARY_OP_TYPE_ADD, - WASM_BINARY_OP_TYPE_SUB, - WASM_BINARY_OP_TYPE_MUL, - WASM_BINARY_OP_TYPE_DIV, - WASM_BINARY_OP_TYPE_REM, - WASM_BINARY_OP_TYPE_AND, - WASM_BINARY_OP_TYPE_OR, - WASM_BINARY_OP_TYPE_XOR, - WASM_BINARY_OP_TYPE_SHL, - WASM_BINARY_OP_TYPE_SHR, - WASM_BINARY_OP_TYPE_MIN, - WASM_BINARY_OP_TYPE_MAX, - WASM_BINARY_OP_TYPE_COPYSIGN, + WASM_BINARY_OP_TYPE_F32_ADD, + WASM_BINARY_OP_TYPE_F32_COPYSIGN, + WASM_BINARY_OP_TYPE_F32_DIV, + WASM_BINARY_OP_TYPE_F32_MAX, + WASM_BINARY_OP_TYPE_F32_MIN, + WASM_BINARY_OP_TYPE_F32_MUL, + WASM_BINARY_OP_TYPE_F32_SUB, + WASM_BINARY_OP_TYPE_F64_ADD, + WASM_BINARY_OP_TYPE_F64_COPYSIGN, + WASM_BINARY_OP_TYPE_F64_DIV, + WASM_BINARY_OP_TYPE_F64_MAX, + WASM_BINARY_OP_TYPE_F64_MIN, + WASM_BINARY_OP_TYPE_F64_MUL, + WASM_BINARY_OP_TYPE_F64_SUB, + WASM_BINARY_OP_TYPE_I32_ADD, + WASM_BINARY_OP_TYPE_I32_AND, + WASM_BINARY_OP_TYPE_I32_DIV_S, + WASM_BINARY_OP_TYPE_I32_DIV_U, + WASM_BINARY_OP_TYPE_I32_MUL, + WASM_BINARY_OP_TYPE_I32_OR, + WASM_BINARY_OP_TYPE_I32_REM_S, + WASM_BINARY_OP_TYPE_I32_REM_U, + WASM_BINARY_OP_TYPE_I32_SHL, + WASM_BINARY_OP_TYPE_I32_SHR_S, + WASM_BINARY_OP_TYPE_I32_SHR_U, + WASM_BINARY_OP_TYPE_I32_SUB, + WASM_BINARY_OP_TYPE_I32_XOR, + WASM_BINARY_OP_TYPE_I64_ADD, + WASM_BINARY_OP_TYPE_I64_AND, + WASM_BINARY_OP_TYPE_I64_DIV_S, + WASM_BINARY_OP_TYPE_I64_DIV_U, + WASM_BINARY_OP_TYPE_I64_MUL, + WASM_BINARY_OP_TYPE_I64_OR, + WASM_BINARY_OP_TYPE_I64_REM_S, + WASM_BINARY_OP_TYPE_I64_REM_U, + WASM_BINARY_OP_TYPE_I64_SHL, + WASM_BINARY_OP_TYPE_I64_SHR_S, + WASM_BINARY_OP_TYPE_I64_SHR_U, + WASM_BINARY_OP_TYPE_I64_SUB, + WASM_BINARY_OP_TYPE_I64_XOR, } WasmBinaryOpType; typedef enum WasmCompareOpType { - WASM_COMPARE_OP_TYPE_EQ, - WASM_COMPARE_OP_TYPE_NE, - WASM_COMPARE_OP_TYPE_LT, - WASM_COMPARE_OP_TYPE_LE, - WASM_COMPARE_OP_TYPE_GT, - WASM_COMPARE_OP_TYPE_GE, + WASM_COMPARE_OP_TYPE_F32_EQ, + WASM_COMPARE_OP_TYPE_F32_GE, + WASM_COMPARE_OP_TYPE_F32_GT, + WASM_COMPARE_OP_TYPE_F32_LE, + WASM_COMPARE_OP_TYPE_F32_LT, + WASM_COMPARE_OP_TYPE_F32_NE, + WASM_COMPARE_OP_TYPE_F64_EQ, + WASM_COMPARE_OP_TYPE_F64_GE, + WASM_COMPARE_OP_TYPE_F64_GT, + WASM_COMPARE_OP_TYPE_F64_LE, + WASM_COMPARE_OP_TYPE_F64_LT, + WASM_COMPARE_OP_TYPE_F64_NE, + WASM_COMPARE_OP_TYPE_I32_EQ, + WASM_COMPARE_OP_TYPE_I32_GE_S, + WASM_COMPARE_OP_TYPE_I32_GE_U, + WASM_COMPARE_OP_TYPE_I32_GT_S, + WASM_COMPARE_OP_TYPE_I32_GT_U, + WASM_COMPARE_OP_TYPE_I32_LE_S, + WASM_COMPARE_OP_TYPE_I32_LE_U, + WASM_COMPARE_OP_TYPE_I32_LT_S, + WASM_COMPARE_OP_TYPE_I32_LT_U, + WASM_COMPARE_OP_TYPE_I32_NE, + WASM_COMPARE_OP_TYPE_I64_EQ, + WASM_COMPARE_OP_TYPE_I64_GE_S, + WASM_COMPARE_OP_TYPE_I64_GE_U, + WASM_COMPARE_OP_TYPE_I64_GT_S, + WASM_COMPARE_OP_TYPE_I64_GT_U, + WASM_COMPARE_OP_TYPE_I64_LE_S, + WASM_COMPARE_OP_TYPE_I64_LE_U, + WASM_COMPARE_OP_TYPE_I64_LT_S, + WASM_COMPARE_OP_TYPE_I64_LT_U, + WASM_COMPARE_OP_TYPE_I64_NE, } WasmCompareOpType; +typedef enum WasmMemOpType { + WASM_MEM_OP_TYPE_F32_LOAD, + WASM_MEM_OP_TYPE_F32_STORE, + WASM_MEM_OP_TYPE_F64_LOAD, + WASM_MEM_OP_TYPE_F64_STORE, + WASM_MEM_OP_TYPE_I32_LOAD, + WASM_MEM_OP_TYPE_I32_LOAD8_S, + WASM_MEM_OP_TYPE_I32_LOAD8_U, + WASM_MEM_OP_TYPE_I32_LOAD16_S, + WASM_MEM_OP_TYPE_I32_LOAD16_U, + WASM_MEM_OP_TYPE_I32_STORE, + WASM_MEM_OP_TYPE_I32_STORE8, + WASM_MEM_OP_TYPE_I32_STORE16, + WASM_MEM_OP_TYPE_I64_LOAD, + WASM_MEM_OP_TYPE_I64_LOAD8_S, + WASM_MEM_OP_TYPE_I64_LOAD8_U, + WASM_MEM_OP_TYPE_I64_LOAD16_S, + WASM_MEM_OP_TYPE_I64_LOAD16_U, + WASM_MEM_OP_TYPE_I64_LOAD32_S, + WASM_MEM_OP_TYPE_I64_LOAD32_U, + WASM_MEM_OP_TYPE_I64_STORE, + WASM_MEM_OP_TYPE_I64_STORE8, + WASM_MEM_OP_TYPE_I64_STORE16, + WASM_MEM_OP_TYPE_I64_STORE32, +} WasmMemOpType; + +typedef enum WasmConvertOpType { + WASM_CONVERT_OP_TYPE_F32_CONVERT_S_I32, + WASM_CONVERT_OP_TYPE_F32_CONVERT_S_I64, + WASM_CONVERT_OP_TYPE_F32_CONVERT_U_I32, + WASM_CONVERT_OP_TYPE_F32_CONVERT_U_I64, + WASM_CONVERT_OP_TYPE_F32_DEMOTE_F64, + WASM_CONVERT_OP_TYPE_F64_CONVERT_S_I32, + WASM_CONVERT_OP_TYPE_F64_CONVERT_S_I64, + WASM_CONVERT_OP_TYPE_F64_CONVERT_U_I32, + WASM_CONVERT_OP_TYPE_F64_CONVERT_U_I64, + WASM_CONVERT_OP_TYPE_F64_PROMOTE_F32, + WASM_CONVERT_OP_TYPE_I32_TRUNC_S_F32, + WASM_CONVERT_OP_TYPE_I32_TRUNC_S_F64, + WASM_CONVERT_OP_TYPE_I32_TRUNC_U_F32, + WASM_CONVERT_OP_TYPE_I32_TRUNC_U_F64, + WASM_CONVERT_OP_TYPE_I32_WRAP_I64, + WASM_CONVERT_OP_TYPE_I64_EXTEND_S_I32, + WASM_CONVERT_OP_TYPE_I64_EXTEND_U_I32, + WASM_CONVERT_OP_TYPE_I64_TRUNC_S_F32, + WASM_CONVERT_OP_TYPE_I64_TRUNC_S_F64, + WASM_CONVERT_OP_TYPE_I64_TRUNC_U_F32, + WASM_CONVERT_OP_TYPE_I64_TRUNC_U_F64, +} WasmConvertOpType; + typedef struct WasmUnaryOp { WasmType type; WasmUnaryOpType op_type; @@ -99,19 +207,17 @@ typedef struct WasmUnaryOp { typedef struct WasmBinaryOp { WasmType type; WasmBinaryOpType op_type; - WasmSigned sign; } WasmBinaryOp; typedef struct WasmCompareOp { WasmType type; WasmCompareOpType op_type; - WasmSigned sign; } WasmCompareOp; typedef struct WasmConvertOp { WasmType type; + WasmConvertOpType op_type; WasmType type2; - WasmSigned sign; } WasmConvertOp; typedef struct WasmCastOp { @@ -121,8 +227,8 @@ typedef struct WasmCastOp { typedef struct WasmMemOp { WasmType type; + WasmMemOpType op_type; WasmMemSize size; - WasmSigned sign; } WasmMemOp; typedef enum WasmVarType { @@ -430,8 +536,28 @@ typedef struct WasmParser { int errors; } WasmParser; +typedef struct WasmBinaryWriter { + void* user_data; + void (*write_data)(size_t offset, + const void* data, + size_t size, + void* user_data); + int log_writes; +} WasmBinaryWriter; + WasmScanner wasm_new_scanner(const char* filename); void wasm_free_scanner(WasmScanner scanner); WasmResult wasm_check_script(WasmScript*); +WasmResult wasm_write_binary(WasmBinaryWriter*, WasmScript*); + +int wasm_get_func_index_by_var(WasmModule* module, WasmVar* var); +int wasm_get_func_type_index_by_var(WasmModule* module, WasmVar* var); +int wasm_get_import_index_by_var(WasmModule* module, WasmVar* var); + +WasmFuncPtr wasm_get_func_by_var(WasmModule* module, WasmVar* var); +WasmFuncTypePtr wasm_get_func_type_by_var(WasmModule* module, WasmVar* var); +WasmImportPtr wasm_get_import_by_var(WasmModule* module, WasmVar* var); + +int wasm_func_is_exported(WasmModule* module, WasmFunc* func); #endif /* WASM_H_ */ |