File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class MCAsmInfo;
19
19
class MCAsmLayout ;
20
20
class MCAssembler ;
21
21
class MCContext ;
22
+ class MCSection ;
22
23
class MCSectionData ;
23
24
class MCSymbol ;
24
25
class MCValue ;
@@ -92,6 +93,12 @@ class MCExpr {
92
93
// / @result - True on success.
93
94
bool EvaluateAsRelocatable (MCValue &Res, const MCAsmLayout &Layout) const ;
94
95
96
+ // / FindAssociatedSection - Find the "associated section" for this expression,
97
+ // / which is currently defined as the absolute section for constants, or
98
+ // / otherwise the section associated with the first defined symbol in the
99
+ // / expression.
100
+ const MCSection *FindAssociatedSection () const ;
101
+
95
102
// / @}
96
103
97
104
static bool classof (const MCExpr *) { return true ; }
@@ -420,6 +427,7 @@ class MCTargetExpr : public MCExpr {
420
427
virtual bool EvaluateAsRelocatableImpl (MCValue &Res,
421
428
const MCAsmLayout *Layout) const = 0;
422
429
virtual void AddValueSymbols (MCAssembler *) const = 0;
430
+ virtual const MCSection *FindAssociatedSection () const = 0;
423
431
424
432
static bool classof (const MCExpr *E) {
425
433
return E->getKind () == MCExpr::Target;
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ namespace llvm {
56
56
mutable unsigned IsUsed : 1 ;
57
57
58
58
private: // MCContext creates and uniques these.
59
+ friend class MCExpr ;
59
60
friend class MCContext ;
60
61
MCSymbol (StringRef name, bool isTemporary)
61
62
: Name(name), Section(0 ), Value(0 ),
Original file line number Diff line number Diff line change @@ -559,3 +559,45 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
559
559
assert (0 && " Invalid assembly expression kind!" );
560
560
return false ;
561
561
}
562
+
563
+ const MCSection *MCExpr::FindAssociatedSection () const {
564
+ switch (getKind ()) {
565
+ case Target:
566
+ // We never look through target specific expressions.
567
+ return cast<MCTargetExpr>(this )->FindAssociatedSection ();
568
+
569
+ case Constant:
570
+ return MCSymbol::AbsolutePseudoSection;
571
+
572
+ case SymbolRef: {
573
+ const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this );
574
+ const MCSymbol &Sym = SRE->getSymbol ();
575
+
576
+ if (Sym.isDefined ())
577
+ return &Sym.getSection ();
578
+
579
+ return 0 ;
580
+ }
581
+
582
+ case Unary:
583
+ return cast<MCUnaryExpr>(this )->getSubExpr ()->FindAssociatedSection ();
584
+
585
+ case Binary: {
586
+ const MCBinaryExpr *BE = cast<MCBinaryExpr>(this );
587
+ const MCSection *LHS_S = BE->getLHS ()->FindAssociatedSection ();
588
+ const MCSection *RHS_S = BE->getRHS ()->FindAssociatedSection ();
589
+
590
+ // If either section is absolute, return the other.
591
+ if (LHS_S == MCSymbol::AbsolutePseudoSection)
592
+ return RHS_S;
593
+ if (RHS_S == MCSymbol::AbsolutePseudoSection)
594
+ return LHS_S;
595
+
596
+ // Otherwise, return the first non-null section.
597
+ return LHS_S ? LHS_S : RHS_S;
598
+ }
599
+ }
600
+
601
+ assert (0 && " Invalid assembly expression kind!" );
602
+ return 0 ;
603
+ }
Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ class ARMMCExpr : public MCTargetExpr {
60
60
bool EvaluateAsRelocatableImpl (MCValue &Res,
61
61
const MCAsmLayout *Layout) const ;
62
62
void AddValueSymbols (MCAssembler *) const ;
63
+ const MCSection *FindAssociatedSection () const {
64
+ return getSubExpr ()->FindAssociatedSection ();
65
+ }
63
66
64
67
static bool classof (const MCExpr *E) {
65
68
return E->getKind () == MCExpr::Target;
You can’t perform that action at this time.
0 commit comments