|
15 | 15 | #ifndef LLVM_MC_MCSECTIONGOFF_H
|
16 | 16 | #define LLVM_MC_MCSECTIONGOFF_H
|
17 | 17 |
|
18 |
| -#include "llvm/ADT/BitmaskEnum.h" |
19 | 18 | #include "llvm/BinaryFormat/GOFF.h"
|
20 | 19 | #include "llvm/MC/MCGOFFAttributes.h"
|
21 | 20 | #include "llvm/MC/MCSection.h"
|
| 21 | +#include "llvm/Support/ErrorHandling.h" |
22 | 22 | #include "llvm/Support/raw_ostream.h"
|
23 | 23 |
|
24 | 24 | namespace llvm {
|
25 | 25 |
|
26 | 26 | class MCExpr;
|
27 | 27 |
|
28 | 28 | class MCSectionGOFF final : public MCSection {
|
29 |
| -private: |
30 |
| - // The names of the GOFF symbols. |
31 |
| - StringRef SDName; |
32 |
| - StringRef EDName; |
33 |
| - StringRef LDorPRName; |
| 29 | + // Parent of this section. Implies that the parent is emitted first. |
| 30 | + MCSectionGOFF *Parent; |
34 | 31 |
|
35 | 32 | // The attributes of the GOFF symbols.
|
36 | 33 | GOFF::SDAttr SDAttributes;
|
37 | 34 | GOFF::EDAttr EDAttributes;
|
38 |
| - GOFF::LDAttr LDAttributes; |
39 | 35 | GOFF::PRAttr PRAttributes;
|
40 | 36 |
|
41 |
| -public: |
42 |
| - enum SectionFlags { |
43 |
| - UsesRootSD = 1, // Uses the common root SD. |
44 |
| - HasLD = 2, // Has a LD symbol. |
45 |
| - HasPR = 4, // Has a PR symbol. |
46 |
| - LDorPRNameIsSD = 8, // The LD or PR name is the same as the SD name. |
47 |
| - LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ 8) |
48 |
| - }; |
| 37 | + // The type of this section. |
| 38 | + GOFF::ESDSymbolType SymbolType; |
| 39 | + |
| 40 | + // Indicates that the ED symbol needs to set the length of the section. |
| 41 | + unsigned RequiresLength : 1; |
49 | 42 |
|
50 |
| -private: |
51 |
| - SectionFlags Flags; |
| 43 | + // Indicates that the PR symbol needs to set the length of the section to a |
| 44 | + // non-zero value. |
| 45 | + unsigned RequiresNonZeroLength : 1; |
52 | 46 |
|
53 | 47 | friend class MCContext;
|
54 |
| - MCSectionGOFF(StringRef SynName, SectionKind K, SectionFlags Flags, |
55 |
| - StringRef SDName, GOFF::SDAttr SDAttributes, StringRef EDName, |
56 |
| - GOFF::EDAttr EDAttributes, StringRef LDorPRName, |
57 |
| - GOFF::LDAttr LDAttributes, GOFF::PRAttr PRAttributes) |
58 |
| - : MCSection(SV_GOFF, SynName, K.isText(), /*IsVirtual=*/false, nullptr), |
59 |
| - SDName(SDName), EDName(EDName), LDorPRName(LDorPRName), |
60 |
| - SDAttributes(SDAttributes), EDAttributes(EDAttributes), |
61 |
| - LDAttributes(LDAttributes), PRAttributes(PRAttributes), Flags(Flags) {} |
| 48 | + MCSectionGOFF(StringRef Name, SectionKind K, GOFF::ESDSymbolType SymbolType, |
| 49 | + GOFF::SDAttr SDAttributes, GOFF::EDAttr EDAttributes, |
| 50 | + GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent = nullptr) |
| 51 | + : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr), |
| 52 | + Parent(Parent), SDAttributes(SDAttributes), EDAttributes(EDAttributes), |
| 53 | + PRAttributes(PRAttributes), SymbolType(SymbolType) {} |
62 | 54 |
|
63 | 55 | public:
|
64 | 56 | void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
|
65 | 57 | raw_ostream &OS,
|
66 | 58 | uint32_t /*Subsection*/) const override {
|
67 |
| - if (!usesRootSD()) |
68 |
| - OS << getSDName() << " CSECT\n"; |
69 |
| - OS << getEDName() << " CATTR\n"; |
70 |
| - if ((hasLD() || hasPR()) && !getLDorPRName().empty()) |
71 |
| - OS << getLDorPRName() << " XATTR\n"; |
| 59 | + ; |
| 60 | + switch (SymbolType) { |
| 61 | + case GOFF::ESD_ST_SectionDefinition: |
| 62 | + OS << Name << " CSECT\n"; |
| 63 | + break; |
| 64 | + case GOFF::ESD_ST_ElementDefinition: |
| 65 | + OS << Name << " CATTR\n"; |
| 66 | + break; |
| 67 | + case GOFF::ESD_ST_PartReference: |
| 68 | + OS << Name << " XATTR\n"; |
| 69 | + break; |
| 70 | + default: |
| 71 | + llvm_unreachable("Wrong section type"); |
| 72 | + } |
72 | 73 | }
|
73 | 74 |
|
74 | 75 | bool useCodeAlign() const override { return false; }
|
75 | 76 |
|
76 |
| - // Accessors to the various symbol names. |
77 |
| - StringRef getSDName() const { return SDName; }; |
78 |
| - StringRef getEDName() const { return EDName; }; |
79 |
| - StringRef getLDorPRName() const { |
80 |
| - assert(Flags & (HasLD | HasPR) && "LD/PR name not available"); |
81 |
| - return (Flags & LDorPRNameIsSD) ? SDName : LDorPRName; |
82 |
| - }; |
83 |
| - |
84 |
| - // Setters for the SD and LD/PR symbol names. |
85 |
| - void setSDName(StringRef Name) { |
86 |
| - assert(!(Flags & UsesRootSD) && "Uses root SD"); |
87 |
| - SDName = Name; |
| 77 | + // Return the id of the section. It is the 1-based ordinal number. |
| 78 | + unsigned getId() const { return getOrdinal() + 1; } |
| 79 | + |
| 80 | + // Return the parent section. |
| 81 | + MCSectionGOFF *getParent() const { return Parent; } |
| 82 | + |
| 83 | + // Returns the type of this section. |
| 84 | + GOFF::ESDSymbolType getSymbolType() const { return SymbolType; } |
| 85 | + |
| 86 | + bool isSD() const { return SymbolType == GOFF::ESD_ST_SectionDefinition; } |
| 87 | + bool isED() const { return SymbolType == GOFF::ESD_ST_ElementDefinition; } |
| 88 | + bool isPR() const { return SymbolType == GOFF::ESD_ST_PartReference; } |
| 89 | + |
| 90 | + // Accessors to the attributes. |
| 91 | + GOFF::SDAttr getSDAttributes() const { |
| 92 | + assert(SymbolType == GOFF::ESD_ST_SectionDefinition && "Not PR symbol"); |
| 93 | + return SDAttributes; |
88 | 94 | }
|
89 |
| - void setLDorPRName(StringRef Name) { LDorPRName = Name; } |
90 |
| - |
91 |
| - // Accessors to the various attributes. |
92 |
| - GOFF::SDAttr getSDAttributes() const { return SDAttributes; } |
93 |
| - GOFF::EDAttr getEDAttributes() const { return EDAttributes; } |
94 |
| - GOFF::LDAttr getLDAttributes() const { |
95 |
| - assert(Flags & HasLD && "LD not available"); |
96 |
| - return LDAttributes; |
| 95 | + GOFF::EDAttr getEDAttributes() const { |
| 96 | + assert(SymbolType == GOFF::ESD_ST_ElementDefinition && "Not PR symbol"); |
| 97 | + return EDAttributes; |
97 | 98 | }
|
98 | 99 | GOFF::PRAttr getPRAttributes() const {
|
99 |
| - assert(Flags & HasPR && "PR not available"); |
| 100 | + assert(SymbolType == GOFF::ESD_ST_PartReference && "Not PR symbol"); |
100 | 101 | return PRAttributes;
|
101 | 102 | }
|
102 | 103 |
|
103 |
| - // Query various flags. |
104 |
| - bool usesRootSD() const { return Flags & UsesRootSD; } |
105 |
| - bool hasLD() const { return Flags & HasLD; } |
106 |
| - bool hasPR() const { return Flags & HasPR; } |
107 |
| - bool isLDorPRNameTheSD() const { return Flags & LDorPRNameIsSD; } |
| 104 | + bool requiresLength() const { return RequiresLength; } |
| 105 | + bool requiresNonZeroLength() const { return RequiresNonZeroLength; } |
| 106 | + |
| 107 | + void setName(StringRef SectionName) { Name = SectionName; } |
108 | 108 |
|
109 | 109 | static bool classof(const MCSection *S) { return S->getVariant() == SV_GOFF; }
|
110 | 110 | };
|
|
0 commit comments