[llvm-commits] [llvm] r103980 - in /llvm/trunk: include/llvm/MC/MCSection.h include/llvm/MC/MCSectionCOFF.h include/llvm/MC/MCSectionELF.h include/llvm/MC/MCSectionMachO.h lib/MC/MCSectionMachO.cpp lib/Target/PIC16/PIC16Section.h
Daniel Dunbar
daniel at zuster.org
Mon May 17 14:54:26 PDT 2010
Author: ddunbar
Date: Mon May 17 16:54:26 2010
New Revision: 103980
URL: http://llvm.org/viewvc/llvm-project?rev=103980&view=rev
Log:
MC: Add dyn_cast support to MCSection.
- Of questionable utility, since in general anything which wants to do this should probably be within a target specific hook, which can rely on the sections being of the appropriate type. However, it can be useful for short term hacks.
Modified:
llvm/trunk/include/llvm/MC/MCSection.h
llvm/trunk/include/llvm/MC/MCSectionCOFF.h
llvm/trunk/include/llvm/MC/MCSectionELF.h
llvm/trunk/include/llvm/MC/MCSectionMachO.h
llvm/trunk/lib/MC/MCSectionMachO.cpp
llvm/trunk/lib/Target/PIC16/PIC16Section.h
Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=103980&r1=103979&r2=103980&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Mon May 17 16:54:26 2010
@@ -17,6 +17,7 @@
#include <string>
#include "llvm/ADT/StringRef.h"
#include "llvm/MC/SectionKind.h"
+#include "llvm/Support/Casting.h"
namespace llvm {
class MCContext;
@@ -27,15 +28,27 @@
/// section in the current translation unit. The MCContext class uniques and
/// creates these.
class MCSection {
+ public:
+ enum SectionVariant {
+ SV_COFF = 0,
+ SV_ELF,
+ SV_MachO,
+ SV_PIC16
+ };
+
+ private:
MCSection(const MCSection&); // DO NOT IMPLEMENT
void operator=(const MCSection&); // DO NOT IMPLEMENT
protected:
- MCSection(SectionKind K) : Kind(K) {}
+ MCSection(SectionVariant V, SectionKind K) : Variant(V), Kind(K) {}
+ SectionVariant Variant;
SectionKind Kind;
public:
virtual ~MCSection();
SectionKind getKind() const { return Kind; }
+
+ SectionVariant getVariant() const { return Variant; }
virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const = 0;
@@ -47,6 +60,8 @@
virtual bool isBaseAddressKnownZero() const {
return false;
}
+
+ static bool classof(const MCSection *) { return true; }
};
} // end namespace llvm
Modified: llvm/trunk/include/llvm/MC/MCSectionCOFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionCOFF.h?rev=103980&r1=103979&r2=103980&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionCOFF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionCOFF.h Mon May 17 16:54:26 2010
@@ -35,8 +35,8 @@
friend class MCContext;
MCSectionCOFF(StringRef Section, unsigned Characteristics,
int Selection, SectionKind K)
- : MCSection(K), SectionName(Section), Characteristics(Characteristics),
- Selection (Selection) {
+ : MCSection(SV_COFF, K), SectionName(Section),
+ Characteristics(Characteristics), Selection (Selection) {
assert ((Characteristics & 0x00F00000) == 0 &&
"alignment must not be set upon section creation");
}
@@ -103,6 +103,11 @@
virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const;
+
+ static bool classof(const MCSection *S) {
+ return S->getVariant() == SV_COFF;
+ }
+ static bool classof(const MCSectionCOFF *) { return true; }
};
} // end namespace llvm
Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=103980&r1=103979&r2=103980&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Mon May 17 16:54:26 2010
@@ -40,7 +40,7 @@
friend class MCContext;
MCSectionELF(StringRef Section, unsigned type, unsigned flags,
SectionKind K, bool isExplicit)
- : MCSection(K), SectionName(Section), Type(type), Flags(flags),
+ : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
IsExplicit(isExplicit) {}
~MCSectionELF();
public:
@@ -178,6 +178,11 @@
virtual bool isBaseAddressKnownZero() const {
return (getFlags() & SHF_ALLOC) == 0;
}
+
+ static bool classof(const MCSection *S) {
+ return S->getVariant() == SV_ELF;
+ }
+ static bool classof(const MCSectionELF *) { return true; }
};
} // end namespace llvm
Modified: llvm/trunk/include/llvm/MC/MCSectionMachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionMachO.h?rev=103980&r1=103979&r2=103980&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionMachO.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionMachO.h Mon May 17 16:54:26 2010
@@ -165,6 +165,11 @@
virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const;
+
+ static bool classof(const MCSection *S) {
+ return S->getVariant() == SV_MachO;
+ }
+ static bool classof(const MCSectionMachO *) { return true; }
};
} // end namespace llvm
Modified: llvm/trunk/lib/MC/MCSectionMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSectionMachO.cpp?rev=103980&r1=103979&r2=103980&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSectionMachO.cpp (original)
+++ llvm/trunk/lib/MC/MCSectionMachO.cpp Mon May 17 16:54:26 2010
@@ -73,7 +73,7 @@
MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
unsigned TAA, unsigned reserved2, SectionKind K)
- : MCSection(K), TypeAndAttributes(TAA), Reserved2(reserved2) {
+ : MCSection(SV_MachO, K), TypeAndAttributes(TAA), Reserved2(reserved2) {
assert(Segment.size() <= 16 && Section.size() <= 16 &&
"Segment or section string too long");
for (unsigned i = 0; i != 16; ++i) {
Modified: llvm/trunk/lib/Target/PIC16/PIC16Section.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Section.h?rev=103980&r1=103979&r2=103980&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Section.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Section.h Mon May 17 16:54:26 2010
@@ -44,7 +44,8 @@
unsigned Size;
PIC16Section(StringRef name, SectionKind K, StringRef addr, int color)
- : MCSection(K), Name(name), Address(addr), Color(color), Size(0) {
+ : MCSection(SV_PIC16, K), Name(name), Address(addr),
+ Color(color), Size(0) {
}
public:
@@ -86,6 +87,11 @@
/// to a section.
virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const;
+
+ static bool classof(const MCSection *S) {
+ return S->getVariant() == SV_PIC16;
+ }
+ static bool classof(const PIC16Section *) { return true; }
};
} // end namespace llvm
More information about the llvm-commits
mailing list