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 getUnqualifiedName(StringRef Name)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 setStorageClass(XCOFF::StorageClass SC)37 void setStorageClass(XCOFF::StorageClass SC) { 38 StorageClass = SC; 39 }; 40 getStorageClass()41 XCOFF::StorageClass getStorageClass() const { 42 assert(StorageClass.hasValue() && 43 "StorageClass not set on XCOFF MCSymbol."); 44 return StorageClass.getValue(); 45 } 46 getUnqualifiedName()47 StringRef getUnqualifiedName() const { return getUnqualifiedName(getName()); } 48 49 MCSectionXCOFF *getRepresentedCsect() const; 50 51 void setRepresentedCsect(MCSectionXCOFF *C); 52 setVisibilityType(XCOFF::VisibilityType SVT)53 void setVisibilityType(XCOFF::VisibilityType SVT) { VisibilityType = SVT; }; 54 getVisibilityType()55 XCOFF::VisibilityType getVisibilityType() const { return VisibilityType; } 56 hasRename()57 bool hasRename() const { return !SymbolTableName.empty(); } 58 setSymbolTableName(StringRef STN)59 void setSymbolTableName(StringRef STN) { SymbolTableName = STN; } 60 getSymbolTableName()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