Revert "Revert "Upgrade to 5.0.71.48"" DO NOT MERGE
This reverts commit f2e3994fa5148cc3d9946666f0b0596290192b0e,
and updates the x64 makefile properly so it doesn't break that
build.
FPIIM-449
Change-Id: Ib83e35bfbae6af627451c926a9650ec57c045605
(cherry picked from commit 109988c7ccb6f3fd1a58574fa3dfb88beaef6632)
diff --git a/src/wasm/wasm-module.h b/src/wasm/wasm-module.h
index 5e2ba58..5f5777c 100644
--- a/src/wasm/wasm-module.h
+++ b/src/wasm/wasm-module.h
@@ -30,11 +30,13 @@
kDeclGlobals = 0x03,
kDeclDataSegments = 0x04,
kDeclFunctionTable = 0x05,
- kDeclWLL = 0x11,
kDeclEnd = 0x06,
+ kDeclStartFunction = 0x07,
+ kDeclImportTable = 0x08,
+ kDeclWLL = 0x11,
};
-static const int kMaxModuleSectionCode = 6;
+static const int kMaxModuleSectionCode = 0x11;
enum WasmFunctionDeclBit {
kDeclFunctionName = 0x01,
@@ -48,22 +50,29 @@
static const size_t kDeclGlobalSize = 6;
static const size_t kDeclDataSegmentSize = 13;
-// Static representation of a wasm function.
+// Static representation of a WASM function.
struct WasmFunction {
FunctionSig* sig; // signature of the function.
+ uint32_t func_index; // index into the function table.
uint16_t sig_index; // index into the signature table.
uint32_t name_offset; // offset in the module bytes of the name, if any.
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_int32_count; // number of int32 local variables.
- uint16_t local_int64_count; // number of int64 local variables.
- uint16_t local_float32_count; // number of float32 local variables.
- uint16_t local_float64_count; // number of float64 local variables.
+ 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 external; // true if this function is externally supplied.
};
-struct ModuleEnv; // forward declaration of decoder interface.
+// Static representation of an imported WASM function.
+struct WasmImport {
+ FunctionSig* sig; // signature of the function.
+ uint16_t sig_index; // index into the signature table.
+ uint32_t module_name_offset; // offset in module bytes of the module name.
+ uint32_t function_name_offset; // offset in module bytes of the import name.
+};
// Static representation of a wasm global variable.
struct WasmGlobal {
@@ -93,25 +102,27 @@
uint8_t max_mem_size_log2; // maximum size of the memory (log base 2).
bool mem_export; // true if the memory is exported.
bool mem_external; // true if the memory is external.
+ int start_function_index; // start function, if any.
std::vector<WasmGlobal>* globals; // globals in this module.
std::vector<FunctionSig*>* signatures; // signatures in this module.
std::vector<WasmFunction>* functions; // functions in this module.
std::vector<WasmDataSegment>* data_segments; // data segments in this module.
std::vector<uint16_t>* function_table; // function table.
+ std::vector<WasmImport>* import_table; // import table.
WasmModule();
~WasmModule();
// Get a pointer to a string stored in the module bytes representing a name.
- const char* GetName(uint32_t offset) {
- CHECK(BoundsCheck(offset, offset + 1));
+ const char* GetName(uint32_t offset) const {
if (offset == 0) return "<?>"; // no name.
+ CHECK(BoundsCheck(offset, offset + 1));
return reinterpret_cast<const char*>(module_start + offset);
}
// Checks the given offset range is contained within the module bytes.
- bool BoundsCheck(uint32_t start, uint32_t end) {
+ bool BoundsCheck(uint32_t start, uint32_t end) const {
size_t size = module_end - module_start;
return start < size && end < size;
}
@@ -121,22 +132,42 @@
Handle<JSArrayBuffer> memory);
};
+// An instantiated WASM module, including memory, function table, etc.
+struct WasmModuleInstance {
+ WasmModule* module; // static representation of the module.
+ // -- Heap allocated --------------------------------------------------------
+ Handle<JSObject> js_object; // JavaScript module object.
+ Handle<Context> context; // JavaScript native context.
+ Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory.
+ Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals.
+ Handle<FixedArray> function_table; // indirect function table.
+ std::vector<Handle<Code>>* function_code; // code objects for each function.
+ std::vector<Handle<Code>>* import_code; // code objects for each import.
+ // -- raw memory ------------------------------------------------------------
+ byte* mem_start; // start of linear memory.
+ size_t mem_size; // size of the linear memory.
+ // -- raw globals -----------------------------------------------------------
+ byte* globals_start; // start of the globals area.
+ size_t globals_size; // size of the globals area.
+
+ explicit WasmModuleInstance(WasmModule* m)
+ : module(m),
+ function_code(nullptr),
+ mem_start(nullptr),
+ mem_size(0),
+ globals_start(nullptr),
+ globals_size(0) {}
+};
+
// forward declaration.
class WasmLinker;
// Interface provided to the decoder/graph builder which contains only
// minimal information about the globals, functions, and function tables.
struct ModuleEnv {
- uintptr_t globals_area; // address of the globals area.
- uintptr_t mem_start; // address of the start of linear memory.
- uintptr_t mem_end; // address of the end of linear memory.
-
WasmModule* module;
+ WasmModuleInstance* instance;
WasmLinker* linker;
- std::vector<Handle<Code>>* function_code;
- Handle<FixedArray> function_table;
- Handle<JSArrayBuffer> memory;
- Handle<Context> context;
bool asm_js; // true if the module originated from asm.js.
bool IsValidGlobal(uint32_t index) {
@@ -148,6 +179,9 @@
bool IsValidSignature(uint32_t index) {
return module && index < module->signatures->size();
}
+ bool IsValidImport(uint32_t index) {
+ return module && index < module->import_table->size();
+ }
MachineType GetGlobalType(uint32_t index) {
DCHECK(IsValidGlobal(index));
return module->globals->at(index).type;
@@ -156,23 +190,41 @@
DCHECK(IsValidFunction(index));
return module->functions->at(index).sig;
}
+ FunctionSig* GetImportSignature(uint32_t index) {
+ DCHECK(IsValidImport(index));
+ return module->import_table->at(index).sig;
+ }
FunctionSig* GetSignature(uint32_t index) {
DCHECK(IsValidSignature(index));
return module->signatures->at(index);
}
size_t FunctionTableSize() {
- return module ? module->function_table->size() : 0;
+ return module && module->function_table ? module->function_table->size()
+ : 0;
}
Handle<Code> GetFunctionCode(uint32_t index);
+ Handle<Code> GetImportCode(uint32_t index);
Handle<FixedArray> GetFunctionTable();
- compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, FunctionSig* sig);
+ static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone,
+ FunctionSig* sig);
+ static compiler::CallDescriptor* GetI32WasmCallDescriptor(
+ Zone* zone, compiler::CallDescriptor* descriptor);
compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index);
};
+// A helper for printing out the names of functions.
+struct WasmFunctionName {
+ const WasmFunction* function_;
+ const WasmModule* module_;
+ WasmFunctionName(const WasmFunction* function, const ModuleEnv* menv)
+ : function_(function), module_(menv ? menv->module : nullptr) {}
+};
+
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 WasmFunctionName& name);
typedef Result<WasmModule*> ModuleResult;
typedef Result<WasmFunction*> FunctionResult;
@@ -185,6 +237,7 @@
// For testing. Decode, verify, and run the last exported function in the
// given decoded module.
int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module);
+
} // namespace wasm
} // namespace internal
} // namespace v8