2015-11-09 12:07:48 +08:00
|
|
|
//===-- HexagonMCExpr.cpp - Hexagon specific MC expression classes
|
|
|
|
//----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "HexagonMCExpr.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
2016-02-16 02:42:07 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2017-02-07 03:35:46 +08:00
|
|
|
#include "llvm/MC/MCSymbolELF.h"
|
2015-11-09 12:07:48 +08:00
|
|
|
#include "llvm/MC/MCValue.h"
|
2017-02-07 03:35:46 +08:00
|
|
|
#include "llvm/Object/ELF.h"
|
2015-11-09 12:07:48 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "hexagon-mcexpr"
|
|
|
|
|
2016-02-16 02:47:55 +08:00
|
|
|
HexagonMCExpr *HexagonMCExpr::create(MCExpr const *Expr, MCContext &Ctx) {
|
2016-02-16 02:42:07 +08:00
|
|
|
return new (Ctx) HexagonMCExpr(Expr);
|
2015-11-09 12:07:48 +08:00
|
|
|
}
|
|
|
|
|
2016-02-16 02:42:07 +08:00
|
|
|
bool HexagonMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
|
|
|
|
MCAsmLayout const *Layout,
|
|
|
|
MCFixup const *Fixup) const {
|
2015-11-09 12:07:48 +08:00
|
|
|
return Expr->evaluateAsRelocatable(Res, Layout, Fixup);
|
|
|
|
}
|
|
|
|
|
2016-02-16 02:42:07 +08:00
|
|
|
void HexagonMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
|
|
|
|
Streamer.visitUsedExpr(*Expr);
|
|
|
|
}
|
2015-11-09 12:07:48 +08:00
|
|
|
|
2016-02-16 02:42:07 +08:00
|
|
|
MCFragment *llvm::HexagonMCExpr::findAssociatedFragment() const {
|
2015-11-09 12:07:48 +08:00
|
|
|
return Expr->findAssociatedFragment();
|
|
|
|
}
|
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
|
|
|
|
switch (Expr->getKind()) {
|
|
|
|
case MCExpr::Target:
|
|
|
|
llvm_unreachable("Cannot handle nested target MCExpr");
|
|
|
|
break;
|
|
|
|
case MCExpr::Constant:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCExpr::Binary: {
|
|
|
|
const MCBinaryExpr *be = cast<MCBinaryExpr>(Expr);
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(be->getLHS(), Asm);
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(be->getRHS(), Asm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MCExpr::SymbolRef: {
|
|
|
|
const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(Expr);
|
|
|
|
switch (symRef.getKind()) {
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
case MCSymbolRefExpr::VK_Hexagon_GD_GOT:
|
|
|
|
case MCSymbolRefExpr::VK_Hexagon_LD_GOT:
|
|
|
|
case MCSymbolRefExpr::VK_Hexagon_GD_PLT:
|
|
|
|
case MCSymbolRefExpr::VK_Hexagon_LD_PLT:
|
|
|
|
case MCSymbolRefExpr::VK_Hexagon_IE:
|
|
|
|
case MCSymbolRefExpr::VK_Hexagon_IE_GOT:
|
|
|
|
case MCSymbolRefExpr::VK_TPREL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MCExpr::Unary:
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexagonMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
|
|
|
|
auto expr = getExpr();
|
|
|
|
fixELFSymbolsInTLSFixupsImpl(expr, Asm);
|
|
|
|
}
|
2016-02-16 02:42:07 +08:00
|
|
|
|
|
|
|
MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
|
2015-11-09 12:07:48 +08:00
|
|
|
|
2016-02-16 02:42:07 +08:00
|
|
|
void HexagonMCExpr::setMustExtend(bool Val) {
|
|
|
|
assert((!Val || !MustNotExtend) && "Extension contradiction");
|
|
|
|
MustExtend = Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HexagonMCExpr::mustExtend() const { return MustExtend; }
|
|
|
|
void HexagonMCExpr::setMustNotExtend(bool Val) {
|
|
|
|
assert((!Val || !MustExtend) && "Extension contradiction");
|
|
|
|
MustNotExtend = Val;
|
|
|
|
}
|
|
|
|
bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; }
|
2015-11-09 12:07:48 +08:00
|
|
|
|
2017-05-03 02:19:11 +08:00
|
|
|
bool HexagonMCExpr::s27_2_reloc() const { return S27_2_reloc; }
|
|
|
|
void HexagonMCExpr::setS27_2_reloc(bool Val) {
|
|
|
|
S27_2_reloc = Val;
|
2016-02-17 04:38:17 +08:00
|
|
|
}
|
|
|
|
|
2016-02-16 02:42:07 +08:00
|
|
|
bool HexagonMCExpr::classof(MCExpr const *E) {
|
2015-11-09 12:07:48 +08:00
|
|
|
return E->getKind() == MCExpr::Target;
|
|
|
|
}
|
|
|
|
|
2016-02-16 02:42:07 +08:00
|
|
|
HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
|
2017-05-03 02:19:11 +08:00
|
|
|
: Expr(Expr), MustNotExtend(false), MustExtend(false), S27_2_reloc(false),
|
2016-03-01 04:42:25 +08:00
|
|
|
SignMismatch(false) {}
|
2015-11-09 12:07:48 +08:00
|
|
|
|
2016-02-16 02:42:07 +08:00
|
|
|
void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
2015-11-09 12:07:48 +08:00
|
|
|
Expr->print(OS, MAI);
|
|
|
|
}
|
2016-03-01 03:17:56 +08:00
|
|
|
|
|
|
|
void HexagonMCExpr::setSignMismatch(bool Val) {
|
|
|
|
SignMismatch = Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HexagonMCExpr::signMismatch() const {
|
|
|
|
return SignMismatch;
|
2017-02-07 03:35:46 +08:00
|
|
|
}
|