Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_WASM_MODULE_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
| 6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
| 7 | 7 |
| 8 #include "src/wasm/wasm-opcodes.h" | 8 #include "src/wasm/wasm-opcodes.h" |
| 9 #include "src/wasm/wasm-result.h" | 9 #include "src/wasm/wasm-result.h" |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // Constants for fixed-size elements within a module. | 47 // Constants for fixed-size elements within a module. |
| 48 static const size_t kDeclMemorySize = 3; | 48 static const size_t kDeclMemorySize = 3; |
| 49 static const size_t kDeclGlobalSize = 6; | 49 static const size_t kDeclGlobalSize = 6; |
| 50 static const size_t kDeclDataSegmentSize = 13; | 50 static const size_t kDeclDataSegmentSize = 13; |
| 51 | 51 |
| 52 // Static representation of a wasm function. | 52 // Static representation of a wasm function. |
| 53 struct WasmFunction { | 53 struct WasmFunction { |
| 54 FunctionSig* sig; // signature of the function. | 54 FunctionSig* sig; // signature of the function. |
| 55 uint32_t func_index; // index into the function table. | |
| 55 uint16_t sig_index; // index into the signature table. | 56 uint16_t sig_index; // index into the signature table. |
| 56 uint32_t name_offset; // offset in the module bytes of the name, if any. | 57 uint32_t name_offset; // offset in the module bytes of the name, if any. |
| 57 uint32_t code_start_offset; // offset in the module bytes of code start. | 58 uint32_t code_start_offset; // offset in the module bytes of code start. |
| 58 uint32_t code_end_offset; // offset in the module bytes of code end. | 59 uint32_t code_end_offset; // offset in the module bytes of code end. |
| 59 uint16_t local_i32_count; // number of i32 local variables. | 60 uint16_t local_i32_count; // number of i32 local variables. |
| 60 uint16_t local_i64_count; // number of i64 local variables. | 61 uint16_t local_i64_count; // number of i64 local variables. |
| 61 uint16_t local_f32_count; // number of f32 local variables. | 62 uint16_t local_f32_count; // number of f32 local variables. |
| 62 uint16_t local_f64_count; // number of f64 local variables. | 63 uint16_t local_f64_count; // number of f64 local variables. |
| 63 bool exported; // true if this function is exported. | 64 bool exported; // true if this function is exported. |
| 64 bool external; // true if this function is externally supplied. | 65 bool external; // true if this function is externally supplied. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 std::vector<WasmGlobal>* globals; // globals in this module. | 100 std::vector<WasmGlobal>* globals; // globals in this module. |
| 100 std::vector<FunctionSig*>* signatures; // signatures in this module. | 101 std::vector<FunctionSig*>* signatures; // signatures in this module. |
| 101 std::vector<WasmFunction>* functions; // functions in this module. | 102 std::vector<WasmFunction>* functions; // functions in this module. |
| 102 std::vector<WasmDataSegment>* data_segments; // data segments in this module. | 103 std::vector<WasmDataSegment>* data_segments; // data segments in this module. |
| 103 std::vector<uint16_t>* function_table; // function table. | 104 std::vector<uint16_t>* function_table; // function table. |
| 104 | 105 |
| 105 WasmModule(); | 106 WasmModule(); |
| 106 ~WasmModule(); | 107 ~WasmModule(); |
| 107 | 108 |
| 108 // Get a pointer to a string stored in the module bytes representing a name. | 109 // Get a pointer to a string stored in the module bytes representing a name. |
| 109 const char* GetName(uint32_t offset) { | 110 const char* GetName(uint32_t offset) const { |
| 110 if (offset == 0) return "<?>"; // no name. | 111 if (offset == 0) return "<?>"; // no name. |
| 111 CHECK(BoundsCheck(offset, offset + 1)); | 112 CHECK(BoundsCheck(offset, offset + 1)); |
| 112 return reinterpret_cast<const char*>(module_start + offset); | 113 return reinterpret_cast<const char*>(module_start + offset); |
| 113 } | 114 } |
| 114 | 115 |
| 115 // Checks the given offset range is contained within the module bytes. | 116 // Checks the given offset range is contained within the module bytes. |
| 116 bool BoundsCheck(uint32_t start, uint32_t end) { | 117 bool BoundsCheck(uint32_t start, uint32_t end) const { |
| 117 size_t size = module_end - module_start; | 118 size_t size = module_end - module_start; |
| 118 return start < size && end < size; | 119 return start < size && end < size; |
| 119 } | 120 } |
| 120 | 121 |
| 121 // Creates a new instantiation of the module in the given isolate. | 122 // Creates a new instantiation of the module in the given isolate. |
| 122 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi, | 123 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi, |
| 123 Handle<JSArrayBuffer> memory); | 124 Handle<JSArrayBuffer> memory); |
| 124 }; | 125 }; |
| 125 | 126 |
| 126 // An instantiated WASM module, including memory, function table, etc. | 127 // An instantiated WASM module, including memory, function table, etc. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 : 0; | 187 : 0; |
| 187 } | 188 } |
| 188 | 189 |
| 189 Handle<Code> GetFunctionCode(uint32_t index); | 190 Handle<Code> GetFunctionCode(uint32_t index); |
| 190 Handle<FixedArray> GetFunctionTable(); | 191 Handle<FixedArray> GetFunctionTable(); |
| 191 | 192 |
| 192 compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, FunctionSig* sig); | 193 compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, FunctionSig* sig); |
| 193 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); | 194 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); |
| 194 }; | 195 }; |
| 195 | 196 |
| 197 // A helper for printing out the names of functions. | |
| 198 struct WasmFunctionName { | |
|
ahaas
2016/02/15 14:44:40
What about calling this struct PrintWasmFunctionHe
| |
| 199 const WasmFunction* function_; | |
| 200 const WasmModule* module_; | |
| 201 WasmFunctionName(const WasmFunction* function, const ModuleEnv* menv) | |
| 202 : function_(function), module_(menv ? menv->module : nullptr) {} | |
| 203 }; | |
| 204 | |
| 196 std::ostream& operator<<(std::ostream& os, const WasmModule& module); | 205 std::ostream& operator<<(std::ostream& os, const WasmModule& module); |
| 197 std::ostream& operator<<(std::ostream& os, const WasmFunction& function); | 206 std::ostream& operator<<(std::ostream& os, const WasmFunction& function); |
| 207 std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name); | |
| 198 | 208 |
| 199 typedef Result<WasmModule*> ModuleResult; | 209 typedef Result<WasmModule*> ModuleResult; |
| 200 typedef Result<WasmFunction*> FunctionResult; | 210 typedef Result<WasmFunction*> FunctionResult; |
| 201 | 211 |
| 202 // For testing. Decode, verify, and run the last exported function in the | 212 // For testing. Decode, verify, and run the last exported function in the |
| 203 // given encoded module. | 213 // given encoded module. |
| 204 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 214 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
| 205 const byte* module_end, bool asm_js = false); | 215 const byte* module_end, bool asm_js = false); |
| 206 | 216 |
| 207 // For testing. Decode, verify, and run the last exported function in the | 217 // For testing. Decode, verify, and run the last exported function in the |
| 208 // given decoded module. | 218 // given decoded module. |
| 209 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); | 219 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); |
| 220 | |
| 210 } // namespace wasm | 221 } // namespace wasm |
| 211 } // namespace internal | 222 } // namespace internal |
| 212 } // namespace v8 | 223 } // namespace v8 |
| 213 | 224 |
| 214 #endif // V8_WASM_MODULE_H_ | 225 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |