@@ -42,11 +42,10 @@ class raw_ostream;
42
42
class MCSymbol {
43
43
protected:
44
44
// A symbol can be regular, equated to an expression, or a common symbol.
45
- enum Contents : uint8_t {
46
- SymContentsUnset,
47
- SymContentsVariable,
48
- SymContentsCommon,
49
- SymContentsTargetCommon, // Index stores the section index
45
+ enum Kind : uint8_t {
46
+ Regular,
47
+ Equated,
48
+ Common,
50
49
};
51
50
52
51
// Special sentinel value for the absolute pseudo fragment.
@@ -65,6 +64,10 @@ class MCSymbol {
65
64
// / relative to, if any.
66
65
mutable MCFragment *Fragment = nullptr ;
67
66
67
+ // / The symbol kind. Use an unsigned bitfield to achieve better bitpacking
68
+ // / with MSVC.
69
+ unsigned kind : 2 ;
70
+
68
71
// / True if this symbol is named. A named symbol will have a pointer to the
69
72
// / name allocated in the bytes immediately prior to the MCSymbol.
70
73
unsigned HasName : 1 ;
@@ -95,10 +98,6 @@ class MCSymbol {
95
98
// / Used to detect cyclic dependency like `a = a + 1` and `a = b; b = a`.
96
99
unsigned IsResolving : 1 ;
97
100
98
- // / This is actually a Contents enumerator, but is unsigned to avoid sign
99
- // / extension and achieve better bitpacking with MSVC.
100
- unsigned SymbolContents : 3 ;
101
-
102
101
// / The alignment of the symbol if it is 'common'.
103
102
// /
104
103
// / Internally, this is stored as log2(align) + 1.
@@ -145,9 +144,9 @@ class MCSymbol {
145
144
};
146
145
147
146
MCSymbol (const MCSymbolTableEntry *Name, bool isTemporary)
148
- : IsTemporary(isTemporary ), IsRedefinable( false ), IsRegistered (false ),
149
- IsExternal (false ), IsPrivateExtern (false ), IsWeakExternal (false ),
150
- IsUsedInReloc (false ), IsResolving( 0 ), SymbolContents(SymContentsUnset ),
147
+ : kind(Kind::Regular ), IsTemporary(isTemporary ), IsRedefinable (false ),
148
+ IsRegistered (false ), IsExternal (false ), IsPrivateExtern (false ),
149
+ IsWeakExternal (false ), IsUsedInReloc( false ), IsResolving( 0 ),
151
150
CommonAlignLog2(0 ), Flags(0 ) {
152
151
Offset = 0 ;
153
152
HasName = !!Name;
@@ -212,9 +211,9 @@ class MCSymbol {
212
211
// / Prepare this symbol to be redefined.
213
212
void redefineIfPossible () {
214
213
if (IsRedefinable) {
215
- if (SymbolContents == SymContentsVariable ) {
214
+ if (kind == Kind::Equated ) {
216
215
Value = nullptr ;
217
- SymbolContents = SymContentsUnset ;
216
+ kind = Kind::Regular ;
218
217
}
219
218
setUndefined ();
220
219
IsRedefinable = false ;
@@ -268,9 +267,7 @@ class MCSymbol {
268
267
// / @{
269
268
270
269
// / isVariable - Check if this is a variable symbol.
271
- bool isVariable () const {
272
- return SymbolContents == SymContentsVariable;
273
- }
270
+ bool isVariable () const { return kind == Equated; }
274
271
275
272
// / Get the expression of the variable symbol.
276
273
const MCExpr *getVariableValue () const {
@@ -293,12 +290,12 @@ class MCSymbol {
293
290
}
294
291
295
292
uint64_t getOffset () const {
296
- assert (SymbolContents == SymContentsUnset &&
293
+ assert (kind == Kind::Regular &&
297
294
" Cannot get offset for a common/variable symbol" );
298
295
return Offset;
299
296
}
300
297
void setOffset (uint64_t Value) {
301
- assert (SymbolContents == SymContentsUnset &&
298
+ assert (kind == Kind::Regular &&
302
299
" Cannot set offset for a common/variable symbol" );
303
300
Offset = Value;
304
301
}
@@ -314,10 +311,10 @@ class MCSymbol {
314
311
// / \param Size - The size of the symbol.
315
312
// / \param Alignment - The alignment of the symbol.
316
313
// / \param Target - Is the symbol a target-specific common-like symbol.
317
- void setCommon (uint64_t Size, Align Alignment, bool Target = false ) {
314
+ void setCommon (uint64_t Size, Align Alignment) {
318
315
assert (getOffset () == 0 );
319
316
CommonSize = Size;
320
- SymbolContents = Target ? SymContentsTargetCommon : SymContentsCommon ;
317
+ kind = Kind::Common ;
321
318
322
319
unsigned Log2Align = encode (Alignment);
323
320
assert (Log2Align < (1U << NumCommonAlignmentBits) &&
@@ -335,29 +332,19 @@ class MCSymbol {
335
332
// /
336
333
// / \param Size - The size of the symbol.
337
334
// / \param Alignment - The alignment of the symbol.
338
- // / \param Target - Is the symbol a target-specific common-like symbol.
339
335
// / \return True if symbol was already declared as a different type
340
- bool declareCommon (uint64_t Size, Align Alignment, bool Target = false ) {
336
+ bool declareCommon (uint64_t Size, Align Alignment) {
341
337
assert (isCommon () || getOffset () == 0 );
342
338
if (isCommon ()) {
343
- if (CommonSize != Size || getCommonAlignment () != Alignment ||
344
- isTargetCommon () != Target)
339
+ if (CommonSize != Size || getCommonAlignment () != Alignment)
345
340
return true ;
346
341
} else
347
- setCommon (Size, Alignment, Target );
342
+ setCommon (Size, Alignment);
348
343
return false ;
349
344
}
350
345
351
346
// / Is this a 'common' symbol.
352
- bool isCommon () const {
353
- return SymbolContents == SymContentsCommon ||
354
- SymbolContents == SymContentsTargetCommon;
355
- }
356
-
357
- // / Is this a target-specific common-like symbol.
358
- bool isTargetCommon () const {
359
- return SymbolContents == SymContentsTargetCommon;
360
- }
347
+ bool isCommon () const { return kind == Kind::Common; }
361
348
362
349
MCFragment *getFragment () const {
363
350
if (Fragment || !isVariable () || isWeakExternal ())
0 commit comments