81typedef std::vector<AsmToken> MCAsmMacroArgument;
82typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
86struct MacroInstantiation {
88 SMLoc InstantiationLoc;
97 size_t CondStackDepth;
100struct ParseStatementInfo {
105 unsigned Opcode = ~0
U;
108 bool ParseError =
false;
112 ParseStatementInfo() =
delete;
114 : AsmRewrites(rewrites) {}
126 void *SavedDiagContext;
127 std::unique_ptr<MCAsmParserExtension> PlatformParser;
129 std::optional<SMLoc> CFIStartProcLoc;
136 std::vector<AsmCond> TheCondStack;
144 std::vector<MacroInstantiation*> ActiveMacros;
147 std::deque<MCAsmMacro> MacroLikeBodies;
150 unsigned MacrosEnabledFlag : 1;
153 unsigned NumOfMacroInstantiations;
156 struct CppHashInfoTy {
161 CppHashInfoTy() : LineNumber(0), Buf(0) {}
163 CppHashInfoTy CppHashInfo;
174 unsigned AssemblerDialect = ~0
U;
177 bool IsDarwin =
false;
180 bool ParsingMSInlineAsm =
false;
183 bool ReportedInconsistentMD5 =
false;
186 bool AltMacroMode =
false;
189 virtual bool parseStatement(ParseStatementInfo &Info,
195 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
202 bool enabledGenDwarfForAssembly();
207 AsmParser(
const AsmParser &) =
delete;
208 AsmParser &
operator=(
const AsmParser &) =
delete;
209 ~AsmParser()
override;
211 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
214 ExtensionDirectiveHandler Handler)
override {
215 ExtensionDirectiveMap[
Directive] = Handler;
219 DirectiveKindMap[
Directive.lower()] = DirectiveKindMap[Alias.
lower()];
233 if (AssemblerDialect == ~0U)
236 return AssemblerDialect;
239 AssemblerDialect = i;
244 SMRange Range = std::nullopt)
override;
246 SMRange Range = std::nullopt)
override;
251 ParsingMSInlineAsm =
V;
276 SMLoc &EndLoc)
override;
294 bool parseCppHashLineFilenameComment(
SMLoc L,
bool SaveLocInfo =
true);
303 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
306 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
309 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
318 void handleMacroExit();
321 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
324 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
326 void printMacroInstantiations();
328 SMRange Range = std::nullopt)
const {
335 bool enterIncludeFile(
const std::string &Filename);
339 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
348 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
359 enum class AssignmentKind {
371 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
372 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
373 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
375 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
378 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
437 DK_BUNDLE_ALIGN_MODE,
451 DK_WEAK_DEF_CAN_BE_HIDDEN,
491 DK_CV_INLINE_SITE_ID,
494 DK_CV_INLINE_LINETABLE,
499 DK_CV_FILECHECKSUM_OFFSET,
505 DK_CFI_DEF_CFA_OFFSET,
506 DK_CFI_ADJUST_CFA_OFFSET,
507 DK_CFI_DEF_CFA_REGISTER,
508 DK_CFI_LLVM_DEF_ASPACE_CFA,
513 DK_CFI_REMEMBER_STATE,
514 DK_CFI_RESTORE_STATE,
518 DK_CFI_RETURN_COLUMN,
543 DK_LTO_SET_CONDITIONAL,
544 DK_CFI_MTE_TAGGED_FRAME,
554 enum CVDefRangeType {
556 CVDR_DEFRANGE_REGISTER,
557 CVDR_DEFRANGE_FRAMEPOINTER_REL,
558 CVDR_DEFRANGE_SUBFIELD_REGISTER,
559 CVDR_DEFRANGE_REGISTER_REL
567 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
568 bool parseDirectiveReloc(
SMLoc DirectiveLoc);
569 bool parseDirectiveValue(
StringRef IDVal,
571 bool parseDirectiveOctaValue(
StringRef IDVal);
572 bool parseDirectiveRealValue(
StringRef IDVal,
574 bool parseDirectiveFill();
575 bool parseDirectiveZero();
577 bool parseDirectiveSet(
StringRef IDVal, AssignmentKind Kind);
578 bool parseDirectiveOrg();
580 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
583 bool parseDirectiveFile(
SMLoc DirectiveLoc);
584 bool parseDirectiveLine();
585 bool parseDirectiveLoc();
586 bool parseDirectiveStabs();
590 bool parseDirectiveCVFile();
591 bool parseDirectiveCVFuncId();
592 bool parseDirectiveCVInlineSiteId();
593 bool parseDirectiveCVLoc();
594 bool parseDirectiveCVLinetable();
595 bool parseDirectiveCVInlineLinetable();
596 bool parseDirectiveCVDefRange();
597 bool parseDirectiveCVString();
598 bool parseDirectiveCVStringTable();
599 bool parseDirectiveCVFileChecksums();
600 bool parseDirectiveCVFileChecksumOffset();
601 bool parseDirectiveCVFPOData();
604 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
605 bool parseDirectiveCFIWindowSave(
SMLoc DirectiveLoc);
606 bool parseDirectiveCFISections();
607 bool parseDirectiveCFIStartProc();
608 bool parseDirectiveCFIEndProc();
609 bool parseDirectiveCFIDefCfaOffset(
SMLoc DirectiveLoc);
610 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
611 bool parseDirectiveCFIAdjustCfaOffset(
SMLoc DirectiveLoc);
612 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
613 bool parseDirectiveCFILLVMDefAspaceCfa(
SMLoc DirectiveLoc);
614 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
615 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
616 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
617 bool parseDirectiveCFIRememberState(
SMLoc DirectiveLoc);
618 bool parseDirectiveCFIRestoreState(
SMLoc DirectiveLoc);
619 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
620 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
621 bool parseDirectiveCFIEscape(
SMLoc DirectiveLoc);
622 bool parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc);
623 bool parseDirectiveCFISignalFrame(
SMLoc DirectiveLoc);
624 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
627 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
630 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
635 bool parseDirectiveBundleAlignMode();
637 bool parseDirectiveBundleLock();
639 bool parseDirectiveBundleUnlock();
642 bool parseDirectiveSpace(
StringRef IDVal);
651 bool parseDirectiveLEB128(
bool Signed);
657 bool parseDirectiveComm(
bool IsLocal);
659 bool parseDirectiveAbort();
660 bool parseDirectiveInclude();
661 bool parseDirectiveIncbin();
664 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
666 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
668 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
670 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
672 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
673 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
674 bool parseDirectiveElse(
SMLoc DirectiveLoc);
675 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
687 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
688 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
689 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
692 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &Info,
696 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &Info);
699 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
702 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
705 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
708 bool parseDirectivePrint(
SMLoc DirectiveLoc);
711 bool parseDirectivePseudoProbe();
714 bool parseDirectiveLTODiscard();
717 bool parseDirectiveAddrsig();
718 bool parseDirectiveAddrsigSym();
720 void initializeDirectiveKindMap();
721 void initializeCVDefRangeTypeMap();
724class HLASMAsmParser final :
public AsmParser {
729 void lexLeadingSpaces() {
735 bool parseAsMachineInstruction(ParseStatementInfo &Info,
741 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
750 bool parseStatement(ParseStatementInfo &Info,
773 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
774 CurBuffer(CB ? CB : SM.getMainFileID()), MacrosEnabledFlag(
true) {
802 "Need to implement createSPIRVAsmParser for SPIRV format.");
815 PlatformParser->Initialize(*
this);
816 initializeDirectiveKindMap();
817 initializeCVDefRangeTypeMap();
819 NumOfMacroInstantiations = 0;
822AsmParser::~AsmParser() {
823 assert((HadError || ActiveMacros.empty()) &&
824 "Unexpected active macro instantiation!");
833void AsmParser::printMacroInstantiations() {
835 for (MacroInstantiation *M :
reverse(ActiveMacros))
837 "while in macro instantiation");
841 printPendingErrors();
843 printMacroInstantiations();
847 if(getTargetParser().getTargetOptions().MCNoWarn)
849 if (getTargetParser().getTargetOptions().MCFatalWarnings)
850 return Error(L, Msg, Range);
852 printMacroInstantiations();
859 printMacroInstantiations();
863bool AsmParser::enterIncludeFile(
const std::string &Filename) {
864 std::string IncludedFile;
878bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
880 std::string IncludedFile;
891 if (!Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
892 return Error(Loc,
"expected absolute expression");
894 return Warning(Loc,
"negative count has no effect");
897 getStreamer().emitBytes(Bytes);
901void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
914 if (!getTok().getString().empty() && getTok().getString().front() !=
'\n' &&
932 if (ParentIncludeLoc !=
SMLoc()) {
933 jumpToLoc(ParentIncludeLoc);
941bool AsmParser::enabledGenDwarfForAssembly() {
943 if (!getContext().getGenDwarfForAssembly())
948 if (getContext().getGenDwarfFileNumber() == 0) {
951 if (!FirstCppHashFilename.
empty())
952 getContext().setMCLineTableRootFile(
953 0, getContext().getCompilationDir(), FirstCppHashFilename,
954 std::nullopt, std::nullopt);
956 getContext().getMCDwarfLineTable(0).getRootFile();
957 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
958 0, getContext().getCompilationDir(), RootFile.
Name,
964bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
965 LTODiscardSymbols.
clear();
968 if (!NoInitialTextSection)
975 AsmCond StartingCondState = TheCondState;
982 if (getContext().getGenDwarfForAssembly()) {
983 MCSection *Sec = getStreamer().getCurrentSectionOnly();
985 MCSymbol *SectionStartSym = getContext().createTempSymbol();
986 getStreamer().emitLabel(SectionStartSym);
989 bool InsertResult = getContext().addGenDwarfSection(Sec);
990 assert(InsertResult &&
".text section should not have debug info yet");
994 getTargetParser().onBeginOfFile();
998 ParseStatementInfo
Info(&AsmStrRewrites);
999 bool Parsed = parseStatement(Info,
nullptr);
1009 printPendingErrors();
1012 if (Parsed && !getLexer().isAtStartOfStatement())
1013 eatToEndOfStatement();
1016 getTargetParser().onEndOfFile();
1017 printPendingErrors();
1020 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1022 getTargetParser().flushPendingInstructions(getStreamer());
1026 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1028 const auto &LineTables = getContext().getMCDwarfLineTables();
1029 if (!LineTables.empty()) {
1031 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1033 printError(getTok().getLoc(),
"unassigned file number: " +
1035 " for .file directives");
1051 if (
Sym->isTemporary() && !
Sym->isVariable() && !
Sym->isDefined())
1055 printError(getTok().getLoc(),
"assembler local symbol '" +
1056 Sym->getName() +
"' not defined");
1062 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1063 if (std::get<2>(LocSym)->isUndefined()) {
1066 CppHashInfo = std::get<1>(LocSym);
1067 printError(std::get<0>(LocSym),
"directional label undefined");
1073 if (!HadError && !NoFinalize) {
1075 TS->emitConstantPools();
1080 return HadError || getContext().hadError();
1083bool AsmParser::checkForValidSection() {
1084 if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) {
1086 return Error(getTok().getLoc(),
1087 "expected section directive before assembly directive");
1093void AsmParser::eatToEndOfStatement() {
1102StringRef AsmParser::parseStringToEndOfStatement() {
1103 const char *Start = getTok().getLoc().getPointer();
1108 const char *
End = getTok().getLoc().getPointer();
1112StringRef AsmParser::parseStringToComma() {
1113 const char *Start = getTok().getLoc().getPointer();
1119 const char *
End = getTok().getLoc().getPointer();
1128bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1129 if (parseExpression(Res))
1132 return parseRParen();
1140bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1141 if (parseExpression(Res))
1143 EndLoc = getTok().getEndLoc();
1144 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1155bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc,
1157 SMLoc FirstTokenLoc = getLexer().getLoc();
1159 switch (FirstTokenKind) {
1161 return TokError(
"unknown token in expression");
1167 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1177 if (parseIdentifier(Identifier)) {
1181 bool ShouldGenerateTempSymbol =
false;
1184 ShouldGenerateTempSymbol =
true;
1186 if (!ShouldGenerateTempSymbol)
1187 return Error(FirstTokenLoc,
"invalid token in expression");
1197 EndLoc = FirstTokenLoc;
1202 std::pair<StringRef, StringRef>
Split;
1207 SMLoc AtLoc = getLexer().getLoc();
1209 if (parseIdentifier(VName))
1210 return Error(AtLoc,
"expected symbol variant after '@'");
1212 Split = std::make_pair(Identifier, VName);
1220 parseIdentifier(VName);
1223 Split = std::make_pair(Identifier, VName);
1231 return Error(getLexer().getLoc(),
"expected a symbol reference");
1236 if (!
Split.second.empty()) {
1237 Variant = getTargetParser().getVariantKindForName(
Split.second);
1244 "invalid variant '" +
Split.second +
"'");
1248 MCSymbol *
Sym = getContext().getInlineAsmLabel(SymbolName);
1250 Sym = getContext().getOrCreateSymbol(
1255 if (
Sym->isVariable()) {
1256 auto V =
Sym->getVariableValue(
false);
1257 bool DoInline = isa<MCConstantExpr>(V) && !
Variant;
1258 if (
auto TV = dyn_cast<MCTargetExpr>(V))
1259 DoInline = TV->inlineAssignedExpr();
1262 return Error(EndLoc,
"unexpected modifier on variable reference");
1263 Res =
Sym->getVariableValue(
false);
1273 return TokError(
"literal value out of range for directive");
1275 SMLoc Loc = getTok().getLoc();
1276 int64_t
IntVal = getTok().getIntVal();
1284 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1286 if (
Split.first.size() != IDVal.
size()) {
1289 return TokError(
"invalid variant '" +
Split.second +
"'");
1290 IDVal =
Split.first;
1292 if (IDVal ==
"f" || IDVal ==
"b") {
1296 if (IDVal ==
"b" &&
Sym->isUndefined())
1297 return Error(Loc,
"directional label undefined");
1298 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo,
Sym));
1306 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1315 return TokError(
"cannot use . as current PC");
1328 return parseParenExpr(Res, EndLoc);
1330 if (!PlatformParser->HasBracketExpressions())
1331 return TokError(
"brackets expression not supported on this target");
1333 return parseBracketExpr(Res, EndLoc);
1336 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1342 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1348 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1380 return TokError(
"expected '(' after operator");
1382 if (parseExpression(Res, EndLoc))
1386 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1391bool AsmParser::parseExpression(
const MCExpr *&Res) {
1393 return parseExpression(Res, EndLoc);
1397AsmParser::applyModifierToExpr(
const MCExpr *E,
1400 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
1414 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
1415 "' (already modified)");
1463 "Argument to the function cannot be a NULL value");
1465 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1466 (*CharPtr !=
'\0')) {
1467 if (*CharPtr ==
'!')
1471 if (*CharPtr ==
'>') {
1481 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1482 if (AltMacroStr[Pos] ==
'!')
1484 Res += AltMacroStr[Pos];
1499bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1502 if (getTargetParser().parsePrimaryExpr(Res, EndLoc) ||
1503 parseBinOpRHS(1, Res, EndLoc))
1511 return TokError(
"unexpected symbol modifier following '@'");
1516 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1518 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1520 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1521 "' (no symbols present)");
1531 if (Res->evaluateAsAbsolute(
Value))
1537bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1539 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1542bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1544 if (parseParenExpr(Res, EndLoc))
1547 for (; ParenDepth > 0; --ParenDepth) {
1548 if (parseBinOpRHS(1, Res, EndLoc))
1553 if (ParenDepth - 1 > 0) {
1554 EndLoc = getTok().getEndLoc();
1562bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1566 if (parseExpression(Expr))
1569 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1570 return Error(StartLoc,
"expected absolute expression");
1577 bool ShouldUseLogicalShr) {
1654 bool ShouldUseLogicalShr) {
1743bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1748 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1752 if (TokPrec < Precedence)
1759 if (getTargetParser().parsePrimaryExpr(RHS, EndLoc))
1765 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1766 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1778bool AsmParser::parseStatement(ParseStatementInfo &Info,
1780 assert(!hasPendingError() &&
"parseStatement started with pending error");
1786 if (getTok().getString().empty() || getTok().getString().front() ==
'\r' ||
1787 getTok().getString().front() ==
'\n')
1796 int64_t LocalLabelVal = -1;
1797 StartTokLoc =
ID.getLoc();
1799 return parseCppHashLineFilenameComment(IDLoc,
1800 !isInsideMacroInstantiation());
1804 LocalLabelVal = getTok().getIntVal();
1805 if (LocalLabelVal < 0) {
1806 if (!TheCondState.
Ignore) {
1808 return Error(IDLoc,
"unexpected token at start of statement");
1812 IDVal = getTok().getString();
1815 if (!TheCondState.
Ignore) {
1817 return Error(IDLoc,
"unexpected token at start of statement");
1835 getTargetParser().starIsStartOfStatement()) {
1839 }
else if (parseIdentifier(IDVal)) {
1840 if (!TheCondState.
Ignore) {
1842 return Error(IDLoc,
"unexpected token at start of statement");
1851 DirectiveKindMap.find(IDVal.
lower());
1852 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1854 : DirKindIt->getValue();
1865 return parseDirectiveIf(IDLoc, DirKind);
1867 return parseDirectiveIfb(IDLoc,
true);
1869 return parseDirectiveIfb(IDLoc,
false);
1871 return parseDirectiveIfc(IDLoc,
true);
1873 return parseDirectiveIfeqs(IDLoc,
true);
1875 return parseDirectiveIfc(IDLoc,
false);
1877 return parseDirectiveIfeqs(IDLoc,
false);
1879 return parseDirectiveIfdef(IDLoc,
true);
1882 return parseDirectiveIfdef(IDLoc,
false);
1884 return parseDirectiveElseIf(IDLoc);
1886 return parseDirectiveElse(IDLoc);
1888 return parseDirectiveEndIf(IDLoc);
1893 if (TheCondState.
Ignore) {
1894 eatToEndOfStatement();
1904 if (checkForValidSection())
1911 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1919 if (LocalLabelVal == -1) {
1920 if (ParsingMSInlineAsm && SI) {
1922 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1924 "We should have an internal name here.");
1927 IDVal = RewrittenLabel;
1929 Sym = getContext().getOrCreateSymbol(IDVal);
1937 StringRef CommentStr = parseStringToEndOfStatement();
1949 Sym->isExternal() && !cast<MCSymbolMachO>(
Sym)->isAltEntry())
1950 return Error(StartTokLoc,
"non-private labels cannot appear between "
1951 ".cfi_startproc / .cfi_endproc pairs") &&
1952 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1954 if (discardLTOSymbol(IDVal))
1957 getTargetParser().doBeforeLabelEmit(
Sym, IDLoc);
1960 if (!getTargetParser().isParsingMSInlineAsm())
1965 if (enabledGenDwarfForAssembly())
1969 getTargetParser().onLabelParsed(
Sym);
1978 return parseAssignment(IDVal, AssignmentKind::Equal);
1982 if (areMacrosEnabled())
1983 if (
MCAsmMacro *M = getContext().lookupMacro(IDVal))
1984 return handleMacroEntry(M, IDLoc);
2001 getTargetParser().flushPendingInstructions(getStreamer());
2003 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
2005 "Should only return Failure iff there was an error");
2013 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
2014 ExtensionDirectiveMap.
lookup(IDVal);
2016 return (*Handler.second)(Handler.first, IDVal, IDLoc);
2025 return parseDirectiveSet(IDVal, AssignmentKind::Set);
2027 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
2028 case DK_LTO_SET_CONDITIONAL:
2029 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
2031 return parseDirectiveAscii(IDVal,
false);
2034 return parseDirectiveAscii(IDVal,
true);
2037 return parseDirectiveValue(IDVal, 1);
2043 return parseDirectiveValue(IDVal, 2);
2048 return parseDirectiveValue(IDVal, 4);
2051 return parseDirectiveValue(IDVal, 8);
2053 return parseDirectiveValue(
2054 IDVal, getContext().getAsmInfo()->getCodePointerSize());
2056 return parseDirectiveOctaValue(IDVal);
2060 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
2063 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
2065 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
2066 return parseDirectiveAlign(IsPow2, 1);
2069 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
2070 return parseDirectiveAlign(IsPow2, 4);
2073 return parseDirectiveAlign(
false, 1);
2075 return parseDirectiveAlign(
false, 2);
2077 return parseDirectiveAlign(
false, 4);
2079 return parseDirectiveAlign(
true, 1);
2081 return parseDirectiveAlign(
true, 2);
2083 return parseDirectiveAlign(
true, 4);
2085 return parseDirectiveOrg();
2087 return parseDirectiveFill();
2089 return parseDirectiveZero();
2091 eatToEndOfStatement();
2095 return parseDirectiveSymbolAttribute(
MCSA_Global);
2096 case DK_LAZY_REFERENCE:
2098 case DK_NO_DEAD_STRIP:
2100 case DK_SYMBOL_RESOLVER:
2102 case DK_PRIVATE_EXTERN:
2106 case DK_WEAK_DEFINITION:
2108 case DK_WEAK_REFERENCE:
2110 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2113 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2116 return parseDirectiveComm(
false);
2118 return parseDirectiveComm(
true);
2120 return parseDirectiveAbort();
2122 return parseDirectiveInclude();
2124 return parseDirectiveIncbin();
2127 return TokError(
Twine(IDVal) +
2128 " not currently supported for this target");
2130 return parseDirectiveRept(IDLoc, IDVal);
2132 return parseDirectiveIrp(IDLoc);
2134 return parseDirectiveIrpc(IDLoc);
2136 return parseDirectiveEndr(IDLoc);
2137 case DK_BUNDLE_ALIGN_MODE:
2138 return parseDirectiveBundleAlignMode();
2139 case DK_BUNDLE_LOCK:
2140 return parseDirectiveBundleLock();
2141 case DK_BUNDLE_UNLOCK:
2142 return parseDirectiveBundleUnlock();
2144 return parseDirectiveLEB128(
true);
2146 return parseDirectiveLEB128(
false);
2149 return parseDirectiveSpace(IDVal);
2151 return parseDirectiveFile(IDLoc);
2153 return parseDirectiveLine();
2155 return parseDirectiveLoc();
2157 return parseDirectiveStabs();
2159 return parseDirectiveCVFile();
2161 return parseDirectiveCVFuncId();
2162 case DK_CV_INLINE_SITE_ID:
2163 return parseDirectiveCVInlineSiteId();
2165 return parseDirectiveCVLoc();
2166 case DK_CV_LINETABLE:
2167 return parseDirectiveCVLinetable();
2168 case DK_CV_INLINE_LINETABLE:
2169 return parseDirectiveCVInlineLinetable();
2170 case DK_CV_DEF_RANGE:
2171 return parseDirectiveCVDefRange();
2173 return parseDirectiveCVString();
2174 case DK_CV_STRINGTABLE:
2175 return parseDirectiveCVStringTable();
2176 case DK_CV_FILECHECKSUMS:
2177 return parseDirectiveCVFileChecksums();
2178 case DK_CV_FILECHECKSUM_OFFSET:
2179 return parseDirectiveCVFileChecksumOffset();
2180 case DK_CV_FPO_DATA:
2181 return parseDirectiveCVFPOData();
2182 case DK_CFI_SECTIONS:
2183 return parseDirectiveCFISections();
2184 case DK_CFI_STARTPROC:
2185 return parseDirectiveCFIStartProc();
2186 case DK_CFI_ENDPROC:
2187 return parseDirectiveCFIEndProc();
2188 case DK_CFI_DEF_CFA:
2189 return parseDirectiveCFIDefCfa(IDLoc);
2190 case DK_CFI_DEF_CFA_OFFSET:
2191 return parseDirectiveCFIDefCfaOffset(IDLoc);
2192 case DK_CFI_ADJUST_CFA_OFFSET:
2193 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2194 case DK_CFI_DEF_CFA_REGISTER:
2195 return parseDirectiveCFIDefCfaRegister(IDLoc);
2196 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2197 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2199 return parseDirectiveCFIOffset(IDLoc);
2200 case DK_CFI_REL_OFFSET:
2201 return parseDirectiveCFIRelOffset(IDLoc);
2202 case DK_CFI_PERSONALITY:
2203 return parseDirectiveCFIPersonalityOrLsda(
true);
2205 return parseDirectiveCFIPersonalityOrLsda(
false);
2206 case DK_CFI_REMEMBER_STATE:
2207 return parseDirectiveCFIRememberState(IDLoc);
2208 case DK_CFI_RESTORE_STATE:
2209 return parseDirectiveCFIRestoreState(IDLoc);
2210 case DK_CFI_SAME_VALUE:
2211 return parseDirectiveCFISameValue(IDLoc);
2212 case DK_CFI_RESTORE:
2213 return parseDirectiveCFIRestore(IDLoc);
2215 return parseDirectiveCFIEscape(IDLoc);
2216 case DK_CFI_RETURN_COLUMN:
2217 return parseDirectiveCFIReturnColumn(IDLoc);
2218 case DK_CFI_SIGNAL_FRAME:
2219 return parseDirectiveCFISignalFrame(IDLoc);
2220 case DK_CFI_UNDEFINED:
2221 return parseDirectiveCFIUndefined(IDLoc);
2222 case DK_CFI_REGISTER:
2223 return parseDirectiveCFIRegister(IDLoc);
2224 case DK_CFI_WINDOW_SAVE:
2225 return parseDirectiveCFIWindowSave(IDLoc);
2228 return parseDirectiveMacrosOnOff(IDVal);
2230 return parseDirectiveMacro(IDLoc);
2233 return parseDirectiveAltmacro(IDVal);
2235 return parseDirectiveExitMacro(IDVal);
2238 return parseDirectiveEndMacro(IDVal);
2240 return parseDirectivePurgeMacro(IDLoc);
2242 return parseDirectiveEnd(IDLoc);
2244 return parseDirectiveError(IDLoc,
false);
2246 return parseDirectiveError(IDLoc,
true);
2248 return parseDirectiveWarning(IDLoc);
2250 return parseDirectiveReloc(IDLoc);
2253 return parseDirectiveDCB(IDVal, 2);
2255 return parseDirectiveDCB(IDVal, 1);
2257 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2259 return parseDirectiveDCB(IDVal, 4);
2261 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2264 return TokError(
Twine(IDVal) +
2265 " not currently supported for this target");
2268 return parseDirectiveDS(IDVal, 2);
2270 return parseDirectiveDS(IDVal, 1);
2272 return parseDirectiveDS(IDVal, 8);
2275 return parseDirectiveDS(IDVal, 4);
2278 return parseDirectiveDS(IDVal, 12);
2280 return parseDirectivePrint(IDLoc);
2282 return parseDirectiveAddrsig();
2283 case DK_ADDRSIG_SYM:
2284 return parseDirectiveAddrsigSym();
2285 case DK_PSEUDO_PROBE:
2286 return parseDirectivePseudoProbe();
2287 case DK_LTO_DISCARD:
2288 return parseDirectiveLTODiscard();
2290 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2293 return Error(IDLoc,
"unknown directive");
2297 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2298 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2299 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2302 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2303 return parseDirectiveMSAlign(IDLoc, Info);
2305 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2307 if (checkForValidSection())
2310 return parseAndMatchAndEmitTargetInstruction(Info, IDVal,
ID, IDLoc);
2313bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2318 std::string OpcodeStr = IDVal.
lower();
2320 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr,
ID,
2321 Info.ParsedOperands);
2322 Info.ParseError = ParseHadError;
2325 if (getShowParsedOperands()) {
2328 OS <<
"parsed instruction: [";
2329 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2332 Info.ParsedOperands[i]->print(
OS);
2340 if (hasPendingError() || ParseHadError)
2345 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2346 getContext().getGenDwarfSectionSyms().
count(
2347 getStreamer().getCurrentSectionOnly())) {
2349 if (ActiveMacros.empty())
2353 ActiveMacros.front()->ExitBuffer);
2358 if (!CppHashInfo.Filename.empty()) {
2359 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2361 getContext().setGenDwarfFileNumber(FileNumber);
2363 unsigned CppHashLocLineNo =
2365 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2368 getStreamer().emitDwarfLocDirective(
2369 getContext().getGenDwarfFileNumber(), Line, 0,
2375 if (!ParseHadError) {
2377 if (getTargetParser().MatchAndEmitInstruction(
2379 getTargetParser().isParsingMSInlineAsm()))
2405bool AsmParser::parseCppHashLineFilenameComment(
SMLoc L,
bool SaveLocInfo) {
2410 "Lexing Cpp line comment: Expected Integer");
2411 int64_t LineNumber = getTok().getIntVal();
2414 "Lexing Cpp line comment: Expected String");
2426 CppHashInfo.Loc =
L;
2428 CppHashInfo.LineNumber = LineNumber;
2429 CppHashInfo.Buf = CurBuffer;
2430 if (FirstCppHashFilename.
empty())
2437void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *Context) {
2438 auto *Parser =
static_cast<AsmParser *
>(
Context);
2444 unsigned CppHashBuf =
2445 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2450 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2459 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2460 if (Parser->SavedDiagHandler)
2461 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2463 Parser->getContext().diagnose(Diag);
2470 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2473 int CppHashLocLineNo =
2474 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2476 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2482 if (Parser->SavedDiagHandler)
2483 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2485 Parser->getContext().diagnose(NewDiag);
2493 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2500 bool EnableAtPseudoVariable) {
2502 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2507 while (!Body.
empty()) {
2509 std::size_t
End = Body.
size(), Pos = 0;
2510 for (; Pos !=
End; ++Pos) {
2512 if (IsDarwin && !NParameters) {
2514 if (Body[Pos] !=
'$' || Pos + 1 ==
End)
2517 char Next = Body[Pos + 1];
2518 if (Next ==
'$' || Next ==
'n' ||
2519 isdigit(
static_cast<unsigned char>(Next)))
2523 if (Body[Pos] ==
'\\' && Pos + 1 !=
End)
2535 if (IsDarwin && !NParameters) {
2536 switch (Body[Pos + 1]) {
2550 unsigned Index = Body[Pos + 1] -
'0';
2556 OS << Token.getString();
2563 unsigned I = Pos + 1;
2565 if (EnableAtPseudoVariable && Body[
I] ==
'@') {
2567 }
else if (Body[
I] ==
'+') {
2575 const char *Begin = Body.
data() + Pos + 1;
2580 OS << NumOfMacroInstantiations;
2590 if (
Index == NParameters) {
2591 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
2598 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2607 if (AltMacroMode && Token.getString().front() ==
'%' &&
2610 OS << Token.getIntVal();
2613 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2620 OS << Token.getString();
2622 OS << Token.getStringContents();
2667class AsmLexerSkipSpaceRAII {
2669 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2673 ~AsmLexerSkipSpaceRAII() {
2683bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2687 StringRef Str = parseStringToEndOfStatement();
2693 unsigned ParenLevel = 0;
2696 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2703 return TokError(
"unexpected token in macro instantiation");
2705 if (ParenLevel == 0) {
2718 MA.push_back(getTok());
2742 MA.push_back(getTok());
2746 if (ParenLevel != 0)
2747 return TokError(
"unbalanced parentheses in macro argument");
2752bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2753 MCAsmMacroArguments &
A) {
2754 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2755 bool NamedParametersFound =
false;
2758 A.resize(NParameters);
2759 FALocs.
resize(NParameters);
2764 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2765 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2771 if (parseIdentifier(FA.
Name))
2772 return Error(IDLoc,
"invalid argument identifier for formal argument");
2775 return TokError(
"expected '=' after formal parameter identifier");
2779 NamedParametersFound =
true;
2781 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2783 if (NamedParametersFound && FA.
Name.
empty())
2784 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2789 const MCExpr *AbsoluteExp;
2793 if (parseExpression(AbsoluteExp, EndLoc))
2795 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2796 getStreamer().getAssemblerPtr()))
2797 return Error(StrLoc,
"expected absolute expression");
2802 FA.
Value.push_back(newToken);
2807 jumpToLoc(EndLoc, CurBuffer);
2812 FA.
Value.push_back(newToken);
2813 }
else if(parseMacroArgument(FA.
Value, Vararg))
2816 unsigned PI = Parameter;
2819 for (FAI = 0; FAI < NParameters; ++FAI)
2820 if (
M->Parameters[FAI].Name == FA.
Name)
2823 if (FAI >= NParameters) {
2824 assert(M &&
"expected macro to be defined");
2825 return Error(IDLoc,
"parameter named '" + FA.
Name +
2826 "' does not exist for macro '" +
M->Name +
"'");
2831 if (!FA.
Value.empty()) {
2836 if (FALocs.
size() <= PI)
2839 FALocs[PI] = Lexer.
getLoc();
2847 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2848 if (
A[FAI].empty()) {
2849 if (
M->Parameters[FAI].Required) {
2851 "missing value for required parameter "
2852 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2856 if (!
M->Parameters[FAI].Value.empty())
2857 A[FAI] =
M->Parameters[FAI].Value;
2866 return TokError(
"too many positional arguments");
2873 if (ActiveMacros.size() == MaxNestingDepth) {
2874 std::ostringstream MaxNestingDepthError;
2875 MaxNestingDepthError <<
"macros cannot be nested more than "
2876 << MaxNestingDepth <<
" levels deep."
2877 <<
" Use -asm-macro-max-nesting-depth to increase "
2879 return TokError(MaxNestingDepthError.str());
2882 MCAsmMacroArguments
A;
2883 if (parseMacroArguments(M,
A))
2891 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2892 return Error(getTok().getLoc(),
"Wrong number of arguments");
2893 if (expandMacro(
OS, *M,
M->Parameters,
A,
true))
2898 OS <<
".endmacro\n";
2900 std::unique_ptr<MemoryBuffer> Instantiation =
2905 MacroInstantiation *
MI =
new MacroInstantiation{
2906 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2907 ActiveMacros.push_back(
MI);
2909 ++NumOfMacroInstantiations;
2919void AsmParser::handleMacroExit() {
2921 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2925 delete ActiveMacros.back();
2926 ActiveMacros.pop_back();
2929bool AsmParser::parseAssignment(
StringRef Name, AssignmentKind Kind) {
2932 SMLoc ExprLoc = getTok().getLoc();
2934 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2946 if (discardLTOSymbol(
Name))
2951 case AssignmentKind::Equal:
2954 case AssignmentKind::Set:
2955 case AssignmentKind::Equiv:
2959 case AssignmentKind::LTOSetConditional:
2961 return Error(ExprLoc,
"expected identifier");
2973bool AsmParser::parseIdentifier(
StringRef &Res) {
2980 SMLoc PrefixLoc = getLexer().getLoc();
2992 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
3006 Res = getTok().getIdentifier();
3018bool AsmParser::parseDirectiveSet(
StringRef IDVal, AssignmentKind Kind) {
3020 if (
check(parseIdentifier(
Name),
"expected identifier") || parseComma() ||
3021 parseAssignment(
Name, Kind))
3026bool AsmParser::parseEscapedString(std::string &Data) {
3031 StringRef Str = getTok().getStringContents();
3032 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
3033 if (Str[i] !=
'\\') {
3042 return TokError(
"unexpected backslash at end of string");
3045 if (Str[i] ==
'x' || Str[i] ==
'X') {
3046 size_t length = Str.size();
3047 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
3048 return TokError(
"invalid hexadecimal escape sequence");
3053 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3054 Value =
Value * 16 + hexDigitValue(Str[++i]);
3061 if ((
unsigned)(Str[i] -
'0') <= 7) {
3063 unsigned Value = Str[i] -
'0';
3065 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3069 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3076 return TokError(
"invalid octal escape sequence (out of range)");
3086 return TokError(
"invalid escape sequence (unrecognized character)");
3088 case 'b': Data +=
'\b';
break;
3089 case 'f': Data +=
'\f';
break;
3090 case 'n': Data +=
'\n';
break;
3091 case 'r': Data +=
'\r';
break;
3092 case 't': Data +=
'\t';
break;
3093 case '"': Data +=
'"';
break;
3094 case '\\': Data +=
'\\';
break;
3102bool AsmParser::parseAngleBracketString(std::string &Data) {
3103 SMLoc EndLoc, StartLoc = getTok().getLoc();
3105 const char *StartChar = StartLoc.
getPointer() + 1;
3106 const char *EndChar = EndLoc.
getPointer() - 1;
3107 jumpToLoc(EndLoc, CurBuffer);
3120bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
3121 auto parseOp = [&]() ->
bool {
3123 if (checkForValidSection())
3128 if (parseEscapedString(Data))
3130 getStreamer().emitBytes(Data);
3133 getStreamer().emitBytes(
StringRef(
"\0", 1));
3137 return parseMany(parseOp);
3142bool AsmParser::parseDirectiveReloc(
SMLoc DirectiveLoc) {
3144 const MCExpr *Expr =
nullptr;
3147 if (parseExpression(
Offset))
3160 if (parseExpression(Expr))
3165 return Error(ExprLoc,
"expression must be relocatable");
3173 if (std::optional<std::pair<bool, std::string>> Err =
3174 getStreamer().emitRelocDirective(*
Offset,
Name, Expr, DirectiveLoc,
3176 return Error(Err->first ? NameLoc : OffsetLoc, Err->second);
3183bool AsmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
3184 auto parseOp = [&]() ->
bool {
3186 SMLoc ExprLoc = getLexer().getLoc();
3187 if (checkForValidSection() || parseExpression(
Value))
3192 uint64_t IntValue = MCE->getValue();
3194 return Error(ExprLoc,
"out of range literal value");
3195 getStreamer().emitIntValue(IntValue,
Size);
3197 getStreamer().emitValue(
Value,
Size, ExprLoc);
3201 return parseMany(parseOp);
3207 return Asm.TokError(
"unknown token in expression");
3208 SMLoc ExprLoc = Asm.getTok().getLoc();
3209 APInt IntValue = Asm.getTok().getAPIntVal();
3211 if (!IntValue.
isIntN(128))
3212 return Asm.Error(ExprLoc,
"out of range literal value");
3213 if (!IntValue.
isIntN(64)) {
3226bool AsmParser::parseDirectiveOctaValue(
StringRef IDVal) {
3227 auto parseOp = [&]() ->
bool {
3228 if (checkForValidSection())
3234 getStreamer().emitInt64(lo);
3235 getStreamer().emitInt64(hi);
3237 getStreamer().emitInt64(hi);
3238 getStreamer().emitInt64(lo);
3243 return parseMany(parseOp);
3257 return TokError(Lexer.
getErr());
3260 return TokError(
"unexpected token in directive");
3272 return TokError(
"invalid floating point literal");
3274 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3276 return TokError(
"invalid floating point literal");
3283 Res =
Value.bitcastToAPInt();
3290bool AsmParser::parseDirectiveRealValue(
StringRef IDVal,
3292 auto parseOp = [&]() ->
bool {
3294 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3301 return parseMany(parseOp);
3306bool AsmParser::parseDirectiveZero() {
3309 if (checkForValidSection() || parseExpression(NumBytes))
3315 if (parseAbsoluteExpression(Val))
3321 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3328bool AsmParser::parseDirectiveFill() {
3331 if (checkForValidSection() || parseExpression(NumValues))
3334 int64_t FillSize = 1;
3335 int64_t FillExpr = 0;
3337 SMLoc SizeLoc, ExprLoc;
3340 SizeLoc = getTok().getLoc();
3341 if (parseAbsoluteExpression(FillSize))
3344 ExprLoc = getTok().getLoc();
3345 if (parseAbsoluteExpression(FillExpr))
3353 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3357 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3361 if (!isUInt<32>(FillExpr) && FillSize > 4)
3362 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3364 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3371bool AsmParser::parseDirectiveOrg() {
3374 if (checkForValidSection() || parseExpression(
Offset))
3378 int64_t FillExpr = 0;
3380 if (parseAbsoluteExpression(FillExpr))
3385 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3391bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
3392 SMLoc AlignmentLoc = getLexer().getLoc();
3395 bool HasFillExpr =
false;
3396 int64_t FillExpr = 0;
3397 int64_t MaxBytesToFill = 0;
3400 auto parseAlign = [&]() ->
bool {
3401 if (parseAbsoluteExpression(Alignment))
3409 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3413 if (parseTokenLoc(MaxBytesLoc) ||
3414 parseAbsoluteExpression(MaxBytesToFill))
3420 if (checkForValidSection())
3424 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3431 bool ReturnVal =
false;
3436 if (Alignment >= 32) {
3437 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3441 Alignment = 1ULL << Alignment;
3449 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3450 Alignment = llvm::bit_floor<uint64_t>(Alignment);
3452 if (!isUInt<32>(Alignment)) {
3453 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3454 Alignment = 1u << 31;
3458 if (HasFillExpr && FillExpr != 0) {
3459 MCSection *Sec = getStreamer().getCurrentSectionOnly();
3462 Warning(FillExprLoc,
"ignoring non-zero fill value in " +
3471 if (MaxBytesToFill < 1) {
3472 ReturnVal |=
Error(MaxBytesLoc,
3473 "alignment directive can never be satisfied in this "
3474 "many bytes, ignoring maximum bytes expression");
3478 if (MaxBytesToFill >= Alignment) {
3479 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3488 assert(Section &&
"must have section to emit alignment");
3489 bool useCodeAlign =
Section->useCodeAlign();
3490 if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) &&
3491 ValueSize == 1 && useCodeAlign) {
3492 getStreamer().emitCodeAlignment(
3493 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3496 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3506bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
3508 int64_t FileNumber = -1;
3510 FileNumber = getTok().getIntVal();
3514 return TokError(
"negative file number");
3521 if (parseEscapedString(Path))
3526 std::string FilenameData;
3528 if (
check(FileNumber == -1,
3529 "explicit path specified, but no file number") ||
3530 parseEscapedString(FilenameData))
3539 bool HasMD5 =
false;
3541 std::optional<StringRef>
Source;
3542 bool HasSource =
false;
3543 std::string SourceString;
3548 "unexpected token in '.file' directive") ||
3549 parseIdentifier(Keyword))
3551 if (Keyword ==
"md5") {
3553 if (
check(FileNumber == -1,
3554 "MD5 checksum specified, but no file number") ||
3557 }
else if (Keyword ==
"source") {
3559 if (
check(FileNumber == -1,
3560 "source specified, but no file number") ||
3562 "unexpected token in '.file' directive") ||
3563 parseEscapedString(SourceString))
3566 return TokError(
"unexpected token in '.file' directive");
3570 if (FileNumber == -1) {
3574 if (getContext().getAsmInfo()->hasSingleParameterDotFile())
3575 getStreamer().emitFileDirective(Filename);
3585 std::optional<MD5::MD5Result> CKMem;
3588 for (
unsigned i = 0; i != 8; ++i) {
3589 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3590 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3595 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3596 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3599 if (FileNumber == 0) {
3603 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
3606 FileNumber, Directory, Filename, CKMem, Source);
3613 ReportedInconsistentMD5 =
true;
3614 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3623bool AsmParser::parseDirectiveLine() {
3626 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
3641bool AsmParser::parseDirectiveLoc() {
3642 int64_t FileNumber = 0, LineNumber = 0;
3643 SMLoc Loc = getTok().getLoc();
3644 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
3646 "file number less than one in '.loc' directive") ||
3647 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
3648 "unassigned file number in '.loc' directive"))
3653 LineNumber = getTok().getIntVal();
3655 return TokError(
"line number less than zero in '.loc' directive");
3659 int64_t ColumnPos = 0;
3661 ColumnPos = getTok().getIntVal();
3663 return TokError(
"column position less than zero in '.loc' directive");
3667 auto PrevFlags = getContext().getCurrentDwarfLoc().getFlags();
3672 auto parseLocOp = [&]() ->
bool {
3674 SMLoc Loc = getTok().getLoc();
3675 if (parseIdentifier(
Name))
3676 return TokError(
"unexpected token in '.loc' directive");
3678 if (
Name ==
"basic_block")
3680 else if (
Name ==
"prologue_end")
3682 else if (
Name ==
"epilogue_begin")
3684 else if (
Name ==
"is_stmt") {
3685 Loc = getTok().getLoc();
3687 if (parseExpression(
Value))
3691 int Value = MCE->getValue();
3693 Flags &= ~DWARF2_FLAG_IS_STMT;
3694 else if (
Value == 1)
3697 return Error(Loc,
"is_stmt value not 0 or 1");
3699 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3701 }
else if (
Name ==
"isa") {
3702 Loc = getTok().getLoc();
3704 if (parseExpression(
Value))
3708 int Value = MCE->getValue();
3710 return Error(Loc,
"isa number less than zero");
3713 return Error(Loc,
"isa number not a constant value");
3715 }
else if (
Name ==
"discriminator") {
3716 if (parseAbsoluteExpression(Discriminator))
3719 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3724 if (parseMany(parseLocOp,
false ))
3727 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3735bool AsmParser::parseDirectiveStabs() {
3736 return TokError(
"unsupported directive '.stabs'");
3741bool AsmParser::parseDirectiveCVFile() {
3742 SMLoc FileNumberLoc = getTok().getLoc();
3745 std::string Checksum;
3748 if (parseIntToken(FileNumber,
3749 "expected file number in '.cv_file' directive") ||
3750 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3752 "unexpected token in '.cv_file' directive") ||
3753 parseEscapedString(Filename))
3757 "unexpected token in '.cv_file' directive") ||
3758 parseEscapedString(Checksum) ||
3759 parseIntToken(ChecksumKind,
3760 "expected checksum kind in '.cv_file' directive") ||
3765 Checksum = fromHex(Checksum);
3766 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3767 memcpy(CKMem, Checksum.data(), Checksum.size());
3771 if (!getStreamer().emitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
3772 static_cast<uint8_t
>(ChecksumKind)))
3773 return Error(FileNumberLoc,
"file number already allocated");
3778bool AsmParser::parseCVFunctionId(int64_t &
FunctionId,
3781 return parseTokenLoc(Loc) ||
3782 parseIntToken(
FunctionId,
"expected function id in '" + DirectiveName +
3784 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3785 "expected function id within range [0, UINT_MAX)");
3788bool AsmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
3790 return parseTokenLoc(Loc) ||
3791 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
3793 check(FileNumber < 1, Loc,
"file number less than one in '" +
3794 DirectiveName +
"' directive") ||
3795 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3796 "unassigned file number in '" + DirectiveName +
"' directive");
3803bool AsmParser::parseDirectiveCVFuncId() {
3804 SMLoc FunctionIdLoc = getTok().getLoc();
3807 if (parseCVFunctionId(
FunctionId,
".cv_func_id") || parseEOL())
3810 if (!getStreamer().emitCVFuncIdDirective(
FunctionId))
3811 return Error(FunctionIdLoc,
"function id already allocated");
3824bool AsmParser::parseDirectiveCVInlineSiteId() {
3825 SMLoc FunctionIdLoc = getTok().getLoc();
3833 if (parseCVFunctionId(
FunctionId,
".cv_inline_site_id"))
3838 getTok().getIdentifier() !=
"within"),
3839 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3844 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3849 getTok().getIdentifier() !=
"inlined_at"),
3850 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3856 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3857 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3862 IACol = getTok().getIntVal();
3869 if (!getStreamer().emitCVInlineSiteIdDirective(
FunctionId, IAFunc, IAFile,
3870 IALine, IACol, FunctionIdLoc))
3871 return Error(FunctionIdLoc,
"function id already allocated");
3883bool AsmParser::parseDirectiveCVLoc() {
3884 SMLoc DirectiveLoc = getTok().getLoc();
3886 if (parseCVFunctionId(
FunctionId,
".cv_loc") ||
3887 parseCVFileId(FileNumber,
".cv_loc"))
3890 int64_t LineNumber = 0;
3892 LineNumber = getTok().getIntVal();
3894 return TokError(
"line number less than zero in '.cv_loc' directive");
3898 int64_t ColumnPos = 0;
3900 ColumnPos = getTok().getIntVal();
3902 return TokError(
"column position less than zero in '.cv_loc' directive");
3906 bool PrologueEnd =
false;
3909 auto parseOp = [&]() ->
bool {
3911 SMLoc Loc = getTok().getLoc();
3912 if (parseIdentifier(
Name))
3913 return TokError(
"unexpected token in '.cv_loc' directive");
3914 if (
Name ==
"prologue_end")
3916 else if (
Name ==
"is_stmt") {
3917 Loc = getTok().getLoc();
3919 if (parseExpression(
Value))
3923 if (
const auto *MCE = dyn_cast<MCConstantExpr>(
Value))
3924 IsStmt = MCE->getValue();
3927 return Error(Loc,
"is_stmt value not 0 or 1");
3929 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3934 if (parseMany(parseOp,
false ))
3937 getStreamer().emitCVLocDirective(
FunctionId, FileNumber, LineNumber,
3938 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
3945bool AsmParser::parseDirectiveCVLinetable() {
3948 SMLoc Loc = getTok().getLoc();
3949 if (parseCVFunctionId(
FunctionId,
".cv_linetable") || parseComma() ||
3950 parseTokenLoc(Loc) ||
3951 check(parseIdentifier(FnStartName), Loc,
3952 "expected identifier in directive") ||
3953 parseComma() || parseTokenLoc(Loc) ||
3954 check(parseIdentifier(FnEndName), Loc,
3955 "expected identifier in directive"))
3958 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3959 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3961 getStreamer().emitCVLinetableDirective(
FunctionId, FnStartSym, FnEndSym);
3967bool AsmParser::parseDirectiveCVInlineLinetable() {
3968 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3970 SMLoc Loc = getTok().getLoc();
3971 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3972 parseTokenLoc(Loc) ||
3975 "expected SourceField in '.cv_inline_linetable' directive") ||
3976 check(SourceFileId <= 0, Loc,
3977 "File id less than zero in '.cv_inline_linetable' directive") ||
3978 parseTokenLoc(Loc) ||
3981 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
3982 check(SourceLineNum < 0, Loc,
3983 "Line number less than zero in '.cv_inline_linetable' directive") ||
3984 parseTokenLoc(Loc) ||
check(parseIdentifier(FnStartName), Loc,
3985 "expected identifier in directive") ||
3986 parseTokenLoc(Loc) ||
check(parseIdentifier(FnEndName), Loc,
3987 "expected identifier in directive"))
3993 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3994 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3995 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3996 SourceLineNum, FnStartSym,
4001void AsmParser::initializeCVDefRangeTypeMap() {
4002 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
4003 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
4004 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4005 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4010bool AsmParser::parseDirectiveCVDefRange() {
4012 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
4014 Loc = getLexer().getLoc();
4016 if (parseIdentifier(GapStartName))
4017 return Error(Loc,
"expected identifier in directive");
4018 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
4020 Loc = getLexer().getLoc();
4022 if (parseIdentifier(GapEndName))
4023 return Error(Loc,
"expected identifier in directive");
4024 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
4026 Ranges.push_back({GapStartSym, GapEndSym});
4032 "expected comma before def_range type in .cv_def_range directive") ||
4033 parseIdentifier(CVDefRangeTypeStr))
4034 return Error(Loc,
"expected def_range type in directive");
4037 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4038 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4040 : CVTypeIt->getValue();
4042 case CVDR_DEFRANGE_REGISTER: {
4044 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4045 ".cv_def_range directive") ||
4046 parseAbsoluteExpression(DRRegister))
4047 return Error(Loc,
"expected register number");
4052 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4055 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4058 "expected comma before offset in .cv_def_range directive") ||
4059 parseAbsoluteExpression(DROffset))
4060 return Error(Loc,
"expected offset value");
4064 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4067 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4069 int64_t DROffsetInParent;
4070 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4071 ".cv_def_range directive") ||
4072 parseAbsoluteExpression(DRRegister))
4073 return Error(Loc,
"expected register number");
4075 "expected comma before offset in .cv_def_range directive") ||
4076 parseAbsoluteExpression(DROffsetInParent))
4077 return Error(Loc,
"expected offset value");
4083 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4086 case CVDR_DEFRANGE_REGISTER_REL: {
4089 int64_t DRBasePointerOffset;
4090 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4091 ".cv_def_range directive") ||
4092 parseAbsoluteExpression(DRRegister))
4093 return Error(Loc,
"expected register value");
4096 "expected comma before flag value in .cv_def_range directive") ||
4097 parseAbsoluteExpression(DRFlags))
4098 return Error(Loc,
"expected flag value");
4099 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4100 "in .cv_def_range directive") ||
4101 parseAbsoluteExpression(DRBasePointerOffset))
4102 return Error(Loc,
"expected base pointer offset value");
4106 DRHdr.
Flags = DRFlags;
4108 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4112 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4119bool AsmParser::parseDirectiveCVString() {
4121 if (checkForValidSection() || parseEscapedString(Data))
4125 std::pair<StringRef, unsigned> Insertion =
4126 getCVContext().addToStringTable(Data);
4127 getStreamer().emitInt32(Insertion.second);
4133bool AsmParser::parseDirectiveCVStringTable() {
4134 getStreamer().emitCVStringTableDirective();
4140bool AsmParser::parseDirectiveCVFileChecksums() {
4141 getStreamer().emitCVFileChecksumsDirective();
4147bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4149 if (parseIntToken(FileNo,
"expected identifier in directive"))
4153 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4159bool AsmParser::parseDirectiveCVFPOData() {
4160 SMLoc DirLoc = getLexer().getLoc();
4162 if (parseIdentifier(ProcName))
4163 return TokError(
"expected symbol name");
4166 MCSymbol *ProcSym = getContext().getOrCreateSymbol(ProcName);
4167 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4173bool AsmParser::parseDirectiveCFISections() {
4180 if (parseIdentifier(
Name))
4181 return TokError(
"expected .eh_frame or .debug_frame");
4182 if (
Name ==
".eh_frame")
4184 else if (
Name ==
".debug_frame")
4192 getStreamer().emitCFISections(EH,
Debug);
4198bool AsmParser::parseDirectiveCFIStartProc() {
4199 CFIStartProcLoc = StartTokLoc;
4204 "unexpected token") ||
4214 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4220bool AsmParser::parseDirectiveCFIEndProc() {
4221 CFIStartProcLoc = std::nullopt;
4226 getStreamer().emitCFIEndProc();
4231bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4232 SMLoc DirectiveLoc) {
4236 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4238 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
4240 return parseAbsoluteExpression(
Register);
4247bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
4249 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4250 parseAbsoluteExpression(
Offset) || parseEOL())
4259bool AsmParser::parseDirectiveCFIDefCfaOffset(
SMLoc DirectiveLoc) {
4261 if (parseAbsoluteExpression(
Offset) || parseEOL())
4264 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4270bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
4271 int64_t Register1 = 0, Register2 = 0;
4272 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4273 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4276 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4282bool AsmParser::parseDirectiveCFIWindowSave(
SMLoc DirectiveLoc) {
4285 getStreamer().emitCFIWindowSave(DirectiveLoc);
4291bool AsmParser::parseDirectiveCFIAdjustCfaOffset(
SMLoc DirectiveLoc) {
4292 int64_t Adjustment = 0;
4293 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4296 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4302bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
4304 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4307 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4313bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(
SMLoc DirectiveLoc) {
4315 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4316 parseAbsoluteExpression(
Offset) || parseComma() ||
4327bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
4331 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4332 parseAbsoluteExpression(
Offset) || parseEOL())
4341bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
4344 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4345 parseAbsoluteExpression(
Offset) || parseEOL())
4353 if (Encoding & ~0xff)
4359 const unsigned Format = Encoding & 0xf;
4366 const unsigned Application = Encoding & 0x70;
4378bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4379 int64_t Encoding = 0;
4380 if (parseAbsoluteExpression(Encoding))
4388 check(parseIdentifier(
Name),
"expected identifier in directive") ||
4395 getStreamer().emitCFIPersonality(
Sym, Encoding);
4397 getStreamer().emitCFILsda(
Sym, Encoding);
4403bool AsmParser::parseDirectiveCFIRememberState(
SMLoc DirectiveLoc) {
4406 getStreamer().emitCFIRememberState(DirectiveLoc);
4412bool AsmParser::parseDirectiveCFIRestoreState(
SMLoc DirectiveLoc) {
4415 getStreamer().emitCFIRestoreState(DirectiveLoc);
4421bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
4424 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4427 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4433bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
4435 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4438 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4444bool AsmParser::parseDirectiveCFIEscape(
SMLoc DirectiveLoc) {
4447 if (parseAbsoluteExpression(CurrValue))
4450 Values.push_back((uint8_t)CurrValue);
4455 if (parseAbsoluteExpression(CurrValue))
4458 Values.push_back((uint8_t)CurrValue);
4461 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4467bool AsmParser::parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc) {
4469 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4471 getStreamer().emitCFIReturnColumn(
Register);
4477bool AsmParser::parseDirectiveCFISignalFrame(
SMLoc DirectiveLoc) {
4481 getStreamer().emitCFISignalFrame();
4487bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
4490 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4493 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4503 AltMacroMode = (
Directive ==
".altmacro");
4513 setMacrosEnabled(
Directive ==
".macros_on");
4519bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
4521 if (parseIdentifier(
Name))
4522 return TokError(
"expected identifier in '.macro' directive");
4531 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4533 "' should be the last parameter");
4536 if (parseIdentifier(Parameter.
Name))
4537 return TokError(
"expected identifier in '.macro' directive");
4541 if (CurrParam.Name == Parameter.
Name)
4542 return TokError(
"macro '" +
Name +
"' has multiple parameters"
4543 " named '" + Parameter.
Name +
"'");
4551 QualLoc = Lexer.
getLoc();
4552 if (parseIdentifier(Qualifier))
4553 return Error(QualLoc,
"missing parameter qualifier for "
4554 "'" + Parameter.
Name +
"' in macro '" +
Name +
"'");
4556 if (Qualifier ==
"req")
4558 else if (Qualifier ==
"vararg")
4561 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4562 "for '" + Parameter.
Name +
"' in macro '" +
Name +
"'");
4570 ParamLoc = Lexer.
getLoc();
4571 if (parseMacroArgument(Parameter.
Value,
false ))
4575 Warning(ParamLoc,
"pointless default value for required parameter "
4576 "'" + Parameter.
Name +
"' in macro '" +
Name +
"'");
4589 AsmToken EndToken, StartToken = getTok();
4590 unsigned MacroDepth = 0;
4600 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4605 if (getTok().getIdentifier() ==
".endm" ||
4606 getTok().getIdentifier() ==
".endmacro") {
4607 if (MacroDepth == 0) {
4608 EndToken = getTok();
4611 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4618 }
else if (getTok().getIdentifier() ==
".macro") {
4624 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4628 eatToEndOfStatement();
4631 if (getContext().lookupMacro(
Name)) {
4632 return Error(DirectiveLoc,
"macro '" +
Name +
"' is already defined");
4638 checkForBadMacro(DirectiveLoc,
Name, Body, Parameters);
4642 getContext().defineMacro(
Name, std::move(
Macro));
4666 if (NParameters == 0)
4669 bool NamedParametersFound =
false;
4670 bool PositionalParametersFound =
false;
4675 while (!Body.
empty()) {
4677 std::size_t
End = Body.
size(), Pos = 0;
4678 for (; Pos !=
End; ++Pos) {
4681 if (Body[Pos] ==
'\\' && Pos + 1 !=
End)
4685 if (Body[Pos] !=
'$' || Pos + 1 ==
End)
4687 char Next = Body[Pos + 1];
4688 if (Next ==
'$' || Next ==
'n' ||
4689 isdigit(
static_cast<unsigned char>(Next)))
4697 if (Body[Pos] ==
'$') {
4698 switch (Body[Pos + 1]) {
4705 PositionalParametersFound =
true;
4710 PositionalParametersFound =
true;
4716 unsigned I = Pos + 1;
4720 const char *Begin = Body.
data() + Pos + 1;
4727 if (
Index == NParameters) {
4728 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4734 NamedParametersFound =
true;
4742 if (!NamedParametersFound && PositionalParametersFound)
4743 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4744 "used in macro body, possible positional parameter "
4745 "found in body which will have no effect");
4754 if (!isInsideMacroInstantiation())
4755 return TokError(
"unexpected '" +
Directive +
"' in file, "
4756 "no current macro definition");
4759 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4760 TheCondState = TheCondStack.back();
4761 TheCondStack.pop_back();
4773 return TokError(
"unexpected token in '" +
Directive +
"' directive");
4777 if (isInsideMacroInstantiation()) {
4784 return TokError(
"unexpected '" +
Directive +
"' in file, "
4785 "no current macro definition");
4790bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
4793 if (parseTokenLoc(Loc) ||
4795 "expected identifier in '.purgem' directive") ||
4799 if (!getContext().lookupMacro(
Name))
4800 return Error(DirectiveLoc,
"macro '" +
Name +
"' is not defined");
4802 getContext().undefineMacro(
Name);
4804 <<
"Un-defining macro: " <<
Name <<
"\n");
4810bool AsmParser::parseDirectiveBundleAlignMode() {
4813 SMLoc ExprLoc = getLexer().getLoc();
4814 int64_t AlignSizePow2;
4815 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4817 check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
4818 "invalid bundle alignment size (expected between 0 and 30)"))
4821 getStreamer().emitBundleAlignMode(
Align(1ULL << AlignSizePow2));
4827bool AsmParser::parseDirectiveBundleLock() {
4828 if (checkForValidSection())
4830 bool AlignToEnd =
false;
4833 SMLoc Loc = getTok().getLoc();
4834 const char *kInvalidOptionError =
4835 "invalid option for '.bundle_lock' directive";
4838 if (
check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
4839 check(Option !=
"align_to_end", Loc, kInvalidOptionError) || parseEOL())
4844 getStreamer().emitBundleLock(AlignToEnd);
4850bool AsmParser::parseDirectiveBundleUnlock() {
4851 if (checkForValidSection() || parseEOL())
4854 getStreamer().emitBundleUnlock();
4860bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
4863 if (checkForValidSection() || parseExpression(NumBytes))
4866 int64_t FillExpr = 0;
4868 if (parseAbsoluteExpression(FillExpr))
4874 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4881bool AsmParser::parseDirectiveDCB(
StringRef IDVal,
unsigned Size) {
4884 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4887 if (NumValues < 0) {
4888 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4896 SMLoc ExprLoc = getLexer().getLoc();
4897 if (parseExpression(
Value))
4903 uint64_t IntValue = MCE->getValue();
4905 return Error(ExprLoc,
"literal value out of range for directive");
4906 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
4907 getStreamer().emitIntValue(IntValue,
Size);
4909 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
4910 getStreamer().emitValue(
Value,
Size, ExprLoc);
4921 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4924 if (NumValues < 0) {
4925 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4933 if (parseRealValue(Semantics, AsInt) || parseEOL())
4936 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
4945bool AsmParser::parseDirectiveDS(
StringRef IDVal,
unsigned Size) {
4948 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4952 if (NumValues < 0) {
4953 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4957 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
4958 getStreamer().emitFill(
Size, 0);
4965bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4966 if (checkForValidSection())
4969 auto parseOp = [&]() ->
bool {
4971 if (parseExpression(
Value))
4974 getStreamer().emitSLEB128Value(
Value);
4976 getStreamer().emitULEB128Value(
Value);
4980 return parseMany(parseOp);
4985bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4986 auto parseOp = [&]() ->
bool {
4988 SMLoc Loc = getTok().getLoc();
4989 if (parseIdentifier(
Name))
4990 return Error(Loc,
"expected identifier");
4992 if (discardLTOSymbol(
Name))
5000 return Error(Loc,
"non-local symbol required");
5002 if (!getStreamer().emitSymbolAttribute(
Sym, Attr))
5003 return Error(Loc,
"unable to emit symbol attribute");
5007 return parseMany(parseOp);
5012bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5013 if (checkForValidSection())
5016 SMLoc IDLoc = getLexer().getLoc();
5018 if (parseIdentifier(
Name))
5019 return TokError(
"expected identifier in directive");
5028 SMLoc SizeLoc = getLexer().getLoc();
5029 if (parseAbsoluteExpression(
Size))
5032 int64_t Pow2Alignment = 0;
5033 SMLoc Pow2AlignmentLoc;
5036 Pow2AlignmentLoc = getLexer().getLoc();
5037 if (parseAbsoluteExpression(Pow2Alignment))
5042 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5045 if ((!IsLocal && Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) ||
5048 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5049 Pow2Alignment =
Log2_64(Pow2Alignment);
5059 return Error(SizeLoc,
"size must be non-negative");
5061 Sym->redefineIfPossible();
5062 if (!
Sym->isUndefined())
5063 return Error(IDLoc,
"invalid symbol redefinition");
5067 getStreamer().emitLocalCommonSymbol(
Sym,
Size,
5068 Align(1ULL << Pow2Alignment));
5072 getStreamer().emitCommonSymbol(
Sym,
Size,
Align(1ULL << Pow2Alignment));
5078bool AsmParser::parseDirectiveAbort() {
5080 SMLoc Loc = getLexer().getLoc();
5082 StringRef Str = parseStringToEndOfStatement();
5087 return Error(Loc,
".abort detected. Assembly stopping.");
5089 return Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
5097bool AsmParser::parseDirectiveInclude() {
5100 SMLoc IncludeLoc = getTok().getLoc();
5103 "expected string in '.include' directive") ||
5104 parseEscapedString(Filename) ||
5106 "unexpected token in '.include' directive") ||
5109 check(enterIncludeFile(Filename), IncludeLoc,
5110 "Could not find include file '" + Filename +
"'"))
5118bool AsmParser::parseDirectiveIncbin() {
5121 SMLoc IncbinLoc = getTok().getLoc();
5123 "expected string in '.incbin' directive") ||
5124 parseEscapedString(Filename))
5128 const MCExpr *Count =
nullptr;
5129 SMLoc SkipLoc, CountLoc;
5134 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5138 CountLoc = getTok().getLoc();
5139 if (parseExpression(Count))
5147 if (
check(Skip < 0, SkipLoc,
"skip is negative"))
5151 if (processIncbinFile(Filename, Skip, Count, CountLoc))
5152 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
5158bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
5159 TheCondStack.push_back(TheCondState);
5161 if (TheCondState.
Ignore) {
5162 eatToEndOfStatement();
5165 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5175 ExprValue = ExprValue == 0;
5178 ExprValue = ExprValue >= 0;
5181 ExprValue = ExprValue > 0;
5184 ExprValue = ExprValue <= 0;
5187 ExprValue = ExprValue < 0;
5191 TheCondState.
CondMet = ExprValue;
5200bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
5201 TheCondStack.push_back(TheCondState);
5204 if (TheCondState.
Ignore) {
5205 eatToEndOfStatement();
5207 StringRef Str = parseStringToEndOfStatement();
5212 TheCondState.
CondMet = ExpectBlank == Str.empty();
5222bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
5223 TheCondStack.push_back(TheCondState);
5226 if (TheCondState.
Ignore) {
5227 eatToEndOfStatement();
5234 StringRef Str2 = parseStringToEndOfStatement();
5248bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
5251 return TokError(
"expected string parameter for '.ifeqs' directive");
5252 return TokError(
"expected string parameter for '.ifnes' directive");
5255 StringRef String1 = getTok().getStringContents();
5261 "expected comma after first string for '.ifeqs' directive");
5262 return TokError(
"expected comma after first string for '.ifnes' directive");
5269 return TokError(
"expected string parameter for '.ifeqs' directive");
5270 return TokError(
"expected string parameter for '.ifnes' directive");
5273 StringRef String2 = getTok().getStringContents();
5276 TheCondStack.push_back(TheCondState);
5278 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5286bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
5288 TheCondStack.push_back(TheCondState);
5291 if (TheCondState.
Ignore) {
5292 eatToEndOfStatement();
5294 if (
check(parseIdentifier(
Name),
"expected identifier after '.ifdef'") ||
5312bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
5315 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5316 " .if or an .elseif");
5319 bool LastIgnoreState =
false;
5320 if (!TheCondStack.empty())
5321 LastIgnoreState = TheCondStack.back().Ignore;
5322 if (LastIgnoreState || TheCondState.
CondMet) {
5323 TheCondState.
Ignore =
true;
5324 eatToEndOfStatement();
5327 if (parseAbsoluteExpression(ExprValue))
5333 TheCondState.
CondMet = ExprValue;
5342bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
5348 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5349 " an .if or an .elseif");
5351 bool LastIgnoreState =
false;
5352 if (!TheCondStack.empty())
5353 LastIgnoreState = TheCondStack.back().Ignore;
5354 if (LastIgnoreState || TheCondState.
CondMet)
5355 TheCondState.
Ignore =
true;
5357 TheCondState.
Ignore =
false;
5364bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
5377bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
5378 if (!TheCondStack.empty()) {
5379 if (TheCondStack.back().Ignore) {
5380 eatToEndOfStatement();
5386 return Error(L,
".err encountered");
5388 StringRef Message =
".error directive invoked in source file";
5391 return TokError(
".error argument must be a string");
5393 Message = getTok().getStringContents();
5397 return Error(L, Message);
5402bool AsmParser::parseDirectiveWarning(
SMLoc L) {
5403 if (!TheCondStack.empty()) {
5404 if (TheCondStack.back().Ignore) {
5405 eatToEndOfStatement();
5410 StringRef Message =
".warning directive invoked in source file";
5414 return TokError(
".warning argument must be a string");
5416 Message = getTok().getStringContents();
5427bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
5432 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5434 if (!TheCondStack.empty()) {
5435 TheCondState = TheCondStack.back();
5436 TheCondStack.pop_back();
5442void AsmParser::initializeDirectiveKindMap() {
5449 DirectiveKindMap[
".set"] = DK_SET;
5450 DirectiveKindMap[
".equ"] = DK_EQU;
5451 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5452 DirectiveKindMap[
".ascii"] = DK_ASCII;
5453 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5454 DirectiveKindMap[
".string"] = DK_STRING;
5455 DirectiveKindMap[
".byte"] = DK_BYTE;
5456 DirectiveKindMap[
".short"] = DK_SHORT;
5457 DirectiveKindMap[
".value"] = DK_VALUE;
5458 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5459 DirectiveKindMap[
".long"] = DK_LONG;
5460 DirectiveKindMap[
".int"] = DK_INT;
5461 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5462 DirectiveKindMap[
".quad"] = DK_QUAD;
5463 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5464 DirectiveKindMap[
".octa"] = DK_OCTA;
5465 DirectiveKindMap[
".single"] = DK_SINGLE;
5466 DirectiveKindMap[
".float"] = DK_FLOAT;
5467 DirectiveKindMap[
".double"] = DK_DOUBLE;
5468 DirectiveKindMap[
".align"] = DK_ALIGN;
5469 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5470 DirectiveKindMap[
".balign"] = DK_BALIGN;
5471 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5472 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5473 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5474 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5475 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5476 DirectiveKindMap[
".org"] = DK_ORG;
5477 DirectiveKindMap[
".fill"] = DK_FILL;
5478 DirectiveKindMap[
".zero"] = DK_ZERO;
5479 DirectiveKindMap[
".extern"] = DK_EXTERN;
5480 DirectiveKindMap[
".globl"] = DK_GLOBL;
5481 DirectiveKindMap[
".global"] = DK_GLOBAL;
5482 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5483 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5484 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5485 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5486 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5487 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5488 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5489 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5490 DirectiveKindMap[
".cold"] = DK_COLD;
5491 DirectiveKindMap[
".comm"] = DK_COMM;
5492 DirectiveKindMap[
".common"] = DK_COMMON;
5493 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5494 DirectiveKindMap[
".abort"] = DK_ABORT;
5495 DirectiveKindMap[
".include"] = DK_INCLUDE;
5496 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5497 DirectiveKindMap[
".code16"] = DK_CODE16;
5498 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5499 DirectiveKindMap[
".rept"] = DK_REPT;
5500 DirectiveKindMap[
".rep"] = DK_REPT;
5501 DirectiveKindMap[
".irp"] = DK_IRP;
5502 DirectiveKindMap[
".irpc"] = DK_IRPC;
5503 DirectiveKindMap[
".endr"] = DK_ENDR;
5504 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5505 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5506 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5507 DirectiveKindMap[
".if"] = DK_IF;
5508 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5509 DirectiveKindMap[
".ifge"] = DK_IFGE;
5510 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5511 DirectiveKindMap[
".ifle"] = DK_IFLE;
5512 DirectiveKindMap[
".iflt"] = DK_IFLT;
5513 DirectiveKindMap[
".ifne"] = DK_IFNE;
5514 DirectiveKindMap[
".ifb"] = DK_IFB;
5515 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5516 DirectiveKindMap[
".ifc"] = DK_IFC;
5517 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5518 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5519 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5520 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5521 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5522 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5523 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5524 DirectiveKindMap[
".else"] = DK_ELSE;
5525 DirectiveKindMap[
".end"] = DK_END;
5526 DirectiveKindMap[
".endif"] = DK_ENDIF;
5527 DirectiveKindMap[
".skip"] = DK_SKIP;
5528 DirectiveKindMap[
".space"] = DK_SPACE;
5529 DirectiveKindMap[
".file"] = DK_FILE;
5530 DirectiveKindMap[
".line"] = DK_LINE;
5531 DirectiveKindMap[
".loc"] = DK_LOC;
5532 DirectiveKindMap[
".stabs"] = DK_STABS;
5533 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5534 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5535 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5536 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5537 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5538 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5539 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5540 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5541 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5542 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5543 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5544 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5545 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5546 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5547 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5548 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5549 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5550 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5551 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5552 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5553 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5554 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5555 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5556 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5557 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5558 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5559 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5560 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5561 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5562 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5563 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5564 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5565 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5566 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5567 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5568 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5569 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5570 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5571 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5572 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5573 DirectiveKindMap[
".macro"] = DK_MACRO;
5574 DirectiveKindMap[
".exitm"] = DK_EXITM;
5575 DirectiveKindMap[
".endm"] = DK_ENDM;
5576 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5577 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5578 DirectiveKindMap[
".err"] = DK_ERR;
5579 DirectiveKindMap[
".error"] = DK_ERROR;
5580 DirectiveKindMap[
".warning"] = DK_WARNING;
5581 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5582 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5583 DirectiveKindMap[
".reloc"] = DK_RELOC;
5584 DirectiveKindMap[
".dc"] = DK_DC;
5585 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5586 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5587 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5588 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5589 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5590 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5591 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5592 DirectiveKindMap[
".dcb"] = DK_DCB;
5593 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5594 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5595 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5596 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5597 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5598 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5599 DirectiveKindMap[
".ds"] = DK_DS;
5600 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5601 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5602 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5603 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5604 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5605 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5606 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5607 DirectiveKindMap[
".print"] = DK_PRINT;
5608 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5609 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5610 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5611 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5612 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5613 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5617 AsmToken EndToken, StartToken = getTok();
5619 unsigned NestLevel = 0;
5623 printError(DirectiveLoc,
"no matching '.endr' in definition");
5628 (getTok().getIdentifier() ==
".rep" ||
5629 getTok().getIdentifier() ==
".rept" ||
5630 getTok().getIdentifier() ==
".irp" ||
5631 getTok().getIdentifier() ==
".irpc")) {
5637 if (NestLevel == 0) {
5638 EndToken = getTok();
5641 printError(getTok().getLoc(),
5642 "unexpected token in '.endr' directive");
5651 eatToEndOfStatement();
5660 return &MacroLikeBodies.back();
5663void AsmParser::instantiateMacroLikeBody(
MCAsmMacro *M,
SMLoc DirectiveLoc,
5667 std::unique_ptr<MemoryBuffer> Instantiation =
5672 MacroInstantiation *
MI =
new MacroInstantiation{
5673 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5674 ActiveMacros.push_back(
MI);
5684bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
5686 SMLoc CountLoc = getTok().getLoc();
5687 if (parseExpression(CountExpr))
5691 if (!CountExpr->evaluateAsAbsolute(Count, getStreamer().getAssemblerPtr())) {
5692 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5695 if (
check(Count < 0, CountLoc,
"Count is negative") || parseEOL())
5709 if (expandMacro(
OS, *M, std::nullopt, std::nullopt,
false))
5712 instantiateMacroLikeBody(M, DirectiveLoc,
OS);
5719bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
5721 MCAsmMacroArguments
A;
5722 if (
check(parseIdentifier(Parameter.
Name),
5723 "expected identifier in '.irp' directive") ||
5724 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5737 for (
const MCAsmMacroArgument &Arg :
A) {
5740 if (expandMacro(
OS, *M, Parameter, Arg,
true))
5744 instantiateMacroLikeBody(M, DirectiveLoc,
OS);
5751bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
5753 MCAsmMacroArguments
A;
5755 if (
check(parseIdentifier(Parameter.
Name),
5756 "expected identifier in '.irpc' directive") ||
5757 parseComma() || parseMacroArguments(
nullptr,
A))
5760 if (
A.size() != 1 ||
A.front().size() != 1)
5761 return TokError(
"unexpected token in '.irpc' directive");
5775 StringRef Values =
A.front().front().getString();
5776 for (std::size_t
I = 0,
End = Values.
size();
I !=
End; ++
I) {
5777 MCAsmMacroArgument Arg;
5782 if (expandMacro(
OS, *M, Parameter, Arg,
true))
5786 instantiateMacroLikeBody(M, DirectiveLoc,
OS);
5791bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
5792 if (ActiveMacros.empty())
5793 return TokError(
"unmatched '.endr' directive");
5803bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
5806 SMLoc ExprLoc = getLexer().getLoc();
5807 if (parseExpression(
Value))
5811 return Error(ExprLoc,
"unexpected expression in _emit");
5813 if (!isUInt<8>(IntValue) && !isInt<8>(IntValue))
5814 return Error(ExprLoc,
"literal value out of range for directive");
5820bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
5822 SMLoc ExprLoc = getLexer().getLoc();
5823 if (parseExpression(
Value))
5827 return Error(ExprLoc,
"unexpected expression in align");
5830 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5836bool AsmParser::parseDirectivePrint(
SMLoc DirectiveLoc) {
5840 return Error(DirectiveLoc,
"expected double quoted string after .print");
5847bool AsmParser::parseDirectiveAddrsig() {
5850 getStreamer().emitAddrsig();
5854bool AsmParser::parseDirectiveAddrsigSym() {
5856 if (
check(parseIdentifier(
Name),
"expected identifier") || parseEOL())
5859 getStreamer().emitAddrsigSym(
Sym);
5863bool AsmParser::parseDirectivePseudoProbe() {
5870 if (parseIntToken(
Guid,
"unexpected token in '.pseudoprobe' directive"))
5873 if (parseIntToken(
Index,
"unexpected token in '.pseudoprobe' directive"))
5876 if (parseIntToken(
Type,
"unexpected token in '.pseudoprobe' directive"))
5879 if (parseIntToken(Attr,
"unexpected token in '.pseudoprobe' directive"))
5883 if (parseIntToken(Discriminator,
5884 "unexpected token in '.pseudoprobe' directive"))
5895 int64_t CallerGuid = 0;
5897 if (parseIntToken(CallerGuid,
5898 "unexpected token in '.pseudoprobe' directive"))
5906 int64_t CallerProbeId = 0;
5908 if (parseIntToken(CallerProbeId,
5909 "unexpected token in '.pseudoprobe' directive"))
5919 if (parseIdentifier(FnName))
5920 return Error(getLexer().getLoc(),
"unexpected token in '.pseudoprobe' directive");
5921 MCSymbol *FnSym = getContext().lookupSymbol(FnName);
5926 getStreamer().emitPseudoProbe(
Guid,
Index,
Type, Attr, Discriminator,
5927 InlineStack, FnSym);
5936bool AsmParser::parseDirectiveLTODiscard() {
5937 auto ParseOp = [&]() ->
bool {
5939 SMLoc Loc = getTok().getLoc();
5940 if (parseIdentifier(
Name))
5941 return Error(Loc,
"expected identifier");
5946 LTODiscardSymbols.
clear();
5947 return parseMany(ParseOp);
5973bool AsmParser::parseMSInlineAsm(
5974 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
5993 unsigned InputIdx = 0;
5994 unsigned OutputIdx = 0;
5997 if (parseCurlyBlockScope(AsmStrRewrites))
6000 ParseStatementInfo
Info(&AsmStrRewrites);
6001 bool StatementErr = parseStatement(Info, &SI);
6003 if (StatementErr ||
Info.ParseError) {
6005 printPendingErrors();
6010 assert(!hasPendingError() &&
"unexpected error from parseStatement");
6012 if (
Info.Opcode == ~0U)
6018 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
6023 !getTargetParser().OmitRegisterFromClobberLists(Operand.
getReg())) {
6024 unsigned NumDefs =
Desc.getNumDefs();
6033 if (SymName.
empty())
6041 if (Operand.
isImm()) {
6049 bool isOutput = (i == 1) &&
Desc.mayStore();
6056 OutputConstraints.
push_back((
"=" + Constraint).str());
6063 if (
Desc.operands()[i - 1].isBranchTarget())
6077 NumOutputs = OutputDecls.
size();
6078 NumInputs = InputDecls.
size();
6082 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
6084 Clobbers.
assign(ClobberRegs.
size(), std::string());
6085 for (
unsigned I = 0, E = ClobberRegs.
size();
I != E; ++
I) {
6091 if (NumOutputs || NumInputs) {
6092 unsigned NumExprs = NumOutputs + NumInputs;
6093 OpDecls.resize(NumExprs);
6094 Constraints.
resize(NumExprs);
6095 for (
unsigned i = 0; i < NumOutputs; ++i) {
6096 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6097 Constraints[i] = OutputConstraints[i];
6099 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6100 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6101 Constraints[
j] = InputConstraints[i];
6106 std::string AsmStringIR;
6110 const char *AsmStart = ASMString.
begin();
6111 const char *AsmEnd = ASMString.
end();
6113 for (
auto it = AsmStrRewrites.
begin(); it != AsmStrRewrites.
end(); ++it) {
6121 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6124 if (
unsigned Len = Loc - AsmStart)
6129 AsmStart = Loc + AR.
Len;
6133 unsigned AdditionalSkip = 0;
6155 size_t OffsetLen = OffsetName.
size();
6156 auto rewrite_it = std::find_if(
6158 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6159 (FusingAR.Kind == AOK_Input ||
6160 FusingAR.Kind == AOK_CallInput);
6162 if (rewrite_it == AsmStrRewrites.
end()) {
6163 OS <<
"offset " << OffsetName;
6165 OS <<
"${" << InputIdx++ <<
":P}";
6166 rewrite_it->Done =
true;
6168 OS <<
'$' << InputIdx++;
6169 rewrite_it->Done =
true;
6182 OS <<
"${" << InputIdx++ <<
":P}";
6184 OS <<
'$' << InputIdx++;
6187 OS <<
"${" << InputIdx++ <<
":P}";
6191 OS <<
"${" << OutputIdx++ <<
":P}";
6193 OS <<
'$' << OutputIdx++;
6198 case 8:
OS <<
"byte ptr ";
break;
6199 case 16:
OS <<
"word ptr ";
break;
6200 case 32:
OS <<
"dword ptr ";
break;
6201 case 64:
OS <<
"qword ptr ";
break;
6202 case 80:
OS <<
"xword ptr ";
break;
6203 case 128:
OS <<
"xmmword ptr ";
break;
6204 case 256:
OS <<
"ymmword ptr ";
break;
6214 if (getContext().getAsmInfo()->getAlignmentIsInBytes())
6219 unsigned Val = AR.
Val;
6221 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6222 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6234 AsmStart = Loc + AR.
Len + AdditionalSkip;
6238 if (AsmStart != AsmEnd)
6241 AsmString =
OS.str();
6245bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6251 if (parseIdentifier(LabelVal))
6252 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6257 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6266 return Error(LabelLoc,
6267 "Cannot have just a label for an HLASM inline asm statement");
6270 getContext().getAsmInfo()->shouldEmitLabelsInUpperCase()
6274 getTargetParser().doBeforeLabelEmit(
Sym, LabelLoc);
6281 if (enabledGenDwarfForAssembly())
6285 getTargetParser().onLabelParsed(
Sym);
6290bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6293 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6297 if (parseIdentifier(OperationEntryVal))
6298 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6304 return parseAndMatchAndEmitTargetInstruction(
6305 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6308bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6310 assert(!hasPendingError() &&
"parseStatement started with pending error");
6313 bool ShouldParseAsHLASMLabel =
false;
6322 ShouldParseAsHLASMLabel =
true;
6328 if (getTok().getString().empty() || getTok().getString().front() ==
'\r' ||
6329 getTok().getString().front() ==
'\n')
6344 if (getTok().getString().front() ==
'\n' ||
6345 getTok().getString().front() ==
'\r') {
6354 if (ShouldParseAsHLASMLabel) {
6357 if (parseAsHLASMLabel(Info, SI)) {
6360 eatToEndOfStatement();
6365 return parseAsMachineInstruction(Info, SI);
6369namespace MCParserUtils {
6374 switch (
Value->getKind()) {
6405 return Parser.
TokError(
"missing expression");
6423 return Parser.
Error(EqualLoc,
"Recursive use of '" +
Name +
"'");
6424 else if (
Sym->isUndefined(
false) && !
Sym->isUsed() &&
6427 else if (
Sym->isVariable() && !
Sym->isUsed() && allow_redef)
6429 else if (!
Sym->isUndefined() && (!
Sym->isVariable() || !allow_redef))
6430 return Parser.
Error(EqualLoc,
"redefinition of '" +
Name +
"'");
6431 else if (!
Sym->isVariable())
6432 return Parser.
Error(EqualLoc,
"invalid assignment to '" +
Name +
"'");
6433 else if (!isa<MCConstantExpr>(
Sym->getVariableValue()))
6434 return Parser.
Error(EqualLoc,
6435 "invalid reassignment of non-absolute variable '" +
6437 }
else if (
Name ==
".") {
6443 Sym->setRedefinable(allow_redef);
6455 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6456 return new HLASMAsmParser(SM,
C, Out, MAI, CB);
6458 return new AsmParser(SM,
C, Out, MAI, CB);
This file defines the StringMap class.
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static Expected< std::vector< unsigned > > getSymbols(SymbolicFile *Obj, uint16_t Index, raw_ostream &SymNames, SymMap *SymMap)
static bool isValidEncoding(int64_t Encoding)
static bool isAngleBracketString(SMLoc &StrLoc, SMLoc &EndLoc)
This function checks if the next token is <string> type or arithmetic.
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static bool isIdentifierChar(char c)
static unsigned getGNUBinOpPrecedence(const MCAsmInfo &MAI, AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static std::string angleBracketString(StringRef AltMacroStr)
creating a string without the escape characters '!'.
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
static bool parseHexOcta(AsmParser &Asm, uint64_t &hi, uint64_t &lo)
static bool isOperator(AsmToken::TokenKind kind)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
This file contains constants used for implementing Dwarf debug support.
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_BASIC_BLOCK
#define DWARF2_LINE_DEFAULT_IS_STMT
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
static bool isHexDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Class for arbitrary precision integers.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
unsigned getBitWidth() const
Return the number of bits in the APInt.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
AsmCond - Class to support conditional assembly.
ConditionalAssemblyType TheCond
AsmLexer - Lexer class for assembly files.
Target independent representation for an assembler token.
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
bool is(TokenKind K) const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Holds state from .cv_file and .cv_loc directives for later emission.
Base class for user error types.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool useParensForSymbolVariant() const
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
bool isLittleEndian() const
True if the target is little endian.
unsigned getAssemblerDialect() const
bool doesAllowAtInName() const
StringRef getPrivateLabelPrefix() const
bool shouldEmitLabelsInUpperCase() const
bool shouldUseLogicalShr() const
StringRef getCommentString() const
bool hasSubsectionsViaSymbols() const
bool getDollarIsPC() const
Generic assembler lexer interface, for use by target specific assembly lexers.
void UnLex(AsmToken const &Token)
void setAllowHashInIdentifier(bool V)
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
void setLexHLASMIntegers(bool V)
Set whether to lex HLASM-flavour integers. For now this is only [0-9]*.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
SMLoc getLoc() const
Get the current source location.
SMLoc getErrLoc()
Get the current error location.
void setLexMasmIntegers(bool V)
Set whether to lex masm-style binary (e.g., 0b1101) and radix-specified literals (e....
const AsmToken & getTok() const
Get the current (last) lexed token.
AsmToken::TokenKind getKind() const
Get the kind of current token.
void setLexHLASMStrings(bool V)
Set whether to "lex" HLASM-flavour character and string literals.
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
const AsmToken & Lex()
Consume the next token from the input stream and return it.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
virtual size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)=0
Look ahead an arbitrary number of tokens.
const std::string & getErr()
Get the current error string.
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
Generic Sema callback for assembly parser.
virtual ~MCAsmParserSemaCallback()
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
virtual bool printError(SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)=0
Emit an error at the location L, with the message Msg.
virtual bool parseEscapedString(std::string &Data)=0
Parse the current token as a string which may include escaped characters and return the string conten...
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
virtual StringRef parseStringToEndOfStatement()=0
Parse up to the end of statement and return the contents from the current token until the end of the ...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
virtual SourceMgr & getSourceManager()=0
virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc, AsmTypeInfo *TypeInfo)=0
Parse a primary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool checkForValidSection()=0
Ensure that we have a valid section set in the streamer.
virtual bool parseIdentifier(StringRef &Res)=0
Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents.
virtual bool discardLTOSymbol(StringRef) const
MCAsmParser & operator=(const MCAsmParser &)=delete
virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression, assuming that an initial '(' has already been consumed.
virtual bool isParsingMSInlineAsm()=0
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
virtual bool parseParenExprOfDepth(unsigned ParenDepth, const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression of a specified parenthesis depth, assuming that the initial '(' charact...
virtual unsigned getAssemblerDialect()
virtual MCAsmLexer & getLexer()=0
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
virtual bool parseAngleBracketString(std::string &Data)=0
Parse an angle-bracket delimited string at the current position if one is present,...
bool TokError(const Twine &Msg, SMRange Range=std::nullopt)
Report an error at the current lexer location.
virtual bool parseAbsoluteExpression(int64_t &Res)=0
Parse an expression which must evaluate to an absolute value.
virtual bool parseMSInlineAsm(std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, SmallVectorImpl< std::pair< void *, bool > > &OpDecls, SmallVectorImpl< std::string > &Constraints, SmallVectorImpl< std::string > &Clobbers, const MCInstrInfo *MII, const MCInstPrinter *IP, MCAsmParserSemaCallback &SI)=0
Parse MS-style inline assembly.
virtual void setAssemblerDialect(unsigned i)
virtual MCContext & getContext()=0
virtual void setParsingMSInlineAsm(bool V)=0
virtual void addDirectiveHandler(StringRef Directive, ExtensionDirectiveHandler Handler)=0
bool Error(SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)
Return an error at the location L, with the message Msg.
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
@ AShr
Arithmetic shift right.
@ LShr
Logical shift right.
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
@ Xor
Bitwise exclusive or.
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
@ NE
Inequality comparison.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
void * allocate(unsigned Size, unsigned Align=8)
Environment getObjectFileType() const
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
bool getGenDwarfForAssembly()
void setGenDwarfForAssembly(bool Value)
void setDwarfVersion(uint16_t v)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
CodeViewContext & getCVContext()
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
uint16_t getDwarfVersion() const
const MCAsmInfo * getAsmInfo() const
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Base class for the full range of assembler expressions which are needed for parsing.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Binary
Binary expressions.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
static void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
virtual void printRegName(raw_ostream &OS, MCRegister Reg) const
Print the assembler register name.
Describe properties that are true of each instruction in the target description file.
Interface to description of machine instruction set.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
virtual bool isMemUseUpRegs() const
isMemUseUpRegs - Is memory operand use up regs, for example, intel MS inline asm may use ARR[baseReg ...
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label? Only valid when par...
virtual MCRegister getReg() const =0
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable,...
virtual StringRef getSymName()
virtual bool isImm() const =0
isImm - Is this an immediate operand?
unsigned getMCOperandNum()
StringRef getConstraint()
virtual void * getOpDecl()
Wrapper class representing physical registers. Should be passed by value.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
virtual StringRef getVirtualSectionKind() const
void setBeginSymbol(MCSymbol *Sym)
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
StringRef getName() const
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI)
Create the default sections and set the initial one.
void setStartTokLocPtr(const SMLoc *Loc)
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
MCTargetStreamer * getTargetStreamer()
virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc)
Emit some number of copies of Value until the byte offset Offset is reached.
virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol, but only if Value is also emitted.
void finish(SMLoc EndLoc=SMLoc())
Finish emission of machine code.
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static VariantKind getVariantKindForName(StringRef Name)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
VariantKind getKind() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
bool isWeakExternal() const
bool isVariable() const
isVariable - Check if this is a variable symbol.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
const MCSubtargetInfo & getSTI() const
Unary assembler expressions.
Opcode getOpcode() const
Get the kind of this unary expression.
static const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getSubExpr() const
Get the child of this unary expression.
static const MCUnaryExpr * createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
This represents an "assembler immediate".
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
StringRef getBuffer() const
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
constexpr bool isSuccess() const
Wrapper class representing virtual and physical registers.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
SourceMgr::DiagKind getKind() const
StringRef getLineContents() const
StringRef getMessage() const
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
const SourceMgr * getSourceMgr() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
constexpr bool isValid() const
Represents a range in source code.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool contains(const T &V) const
Check if the SmallSet contains the given element.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
void * getDiagContext() const
unsigned getMainFileID() const
DiagHandlerTy getDiagHandler() const
const MemoryBuffer * getMemoryBuffer(unsigned i) const
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
SMLoc getParentIncludeLoc(unsigned i) const
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
std::string upper() const
Convert the given ASCII string to uppercase.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
std::string lower() const
int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
This class represents a function that is read from a sample profile.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
@ C
The default llvm calling convention, compatible with C.
std::variant< std::monostate, Loc::Single, Loc::Multi, Loc::MMI, Loc::EntryValue > Variant
Alias for the std::variant specialization base class of DbgVariable.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *Value)
Returns whether the given symbol is used anywhere in the given expression, or subexpressions.
std::variant< std::monostate, DecisionParameters, BranchParameters > Parameters
The type of MC/DC-specific parameters.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
MCAsmParserExtension * createCOFFAsmParser()
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
std::tuple< uint64_t, uint32_t > InlineSite
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
MCAsmParserExtension * createXCOFFAsmParser()
MCAsmParserExtension * createGOFFAsmParser()
auto reverse(ContainerTy &&C)
cl::opt< unsigned > AsmMacroMaxNestingDepth
const char AsmRewritePrecedence[]
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
static bool hasDiscriminator(uint32_t Flags)
MCAsmParserExtension * createWasmAsmParser()
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance for parsing assembly similar to gas syntax.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
MCAsmParserExtension * createELFAsmParser()
MCAsmParserExtension * createDarwinAsmParser()
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
ArrayRef< int > hi(ArrayRef< int > Vuu)
ArrayRef< int > lo(ArrayRef< int > Vuu)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Description of the encoding of one expression Op.
std::vector< AsmToken > Value
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
std::optional< StringRef > Source
The source code of the file.