79 cl::desc(
"The maximum nesting depth allowed for assembly macros."));
84 typedef std::vector<AsmToken> MCAsmMacroArgument;
85 typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
89 struct MacroInstantiation {
91 SMLoc InstantiationLoc;
100 size_t CondStackDepth;
103 struct ParseStatementInfo {
108 unsigned Opcode = ~0U;
111 bool ParseError =
false;
115 ParseStatementInfo() =
delete;
117 : AsmRewrites(rewrites) {}
129 void *SavedDiagContext;
130 std::unique_ptr<MCAsmParserExtension> PlatformParser;
137 std::vector<AsmCond> TheCondStack;
145 std::vector<MacroInstantiation*> ActiveMacros;
148 std::deque<MCAsmMacro> MacroLikeBodies;
151 unsigned MacrosEnabledFlag : 1;
154 unsigned NumOfMacroInstantiations;
157 struct CppHashInfoTy {
162 CppHashInfoTy() : Filename(), LineNumber(0), Loc(), Buf(0) {}
164 CppHashInfoTy CppHashInfo;
173 unsigned AssemblerDialect = ~0U;
176 bool IsDarwin =
false;
179 bool ParsingInlineAsm =
false;
182 bool ReportedInconsistentMD5 =
false;
185 bool AltMacroMode =
false;
190 AsmParser(
const AsmParser &) =
delete;
191 AsmParser &operator=(
const AsmParser &) =
delete;
192 ~AsmParser()
override;
194 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
197 ExtensionDirectiveHandler Handler)
override {
198 ExtensionDirectiveMap[
Directive] = Handler;
202 DirectiveKindMap[
Directive] = DirectiveKindMap[Alias];
209 MCAsmLexer &getLexer()
override {
return Lexer; }
210 MCContext &getContext()
override {
return Ctx; }
211 MCStreamer &getStreamer()
override {
return Out; }
215 unsigned getAssemblerDialect()
override {
216 if (AssemblerDialect == ~0U)
219 return AssemblerDialect;
221 void setAssemblerDialect(
unsigned i)
override {
222 AssemblerDialect = i;
231 void setParsingInlineAsm(
bool V)
override {
232 ParsingInlineAsm = V;
237 bool isParsingInlineAsm()
override {
return ParsingInlineAsm; }
239 bool parseMSInlineAsm(
void *AsmLoc, std::string &AsmString,
240 unsigned &NumOutputs,
unsigned &NumInputs,
247 bool parseExpression(
const MCExpr *&Res);
248 bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
249 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
250 bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
251 bool parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
252 SMLoc &EndLoc)
override;
253 bool parseAbsoluteExpression(int64_t &Res)
override;
261 bool parseIdentifier(
StringRef &Res)
override;
262 void eatToEndOfStatement()
override;
264 bool checkForValidSection()
override;
269 bool parseStatement(ParseStatementInfo &
Info,
272 bool parseCppHashLineFilenameComment(
SMLoc L);
282 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
285 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
288 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
297 void handleMacroExit();
300 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
303 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &A);
305 void printMacroInstantiations();
316 bool enabledGenDwarfForAssembly();
319 bool enterIncludeFile(
const std::string &Filename);
323 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
332 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
337 StringRef parseStringToEndOfStatement()
override;
344 bool NoDeadStrip =
false);
349 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
350 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
351 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
353 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
355 bool parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName);
356 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
415 DK_BUNDLE_ALIGN_MODE,
429 DK_WEAK_DEF_CAN_BE_HIDDEN,
469 DK_CV_INLINE_SITE_ID,
472 DK_CV_INLINE_LINETABLE,
477 DK_CV_FILECHECKSUM_OFFSET,
483 DK_CFI_DEF_CFA_OFFSET,
484 DK_CFI_ADJUST_CFA_OFFSET,
485 DK_CFI_DEF_CFA_REGISTER,
490 DK_CFI_REMEMBER_STATE,
491 DK_CFI_RESTORE_STATE,
495 DK_CFI_RETURN_COLUMN,
526 enum CVDefRangeType {
528 CVDR_DEFRANGE_REGISTER,
529 CVDR_DEFRANGE_FRAMEPOINTER_REL,
530 CVDR_DEFRANGE_SUBFIELD_REGISTER,
531 CVDR_DEFRANGE_REGISTER_REL
539 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
540 bool parseDirectiveReloc(
SMLoc DirectiveLoc);
541 bool parseDirectiveValue(
StringRef IDVal,
543 bool parseDirectiveOctaValue(
StringRef IDVal);
544 bool parseDirectiveRealValue(
StringRef IDVal,
546 bool parseDirectiveFill();
547 bool parseDirectiveZero();
549 bool parseDirectiveSet(
StringRef IDVal,
bool allow_redef);
550 bool parseDirectiveOrg();
552 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
555 bool parseDirectiveFile(
SMLoc DirectiveLoc);
556 bool parseDirectiveLine();
557 bool parseDirectiveLoc();
558 bool parseDirectiveStabs();
562 bool parseDirectiveCVFile();
563 bool parseDirectiveCVFuncId();
564 bool parseDirectiveCVInlineSiteId();
565 bool parseDirectiveCVLoc();
566 bool parseDirectiveCVLinetable();
567 bool parseDirectiveCVInlineLinetable();
568 bool parseDirectiveCVDefRange();
569 bool parseDirectiveCVString();
570 bool parseDirectiveCVStringTable();
571 bool parseDirectiveCVFileChecksums();
572 bool parseDirectiveCVFileChecksumOffset();
573 bool parseDirectiveCVFPOData();
576 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
577 bool parseDirectiveCFIWindowSave();
578 bool parseDirectiveCFISections();
579 bool parseDirectiveCFIStartProc();
580 bool parseDirectiveCFIEndProc();
581 bool parseDirectiveCFIDefCfaOffset();
582 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
583 bool parseDirectiveCFIAdjustCfaOffset();
584 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
585 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
586 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
587 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
588 bool parseDirectiveCFIRememberState();
589 bool parseDirectiveCFIRestoreState();
590 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
591 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
592 bool parseDirectiveCFIEscape();
593 bool parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc);
594 bool parseDirectiveCFISignalFrame();
595 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
598 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
601 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
606 bool parseDirectiveBundleAlignMode();
608 bool parseDirectiveBundleLock();
610 bool parseDirectiveBundleUnlock();
613 bool parseDirectiveSpace(
StringRef IDVal);
622 bool parseDirectiveLEB128(
bool Signed);
628 bool parseDirectiveComm(
bool IsLocal);
630 bool parseDirectiveAbort();
631 bool parseDirectiveInclude();
632 bool parseDirectiveIncbin();
635 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
637 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
639 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
641 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
643 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
644 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
645 bool parseDirectiveElse(
SMLoc DirectiveLoc);
646 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
647 bool parseEscapedString(std::string &
Data)
override;
657 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
658 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
659 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
662 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &
Info,
666 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &
Info);
669 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
672 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
675 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
678 bool parseDirectivePrint(
SMLoc DirectiveLoc);
681 bool parseDirectiveAddrsig();
682 bool parseDirectiveAddrsigSym();
684 void initializeDirectiveKindMap();
685 void initializeCVDefRangeTypeMap();
703 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
704 CurBuffer(CB ? CB : SM.
getMainFileID()), MacrosEnabledFlag(
true) {
730 "Need to implement createXCOFFAsmParser for XCOFF format.");
734 PlatformParser->Initialize(*
this);
735 initializeDirectiveKindMap();
736 initializeCVDefRangeTypeMap();
738 NumOfMacroInstantiations = 0;
741 AsmParser::~AsmParser() {
742 assert((HadError || ActiveMacros.empty()) &&
743 "Unexpected active macro instantiation!");
750 void AsmParser::printMacroInstantiations() {
752 for (std::vector<MacroInstantiation *>::const_reverse_iterator
753 it = ActiveMacros.rbegin(),
754 ie = ActiveMacros.rend();
757 "while in macro instantiation");
761 printPendingErrors();
763 printMacroInstantiations();
767 if(getTargetParser().getTargetOptions().MCNoWarn)
769 if (getTargetParser().getTargetOptions().MCFatalWarnings)
770 return Error(L, Msg, Range);
772 printMacroInstantiations();
779 printMacroInstantiations();
783 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
784 std::string IncludedFile;
798 bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
800 std::string IncludedFile;
811 if (!Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
812 return Error(Loc,
"expected absolute expression");
814 return Warning(Loc,
"negative count has no effect");
817 getStreamer().EmitBytes(Bytes);
821 void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
834 if (!getTok().getString().empty() && getTok().getString().front() !=
'\n' &&
852 if (ParentIncludeLoc !=
SMLoc()) {
853 jumpToLoc(ParentIncludeLoc);
861 bool AsmParser::enabledGenDwarfForAssembly() {
863 if (!getContext().getGenDwarfForAssembly())
868 if (getContext().getGenDwarfFileNumber() == 0) {
871 if (!FirstCppHashFilename.
empty())
872 getContext().setMCLineTableRootFile(0,
873 getContext().getCompilationDir(),
874 FirstCppHashFilename,
877 getContext().getMCDwarfLineTable(0).getRootFile();
878 getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
879 0, getContext().getCompilationDir(), RootFile.
Name,
885 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
887 if (!NoInitialTextSection)
894 AsmCond StartingCondState = TheCondState;
901 if (getContext().getGenDwarfForAssembly()) {
902 MCSection *Sec = getStreamer().getCurrentSectionOnly();
904 MCSymbol *SectionStartSym = getContext().createTempSymbol();
905 getStreamer().EmitLabel(SectionStartSym);
908 bool InsertResult = getContext().addGenDwarfSection(Sec);
909 assert(InsertResult &&
".text section should not have debug info yet");
915 ParseStatementInfo
Info(&AsmStrRewrites);
916 bool Parsed = parseStatement(Info,
nullptr);
926 printPendingErrors();
929 if (Parsed && !getLexer().isAtStartOfStatement())
930 eatToEndOfStatement();
933 getTargetParser().onEndOfFile();
934 printPendingErrors();
937 assert(!hasPendingError() &&
"unexpected error from parseStatement");
939 getTargetParser().flushPendingInstructions(getStreamer());
943 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
945 const auto &LineTables = getContext().getMCDwarfLineTables();
946 if (!LineTables.empty()) {
948 for (
const auto &
File : LineTables.begin()->second.getMCDwarfFiles()) {
949 if (
File.Name.empty() && Index != 0)
950 printError(getTok().getLoc(),
"unassigned file number: " +
952 " for .file directives");
963 for (
const auto &TableEntry : getContext().getSymbols()) {
964 MCSymbol *Sym = TableEntry.getValue();
972 printError(getTok().getLoc(),
"assembler local symbol '" +
973 Sym->
getName() +
"' not defined");
979 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
980 if (std::get<2>(LocSym)->isUndefined()) {
983 CppHashInfo = std::get<1>(LocSym);
984 printError(std::get<0>(LocSym),
"directional label undefined");
991 if (!HadError && !NoFinalize)
994 return HadError || getContext().hadError();
997 bool AsmParser::checkForValidSection() {
998 if (!ParsingInlineAsm && !getStreamer().getCurrentSectionOnly()) {
1000 return Error(getTok().getLoc(),
1001 "expected section directive before assembly directive");
1007 void AsmParser::eatToEndOfStatement() {
1016 StringRef AsmParser::parseStringToEndOfStatement() {
1017 const char *Start = getTok().getLoc().getPointer();
1022 const char *End = getTok().getLoc().getPointer();
1026 StringRef AsmParser::parseStringToComma() {
1027 const char *Start = getTok().getLoc().getPointer();
1033 const char *End = getTok().getLoc().getPointer();
1042 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1043 if (parseExpression(Res))
1046 return TokError(
"expected ')' in parentheses expression");
1057 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1058 if (parseExpression(Res))
1060 EndLoc = getTok().getEndLoc();
1061 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1072 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1073 SMLoc FirstTokenLoc = getLexer().getLoc();
1075 switch (FirstTokenKind) {
1077 return TokError(
"unknown token in expression");
1083 if (parsePrimaryExpr(Res, EndLoc))
1092 if (parseIdentifier(Identifier)) {
1103 EndLoc = FirstTokenLoc;
1106 return Error(FirstTokenLoc,
"invalid token in expression");
1110 std::pair<StringRef, StringRef> Split;
1115 SMLoc AtLoc = getLexer().getLoc();
1117 if (parseIdentifier(VName))
1118 return Error(AtLoc,
"expected symbol variant after '@'");
1120 Split = std::make_pair(Identifier, VName);
1123 Split = Identifier.
split(
'@');
1128 parseIdentifier(VName);
1131 "unexpected token in variant, expected ')'"))
1133 Split = std::make_pair(Identifier, VName);
1140 if (SymbolName.empty())
1141 return Error(getLexer().getLoc(),
"expected a symbol reference");
1146 if (!Split.second.empty()) {
1149 SymbolName = Split.first;
1154 "invalid variant '" + Split.second +
"'");
1158 MCSymbol *Sym = getContext().getInlineAsmLabel(SymbolName);
1160 Sym = getContext().getOrCreateSymbol(SymbolName);
1166 bool DoInline = isa<MCConstantExpr>(V) && !Variant;
1167 if (
auto TV = dyn_cast<MCTargetExpr>(V))
1168 DoInline = TV->inlineAssignedExpr();
1171 return Error(EndLoc,
"unexpected modifier on variable reference");
1182 return TokError(
"literal value out of range for directive");
1184 SMLoc Loc = getTok().getLoc();
1185 int64_t
IntVal = getTok().getIntVal();
1193 std::pair<StringRef, StringRef> Split = IDVal.
split(
'@');
1195 if (Split.first.size() != IDVal.
size()) {
1198 return TokError(
"invalid variant '" + Split.second +
"'");
1199 IDVal = Split.first;
1201 if (IDVal ==
"f" || IDVal ==
"b") {
1206 return Error(Loc,
"directional label undefined");
1207 DirLabels.
push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1234 return parseParenExpr(Res, EndLoc);
1236 if (!PlatformParser->HasBracketExpressions())
1237 return TokError(
"brackets expression not supported on this target");
1239 return parseBracketExpr(Res, EndLoc);
1242 if (parsePrimaryExpr(Res, EndLoc))
1248 if (parsePrimaryExpr(Res, EndLoc))
1254 if (parsePrimaryExpr(Res, EndLoc))
1286 return TokError(
"expected '(' after operator");
1288 if (parseExpression(Res, EndLoc))
1291 return TokError(
"expected ')'");
1293 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1298 bool AsmParser::parseExpression(
const MCExpr *&Res) {
1300 return parseExpression(Res, EndLoc);
1304 AsmParser::applyModifierToExpr(
const MCExpr *
E,
1307 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
1321 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
1322 "' (already modified)");
1339 const MCExpr *LHS = applyModifierToExpr(BE->
getLHS(), Variant);
1340 const MCExpr *RHS = applyModifierToExpr(BE->
getRHS(), Variant);
1370 "Argument to the function cannot be a NULL value");
1372 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1373 (*CharPtr !=
'\0')) {
1374 if (*CharPtr ==
'!')
1378 if (*CharPtr ==
'>') {
1388 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1389 if (AltMacroStr[Pos] ==
'!')
1391 Res += AltMacroStr[Pos];
1406 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1409 if (getTargetParser().parsePrimaryExpr(Res, EndLoc) ||
1410 parseBinOpRHS(1, Res, EndLoc))
1420 return TokError(
"unexpected symbol modifier following '@'");
1425 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1427 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1429 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1430 "' (no symbols present)");
1440 if (Res->evaluateAsAbsolute(Value))
1446 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1448 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1451 bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1453 if (parseParenExpr(Res, EndLoc))
1456 for (; ParenDepth > 0; --ParenDepth) {
1457 if (parseBinOpRHS(1, Res, EndLoc))
1462 if (ParenDepth - 1 > 0) {
1463 EndLoc = getTok().getEndLoc();
1465 "expected ')' in parentheses expression"))
1472 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1476 if (parseExpression(Expr))
1479 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1480 return Error(StartLoc,
"expected absolute expression");
1487 bool ShouldUseLogicalShr) {
1565 bool ShouldUseLogicalShr) {
1648 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1653 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(),
Kind);
1657 if (TokPrec < Precedence)
1664 if (getTargetParser().parsePrimaryExpr(RHS, EndLoc))
1670 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(),
Dummy);
1671 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1683 bool AsmParser::parseStatement(ParseStatementInfo &
Info,
1685 assert(!hasPendingError() &&
"parseStatement started with pending error");
1691 if (getTok().getString().empty() || getTok().getString().front() ==
'\r' ||
1692 getTok().getString().front() ==
'\n')
1701 int64_t LocalLabelVal = -1;
1703 return parseCppHashLineFilenameComment(IDLoc);
1706 LocalLabelVal = getTok().getIntVal();
1707 if (LocalLabelVal < 0) {
1708 if (!TheCondState.
Ignore) {
1710 return Error(IDLoc,
"unexpected token at start of statement");
1714 IDVal = getTok().getString();
1717 if (!TheCondState.
Ignore) {
1719 return Error(IDLoc,
"unexpected token at start of statement");
1737 getTargetParser().starIsStartOfStatement()) {
1741 }
else if (parseIdentifier(IDVal)) {
1742 if (!TheCondState.
Ignore) {
1744 return Error(IDLoc,
"unexpected token at start of statement");
1753 DirectiveKindMap.find(IDVal);
1754 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1757 : DirKindIt->getValue();
1768 return parseDirectiveIf(IDLoc, DirKind);
1770 return parseDirectiveIfb(IDLoc,
true);
1772 return parseDirectiveIfb(IDLoc,
false);
1774 return parseDirectiveIfc(IDLoc,
true);
1776 return parseDirectiveIfeqs(IDLoc,
true);
1778 return parseDirectiveIfc(IDLoc,
false);
1780 return parseDirectiveIfeqs(IDLoc,
false);
1782 return parseDirectiveIfdef(IDLoc,
true);
1785 return parseDirectiveIfdef(IDLoc,
false);
1787 return parseDirectiveElseIf(IDLoc);
1789 return parseDirectiveElse(IDLoc);
1791 return parseDirectiveEndIf(IDLoc);
1796 if (TheCondState.
Ignore) {
1797 eatToEndOfStatement();
1806 if (!getTargetParser().isLabel(ID))
1808 if (checkForValidSection())
1816 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1824 if (LocalLabelVal == -1) {
1825 if (ParsingInlineAsm && SI) {
1829 "We should have an internal name here.");
1830 Info.AsmRewrites->emplace_back(
AOK_Label, IDLoc, IDVal.
size(),
1832 IDVal = RewrittenLabel;
1834 Sym = getContext().getOrCreateSymbol(IDVal);
1842 StringRef CommentStr = parseStringToEndOfStatement();
1853 getTargetParser().doBeforeLabelEmit(Sym);
1856 if (!getTargetParser().isParsingInlineAsm())
1861 if (enabledGenDwarfForAssembly())
1865 getTargetParser().onLabelParsed(Sym);
1871 if (!getTargetParser().equalIsAsmAssignment())
1876 return parseAssignment(IDVal,
true);
1883 if (areMacrosEnabled())
1884 if (
const MCAsmMacro *M = getContext().lookupMacro(IDVal)) {
1885 return handleMacroEntry(M, IDLoc);
1903 getTargetParser().flushPendingInstructions(getStreamer());
1905 SMLoc StartTokLoc = getTok().getLoc();
1906 bool TPDirectiveReturn = getTargetParser().ParseDirective(ID);
1908 if (hasPendingError())
1915 if (TPDirectiveReturn && StartTokLoc != getTok().getLoc())
1918 if (!TPDirectiveReturn || StartTokLoc != getTok().getLoc())
1923 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1924 ExtensionDirectiveMap.
lookup(IDVal);
1926 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1935 return parseDirectiveSet(IDVal,
true);
1937 return parseDirectiveSet(IDVal,
false);
1939 return parseDirectiveAscii(IDVal,
false);
1942 return parseDirectiveAscii(IDVal,
true);
1945 return parseDirectiveValue(IDVal, 1);
1951 return parseDirectiveValue(IDVal, 2);
1956 return parseDirectiveValue(IDVal, 4);
1959 return parseDirectiveValue(IDVal, 8);
1961 return parseDirectiveValue(
1962 IDVal, getContext().getAsmInfo()->getCodePointerSize());
1964 return parseDirectiveOctaValue(IDVal);
1973 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1974 return parseDirectiveAlign(IsPow2, 1);
1977 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1978 return parseDirectiveAlign(IsPow2, 4);
1981 return parseDirectiveAlign(
false, 1);
1983 return parseDirectiveAlign(
false, 2);
1985 return parseDirectiveAlign(
false, 4);
1987 return parseDirectiveAlign(
true, 1);
1989 return parseDirectiveAlign(
true, 2);
1991 return parseDirectiveAlign(
true, 4);
1993 return parseDirectiveOrg();
1995 return parseDirectiveFill();
1997 return parseDirectiveZero();
1999 eatToEndOfStatement();
2003 return parseDirectiveSymbolAttribute(
MCSA_Global);
2004 case DK_LAZY_REFERENCE:
2006 case DK_NO_DEAD_STRIP:
2008 case DK_SYMBOL_RESOLVER:
2010 case DK_PRIVATE_EXTERN:
2014 case DK_WEAK_DEFINITION:
2016 case DK_WEAK_REFERENCE:
2018 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2021 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2024 return parseDirectiveComm(
false);
2026 return parseDirectiveComm(
true);
2028 return parseDirectiveAbort();
2030 return parseDirectiveInclude();
2032 return parseDirectiveIncbin();
2035 return TokError(
Twine(IDVal) +
2036 " not currently supported for this target");
2038 return parseDirectiveRept(IDLoc, IDVal);
2040 return parseDirectiveIrp(IDLoc);
2042 return parseDirectiveIrpc(IDLoc);
2044 return parseDirectiveEndr(IDLoc);
2045 case DK_BUNDLE_ALIGN_MODE:
2046 return parseDirectiveBundleAlignMode();
2047 case DK_BUNDLE_LOCK:
2048 return parseDirectiveBundleLock();
2049 case DK_BUNDLE_UNLOCK:
2050 return parseDirectiveBundleUnlock();
2052 return parseDirectiveLEB128(
true);
2054 return parseDirectiveLEB128(
false);
2057 return parseDirectiveSpace(IDVal);
2059 return parseDirectiveFile(IDLoc);
2061 return parseDirectiveLine();
2063 return parseDirectiveLoc();
2065 return parseDirectiveStabs();
2067 return parseDirectiveCVFile();
2069 return parseDirectiveCVFuncId();
2070 case DK_CV_INLINE_SITE_ID:
2071 return parseDirectiveCVInlineSiteId();
2073 return parseDirectiveCVLoc();
2074 case DK_CV_LINETABLE:
2075 return parseDirectiveCVLinetable();
2076 case DK_CV_INLINE_LINETABLE:
2077 return parseDirectiveCVInlineLinetable();
2078 case DK_CV_DEF_RANGE:
2079 return parseDirectiveCVDefRange();
2081 return parseDirectiveCVString();
2082 case DK_CV_STRINGTABLE:
2083 return parseDirectiveCVStringTable();
2084 case DK_CV_FILECHECKSUMS:
2085 return parseDirectiveCVFileChecksums();
2086 case DK_CV_FILECHECKSUM_OFFSET:
2087 return parseDirectiveCVFileChecksumOffset();
2088 case DK_CV_FPO_DATA:
2089 return parseDirectiveCVFPOData();
2090 case DK_CFI_SECTIONS:
2091 return parseDirectiveCFISections();
2092 case DK_CFI_STARTPROC:
2093 return parseDirectiveCFIStartProc();
2094 case DK_CFI_ENDPROC:
2095 return parseDirectiveCFIEndProc();
2096 case DK_CFI_DEF_CFA:
2097 return parseDirectiveCFIDefCfa(IDLoc);
2098 case DK_CFI_DEF_CFA_OFFSET:
2099 return parseDirectiveCFIDefCfaOffset();
2100 case DK_CFI_ADJUST_CFA_OFFSET:
2101 return parseDirectiveCFIAdjustCfaOffset();
2102 case DK_CFI_DEF_CFA_REGISTER:
2103 return parseDirectiveCFIDefCfaRegister(IDLoc);
2105 return parseDirectiveCFIOffset(IDLoc);
2106 case DK_CFI_REL_OFFSET:
2107 return parseDirectiveCFIRelOffset(IDLoc);
2108 case DK_CFI_PERSONALITY:
2109 return parseDirectiveCFIPersonalityOrLsda(
true);
2111 return parseDirectiveCFIPersonalityOrLsda(
false);
2112 case DK_CFI_REMEMBER_STATE:
2113 return parseDirectiveCFIRememberState();
2114 case DK_CFI_RESTORE_STATE:
2115 return parseDirectiveCFIRestoreState();
2116 case DK_CFI_SAME_VALUE:
2117 return parseDirectiveCFISameValue(IDLoc);
2118 case DK_CFI_RESTORE:
2119 return parseDirectiveCFIRestore(IDLoc);
2121 return parseDirectiveCFIEscape();
2122 case DK_CFI_RETURN_COLUMN:
2123 return parseDirectiveCFIReturnColumn(IDLoc);
2124 case DK_CFI_SIGNAL_FRAME:
2125 return parseDirectiveCFISignalFrame();
2126 case DK_CFI_UNDEFINED:
2127 return parseDirectiveCFIUndefined(IDLoc);
2128 case DK_CFI_REGISTER:
2129 return parseDirectiveCFIRegister(IDLoc);
2130 case DK_CFI_WINDOW_SAVE:
2131 return parseDirectiveCFIWindowSave();
2134 return parseDirectiveMacrosOnOff(IDVal);
2136 return parseDirectiveMacro(IDLoc);
2139 return parseDirectiveAltmacro(IDVal);
2141 return parseDirectiveExitMacro(IDVal);
2144 return parseDirectiveEndMacro(IDVal);
2146 return parseDirectivePurgeMacro(IDLoc);
2148 return parseDirectiveEnd(IDLoc);
2150 return parseDirectiveError(IDLoc,
false);
2152 return parseDirectiveError(IDLoc,
true);
2154 return parseDirectiveWarning(IDLoc);
2156 return parseDirectiveReloc(IDLoc);
2159 return parseDirectiveDCB(IDVal, 2);
2161 return parseDirectiveDCB(IDVal, 1);
2165 return parseDirectiveDCB(IDVal, 4);
2170 return TokError(
Twine(IDVal) +
2171 " not currently supported for this target");
2174 return parseDirectiveDS(IDVal, 2);
2176 return parseDirectiveDS(IDVal, 1);
2178 return parseDirectiveDS(IDVal, 8);
2181 return parseDirectiveDS(IDVal, 4);
2184 return parseDirectiveDS(IDVal, 12);
2186 return parseDirectivePrint(IDLoc);
2188 return parseDirectiveAddrsig();
2189 case DK_ADDRSIG_SYM:
2190 return parseDirectiveAddrsigSym();
2193 return Error(IDLoc,
"unknown directive");
2197 if (ParsingInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2198 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2199 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2202 if (ParsingInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2203 return parseDirectiveMSAlign(IDLoc, Info);
2205 if (ParsingInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2206 Info.AsmRewrites->emplace_back(
AOK_EVEN, IDLoc, 4);
2207 if (checkForValidSection())
2211 std::string OpcodeStr = IDVal.
lower();
2213 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, ID,
2214 Info.ParsedOperands);
2215 Info.ParseError = ParseHadError;
2218 if (getShowParsedOperands()) {
2221 OS <<
"parsed instruction: [";
2222 for (
unsigned i = 0; i != Info.ParsedOperands.size(); ++i) {
2225 Info.ParsedOperands[i]->print(OS);
2233 if (hasPendingError() || ParseHadError)
2238 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2239 getContext().getGenDwarfSectionSyms().count(
2240 getStreamer().getCurrentSectionOnly())) {
2242 if (ActiveMacros.empty())
2245 Line = SrcMgr.
FindLineNumber(ActiveMacros.front()->InstantiationLoc,
2246 ActiveMacros.front()->ExitBuffer);
2251 if (!CppHashInfo.Filename.empty()) {
2252 unsigned FileNumber = getStreamer().EmitDwarfFileDirective(
2254 getContext().setGenDwarfFileNumber(FileNumber);
2256 unsigned CppHashLocLineNo =
2258 Line = CppHashInfo.LineNumber - 1 + (Line - CppHashLocLineNo);
2261 getStreamer().EmitDwarfLocDirective(
2262 getContext().getGenDwarfFileNumber(), Line, 0,
2268 if (!ParseHadError) {
2270 if (getTargetParser().MatchAndEmitInstruction(
2271 IDLoc, Info.Opcode, Info.ParsedOperands, Out, ErrorInfo,
2272 getTargetParser().isParsingInlineAsm()))
2298 bool AsmParser::parseCppHashLineFilenameComment(
SMLoc L) {
2303 "Lexing Cpp line comment: Expected Integer");
2304 int64_t LineNumber = getTok().getIntVal();
2307 "Lexing Cpp line comment: Expected String");
2308 StringRef Filename = getTok().getString();
2312 Filename = Filename.
substr(1, Filename.
size() - 2);
2316 CppHashInfo.Loc = L;
2317 CppHashInfo.Filename = Filename;
2318 CppHashInfo.LineNumber = LineNumber;
2319 CppHashInfo.Buf = CurBuffer;
2320 if (FirstCppHashFilename.
empty())
2321 FirstCppHashFilename = Filename;
2328 const AsmParser *Parser =
static_cast<const AsmParser *
>(
Context);
2334 unsigned CppHashBuf =
2335 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2340 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2349 if (!Parser->CppHashInfo.LineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
2350 DiagBuf != CppHashBuf) {
2351 if (Parser->SavedDiagHandler)
2352 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2354 Diag.
print(
nullptr, OS);
2361 const std::string &Filename = Parser->CppHashInfo.Filename;
2364 int CppHashLocLineNo =
2365 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2367 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2373 if (Parser->SavedDiagHandler)
2374 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
2376 NewDiag.print(
nullptr, OS);
2384 return isalnum(static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2391 bool EnableAtPseudoVariable,
SMLoc L) {
2392 unsigned NParameters = Parameters.
size();
2393 bool HasVararg = NParameters ? Parameters.
back().
Vararg :
false;
2394 if ((!IsDarwin || NParameters != 0) && NParameters != A.
size())
2395 return Error(L,
"Wrong number of arguments");
2399 while (!Body.
empty()) {
2401 std::size_t End = Body.
size(), Pos = 0;
2402 for (; Pos != End; ++Pos) {
2404 if (IsDarwin && !NParameters) {
2406 if (Body[Pos] !=
'$' || Pos + 1 == End)
2409 char Next = Body[Pos + 1];
2410 if (Next ==
'$' || Next ==
'n' ||
2411 isdigit(static_cast<unsigned char>(Next)))
2415 if (Body[Pos] ==
'\\' && Pos + 1 != End)
2421 OS << Body.
slice(0, Pos);
2427 if (IsDarwin && !NParameters) {
2428 switch (Body[Pos + 1]) {
2442 unsigned Index = Body[Pos + 1] -
'0';
2443 if (Index >= A.
size())
2447 for (
const AsmToken &Token : A[Index])
2448 OS << Token.getString();
2454 unsigned I = Pos + 1;
2457 if (EnableAtPseudoVariable && Body[I] ==
'@' && I + 1 != End)
2463 const char *Begin = Body.
data() + Pos + 1;
2467 if (Argument ==
"@") {
2468 OS << NumOfMacroInstantiations;
2471 for (; Index < NParameters; ++
Index)
2472 if (Parameters[Index].
Name == Argument)
2475 if (Index == NParameters) {
2476 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
2479 OS <<
'\\' << Argument;
2483 bool VarargParameter = HasVararg && Index == (NParameters - 1);
2484 for (
const AsmToken &Token : A[Index])
2492 if (AltMacroMode && Token.getString().front() ==
'%' &&
2495 OS << Token.getIntVal();
2498 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2505 OS << Token.getString();
2507 OS << Token.getStringContents();
2509 Pos += 1 + Argument.
size();
2552 class AsmLexerSkipSpaceRAII {
2554 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2558 ~AsmLexerSkipSpaceRAII() {
2568 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2572 StringRef Str = parseStringToEndOfStatement();
2578 unsigned ParenLevel = 0;
2581 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2588 return TokError(
"unexpected token in macro instantiation");
2590 if (ParenLevel == 0) {
2605 MA.push_back(getTok());
2631 MA.push_back(getTok());
2635 if (ParenLevel != 0)
2636 return TokError(
"unbalanced parentheses in macro argument");
2641 bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2642 MCAsmMacroArguments &A) {
2643 const unsigned NParameters = M ? M->
Parameters.size() : 0;
2644 bool NamedParametersFound =
false;
2648 FALocs.
resize(NParameters);
2653 bool HasVararg = NParameters ? M->
Parameters.back().Vararg :
false;
2654 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2660 if (parseIdentifier(FA.
Name))
2661 return Error(IDLoc,
"invalid argument identifier for formal argument");
2664 return TokError(
"expected '=' after formal parameter identifier");
2668 NamedParametersFound =
true;
2670 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2672 if (NamedParametersFound && FA.
Name.
empty())
2673 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2678 const MCExpr *AbsoluteExp;
2682 if (parseExpression(AbsoluteExp, EndLoc))
2684 if (!AbsoluteExp->evaluateAsAbsolute(Value,
2685 getStreamer().getAssemblerPtr()))
2686 return Error(StrLoc,
"expected absolute expression");
2690 StringRef(StrChar, EndChar - StrChar), Value);
2691 FA.
Value.push_back(newToken);
2696 jumpToLoc(EndLoc, CurBuffer);
2701 FA.
Value.push_back(newToken);
2702 }
else if(parseMacroArgument(FA.
Value, Vararg))
2705 unsigned PI = Parameter;
2708 for (FAI = 0; FAI < NParameters; ++FAI)
2712 if (FAI >= NParameters) {
2713 assert(M &&
"expected macro to be defined");
2714 return Error(IDLoc,
"parameter named '" + FA.
Name +
2715 "' does not exist for macro '" + M->
Name +
"'");
2720 if (!FA.
Value.empty()) {
2725 if (FALocs.
size() <= PI)
2728 FALocs[PI] = Lexer.
getLoc();
2735 bool Failure =
false;
2736 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2737 if (A[FAI].
empty()) {
2739 Error(FALocs[FAI].isValid() ? FALocs[FAI] : Lexer.
getLoc(),
2740 "missing value for required parameter " 2756 return TokError(
"too many positional arguments");
2759 bool AsmParser::handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc) {
2763 if (ActiveMacros.size() == MaxNestingDepth) {
2764 std::ostringstream MaxNestingDepthError;
2765 MaxNestingDepthError <<
"macros cannot be nested more than " 2766 << MaxNestingDepth <<
" levels deep." 2767 <<
" Use -asm-macro-max-nesting-depth to increase " 2769 return TokError(MaxNestingDepthError.str());
2772 MCAsmMacroArguments A;
2773 if (parseMacroArguments(M, A))
2782 if (expandMacro(OS, Body, M->
Parameters, A,
true, getTok().getLoc()))
2787 OS <<
".endmacro\n";
2789 std::unique_ptr<MemoryBuffer> Instantiation =
2794 MacroInstantiation *
MI =
new MacroInstantiation{
2795 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2796 ActiveMacros.push_back(MI);
2798 ++NumOfMacroInstantiations;
2808 void AsmParser::handleMacroExit() {
2810 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2814 delete ActiveMacros.back();
2815 ActiveMacros.pop_back();
2818 bool AsmParser::parseAssignment(
StringRef Name,
bool allow_redef,
2844 bool AsmParser::parseIdentifier(
StringRef &Res) {
2851 SMLoc PrefixLoc = getLexer().getLoc();
2877 Res = getTok().getIdentifier();
2888 bool AsmParser::parseDirectiveSet(
StringRef IDVal,
bool allow_redef) {
2890 if (check(parseIdentifier(Name),
"expected identifier") ||
2891 parseToken(
AsmToken::Comma) || parseAssignment(Name, allow_redef,
true))
2892 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2896 bool AsmParser::parseEscapedString(std::string &
Data) {
2901 StringRef Str = getTok().getStringContents();
2902 for (
unsigned i = 0,
e = Str.
size(); i !=
e; ++i) {
2903 if (Str[i] !=
'\\') {
2912 return TokError(
"unexpected backslash at end of string");
2915 if (Str[i] ==
'x' || Str[i] ==
'X') {
2916 size_t length = Str.
size();
2917 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
2918 return TokError(
"invalid hexadecimal escape sequence");
2923 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
2926 Data += (
unsigned char)(Value & 0xFF);
2931 if ((
unsigned)(Str[i] -
'0') <= 7) {
2933 unsigned Value = Str[i] -
'0';
2935 if (i + 1 !=
e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2937 Value = Value * 8 + (Str[i] -
'0');
2939 if (i + 1 !=
e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2941 Value = Value * 8 + (Str[i] -
'0');
2946 return TokError(
"invalid octal escape sequence (out of range)");
2948 Data += (
unsigned char)Value;
2956 return TokError(
"invalid escape sequence (unrecognized character)");
2958 case 'b': Data +=
'\b';
break;
2959 case 'f': Data +=
'\f';
break;
2960 case 'n': Data +=
'\n';
break;
2961 case 'r': Data +=
'\r';
break;
2962 case 't': Data +=
'\t';
break;
2963 case '"': Data +=
'"';
break;
2964 case '\\': Data +=
'\\';
break;
2974 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
2975 auto parseOp = [&]() ->
bool {
2977 if (checkForValidSection() || parseEscapedString(Data))
2979 getStreamer().EmitBytes(Data);
2981 getStreamer().EmitBytes(
StringRef(
"\0", 1));
2985 if (parseMany(parseOp))
2986 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2992 bool AsmParser::parseDirectiveReloc(
SMLoc DirectiveLoc) {
2994 const MCExpr *Expr =
nullptr;
2995 int64_t OffsetValue;
2998 if (parseExpression(Offset))
3001 if ((Offset->evaluateAsAbsolute(OffsetValue,
3002 getStreamer().getAssemblerPtr()) &&
3003 check(OffsetValue < 0, OffsetLoc,
"expression is negative")) ||
3006 OffsetLoc,
"expected non-negative number or a label")) ||
3018 if (parseExpression(Expr))
3023 return Error(ExprLoc,
"expression must be relocatable");
3027 "unexpected token in .reloc directive"))
3032 if (getStreamer().EmitRelocDirective(*Offset, Name, Expr, DirectiveLoc, STI))
3033 return Error(NameLoc,
"unknown relocation name");
3040 bool AsmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
3041 auto parseOp = [&]() ->
bool {
3043 SMLoc ExprLoc = getLexer().getLoc();
3044 if (checkForValidSection() || parseExpression(Value))
3047 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3048 assert(Size <= 8 &&
"Invalid size");
3049 uint64_t IntValue = MCE->getValue();
3050 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
3051 return Error(ExprLoc,
"out of range literal value");
3052 getStreamer().EmitIntValue(IntValue, Size);
3054 getStreamer().EmitValue(Value, Size, ExprLoc);
3058 if (parseMany(parseOp))
3059 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3066 return Asm.TokError(
"unknown token in expression");
3067 SMLoc ExprLoc = Asm.getTok().getLoc();
3068 APInt IntValue = Asm.getTok().getAPIntVal();
3070 if (!IntValue.
isIntN(128))
3071 return Asm.Error(ExprLoc,
"out of range literal value");
3072 if (!IntValue.
isIntN(64)) {
3085 bool AsmParser::parseDirectiveOctaValue(
StringRef IDVal) {
3086 auto parseOp = [&]() ->
bool {
3087 if (checkForValidSection())
3093 getStreamer().EmitIntValue(lo, 8);
3094 getStreamer().EmitIntValue(hi, 8);
3096 getStreamer().EmitIntValue(hi, 8);
3097 getStreamer().EmitIntValue(lo, 8);
3102 if (parseMany(parseOp))
3103 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3118 return TokError(Lexer.
getErr());
3121 return TokError(
"unexpected token in directive");
3132 return TokError(
"invalid floating point literal");
3136 return TokError(
"invalid floating point literal");
3150 bool AsmParser::parseDirectiveRealValue(
StringRef IDVal,
3152 auto parseOp = [&]() ->
bool {
3154 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3161 if (parseMany(parseOp))
3162 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3168 bool AsmParser::parseDirectiveZero() {
3171 if (checkForValidSection() || parseExpression(NumBytes))
3177 if (parseAbsoluteExpression(Val))
3182 "unexpected token in '.zero' directive"))
3184 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3191 bool AsmParser::parseDirectiveFill() {
3194 if (checkForValidSection() || parseExpression(NumValues))
3197 int64_t FillSize = 1;
3198 int64_t FillExpr = 0;
3200 SMLoc SizeLoc, ExprLoc;
3203 SizeLoc = getTok().getLoc();
3204 if (parseAbsoluteExpression(FillSize))
3207 ExprLoc = getTok().getLoc();
3208 if (parseAbsoluteExpression(FillExpr))
3213 "unexpected token in '.fill' directive"))
3217 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3221 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3226 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3228 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3235 bool AsmParser::parseDirectiveOrg() {
3238 if (checkForValidSection() || parseExpression(Offset))
3242 int64_t FillExpr = 0;
3244 if (parseAbsoluteExpression(FillExpr))
3245 return addErrorSuffix(
" in '.org' directive");
3247 return addErrorSuffix(
" in '.org' directive");
3249 getStreamer().emitValueToOffset(Offset, FillExpr, OffsetLoc);
3255 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
3256 SMLoc AlignmentLoc = getLexer().getLoc();
3259 bool HasFillExpr =
false;
3260 int64_t FillExpr = 0;
3261 int64_t MaxBytesToFill = 0;
3263 auto parseAlign = [&]() ->
bool {
3264 if (parseAbsoluteExpression(Alignment))
3272 if (parseAbsoluteExpression(FillExpr))
3276 if (parseTokenLoc(MaxBytesLoc) ||
3277 parseAbsoluteExpression(MaxBytesToFill))
3283 if (checkForValidSection())
3284 return addErrorSuffix(
" in directive");
3287 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3291 return addErrorSuffix(
" in directive");
3294 bool ReturnVal =
false;
3299 if (Alignment >= 32) {
3300 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3304 Alignment = 1ULL << Alignment;
3312 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3317 if (MaxBytesToFill < 1) {
3318 ReturnVal |=
Error(MaxBytesLoc,
3319 "alignment directive can never be satisfied in this " 3320 "many bytes, ignoring maximum bytes expression");
3324 if (MaxBytesToFill >= Alignment) {
3325 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and " 3334 assert(Section &&
"must have section to emit alignment");
3337 ValueSize == 1 && UseCodeAlign) {
3338 getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
3341 getStreamer().EmitValueToAlignment(Alignment, FillExpr, ValueSize,
3351 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
3353 int64_t FileNumber = -1;
3355 FileNumber = getTok().getIntVal();
3359 return TokError(
"negative file number");
3367 "unexpected token in '.file' directive") ||
3368 parseEscapedString(Path))
3373 std::string FilenameData;
3375 if (check(FileNumber == -1,
3376 "explicit path specified, but no file number") ||
3377 parseEscapedString(FilenameData))
3379 Filename = FilenameData;
3385 uint64_t MD5Hi, MD5Lo;
3386 bool HasMD5 =
false;
3389 bool HasSource =
false;
3390 std::string SourceString;
3395 "unexpected token in '.file' directive") ||
3396 parseIdentifier(Keyword))
3398 if (Keyword ==
"md5") {
3400 if (check(FileNumber == -1,
3401 "MD5 checksum specified, but no file number") ||
3404 }
else if (Keyword ==
"source") {
3406 if (check(FileNumber == -1,
3407 "source specified, but no file number") ||
3409 "unexpected token in '.file' directive") ||
3410 parseEscapedString(SourceString))
3413 return TokError(
"unexpected token in '.file' directive");
3417 if (FileNumber == -1) {
3421 if (getContext().getAsmInfo()->hasSingleParameterDotFile())
3422 getStreamer().EmitFileDirective(Filename);
3435 for (
unsigned i = 0; i != 8; ++i) {
3436 Sum.
Bytes[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3437 Sum.
Bytes[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3442 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3443 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3444 Source =
StringRef(SourceBuf, SourceString.size());
3446 if (FileNumber == 0) {
3448 return Warning(DirectiveLoc,
"file 0 not supported prior to DWARF-5");
3449 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
3452 FileNumber, Directory, Filename, CKMem, Source);
3459 ReportedInconsistentMD5 =
true;
3460 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3469 bool AsmParser::parseDirectiveLine() {
3472 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
3478 "unexpected token in '.line' directive"))
3491 bool AsmParser::parseDirectiveLoc() {
3492 int64_t FileNumber = 0, LineNumber = 0;
3493 SMLoc Loc = getTok().getLoc();
3494 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
3496 "file number less than one in '.loc' directive") ||
3497 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
3498 "unassigned file number in '.loc' directive"))
3503 LineNumber = getTok().getIntVal();
3505 return TokError(
"line number less than zero in '.loc' directive");
3509 int64_t ColumnPos = 0;
3511 ColumnPos = getTok().getIntVal();
3513 return TokError(
"column position less than zero in '.loc' directive");
3519 int64_t Discriminator = 0;
3521 auto parseLocOp = [&]() ->
bool {
3523 SMLoc Loc = getTok().getLoc();
3524 if (parseIdentifier(Name))
3525 return TokError(
"unexpected token in '.loc' directive");
3527 if (Name ==
"basic_block")
3529 else if (Name ==
"prologue_end")
3531 else if (Name ==
"epilogue_begin")
3533 else if (Name ==
"is_stmt") {
3534 Loc = getTok().getLoc();
3536 if (parseExpression(Value))
3539 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3540 int Value = MCE->getValue();
3543 else if (Value == 1)
3546 return Error(Loc,
"is_stmt value not 0 or 1");
3548 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3550 }
else if (Name ==
"isa") {
3551 Loc = getTok().getLoc();
3553 if (parseExpression(Value))
3556 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3557 int Value = MCE->getValue();
3559 return Error(Loc,
"isa number less than zero");
3562 return Error(Loc,
"isa number not a constant value");
3564 }
else if (Name ==
"discriminator") {
3565 if (parseAbsoluteExpression(Discriminator))
3568 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3573 if (parseMany(parseLocOp,
false ))
3576 getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3584 bool AsmParser::parseDirectiveStabs() {
3585 return TokError(
"unsupported directive '.stabs'");
3590 bool AsmParser::parseDirectiveCVFile() {
3591 SMLoc FileNumberLoc = getTok().getLoc();
3593 std::string Filename;
3594 std::string Checksum;
3597 if (parseIntToken(FileNumber,
3598 "expected file number in '.cv_file' directive") ||
3599 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3601 "unexpected token in '.cv_file' directive") ||
3602 parseEscapedString(Filename))
3606 "unexpected token in '.cv_file' directive") ||
3607 parseEscapedString(Checksum) ||
3608 parseIntToken(ChecksumKind,
3609 "expected checksum kind in '.cv_file' directive") ||
3611 "unexpected token in '.cv_file' directive"))
3616 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3617 memcpy(CKMem, Checksum.data(), Checksum.size());
3621 if (!getStreamer().EmitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
3622 static_cast<uint8_t>(ChecksumKind)))
3623 return Error(FileNumberLoc,
"file number already allocated");
3628 bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3631 return parseTokenLoc(Loc) ||
3632 parseIntToken(FunctionId,
"expected function id in '" + DirectiveName +
3634 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3635 "expected function id within range [0, UINT_MAX)");
3638 bool AsmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
3640 return parseTokenLoc(Loc) ||
3641 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
3643 check(FileNumber < 1, Loc,
"file number less than one in '" +
3644 DirectiveName +
"' directive") ||
3645 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3646 "unassigned file number in '" + DirectiveName +
"' directive");
3653 bool AsmParser::parseDirectiveCVFuncId() {
3654 SMLoc FunctionIdLoc = getTok().getLoc();
3657 if (parseCVFunctionId(FunctionId,
".cv_func_id") ||
3659 "unexpected token in '.cv_func_id' directive"))
3662 if (!getStreamer().EmitCVFuncIdDirective(FunctionId))
3663 return Error(FunctionIdLoc,
"function id already allocated");
3676 bool AsmParser::parseDirectiveCVInlineSiteId() {
3677 SMLoc FunctionIdLoc = getTok().getLoc();
3685 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3690 getTok().getIdentifier() !=
"within"),
3691 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3696 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3701 getTok().getIdentifier() !=
"inlined_at"),
3702 "expected 'inlined_at' identifier in '.cv_inline_site_id' " 3708 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3709 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3714 IACol = getTok().getIntVal();
3719 "unexpected token in '.cv_inline_site_id' directive"))
3722 if (!getStreamer().EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3723 IALine, IACol, FunctionIdLoc))
3724 return Error(FunctionIdLoc,
"function id already allocated");
3736 bool AsmParser::parseDirectiveCVLoc() {
3737 SMLoc DirectiveLoc = getTok().getLoc();
3738 int64_t FunctionId, FileNumber;
3739 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3740 parseCVFileId(FileNumber,
".cv_loc"))
3743 int64_t LineNumber = 0;
3745 LineNumber = getTok().getIntVal();
3747 return TokError(
"line number less than zero in '.cv_loc' directive");
3751 int64_t ColumnPos = 0;
3753 ColumnPos = getTok().getIntVal();
3755 return TokError(
"column position less than zero in '.cv_loc' directive");
3759 bool PrologueEnd =
false;
3760 uint64_t IsStmt = 0;
3762 auto parseOp = [&]() ->
bool {
3764 SMLoc Loc = getTok().getLoc();
3765 if (parseIdentifier(Name))
3766 return TokError(
"unexpected token in '.cv_loc' directive");
3767 if (Name ==
"prologue_end")
3769 else if (Name ==
"is_stmt") {
3770 Loc = getTok().getLoc();
3772 if (parseExpression(Value))
3776 if (
const auto *MCE = dyn_cast<MCConstantExpr>(Value))
3777 IsStmt = MCE->getValue();
3780 return Error(Loc,
"is_stmt value not 0 or 1");
3782 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3787 if (parseMany(parseOp,
false ))
3790 getStreamer().EmitCVLocDirective(FunctionId, FileNumber, LineNumber,
3791 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
3798 bool AsmParser::parseDirectiveCVLinetable() {
3801 SMLoc Loc = getTok().getLoc();
3802 if (parseCVFunctionId(FunctionId,
".cv_linetable") ||
3804 "unexpected token in '.cv_linetable' directive") ||
3805 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3806 "expected identifier in directive") ||
3808 "unexpected token in '.cv_linetable' directive") ||
3809 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3810 "expected identifier in directive"))
3813 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3814 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3816 getStreamer().EmitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3822 bool AsmParser::parseDirectiveCVInlineLinetable() {
3823 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3825 SMLoc Loc = getTok().getLoc();
3826 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3827 parseTokenLoc(Loc) ||
3830 "expected SourceField in '.cv_inline_linetable' directive") ||
3831 check(SourceFileId <= 0, Loc,
3832 "File id less than zero in '.cv_inline_linetable' directive") ||
3833 parseTokenLoc(Loc) ||
3836 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
3837 check(SourceLineNum < 0, Loc,
3838 "Line number less than zero in '.cv_inline_linetable' directive") ||
3839 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3840 "expected identifier in directive") ||
3841 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3842 "expected identifier in directive"))
3848 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3849 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3850 getStreamer().EmitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3851 SourceLineNum, FnStartSym,
3856 void AsmParser::initializeCVDefRangeTypeMap() {
3857 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
3858 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
3859 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
3860 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
3865 bool AsmParser::parseDirectiveCVDefRange() {
3867 std::vector<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
3869 Loc = getLexer().getLoc();
3871 if (parseIdentifier(GapStartName))
3872 return Error(Loc,
"expected identifier in directive");
3873 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
3875 Loc = getLexer().getLoc();
3877 if (parseIdentifier(GapEndName))
3878 return Error(Loc,
"expected identifier in directive");
3879 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
3881 Ranges.push_back({GapStartSym, GapEndSym});
3887 "expected comma before def_range type in .cv_def_range directive") ||
3888 parseIdentifier(CVDefRangeTypeStr))
3889 return Error(Loc,
"expected def_range type in directive");
3892 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
3893 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
3895 : CVTypeIt->getValue();
3897 case CVDR_DEFRANGE_REGISTER: {
3899 if (parseToken(
AsmToken::Comma,
"expected comma before register number in " 3900 ".cv_def_range directive") ||
3901 parseAbsoluteExpression(DRRegister))
3902 return Error(Loc,
"expected register number");
3907 getStreamer().EmitCVDefRangeDirective(Ranges, DRHdr);
3910 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
3913 "expected comma before offset in .cv_def_range directive") ||
3914 parseAbsoluteExpression(DROffset))
3915 return Error(Loc,
"expected offset value");
3919 getStreamer().EmitCVDefRangeDirective(Ranges, DRHdr);
3922 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
3924 int64_t DROffsetInParent;
3925 if (parseToken(
AsmToken::Comma,
"expected comma before register number in " 3926 ".cv_def_range directive") ||
3927 parseAbsoluteExpression(DRRegister))
3928 return Error(Loc,
"expected register number");
3930 "expected comma before offset in .cv_def_range directive") ||
3931 parseAbsoluteExpression(DROffsetInParent))
3932 return Error(Loc,
"expected offset value");
3938 getStreamer().EmitCVDefRangeDirective(Ranges, DRHdr);
3941 case CVDR_DEFRANGE_REGISTER_REL: {
3944 int64_t DRBasePointerOffset;
3945 if (parseToken(
AsmToken::Comma,
"expected comma before register number in " 3946 ".cv_def_range directive") ||
3947 parseAbsoluteExpression(DRRegister))
3948 return Error(Loc,
"expected register value");
3951 "expected comma before flag value in .cv_def_range directive") ||
3952 parseAbsoluteExpression(DRFlags))
3953 return Error(Loc,
"expected flag value");
3954 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset " 3955 "in .cv_def_range directive") ||
3956 parseAbsoluteExpression(DRBasePointerOffset))
3957 return Error(Loc,
"expected base pointer offset value");
3961 DRHdr.
Flags = DRFlags;
3963 getStreamer().EmitCVDefRangeDirective(Ranges, DRHdr);
3967 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
3974 bool AsmParser::parseDirectiveCVString() {
3976 if (checkForValidSection() || parseEscapedString(Data))
3977 return addErrorSuffix(
" in '.cv_string' directive");
3980 std::pair<StringRef, unsigned> Insertion =
3981 getCVContext().addToStringTable(Data);
3982 getStreamer().EmitIntValue(Insertion.second, 4);
3988 bool AsmParser::parseDirectiveCVStringTable() {
3989 getStreamer().EmitCVStringTableDirective();
3995 bool AsmParser::parseDirectiveCVFileChecksums() {
3996 getStreamer().EmitCVFileChecksumsDirective();
4002 bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4004 if (parseIntToken(FileNo,
"expected identifier in directive"))
4008 getStreamer().EmitCVFileChecksumOffsetDirective(FileNo);
4014 bool AsmParser::parseDirectiveCVFPOData() {
4015 SMLoc DirLoc = getLexer().getLoc();
4017 if (parseIdentifier(ProcName))
4018 return TokError(
"expected symbol name");
4019 if (parseEOL(
"unexpected tokens"))
4020 return addErrorSuffix(
" in '.cv_fpo_data' directive");
4021 MCSymbol *ProcSym = getContext().getOrCreateSymbol(ProcName);
4022 getStreamer().EmitCVFPOData(ProcSym, DirLoc);
4028 bool AsmParser::parseDirectiveCFISections() {
4033 if (parseIdentifier(Name))
4034 return TokError(
"Expected an identifier");
4036 if (Name ==
".eh_frame")
4038 else if (Name ==
".debug_frame")
4044 if (parseIdentifier(Name))
4045 return TokError(
"Expected an identifier");
4047 if (Name ==
".eh_frame")
4049 else if (Name ==
".debug_frame")
4053 getStreamer().EmitCFISections(EH, Debug);
4059 bool AsmParser::parseDirectiveCFIStartProc() {
4062 if (check(parseIdentifier(Simple) || Simple !=
"simple",
4063 "unexpected token") ||
4065 return addErrorSuffix(
" in '.cfi_startproc' directive");
4073 getStreamer().EmitCFIStartProc(!Simple.
empty(), Lexer.
getLoc());
4079 bool AsmParser::parseDirectiveCFIEndProc() {
4080 getStreamer().EmitCFIEndProc();
4085 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4086 SMLoc DirectiveLoc) {
4090 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4092 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
4094 return parseAbsoluteExpression(Register);
4101 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
4102 int64_t Register = 0,
Offset = 0;
4103 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
4105 parseAbsoluteExpression(
Offset))
4108 getStreamer().EmitCFIDefCfa(Register,
Offset);
4114 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
4116 if (parseAbsoluteExpression(Offset))
4119 getStreamer().EmitCFIDefCfaOffset(Offset);
4125 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
4126 int64_t Register1 = 0, Register2 = 0;
4127 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) ||
4129 parseRegisterOrRegisterNumber(Register2, DirectiveLoc))
4132 getStreamer().EmitCFIRegister(Register1, Register2);
4138 bool AsmParser::parseDirectiveCFIWindowSave() {
4139 getStreamer().EmitCFIWindowSave();
4145 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
4146 int64_t Adjustment = 0;
4147 if (parseAbsoluteExpression(Adjustment))
4150 getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
4156 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
4157 int64_t Register = 0;
4158 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4161 getStreamer().EmitCFIDefCfaRegister(Register);
4167 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
4168 int64_t Register = 0;
4171 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
4173 parseAbsoluteExpression(Offset))
4176 getStreamer().EmitCFIOffset(Register, Offset);
4182 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
4183 int64_t Register = 0,
Offset = 0;
4185 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
4187 parseAbsoluteExpression(
Offset))
4190 getStreamer().EmitCFIRelOffset(Register,
Offset);
4195 if (Encoding & ~0xff)
4201 const unsigned Format = Encoding & 0xf;
4208 const unsigned Application = Encoding & 0x70;
4220 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4221 int64_t Encoding = 0;
4222 if (parseAbsoluteExpression(Encoding))
4230 check(parseIdentifier(Name),
"expected identifier in directive"))
4233 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4236 getStreamer().EmitCFIPersonality(Sym, Encoding);
4238 getStreamer().EmitCFILsda(Sym, Encoding);
4244 bool AsmParser::parseDirectiveCFIRememberState() {
4245 getStreamer().EmitCFIRememberState();
4251 bool AsmParser::parseDirectiveCFIRestoreState() {
4252 getStreamer().EmitCFIRestoreState();
4258 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
4259 int64_t Register = 0;
4261 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4264 getStreamer().EmitCFISameValue(Register);
4270 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
4271 int64_t Register = 0;
4272 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4275 getStreamer().EmitCFIRestore(Register);
4281 bool AsmParser::parseDirectiveCFIEscape() {
4284 if (parseAbsoluteExpression(CurrValue))
4287 Values.push_back((uint8_t)CurrValue);
4292 if (parseAbsoluteExpression(CurrValue))
4295 Values.push_back((uint8_t)CurrValue);
4298 getStreamer().EmitCFIEscape(Values);
4304 bool AsmParser::parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc) {
4305 int64_t Register = 0;
4306 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4308 getStreamer().EmitCFIReturnColumn(Register);
4314 bool AsmParser::parseDirectiveCFISignalFrame() {
4316 "unexpected token in '.cfi_signal_frame'"))
4319 getStreamer().EmitCFISignalFrame();
4325 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
4326 int64_t Register = 0;
4328 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4331 getStreamer().EmitCFIUndefined(Register);
4340 return TokError(
"unexpected token in '" + Directive +
"' directive");
4341 AltMacroMode = (Directive ==
".altmacro");
4348 bool AsmParser::parseDirectiveMacrosOnOff(
StringRef Directive) {
4350 "unexpected token in '" + Directive +
"' directive"))
4353 setMacrosEnabled(Directive ==
".macros_on");
4359 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
4361 if (parseIdentifier(Name))
4362 return TokError(
"expected identifier in '.macro' directive");
4370 if (!Parameters.empty() && Parameters.back().Vararg)
4372 "Vararg parameter '" + Parameters.back().Name +
4373 "' should be last one in the list of parameters.");
4376 if (parseIdentifier(Parameter.
Name))
4377 return TokError(
"expected identifier in '.macro' directive");
4381 if (CurrParam.Name.equals(Parameter.
Name))
4382 return TokError(
"macro '" + Name +
"' has multiple parameters" 4383 " named '" + Parameter.
Name +
"'");
4391 QualLoc = Lexer.
getLoc();
4392 if (parseIdentifier(Qualifier))
4393 return Error(QualLoc,
"missing parameter qualifier for " 4394 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4396 if (Qualifier ==
"req")
4398 else if (Qualifier ==
"vararg")
4401 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier " 4402 "for '" + Parameter.
Name +
"' in macro '" + Name +
"'");
4410 ParamLoc = Lexer.
getLoc();
4411 if (parseMacroArgument(Parameter.
Value,
false ))
4415 Warning(ParamLoc,
"pointless default value for required parameter " 4416 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4419 Parameters.push_back(std::move(Parameter));
4429 AsmToken EndToken, StartToken = getTok();
4430 unsigned MacroDepth = 0;
4440 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4444 if (getTok().getIdentifier() ==
".endm" ||
4445 getTok().getIdentifier() ==
".endmacro") {
4446 if (MacroDepth == 0) {
4447 EndToken = getTok();
4450 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4457 }
else if (getTok().getIdentifier() ==
".macro") {
4465 eatToEndOfStatement();
4468 if (getContext().lookupMacro(Name)) {
4469 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4475 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4479 getContext().defineMacro(Name, std::move(Macro));
4497 void AsmParser::checkForBadMacro(
SMLoc DirectiveLoc,
StringRef Name,
4502 unsigned NParameters = Parameters.
size();
4503 if (NParameters == 0)
4506 bool NamedParametersFound =
false;
4507 bool PositionalParametersFound =
false;
4512 while (!Body.
empty()) {
4514 std::size_t End = Body.
size(), Pos = 0;
4515 for (; Pos != End; ++Pos) {
4518 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4522 if (Body[Pos] !=
'$' || Pos + 1 == End)
4524 char Next = Body[Pos + 1];
4525 if (Next ==
'$' || Next ==
'n' ||
4526 isdigit(static_cast<unsigned char>(Next)))
4534 if (Body[Pos] ==
'$') {
4535 switch (Body[Pos + 1]) {
4542 PositionalParametersFound =
true;
4547 PositionalParametersFound =
true;
4553 unsigned I = Pos + 1;
4557 const char *Begin = Body.
data() + Pos + 1;
4560 for (; Index < NParameters; ++
Index)
4561 if (Parameters[Index].Name == Argument)
4564 if (Index == NParameters) {
4565 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4571 NamedParametersFound =
true;
4572 Pos += 1 + Argument.
size();
4579 if (!NamedParametersFound && PositionalParametersFound)
4580 Warning(DirectiveLoc,
"macro defined with named parameters which are not " 4581 "used in macro body, possible positional parameter " 4582 "found in body which will have no effect");
4587 bool AsmParser::parseDirectiveExitMacro(
StringRef Directive) {
4589 "unexpected token in '" + Directive +
"' directive"))
4592 if (!isInsideMacroInstantiation())
4593 return TokError(
"unexpected '" + Directive +
"' in file, " 4594 "no current macro definition");
4597 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4598 TheCondState = TheCondStack.back();
4599 TheCondStack.pop_back();
4609 bool AsmParser::parseDirectiveEndMacro(
StringRef Directive) {
4611 return TokError(
"unexpected token in '" + Directive +
"' directive");
4615 if (isInsideMacroInstantiation()) {
4622 return TokError(
"unexpected '" + Directive +
"' in file, " 4623 "no current macro definition");
4628 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
4631 if (parseTokenLoc(Loc) ||
4632 check(parseIdentifier(Name), Loc,
4633 "expected identifier in '.purgem' directive") ||
4635 "unexpected token in '.purgem' directive"))
4638 if (!getContext().lookupMacro(Name))
4639 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4641 getContext().undefineMacro(Name);
4643 <<
"Un-defining macro: " << Name <<
"\n");
4649 bool AsmParser::parseDirectiveBundleAlignMode() {
4652 SMLoc ExprLoc = getLexer().getLoc();
4653 int64_t AlignSizePow2;
4654 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4656 "in '.bundle_align_mode' " 4658 check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
4659 "invalid bundle alignment size (expected between 0 and 30)"))
4664 getStreamer().EmitBundleAlignMode(static_cast<unsigned>(AlignSizePow2));
4670 bool AsmParser::parseDirectiveBundleLock() {
4671 if (checkForValidSection())
4673 bool AlignToEnd =
false;
4676 SMLoc Loc = getTok().getLoc();
4677 const char *kInvalidOptionError =
4678 "invalid option for '.bundle_lock' directive";
4681 if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
4682 check(Option !=
"align_to_end", Loc, kInvalidOptionError) ||
4684 "unexpected token after '.bundle_lock' directive option"))
4689 getStreamer().EmitBundleLock(AlignToEnd);
4695 bool AsmParser::parseDirectiveBundleUnlock() {
4696 if (checkForValidSection() ||
4698 "unexpected token in '.bundle_unlock' directive"))
4701 getStreamer().EmitBundleUnlock();
4707 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
4710 if (checkForValidSection() || parseExpression(NumBytes))
4713 int64_t FillExpr = 0;
4715 if (parseAbsoluteExpression(FillExpr))
4716 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4718 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4721 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4728 bool AsmParser::parseDirectiveDCB(
StringRef IDVal,
unsigned Size) {
4731 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4734 if (NumValues < 0) {
4735 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4740 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4744 SMLoc ExprLoc = getLexer().getLoc();
4745 if (parseExpression(Value))
4749 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
4750 assert(Size <= 8 &&
"Invalid size");
4751 uint64_t IntValue = MCE->getValue();
4752 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
4753 return Error(ExprLoc,
"literal value out of range for directive");
4754 for (uint64_t i = 0,
e = NumValues; i !=
e; ++i)
4755 getStreamer().EmitIntValue(IntValue, Size);
4757 for (uint64_t i = 0,
e = NumValues; i !=
e; ++i)
4758 getStreamer().EmitValue(Value, Size, ExprLoc);
4762 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4773 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4776 if (NumValues < 0) {
4777 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4782 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4786 if (parseRealValue(Semantics, AsInt))
4790 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4793 for (uint64_t i = 0,
e = NumValues; i !=
e; ++i)
4802 bool AsmParser::parseDirectiveDS(
StringRef IDVal,
unsigned Size) {
4805 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4808 if (NumValues < 0) {
4809 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4814 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4817 for (uint64_t i = 0,
e = NumValues; i !=
e; ++i)
4818 getStreamer().emitFill(Size, 0);
4825 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4826 if (checkForValidSection())
4829 auto parseOp = [&]() ->
bool {
4831 if (parseExpression(Value))
4834 getStreamer().EmitSLEB128Value(Value);
4836 getStreamer().EmitULEB128Value(Value);
4840 if (parseMany(parseOp))
4841 return addErrorSuffix(
" in directive");
4848 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4849 auto parseOp = [&]() ->
bool {
4851 SMLoc Loc = getTok().getLoc();
4852 if (parseIdentifier(Name))
4853 return Error(Loc,
"expected identifier");
4854 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4858 return Error(Loc,
"non-local symbol required");
4860 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
4861 return Error(Loc,
"unable to emit symbol attribute");
4865 if (parseMany(parseOp))
4866 return addErrorSuffix(
" in directive");
4872 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4873 if (checkForValidSection())
4876 SMLoc IDLoc = getLexer().getLoc();
4878 if (parseIdentifier(Name))
4879 return TokError(
"expected identifier in directive");
4882 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4885 return TokError(
"unexpected token in directive");
4889 SMLoc SizeLoc = getLexer().getLoc();
4890 if (parseAbsoluteExpression(Size))
4893 int64_t Pow2Alignment = 0;
4894 SMLoc Pow2AlignmentLoc;
4897 Pow2AlignmentLoc = getLexer().getLoc();
4898 if (parseAbsoluteExpression(Pow2Alignment))
4903 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4909 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4910 Pow2Alignment =
Log2_64(Pow2Alignment);
4915 "unexpected token in '.comm' or '.lcomm' directive"))
4921 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't " 4922 "be less than zero");
4927 if (Pow2Alignment < 0)
4928 return Error(Pow2AlignmentLoc,
"invalid '.comm' or '.lcomm' directive " 4929 "alignment, can't be less than zero");
4933 return Error(IDLoc,
"invalid symbol redefinition");
4937 getStreamer().EmitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4941 getStreamer().EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4947 bool AsmParser::parseDirectiveAbort() {
4949 SMLoc Loc = getLexer().getLoc();
4951 StringRef Str = parseStringToEndOfStatement();
4953 "unexpected token in '.abort' directive"))
4957 return Error(Loc,
".abort detected. Assembly stopping.");
4959 return Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
4967 bool AsmParser::parseDirectiveInclude() {
4969 std::string Filename;
4970 SMLoc IncludeLoc = getTok().getLoc();
4973 "expected string in '.include' directive") ||
4974 parseEscapedString(Filename) ||
4976 "unexpected token in '.include' directive") ||
4979 check(enterIncludeFile(Filename), IncludeLoc,
4980 "Could not find include file '" + Filename +
"'"))
4988 bool AsmParser::parseDirectiveIncbin() {
4990 std::string Filename;
4991 SMLoc IncbinLoc = getTok().getLoc();
4993 "expected string in '.incbin' directive") ||
4994 parseEscapedString(Filename))
4998 const MCExpr *Count =
nullptr;
4999 SMLoc SkipLoc, CountLoc;
5004 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5008 CountLoc = getTok().getLoc();
5009 if (parseExpression(Count))
5015 "unexpected token in '.incbin' directive"))
5018 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5022 if (processIncbinFile(Filename, Skip, Count, CountLoc))
5023 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
5029 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
5030 TheCondStack.push_back(TheCondState);
5032 if (TheCondState.
Ignore) {
5033 eatToEndOfStatement();
5036 if (parseAbsoluteExpression(ExprValue) ||
5038 "unexpected token in '.if' directive"))
5048 ExprValue = ExprValue == 0;
5051 ExprValue = ExprValue >= 0;
5054 ExprValue = ExprValue > 0;
5057 ExprValue = ExprValue <= 0;
5060 ExprValue = ExprValue < 0;
5064 TheCondState.
CondMet = ExprValue;
5073 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
5074 TheCondStack.push_back(TheCondState);
5077 if (TheCondState.
Ignore) {
5078 eatToEndOfStatement();
5080 StringRef Str = parseStringToEndOfStatement();
5083 "unexpected token in '.ifb' directive"))
5096 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
5097 TheCondStack.push_back(TheCondState);
5100 if (TheCondState.
Ignore) {
5101 eatToEndOfStatement();
5105 if (parseToken(
AsmToken::Comma,
"unexpected token in '.ifc' directive"))
5108 StringRef Str2 = parseStringToEndOfStatement();
5111 "unexpected token in '.ifc' directive"))
5123 bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
5126 return TokError(
"expected string parameter for '.ifeqs' directive");
5127 return TokError(
"expected string parameter for '.ifnes' directive");
5130 StringRef String1 = getTok().getStringContents();
5136 "expected comma after first string for '.ifeqs' directive");
5137 return TokError(
"expected comma after first string for '.ifnes' directive");
5144 return TokError(
"expected string parameter for '.ifeqs' directive");
5145 return TokError(
"expected string parameter for '.ifnes' directive");
5148 StringRef String2 = getTok().getStringContents();
5151 TheCondStack.push_back(TheCondState);
5153 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5161 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
5163 TheCondStack.push_back(TheCondState);
5166 if (TheCondState.
Ignore) {
5167 eatToEndOfStatement();
5169 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5173 MCSymbol *Sym = getContext().lookupSymbol(Name);
5187 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
5190 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an" 5191 " .if or an .elseif");
5194 bool LastIgnoreState =
false;
5195 if (!TheCondStack.empty())
5196 LastIgnoreState = TheCondStack.back().Ignore;
5197 if (LastIgnoreState || TheCondState.
CondMet) {
5198 TheCondState.
Ignore =
true;
5199 eatToEndOfStatement();
5202 if (parseAbsoluteExpression(ExprValue))
5206 "unexpected token in '.elseif' directive"))
5209 TheCondState.
CondMet = ExprValue;
5218 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
5220 "unexpected token in '.else' directive"))
5225 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow " 5226 " an .if or an .elseif");
5228 bool LastIgnoreState =
false;
5229 if (!TheCondStack.empty())
5230 LastIgnoreState = TheCondStack.back().Ignore;
5231 if (LastIgnoreState || TheCondState.
CondMet)
5232 TheCondState.
Ignore =
true;
5234 TheCondState.
Ignore =
false;
5241 bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
5243 "unexpected token in '.end' directive"))
5255 bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
5256 if (!TheCondStack.empty()) {
5257 if (TheCondStack.back().Ignore) {
5258 eatToEndOfStatement();
5264 return Error(L,
".err encountered");
5266 StringRef Message =
".error directive invoked in source file";
5269 return TokError(
".error argument must be a string");
5271 Message = getTok().getStringContents();
5275 return Error(L, Message);
5280 bool AsmParser::parseDirectiveWarning(
SMLoc L) {
5281 if (!TheCondStack.empty()) {
5282 if (TheCondStack.back().Ignore) {
5283 eatToEndOfStatement();
5288 StringRef Message =
".warning directive invoked in source file";
5292 return TokError(
".warning argument must be a string");
5294 Message = getTok().getStringContents();
5297 "expected end of statement in '.warning' directive"))
5306 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
5308 "unexpected token in '.endif' directive"))
5312 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow " 5314 if (!TheCondStack.empty()) {
5315 TheCondState = TheCondStack.back();
5316 TheCondStack.pop_back();
5322 void AsmParser::initializeDirectiveKindMap() {
5323 DirectiveKindMap[
".set"] = DK_SET;
5324 DirectiveKindMap[
".equ"] = DK_EQU;
5325 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5326 DirectiveKindMap[
".ascii"] = DK_ASCII;
5327 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5328 DirectiveKindMap[
".string"] = DK_STRING;
5329 DirectiveKindMap[
".byte"] = DK_BYTE;
5330 DirectiveKindMap[
".short"] = DK_SHORT;
5331 DirectiveKindMap[
".value"] = DK_VALUE;
5332 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5333 DirectiveKindMap[
".long"] = DK_LONG;
5334 DirectiveKindMap[
".int"] = DK_INT;
5335 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5336 DirectiveKindMap[
".quad"] = DK_QUAD;
5337 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5338 DirectiveKindMap[
".octa"] = DK_OCTA;
5339 DirectiveKindMap[
".single"] = DK_SINGLE;
5340 DirectiveKindMap[
".float"] = DK_FLOAT;
5341 DirectiveKindMap[
".double"] = DK_DOUBLE;
5342 DirectiveKindMap[
".align"] = DK_ALIGN;
5343 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5344 DirectiveKindMap[
".balign"] = DK_BALIGN;
5345 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5346 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5347 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5348 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5349 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5350 DirectiveKindMap[
".org"] = DK_ORG;
5351 DirectiveKindMap[
".fill"] = DK_FILL;
5352 DirectiveKindMap[
".zero"] = DK_ZERO;
5353 DirectiveKindMap[
".extern"] = DK_EXTERN;
5354 DirectiveKindMap[
".globl"] = DK_GLOBL;
5355 DirectiveKindMap[
".global"] = DK_GLOBAL;
5356 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5357 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5358 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5359 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5360 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5361 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5362 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5363 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5364 DirectiveKindMap[
".cold"] = DK_COLD;
5365 DirectiveKindMap[
".comm"] = DK_COMM;
5366 DirectiveKindMap[
".common"] = DK_COMMON;
5367 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5368 DirectiveKindMap[
".abort"] = DK_ABORT;
5369 DirectiveKindMap[
".include"] = DK_INCLUDE;
5370 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5371 DirectiveKindMap[
".code16"] = DK_CODE16;
5372 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5373 DirectiveKindMap[
".rept"] = DK_REPT;
5374 DirectiveKindMap[
".rep"] = DK_REPT;
5375 DirectiveKindMap[
".irp"] = DK_IRP;
5376 DirectiveKindMap[
".irpc"] = DK_IRPC;
5377 DirectiveKindMap[
".endr"] = DK_ENDR;
5378 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5379 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5380 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5381 DirectiveKindMap[
".if"] = DK_IF;
5382 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5383 DirectiveKindMap[
".ifge"] = DK_IFGE;
5384 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5385 DirectiveKindMap[
".ifle"] = DK_IFLE;
5386 DirectiveKindMap[
".iflt"] = DK_IFLT;
5387 DirectiveKindMap[
".ifne"] = DK_IFNE;
5388 DirectiveKindMap[
".ifb"] = DK_IFB;
5389 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5390 DirectiveKindMap[
".ifc"] = DK_IFC;
5391 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5392 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5393 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5394 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5395 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5396 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5397 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5398 DirectiveKindMap[
".else"] = DK_ELSE;
5399 DirectiveKindMap[
".end"] = DK_END;
5400 DirectiveKindMap[
".endif"] = DK_ENDIF;
5401 DirectiveKindMap[
".skip"] = DK_SKIP;
5402 DirectiveKindMap[
".space"] = DK_SPACE;
5403 DirectiveKindMap[
".file"] = DK_FILE;
5404 DirectiveKindMap[
".line"] = DK_LINE;
5405 DirectiveKindMap[
".loc"] = DK_LOC;
5406 DirectiveKindMap[
".stabs"] = DK_STABS;
5407 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5408 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5409 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5410 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5411 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5412 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5413 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5414 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5415 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5416 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5417 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5418 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5419 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5420 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5421 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5422 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5423 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5424 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5425 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5426 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5427 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5428 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5429 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5430 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5431 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5432 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5433 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5434 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5435 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5436 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5437 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5438 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5439 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5440 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5441 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5442 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5443 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5444 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5445 DirectiveKindMap[
".macro"] = DK_MACRO;
5446 DirectiveKindMap[
".exitm"] = DK_EXITM;
5447 DirectiveKindMap[
".endm"] = DK_ENDM;
5448 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5449 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5450 DirectiveKindMap[
".err"] = DK_ERR;
5451 DirectiveKindMap[
".error"] = DK_ERROR;
5452 DirectiveKindMap[
".warning"] = DK_WARNING;
5453 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5454 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5455 DirectiveKindMap[
".reloc"] = DK_RELOC;
5456 DirectiveKindMap[
".dc"] = DK_DC;
5457 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5458 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5459 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5460 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5461 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5462 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5463 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5464 DirectiveKindMap[
".dcb"] = DK_DCB;
5465 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5466 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5467 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5468 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5469 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5470 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5471 DirectiveKindMap[
".ds"] = DK_DS;
5472 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5473 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5474 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5475 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5476 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5477 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5478 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5479 DirectiveKindMap[
".print"] = DK_PRINT;
5480 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5481 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5485 AsmToken EndToken, StartToken = getTok();
5487 unsigned NestLevel = 0;
5491 printError(DirectiveLoc,
"no matching '.endr' in definition");
5496 (getTok().getIdentifier() ==
".rep" ||
5497 getTok().getIdentifier() ==
".rept" ||
5498 getTok().getIdentifier() ==
".irp" ||
5499 getTok().getIdentifier() ==
".irpc")) {
5505 if (NestLevel == 0) {
5506 EndToken = getTok();
5509 printError(getTok().getLoc(),
5510 "unexpected token in '.endr' directive");
5519 eatToEndOfStatement();
5528 return &MacroLikeBodies.back();
5531 void AsmParser::instantiateMacroLikeBody(
MCAsmMacro *M,
SMLoc DirectiveLoc,
5535 std::unique_ptr<MemoryBuffer> Instantiation =
5540 MacroInstantiation *
MI =
new MacroInstantiation{
5541 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5542 ActiveMacros.push_back(MI);
5552 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
5554 SMLoc CountLoc = getTok().getLoc();
5555 if (parseExpression(CountExpr))
5559 if (!CountExpr->evaluateAsAbsolute(Count, getStreamer().getAssemblerPtr())) {
5560 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5563 if (check(Count < 0, CountLoc,
"Count is negative") ||
5565 "unexpected token in '" + Dir +
"' directive"))
5569 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5579 if (expandMacro(OS, M->
Body,
None,
None,
false, getTok().getLoc()))
5582 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5589 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
5591 MCAsmMacroArguments A;
5592 if (check(parseIdentifier(Parameter.
Name),
5593 "expected identifier in '.irp' directive") ||
5595 parseMacroArguments(
nullptr, A) ||
5600 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5609 for (
const MCAsmMacroArgument &
Arg : A) {
5612 if (expandMacro(OS, M->
Body, Parameter,
Arg,
true, getTok().getLoc()))
5616 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5623 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
5625 MCAsmMacroArguments A;
5627 if (check(parseIdentifier(Parameter.
Name),
5628 "expected identifier in '.irpc' directive") ||
5630 parseMacroArguments(
nullptr, A))
5633 if (A.size() != 1 || A.front().size() != 1)
5634 return TokError(
"unexpected token in '.irpc' directive");
5641 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5651 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5652 MCAsmMacroArgument
Arg;
5657 if (expandMacro(OS, M->
Body, Parameter, Arg,
true, getTok().getLoc()))
5661 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5666 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
5667 if (ActiveMacros.empty())
5668 return TokError(
"unmatched '.endr' directive");
5678 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
5681 SMLoc ExprLoc = getLexer().getLoc();
5682 if (parseExpression(Value))
5686 return Error(ExprLoc,
"unexpected expression in _emit");
5687 uint64_t IntValue = MCE->
getValue();
5689 return Error(ExprLoc,
"literal value out of range for directive");
5691 Info.AsmRewrites->emplace_back(
AOK_Emit, IDLoc, Len);
5695 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
5697 SMLoc ExprLoc = getLexer().getLoc();
5698 if (parseExpression(Value))
5702 return Error(ExprLoc,
"unexpected expression in align");
5703 uint64_t IntValue = MCE->
getValue();
5705 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5711 bool AsmParser::parseDirectivePrint(
SMLoc DirectiveLoc) {
5715 return Error(DirectiveLoc,
"expected double quoted string after .print");
5722 bool AsmParser::parseDirectiveAddrsig() {
5723 getStreamer().EmitAddrsig();
5727 bool AsmParser::parseDirectiveAddrsigSym() {
5729 if (check(parseIdentifier(Name),
5730 "expected identifier in '.addrsig_sym' directive"))
5732 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
5733 getStreamer().EmitAddrsigSym(Sym);
5760 bool AsmParser::parseMSInlineAsm(
5761 void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs,
5762 unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5780 unsigned InputIdx = 0;
5781 unsigned OutputIdx = 0;
5784 if (parseCurlyBlockScope(AsmStrRewrites))
5787 ParseStatementInfo
Info(&AsmStrRewrites);
5788 bool StatementErr = parseStatement(Info, &SI);
5790 if (StatementErr || Info.ParseError) {
5792 printPendingErrors();
5797 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5799 if (Info.Opcode == ~0U)
5805 for (
unsigned i = 1,
e = Info.ParsedOperands.size(); i !=
e; ++i) {
5810 !getTargetParser().OmitRegisterFromClobberLists(Operand.
getReg())) {
5820 if (SymName.
empty())
5828 if (Operand.
isImm()) {
5836 bool isOutput = (i == 1) && Desc.
mayStore();
5842 OutputConstraints.
push_back((
"=" + Constraint).str());
5858 ClobberRegs.
insert(ClobberRegs.
end(), ImpDefs.begin(), ImpDefs.end());
5862 NumOutputs = OutputDecls.
size();
5863 NumInputs = InputDecls.
size();
5867 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
5869 Clobbers.
assign(ClobberRegs.
size(), std::string());
5870 for (
unsigned I = 0, E = ClobberRegs.
size();
I !=
E; ++
I) {
5876 if (NumOutputs || NumInputs) {
5877 unsigned NumExprs = NumOutputs + NumInputs;
5878 OpDecls.resize(NumExprs);
5879 Constraints.
resize(NumExprs);
5880 for (
unsigned i = 0; i < NumOutputs; ++i) {
5881 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
5882 Constraints[i] = OutputConstraints[i];
5884 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) {
5885 OpDecls[j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
5886 Constraints[j] = InputConstraints[i];
5891 std::string AsmStringIR;
5895 const char *AsmStart = ASMString.
begin();
5896 const char *AsmEnd = ASMString.
end();
5898 for (
auto it = AsmStrRewrites.
begin(); it != AsmStrRewrites.
end(); ++it) {
5906 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
5909 if (
unsigned Len = Loc - AsmStart)
5914 AsmStart = Loc + AR.
Len;
5918 unsigned AdditionalSkip = 0;
5940 size_t OffsetLen = OffsetName.
size();
5943 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
5947 if (rewrite_it == AsmStrRewrites.
end()) {
5948 OS <<
"offset " << OffsetName;
5950 OS <<
"${" << InputIdx++ <<
":P}";
5951 rewrite_it->Done =
true;
5953 OS <<
'$' << InputIdx++;
5954 rewrite_it->Done =
true;
5966 OS <<
'$' << InputIdx++;
5969 OS <<
"${" << InputIdx++ <<
":P}";
5972 OS <<
'$' << OutputIdx++;
5977 case 8: OS <<
"byte ptr ";
break;
5978 case 16: OS <<
"word ptr ";
break;
5979 case 32: OS <<
"dword ptr ";
break;
5980 case 64: OS <<
"qword ptr ";
break;
5981 case 80: OS <<
"xword ptr ";
break;
5982 case 128: OS <<
"xmmword ptr ";
break;
5983 case 256: OS <<
"ymmword ptr ";
break;
5993 if (getContext().getAsmInfo()->getAlignmentIsInBytes())
5998 unsigned Val = AR.
Val;
6000 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6001 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6013 AsmStart = Loc + AR.
Len + AdditionalSkip;
6017 if (AsmStart != AsmEnd)
6018 OS <<
StringRef(AsmStart, AsmEnd - AsmStart);
6020 AsmString = OS.
str();
6025 namespace MCParserUtils {
6048 Sym, static_cast<const MCUnaryExpr *>(Value)->getSubExpr());
6061 return Parser.
TokError(
"missing expression");
6079 return Parser.
Error(EqualLoc,
"Recursive use of '" + Name +
"'");
6086 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6088 return Parser.
Error(EqualLoc,
"invalid assignment to '" + Name +
"'");
6090 return Parser.
Error(EqualLoc,
6091 "invalid reassignment of non-absolute variable '" +
6093 }
else if (Name ==
".") {
6111 return new AsmParser(SM, C, Out, MAI, CB);
static const MCUnaryExpr * createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
bool getCOMMDirectiveAlignmentIsInBytes() const
const MCAsmInfo * getAsmInfo() const
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
constexpr bool isUInt< 32 >(uint64_t x)
Represents a range in source code.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Signed less than comparison (result is either 0 or some target-specific non-zero value).
static bool parseHexOcta(AsmParser &Asm, uint64_t &hi, uint64_t &lo)
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
LLVM_NODISCARD StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
reference emplace_back(ArgTypes &&... Args)
const AsmToken & getTok() const
Get the current (last) lexed token.
const MCAsmInfo & getMAI() const
void setGenDwarfForAssembly(bool Value)
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual ~MCAsmParserSemaCallback()
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
uint64_t getZExtValue() const
Get zero extended value.
This class represents an incoming formal argument to a Function.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
const T & back() const
back - Get the last element.
#define DWARF2_FLAG_PROLOGUE_END
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
StringRef getBuffer() const
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
unsigned getNumImplicitDefs() const
Return the number of implicit defs this instruct has.
Optional< StringRef > Source
The source code of the file.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
bool isVariable() const
isVariable - Check if this is a variable symbol.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value)...
DiagHandlerTy getDiagHandler() const
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.
This represents an "assembler immediate".
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
void redefineIfPossible()
Prepare this symbol to be redefined.
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
MCTargetAsmParser - Generic interface to target specific assembly parsers.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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...
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
static VariantKind getVariantKindForName(StringRef Name)
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
MCAsmParserExtension * createWasmAsmParser()
bool isNot(TokenKind K) const
Opcode getOpcode() const
Get the kind of this unary expression.
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
MCAsmParserExtension * createDarwinAsmParser()
constexpr bool isInt< 8 >(int64_t x)
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
A raw_ostream that writes to an SmallVector or SmallString.
virtual void printRegName(raw_ostream &OS, unsigned RegNo) const
Print the assembler register name.
Expected< opStatus > convertFromString(StringRef, roundingMode)
uint16_t getDwarfVersion() const
Error takeError()
Take ownership of the stored error.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
bool useParensForSymbolVariant() const
unsigned getBitWidth() const
Return the number of bits in the APInt.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation.
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
MCAsmParserExtension * createELFAsmParser()
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance.
static bool isIdentifierChar(char c)
const MCSubtargetInfo & getSTI() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
AsmLexer - Lexer class for assembly files.
SMLoc getLoc() const
Get the current source location.
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
#define DWARF2_FLAG_IS_STMT
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void setBuffer(StringRef Buf, const char *ptr=nullptr)
Generic assembler lexer interface, for use by target specific assembly lexers.
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
Target independent representation for an assembler token.
Represent a reference to a symbol from inside an expression.
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Tagged union holding either a T or a Error.
void * allocate(unsigned Size, unsigned Align=8)
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
AsmCond - Class to support conditional assembly.
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
virtual StringRef getSymName()
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
This file implements a class to represent arbitrary precision integral constant values and operations...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
void assign(size_type NumElts, const T &Elt)
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Context object for machine code objects.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true) override
Look ahead an arbitrary number of tokens.
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *Value)
Returns whether the given symbol is used anywhere in the given expression, or subexpressions.
Optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
StringRef getLineContents() const
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
static unsigned getGNUBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
Directive
IDs for all OpenMP directives.
Unary assembler expressions.
static bool isOperator(AsmToken::TokenKind kind)
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD size_t size() const
size - Get the string size.
bool shouldUseLogicalShr() const
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
virtual void * getOpDecl()
static const fltSemantics & IEEEdouble() LLVM_READNONE
StringRef getConstraint()
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Analysis containing CSE Info
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
void setLexMasmIntegers(bool V)
Set whether to lex masm-style binary and hex literals.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
unsigned getMainFileID() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
const char * getPointer() const
virtual MCContext & getContext()=0
static const MCUnaryExpr * createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
initializer< Ty > init(const Ty &Val)
Streaming machine code generation interface.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
const MCPhysReg * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
static const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
constexpr bool isUInt< 8 >(uint64_t x)
.weak_def_can_be_hidden (MachO)
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
void setRedefinable(bool Value)
Mark this symbol as redefinable.
unsigned getAssemblerDialect() const
#define DWARF2_FLAG_EPILOGUE_BEGIN
Instrumentation for Order File
size_t size() const
size - Get the array size.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static cl::opt< unsigned > AsmMacroMaxNestingDepth("asm-macro-max-nesting-depth", cl::init(20), cl::Hidden, cl::desc("The maximum nesting depth allowed for assembly macros."))
Interface to description of machine instruction set.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
StringRef getPrivateLabelPrefix() const
MCAsmMacroParameters Parameters
const MCObjectFileInfo * getObjectFileInfo() const
const std::string & getErr()
Get the current error string.
Generic Sema callback for assembly parser.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
#define DWARF2_FLAG_BASIC_BLOCK
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
bool Error(SMLoc L, const Twine &Msg, SMRange Range=None)
Return an error at the location L, with the message Msg.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
Environment getObjectFileType() const
bool hasSubsectionsViaSymbols() const
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
void Finish()
Finish emission of machine code.
virtual unsigned getReg() const =0
virtual bool UseCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
iterator erase(const_iterator CI)
MCAsmParserExtension * createCOFFAsmParser()
Binary assembler expressions.
static bool isValidEncoding(int64_t Encoding)
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool getGenDwarfForAssembly()
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
AsmToken::TokenKind getKind() const
Get the kind of current token.
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
LLVM_NODISCARD int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
static const fltSemantics & IEEEsingle() LLVM_READNONE
virtual void InitSections(bool NoExecStack)
Create the default sections and set the initial one.
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
void UnLex(AsmToken const &Token)
const MCSymbol & getSymbol() const
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label? Only valid when par...
StringRef getMessage() const
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
MCSymbol * getBeginSymbol()
StringRef str()
Return a StringRef for the vector contents.
bool isUsed() const
isUsed - Check if this is used.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
bool getDollarIsPC() const
Signed greater than comparison (result is either 0 or some target-specific non-zero value) ...
const AsmToken & Lex()
Consume the next token from the input stream and return it.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool is(TokenKind K) const
This file contains constants used for implementing Dwarf debug support.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
bool doesAllowAtInName() const
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value)...
Class for arbitrary precision integers.
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...
Base class for user error types.
SourceMgr::DiagKind getKind() const
bool mayStore() const
Return true if this instruction could possibly modify memory.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
iterator insert(iterator I, T &&Elt)
#define DWARF2_LINE_DEFAULT_IS_STMT
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
static SMLoc getFromPointer(const char *Ptr)
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...
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
SMLoc getParentIncludeLoc(unsigned i) const
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
static void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
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...
virtual bool isImm() const =0
isImm - Is this an immediate operand?
virtual StringRef LookupInlineAsmLabel(StringRef Identifier, SourceMgr &SM, SMLoc Location, bool Create)=0
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
Generic base class for all target subtargets.
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
void * getDiagContext() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
References to labels and assigned expressions.
bool isLittleEndian() const
True if the target is little endian.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
static bool isAltmacroString(SMLoc &StrLoc, SMLoc &EndLoc)
This function checks if the next token is <string> type or arithmetic.
std::vector< AsmToken > Value
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable, rather than its value? Only valid when parsing MS-style inline assembly.
Opcode getOpcode() const
Get the kind of this binary expression.
StringRef getName() const
getName - Get the symbol name.
CodeViewContext & getCVContext()
LLVM_NODISCARD std::string lower() const
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getTextAlignFillValue() const
bool TokError(const Twine &Msg, SMRange Range=None)
Report an error at the current lexer location.
LLVM_NODISCARD char front() const
front - Get the first character in the string.
std::array< uint8_t, 16 > Bytes
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
A raw_ostream that writes to an std::string.
const MCExpr * getSubExpr() const
Get the child of this unary expression.
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
const char AsmRewritePrecedence[]
LLVM Value Representation.
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
const MCOperandInfo * OpInfo
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
SMLoc getErrLoc()
Get the current error location.
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned getMCOperandNum()
StringRef - Represent a constant reference to a string, i.e.
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
APInt bitcastToAPInt() const
Target specific expression.
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
Represents a location in source code.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
ConditionalAssemblyType TheCond
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
const SourceMgr * getSourceMgr() const
bool isBranchTarget() const
Set if this operand is a branch target.
virtual bool isReg() const =0
isReg - Is this a register operand?
Wrapper class representing virtual and physical registers.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
static std::string altMacroString(StringRef AltMacroStr)
creating a string without the escape characters '!'.
void setBeginSymbol(MCSymbol *Sym)
Holds state from .cv_file and .cv_loc directives for later emission.