1 //===-- llvm/BinaryFormat/XCOFF.cpp - The XCOFF file format -----*- 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/XCOFF.h"
10 #include "llvm/ADT/StringRef.h"
11 
12 using namespace llvm;
13 
14 #define SMC_CASE(A)                                                            \
15   case XCOFF::XMC_##A:                                                         \
16     return #A;
17 StringRef XCOFF::getMappingClassString(XCOFF::StorageMappingClass SMC) {
18   switch (SMC) {
19     SMC_CASE(PR)
20     SMC_CASE(RO)
21     SMC_CASE(DB)
22     SMC_CASE(GL)
23     SMC_CASE(XO)
24     SMC_CASE(SV)
25     SMC_CASE(SV64)
26     SMC_CASE(SV3264)
27     SMC_CASE(TI)
28     SMC_CASE(TB)
29     SMC_CASE(RW)
30     SMC_CASE(TC0)
31     SMC_CASE(TC)
32     SMC_CASE(TD)
33     SMC_CASE(DS)
34     SMC_CASE(UA)
35     SMC_CASE(BS)
36     SMC_CASE(UC)
37     SMC_CASE(TL)
38     SMC_CASE(UL)
39     SMC_CASE(TE)
40 #undef SMC_CASE
41   }
42 
43   // TODO: need to add a test case for "Unknown" and other SMC.
44   return "Unknown";
45 }
46 
47 #define RELOC_CASE(A)                                                          \
48   case XCOFF::A:                                                               \
49     return #A;
50 StringRef XCOFF::getRelocationTypeString(XCOFF::RelocationType Type) {
51   switch (Type) {
52     RELOC_CASE(R_POS)
53     RELOC_CASE(R_RL)
54     RELOC_CASE(R_RLA)
55     RELOC_CASE(R_NEG)
56     RELOC_CASE(R_REL)
57     RELOC_CASE(R_TOC)
58     RELOC_CASE(R_TRL)
59     RELOC_CASE(R_TRLA)
60     RELOC_CASE(R_GL)
61     RELOC_CASE(R_TCL)
62     RELOC_CASE(R_REF)
63     RELOC_CASE(R_BA)
64     RELOC_CASE(R_BR)
65     RELOC_CASE(R_RBA)
66     RELOC_CASE(R_RBR)
67     RELOC_CASE(R_TLS)
68     RELOC_CASE(R_TLS_IE)
69     RELOC_CASE(R_TLS_LD)
70     RELOC_CASE(R_TLS_LE)
71     RELOC_CASE(R_TLSM)
72     RELOC_CASE(R_TLSML)
73     RELOC_CASE(R_TOCU)
74     RELOC_CASE(R_TOCL)
75   }
76   return "Unknown";
77 }
78 #undef RELOC_CASE
79