[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}
This commit is contained in:
titzer 2016-05-13 05:47:49 -07:00 committed by Commit bot
parent 7bc54ba832
commit 82db9dece3
7 changed files with 14 additions and 101 deletions

View File

@ -172,10 +172,6 @@ class ModuleDecoder : public Decoder {
0, // name_length
0, // code_start_offset
0, // code_end_offset
0, // local_i32_count
0, // local_i64_count
0, // local_f32_count
0, // local_f64_count
false}); // exported
WasmFunction* function = &module->functions.back();
function->sig_index = consume_sig_index(module, &function->sig);
@ -230,10 +226,6 @@ class ModuleDecoder : public Decoder {
0, // name_length
0, // code_start_offset
0, // code_end_offset
0, // local_i32_count
0, // local_i64_count
0, // local_f32_count
0, // local_f64_count
false}); // exported
WasmFunction* function = &module->functions.back();
DecodeFunctionInModule(module, function, false);
@ -519,10 +511,8 @@ class ModuleDecoder : public Decoder {
function->sig = module->signatures[function->sig_index];
}
TRACE(" +%d <function attributes:%s%s%s>\n",
static_cast<int>(pc_ - start_),
TRACE(" +%d <function attributes:%s%s>\n", static_cast<int>(pc_ - start_),
decl_bits & kDeclFunctionName ? " name" : "",
decl_bits & kDeclFunctionLocals ? " locals" : "",
decl_bits & kDeclFunctionExport ? " exported" : "");
function->exported = decl_bits & kDeclFunctionExport;
@ -532,13 +522,6 @@ class ModuleDecoder : public Decoder {
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");
if (ok()) {
if ((pc_ + size) > limit_) {

View File

@ -88,12 +88,6 @@ std::ostream& operator<<(std::ostream& os, const WasmModule& module) {
std::ostream& operator<<(std::ostream& os, const WasmFunction& function) {
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: "
<< (function.code_end_offset - function.code_start_offset);
return os;

View File

@ -96,7 +96,6 @@ struct WasmSection {
enum WasmFunctionDeclBit {
kDeclFunctionName = 0x01,
kDeclFunctionLocals = 0x04,
kDeclFunctionExport = 0x08
};
@ -115,10 +114,6 @@ struct WasmFunction {
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_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.
};

View File

@ -40,7 +40,7 @@ void testFunctionNameTable(Vector<Vector<const char>> names) {
if (func_index % 2) all_names.push_back('\0');
module.functions.push_back(
{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;
}

View File

@ -168,7 +168,7 @@ class TestingModule : public ModuleEnv {
module->functions.reserve(kMaxFunctions);
}
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);
DCHECK_LT(index, kMaxFunctions); // limited for testing.
return index;

View File

@ -1177,10 +1177,6 @@ class TestModuleEnv : public ModuleEnv {
0, // name_length
0, // code_start_offset
0, // code_end_offset
0, // local_i32_count
0, // local_i64_count
0, // local_f32_count
0, // local_f64_count
false}); // exported
CHECK(mod.functions.size() <= 127);
return static_cast<byte>(mod.functions.size() - 1);

View File

@ -343,21 +343,16 @@ TEST_F(WasmModuleVerifyTest, FunctionWithoutSig) {
}
TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) {
const int kCodeStartOffset = 49;
const int kCodeStartOffset = 41;
const int kCodeEndOffset = kCodeStartOffset + 1;
static const byte data[] = {
// signatures
SIGNATURES_SECTION_VOID_VOID,
// func#0 ------------------------------------------------------
SECTION(OLD_FUNCTIONS, 18), 1,
kDeclFunctionLocals | kDeclFunctionExport | kDeclFunctionName,
SECTION(OLD_FUNCTIONS, 10), 1, kDeclFunctionExport | kDeclFunctionName,
SIG_INDEX(0), // signature index
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
kExprNop,
};
@ -379,11 +374,6 @@ TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) {
EXPECT_EQ(kCodeStartOffset, function->code_start_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);
if (result.val) delete result.val;
@ -415,47 +405,6 @@ TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) {
EXPECT_EQ(kCodeStartOffset, function->code_start_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);
if (result.val) delete result.val;
@ -463,7 +412,7 @@ TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) {
TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) {
static const byte kNameOffset = 49;
static const byte kCodeStartOffset = 61;
static const byte kCodeStartOffset = 53;
static const byte kCodeEndOffset = kCodeStartOffset + 3;
static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22;
@ -476,18 +425,14 @@ TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) {
// sig#0 -----------------------------------------------------
SIGNATURES_SECTION_VOID_VOID,
// func#0 ----------------------------------------------------
SECTION(OLD_FUNCTIONS, 20), 1,
kDeclFunctionLocals | kDeclFunctionName, // --
SIG_INDEX(0), // signature index
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
kExprNop, // func#0 body
kExprNop, // func#0 body
kExprNop, // func#0 body
SECTION(OLD_FUNCTIONS, 12), 1,
kDeclFunctionName, // --
SIG_INDEX(0), // signature index
2, 'h', 'i', // name
3, 0, // body size
kExprNop, // func#0 body
kExprNop, // func#0 body
kExprNop, // func#0 body
// memory section --------------------------------------------
SECTION(MEMORY, 3), 28, 28, 1,
// segment#0 -------------------------------------------------