Commit 7f672535 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Move decoding constants out of wasm-module.h and into module-decoder.h

R=clemensh@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2703243002
Cr-Commit-Position: refs/heads/master@{#43332}
parent 9a407a43
...@@ -28,6 +28,39 @@ namespace wasm { ...@@ -28,6 +28,39 @@ namespace wasm {
#define TRACE(...) #define TRACE(...)
#endif #endif
const char* SectionName(WasmSectionCode code) {
switch (code) {
case kUnknownSectionCode:
return "Unknown";
case kTypeSectionCode:
return "Type";
case kImportSectionCode:
return "Import";
case kFunctionSectionCode:
return "Function";
case kTableSectionCode:
return "Table";
case kMemorySectionCode:
return "Memory";
case kGlobalSectionCode:
return "Global";
case kExportSectionCode:
return "Export";
case kStartSectionCode:
return "Start";
case kCodeSectionCode:
return "Code";
case kElementSectionCode:
return "Element";
case kDataSectionCode:
return "Data";
case kNameSectionCode:
return "Name";
default:
return "<unknown>";
}
}
namespace { namespace {
const char* kNameString = "name"; const char* kNameString = "name";
......
...@@ -14,6 +14,35 @@ namespace v8 { ...@@ -14,6 +14,35 @@ namespace v8 {
namespace internal { namespace internal {
namespace wasm { namespace wasm {
const uint32_t kWasmMagic = 0x6d736100;
const uint32_t kWasmVersion = 0x01;
const uint32_t kWasmLegacyVersion = 0x0d; // TODO(titzer): remove 0xD!
const uint8_t kWasmFunctionTypeForm = 0x60;
const uint8_t kWasmAnyFunctionTypeForm = 0x70;
const uint8_t kResizableMaximumFlag = 1;
enum WasmSectionCode {
kUnknownSectionCode = 0, // code for unknown sections
kTypeSectionCode = 1, // Function signature declarations
kImportSectionCode = 2, // Import declarations
kFunctionSectionCode = 3, // Function declarations
kTableSectionCode = 4, // Indirect function table and other tables
kMemorySectionCode = 5, // Memory attributes
kGlobalSectionCode = 6, // Global declarations
kExportSectionCode = 7, // Exports
kStartSectionCode = 8, // Start function declaration
kElementSectionCode = 9, // Elements section
kCodeSectionCode = 10, // Function code
kDataSectionCode = 11, // Data segments
kNameSectionCode = 12, // Name section (encoded as a string)
};
inline bool IsValidSectionCode(uint8_t byte) {
return kTypeSectionCode <= byte && byte <= kDataSectionCode;
}
const char* SectionName(WasmSectionCode code);
typedef Result<const WasmModule*> ModuleResult; typedef Result<const WasmModule*> ModuleResult;
typedef Result<WasmFunction*> FunctionResult; typedef Result<WasmFunction*> FunctionResult;
typedef std::vector<std::pair<int, int>> FunctionOffsets; typedef std::vector<std::pair<int, int>> FunctionOffsets;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "src/wasm/function-body-decoder.h" #include "src/wasm/function-body-decoder.h"
#include "src/wasm/leb-helper.h" #include "src/wasm/leb-helper.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-macro-gen.h" #include "src/wasm/wasm-macro-gen.h"
#include "src/wasm/wasm-module-builder.h" #include "src/wasm/wasm-module-builder.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
......
...@@ -669,39 +669,6 @@ Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size, ...@@ -669,39 +669,6 @@ Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size,
enable_guard_regions); enable_guard_regions);
} }
const char* wasm::SectionName(WasmSectionCode code) {
switch (code) {
case kUnknownSectionCode:
return "Unknown";
case kTypeSectionCode:
return "Type";
case kImportSectionCode:
return "Import";
case kFunctionSectionCode:
return "Function";
case kTableSectionCode:
return "Table";
case kMemorySectionCode:
return "Memory";
case kGlobalSectionCode:
return "Global";
case kExportSectionCode:
return "Export";
case kStartSectionCode:
return "Start";
case kCodeSectionCode:
return "Code";
case kElementSectionCode:
return "Element";
case kDataSectionCode:
return "Data";
case kNameSectionCode:
return "Name";
default:
return "<unknown>";
}
}
std::ostream& wasm::operator<<(std::ostream& os, const WasmModule& module) { std::ostream& wasm::operator<<(std::ostream& os, const WasmModule& module) {
os << "WASM module with "; os << "WASM module with ";
os << (module.min_mem_pages * module.kPageSize) << " min mem"; os << (module.min_mem_pages * module.kPageSize) << " min mem";
......
...@@ -33,40 +33,6 @@ class CallDescriptor; ...@@ -33,40 +33,6 @@ class CallDescriptor;
namespace wasm { namespace wasm {
class ErrorThrower; class ErrorThrower;
const uint32_t kWasmMagic = 0x6d736100;
const uint32_t kWasmVersion = 0x01;
// Legacy version supported for short transitionary period.
const uint32_t kWasmLegacyVersion = 0x0d;
const uint8_t kWasmFunctionTypeForm = 0x60;
const uint8_t kWasmAnyFunctionTypeForm = 0x70;
enum WasmSectionCode {
kUnknownSectionCode = 0, // code for unknown sections
kTypeSectionCode = 1, // Function signature declarations
kImportSectionCode = 2, // Import declarations
kFunctionSectionCode = 3, // Function declarations
kTableSectionCode = 4, // Indirect function table and other tables
kMemorySectionCode = 5, // Memory attributes
kGlobalSectionCode = 6, // Global declarations
kExportSectionCode = 7, // Exports
kStartSectionCode = 8, // Start function declaration
kElementSectionCode = 9, // Elements section
kCodeSectionCode = 10, // Function code
kDataSectionCode = 11, // Data segments
kNameSectionCode = 12, // Name section (encoded as a string)
};
inline bool IsValidSectionCode(uint8_t byte) {
return kTypeSectionCode <= byte && byte <= kDataSectionCode;
}
const char* SectionName(WasmSectionCode code);
// Constants for fixed-size elements within a module.
static const uint8_t kResizableMaximumFlag = 1;
static const int32_t kInvalidFunctionIndex = -1;
enum WasmExternalKind { enum WasmExternalKind {
kExternalFunction = 0, kExternalFunction = 0,
kExternalTable = 1, kExternalTable = 1,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "src/wasm/wasm-module.h" #include "src/wasm/module-decoder.h"
int fuzz_wasm_section(v8::internal::wasm::WasmSectionCode section, int fuzz_wasm_section(v8::internal::wasm::WasmSectionCode section,
const uint8_t* data, size_t size); const uint8_t* data, size_t size);
......
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