LCOV - code coverage report
Current view: top level - include/llvm/BinaryFormat - Wasm.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 4 4 100.0 %
Date: 2018-02-23 15:42:53 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Wasm.h - Wasm object file format -------------------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file defines manifest constants for the wasm object file format.
      11             : // See: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_BINARYFORMAT_WASM_H
      16             : #define LLVM_BINARYFORMAT_WASM_H
      17             : 
      18             : #include "llvm/ADT/ArrayRef.h"
      19             : 
      20             : namespace llvm {
      21             : namespace wasm {
      22             : 
      23             : // Object file magic string.
      24             : const char WasmMagic[] = {'\0', 'a', 's', 'm'};
      25             : // Wasm binary format version
      26             : const uint32_t WasmVersion = 0x1;
      27             : // Wasm uses a 64k page size
      28             : const uint32_t WasmPageSize = 65536;
      29             : 
      30             : struct WasmObjectHeader {
      31             :   StringRef Magic;
      32             :   uint32_t Version;
      33             : };
      34             : 
      35          86 : struct WasmSignature {
      36             :   std::vector<int32_t> ParamTypes;
      37             :   int32_t ReturnType;
      38             : };
      39             : 
      40             : struct WasmExport {
      41             :   StringRef Name;
      42             :   uint32_t Kind;
      43             :   uint32_t Index;
      44             : };
      45             : 
      46             : struct WasmLimits {
      47             :   uint32_t Flags;
      48             :   uint32_t Initial;
      49             :   uint32_t Maximum;
      50             : };
      51             : 
      52             : struct WasmTable {
      53             :   int32_t ElemType;
      54             :   WasmLimits Limits;
      55             : };
      56             : 
      57             : struct WasmInitExpr {
      58             :   uint8_t Opcode;
      59             :   union {
      60             :     int32_t Int32;
      61             :     int64_t Int64;
      62             :     int32_t Float32;
      63             :     int64_t Float64;
      64             :     uint32_t Global;
      65             :   } Value;
      66             : };
      67             : 
      68             : struct WasmGlobalType {
      69             :   int32_t Type;
      70             :   bool Mutable;
      71             : };
      72             : 
      73             : struct WasmGlobal {
      74             :   uint32_t Index;
      75             :   WasmGlobalType Type;
      76             :   WasmInitExpr InitExpr;
      77             : };
      78             : 
      79             : struct WasmImport {
      80             :   StringRef Module;
      81             :   StringRef Field;
      82             :   uint32_t Kind;
      83             :   union {
      84             :     uint32_t SigIndex;
      85             :     WasmGlobalType Global;
      86             :     WasmTable Table;
      87             :     WasmLimits Memory;
      88             :   };
      89             : };
      90             : 
      91             : struct WasmLocalDecl {
      92             :   int32_t Type;
      93             :   uint32_t Count;
      94             : };
      95             : 
      96          38 : struct WasmFunction {
      97             :   uint32_t Index;
      98             :   std::vector<WasmLocalDecl> Locals;
      99             :   ArrayRef<uint8_t> Body;
     100             :   uint32_t CodeSectionOffset;
     101             :   uint32_t Size;
     102             :   StringRef Name; // from the "names" section
     103             :   StringRef Comdat; // from the "comdat info" section
     104             : };
     105             : 
     106             : struct WasmDataSegment {
     107             :   uint32_t MemoryIndex;
     108             :   WasmInitExpr Offset;
     109             :   ArrayRef<uint8_t> Content;
     110             :   StringRef Name;
     111             :   uint32_t Alignment;
     112             :   uint32_t Flags;
     113             :   StringRef Comdat; // from the "comdat info" section
     114             : };
     115             : 
     116           4 : struct WasmElemSegment {
     117             :   uint32_t TableIndex;
     118             :   WasmInitExpr Offset;
     119             :   std::vector<uint32_t> Functions;
     120             : };
     121             : 
     122             : // Represents the location of a Wasm data symbol within a WasmDataSegment, as
     123             : // the index of the segment, and the offset and size within the segment.
     124             : struct WasmDataReference {
     125             :   uint32_t Segment;
     126             :   uint32_t Offset;
     127             :   uint32_t Size;
     128             : };
     129             : 
     130             : struct WasmRelocation {
     131             :   uint32_t Type;   // The type of the relocation.
     132             :   uint32_t Index;  // Index into either symbol or type index space.
     133             :   uint64_t Offset; // Offset from the start of the section.
     134             :   int64_t Addend;  // A value to add to the symbol.
     135             : };
     136             : 
     137             : struct WasmInitFunc {
     138             :   uint32_t Priority;
     139             :   uint32_t Symbol;
     140             : };
     141             : 
     142             : struct WasmSymbolInfo {
     143             :   StringRef Name;
     144             :   uint32_t Kind;
     145             :   uint32_t Flags;
     146             :   union {
     147             :     // For function or global symbols, the index in function of global index
     148             :     // space.
     149             :     uint32_t ElementIndex;
     150             :     // For a data symbols, the address of the data relative to segment.
     151             :     WasmDataReference DataRef;
     152             :   };
     153             : };
     154             : 
     155             : struct WasmFunctionName {
     156             :   uint32_t Index;
     157             :   StringRef Name;
     158             : };
     159             : 
     160          72 : struct WasmLinkingData {
     161             :   uint32_t DataSize;
     162             :   std::vector<WasmInitFunc> InitFunctions;
     163             :   std::vector<WasmSymbolInfo> SymbolTable;
     164             : };
     165             : 
     166             : enum : unsigned {
     167             :   WASM_SEC_CUSTOM = 0,   // Custom / User-defined section
     168             :   WASM_SEC_TYPE = 1,     // Function signature declarations
     169             :   WASM_SEC_IMPORT = 2,   // Import declarations
     170             :   WASM_SEC_FUNCTION = 3, // Function declarations
     171             :   WASM_SEC_TABLE = 4,    // Indirect function table and other tables
     172             :   WASM_SEC_MEMORY = 5,   // Memory attributes
     173             :   WASM_SEC_GLOBAL = 6,   // Global declarations
     174             :   WASM_SEC_EXPORT = 7,   // Exports
     175             :   WASM_SEC_START = 8,    // Start function declaration
     176             :   WASM_SEC_ELEM = 9,     // Elements section
     177             :   WASM_SEC_CODE = 10,    // Function bodies (code)
     178             :   WASM_SEC_DATA = 11     // Data segments
     179             : };
     180             : 
     181             : // Type immediate encodings used in various contexts.
     182             : enum {
     183             :   WASM_TYPE_I32 = -0x01,
     184             :   WASM_TYPE_I64 = -0x02,
     185             :   WASM_TYPE_F32 = -0x03,
     186             :   WASM_TYPE_F64 = -0x04,
     187             :   WASM_TYPE_ANYFUNC = -0x10,
     188             :   WASM_TYPE_FUNC = -0x20,
     189             :   WASM_TYPE_NORESULT = -0x40, // for blocks with no result values
     190             : };
     191             : 
     192             : // Kinds of externals (for imports and exports).
     193             : enum : unsigned {
     194             :   WASM_EXTERNAL_FUNCTION = 0x0,
     195             :   WASM_EXTERNAL_TABLE = 0x1,
     196             :   WASM_EXTERNAL_MEMORY = 0x2,
     197             :   WASM_EXTERNAL_GLOBAL = 0x3,
     198             : };
     199             : 
     200             : // Opcodes used in initializer expressions.
     201             : enum : unsigned {
     202             :   WASM_OPCODE_END = 0x0b,
     203             :   WASM_OPCODE_GET_GLOBAL = 0x23,
     204             :   WASM_OPCODE_I32_CONST = 0x41,
     205             :   WASM_OPCODE_I64_CONST = 0x42,
     206             :   WASM_OPCODE_F32_CONST = 0x43,
     207             :   WASM_OPCODE_F64_CONST = 0x44,
     208             : };
     209             : 
     210             : enum : unsigned {
     211             :   WASM_LIMITS_FLAG_HAS_MAX = 0x1,
     212             : };
     213             : 
     214             : // Subset of types that a value can have
     215             : enum class ValType {
     216             :   I32 = WASM_TYPE_I32,
     217             :   I64 = WASM_TYPE_I64,
     218             :   F32 = WASM_TYPE_F32,
     219             :   F64 = WASM_TYPE_F64,
     220             : };
     221             : 
     222             : // Kind codes used in the custom "name" section
     223             : enum : unsigned {
     224             :   WASM_NAMES_FUNCTION = 0x1,
     225             :   WASM_NAMES_LOCAL    = 0x2,
     226             : };
     227             : 
     228             : // Kind codes used in the custom "linking" section
     229             : enum : unsigned {
     230             :   WASM_DATA_SIZE      = 0x3,
     231             :   WASM_SEGMENT_INFO   = 0x5,
     232             :   WASM_INIT_FUNCS     = 0x6,
     233             :   WASM_COMDAT_INFO    = 0x7,
     234             :   WASM_SYMBOL_TABLE   = 0x8,
     235             : };
     236             : 
     237             : // Kind codes used in the custom "linking" section in the WASM_COMDAT_INFO
     238             : enum : unsigned {
     239             :   WASM_COMDAT_DATA        = 0x0,
     240             :   WASM_COMDAT_FUNCTION    = 0x1,
     241             : };
     242             : 
     243             : // Kind codes used in the custom "linking" section in the WASM_SYMBOL_TABLE
     244             : enum WasmSymbolType : unsigned {
     245             :   WASM_SYMBOL_TYPE_FUNCTION = 0x0,
     246             :   WASM_SYMBOL_TYPE_DATA     = 0x1,
     247             :   WASM_SYMBOL_TYPE_GLOBAL   = 0x2,
     248             : };
     249             : 
     250             : const unsigned WASM_SYMBOL_BINDING_MASK       = 0x3;
     251             : const unsigned WASM_SYMBOL_VISIBILITY_MASK    = 0xc;
     252             : 
     253             : const unsigned WASM_SYMBOL_BINDING_GLOBAL     = 0x0;
     254             : const unsigned WASM_SYMBOL_BINDING_WEAK       = 0x1;
     255             : const unsigned WASM_SYMBOL_BINDING_LOCAL      = 0x2;
     256             : const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0;
     257             : const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN  = 0x4;
     258             : const unsigned WASM_SYMBOL_UNDEFINED          = 0x10;
     259             : 
     260             : #define WASM_RELOC(name, value) name = value,
     261             : 
     262             : enum : unsigned {
     263             : #include "WasmRelocs.def"
     264             : };
     265             : 
     266             : #undef WASM_RELOC
     267             : 
     268             : } // end namespace wasm
     269             : } // end namespace llvm
     270             : 
     271             : #endif

Generated by: LCOV version 1.13