summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2011-04-29 18:00:03 +0000
committerDaniel Dunbar <daniel@zuster.org>2011-04-29 18:00:03 +0000
commitdc3e4cc5ed6ab5d92a4fef429eec1a688b08d913 (patch)
tree1080897f2cddd21923fb1076e9215becf8669488 /llvm/lib/MC
parent252e8f9ac1cd15410f3cc13fc29dbaaa2de40678 (diff)
downloadbcm5719-llvm-dc3e4cc5ed6ab5d92a4fef429eec1a688b08d913.tar.gz
bcm5719-llvm-dc3e4cc5ed6ab5d92a4fef429eec1a688b08d913.zip
MCExpr: Add FindAssociatedSection, which attempts to mirror the 'as' semantics
that associate sections with expressions. llvm-svn: 130517
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/MCExpr.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 312621509fe..3a674d75ed7 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -559,3 +559,45 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
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;
+}
OpenPOWER on IntegriCloud