Sam Clegg | 5f87ab3 | 2018-05-14 22:42:07 +0000 | [diff] [blame] | 1 | //===-- llvm/BinaryFormat/Wasm.cpp -------------------------------*- C++-*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Sam Clegg | 5f87ab3 | 2018-05-14 22:42:07 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/BinaryFormat/Wasm.h" |
| 10 | |
Heejin Ahn | 18c56a0 | 2019-02-04 19:13:39 +0000 | [diff] [blame] | 11 | std::string llvm::wasm::toString(wasm::WasmSymbolType Type) { |
| 12 | switch (Type) { |
Sam Clegg | 5f87ab3 | 2018-05-14 22:42:07 +0000 | [diff] [blame] | 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"; |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 21 | case wasm::WASM_SYMBOL_TYPE_EVENT: |
| 22 | return "WASM_SYMBOL_TYPE_EVENT"; |
Sam Clegg | 5f87ab3 | 2018-05-14 22:42:07 +0000 | [diff] [blame] | 23 | } |
| 24 | llvm_unreachable("unknown symbol type"); |
| 25 | } |
| 26 | |
Heejin Ahn | 18c56a0 | 2019-02-04 19:13:39 +0000 | [diff] [blame] | 27 | std::string llvm::wasm::relocTypetoString(uint32_t Type) { |
| 28 | switch (Type) { |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 29 | #define WASM_RELOC(NAME, VALUE) \ |
| 30 | case VALUE: \ |
| 31 | return #NAME; |
Sam Clegg | 5f87ab3 | 2018-05-14 22:42:07 +0000 | [diff] [blame] | 32 | #include "llvm/BinaryFormat/WasmRelocs.def" |
| 33 | #undef WASM_RELOC |
| 34 | default: |
| 35 | llvm_unreachable("unknown reloc type"); |
| 36 | } |
| 37 | } |
Keno Fischer | cadcb9e | 2019-06-26 00:52:42 +0000 | [diff] [blame] | 38 | |
| 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 | } |