• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- MCSymbolXCOFF.h -  ----------------------------------------*- 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 #ifndef LLVM_MC_MCSYMBOLXCOFF_H
9 #define LLVM_MC_MCSYMBOLXCOFF_H
10 
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/BinaryFormat/XCOFF.h"
14 #include "llvm/MC/MCSymbol.h"
15 
16 namespace llvm {
17 
18 class MCSectionXCOFF;
19 
20 class MCSymbolXCOFF : public MCSymbol {
21 public:
MCSymbolXCOFF(const StringMapEntry<bool> * Name,bool isTemporary)22   MCSymbolXCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
23       : MCSymbol(SymbolKindXCOFF, Name, isTemporary) {}
24 
classof(const MCSymbol * S)25   static bool classof(const MCSymbol *S) { return S->isXCOFF(); }
26 
setStorageClass(XCOFF::StorageClass SC)27   void setStorageClass(XCOFF::StorageClass SC) {
28     assert((!StorageClass.hasValue() || StorageClass.getValue() == SC) &&
29            "Redefining StorageClass of XCOFF MCSymbol.");
30     StorageClass = SC;
31   };
32 
getStorageClass()33   XCOFF::StorageClass getStorageClass() const {
34     assert(StorageClass.hasValue() &&
35            "StorageClass not set on XCOFF MCSymbol.");
36     return StorageClass.getValue();
37   }
38 
setContainingCsect(MCSectionXCOFF * C)39   void setContainingCsect(MCSectionXCOFF *C) {
40     assert((!ContainingCsect || ContainingCsect == C) &&
41            "Trying to set a containing csect that doesn't match the one that"
42            "this symbol is already mapped to.");
43     ContainingCsect = C;
44   }
45 
getContainingCsect()46   MCSectionXCOFF *getContainingCsect() const {
47     assert(ContainingCsect &&
48            "Trying to get containing csect but none was set.");
49     return ContainingCsect;
50   }
51 
hasContainingCsect()52   bool hasContainingCsect() const { return ContainingCsect != nullptr; }
53 
getUnqualifiedName()54   StringRef getUnqualifiedName() const {
55     const StringRef name = getName();
56     if (name.back() == ']') {
57       StringRef lhs, rhs;
58       std::tie(lhs, rhs) = name.rsplit('[');
59       assert(!rhs.empty() && "Invalid SMC format in XCOFF symbol.");
60       return lhs;
61     }
62     return name;
63   }
64 
65 private:
66   Optional<XCOFF::StorageClass> StorageClass;
67   MCSectionXCOFF *ContainingCsect = nullptr;
68 };
69 
70 } // end namespace llvm
71 
72 #endif // LLVM_MC_MCSYMBOLXCOFF_H
73