diff options
Diffstat (limited to 'include/llvm/Support/Wasm.h')
-rw-r--r-- | include/llvm/Support/Wasm.h | 145 |
1 files changed, 130 insertions, 15 deletions
diff --git a/include/llvm/Support/Wasm.h b/include/llvm/Support/Wasm.h index 8ac6b9038e91..8e6c418c8189 100644 --- a/include/llvm/Support/Wasm.h +++ b/include/llvm/Support/Wasm.h @@ -23,22 +23,94 @@ namespace wasm { // Object file magic string. const char WasmMagic[] = {'\0', 'a', 's', 'm'}; // Wasm binary format version -const uint32_t WasmVersion = 0xd; +const uint32_t WasmVersion = 0x1; struct WasmObjectHeader { StringRef Magic; uint32_t Version; }; -struct WasmSection { - uint32_t Type; // Section type (See below) - uint32_t Offset; // Offset with in the file - StringRef Name; // Section name (User-defined sections only) - ArrayRef<uint8_t> Content; // Section content +struct WasmSignature { + std::vector<int32_t> ParamTypes; + int32_t ReturnType; +}; + +struct WasmImport { + StringRef Module; + StringRef Field; + uint32_t Kind; + union { + uint32_t SigIndex; + int32_t GlobalType; + }; + bool GlobalMutable; +}; + +struct WasmExport { + StringRef Name; + uint32_t Kind; + uint32_t Index; +}; + +struct WasmLimits { + uint32_t Flags; + uint32_t Initial; + uint32_t Maximum; +}; + +struct WasmTable { + int32_t ElemType; + WasmLimits Limits; +}; + +struct WasmInitExpr { + uint8_t Opcode; + union { + int32_t Int32; + int64_t Int64; + int32_t Float32; + int64_t Float64; + uint32_t Global; + } Value; +}; + +struct WasmGlobal { + int32_t Type; + bool Mutable; + WasmInitExpr InitExpr; +}; + +struct WasmLocalDecl { + int32_t Type; + uint32_t Count; +}; + +struct WasmFunction { + std::vector<WasmLocalDecl> Locals; + ArrayRef<uint8_t> Body; +}; + +struct WasmDataSegment { + uint32_t Index; + WasmInitExpr Offset; + ArrayRef<uint8_t> Content; +}; + +struct WasmElemSegment { + uint32_t TableIndex; + WasmInitExpr Offset; + std::vector<uint32_t> Functions; +}; + +struct WasmRelocation { + uint32_t Type; // The type of the relocation. + int32_t Index; // Index into function to global index space. + uint64_t Offset; // Offset from the start of the section. + uint64_t Addend; // A value to add to the symbol. }; enum : unsigned { - WASM_SEC_USER = 0, // User-defined section + WASM_SEC_CUSTOM = 0, // Custom / User-defined section WASM_SEC_TYPE = 1, // Function signature declarations WASM_SEC_IMPORT = 2, // Import declarations WASM_SEC_FUNCTION = 3, // Function declarations @@ -53,14 +125,14 @@ enum : unsigned { }; // Type immediate encodings used in various contexts. -enum : unsigned { - WASM_TYPE_I32 = 0x7f, - WASM_TYPE_I64 = 0x7e, - WASM_TYPE_F32 = 0x7d, - WASM_TYPE_F64 = 0x7c, - WASM_TYPE_ANYFUNC = 0x70, - WASM_TYPE_FUNC = 0x60, - WASM_TYPE_NORESULT = 0x40, // for blocks with no result values +enum { + WASM_TYPE_I32 = -0x01, + WASM_TYPE_I64 = -0x02, + WASM_TYPE_F32 = -0x03, + WASM_TYPE_F64 = -0x04, + WASM_TYPE_ANYFUNC = -0x10, + WASM_TYPE_FUNC = -0x20, + WASM_TYPE_NORESULT = -0x40, // for blocks with no result values }; // Kinds of externals (for imports and exports). @@ -81,6 +153,49 @@ enum : unsigned { WASM_OPCODE_F64_CONST = 0x44, }; +enum : unsigned { + WASM_NAMES_FUNCTION = 0x1, + WASM_NAMES_LOCAL = 0x2, +}; + +enum : unsigned { + WASM_LIMITS_FLAG_HAS_MAX = 0x1, +}; + +// Subset of types that a value can have +enum class ValType { + I32 = WASM_TYPE_I32, + I64 = WASM_TYPE_I64, + F32 = WASM_TYPE_F32, + F64 = WASM_TYPE_F64, +}; + +// Linking metadata kinds. +enum : unsigned { + WASM_STACK_POINTER = 0x1, +}; + +#define WASM_RELOC(name, value) name = value, + +enum : unsigned { +#include "WasmRelocs/WebAssembly.def" +}; + +#undef WASM_RELOC + +struct Global { + ValType Type; + bool Mutable; + + // The initial value for this global is either the value of an imported + // global, in which case InitialModule and InitialName specify the global + // import, or a value, in which case InitialModule is empty and InitialValue + // holds the value. + StringRef InitialModule; + StringRef InitialName; + uint64_t InitialValue; +}; + } // end namespace wasm } // end namespace llvm |