MC: Add MCSpecifierExpr::create
as a target-agnostic implementation to replace target-specific XXXMCExpr::create.
This commit is contained in:
@@ -510,12 +510,16 @@ protected:
|
||||
// Target-specific relocation specifier code
|
||||
const Spec specifier;
|
||||
|
||||
public:
|
||||
explicit MCSpecifierExpr(const MCExpr *Expr, Spec S)
|
||||
: MCExpr(Specifier, SMLoc()), Expr(Expr), specifier(S) {}
|
||||
explicit MCSpecifierExpr(const MCExpr *Expr, Spec S, SMLoc Loc = SMLoc())
|
||||
: MCExpr(Specifier, Loc), Expr(Expr), specifier(S) {}
|
||||
virtual ~MCSpecifierExpr() = default;
|
||||
|
||||
public:
|
||||
LLVM_ABI static const MCSpecifierExpr *
|
||||
create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc = SMLoc());
|
||||
LLVM_ABI static const MCSpecifierExpr *
|
||||
create(const MCSymbol *Sym, Spec S, MCContext &Ctx, SMLoc Loc = SMLoc());
|
||||
|
||||
Spec getSpecifier() const { return specifier; }
|
||||
const MCExpr *getSubExpr() const { return Expr; }
|
||||
|
||||
|
||||
@@ -737,6 +737,16 @@ MCFragment *MCExpr::findAssociatedFragment() const {
|
||||
llvm_unreachable("Invalid assembly expression kind!");
|
||||
}
|
||||
|
||||
const MCSpecifierExpr *MCSpecifierExpr::create(const MCExpr *Expr, Spec S,
|
||||
MCContext &Ctx, SMLoc Loc) {
|
||||
return new (Ctx) MCSpecifierExpr(Expr, S, Loc);
|
||||
}
|
||||
|
||||
const MCSpecifierExpr *MCSpecifierExpr::create(const MCSymbol *Sym, Spec S,
|
||||
MCContext &Ctx, SMLoc Loc) {
|
||||
return new (Ctx) MCSpecifierExpr(MCSymbolRefExpr::create(Sym, Ctx), S, Loc);
|
||||
}
|
||||
|
||||
bool MCSpecifierExpr::evaluateAsRelocatableImpl(MCValue &Res,
|
||||
const MCAssembler *Asm) const {
|
||||
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
|
||||
|
||||
@@ -848,14 +848,14 @@ bool SparcAsmParser::expandSETX(MCInst &Inst, SMLoc IDLoc,
|
||||
// sethi %hh(val), tmp
|
||||
Instructions.push_back(MCInstBuilder(SP::SETHIi)
|
||||
.addReg(MCTmpOp.getReg())
|
||||
.addExpr(Sparc::createSpecifierExpr(
|
||||
getContext(), ValExpr, ELF::R_SPARC_HH22)));
|
||||
.addExpr(MCSpecifierExpr::create(
|
||||
ValExpr, ELF::R_SPARC_HH22, getContext())));
|
||||
// or tmp, %hm(val), tmp
|
||||
Instructions.push_back(MCInstBuilder(SP::ORri)
|
||||
.addReg(MCTmpOp.getReg())
|
||||
.addReg(MCTmpOp.getReg())
|
||||
.addExpr(Sparc::createSpecifierExpr(
|
||||
getContext(), ValExpr, ELF::R_SPARC_HM10)));
|
||||
.addExpr(MCSpecifierExpr::create(
|
||||
ValExpr, ELF::R_SPARC_HM10, getContext())));
|
||||
// sllx tmp, 32, tmp
|
||||
Instructions.push_back(MCInstBuilder(SP::SLLXri)
|
||||
.addReg(MCTmpOp.getReg())
|
||||
@@ -1689,7 +1689,7 @@ const SparcMCExpr *SparcAsmParser::adjustPICRelocation(uint16_t RelType,
|
||||
}
|
||||
}
|
||||
|
||||
return Sparc::createSpecifierExpr(getContext(), subExpr, RelType);
|
||||
return MCSpecifierExpr::create(subExpr, RelType, getContext());
|
||||
}
|
||||
|
||||
bool SparcAsmParser::matchSparcAsmModifiers(const MCExpr *&EVal,
|
||||
|
||||
@@ -50,7 +50,7 @@ SparcELFMCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
|
||||
MCStreamer &Streamer) const {
|
||||
if (Encoding & dwarf::DW_EH_PE_pcrel) {
|
||||
MCContext &Ctx = Streamer.getContext();
|
||||
return Sparc::createSpecifierExpr(Ctx, Sym, ELF::R_SPARC_DISP32);
|
||||
return MCSpecifierExpr::create(Sym, ELF::R_SPARC_DISP32, Ctx);
|
||||
}
|
||||
|
||||
return MCAsmInfo::getExprForPersonalitySymbol(Sym, Encoding, Streamer);
|
||||
@@ -62,7 +62,7 @@ SparcELFMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
|
||||
MCStreamer &Streamer) const {
|
||||
if (Encoding & dwarf::DW_EH_PE_pcrel) {
|
||||
MCContext &Ctx = Streamer.getContext();
|
||||
return Sparc::createSpecifierExpr(Ctx, Sym, ELF::R_SPARC_DISP32);
|
||||
return MCSpecifierExpr::create(Sym, ELF::R_SPARC_DISP32, Ctx);
|
||||
}
|
||||
return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer);
|
||||
}
|
||||
|
||||
@@ -22,16 +22,6 @@ using namespace llvm;
|
||||
|
||||
#define DEBUG_TYPE "sparcmcexpr"
|
||||
|
||||
const SparcMCExpr *Sparc::createSpecifierExpr(MCContext &Ctx,
|
||||
const MCExpr *Expr, uint16_t S) {
|
||||
return new (Ctx) MCSpecifierExpr(Expr, S);
|
||||
}
|
||||
|
||||
const SparcMCExpr *Sparc::createSpecifierExpr(MCContext &Ctx,
|
||||
const MCSymbol *Sym, uint16_t S) {
|
||||
return new (Ctx) MCSpecifierExpr(MCSymbolRefExpr::create(Sym, Ctx), S);
|
||||
}
|
||||
|
||||
StringRef Sparc::getSpecifierName(uint16_t S) {
|
||||
// clang-format off
|
||||
switch (uint16_t(S)) {
|
||||
|
||||
@@ -23,10 +23,6 @@ class StringRef;
|
||||
using SparcMCExpr = MCSpecifierExpr;
|
||||
|
||||
namespace Sparc {
|
||||
const SparcMCExpr *createSpecifierExpr(MCContext &Ctx, const MCExpr *Expr,
|
||||
uint16_t S);
|
||||
const SparcMCExpr *createSpecifierExpr(MCContext &Ctx, const MCSymbol *Sym,
|
||||
uint16_t S);
|
||||
uint16_t parseSpecifier(StringRef name);
|
||||
StringRef getSpecifierName(uint16_t S);
|
||||
} // namespace Sparc
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
static MCOperand createSparcMCOperand(uint16_t Kind, MCSymbol *Sym,
|
||||
MCContext &OutContext) {
|
||||
const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Sym, OutContext);
|
||||
const SparcMCExpr *expr = Sparc::createSpecifierExpr(OutContext, MCSym, Kind);
|
||||
const SparcMCExpr *expr = MCSpecifierExpr::create(MCSym, Kind, OutContext);
|
||||
return MCOperand::createExpr(expr);
|
||||
}
|
||||
static MCOperand createPCXCallOP(MCSymbol *Label,
|
||||
@@ -101,7 +101,7 @@ static MCOperand createPCXRelExprOp(uint16_t Spec, MCSymbol *GOTLabel,
|
||||
|
||||
const MCBinaryExpr *Sub = MCBinaryExpr::createSub(Cur, Start, OutContext);
|
||||
const MCBinaryExpr *Add = MCBinaryExpr::createAdd(GOT, Sub, OutContext);
|
||||
const SparcMCExpr *expr = Sparc::createSpecifierExpr(OutContext, Add, Spec);
|
||||
const SparcMCExpr *expr = MCSpecifierExpr::create(Add, Spec, OutContext);
|
||||
return MCOperand::createExpr(expr);
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ MCOperand SparcAsmPrinter::lowerOperand(const MachineOperand &MO) const {
|
||||
|
||||
const MCExpr *expr = MCSymbolRefExpr::create(Symbol, OutContext);
|
||||
if (RelType)
|
||||
expr = Sparc::createSpecifierExpr(OutContext, expr, RelType);
|
||||
expr = MCSpecifierExpr::create(expr, RelType, OutContext);
|
||||
return MCOperand::createExpr(expr);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference(
|
||||
}
|
||||
|
||||
MCContext &Ctx = getContext();
|
||||
return Sparc::createSpecifierExpr(Ctx, SSym, ELF::R_SPARC_DISP32);
|
||||
return MCSpecifierExpr::create(SSym, ELF::R_SPARC_DISP32, Ctx);
|
||||
}
|
||||
|
||||
return TargetLoweringObjectFileELF::getTTypeGlobalReference(GV, Encoding, TM,
|
||||
|
||||
Reference in New Issue
Block a user