Commit 3f207617 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Binary 0xD: update encoding of opcodes, types, and add immediates.

R=ahaas@chromium.org,rossberg@chromium.org,binji@chromium.org,bradnelson@chromium.org
BUG=chromium:575167, chromium:659591

Review-Url: https://codereview.chromium.org/2440953002
Cr-Commit-Position: refs/heads/master@{#40600}
parent ff5194e3
......@@ -1394,6 +1394,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
current_function_builder_->AddAsmWasmOffset(expr->position());
current_function_builder_->Emit(kExprCallIndirect);
current_function_builder_->EmitVarInt(indices->signature_index);
current_function_builder_->EmitVarInt(0); // table index
returns_value =
builder_->GetSignature(indices->signature_index)->return_count() >
0;
......
......@@ -317,6 +317,11 @@ class WasmDecoder : public Decoder {
ImmI64Operand operand(this, pc);
return 1 + operand.length;
}
case kExprGrowMemory:
case kExprMemorySize: {
MemoryIndexOperand operand(this, pc);
return 1 + operand.length;
}
case kExprI8Const:
return 2;
case kExprF32Const:
......@@ -1102,17 +1107,23 @@ class WasmFullDecoder : public WasmDecoder {
case kExprF64StoreMem:
len = DecodeStoreMem(kAstF64, MachineType::Float64());
break;
case kExprGrowMemory:
case kExprGrowMemory: {
MemoryIndexOperand operand(this, pc_);
if (module_->origin != kAsmJsOrigin) {
Value val = Pop(0, kAstI32);
Push(kAstI32, BUILD(GrowMemory, val.node));
} else {
error("grow_memory is not supported for asmjs modules");
}
len = 1 + operand.length;
break;
case kExprMemorySize:
}
case kExprMemorySize: {
MemoryIndexOperand operand(this, pc_);
Push(kAstI32, BUILD(CurrentMemoryPages));
len = 1 + operand.length;
break;
}
case kExprCallFunction: {
CallFunctionOperand operand(this, pc_);
if (Validate(pc_, operand)) {
......
......@@ -186,14 +186,19 @@ struct BreakDepthOperand {
};
struct CallIndirectOperand {
uint32_t table_index;
uint32_t index;
FunctionSig* sig;
unsigned length;
inline CallIndirectOperand(Decoder* decoder, const byte* pc) {
unsigned len1 = 0;
unsigned len2 = 0;
index = decoder->checked_read_u32v(pc, 1 + len1, &len2, "signature index");
length = len1 + len2;
unsigned len = 0;
index = decoder->checked_read_u32v(pc, 1, &len, "signature index");
table_index = decoder->checked_read_u8(pc, 1 + len, "table index");
if (table_index != 0) {
decoder->error(pc, pc + 1 + len, "expected table index 0, found %u",
table_index);
}
length = 1 + len;
sig = nullptr;
}
};
......@@ -211,6 +216,18 @@ struct CallFunctionOperand {
}
};
struct MemoryIndexOperand {
uint32_t index;
unsigned length;
inline MemoryIndexOperand(Decoder* decoder, const byte* pc) {
index = decoder->checked_read_u8(pc, 1, "memory index");
if (index != 0) {
decoder->error(pc, pc + 1, "expected memory index 0, found %u", index);
}
length = 1;
}
};
struct BranchTableOperand {
uint32_t table_count;
const byte* start;
......
......@@ -313,7 +313,7 @@ class ModuleDecoder : public Decoder {
static_cast<uint32_t>(module->function_tables.size());
module->function_tables.push_back(
{0, 0, std::vector<int32_t>(), true, false, SignatureMap()});
expect_u8("element type", 0x20);
expect_u8("element type", kWasmAnyFunctionTypeForm);
WasmIndirectFunctionTable* table = &module->function_tables.back();
consume_resizable_limits("element count", "elements", kMaxTableSize,
&table->size, &table->max_size);
......
......@@ -1592,13 +1592,17 @@ class ThreadImpl : public WasmInterpreter::Thread {
ASMJS_STORE_CASE(F64AsmjsStoreMem, double, double);
#undef ASMJS_STORE_CASE
case kExprGrowMemory: {
MemoryIndexOperand operand(&decoder, code->at(pc));
uint32_t delta_pages = Pop().to<uint32_t>();
Push(pc, WasmVal(ExecuteGrowMemory(delta_pages, instance())));
len = 1 + operand.length;
break;
}
case kExprMemorySize: {
MemoryIndexOperand operand(&decoder, code->at(pc));
Push(pc, WasmVal(static_cast<uint32_t>(instance()->mem_size /
WasmModule::kPageSize)));
len = 1 + operand.length;
break;
}
#define EXECUTE_SIMPLE_BINOP(name, ctype, op) \
......
......@@ -420,21 +420,23 @@ class LocalDeclEncoder {
#define WASM_CALL_FUNCTION(index, ...) \
__VA_ARGS__, kExprCallFunction, static_cast<byte>(index)
#define TABLE_ZERO 0
// TODO(titzer): change usages of these macros to put func last.
#define WASM_CALL_INDIRECT0(index, func) \
func, kExprCallIndirect, static_cast<byte>(index)
func, kExprCallIndirect, static_cast<byte>(index), TABLE_ZERO
#define WASM_CALL_INDIRECT1(index, func, a) \
a, func, kExprCallIndirect, static_cast<byte>(index)
a, func, kExprCallIndirect, static_cast<byte>(index), TABLE_ZERO
#define WASM_CALL_INDIRECT2(index, func, a, b) \
a, b, func, kExprCallIndirect, static_cast<byte>(index)
a, b, func, kExprCallIndirect, static_cast<byte>(index), TABLE_ZERO
#define WASM_CALL_INDIRECT3(index, func, a, b, c) \
a, b, c, func, kExprCallIndirect, static_cast<byte>(index)
a, b, c, func, kExprCallIndirect, static_cast<byte>(index), TABLE_ZERO
#define WASM_CALL_INDIRECT4(index, func, a, b, c, d) \
a, b, c, d, func, kExprCallIndirect, static_cast<byte>(index)
a, b, c, d, func, kExprCallIndirect, static_cast<byte>(index), TABLE_ZERO
#define WASM_CALL_INDIRECT5(index, func, a, b, c, d, e) \
a, b, c, d, e, func, kExprCallIndirect, static_cast<byte>(index)
a, b, c, d, e, func, kExprCallIndirect, static_cast<byte>(index), TABLE_ZERO
#define WASM_CALL_INDIRECTN(arity, index, func, ...) \
__VA_ARGS__, func, kExprCallIndirect, static_cast<byte>(index)
__VA_ARGS__, func, kExprCallIndirect, static_cast<byte>(index), TABLE_ZERO
#define WASM_NOT(x) x, kExprI32Eqz
#define WASM_SEQ(...) __VA_ARGS__
......@@ -605,8 +607,8 @@ class LocalDeclEncoder {
//------------------------------------------------------------------------------
// Memory Operations.
//------------------------------------------------------------------------------
#define WASM_GROW_MEMORY(x) x, kExprGrowMemory
#define WASM_MEMORY_SIZE kExprMemorySize
#define WASM_GROW_MEMORY(x) x, kExprGrowMemory, 0
#define WASM_MEMORY_SIZE kExprMemorySize, 0
//------------------------------------------------------------------------------
// Simd Operations.
......
......@@ -31,10 +31,10 @@ const size_t kMaxModuleSize = 1024 * 1024 * 1024;
const size_t kMaxFunctionSize = 128 * 1024;
const size_t kMaxStringSize = 256;
const uint32_t kWasmMagic = 0x6d736100;
const uint32_t kWasmVersion = 0x0c;
const uint32_t kWasmVersion = 0x0d;
const uint8_t kWasmFunctionTypeForm = 0x40;
const uint8_t kWasmAnyFunctionTypeForm = 0x20;
const uint8_t kWasmFunctionTypeForm = 0x60;
const uint8_t kWasmAnyFunctionTypeForm = 0x70;
enum WasmSectionCode {
kUnknownSectionCode = 0, // code for unknown sections
......
......@@ -15,12 +15,12 @@ namespace wasm {
// Binary encoding of local types.
enum LocalTypeCode {
kLocalVoid = 0,
kLocalI32 = 1,
kLocalI64 = 2,
kLocalF32 = 3,
kLocalF64 = 4,
kLocalS128 = 5
kLocalVoid = 0x40,
kLocalI32 = 0x7f,
kLocalI64 = 0x7e,
kLocalF32 = 0x7d,
kLocalF64 = 0x7c,
kLocalS128 = 0x7b
};
// Type code for multi-value block types.
......@@ -47,199 +47,198 @@ typedef int WasmCodePosition;
const WasmCodePosition kNoCodePosition = -1;
// Control expressions and blocks.
#define FOREACH_CONTROL_OPCODE(V) \
V(Unreachable, 0x00, _) \
V(Block, 0x01, _) \
V(Loop, 0x02, _) \
V(If, 0x03, _) \
V(Else, 0x04, _) \
V(Select, 0x05, _) \
V(Br, 0x06, _) \
V(BrIf, 0x07, _) \
V(BrTable, 0x08, _) \
V(Return, 0x09, _) \
V(Nop, 0x0a, _) \
V(Throw, 0xfa, _) \
V(Try, 0xfb, _) \
V(Catch, 0xfe, _) \
V(End, 0x0F, _)
#define FOREACH_CONTROL_OPCODE(V) \
V(Unreachable, 0x00, _) \
V(Nop, 0x01, _) \
V(Block, 0x02, _) \
V(Loop, 0x03, _) \
V(If, 0x004, _) \
V(Else, 0x05, _) \
V(Try, 0x06, _ /* eh_prototype */) \
V(Catch, 0x07, _ /* eh_prototype */) \
V(Throw, 0x08, _ /* eh_prototype */) \
V(End, 0x0b, _) \
V(Br, 0x0c, _) \
V(BrIf, 0x0d, _) \
V(BrTable, 0x0e, _) \
V(Return, 0x0f, _)
// Constants, locals, globals, and calls.
#define FOREACH_MISC_OPCODE(V) \
V(I32Const, 0x10, _) \
V(I64Const, 0x11, _) \
V(F64Const, 0x12, _) \
V(F32Const, 0x13, _) \
V(GetLocal, 0x14, _) \
V(SetLocal, 0x15, _) \
V(TeeLocal, 0x19, _) \
V(Drop, 0x0b, _) \
V(CallFunction, 0x16, _) \
V(CallIndirect, 0x17, _) \
V(I8Const, 0xcb, _) \
V(GetGlobal, 0xbb, _) \
V(SetGlobal, 0xbc, _)
V(CallFunction, 0x10, _) \
V(CallIndirect, 0x11, _) \
V(Drop, 0x1a, _) \
V(Select, 0x1b, _) \
V(GetLocal, 0x20, _) \
V(SetLocal, 0x21, _) \
V(TeeLocal, 0x22, _) \
V(GetGlobal, 0x23, _) \
V(SetGlobal, 0x24, _) \
V(I32Const, 0x41, _) \
V(I64Const, 0x42, _) \
V(F32Const, 0x43, _) \
V(F64Const, 0x44, _) \
V(I8Const, 0xcb, _ /* TODO(titzer): V8 specific, remove */)
// Load memory expressions.
#define FOREACH_LOAD_MEM_OPCODE(V) \
V(I32LoadMem8S, 0x20, i_i) \
V(I32LoadMem8U, 0x21, i_i) \
V(I32LoadMem16S, 0x22, i_i) \
V(I32LoadMem16U, 0x23, i_i) \
V(I64LoadMem8S, 0x24, l_i) \
V(I64LoadMem8U, 0x25, l_i) \
V(I64LoadMem16S, 0x26, l_i) \
V(I64LoadMem16U, 0x27, l_i) \
V(I64LoadMem32S, 0x28, l_i) \
V(I64LoadMem32U, 0x29, l_i) \
V(I32LoadMem, 0x2a, i_i) \
V(I64LoadMem, 0x2b, l_i) \
V(F32LoadMem, 0x2c, f_i) \
V(F64LoadMem, 0x2d, d_i)
V(I32LoadMem, 0x28, i_i) \
V(I64LoadMem, 0x29, l_i) \
V(F32LoadMem, 0x2a, f_i) \
V(F64LoadMem, 0x2b, d_i) \
V(I32LoadMem8S, 0x2c, i_i) \
V(I32LoadMem8U, 0x2d, i_i) \
V(I32LoadMem16S, 0x2e, i_i) \
V(I32LoadMem16U, 0x2f, i_i) \
V(I64LoadMem8S, 0x30, l_i) \
V(I64LoadMem8U, 0x31, l_i) \
V(I64LoadMem16S, 0x32, l_i) \
V(I64LoadMem16U, 0x33, l_i) \
V(I64LoadMem32S, 0x34, l_i) \
V(I64LoadMem32U, 0x35, l_i)
// Store memory expressions.
#define FOREACH_STORE_MEM_OPCODE(V) \
V(I32StoreMem8, 0x2e, i_ii) \
V(I32StoreMem16, 0x2f, i_ii) \
V(I64StoreMem8, 0x30, l_il) \
V(I64StoreMem16, 0x31, l_il) \
V(I64StoreMem32, 0x32, l_il) \
V(I32StoreMem, 0x33, i_ii) \
V(I64StoreMem, 0x34, l_il) \
V(F32StoreMem, 0x35, f_if) \
V(F64StoreMem, 0x36, d_id)
#define FOREACH_SIMPLE_MEM_OPCODE(V) V(GrowMemory, 0x39, i_i)
// Load memory expressions.
V(I32StoreMem, 0x36, i_ii) \
V(I64StoreMem, 0x37, l_il) \
V(F32StoreMem, 0x38, f_if) \
V(F64StoreMem, 0x39, d_id) \
V(I32StoreMem8, 0x3a, i_ii) \
V(I32StoreMem16, 0x3b, i_ii) \
V(I64StoreMem8, 0x3c, l_il) \
V(I64StoreMem16, 0x3d, l_il) \
V(I64StoreMem32, 0x3e, l_il)
// Miscellaneous memory expressions
#define FOREACH_MISC_MEM_OPCODE(V) \
V(MemorySize, 0x3b, i_v)
V(MemorySize, 0x3f, i_v) \
V(GrowMemory, 0x40, i_i)
// Expressions with signatures.
#define FOREACH_SIMPLE_OPCODE(V) \
V(I32Add, 0x40, i_ii) \
V(I32Sub, 0x41, i_ii) \
V(I32Mul, 0x42, i_ii) \
V(I32DivS, 0x43, i_ii) \
V(I32DivU, 0x44, i_ii) \
V(I32RemS, 0x45, i_ii) \
V(I32RemU, 0x46, i_ii) \
V(I32And, 0x47, i_ii) \
V(I32Ior, 0x48, i_ii) \
V(I32Xor, 0x49, i_ii) \
V(I32Shl, 0x4a, i_ii) \
V(I32ShrU, 0x4b, i_ii) \
V(I32ShrS, 0x4c, i_ii) \
V(I32Eq, 0x4d, i_ii) \
V(I32Ne, 0x4e, i_ii) \
V(I32LtS, 0x4f, i_ii) \
V(I32LeS, 0x50, i_ii) \
V(I32LtU, 0x51, i_ii) \
V(I32LeU, 0x52, i_ii) \
V(I32GtS, 0x53, i_ii) \
V(I32GeS, 0x54, i_ii) \
V(I32GtU, 0x55, i_ii) \
V(I32GeU, 0x56, i_ii) \
V(I32Clz, 0x57, i_i) \
V(I32Ctz, 0x58, i_i) \
V(I32Popcnt, 0x59, i_i) \
V(I32Eqz, 0x5a, i_i) \
V(I64Add, 0x5b, l_ll) \
V(I64Sub, 0x5c, l_ll) \
V(I64Mul, 0x5d, l_ll) \
V(I64DivS, 0x5e, l_ll) \
V(I64DivU, 0x5f, l_ll) \
V(I64RemS, 0x60, l_ll) \
V(I64RemU, 0x61, l_ll) \
V(I64And, 0x62, l_ll) \
V(I64Ior, 0x63, l_ll) \
V(I64Xor, 0x64, l_ll) \
V(I64Shl, 0x65, l_ll) \
V(I64ShrU, 0x66, l_ll) \
V(I64ShrS, 0x67, l_ll) \
V(I64Eq, 0x68, i_ll) \
V(I64Ne, 0x69, i_ll) \
V(I64LtS, 0x6a, i_ll) \
V(I64LeS, 0x6b, i_ll) \
V(I64LtU, 0x6c, i_ll) \
V(I64LeU, 0x6d, i_ll) \
V(I64GtS, 0x6e, i_ll) \
V(I64GeS, 0x6f, i_ll) \
V(I64GtU, 0x70, i_ll) \
V(I64GeU, 0x71, i_ll) \
V(I64Clz, 0x72, l_l) \
V(I64Ctz, 0x73, l_l) \
V(I64Popcnt, 0x74, l_l) \
V(I64Eqz, 0xba, i_l) \
V(F32Add, 0x75, f_ff) \
V(F32Sub, 0x76, f_ff) \
V(F32Mul, 0x77, f_ff) \
V(F32Div, 0x78, f_ff) \
V(F32Min, 0x79, f_ff) \
V(F32Max, 0x7a, f_ff) \
V(F32Abs, 0x7b, f_f) \
V(F32Neg, 0x7c, f_f) \
V(F32CopySign, 0x7d, f_ff) \
V(F32Ceil, 0x7e, f_f) \
V(F32Floor, 0x7f, f_f) \
V(F32Trunc, 0x80, f_f) \
V(F32NearestInt, 0x81, f_f) \
V(F32Sqrt, 0x82, f_f) \
V(F32Eq, 0x83, i_ff) \
V(F32Ne, 0x84, i_ff) \
V(F32Lt, 0x85, i_ff) \
V(F32Le, 0x86, i_ff) \
V(F32Gt, 0x87, i_ff) \
V(F32Ge, 0x88, i_ff) \
V(F64Add, 0x89, d_dd) \
V(F64Sub, 0x8a, d_dd) \
V(F64Mul, 0x8b, d_dd) \
V(F64Div, 0x8c, d_dd) \
V(F64Min, 0x8d, d_dd) \
V(F64Max, 0x8e, d_dd) \
V(F64Abs, 0x8f, d_d) \
V(F64Neg, 0x90, d_d) \
V(F64CopySign, 0x91, d_dd) \
V(F64Ceil, 0x92, d_d) \
V(F64Floor, 0x93, d_d) \
V(F64Trunc, 0x94, d_d) \
V(F64NearestInt, 0x95, d_d) \
V(F64Sqrt, 0x96, d_d) \
V(F64Eq, 0x97, i_dd) \
V(F64Ne, 0x98, i_dd) \
V(F64Lt, 0x99, i_dd) \
V(F64Le, 0x9a, i_dd) \
V(F64Gt, 0x9b, i_dd) \
V(F64Ge, 0x9c, i_dd) \
V(I32SConvertF32, 0x9d, i_f) \
V(I32SConvertF64, 0x9e, i_d) \
V(I32UConvertF32, 0x9f, i_f) \
V(I32UConvertF64, 0xa0, i_d) \
V(I32ConvertI64, 0xa1, i_l) \
V(I64SConvertF32, 0xa2, l_f) \
V(I64SConvertF64, 0xa3, l_d) \
V(I64UConvertF32, 0xa4, l_f) \
V(I64UConvertF64, 0xa5, l_d) \
V(I64SConvertI32, 0xa6, l_i) \
V(I64UConvertI32, 0xa7, l_i) \
V(F32SConvertI32, 0xa8, f_i) \
V(F32UConvertI32, 0xa9, f_i) \
V(F32SConvertI64, 0xaa, f_l) \
V(F32UConvertI64, 0xab, f_l) \
V(F32ConvertF64, 0xac, f_d) \
V(F32ReinterpretI32, 0xad, f_i) \
V(F64SConvertI32, 0xae, d_i) \
V(F64UConvertI32, 0xaf, d_i) \
V(F64SConvertI64, 0xb0, d_l) \
V(F64UConvertI64, 0xb1, d_l) \
V(F64ConvertF32, 0xb2, d_f) \
V(F64ReinterpretI64, 0xb3, d_l) \
V(I32ReinterpretF32, 0xb4, i_f) \
V(I64ReinterpretF64, 0xb5, l_d) \
V(I32Ror, 0xb6, i_ii) \
V(I32Rol, 0xb7, i_ii) \
V(I64Ror, 0xb8, l_ll) \
V(I64Rol, 0xb9, l_ll)
V(I32Eqz, 0x45, i_i) \
V(I32Eq, 0x46, i_ii) \
V(I32Ne, 0x47, i_ii) \
V(I32LtS, 0x48, i_ii) \
V(I32LtU, 0x49, i_ii) \
V(I32GtS, 0x4a, i_ii) \
V(I32GtU, 0x4b, i_ii) \
V(I32LeS, 0x4c, i_ii) \
V(I32LeU, 0x4d, i_ii) \
V(I32GeS, 0x4e, i_ii) \
V(I32GeU, 0x4f, i_ii) \
V(I64Eqz, 0x50, i_l) \
V(I64Eq, 0x51, i_ll) \
V(I64Ne, 0x52, i_ll) \
V(I64LtS, 0x53, i_ll) \
V(I64LtU, 0x54, i_ll) \
V(I64GtS, 0x55, i_ll) \
V(I64GtU, 0x56, i_ll) \
V(I64LeS, 0x57, i_ll) \
V(I64LeU, 0x58, i_ll) \
V(I64GeS, 0x59, i_ll) \
V(I64GeU, 0x5a, i_ll) \
V(F32Eq, 0x5b, i_ff) \
V(F32Ne, 0x5c, i_ff) \
V(F32Lt, 0x5d, i_ff) \
V(F32Gt, 0x5e, i_ff) \
V(F32Le, 0x5f, i_ff) \
V(F32Ge, 0x60, i_ff) \
V(F64Eq, 0x61, i_dd) \
V(F64Ne, 0x62, i_dd) \
V(F64Lt, 0x63, i_dd) \
V(F64Gt, 0x64, i_dd) \
V(F64Le, 0x65, i_dd) \
V(F64Ge, 0x66, i_dd) \
V(I32Clz, 0x67, i_i) \
V(I32Ctz, 0x68, i_i) \
V(I32Popcnt, 0x69, i_i) \
V(I32Add, 0x6a, i_ii) \
V(I32Sub, 0x6b, i_ii) \
V(I32Mul, 0x6c, i_ii) \
V(I32DivS, 0x6d, i_ii) \
V(I32DivU, 0x6e, i_ii) \
V(I32RemS, 0x6f, i_ii) \
V(I32RemU, 0x70, i_ii) \
V(I32And, 0x71, i_ii) \
V(I32Ior, 0x72, i_ii) \
V(I32Xor, 0x73, i_ii) \
V(I32Shl, 0x74, i_ii) \
V(I32ShrS, 0x75, i_ii) \
V(I32ShrU, 0x76, i_ii) \
V(I32Rol, 0x77, i_ii) \
V(I32Ror, 0x78, i_ii) \
V(I64Clz, 0x79, l_l) \
V(I64Ctz, 0x7a, l_l) \
V(I64Popcnt, 0x7b, l_l) \
V(I64Add, 0x7c, l_ll) \
V(I64Sub, 0x7d, l_ll) \
V(I64Mul, 0x7e, l_ll) \
V(I64DivS, 0x7f, l_ll) \
V(I64DivU, 0x80, l_ll) \
V(I64RemS, 0x81, l_ll) \
V(I64RemU, 0x82, l_ll) \
V(I64And, 0x83, l_ll) \
V(I64Ior, 0x84, l_ll) \
V(I64Xor, 0x85, l_ll) \
V(I64Shl, 0x86, l_ll) \
V(I64ShrS, 0x87, l_ll) \
V(I64ShrU, 0x88, l_ll) \
V(I64Rol, 0x89, l_ll) \
V(I64Ror, 0x8a, l_ll) \
V(F32Abs, 0x8b, f_f) \
V(F32Neg, 0x8c, f_f) \
V(F32Ceil, 0x8d, f_f) \
V(F32Floor, 0x8e, f_f) \
V(F32Trunc, 0x8f, f_f) \
V(F32NearestInt, 0x90, f_f) \
V(F32Sqrt, 0x91, f_f) \
V(F32Add, 0x92, f_ff) \
V(F32Sub, 0x93, f_ff) \
V(F32Mul, 0x94, f_ff) \
V(F32Div, 0x95, f_ff) \
V(F32Min, 0x96, f_ff) \
V(F32Max, 0x97, f_ff) \
V(F32CopySign, 0x98, f_ff) \
V(F64Abs, 0x99, d_d) \
V(F64Neg, 0x9a, d_d) \
V(F64Ceil, 0x9b, d_d) \
V(F64Floor, 0x9c, d_d) \
V(F64Trunc, 0x9d, d_d) \
V(F64NearestInt, 0x9e, d_d) \
V(F64Sqrt, 0x9f, d_d) \
V(F64Add, 0xa0, d_dd) \
V(F64Sub, 0xa1, d_dd) \
V(F64Mul, 0xa2, d_dd) \
V(F64Div, 0xa3, d_dd) \
V(F64Min, 0xa4, d_dd) \
V(F64Max, 0xa5, d_dd) \
V(F64CopySign, 0xa6, d_dd) \
V(I32ConvertI64, 0xa7, i_l) \
V(I32SConvertF32, 0xa8, i_f) \
V(I32UConvertF32, 0xa9, i_f) \
V(I32SConvertF64, 0xaa, i_d) \
V(I32UConvertF64, 0xab, i_d) \
V(I64SConvertI32, 0xac, l_i) \
V(I64UConvertI32, 0xad, l_i) \
V(I64SConvertF32, 0xae, l_f) \
V(I64UConvertF32, 0xaf, l_f) \
V(I64SConvertF64, 0xb0, l_d) \
V(I64UConvertF64, 0xb1, l_d) \
V(F32SConvertI32, 0xb2, f_i) \
V(F32UConvertI32, 0xb3, f_i) \
V(F32SConvertI64, 0xb4, f_l) \
V(F32UConvertI64, 0xb5, f_l) \
V(F32ConvertF64, 0xb6, f_d) \
V(F64SConvertI32, 0xb7, d_i) \
V(F64UConvertI32, 0xb8, d_i) \
V(F64SConvertI64, 0xb9, d_l) \
V(F64UConvertI64, 0xba, d_l) \
V(F64ConvertF32, 0xbb, d_f) \
V(I32ReinterpretF32, 0xbc, i_f) \
V(I64ReinterpretF64, 0xbd, l_d) \
V(F32ReinterpretI32, 0xbe, f_i) \
V(F64ReinterpretI64, 0xbf, d_l)
// For compatibility with Asm.js.
#define FOREACH_ASMJS_COMPAT_OPCODE(V) \
......@@ -406,7 +405,6 @@ const WasmCodePosition kNoCodePosition = -1;
FOREACH_CONTROL_OPCODE(V) \
FOREACH_MISC_OPCODE(V) \
FOREACH_SIMPLE_OPCODE(V) \
FOREACH_SIMPLE_MEM_OPCODE(V) \
FOREACH_STORE_MEM_OPCODE(V) \
FOREACH_LOAD_MEM_OPCODE(V) \
FOREACH_MISC_MEM_OPCODE(V) \
......
......@@ -1570,7 +1570,7 @@ static void CompileCallIndirectMany(LocalType param) {
ADD_CODE(code, kExprGetLocal, p);
}
ADD_CODE(code, kExprI8Const, 0);
ADD_CODE(code, kExprCallIndirect, 1);
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size());
t.Compile();
......
......@@ -2920,7 +2920,7 @@ static void CompileCallIndirectMany(LocalType param) {
ADD_CODE(code, kExprGetLocal, p);
}
ADD_CODE(code, kExprI8Const, 0);
ADD_CODE(code, kExprCallIndirect, 1);
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size());
t.Compile();
......
......@@ -12,9 +12,9 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addMemory(1, 1, false);
builder.addFunction("foo", kSig_i_v)
.addBody([
kExprMemorySize,
kExprMemorySize, kMemoryZero,
kExprI32Const, 0x10,
kExprGrowMemory,
kExprGrowMemory, kMemoryZero,
kExprI32Mul,
])
.exportFunc();
......
......@@ -20,7 +20,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprGetLocal, 0,
kExprI32LoadMem, 0, 0,
kExprI32Const, 1,
kExprCallIndirect, signature,
kExprCallIndirect, signature, kTableZero,
kExprGetLocal,0,
kExprI32LoadMem,0, 0,
kExprCallFunction, 0,
......
......@@ -12,7 +12,7 @@ var kPageSize = 0x10000;
function genGrowMemoryBuilder() {
var builder = new WasmModuleBuilder();
builder.addFunction("grow_memory", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprGrowMemory])
.addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
.exportFunc();
builder.addFunction("load", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
......@@ -325,7 +325,7 @@ function testGrowMemoryCurrentMemory() {
var builder = genGrowMemoryBuilder();
builder.addMemory(1, 1, false);
builder.addFunction("memory_size", kSig_i_v)
.addBody([kExprMemorySize])
.addBody([kExprMemorySize, kMemoryZero])
.exportFunc();
var module = builder.instantiate();
function growMem(pages) { return module.exports.grow_memory(pages); }
......@@ -449,7 +449,7 @@ function testGrowMemoryOutOfBoundsOffset2() {
.addBody([
kExprI32Const, 20,
kExprI32Const, 29,
kExprGrowMemory,
kExprGrowMemory, kMemoryZero,
kExprI32StoreMem, 0, 0xFF, 0xFF, 0xFF, 0x3a
])
.exportAs("main");
......
......@@ -188,7 +188,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(2*kPageSize, memory.buffer.byteLength);
let builder = new WasmModuleBuilder();
builder.addFunction("grow", kSig_i_i)
.addBody([kExprGetLocal, 0, kExprGrowMemory])
.addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
.exportFunc();
builder.addImportedMemory("mine");
let instance = builder.instantiate({mine: memory});
......
......@@ -27,7 +27,7 @@ var module = (function () {
kExprGetLocal, 1,
kExprGetLocal, 2,
kExprGetLocal, 0,
kExprCallIndirect, sig_index
kExprCallIndirect, sig_index, kTableZero
])
.exportFunc()
builder.appendToTable([1, 2, 3]);
......@@ -71,7 +71,7 @@ module = (function () {
kExprGetLocal, 1,
kExprGetLocal, 2,
kExprGetLocal, 0,
kExprCallIndirect, sig_i_ii
kExprCallIndirect, sig_i_ii, kTableZero
])
.exportFunc();
builder.appendToTable([mul.index, add.index, popcnt.index, main.index]);
......@@ -117,7 +117,7 @@ module = (function () {
kExprI32Const, 33, // --
kExprGetLocal, 0, // --
kExprGetLocal, 1, // --
kExprCallIndirect, 0]) // --
kExprCallIndirect, 0, kTableZero]) // --
.exportAs("main");
builder.appendToTable([f.mul.index, f.add.index, f.sub.index]);
......@@ -144,7 +144,7 @@ assertTraps(kTrapFuncInvalid, "module.exports.main(12, 3)");
kExprI32Const, 33, // --
kExprGetLocal, 0, // --
kExprGetLocal, 1, // --
kExprCallIndirect, 0]) // --
kExprCallIndirect, 0, kTableZero]) // --
.exportAs("main");
builder.setFunctionTableLength(length);
......@@ -181,7 +181,7 @@ assertTraps(kTrapFuncInvalid, "module.exports.main(12, 3)");
kExprI32Const, 33, // --
kExprGetLocal, 0, // --
kExprGetLocal, 1, // --
kExprCallIndirect, 0]) // --
kExprCallIndirect, 0, kTableZero]) // --
.exportAs("main");
builder.setFunctionTableLength(10);
......
......@@ -42,7 +42,7 @@ function AddFunctions(builder) {
kExprI32Const, 33, // --
kExprGetLocal, 0, // --
kExprGetLocal, 1, // --
kExprCallIndirect, 0]) // --
kExprCallIndirect, 0, kTableZero]) // --
.exportAs("main");
f.add.exportAs("blarg");
......
......@@ -124,7 +124,7 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
kExprGetLocal, 0,
kExprI32LoadMem, 0, 0,
kExprI32Const, 1,
kExprCallIndirect, signature,
kExprCallIndirect, signature, kTableZero,
kExprGetLocal,0,
kExprI32LoadMem,0, 0,
kExprCallFunction, 0,
......
......@@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
print("testMemorySizeZero()");
var builder = new WasmModuleBuilder();
builder.addFunction("memory_size", kSig_i_v)
.addBody([kExprMemorySize])
.addBody([kExprMemorySize, kMemoryZero])
.exportFunc();
var module = builder.instantiate();
assertEquals(0, module.exports.memory_size());
......@@ -23,7 +23,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var size = 11;
builder.addMemory(size, size, false);
builder.addFunction("memory_size", kSig_i_v)
.addBody([kExprMemorySize])
.addBody([kExprMemorySize, kMemoryZero])
.exportFunc();
var module = builder.instantiate();
assertEquals(size, module.exports.memory_size());
......
......@@ -135,7 +135,7 @@ Error.prepareStackTrace = function(error, frames) {
builder.addFunction("recursion", sig_index)
.addBody([
kExprI32Const, 0,
kExprCallIndirect, sig_index
kExprCallIndirect, sig_index, kTableZero
])
.exportFunc()
builder.appendToTable([0]);
......
......@@ -89,7 +89,7 @@ var debug = true;
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
module.addFunction("main", kSig_i_iii)
.addBody([kExprGetLocal,
1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect, 0])
1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect, 0, kTableZero])
.exportAs("main");
module.appendToTable([0]);
......
......@@ -52,7 +52,7 @@ builder.addFunction("main", kSig_i_i)
kExprEnd,
// offset 30
kExprGetLocal, 0,
kExprCallIndirect, sig_index,
kExprCallIndirect, sig_index, kTableZero,
kExprEnd,
])
.exportAs("main");
......
......@@ -21,7 +21,7 @@ var kWasmH1 = 0x61;
var kWasmH2 = 0x73;
var kWasmH3 = 0x6d;
var kWasmV0 = 0xC;
var kWasmV0 = 0xD;
var kWasmV1 = 0;
var kWasmV2 = 0;
var kWasmV3 = 0;
......@@ -48,68 +48,71 @@ function bytesWithHeader() {
return buffer;
}
var kDeclNoLocals = 0;
let kDeclNoLocals = 0;
// Section declaration constants
var kUnknownSectionCode = 0;
var kTypeSectionCode = 1; // Function signature declarations
var kImportSectionCode = 2; // Import declarations
var kFunctionSectionCode = 3; // Function declarations
var kTableSectionCode = 4; // Indirect function table and other tables
var kMemorySectionCode = 5; // Memory attributes
var kGlobalSectionCode = 6; // Global declarations
var kExportSectionCode = 7; // Exports
var kStartSectionCode = 8; // Start function declaration
var kElementSectionCode = 9; // Elements section
var kCodeSectionCode = 10; // Function code
var kDataSectionCode = 11; // Data segments
var kNameSectionCode = 12; // Name section (encoded as string)
let kUnknownSectionCode = 0;
let kTypeSectionCode = 1; // Function signature declarations
let kImportSectionCode = 2; // Import declarations
let kFunctionSectionCode = 3; // Function declarations
let kTableSectionCode = 4; // Indirect function table and other tables
let kMemorySectionCode = 5; // Memory attributes
let kGlobalSectionCode = 6; // Global declarations
let kExportSectionCode = 7; // Exports
let kStartSectionCode = 8; // Start function declaration
let kElementSectionCode = 9; // Elements section
let kCodeSectionCode = 10; // Function code
let kDataSectionCode = 11; // Data segments
let kNameSectionCode = 12; // Name section (encoded as string)
var kWasmFunctionTypeForm = 0x40;
var kWasmAnyFunctionTypeForm = 0x20;
let kWasmFunctionTypeForm = 0x60;
let kWasmAnyFunctionTypeForm = 0x70;
var kResizableMaximumFlag = 1;
let kResizableMaximumFlag = 1;
// Function declaration flags
var kDeclFunctionName = 0x01;
var kDeclFunctionImport = 0x02;
var kDeclFunctionLocals = 0x04;
var kDeclFunctionExport = 0x08;
let kDeclFunctionName = 0x01;
let kDeclFunctionImport = 0x02;
let kDeclFunctionLocals = 0x04;
let kDeclFunctionExport = 0x08;
// Local types
var kAstStmt = 0;
var kAstI32 = 1;
var kAstI64 = 2;
var kAstF32 = 3;
var kAstF64 = 4;
var kAstS128 = 5;
let kAstStmt = 0x40;
let kAstI32 = 0x7f;
let kAstI64 = 0x7e;
let kAstF32 = 0x7d;
let kAstF64 = 0x7c;
let kAstS128 = 0x7b;
var kExternalFunction = 0;
var kExternalTable = 1;
var kExternalMemory = 2;
var kExternalGlobal = 3;
let kExternalFunction = 0;
let kExternalTable = 1;
let kExternalMemory = 2;
let kExternalGlobal = 3;
let kTableZero = 0;
let kMemoryZero = 0;
// Useful signatures
var kSig_i_i = makeSig([kAstI32], [kAstI32]);
var kSig_i_l = makeSig([kAstI64], [kAstI32]);
var kSig_i_ii = makeSig([kAstI32, kAstI32], [kAstI32]);
var kSig_i_iii = makeSig([kAstI32, kAstI32, kAstI32], [kAstI32]);
var kSig_d_dd = makeSig([kAstF64, kAstF64], [kAstF64]);
var kSig_l_ll = makeSig([kAstI64, kAstI64], [kAstI64]);
var kSig_i_dd = makeSig([kAstF64, kAstF64], [kAstI32]);
var kSig_v_v = makeSig([], []);
var kSig_i_v = makeSig([], [kAstI32]);
var kSig_l_v = makeSig([], [kAstI64]);
var kSig_f_v = makeSig([], [kAstF64]);
var kSig_d_v = makeSig([], [kAstF64]);
var kSig_v_i = makeSig([kAstI32], []);
var kSig_v_ii = makeSig([kAstI32, kAstI32], []);
var kSig_v_iii = makeSig([kAstI32, kAstI32, kAstI32], []);
var kSig_v_l = makeSig([kAstI64], []);
var kSig_v_d = makeSig([kAstF64], []);
var kSig_v_dd = makeSig([kAstF64, kAstF64], []);
var kSig_v_ddi = makeSig([kAstF64, kAstF64, kAstI32], []);
var kSig_s_v = makeSig([], [kAstS128]);
let kSig_i_i = makeSig([kAstI32], [kAstI32]);
let kSig_i_l = makeSig([kAstI64], [kAstI32]);
let kSig_i_ii = makeSig([kAstI32, kAstI32], [kAstI32]);
let kSig_i_iii = makeSig([kAstI32, kAstI32, kAstI32], [kAstI32]);
let kSig_d_dd = makeSig([kAstF64, kAstF64], [kAstF64]);
let kSig_l_ll = makeSig([kAstI64, kAstI64], [kAstI64]);
let kSig_i_dd = makeSig([kAstF64, kAstF64], [kAstI32]);
let kSig_v_v = makeSig([], []);
let kSig_i_v = makeSig([], [kAstI32]);
let kSig_l_v = makeSig([], [kAstI64]);
let kSig_f_v = makeSig([], [kAstF64]);
let kSig_d_v = makeSig([], [kAstF64]);
let kSig_v_i = makeSig([kAstI32], []);
let kSig_v_ii = makeSig([kAstI32, kAstI32], []);
let kSig_v_iii = makeSig([kAstI32, kAstI32, kAstI32], []);
let kSig_v_l = makeSig([kAstI64], []);
let kSig_v_d = makeSig([kAstF64], []);
let kSig_v_dd = makeSig([kAstF64, kAstF64], []);
let kSig_v_ddi = makeSig([kAstF64, kAstF64, kAstI32], []);
let kSig_s_v = makeSig([], [kAstS128]);
function makeSig(params, results) {
return {params: params, results: results};
......@@ -136,198 +139,194 @@ function makeSig_r_xx(r, x) {
}
// Opcodes
var kExprUnreachable = 0x00;
var kExprNop = 0x0a;
var kExprBlock = 0x01;
var kExprLoop = 0x02;
var kExprIf = 0x03;
var kExprElse = 0x04;
var kExprSelect = 0x05;
var kExprBr = 0x06;
var kExprBrIf = 0x07;
var kExprBrTable = 0x08;
var kExprReturn = 0x09;
var kExprThrow = 0xfa;
var kExprTry = 0xfb;
var kExprCatch = 0xfe;
var kExprEnd = 0x0f;
var kExprTeeLocal = 0x19;
var kExprDrop = 0x0b;
var kExprI32Const = 0x10;
var kExprI64Const = 0x11;
var kExprF64Const = 0x12;
var kExprF32Const = 0x13;
var kExprGetLocal = 0x14;
var kExprSetLocal = 0x15;
var kExprCallFunction = 0x16;
var kExprCallIndirect = 0x17;
var kExprI8Const = 0xcb;
var kExprGetGlobal = 0xbb;
var kExprSetGlobal = 0xbc;
var kExprI32LoadMem8S = 0x20;
var kExprI32LoadMem8U = 0x21;
var kExprI32LoadMem16S = 0x22;
var kExprI32LoadMem16U = 0x23;
var kExprI64LoadMem8S = 0x24;
var kExprI64LoadMem8U = 0x25;
var kExprI64LoadMem16S = 0x26;
var kExprI64LoadMem16U = 0x27;
var kExprI64LoadMem32S = 0x28;
var kExprI64LoadMem32U = 0x29;
var kExprI32LoadMem = 0x2a;
var kExprI64LoadMem = 0x2b;
var kExprF32LoadMem = 0x2c;
var kExprF64LoadMem = 0x2d;
var kExprI32StoreMem8 = 0x2e;
var kExprI32StoreMem16 = 0x2f;
var kExprI64StoreMem8 = 0x30;
var kExprI64StoreMem16 = 0x31;
var kExprI64StoreMem32 = 0x32;
var kExprI32StoreMem = 0x33;
var kExprI64StoreMem = 0x34;
var kExprF32StoreMem = 0x35;
var kExprF64StoreMem = 0x36;
var kExprMemorySize = 0x3b;
var kExprGrowMemory = 0x39;
var kExprI32Add = 0x40;
var kExprI32Sub = 0x41;
var kExprI32Mul = 0x42;
var kExprI32DivS = 0x43;
var kExprI32DivU = 0x44;
var kExprI32RemS = 0x45;
var kExprI32RemU = 0x46;
var kExprI32And = 0x47;
var kExprI32Ior = 0x48;
var kExprI32Xor = 0x49;
var kExprI32Shl = 0x4a;
var kExprI32ShrU = 0x4b;
var kExprI32ShrS = 0x4c;
var kExprI32Eq = 0x4d;
var kExprI32Ne = 0x4e;
var kExprI32LtS = 0x4f;
var kExprI32LeS = 0x50;
var kExprI32LtU = 0x51;
var kExprI32LeU = 0x52;
var kExprI32GtS = 0x53;
var kExprI32GeS = 0x54;
var kExprI32GtU = 0x55;
var kExprI32GeU = 0x56;
var kExprI32Clz = 0x57;
var kExprI32Ctz = 0x58;
var kExprI32Popcnt = 0x59;
var kExprI32Eqz = 0x5a;
var kExprI64Add = 0x5b;
var kExprI64Sub = 0x5c;
var kExprI64Mul = 0x5d;
var kExprI64DivS = 0x5e;
var kExprI64DivU = 0x5f;
var kExprI64RemS = 0x60;
var kExprI64RemU = 0x61;
var kExprI64And = 0x62;
var kExprI64Ior = 0x63;
var kExprI64Xor = 0x64;
var kExprI64Shl = 0x65;
var kExprI64ShrU = 0x66;
var kExprI64ShrS = 0x67;
var kExprI64Eq = 0x68;
var kExprI64Ne = 0x69;
var kExprI64LtS = 0x6a;
var kExprI64LeS = 0x6b;
var kExprI64LtU = 0x6c;
var kExprI64LeU = 0x6d;
var kExprI64GtS = 0x6e;
var kExprI64GeS = 0x6f;
var kExprI64GtU = 0x70;
var kExprI64GeU = 0x71;
var kExprI64Clz = 0x72;
var kExprI64Ctz = 0x73;
var kExprI64Popcnt = 0x74;
var kExprF32Add = 0x75;
var kExprF32Sub = 0x76;
var kExprF32Mul = 0x77;
var kExprF32Div = 0x78;
var kExprF32Min = 0x79;
var kExprF32Max = 0x7a;
var kExprF32Abs = 0x7b;
var kExprF32Neg = 0x7c;
var kExprF32CopySign = 0x7d;
var kExprF32Ceil = 0x7e;
var kExprF32Floor = 0x7f;
var kExprF32Trunc = 0x80;
var kExprF32NearestInt = 0x81;
var kExprF32Sqrt = 0x82;
var kExprF32Eq = 0x83;
var kExprF32Ne = 0x84;
var kExprF32Lt = 0x85;
var kExprF32Le = 0x86;
var kExprF32Gt = 0x87;
var kExprF32Ge = 0x88;
var kExprF64Add = 0x89;
var kExprF64Sub = 0x8a;
var kExprF64Mul = 0x8b;
var kExprF64Div = 0x8c;
var kExprF64Min = 0x8d;
var kExprF64Max = 0x8e;
var kExprF64Abs = 0x8f;
var kExprF64Neg = 0x90;
var kExprF64CopySign = 0x91;
var kExprF64Ceil = 0x92;
var kExprF64Floor = 0x93;
var kExprF64Trunc = 0x94;
var kExprF64NearestInt = 0x95;
var kExprF64Sqrt = 0x96;
var kExprF64Eq = 0x97;
var kExprF64Ne = 0x98;
var kExprF64Lt = 0x99;
var kExprF64Le = 0x9a;
var kExprF64Gt = 0x9b;
var kExprF64Ge = 0x9c;
var kExprI32SConvertF32 = 0x9d;
var kExprI32SConvertF64 = 0x9e;
var kExprI32UConvertF32 = 0x9f;
var kExprI32UConvertF64 = 0xa0;
var kExprI32ConvertI64 = 0xa1;
var kExprI64SConvertF32 = 0xa2;
var kExprI64SConvertF64 = 0xa3;
var kExprI64UConvertF32 = 0xa4;
var kExprI64UConvertF64 = 0xa5;
var kExprI64SConvertI32 = 0xa6;
var kExprI64UConvertI32 = 0xa7;
var kExprF32SConvertI32 = 0xa8;
var kExprF32UConvertI32 = 0xa9;
var kExprF32SConvertI64 = 0xaa;
var kExprF32UConvertI64 = 0xab;
var kExprF32ConvertF64 = 0xac;
var kExprF32ReinterpretI32 = 0xad;
var kExprF64SConvertI32 = 0xae;
var kExprF64UConvertI32 = 0xaf;
var kExprF64SConvertI64 = 0xb0;
var kExprF64UConvertI64 = 0xb1;
var kExprF64ConvertF32 = 0xb2;
var kExprF64ReinterpretI64 = 0xb3;
var kExprI32ReinterpretF32 = 0xb4;
var kExprI64ReinterpretF64 = 0xb5;
var kExprI32Ror = 0xb6;
var kExprI32Rol = 0xb7;
var kExprI64Ror = 0xb8;
var kExprI64Rol = 0xb9;
let kExprUnreachable = 0x00;
let kExprNop = 0x01;
let kExprBlock = 0x02;
let kExprLoop = 0x03;
let kExprIf = 0x04;
let kExprElse = 0x05;
let kExprTry = 0x06;
let kExprCatch = 0x07;
let kExprThrow = 0x08;
let kExprEnd = 0x0b;
let kExprBr = 0x0c;
let kExprBrIf = 0x0d;
let kExprBrTable = 0x0e;
let kExprReturn = 0x0f;
let kExprCallFunction = 0x10;
let kExprCallIndirect = 0x11;
let kExprDrop = 0x1a;
let kExprSelect = 0x1b;
let kExprGetLocal = 0x20;
let kExprSetLocal = 0x21;
let kExprTeeLocal = 0x22;
let kExprGetGlobal = 0x23;
let kExprSetGlobal = 0x24;
let kExprI32Const = 0x41;
let kExprI64Const = 0x42;
let kExprF32Const = 0x43;
let kExprF64Const = 0x44;
let kExprI8Const = 0xcb;
let kExprI32LoadMem = 0x28;
let kExprI64LoadMem = 0x29;
let kExprF32LoadMem = 0x2a;
let kExprF64LoadMem = 0x2b;
let kExprI32LoadMem8S = 0x2c;
let kExprI32LoadMem8U = 0x2d;
let kExprI32LoadMem16S = 0x2e;
let kExprI32LoadMem16U = 0x2f;
let kExprI64LoadMem8S = 0x30;
let kExprI64LoadMem8U = 0x31;
let kExprI64LoadMem16S = 0x32;
let kExprI64LoadMem16U = 0x33;
let kExprI64LoadMem32S = 0x34;
let kExprI64LoadMem32U = 0x35;
let kExprI32StoreMem = 0x36;
let kExprI64StoreMem = 0x37;
let kExprF32StoreMem = 0x38;
let kExprF64StoreMem = 0x39;
let kExprI32StoreMem8 = 0x3a;
let kExprI32StoreMem16 = 0x3b;
let kExprI64StoreMem8 = 0x3c;
let kExprI64StoreMem16 = 0x3d;
let kExprI64StoreMem32 = 0x3e;
let kExprMemorySize = 0x3f;
let kExprGrowMemory = 0x40;
let kExprI32Eqz = 0x45;
let kExprI32Eq = 0x46;
let kExprI32Ne = 0x47;
let kExprI32LtS = 0x48;
let kExprI32LtU = 0x49;
let kExprI32GtS = 0x4a;
let kExprI32GtU = 0x4b;
let kExprI32LeS = 0x4c;
let kExprI32LeU = 0x4d;
let kExprI32GeS = 0x4e;
let kExprI32GeU = 0x4f;
let kExprI64Eqz = 0x50;
let kExprI64Eq = 0x51;
let kExprI64Ne = 0x52;
let kExprI64LtS = 0x53;
let kExprI64LtU = 0x54;
let kExprI64GtS = 0x55;
let kExprI64GtU = 0x56;
let kExprI64LeS = 0x57;
let kExprI64LeU = 0x58;
let kExprI64GeS = 0x59;
let kExprI64GeU = 0x5a;
let kExprF32Eq = 0x5b;
let kExprF32Ne = 0x5c;
let kExprF32Lt = 0x5d;
let kExprF32Gt = 0x5e;
let kExprF32Le = 0x5f;
let kExprF32Ge = 0x60;
let kExprF64Eq = 0x61;
let kExprF64Ne = 0x62;
let kExprF64Lt = 0x63;
let kExprF64Gt = 0x64;
let kExprF64Le = 0x65;
let kExprF64Ge = 0x66;
let kExprI32Clz = 0x67;
let kExprI32Ctz = 0x68;
let kExprI32Popcnt = 0x69;
let kExprI32Add = 0x6a;
let kExprI32Sub = 0x6b;
let kExprI32Mul = 0x6c;
let kExprI32DivS = 0x6d;
let kExprI32DivU = 0x6e;
let kExprI32RemS = 0x6f;
let kExprI32RemU = 0x70;
let kExprI32And = 0x71;
let kExprI32Ior = 0x72;
let kExprI32Xor = 0x73;
let kExprI32Shl = 0x74;
let kExprI32ShrS = 0x75;
let kExprI32ShrU = 0x76;
let kExprI32Rol = 0x77;
let kExprI32Ror = 0x78;
let kExprI64Clz = 0x79;
let kExprI64Ctz = 0x7a;
let kExprI64Popcnt = 0x7b;
let kExprI64Add = 0x7c;
let kExprI64Sub = 0x7d;
let kExprI64Mul = 0x7e;
let kExprI64DivS = 0x7f;
let kExprI64DivU = 0x80;
let kExprI64RemS = 0x81;
let kExprI64RemU = 0x82;
let kExprI64And = 0x83;
let kExprI64Ior = 0x84;
let kExprI64Xor = 0x85;
let kExprI64Shl = 0x86;
let kExprI64ShrS = 0x87;
let kExprI64ShrU = 0x88;
let kExprI64Rol = 0x89;
let kExprI64Ror = 0x8a;
let kExprF32Abs = 0x8b;
let kExprF32Neg = 0x8c;
let kExprF32Ceil = 0x8d;
let kExprF32Floor = 0x8e;
let kExprF32Trunc = 0x8f;
let kExprF32NearestInt = 0x90;
let kExprF32Sqrt = 0x91;
let kExprF32Add = 0x92;
let kExprF32Sub = 0x93;
let kExprF32Mul = 0x94;
let kExprF32Div = 0x95;
let kExprF32Min = 0x96;
let kExprF32Max = 0x97;
let kExprF32CopySign = 0x98;
let kExprF64Abs = 0x99;
let kExprF64Neg = 0x9a;
let kExprF64Ceil = 0x9b;
let kExprF64Floor = 0x9c;
let kExprF64Trunc = 0x9d;
let kExprF64NearestInt = 0x9e;
let kExprF64Sqrt = 0x9f;
let kExprF64Add = 0xa0;
let kExprF64Sub = 0xa1;
let kExprF64Mul = 0xa2;
let kExprF64Div = 0xa3;
let kExprF64Min = 0xa4;
let kExprF64Max = 0xa5;
let kExprF64CopySign = 0xa6;
let kExprI32ConvertI64 = 0xa7;
let kExprI32SConvertF32 = 0xa8;
let kExprI32UConvertF32 = 0xa9;
let kExprI32SConvertF64 = 0xaa;
let kExprI32UConvertF64 = 0xab;
let kExprI64SConvertI32 = 0xac;
let kExprI64UConvertI32 = 0xad;
let kExprI64SConvertF32 = 0xae;
let kExprI64UConvertF32 = 0xaf;
let kExprI64SConvertF64 = 0xb0;
let kExprI64UConvertF64 = 0xb1;
let kExprF32SConvertI32 = 0xb2;
let kExprF32UConvertI32 = 0xb3;
let kExprF32SConvertI64 = 0xb4;
let kExprF32UConvertI64 = 0xb5;
let kExprF32ConvertF64 = 0xb6;
let kExprF64SConvertI32 = 0xb7;
let kExprF64UConvertI32 = 0xb8;
let kExprF64SConvertI64 = 0xb9;
let kExprF64UConvertI64 = 0xba;
let kExprF64ConvertF32 = 0xbb;
let kExprI32ReinterpretF32 = 0xbc;
let kExprI64ReinterpretF64 = 0xbd;
let kExprF32ReinterpretI32 = 0xbe;
let kExprF64ReinterpretI64 = 0xbf;
var kTrapUnreachable = 0;
var kTrapMemOutOfBounds = 1;
var kTrapDivByZero = 2;
var kTrapDivUnrepresentable = 3;
var kTrapRemByZero = 4;
var kTrapFloatUnrepresentable = 5;
var kTrapFuncInvalid = 6;
var kTrapFuncSigMismatch = 7;
var kTrapInvalidIndex = 8;
let kTrapUnreachable = 0;
let kTrapMemOutOfBounds = 1;
let kTrapDivByZero = 2;
let kTrapDivUnrepresentable = 3;
let kTrapRemByZero = 4;
let kTrapFloatUnrepresentable = 5;
let kTrapFuncInvalid = 6;
let kTrapFuncSigMismatch = 7;
let kTrapInvalidIndex = 8;
var kTrapMsgs = [
let kTrapMsgs = [
"unreachable",
"memory access out of bounds",
"divide by zero",
......
......@@ -1149,7 +1149,7 @@ TEST_F(AstDecoderTest, AllSimpleExpressions) {
}
TEST_F(AstDecoderTest, MemorySize) {
byte code[] = {kExprMemorySize};
byte code[] = {kExprMemorySize, 0};
EXPECT_VERIFIES_C(i_i, code);
EXPECT_FAILURE_C(f_ff, code);
}
......@@ -1632,7 +1632,7 @@ TEST_F(AstDecoderTest, WasmGrowMemory) {
module = &module_env;
module->origin = kWasmOrigin;
byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))};
byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0};
EXPECT_VERIFIES_C(i_i, code);
EXPECT_FAILURE_C(i_d, code);
}
......@@ -1642,7 +1642,7 @@ TEST_F(AstDecoderTest, AsmJsGrowMemory) {
module = &module_env;
module->origin = kAsmJsOrigin;
byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))};
byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0};
EXPECT_FAILURE_C(i_i, code);
}
......@@ -2316,7 +2316,7 @@ TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
EXPECT_LENGTH(2, kExprGetGlobal);
EXPECT_LENGTH(2, kExprSetGlobal);
EXPECT_LENGTH(2, kExprCallFunction);
EXPECT_LENGTH(2, kExprCallIndirect);
EXPECT_LENGTH(3, kExprCallIndirect);
}
TEST_F(WasmOpcodeLengthTest, I32Const) {
......@@ -2375,8 +2375,8 @@ TEST_F(WasmOpcodeLengthTest, LoadsAndStores) {
}
TEST_F(WasmOpcodeLengthTest, MiscMemExpressions) {
EXPECT_LENGTH(1, kExprMemorySize);
EXPECT_LENGTH(1, kExprGrowMemory);
EXPECT_LENGTH(2, kExprMemorySize);
EXPECT_LENGTH(2, kExprGrowMemory);
}
TEST_F(WasmOpcodeLengthTest, SimpleExpressions) {
......
......@@ -131,12 +131,12 @@ TEST_F(WasmMacroGenTest, CallFunction) {
}
TEST_F(WasmMacroGenTest, CallIndirect) {
EXPECT_SIZE(4, WASM_CALL_INDIRECT0(0, WASM_ZERO));
EXPECT_SIZE(4, WASM_CALL_INDIRECT0(1, WASM_ZERO));
EXPECT_SIZE(4, WASM_CALL_INDIRECT0(11, WASM_ZERO));
EXPECT_SIZE(5, WASM_CALL_INDIRECT0(0, WASM_ZERO));
EXPECT_SIZE(5, WASM_CALL_INDIRECT0(1, WASM_ZERO));
EXPECT_SIZE(5, WASM_CALL_INDIRECT0(11, WASM_ZERO));
EXPECT_SIZE(6, WASM_CALL_INDIRECT1(0, WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(8, WASM_CALL_INDIRECT2(1, WASM_ZERO, WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(7, WASM_CALL_INDIRECT1(0, WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(9, WASM_CALL_INDIRECT2(1, WASM_ZERO, WASM_ZERO, WASM_ZERO));
}
TEST_F(WasmMacroGenTest, Int32Ops) {
......
......@@ -12,30 +12,30 @@ cd ${TOOLS_DIR}/..
rm -rf test/fuzzer/wasm
rm -rf test/fuzzer/wasm_asmjs
make x64.debug -j
make x64.release -j
mkdir -p test/fuzzer/wasm
mkdir -p test/fuzzer/wasm_asmjs
# asm.js
./tools/run-tests.py -j8 --variants=default --timeout=10 --arch=x64 \
--mode=debug --no-presubmit --extra-flags="--dump-wasm-module \
--mode=release --no-presubmit --extra-flags="--dump-wasm-module \
--dump-wasm-module-path=./test/fuzzer/wasm_asmjs/" mjsunit/wasm/asm*
./tools/run-tests.py -j8 --variants=default --timeout=10 --arch=x64 \
--mode=debug --no-presubmit --extra-flags="--dump-wasm-module \
--mode=release --no-presubmit --extra-flags="--dump-wasm-module \
--dump-wasm-module-path=./test/fuzzer/wasm_asmjs/" mjsunit/asm/*
./tools/run-tests.py -j8 --variants=default --timeout=10 --arch=x64 \
--mode=debug --no-presubmit --extra-flags="--dump-wasm-module \
--mode=release --no-presubmit --extra-flags="--dump-wasm-module \
--dump-wasm-module-path=./test/fuzzer/wasm_asmjs/" mjsunit/regress/asm/*
# WASM
./tools/run-tests.py -j8 --variants=default --timeout=10 --arch=x64 \
--mode=debug --no-presubmit --extra-flags="--dump-wasm-module \
--mode=release --no-presubmit --extra-flags="--dump-wasm-module \
--dump-wasm-module-path=./test/fuzzer/wasm/" unittests
./tools/run-tests.py -j8 --variants=default --timeout=10 --arch=x64 \
--mode=debug --no-presubmit --extra-flags="--dump-wasm-module \
--mode=release --no-presubmit --extra-flags="--dump-wasm-module \
--dump-wasm-module-path=./test/fuzzer/wasm/" mjsunit/wasm/*
./tools/run-tests.py -j8 --variants=default --timeout=10 --arch=x64 \
--mode=debug --no-presubmit --extra-flags="--dump-wasm-module \
--mode=release --no-presubmit --extra-flags="--dump-wasm-module \
--dump-wasm-module-path=./test/fuzzer/wasm/" \
$(cd test/; ls cctest/wasm/test-*.cc | \
sed -es/wasm\\///g | sed -es/[.]cc/\\/\\*/g)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment