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_TABLE:
18     return "WASM_SYMBOL_TYPE_TABLE";
19   case wasm::WASM_SYMBOL_TYPE_DATA:
20     return "WASM_SYMBOL_TYPE_DATA";
21   case wasm::WASM_SYMBOL_TYPE_SECTION:
22     return "WASM_SYMBOL_TYPE_SECTION";
23   case wasm::WASM_SYMBOL_TYPE_EVENT:
24     return "WASM_SYMBOL_TYPE_EVENT";
25   }
26   llvm_unreachable("unknown symbol type");
27 }
28 
relocTypetoString(uint32_t Type)29 std::string llvm::wasm::relocTypetoString(uint32_t Type) {
30   switch (Type) {
31 #define WASM_RELOC(NAME, VALUE)                                                \
32   case VALUE:                                                                  \
33     return #NAME;
34 #include "llvm/BinaryFormat/WasmRelocs.def"
35 #undef WASM_RELOC
36   default:
37     llvm_unreachable("unknown reloc type");
38   }
39 }
40 
relocTypeHasAddend(uint32_t Type)41 bool llvm::wasm::relocTypeHasAddend(uint32_t Type) {
42   switch (Type) {
43   case R_WASM_MEMORY_ADDR_LEB:
44   case R_WASM_MEMORY_ADDR_LEB64:
45   case R_WASM_MEMORY_ADDR_SLEB:
46   case R_WASM_MEMORY_ADDR_SLEB64:
47   case R_WASM_MEMORY_ADDR_REL_SLEB:
48   case R_WASM_MEMORY_ADDR_REL_SLEB64:
49   case R_WASM_MEMORY_ADDR_I32:
50   case R_WASM_MEMORY_ADDR_I64:
51   case R_WASM_MEMORY_ADDR_TLS_SLEB:
52   case R_WASM_FUNCTION_OFFSET_I32:
53   case R_WASM_FUNCTION_OFFSET_I64:
54   case R_WASM_SECTION_OFFSET_I32:
55     return true;
56   default:
57     return false;
58   }
59 }
60