Skip to content

Commit a02afb0

Browse files
committed
AVR: Migrate to the new relocation specifier representation
Define printImpl and evaluateAsRelocationImpl within AVRMCAsmInfo.
1 parent 602c308 commit a02afb0

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ AVR::Fixups AVRMCExpr::getFixupKind() const {
116116
return Kind;
117117
}
118118

119+
void AVRMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
120+
const MCSpecifierExpr &Expr) const {
121+
auto &E = static_cast<const AVRMCExpr &>(Expr);
122+
assert(E.getSpecifier() != AVR::S_AVR_NONE);
123+
OS << E.getName() << '(';
124+
if (E.isNegated())
125+
OS << '-' << '(';
126+
printExpr(OS, *E.getSubExpr());
127+
if (E.isNegated())
128+
OS << ')';
129+
OS << ')';
130+
}
131+
119132
int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
120133
if (Negated)
121134
Value *= -1;
@@ -164,15 +177,19 @@ int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
164177
return static_cast<uint64_t>(Value) & 0xff;
165178
}
166179

167-
bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
168-
const MCAssembler *Asm) const {
180+
// bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
181+
// const MCAssembler *Asm) const {
182+
bool AVRMCAsmInfo::evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr,
183+
MCValue &Result,
184+
const MCAssembler *Asm) const {
185+
auto &E = static_cast<const AVRMCExpr &>(Expr);
169186
MCValue Value;
170-
bool isRelocatable = getSubExpr()->evaluateAsRelocatable(Value, Asm);
187+
bool isRelocatable = E.getSubExpr()->evaluateAsRelocatable(Value, Asm);
171188
if (!isRelocatable)
172189
return false;
173190

174191
if (Value.isAbsolute()) {
175-
Result = MCValue::get(evaluateAsInt64(Value.getConstant()));
192+
Result = MCValue::get(E.evaluateAsInt64(Value.getConstant()));
176193
} else {
177194
if (!Asm || !Asm->hasLayout())
178195
return false;
@@ -181,7 +198,7 @@ bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
181198
if (Value.getSpecifier() != MCSymbolRefExpr::VK_None)
182199
return false;
183200
assert(!Value.getSubSym());
184-
if (specifier == AVR::S_PM)
201+
if (E.getSpecifier() == AVR::S_PM)
185202
Spec = AVR::S_PM;
186203

187204
// TODO: don't attach specifier to MCSymbolRefExpr.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class Triple;
2525
class AVRMCAsmInfo : public MCAsmInfo {
2626
public:
2727
explicit AVRMCAsmInfo(const Triple &TT, const MCTargetOptions &Options);
28+
void printSpecifierExpr(raw_ostream &OS,
29+
const MCSpecifierExpr &Expr) const override;
30+
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res,
31+
const MCAssembler *Asm) const override;
2832
};
2933

3034
namespace AVR {

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,4 @@ const AVRMCExpr *AVRMCExpr::create(Specifier Kind, const MCExpr *Expr,
2121
return new (Ctx) AVRMCExpr(Kind, Expr, Negated);
2222
}
2323

24-
void AVRMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
25-
assert(specifier != AVR::S_AVR_NONE);
26-
OS << getName() << '(';
27-
if (isNegated())
28-
OS << '-' << '(';
29-
MAI->printExpr(OS, *getSubExpr());
30-
if (isNegated())
31-
OS << ')';
32-
OS << ')';
33-
}
34-
3524
} // namespace llvm

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace llvm {
1818
/// A expression in AVR machine code.
1919
class AVRMCExpr : public MCSpecifierExpr {
2020
public:
21+
friend class AVRMCAsmInfo;
2122
using Specifier = Spec;
2223
/// Specifies the type of an expression.
2324

@@ -36,10 +37,6 @@ class AVRMCExpr : public MCSpecifierExpr {
3637
bool isNegated() const { return Negated; }
3738
void setNegated(bool negated = true) { Negated = negated; }
3839

39-
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
40-
bool evaluateAsRelocatableImpl(MCValue &Res,
41-
const MCAssembler *Asm) const override;
42-
4340
public:
4441
static Specifier parseSpecifier(StringRef Name);
4542

0 commit comments

Comments
 (0)