[llvm-commits] [llvm] r130517 - in /llvm/trunk: include/llvm/MC/MCExpr.h include/llvm/MC/MCSymbol.h lib/MC/MCExpr.cpp lib/Target/ARM/ARMMCExpr.h
Daniel Dunbar
daniel at zuster.org
Fri Apr 29 11:00:03 PDT 2011
Author: ddunbar
Date: Fri Apr 29 13:00:03 2011
New Revision: 130517
URL: http://llvm.org/viewvc/llvm-project?rev=130517&view=rev
Log:
MCExpr: Add FindAssociatedSection, which attempts to mirror the 'as' semantics
that associate sections with expressions.
Modified:
llvm/trunk/include/llvm/MC/MCExpr.h
llvm/trunk/include/llvm/MC/MCSymbol.h
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/lib/Target/ARM/ARMMCExpr.h
Modified: llvm/trunk/include/llvm/MC/MCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCExpr.h?rev=130517&r1=130516&r2=130517&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCExpr.h (original)
+++ llvm/trunk/include/llvm/MC/MCExpr.h Fri Apr 29 13:00:03 2011
@@ -19,6 +19,7 @@
class MCAsmLayout;
class MCAssembler;
class MCContext;
+class MCSection;
class MCSectionData;
class MCSymbol;
class MCValue;
@@ -92,6 +93,12 @@
/// @result - True on success.
bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout &Layout) const;
+ /// FindAssociatedSection - Find the "associated section" for this expression,
+ /// which is currently defined as the absolute section for constants, or
+ /// otherwise the section associated with the first defined symbol in the
+ /// expression.
+ const MCSection *FindAssociatedSection() const;
+
/// @}
static bool classof(const MCExpr *) { return true; }
@@ -420,6 +427,7 @@
virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const = 0;
virtual void AddValueSymbols(MCAssembler *) const = 0;
+ virtual const MCSection *FindAssociatedSection() const = 0;
static bool classof(const MCExpr *E) {
return E->getKind() == MCExpr::Target;
Modified: llvm/trunk/include/llvm/MC/MCSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbol.h?rev=130517&r1=130516&r2=130517&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbol.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbol.h Fri Apr 29 13:00:03 2011
@@ -56,6 +56,7 @@
mutable unsigned IsUsed : 1;
private: // MCContext creates and uniques these.
+ friend class MCExpr;
friend class MCContext;
MCSymbol(StringRef name, bool isTemporary)
: Name(name), Section(0), Value(0),
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=130517&r1=130516&r2=130517&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Fri Apr 29 13:00:03 2011
@@ -559,3 +559,45 @@
assert(0 && "Invalid assembly expression kind!");
return false;
}
+
+const MCSection *MCExpr::FindAssociatedSection() const {
+ switch (getKind()) {
+ case Target:
+ // We never look through target specific expressions.
+ return cast<MCTargetExpr>(this)->FindAssociatedSection();
+
+ case Constant:
+ return MCSymbol::AbsolutePseudoSection;
+
+ case SymbolRef: {
+ const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
+ const MCSymbol &Sym = SRE->getSymbol();
+
+ if (Sym.isDefined())
+ return &Sym.getSection();
+
+ return 0;
+ }
+
+ case Unary:
+ return cast<MCUnaryExpr>(this)->getSubExpr()->FindAssociatedSection();
+
+ case Binary: {
+ const MCBinaryExpr *BE = cast<MCBinaryExpr>(this);
+ const MCSection *LHS_S = BE->getLHS()->FindAssociatedSection();
+ const MCSection *RHS_S = BE->getRHS()->FindAssociatedSection();
+
+ // If either section is absolute, return the other.
+ if (LHS_S == MCSymbol::AbsolutePseudoSection)
+ return RHS_S;
+ if (RHS_S == MCSymbol::AbsolutePseudoSection)
+ return LHS_S;
+
+ // Otherwise, return the first non-null section.
+ return LHS_S ? LHS_S : RHS_S;
+ }
+ }
+
+ assert(0 && "Invalid assembly expression kind!");
+ return 0;
+}
Modified: llvm/trunk/lib/Target/ARM/ARMMCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMMCExpr.h?rev=130517&r1=130516&r2=130517&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMMCExpr.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMMCExpr.h Fri Apr 29 13:00:03 2011
@@ -60,6 +60,9 @@
bool EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const;
void AddValueSymbols(MCAssembler *) const;
+ const MCSection *FindAssociatedSection() const {
+ return getSubExpr()->FindAssociatedSection();
+ }
static bool classof(const MCExpr *E) {
return E->getKind() == MCExpr::Target;
More information about the llvm-commits
mailing list