Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Unified Diff: test/mjsunit/wasm/wasm-module-builder.js

Issue 2361053004: Revert of [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/wasm/wasm-constants.js ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/wasm-module-builder.js
diff --git a/test/mjsunit/wasm/wasm-module-builder.js b/test/mjsunit/wasm/wasm-module-builder.js
index 7b77a8c9b105106a2231c6ac12d0f4e66d964a4d..f0cf9d18d3570a5a6e161074f738609ff6d208b1 100644
--- a/test/mjsunit/wasm/wasm-module-builder.js
+++ b/test/mjsunit/wasm/wasm-module-builder.js
@@ -61,7 +61,7 @@
emit_section(section_code, content_generator) {
// Emit section name.
- this.emit_u8(section_code);
+ this.emit_string(section_names[section_code]);
// Emit the section to a temporary buffer: its full length isn't know yet.
let section = new Binary;
content_generator(section);
@@ -147,7 +147,7 @@
addFunction(name, type) {
let type_index = (typeof type) == "number" ? type : this.addType(type);
let func = new WasmFunctionBuilder(name, type_index);
- func.index = this.functions.length + this.imports.length;
+ func.index = this.functions.length;
this.functions.push(func);
return func;
}
@@ -182,7 +182,7 @@
// Add type section
if (wasm.types.length > 0) {
if (debug) print("emitting types @ " + binary.length);
- binary.emit_section(kTypeSectionCode, section => {
+ binary.emit_section(kDeclTypes, section => {
section.emit_varint(wasm.types.length);
for (let type of wasm.types) {
section.emit_u8(kWasmFunctionTypeForm);
@@ -198,16 +198,27 @@
});
}
+ if (wasm.globals.length > 0) {
+ if (debug) print ("emitting globals @ " + binary.length);
+ binary.emit_section(kDeclGlobals, section => {
+ section.emit_varint(wasm.globals.length);
+ for (let global_type of wasm.globals) {
+ section.emit_varint(0); // length of global name
+ section.emit_u8(global_type);
+ section.emit_u8(false); // we do not support exported globals
+ }
+ });
+ }
+
// Add imports section
if (wasm.imports.length > 0) {
if (debug) print("emitting imports @ " + binary.length);
- binary.emit_section(kImportSectionCode, section => {
+ binary.emit_section(kDeclImports, section => {
section.emit_varint(wasm.imports.length);
for (let imp of wasm.imports) {
+ section.emit_varint(imp.type);
section.emit_string(imp.module);
section.emit_string(imp.name || '');
- section.emit_u8(kExternalFunction);
- section.emit_varint(imp.type);
}
});
}
@@ -218,7 +229,7 @@
let exports = 0;
if (wasm.functions.length > 0) {
if (debug) print("emitting function decls @ " + binary.length);
- binary.emit_section(kFunctionSectionCode, section => {
+ binary.emit_section(kDeclFunctions, section => {
section.emit_varint(wasm.functions.length);
for (let func of wasm.functions) {
has_names = has_names || (func.name != undefined &&
@@ -232,75 +243,39 @@
// Add table.
if (wasm.table.length > 0) {
if (debug) print("emitting table @ " + binary.length);
- binary.emit_section(kTableSectionCode, section => {
- section.emit_u8(1); // one table entry
- section.emit_u8(kWasmAnyFunctionTypeForm);
- section.emit_u8(1);
+ binary.emit_section(kDeclTable, section => {
section.emit_varint(wasm.table.length);
- section.emit_varint(wasm.table.length);
+ if (wasm.pad !== null) {
+ if (debug) print("emitting table padding @ " + binary.length);
+ section.emit_varint(wasm.pad);
+ }
+ for (let index of wasm.table) {
+ section.emit_varint(index);
+ }
});
}
// Add memory section
if (wasm.memory != undefined) {
if (debug) print("emitting memory @ " + binary.length);
- binary.emit_section(kMemorySectionCode, section => {
- section.emit_u8(1); // one memory entry
- section.emit_varint(kResizableMaximumFlag);
+ binary.emit_section(kDeclMemory, section => {
section.emit_varint(wasm.memory.min);
section.emit_varint(wasm.memory.max);
- });
- }
-
- // Add global section.
- if (wasm.globals.length > 0) {
- if (debug) print ("emitting globals @ " + binary.length);
- binary.emit_section(kGlobalSectionCode, section => {
- section.emit_varint(wasm.globals.length);
- for (let global_type of wasm.globals) {
- section.emit_u8(global_type);
- section.emit_u8(true); // mutable
- switch (global_type) {
- case kAstI32:
- section.emit_u8(kExprI32Const);
- section.emit_u8(0);
- break;
- case kAstI64:
- section.emit_u8(kExprI64Const);
- section.emit_u8(0);
- break;
- case kAstF32:
- section.emit_u8(kExprF32Const);
- section.emit_u32(0);
- break;
- case kAstF64:
- section.emit_u8(kExprI32Const);
- section.emit_u32(0);
- section.emit_u32(0);
- break;
- }
- section.emit_u8(kExprEnd); // end of init expression
- }
- });
- }
+ section.emit_u8(wasm.memory.exp ? 1 : 0);
+ });
+ }
+
// Add export table.
- var mem_export = (wasm.memory != undefined && wasm.memory.exp);
- if (exports > 0 || mem_export) {
+ if (exports > 0) {
if (debug) print("emitting exports @ " + binary.length);
- binary.emit_section(kExportSectionCode, section => {
- section.emit_varint(exports + (mem_export ? 1 : 0));
+ binary.emit_section(kDeclExports, section => {
+ section.emit_varint(exports);
for (let func of wasm.functions) {
for (let exp of func.exports) {
+ section.emit_varint(func.index);
section.emit_string(exp);
- section.emit_u8(kExternalFunction);
- section.emit_varint(func.index);
- }
- }
- if (mem_export) {
- section.emit_string("memory");
- section.emit_u8(kExternalMemory);
- section.emit_u8(0);
+ }
}
});
}
@@ -308,24 +283,8 @@
// Add start function section.
if (wasm.start_index != undefined) {
if (debug) print("emitting start function @ " + binary.length);
- binary.emit_section(kStartSectionCode, section => {
+ binary.emit_section(kDeclStart, section => {
section.emit_varint(wasm.start_index);
- });
- }
-
- // Add table elements.
- if (wasm.table.length > 0) {
- if (debug) print("emitting table @ " + binary.length);
- binary.emit_section(kElementSectionCode, section => {
- section.emit_u8(1);
- section.emit_u8(0); // table index
- section.emit_u8(kExprI32Const);
- section.emit_u8(0);
- section.emit_u8(kExprEnd);
- section.emit_varint(wasm.table.length);
- for (let index of wasm.table) {
- section.emit_varint(index);
- }
});
}
@@ -333,7 +292,7 @@
if (wasm.functions.length > 0) {
// emit function bodies
if (debug) print("emitting code @ " + binary.length);
- binary.emit_section(kCodeSectionCode, section => {
+ binary.emit_section(kDeclCode, section => {
section.emit_varint(wasm.functions.length);
for (let func of wasm.functions) {
// Function body length will be patched later.
@@ -372,13 +331,10 @@
// Add data segments.
if (wasm.segments.length > 0) {
if (debug) print("emitting data segments @ " + binary.length);
- binary.emit_section(kDataSectionCode, section => {
+ binary.emit_section(kDeclData, section => {
section.emit_varint(wasm.segments.length);
for (let seg of wasm.segments) {
- section.emit_u8(0); // linear memory index 0
- section.emit_u8(kExprI32Const);
section.emit_varint(seg.addr);
- section.emit_u8(kExprEnd);
section.emit_varint(seg.data.length);
section.emit_bytes(seg.data);
}
@@ -394,8 +350,7 @@
// Add function names.
if (has_names) {
if (debug) print("emitting names @ " + binary.length);
- binary.emit_section(kUnknownSectionCode, section => {
- section.emit_string("name");
+ binary.emit_section(kDeclNames, section => {
section.emit_varint(wasm.functions.length);
for (let func of wasm.functions) {
var name = func.name == undefined ? "" : func.name;
« no previous file with comments | « test/mjsunit/wasm/wasm-constants.js ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698