Skip to content

Commit d89084c

Browse files
committed
MCAssembler: Add reportError to simplify getContext().reportError
1 parent fe32806 commit d89084c

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ class MCAssembler {
229229
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F,
230230
uint64_t FSize) const;
231231

232+
void reportError(SMLoc L, const Twine &Msg) const;
233+
232234
void dump() const;
233235
};
234236

llvm/lib/MC/MCAssembler.cpp

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ bool MCAssembler::evaluateFixup(const MCFragment *DF, const MCFixup &Fixup,
154154
// On error claim to have completely evaluated the fixup, to prevent any
155155
// further processing from being done.
156156
const MCExpr *Expr = Fixup.getValue();
157-
MCContext &Ctx = getContext();
158157
Value = 0;
159158
if (!Expr->evaluateAsRelocatable(Target, this)) {
160-
Ctx.reportError(Fixup.getLoc(), "expected relocatable expression");
159+
reportError(Fixup.getLoc(), "expected relocatable expression");
161160
return true;
162161
}
163162

@@ -218,13 +217,12 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
218217
auto &FF = cast<MCFillFragment>(F);
219218
int64_t NumValues = 0;
220219
if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *this)) {
221-
getContext().reportError(FF.getLoc(),
222-
"expected assembly-time absolute expression");
220+
reportError(FF.getLoc(), "expected assembly-time absolute expression");
223221
return 0;
224222
}
225223
int64_t Size = NumValues * FF.getValueSize();
226224
if (Size < 0) {
227-
getContext().reportError(FF.getLoc(), "invalid number of bytes");
225+
reportError(FF.getLoc(), "invalid number of bytes");
228226
return 0;
229227
}
230228
return Size;
@@ -268,26 +266,25 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
268266
const MCOrgFragment &OF = cast<MCOrgFragment>(F);
269267
MCValue Value;
270268
if (!OF.getOffset().evaluateAsValue(Value, *this)) {
271-
getContext().reportError(OF.getLoc(),
272-
"expected assembly-time absolute expression");
273-
return 0;
269+
reportError(OF.getLoc(), "expected assembly-time absolute expression");
270+
return 0;
274271
}
275272

276273
uint64_t FragmentOffset = getFragmentOffset(OF);
277274
int64_t TargetLocation = Value.getConstant();
278275
if (const auto *SA = Value.getAddSym()) {
279276
uint64_t Val;
280277
if (!getSymbolOffset(*SA, Val)) {
281-
getContext().reportError(OF.getLoc(), "expected absolute expression");
278+
reportError(OF.getLoc(), "expected absolute expression");
282279
return 0;
283280
}
284281
TargetLocation += Val;
285282
}
286283
int64_t Size = TargetLocation - FragmentOffset;
287284
if (Size < 0 || Size >= 0x40000000) {
288-
getContext().reportError(
289-
OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
290-
"' (at offset '" + Twine(FragmentOffset) + "')");
285+
reportError(OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
286+
"' (at offset '" + Twine(FragmentOffset) +
287+
"')");
291288
return 0;
292289
}
293290
return Size;
@@ -481,17 +478,15 @@ const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
481478
const MCExpr *Expr = Symbol.getVariableValue();
482479
MCValue Value;
483480
if (!Expr->evaluateAsValue(Value, *this)) {
484-
getContext().reportError(Expr->getLoc(),
485-
"expression could not be evaluated");
481+
reportError(Expr->getLoc(), "expression could not be evaluated");
486482
return nullptr;
487483
}
488484

489485
const MCSymbol *SymB = Value.getSubSym();
490486
if (SymB) {
491-
getContext().reportError(
492-
Expr->getLoc(),
493-
Twine("symbol '") + SymB->getName() +
494-
"' could not be evaluated in a subtraction expression");
487+
reportError(Expr->getLoc(),
488+
Twine("symbol '") + SymB->getName() +
489+
"' could not be evaluated in a subtraction expression");
495490
return nullptr;
496491
}
497492

@@ -501,9 +496,8 @@ const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
501496

502497
const MCSymbol &ASym = *A;
503498
if (ASym.isCommon()) {
504-
getContext().reportError(Expr->getLoc(),
505-
"Common symbol '" + ASym.getName() +
506-
"' cannot be used in assignment expr");
499+
reportError(Expr->getLoc(), "Common symbol '" + ASym.getName() +
500+
"' cannot be used in assignment expr");
507501
return nullptr;
508502
}
509503

@@ -690,8 +684,7 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
690684
assert(ControlledNopLength >= 0 && "Expected non-negative NOP size");
691685

692686
if (ControlledNopLength > MaximumNopLength) {
693-
Asm.getContext().reportError(NF.getLoc(),
694-
"illegal NOP size " +
687+
Asm.reportError(NF.getLoc(), "illegal NOP size " +
695688
std::to_string(ControlledNopLength) +
696689
". (expected within [0, " +
697690
std::to_string(MaximumNopLength) + "])");
@@ -800,15 +793,13 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
800793
// directives to fill the contents of virtual sections.
801794
const MCDataFragment &DF = cast<MCDataFragment>(F);
802795
if (DF.getFixups().size())
803-
getContext().reportError(SMLoc(), Sec->getVirtualSectionKind() +
804-
" section '" + Sec->getName() +
805-
"' cannot have fixups");
796+
reportError(SMLoc(), Sec->getVirtualSectionKind() + " section '" +
797+
Sec->getName() + "' cannot have fixups");
806798
for (char C : DF.getContents())
807799
if (C) {
808-
getContext().reportError(SMLoc(),
809-
Sec->getVirtualSectionKind() +
810-
" section '" + Sec->getName() +
811-
"' cannot have non-zero initializers");
800+
reportError(SMLoc(), Sec->getVirtualSectionKind() + " section '" +
801+
Sec->getName() +
802+
"' cannot have non-zero initializers");
812803
break;
813804
}
814805
break;
@@ -1050,9 +1041,9 @@ bool MCAssembler::relaxLEB(MCLEBFragment &LF) {
10501041
bool Relaxed, UseZeroPad;
10511042
std::tie(Relaxed, UseZeroPad) = getBackend().relaxLEB128(LF, Value);
10521043
if (!Relaxed) {
1053-
getContext().reportError(LF.getValue().getLoc(),
1054-
Twine(LF.isSigned() ? ".s" : ".u") +
1055-
"leb128 expression is not absolute");
1044+
reportError(LF.getValue().getLoc(),
1045+
Twine(LF.isSigned() ? ".s" : ".u") +
1046+
"leb128 expression is not absolute");
10561047
LF.setValue(MCConstantExpr::create(0, Context));
10571048
}
10581049
uint8_t Tmp[10]; // maximum size: ceil(64/7)
@@ -1165,8 +1156,8 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCDwarfCallFrameFragment &DF) {
11651156
int64_t Value;
11661157
bool Abs = DF.getAddrDelta().evaluateAsAbsolute(Value, *this);
11671158
if (!Abs) {
1168-
getContext().reportError(DF.getAddrDelta().getLoc(),
1169-
"invalid CFI advance_loc expression");
1159+
reportError(DF.getAddrDelta().getLoc(),
1160+
"invalid CFI advance_loc expression");
11701161
DF.setAddrDelta(MCConstantExpr::create(0, Context));
11711162
return false;
11721163
}
@@ -1244,6 +1235,10 @@ bool MCAssembler::layoutOnce() {
12441235
return Changed;
12451236
}
12461237

1238+
void MCAssembler::reportError(SMLoc L, const Twine &Msg) const {
1239+
getContext().reportError(L, Msg);
1240+
}
1241+
12471242
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
12481243
LLVM_DUMP_METHOD void MCAssembler::dump() const{
12491244
raw_ostream &OS = errs();

0 commit comments

Comments
 (0)