summaryrefslogtreecommitdiff
path: root/lib/MC/MCFixup.cpp
blob: e41e67350c5a18bc08f3b9f34cacb7f564980647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//===- MCFixup.cpp - Assembly Fixup Implementation ------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/MC/MCFixup.h"
using namespace llvm;

static MCSymbolRefExpr::VariantKind getAccessVariant(const MCExpr *Expr) {
  switch (Expr->getKind()) {
  case MCExpr::Unary: {
    assert(getAccessVariant(cast<MCUnaryExpr>(Expr)->getSubExpr()) ==
           MCSymbolRefExpr::VK_None);
    return MCSymbolRefExpr::VK_None;
  }

  case MCExpr::Target:
    llvm_unreachable("unsupported");

  case MCExpr::Constant:
    return MCSymbolRefExpr::VK_None;

  case MCExpr::SymbolRef: {
    const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(Expr);
    return SRE->getKind();
  }
  case MCExpr::Binary: {
    const MCBinaryExpr *ABE = cast<MCBinaryExpr>(Expr);
    assert(getAccessVariant(ABE->getRHS()) == MCSymbolRefExpr::VK_None);
    return getAccessVariant(ABE->getLHS());
  }
  }
  llvm_unreachable("unknown MCExpr kind");
}

MCSymbolRefExpr::VariantKind MCFixup::getAccessVariant() const {
  return ::getAccessVariant(getValue());
}