MCFragment: Refactor LEB

* Deduplicate creation of SLEB128/ULEB128 with makeLEB.
* Call newFragment to prepare for removing getOrCreateDataFragment.
This commit is contained in:
Fangrui Song
2025-07-19 09:59:27 -07:00
parent 64220357b4
commit ecf0cbda18
2 changed files with 10 additions and 10 deletions

View File

@@ -443,6 +443,12 @@ public:
}
//== FT_LEB functions
void makeLEB(bool IsSigned, const MCExpr *Value) {
assert(Kind == FT_Data);
Kind = MCFragment::FT_LEB;
u.leb.IsSigned = IsSigned;
u.leb.Value = Value;
}
const MCExpr &getLEBValue() const {
assert(Kind == FT_LEB);
return *u.leb.Value;
@@ -455,10 +461,6 @@ public:
assert(Kind == FT_LEB);
return u.leb.IsSigned;
}
void setLEBSigned(bool S) {
assert(Kind == FT_LEB);
u.leb.IsSigned = S;
}
//== FT_DwarfFrame functions
const MCExpr &getDwarfAddrDelta() const {

View File

@@ -215,9 +215,8 @@ void MCObjectStreamer::emitULEB128Value(const MCExpr *Value) {
return;
}
auto *F = getOrCreateDataFragment();
F->Kind = MCFragment::FT_LEB;
F->setLEBSigned(false);
F->setLEBValue(Value);
F->makeLEB(false, Value);
newFragment();
}
void MCObjectStreamer::emitSLEB128Value(const MCExpr *Value) {
@@ -227,9 +226,8 @@ void MCObjectStreamer::emitSLEB128Value(const MCExpr *Value) {
return;
}
auto *F = getOrCreateDataFragment();
F->Kind = MCFragment::FT_LEB;
F->setLEBSigned(true);
F->setLEBValue(Value);
F->makeLEB(true, Value);
newFragment();
}
void MCObjectStreamer::emitWeakReference(MCSymbol *Alias,