File indexing completed on 2026-05-10 08:44:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_MC_MCASMINFO_H
0016 #define LLVM_MC_MCASMINFO_H
0017
0018 #include "llvm/ADT/StringRef.h"
0019 #include "llvm/MC/MCDirectives.h"
0020 #include "llvm/MC/MCTargetOptions.h"
0021 #include <vector>
0022
0023 namespace llvm {
0024
0025 class MCContext;
0026 class MCCFIInstruction;
0027 class MCExpr;
0028 class MCSection;
0029 class MCStreamer;
0030 class MCSubtargetInfo;
0031 class MCSymbol;
0032
0033 namespace WinEH {
0034
0035 enum class EncodingType {
0036 Invalid,
0037 Alpha,
0038 Alpha64,
0039 ARM,
0040 CE,
0041 Itanium,
0042 X86,
0043 MIPS = Alpha,
0044 };
0045
0046 }
0047
0048 namespace LCOMM {
0049
0050 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
0051
0052 }
0053
0054
0055
0056 class MCAsmInfo {
0057 public:
0058
0059 enum AsmCharLiteralSyntax {
0060 ACLS_Unknown,
0061
0062 ACLS_SingleQuotePrefix,
0063
0064 };
0065
0066 protected:
0067
0068
0069
0070
0071
0072 unsigned CodePointerSize = 4;
0073
0074
0075
0076 unsigned CalleeSaveStackSlotSize = 4;
0077
0078
0079 bool IsLittleEndian = true;
0080
0081
0082 bool StackGrowsUp = false;
0083
0084
0085
0086 bool HasSubsectionsViaSymbols = false;
0087
0088
0089
0090
0091 bool HasCOFFAssociativeComdats = false;
0092
0093
0094
0095 bool HasCOFFComdatConstants = false;
0096
0097 bool IsAIX = false;
0098
0099
0100 bool IsHLASM = false;
0101
0102
0103
0104 unsigned MaxInstLength = 4;
0105
0106
0107
0108 unsigned MinInstAlignment = 1;
0109
0110
0111
0112 bool DollarIsPC = false;
0113
0114
0115
0116 const char *SeparatorString;
0117
0118
0119
0120 StringRef CommentString;
0121
0122
0123
0124
0125
0126
0127
0128 bool AllowAdditionalComments = true;
0129
0130
0131 const char *LabelSuffix;
0132
0133
0134 bool UseAssignmentForEHBegin = false;
0135
0136
0137 bool NeedsLocalForSize = false;
0138
0139
0140
0141
0142 StringRef PrivateGlobalPrefix;
0143
0144
0145
0146 StringRef PrivateLabelPrefix;
0147
0148
0149
0150
0151
0152 StringRef LinkerPrivateGlobalPrefix;
0153
0154
0155
0156 const char *InlineAsmStart;
0157 const char *InlineAsmEnd;
0158
0159
0160
0161
0162 const char *Code16Directive;
0163 const char *Code32Directive;
0164 const char *Code64Directive;
0165
0166
0167 unsigned AssemblerDialect = 0;
0168
0169
0170
0171 bool AllowAtInName = false;
0172
0173
0174
0175
0176
0177
0178 bool AllowQuestionAtStartOfIdentifier = false;
0179
0180
0181
0182
0183
0184
0185 bool AllowDollarAtStartOfIdentifier = false;
0186
0187
0188
0189
0190
0191
0192 bool AllowAtAtStartOfIdentifier = false;
0193
0194
0195
0196 bool SupportsQuotedNames = true;
0197
0198
0199
0200
0201 bool UseDataRegionDirectives = false;
0202
0203
0204 bool HasLEB128Directives = true;
0205
0206
0207 bool PPCUseFullRegisterNames = false;
0208
0209
0210
0211
0212
0213
0214
0215 const char *ZeroDirective;
0216
0217
0218
0219
0220 const char *AsciiDirective;
0221
0222
0223
0224
0225 const char *AscizDirective;
0226
0227
0228
0229
0230 AsmCharLiteralSyntax CharacterLiteralSyntax = ACLS_Unknown;
0231
0232
0233
0234
0235
0236 const char *Data8bitsDirective;
0237 const char *Data16bitsDirective;
0238 const char *Data32bitsDirective;
0239 const char *Data64bitsDirective;
0240
0241
0242 bool SupportsSignedData = true;
0243
0244
0245
0246
0247 const char *GPRel64Directive = nullptr;
0248
0249
0250
0251
0252 const char *GPRel32Directive = nullptr;
0253
0254
0255
0256
0257 const char *DTPRel32Directive = nullptr;
0258 const char *DTPRel64Directive = nullptr;
0259 const char *TPRel32Directive = nullptr;
0260 const char *TPRel64Directive = nullptr;
0261
0262
0263
0264
0265 bool SunStyleELFSectionSwitchSyntax = false;
0266
0267
0268
0269
0270 bool UsesELFSectionDirectiveForBSS = false;
0271
0272 bool NeedsDwarfSectionOffsetDirective = false;
0273
0274
0275
0276
0277
0278
0279
0280 bool AlignmentIsInBytes = true;
0281
0282
0283
0284 unsigned TextAlignFillValue = 0;
0285
0286
0287
0288
0289
0290 const char *GlobalDirective;
0291
0292
0293
0294
0295
0296
0297 bool SetDirectiveSuppressesReloc = false;
0298
0299
0300
0301 bool COMMDirectiveAlignmentIsInBytes = true;
0302
0303
0304
0305 LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
0306
0307
0308
0309 bool HasFunctionAlignment = true;
0310
0311
0312
0313 bool HasDotTypeDotSizeDirective = true;
0314
0315
0316
0317 bool HasSingleParameterDotFile = true;
0318
0319
0320
0321 bool HasIdentDirective = false;
0322
0323
0324
0325 bool HasNoDeadStrip = false;
0326
0327
0328 const char *WeakDirective;
0329
0330
0331
0332 const char *WeakRefDirective = nullptr;
0333
0334
0335
0336 bool HasWeakDefCanBeHiddenDirective = false;
0337
0338
0339
0340
0341 bool AvoidWeakIfComdat = false;
0342
0343
0344
0345 MCSymbolAttr HiddenVisibilityAttr = MCSA_Hidden;
0346
0347
0348
0349 MCSymbolAttr ExportedVisibilityAttr = MCSA_Exported;
0350
0351
0352
0353 MCSymbolAttr HiddenDeclarationVisibilityAttr = MCSA_Hidden;
0354
0355
0356
0357 MCSymbolAttr ProtectedVisibilityAttr = MCSA_Protected;
0358
0359 MCSymbolAttr MemtagAttr = MCSA_Memtag;
0360
0361
0362
0363
0364
0365 bool SupportsDebugInformation = false;
0366
0367
0368 ExceptionHandling ExceptionsType = ExceptionHandling::None;
0369
0370
0371
0372 bool UsesCFIWithoutEH = false;
0373
0374
0375 WinEH::EncodingType WinEHEncodingType = WinEH::EncodingType::Invalid;
0376
0377
0378
0379 bool DwarfUsesRelocationsAcrossSections = true;
0380
0381
0382
0383 bool DwarfFDESymbolsUseAbsDiff = false;
0384
0385
0386
0387 bool EnableDwarfFileDirectoryDefault = true;
0388
0389
0390
0391 bool DwarfRegNumForCFI = false;
0392
0393
0394
0395 bool UseParensForSymbolVariant = false;
0396
0397
0398
0399 bool UseParensForDollarSignNames = true;
0400
0401
0402
0403 bool SupportsExtendedDwarfLocDirective = true;
0404
0405
0406
0407 std::vector<MCCFIInstruction> InitialFrameState;
0408
0409
0410
0411
0412
0413
0414
0415 std::pair<int, int> BinutilsVersion = {2, 26};
0416
0417
0418
0419
0420
0421
0422 bool UseIntegratedAssembler;
0423
0424
0425 bool ParseInlineAsmUsingAsmParser;
0426
0427
0428 bool PreserveAsmComments;
0429
0430
0431 unsigned CommentColumn = 40;
0432
0433
0434
0435 bool UseLogicalShr = true;
0436
0437
0438
0439 bool HasMipsExpressions = false;
0440
0441
0442 bool UseMotorolaIntegers = false;
0443
0444 public:
0445 explicit MCAsmInfo();
0446 virtual ~MCAsmInfo();
0447
0448
0449 unsigned getCodePointerSize() const { return CodePointerSize; }
0450
0451
0452
0453 unsigned getCalleeSaveStackSlotSize() const {
0454 return CalleeSaveStackSlotSize;
0455 }
0456
0457
0458 bool isLittleEndian() const { return IsLittleEndian; }
0459
0460
0461 bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
0462
0463 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
0464
0465
0466
0467 const char *getData8bitsDirective() const { return Data8bitsDirective; }
0468 const char *getData16bitsDirective() const { return Data16bitsDirective; }
0469 const char *getData32bitsDirective() const { return Data32bitsDirective; }
0470 const char *getData64bitsDirective() const { return Data64bitsDirective; }
0471 bool supportsSignedData() const { return SupportsSignedData; }
0472 const char *getGPRel64Directive() const { return GPRel64Directive; }
0473 const char *getGPRel32Directive() const { return GPRel32Directive; }
0474 const char *getDTPRel64Directive() const { return DTPRel64Directive; }
0475 const char *getDTPRel32Directive() const { return DTPRel32Directive; }
0476 const char *getTPRel64Directive() const { return TPRel64Directive; }
0477 const char *getTPRel32Directive() const { return TPRel32Directive; }
0478
0479
0480
0481
0482 virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
0483 return nullptr;
0484 }
0485
0486 virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
0487 unsigned Encoding,
0488 MCStreamer &Streamer) const;
0489
0490 virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
0491 unsigned Encoding,
0492 MCStreamer &Streamer) const;
0493
0494
0495 virtual bool isAcceptableChar(char C) const;
0496
0497
0498
0499 virtual bool isValidUnquotedName(StringRef Name) const;
0500
0501
0502
0503
0504
0505
0506
0507
0508 virtual bool shouldOmitSectionDirective(StringRef SectionName) const;
0509
0510 bool usesSunStyleELFSectionSwitchSyntax() const {
0511 return SunStyleELFSectionSwitchSyntax;
0512 }
0513
0514 bool usesELFSectionDirectiveForBSS() const {
0515 return UsesELFSectionDirectiveForBSS;
0516 }
0517
0518 bool needsDwarfSectionOffsetDirective() const {
0519 return NeedsDwarfSectionOffsetDirective;
0520 }
0521
0522
0523
0524 bool isAIX() const { return IsAIX; }
0525 bool isHLASM() const { return IsHLASM; }
0526 bool isMachO() const { return HasSubsectionsViaSymbols; }
0527 bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; }
0528 bool hasCOFFComdatConstants() const { return HasCOFFComdatConstants; }
0529
0530
0531
0532 virtual unsigned getMaxInstLength(const MCSubtargetInfo *STI = nullptr) const {
0533 return MaxInstLength;
0534 }
0535
0536 unsigned getMinInstAlignment() const { return MinInstAlignment; }
0537 bool getDollarIsPC() const { return DollarIsPC; }
0538 const char *getSeparatorString() const { return SeparatorString; }
0539
0540 unsigned getCommentColumn() const { return CommentColumn; }
0541 void setCommentColumn(unsigned Col) { CommentColumn = Col; }
0542
0543 StringRef getCommentString() const { return CommentString; }
0544 bool shouldAllowAdditionalComments() const { return AllowAdditionalComments; }
0545 const char *getLabelSuffix() const { return LabelSuffix; }
0546
0547 bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
0548 bool needsLocalForSize() const { return NeedsLocalForSize; }
0549 StringRef getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
0550 StringRef getPrivateLabelPrefix() const { return PrivateLabelPrefix; }
0551
0552 bool hasLinkerPrivateGlobalPrefix() const {
0553 return !LinkerPrivateGlobalPrefix.empty();
0554 }
0555
0556 StringRef getLinkerPrivateGlobalPrefix() const {
0557 if (hasLinkerPrivateGlobalPrefix())
0558 return LinkerPrivateGlobalPrefix;
0559 return getPrivateGlobalPrefix();
0560 }
0561
0562 const char *getInlineAsmStart() const { return InlineAsmStart; }
0563 const char *getInlineAsmEnd() const { return InlineAsmEnd; }
0564 const char *getCode16Directive() const { return Code16Directive; }
0565 const char *getCode32Directive() const { return Code32Directive; }
0566 const char *getCode64Directive() const { return Code64Directive; }
0567 unsigned getAssemblerDialect() const { return AssemblerDialect; }
0568 bool doesAllowAtInName() const { return AllowAtInName; }
0569 void setAllowAtInName(bool V) { AllowAtInName = V; }
0570 bool doesAllowQuestionAtStartOfIdentifier() const {
0571 return AllowQuestionAtStartOfIdentifier;
0572 }
0573 bool doesAllowAtAtStartOfIdentifier() const {
0574 return AllowAtAtStartOfIdentifier;
0575 }
0576 bool doesAllowDollarAtStartOfIdentifier() const {
0577 return AllowDollarAtStartOfIdentifier;
0578 }
0579 bool supportsNameQuoting() const { return SupportsQuotedNames; }
0580
0581 bool doesSupportDataRegionDirectives() const {
0582 return UseDataRegionDirectives;
0583 }
0584
0585 bool hasLEB128Directives() const { return HasLEB128Directives; }
0586
0587 bool useFullRegisterNames() const { return PPCUseFullRegisterNames; }
0588 void setFullRegisterNames(bool V) { PPCUseFullRegisterNames = V; }
0589
0590 const char *getZeroDirective() const { return ZeroDirective; }
0591 const char *getAsciiDirective() const { return AsciiDirective; }
0592 const char *getAscizDirective() const { return AscizDirective; }
0593 AsmCharLiteralSyntax characterLiteralSyntax() const {
0594 return CharacterLiteralSyntax;
0595 }
0596 bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
0597 unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
0598 const char *getGlobalDirective() const { return GlobalDirective; }
0599
0600 bool doesSetDirectiveSuppressReloc() const {
0601 return SetDirectiveSuppressesReloc;
0602 }
0603
0604 bool getCOMMDirectiveAlignmentIsInBytes() const {
0605 return COMMDirectiveAlignmentIsInBytes;
0606 }
0607
0608 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
0609 return LCOMMDirectiveAlignmentType;
0610 }
0611
0612 bool hasFunctionAlignment() const { return HasFunctionAlignment; }
0613 bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
0614 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
0615 bool hasIdentDirective() const { return HasIdentDirective; }
0616 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
0617 const char *getWeakDirective() const { return WeakDirective; }
0618 const char *getWeakRefDirective() const { return WeakRefDirective; }
0619
0620 bool hasWeakDefCanBeHiddenDirective() const {
0621 return HasWeakDefCanBeHiddenDirective;
0622 }
0623
0624 bool avoidWeakIfComdat() const { return AvoidWeakIfComdat; }
0625
0626 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
0627
0628 MCSymbolAttr getExportedVisibilityAttr() const { return ExportedVisibilityAttr; }
0629
0630 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
0631 return HiddenDeclarationVisibilityAttr;
0632 }
0633
0634 MCSymbolAttr getProtectedVisibilityAttr() const {
0635 return ProtectedVisibilityAttr;
0636 }
0637
0638 MCSymbolAttr getMemtagAttr() const { return MemtagAttr; }
0639
0640 bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
0641
0642 ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
0643 WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
0644
0645 void setExceptionsType(ExceptionHandling EH) {
0646 ExceptionsType = EH;
0647 }
0648
0649 bool usesCFIWithoutEH() const {
0650 return ExceptionsType == ExceptionHandling::None && UsesCFIWithoutEH;
0651 }
0652
0653
0654
0655 bool usesCFIForEH() const {
0656 return (ExceptionsType == ExceptionHandling::DwarfCFI ||
0657 ExceptionsType == ExceptionHandling::ARM ||
0658 ExceptionsType == ExceptionHandling::ZOS || usesWindowsCFI());
0659 }
0660
0661 bool usesWindowsCFI() const {
0662 return ExceptionsType == ExceptionHandling::WinEH &&
0663 (WinEHEncodingType != WinEH::EncodingType::Invalid &&
0664 WinEHEncodingType != WinEH::EncodingType::X86);
0665 }
0666
0667 bool doesDwarfUseRelocationsAcrossSections() const {
0668 return DwarfUsesRelocationsAcrossSections;
0669 }
0670
0671 bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
0672 bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
0673 bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
0674 bool useParensForDollarSignNames() const {
0675 return UseParensForDollarSignNames;
0676 }
0677 bool supportsExtendedDwarfLocDirective() const {
0678 return SupportsExtendedDwarfLocDirective;
0679 }
0680
0681 bool usesDwarfFileAndLocDirectives() const { return !IsAIX; }
0682
0683 bool enableDwarfFileDirectoryDefault() const {
0684 return EnableDwarfFileDirectoryDefault;
0685 }
0686
0687 void addInitialFrameState(const MCCFIInstruction &Inst);
0688
0689 const std::vector<MCCFIInstruction> &getInitialFrameState() const {
0690 return InitialFrameState;
0691 }
0692
0693 void setBinutilsVersion(std::pair<int, int> Value) {
0694 BinutilsVersion = Value;
0695 }
0696
0697
0698 bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
0699
0700
0701 bool parseInlineAsmUsingAsmParser() const {
0702 return ParseInlineAsmUsingAsmParser;
0703 }
0704
0705 bool binutilsIsAtLeast(int Major, int Minor) const {
0706 return BinutilsVersion >= std::make_pair(Major, Minor);
0707 }
0708
0709
0710 virtual void setUseIntegratedAssembler(bool Value) {
0711 UseIntegratedAssembler = Value;
0712 }
0713
0714
0715 virtual void setParseInlineAsmUsingAsmParser(bool Value) {
0716 ParseInlineAsmUsingAsmParser = Value;
0717 }
0718
0719
0720 bool preserveAsmComments() const { return PreserveAsmComments; }
0721
0722
0723 virtual void setPreserveAsmComments(bool Value) {
0724 PreserveAsmComments = Value;
0725 }
0726
0727
0728 bool shouldUseLogicalShr() const { return UseLogicalShr; }
0729
0730 bool hasMipsExpressions() const { return HasMipsExpressions; }
0731 bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
0732 };
0733
0734 }
0735
0736 #endif