Home | History | Annotate | Line # | Download | only in MC
      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:
     22   MCSymbolXCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
     23       : MCSymbol(SymbolKindXCOFF, Name, isTemporary) {}
     24 
     25   static bool classof(const MCSymbol *S) { return S->isXCOFF(); }
     26 
     27   static StringRef getUnqualifiedName(StringRef Name) {
     28     if (Name.back() == ']') {
     29       StringRef Lhs, Rhs;
     30       std::tie(Lhs, Rhs) = Name.rsplit('[');
     31       assert(!Rhs.empty() && "Invalid SMC format in XCOFF symbol.");
     32       return Lhs;
     33     }
     34     return Name;
     35   }
     36 
     37   void setStorageClass(XCOFF::StorageClass SC) {
     38     StorageClass = SC;
     39   };
     40 
     41   XCOFF::StorageClass getStorageClass() const {
     42     assert(StorageClass.hasValue() &&
     43            "StorageClass not set on XCOFF MCSymbol.");
     44     return StorageClass.getValue();
     45   }
     46 
     47   StringRef getUnqualifiedName() const { return getUnqualifiedName(getName()); }
     48 
     49   MCSectionXCOFF *getRepresentedCsect() const;
     50 
     51   void setRepresentedCsect(MCSectionXCOFF *C);
     52 
     53   void setVisibilityType(XCOFF::VisibilityType SVT) { VisibilityType = SVT; };
     54 
     55   XCOFF::VisibilityType getVisibilityType() const { return VisibilityType; }
     56 
     57   bool hasRename() const { return !SymbolTableName.empty(); }
     58 
     59   void setSymbolTableName(StringRef STN) { SymbolTableName = STN; }
     60 
     61   StringRef getSymbolTableName() const {
     62     if (hasRename())
     63       return SymbolTableName;
     64     return getUnqualifiedName();
     65   }
     66 
     67 private:
     68   Optional<XCOFF::StorageClass> StorageClass;
     69   MCSectionXCOFF *RepresentedCsect = nullptr;
     70   XCOFF::VisibilityType VisibilityType = XCOFF::SYM_V_UNSPECIFIED;
     71   StringRef SymbolTableName;
     72 };
     73 
     74 } // end namespace llvm
     75 
     76 #endif // LLVM_MC_MCSYMBOLXCOFF_H
     77