Commit 82db9dec authored by titzer's avatar titzer Committed by Commit bot

[wasm] Remove legacy encoding of local variables from asm->wasm.

R=ahaas@chromium.org,bradnelson@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/1980483002
Cr-Commit-Position: refs/heads/master@{#36239}
parent 7bc54ba8
...@@ -172,10 +172,6 @@ class ModuleDecoder : public Decoder { ...@@ -172,10 +172,6 @@ class ModuleDecoder : public Decoder {
0, // name_length 0, // name_length
0, // code_start_offset 0, // code_start_offset
0, // code_end_offset 0, // code_end_offset
0, // local_i32_count
0, // local_i64_count
0, // local_f32_count
0, // local_f64_count
false}); // exported false}); // exported
WasmFunction* function = &module->functions.back(); WasmFunction* function = &module->functions.back();
function->sig_index = consume_sig_index(module, &function->sig); function->sig_index = consume_sig_index(module, &function->sig);
...@@ -230,10 +226,6 @@ class ModuleDecoder : public Decoder { ...@@ -230,10 +226,6 @@ class ModuleDecoder : public Decoder {
0, // name_length 0, // name_length
0, // code_start_offset 0, // code_start_offset
0, // code_end_offset 0, // code_end_offset
0, // local_i32_count
0, // local_i64_count
0, // local_f32_count
0, // local_f64_count
false}); // exported false}); // exported
WasmFunction* function = &module->functions.back(); WasmFunction* function = &module->functions.back();
DecodeFunctionInModule(module, function, false); DecodeFunctionInModule(module, function, false);
...@@ -519,10 +511,8 @@ class ModuleDecoder : public Decoder { ...@@ -519,10 +511,8 @@ class ModuleDecoder : public Decoder {
function->sig = module->signatures[function->sig_index]; function->sig = module->signatures[function->sig_index];
} }
TRACE(" +%d <function attributes:%s%s%s>\n", TRACE(" +%d <function attributes:%s%s>\n", static_cast<int>(pc_ - start_),
static_cast<int>(pc_ - start_),
decl_bits & kDeclFunctionName ? " name" : "", decl_bits & kDeclFunctionName ? " name" : "",
decl_bits & kDeclFunctionLocals ? " locals" : "",
decl_bits & kDeclFunctionExport ? " exported" : ""); decl_bits & kDeclFunctionExport ? " exported" : "");
function->exported = decl_bits & kDeclFunctionExport; function->exported = decl_bits & kDeclFunctionExport;
...@@ -532,13 +522,6 @@ class ModuleDecoder : public Decoder { ...@@ -532,13 +522,6 @@ class ModuleDecoder : public Decoder {
consume_string(&function->name_length, function->exported); consume_string(&function->name_length, function->exported);
} }
if (decl_bits & kDeclFunctionLocals) {
function->local_i32_count = consume_u16("i32 count");
function->local_i64_count = consume_u16("i64 count");
function->local_f32_count = consume_u16("f32 count");
function->local_f64_count = consume_u16("f64 count");
}
uint16_t size = consume_u16("body size"); uint16_t size = consume_u16("body size");
if (ok()) { if (ok()) {
if ((pc_ + size) > limit_) { if ((pc_ + size) > limit_) {
......
...@@ -88,12 +88,6 @@ std::ostream& operator<<(std::ostream& os, const WasmModule& module) { ...@@ -88,12 +88,6 @@ std::ostream& operator<<(std::ostream& os, const WasmModule& module) {
std::ostream& operator<<(std::ostream& os, const WasmFunction& function) { std::ostream& operator<<(std::ostream& os, const WasmFunction& function) {
os << "WASM function with signature " << *function.sig; os << "WASM function with signature " << *function.sig;
os << " locals: ";
if (function.local_i32_count) os << function.local_i32_count << " i32s ";
if (function.local_i64_count) os << function.local_i64_count << " i64s ";
if (function.local_f32_count) os << function.local_f32_count << " f32s ";
if (function.local_f64_count) os << function.local_f64_count << " f64s ";
os << " code bytes: " os << " code bytes: "
<< (function.code_end_offset - function.code_start_offset); << (function.code_end_offset - function.code_start_offset);
return os; return os;
......
...@@ -96,7 +96,6 @@ struct WasmSection { ...@@ -96,7 +96,6 @@ struct WasmSection {
enum WasmFunctionDeclBit { enum WasmFunctionDeclBit {
kDeclFunctionName = 0x01, kDeclFunctionName = 0x01,
kDeclFunctionLocals = 0x04,
kDeclFunctionExport = 0x08 kDeclFunctionExport = 0x08
}; };
...@@ -115,10 +114,6 @@ struct WasmFunction { ...@@ -115,10 +114,6 @@ struct WasmFunction {
uint32_t name_length; // length in bytes of the name. uint32_t name_length; // length in bytes of the name.
uint32_t code_start_offset; // offset in the module bytes of code start. uint32_t code_start_offset; // offset in the module bytes of code start.
uint32_t code_end_offset; // offset in the module bytes of code end. uint32_t code_end_offset; // offset in the module bytes of code end.
uint16_t local_i32_count; // number of i32 local variables.
uint16_t local_i64_count; // number of i64 local variables.
uint16_t local_f32_count; // number of f32 local variables.
uint16_t local_f64_count; // number of f64 local variables.
bool exported; // true if this function is exported. bool exported; // true if this function is exported.
}; };
......
...@@ -40,7 +40,7 @@ void testFunctionNameTable(Vector<Vector<const char>> names) { ...@@ -40,7 +40,7 @@ void testFunctionNameTable(Vector<Vector<const char>> names) {
if (func_index % 2) all_names.push_back('\0'); if (func_index % 2) all_names.push_back('\0');
module.functions.push_back( module.functions.push_back(
{nullptr, 0, 0, static_cast<uint32_t>(name_offset), {nullptr, 0, 0, static_cast<uint32_t>(name_offset),
static_cast<uint32_t>(name.length()), 0, 0, 0, 0, 0, 0, false}); static_cast<uint32_t>(name.length()), 0, 0, false});
++func_index; ++func_index;
} }
......
...@@ -168,7 +168,7 @@ class TestingModule : public ModuleEnv { ...@@ -168,7 +168,7 @@ class TestingModule : public ModuleEnv {
module->functions.reserve(kMaxFunctions); module->functions.reserve(kMaxFunctions);
} }
uint32_t index = static_cast<uint32_t>(module->functions.size()); uint32_t index = static_cast<uint32_t>(module->functions.size());
module->functions.push_back({sig, index, 0, 0, 0, 0, 0, 0, 0, 0, 0, false}); module->functions.push_back({sig, index, 0, 0, 0, 0, 0, false});
instance->function_code.push_back(code); instance->function_code.push_back(code);
DCHECK_LT(index, kMaxFunctions); // limited for testing. DCHECK_LT(index, kMaxFunctions); // limited for testing.
return index; return index;
......
...@@ -1177,10 +1177,6 @@ class TestModuleEnv : public ModuleEnv { ...@@ -1177,10 +1177,6 @@ class TestModuleEnv : public ModuleEnv {
0, // name_length 0, // name_length
0, // code_start_offset 0, // code_start_offset
0, // code_end_offset 0, // code_end_offset
0, // local_i32_count
0, // local_i64_count
0, // local_f32_count
0, // local_f64_count
false}); // exported false}); // exported
CHECK(mod.functions.size() <= 127); CHECK(mod.functions.size() <= 127);
return static_cast<byte>(mod.functions.size() - 1); return static_cast<byte>(mod.functions.size() - 1);
......
...@@ -343,21 +343,16 @@ TEST_F(WasmModuleVerifyTest, FunctionWithoutSig) { ...@@ -343,21 +343,16 @@ TEST_F(WasmModuleVerifyTest, FunctionWithoutSig) {
} }
TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) { TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) {
const int kCodeStartOffset = 49; const int kCodeStartOffset = 41;
const int kCodeEndOffset = kCodeStartOffset + 1; const int kCodeEndOffset = kCodeStartOffset + 1;
static const byte data[] = { static const byte data[] = {
// signatures // signatures
SIGNATURES_SECTION_VOID_VOID, SIGNATURES_SECTION_VOID_VOID,
// func#0 ------------------------------------------------------ // func#0 ------------------------------------------------------
SECTION(OLD_FUNCTIONS, 18), 1, SECTION(OLD_FUNCTIONS, 10), 1, kDeclFunctionExport | kDeclFunctionName,
kDeclFunctionLocals | kDeclFunctionExport | kDeclFunctionName,
SIG_INDEX(0), // signature index SIG_INDEX(0), // signature index
NAME_LENGTH(2), 'h', 'i', // name NAME_LENGTH(2), 'h', 'i', // name
U16_LE(1466), // local int32 count
U16_LE(1355), // local int64 count
U16_LE(1244), // local float32 count
U16_LE(1133), // local float64 count
1, 0, // size 1, 0, // size
kExprNop, kExprNop,
}; };
...@@ -379,11 +374,6 @@ TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) { ...@@ -379,11 +374,6 @@ TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) {
EXPECT_EQ(kCodeStartOffset, function->code_start_offset); EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
EXPECT_EQ(kCodeEndOffset, function->code_end_offset); EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
EXPECT_EQ(1466, function->local_i32_count);
EXPECT_EQ(1355, function->local_i64_count);
EXPECT_EQ(1244, function->local_f32_count);
EXPECT_EQ(1133, function->local_f64_count);
EXPECT_TRUE(function->exported); EXPECT_TRUE(function->exported);
if (result.val) delete result.val; if (result.val) delete result.val;
...@@ -415,47 +405,6 @@ TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { ...@@ -415,47 +405,6 @@ TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) {
EXPECT_EQ(kCodeStartOffset, function->code_start_offset); EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
EXPECT_EQ(kCodeEndOffset, function->code_end_offset); EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
EXPECT_EQ(0, function->local_i32_count);
EXPECT_EQ(0, function->local_i64_count);
EXPECT_EQ(0, function->local_f32_count);
EXPECT_EQ(0, function->local_f64_count);
EXPECT_FALSE(function->exported);
if (result.val) delete result.val;
}
TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) {
static const byte kCodeStartOffset = 46;
static const byte kCodeEndOffset = kCodeStartOffset + 1;
static const byte data[] = {
SIGNATURES_SECTION_VOID_VOID, // --
SECTION(OLD_FUNCTIONS, 15), 1,
// func#0 ------------------------------------------------------
kDeclFunctionLocals, 0, 0, // signature index
1, 2, // local int32 count
3, 4, // local int64 count
5, 6, // local float32 count
7, 8, // local float64 count
1, 0, // body size
kExprNop // body
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_OK(result);
EXPECT_EQ(1, result.val->functions.size());
WasmFunction* function = &result.val->functions.back();
EXPECT_EQ(0, function->name_length);
EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
EXPECT_EQ(513, function->local_i32_count);
EXPECT_EQ(1027, function->local_i64_count);
EXPECT_EQ(1541, function->local_f32_count);
EXPECT_EQ(2055, function->local_f64_count);
EXPECT_FALSE(function->exported); EXPECT_FALSE(function->exported);
if (result.val) delete result.val; if (result.val) delete result.val;
...@@ -463,7 +412,7 @@ TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) { ...@@ -463,7 +412,7 @@ TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) {
TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) {
static const byte kNameOffset = 49; static const byte kNameOffset = 49;
static const byte kCodeStartOffset = 61; static const byte kCodeStartOffset = 53;
static const byte kCodeEndOffset = kCodeStartOffset + 3; static const byte kCodeEndOffset = kCodeStartOffset + 3;
static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22; static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22;
...@@ -476,14 +425,10 @@ TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { ...@@ -476,14 +425,10 @@ TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) {
// sig#0 ----------------------------------------------------- // sig#0 -----------------------------------------------------
SIGNATURES_SECTION_VOID_VOID, SIGNATURES_SECTION_VOID_VOID,
// func#0 ---------------------------------------------------- // func#0 ----------------------------------------------------
SECTION(OLD_FUNCTIONS, 20), 1, SECTION(OLD_FUNCTIONS, 12), 1,
kDeclFunctionLocals | kDeclFunctionName, // -- kDeclFunctionName, // --
SIG_INDEX(0), // signature index SIG_INDEX(0), // signature index
2, 'h', 'i', // name 2, 'h', 'i', // name
1, 2, // local int32 count
3, 4, // local int64 count
5, 6, // local float32 count
7, 8, // local float64 count
3, 0, // body size 3, 0, // body size
kExprNop, // func#0 body kExprNop, // func#0 body
kExprNop, // func#0 body kExprNop, // func#0 body
......
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