Skip to content

Commit 111cc47

Browse files
committed
[AVR] Rename VariantKind to Specifier
Follow the X86, Mips, and RISCV renaming. > "Relocation modifier" suggests adjustments happen during the linker's relocation step rather than the assembler's expression evaluation. > "Relocation specifier" is clear, aligns with Arm and IBM AIX's documentation, and fits the assembler's role seamlessly. In addition, rename *MCExpr::getKind, which confusingly shadows the base class getKind.
1 parent 910f7f4 commit 111cc47

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
lines changed

llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ bool AVRAsmParser::tryParseExpression(OperandVector &Operands, int64_t offset) {
447447

448448
bool AVRAsmParser::tryParseRelocExpression(OperandVector &Operands) {
449449
bool isNegated = false;
450-
AVRMCExpr::VariantKind ModifierKind = AVRMCExpr::VK_AVR_NONE;
450+
AVRMCExpr::Specifier ModifierKind = AVRMCExpr::VK_AVR_NONE;
451451

452452
SMLoc S = Parser.getTok().getLoc();
453453

@@ -471,15 +471,15 @@ bool AVRAsmParser::tryParseRelocExpression(OperandVector &Operands) {
471471
return true;
472472
}
473473
StringRef ModifierName = Parser.getTok().getString();
474-
ModifierKind = AVRMCExpr::getKindByName(ModifierName);
474+
ModifierKind = AVRMCExpr::parseSpecifier(ModifierName);
475475

476476
if (ModifierKind != AVRMCExpr::VK_AVR_NONE) {
477477
Parser.Lex();
478478
Parser.Lex(); // Eat modifier name and parenthesis
479479
if (Parser.getTok().getString() == GENERATE_STUBS &&
480480
Parser.getTok().getKind() == AsmToken::Identifier) {
481481
std::string GSModName = ModifierName.str() + "_" + GENERATE_STUBS;
482-
ModifierKind = AVRMCExpr::getKindByName(GSModName);
482+
ModifierKind = AVRMCExpr::parseSpecifier(GSModName);
483483
if (ModifierKind != AVRMCExpr::VK_AVR_NONE)
484484
Parser.Lex(); // Eat gs modifier name
485485
}
@@ -705,17 +705,16 @@ ParseStatus AVRAsmParser::parseLiteralValues(unsigned SizeInBytes, SMLoc L) {
705705
if (Parser.getTok().getKind() == AsmToken::Identifier &&
706706
Parser.getLexer().peekTok().getKind() == AsmToken::LParen) {
707707
StringRef ModifierName = Parser.getTok().getString();
708-
AVRMCExpr::VariantKind ModifierKind =
709-
AVRMCExpr::getKindByName(ModifierName);
710-
if (ModifierKind != AVRMCExpr::VK_AVR_NONE) {
708+
AVRMCExpr::Specifier Spec = AVRMCExpr::parseSpecifier(ModifierName);
709+
if (Spec != AVRMCExpr::VK_AVR_NONE) {
711710
Parser.Lex();
712711
Parser.Lex(); // Eat the modifier and parenthesis
713712
} else {
714713
return Error(Parser.getTok().getLoc(), "unknown modifier");
715714
}
716715
MCSymbol *Symbol =
717716
getContext().getOrCreateSymbol(Parser.getTok().getString());
718-
AVRStreamer.emitValueForModiferKind(Symbol, SizeInBytes, L, ModifierKind);
717+
AVRStreamer.emitValueForModiferKind(Symbol, SizeInBytes, L, Spec);
719718
Lex(); // Eat the symbol name.
720719
if (parseToken(AsmToken::RParen))
721720
return ParseStatus::Failure;

llvm/lib/Target/AVR/MCTargetDesc/AVRELFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ unsigned AVRELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
4040
const unsigned Kind = Fixup.getTargetKind();
4141
if (Kind >= FirstLiteralRelocationKind)
4242
return Kind - FirstLiteralRelocationKind;
43-
auto Modifier = AVRMCExpr::VariantKind(Target.getAccessVariant());
43+
auto Modifier = AVRMCExpr::Specifier(Target.getAccessVariant());
4444
switch ((unsigned)Fixup.getKind()) {
4545
case FK_Data_1:
4646
switch (Modifier) {

llvm/lib/Target/AVR/MCTargetDesc/AVRMCELFStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ using namespace llvm;
2222

2323
void AVRMCELFStreamer::emitValueForModiferKind(
2424
const MCSymbol *Sym, unsigned SizeInBytes, SMLoc Loc,
25-
AVRMCExpr::VariantKind ModifierKind) {
26-
AVRMCExpr::VariantKind Kind = AVRMCExpr::VK_AVR_NONE;
25+
AVRMCExpr::Specifier ModifierKind) {
26+
AVRMCExpr::Specifier Kind = AVRMCExpr::VK_AVR_NONE;
2727
if (ModifierKind == AVRMCExpr::VK_AVR_NONE) {
2828
Kind = AVRMCExpr::VK_DIFF8;
2929
if (SizeInBytes == SIZE_LONG)

llvm/lib/Target/AVR/MCTargetDesc/AVRMCELFStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AVRMCELFStreamer : public MCELFStreamer {
4343

4444
void emitValueForModiferKind(
4545
const MCSymbol *Sym, unsigned SizeInBytes, SMLoc Loc = SMLoc(),
46-
AVRMCExpr::VariantKind ModifierKind = AVRMCExpr::VK_AVR_NONE);
46+
AVRMCExpr::Specifier ModifierKind = AVRMCExpr::VK_AVR_NONE);
4747
};
4848

4949
MCStreamer *createAVRELFStreamer(Triple const &TT, MCContext &Context,

llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace {
1919

2020
const struct ModifierEntry {
2121
const char *const Spelling;
22-
AVRMCExpr::VariantKind VariantKind;
22+
AVRMCExpr::Specifier specifier;
2323
} ModifierNames[] = {
2424
{"lo8", AVRMCExpr::VK_LO8}, {"hi8", AVRMCExpr::VK_HI8},
2525
{"hh8", AVRMCExpr::VK_HH8}, // synonym with hlo8
@@ -34,13 +34,13 @@ const struct ModifierEntry {
3434

3535
} // end of anonymous namespace
3636

37-
const AVRMCExpr *AVRMCExpr::create(VariantKind Kind, const MCExpr *Expr,
37+
const AVRMCExpr *AVRMCExpr::create(Specifier Kind, const MCExpr *Expr,
3838
bool Negated, MCContext &Ctx) {
3939
return new (Ctx) AVRMCExpr(Kind, Expr, Negated);
4040
}
4141

4242
void AVRMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
43-
assert(Kind != VK_AVR_NONE);
43+
assert(specifier != VK_AVR_NONE);
4444
OS << getName() << '(';
4545
if (isNegated())
4646
OS << '-' << '(';
@@ -85,7 +85,7 @@ bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
8585
MCSymbolRefExpr::VariantKind Modifier = Sym->getKind();
8686
if (Modifier != MCSymbolRefExpr::VK_None)
8787
return false;
88-
if (Kind == VK_PM) {
88+
if (specifier == VK_PM) {
8989
Modifier = MCSymbolRefExpr::VariantKind(AVRMCExpr::VK_PM);
9090
}
9191

@@ -100,7 +100,7 @@ int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
100100
if (Negated)
101101
Value *= -1;
102102

103-
switch (Kind) {
103+
switch (specifier) {
104104
case AVRMCExpr::VK_LO8:
105105
Value &= 0xff;
106106
break;
@@ -147,7 +147,7 @@ int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
147147
AVR::Fixups AVRMCExpr::getFixupKind() const {
148148
AVR::Fixups Kind = AVR::Fixups::LastTargetFixupKind;
149149

150-
switch (getKind()) {
150+
switch (specifier) {
151151
case VK_LO8:
152152
Kind = isNegated() ? AVR::fixup_lo8_ldi_neg : AVR::fixup_lo8_ldi;
153153
break;
@@ -195,7 +195,7 @@ void AVRMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
195195
const char *AVRMCExpr::getName() const {
196196
const auto &Modifier =
197197
llvm::find_if(ModifierNames, [this](ModifierEntry const &Mod) {
198-
return Mod.VariantKind == Kind;
198+
return Mod.specifier == specifier;
199199
});
200200

201201
if (Modifier != std::end(ModifierNames)) {
@@ -204,14 +204,14 @@ const char *AVRMCExpr::getName() const {
204204
return nullptr;
205205
}
206206

207-
AVRMCExpr::VariantKind AVRMCExpr::getKindByName(StringRef Name) {
207+
AVRMCExpr::Specifier AVRMCExpr::parseSpecifier(StringRef Name) {
208208
const auto &Modifier =
209209
llvm::find_if(ModifierNames, [&Name](ModifierEntry const &Mod) {
210210
return Mod.Spelling == Name;
211211
});
212212

213213
if (Modifier != std::end(ModifierNames)) {
214-
return Modifier->VariantKind;
214+
return Modifier->specifier;
215215
}
216216
return VK_AVR_NONE;
217217
}

llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ namespace llvm {
1919
class AVRMCExpr : public MCTargetExpr {
2020
public:
2121
/// Specifies the type of an expression.
22-
enum VariantKind {
22+
enum Specifier {
2323
VK_None,
2424

25-
// While not strictly necessary, start at a larger number to avoid confusion
26-
// with MCSymbolRefExpr::VariantKind.
27-
VK_AVR_NONE = 100,
25+
VK_AVR_NONE = MCSymbolRefExpr::FirstTargetSpecifier,
2826

2927
VK_HI8, ///< Corresponds to `hi8()`.
3028
VK_LO8, ///< Corresponds to `lo8()`.
@@ -47,11 +45,11 @@ class AVRMCExpr : public MCTargetExpr {
4745

4846
public:
4947
/// Creates an AVR machine code expression.
50-
static const AVRMCExpr *create(VariantKind Kind, const MCExpr *Expr,
48+
static const AVRMCExpr *create(Specifier S, const MCExpr *Expr,
5149
bool isNegated, MCContext &Ctx);
5250

5351
/// Gets the type of the expression.
54-
VariantKind getKind() const { return Kind; }
52+
Specifier getSpecifier() const { return specifier; }
5553
/// Gets the name of the expression.
5654
const char *getName() const;
5755
const MCExpr *getSubExpr() const { return SubExpr; }
@@ -77,18 +75,18 @@ class AVRMCExpr : public MCTargetExpr {
7775
}
7876

7977
public:
80-
static VariantKind getKindByName(StringRef Name);
78+
static Specifier parseSpecifier(StringRef Name);
8179

8280
private:
8381
int64_t evaluateAsInt64(int64_t Value) const;
8482

85-
const VariantKind Kind;
83+
const Specifier specifier;
8684
const MCExpr *SubExpr;
8785
bool Negated;
8886

8987
private:
90-
explicit AVRMCExpr(VariantKind Kind, const MCExpr *Expr, bool Negated)
91-
: Kind(Kind), SubExpr(Expr), Negated(Negated) {}
88+
explicit AVRMCExpr(Specifier S, const MCExpr *Expr, bool Negated)
89+
: specifier(S), SubExpr(Expr), Negated(Negated) {}
9290
~AVRMCExpr() = default;
9391
};
9492

0 commit comments

Comments
 (0)