Given target assembler parsers a chance to handle variant expressions

first. Use this to turn the PPC modifiers into PPC specific expressions,
allowing them to work on constants.

llvm-svn: 189400
This commit is contained in:
Joerg Sonnenberger 2013-08-27 20:23:19 +00:00
parent 06fbed03fc
commit b822af4721
6 changed files with 49 additions and 3 deletions

View File

@ -11,6 +11,7 @@
#define LLVM_MC_TARGETPARSER_H
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
#include "llvm/MC/MCExpr.h"
namespace llvm {
class MCStreamer;
@ -174,6 +175,12 @@ public:
virtual void convertToMapAndConstraints(unsigned Kind,
const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
MCSymbolRefExpr::VariantKind,
MCContext &Ctx) {
return 0;
}
};
} // End llvm namespace

View File

@ -896,6 +896,10 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
const MCExpr *
AsmParser::ApplyModifierToExpr(const MCExpr *E,
MCSymbolRefExpr::VariantKind Variant) {
// Ask the target implementation about this expression first.
const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
if (NewE)
return NewE;
// Recurse over the given expression, rebuilding it to apply the given variant
// if there is exactly one symbol.
switch (E->getKind()) {

View File

@ -235,6 +235,10 @@ public:
virtual bool ParseDirective(AsmToken DirectiveID);
unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
MCSymbolRefExpr::VariantKind,
MCContext &Ctx);
};
/// PPCOperand - Instances of this class represent a parsed PowerPC machine
@ -1363,3 +1367,26 @@ unsigned PPCAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
return Match_InvalidOperand;
}
const MCExpr *
PPCAsmParser::applyModifierToExpr(const MCExpr *E,
MCSymbolRefExpr::VariantKind Variant,
MCContext &Ctx) {
switch (Variant) {
case MCSymbolRefExpr::VK_PPC_LO:
return PPCMCExpr::Create(PPCMCExpr::VK_PPC_LO, E, false, Ctx);
case MCSymbolRefExpr::VK_PPC_HI:
return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HI, E, false, Ctx);
case MCSymbolRefExpr::VK_PPC_HA:
return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HA, E, false, Ctx);
case MCSymbolRefExpr::VK_PPC_HIGHER:
return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHER, E, false, Ctx);
case MCSymbolRefExpr::VK_PPC_HIGHERA:
return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHERA, E, false, Ctx);
case MCSymbolRefExpr::VK_PPC_HIGHEST:
return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHEST, E, false, Ctx);
case MCSymbolRefExpr::VK_PPC_HIGHESTA:
return PPCMCExpr::Create(PPCMCExpr::VK_PPC_HIGHESTA, E, false, Ctx);
default:
return 0;
}
}

View File

@ -54,7 +54,7 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const {
MCValue Value;
if (!getSubExpr()->EvaluateAsRelocatable(Value, *Layout))
if (Layout && !getSubExpr()->EvaluateAsRelocatable(Value, *Layout))
return false;
if (Value.isAbsolute()) {
@ -85,7 +85,7 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
break;
}
Res = MCValue::get(Result);
} else {
} else if (Layout) {
MCContext &Context = Layout->getAssembler().getContext();
const MCSymbolRefExpr *Sym = Value.getSymA();
MCSymbolRefExpr::VariantKind Modifier = Sym->getKind();
@ -118,7 +118,8 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
}
Sym = MCSymbolRefExpr::Create(&Sym->getSymbol(), Modifier, Context);
Res = MCValue::get(Sym, Value.getSymB(), Value.getConstant());
}
} else
return false;
return true;
}

View File

@ -96,3 +96,6 @@
# CHECK-NEXT: ld 1, 32768(2)
ld 1, 32768(2)
# CHECK: error: invalid modifier 'got' (no symbols present)
addi 4, 3, 123@got
# CHECK-NEXT: addi 4, 3, 123@got

View File

@ -442,3 +442,7 @@ base:
# CHECK-REL: 0x{{[0-9A-F]*[08]}} R_PPC64_DTPREL64 target 0x0
.quad target@dtprel
# Constant fixup
ori 1, 2, 131071@l
# CHECK: ori 1, 2, 131071@l # encoding: [0x60,0x41,A,A]
# CHECK-NEXT: # fixup A - offset: 2, value: 131071@l, kind: fixup_ppc_half16