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/StringRef.h" 12 #include "llvm/BinaryFormat/XCOFF.h" 13 #include "llvm/MC/MCSymbol.h" 14 #include "llvm/MC/MCSymbolTableEntry.h" 15 16 namespace llvm { 17 18 class MCSectionXCOFF; 19 20 class MCSymbolXCOFF : public MCSymbol { 21 22 enum XCOFFSymbolFlags : uint16_t { SF_EHInfo = 0x0001 }; 23 24 public: MCSymbolXCOFF(const MCSymbolTableEntry * Name,bool isTemporary)25 MCSymbolXCOFF(const MCSymbolTableEntry *Name, bool isTemporary) 26 : MCSymbol(SymbolKindXCOFF, Name, isTemporary) {} 27 classof(const MCSymbol * S)28 static bool classof(const MCSymbol *S) { return S->isXCOFF(); } 29 30 enum CodeModel : uint8_t { CM_Small, CM_Large }; 31 getUnqualifiedName(StringRef Name)32 static StringRef getUnqualifiedName(StringRef Name) { 33 if (Name.back() == ']') { 34 StringRef Lhs, Rhs; 35 std::tie(Lhs, Rhs) = Name.rsplit('['); 36 assert(!Rhs.empty() && "Invalid SMC format in XCOFF symbol."); 37 return Lhs; 38 } 39 return Name; 40 } 41 setStorageClass(XCOFF::StorageClass SC)42 void setStorageClass(XCOFF::StorageClass SC) { 43 StorageClass = SC; 44 }; 45 getStorageClass()46 XCOFF::StorageClass getStorageClass() const { 47 assert(StorageClass && "StorageClass not set on XCOFF MCSymbol."); 48 return *StorageClass; 49 } 50 getUnqualifiedName()51 StringRef getUnqualifiedName() const { return getUnqualifiedName(getName()); } 52 53 MCSectionXCOFF *getRepresentedCsect() const; 54 55 void setRepresentedCsect(MCSectionXCOFF *C); 56 setVisibilityType(XCOFF::VisibilityType SVT)57 void setVisibilityType(XCOFF::VisibilityType SVT) { VisibilityType = SVT; }; 58 getVisibilityType()59 XCOFF::VisibilityType getVisibilityType() const { return VisibilityType; } 60 hasRename()61 bool hasRename() const { return HasRename; } 62 setSymbolTableName(StringRef STN)63 void setSymbolTableName(StringRef STN) { 64 SymbolTableName = STN; 65 HasRename = true; 66 } 67 getSymbolTableName()68 StringRef getSymbolTableName() const { 69 if (hasRename()) 70 return SymbolTableName; 71 return getUnqualifiedName(); 72 } 73 isEHInfo()74 bool isEHInfo() const { return getFlags() & SF_EHInfo; } 75 setEHInfo()76 void setEHInfo() const { modifyFlags(SF_EHInfo, SF_EHInfo); } 77 hasPerSymbolCodeModel()78 bool hasPerSymbolCodeModel() const { return PerSymbolCodeModel.has_value(); } 79 getPerSymbolCodeModel()80 CodeModel getPerSymbolCodeModel() const { 81 assert(hasPerSymbolCodeModel() && 82 "Requested code model for symbol without one"); 83 return *PerSymbolCodeModel; 84 } 85 setPerSymbolCodeModel(MCSymbolXCOFF::CodeModel Model)86 void setPerSymbolCodeModel(MCSymbolXCOFF::CodeModel Model) { 87 PerSymbolCodeModel = Model; 88 } 89 90 private: 91 std::optional<XCOFF::StorageClass> StorageClass; 92 std::optional<CodeModel> PerSymbolCodeModel; 93 94 MCSectionXCOFF *RepresentedCsect = nullptr; 95 XCOFF::VisibilityType VisibilityType = XCOFF::SYM_V_UNSPECIFIED; 96 StringRef SymbolTableName; 97 bool HasRename = false; 98 }; 99 100 } // end namespace llvm 101 102 #endif // LLVM_MC_MCSYMBOLXCOFF_H 103