1 //===-- llvm/BinaryFormat/Wasm.cpp -------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/BinaryFormat/Wasm.h"
10 
toString(wasm::WasmSymbolType Type)11 std::string llvm::wasm::toString(wasm::WasmSymbolType Type) {
12   switch (Type) {
13   case wasm::WASM_SYMBOL_TYPE_FUNCTION:
14     return "WASM_SYMBOL_TYPE_FUNCTION";
15   case wasm::WASM_SYMBOL_TYPE_GLOBAL:
16     return "WASM_SYMBOL_TYPE_GLOBAL";
17   case wasm::WASM_SYMBOL_TYPE_DATA:
18     return "WASM_SYMBOL_TYPE_DATA";
19   case wasm::WASM_SYMBOL_TYPE_SECTION:
20     return "WASM_SYMBOL_TYPE_SECTION";
21   case wasm::WASM_SYMBOL_TYPE_EVENT:
22     return "WASM_SYMBOL_TYPE_EVENT";
23   }
24   llvm_unreachable("unknown symbol type");
25 }
26 
relocTypetoString(uint32_t Type)27 std::string llvm::wasm::relocTypetoString(uint32_t Type) {
28   switch (Type) {
29 #define WASM_RELOC(NAME, VALUE)                                                \
30   case VALUE:                                                                  \
31     return #NAME;
32 #include "llvm/BinaryFormat/WasmRelocs.def"
33 #undef WASM_RELOC
34   default:
35     llvm_unreachable("unknown reloc type");
36   }
37 }
38 
relocTypeHasAddend(uint32_t Type)39 bool llvm::wasm::relocTypeHasAddend(uint32_t Type) {
40   switch (Type) {
41   case R_WASM_MEMORY_ADDR_LEB:
42   case R_WASM_MEMORY_ADDR_SLEB:
43   case R_WASM_MEMORY_ADDR_REL_SLEB:
44   case R_WASM_MEMORY_ADDR_I32:
45   case R_WASM_FUNCTION_OFFSET_I32:
46   case R_WASM_SECTION_OFFSET_I32:
47     return true;
48   default:
49     return false;
50   }
51 }
52