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 MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
size_t CondStackDepth);
106 struct ParseStatementInfo {
111 unsigned Opcode = ~0U;
114 bool ParseError =
false;
118 ParseStatementInfo() =
delete;
120 : AsmRewrites(rewrites) {}
132 void *SavedDiagContext;
133 std::unique_ptr<MCAsmParserExtension> PlatformParser;
140 std::vector<AsmCond> TheCondStack;
148 std::vector<MacroInstantiation*> ActiveMacros;
151 std::deque<MCAsmMacro> MacroLikeBodies;
154 unsigned MacrosEnabledFlag : 1;
157 unsigned NumOfMacroInstantiations;
160 struct CppHashInfoTy {
162 int64_t LineNumber = 0;
166 CppHashInfoTy CppHashInfo;
172 unsigned AssemblerDialect = ~0U;
175 bool IsDarwin =
false;
178 bool ParsingInlineAsm =
false;
181 bool ReportedInconsistentMD5 =
false;
184 bool AltMacroMode =
false;
189 AsmParser(
const AsmParser &) =
delete;
190 AsmParser &operator=(
const AsmParser &) =
delete;
191 ~AsmParser()
override;
193 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
195 void addDirectiveHandler(
StringRef Directive,
196 ExtensionDirectiveHandler Handler)
override {
197 ExtensionDirectiveMap[Directive] = Handler;
201 DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
208 MCAsmLexer &getLexer()
override {
return Lexer; }
209 MCContext &getContext()
override {
return Ctx; }
210 MCStreamer &getStreamer()
override {
return Out; }
214 unsigned getAssemblerDialect()
override {
215 if (AssemblerDialect == ~0U)
218 return AssemblerDialect;
220 void setAssemblerDialect(
unsigned i)
override {
221 AssemblerDialect = i;
230 void setParsingInlineAsm(
bool V)
override {
231 ParsingInlineAsm = V;
236 bool isParsingInlineAsm()
override {
return ParsingInlineAsm; }
238 bool parseMSInlineAsm(
void *AsmLoc, std::string &AsmString,
239 unsigned &NumOutputs,
unsigned &NumInputs,
246 bool parseExpression(
const MCExpr *&Res);
247 bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
248 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
249 bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
250 bool parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
251 SMLoc &EndLoc)
override;
252 bool parseAbsoluteExpression(int64_t &Res)
override;
260 bool parseIdentifier(
StringRef &Res)
override;
261 void eatToEndOfStatement()
override;
263 bool checkForValidSection()
override;
268 bool parseStatement(ParseStatementInfo &
Info,
271 bool parseCppHashLineFilenameComment(
SMLoc L);
281 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
284 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
287 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
296 void handleMacroExit();
299 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
302 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &A);
304 void printMacroInstantiations();
315 bool enabledGenDwarfForAssembly();
318 bool enterIncludeFile(
const std::string &Filename);
322 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
331 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
336 StringRef parseStringToEndOfStatement()
override;
343 bool NoDeadStrip =
false);
348 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
349 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
350 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
352 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
354 bool parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName);
355 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
414 DK_BUNDLE_ALIGN_MODE,
428 DK_WEAK_DEF_CAN_BE_HIDDEN,
467 DK_CV_INLINE_SITE_ID,
470 DK_CV_INLINE_LINETABLE,
475 DK_CV_FILECHECKSUM_OFFSET,
481 DK_CFI_DEF_CFA_OFFSET,
482 DK_CFI_ADJUST_CFA_OFFSET,
483 DK_CFI_DEF_CFA_REGISTER,
488 DK_CFI_REMEMBER_STATE,
489 DK_CFI_RESTORE_STATE,
493 DK_CFI_RETURN_COLUMN,
524 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
525 bool parseDirectiveReloc(
SMLoc DirectiveLoc);
526 bool parseDirectiveValue(
StringRef IDVal,
528 bool parseDirectiveOctaValue(
StringRef IDVal);
529 bool parseDirectiveRealValue(
StringRef IDVal,
531 bool parseDirectiveFill();
532 bool parseDirectiveZero();
534 bool parseDirectiveSet(
StringRef IDVal,
bool allow_redef);
535 bool parseDirectiveOrg();
537 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
540 bool parseDirectiveFile(
SMLoc DirectiveLoc);
541 bool parseDirectiveLine();
542 bool parseDirectiveLoc();
543 bool parseDirectiveStabs();
547 bool parseDirectiveCVFile();
548 bool parseDirectiveCVFuncId();
549 bool parseDirectiveCVInlineSiteId();
550 bool parseDirectiveCVLoc();
551 bool parseDirectiveCVLinetable();
552 bool parseDirectiveCVInlineLinetable();
553 bool parseDirectiveCVDefRange();
554 bool parseDirectiveCVString();
555 bool parseDirectiveCVStringTable();
556 bool parseDirectiveCVFileChecksums();
557 bool parseDirectiveCVFileChecksumOffset();
558 bool parseDirectiveCVFPOData();
561 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
562 bool parseDirectiveCFIWindowSave();
563 bool parseDirectiveCFISections();
564 bool parseDirectiveCFIStartProc();
565 bool parseDirectiveCFIEndProc();
566 bool parseDirectiveCFIDefCfaOffset();
567 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
568 bool parseDirectiveCFIAdjustCfaOffset();
569 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
570 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
571 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
572 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
573 bool parseDirectiveCFIRememberState();
574 bool parseDirectiveCFIRestoreState();
575 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
576 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
577 bool parseDirectiveCFIEscape();
578 bool parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc);
579 bool parseDirectiveCFISignalFrame();
580 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
583 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
584 bool parseDirectiveExitMacro(
StringRef Directive);
585 bool parseDirectiveEndMacro(
StringRef Directive);
586 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
587 bool parseDirectiveMacrosOnOff(
StringRef Directive);
589 bool parseDirectiveAltmacro(
StringRef Directive);
591 bool parseDirectiveBundleAlignMode();
593 bool parseDirectiveBundleLock();
595 bool parseDirectiveBundleUnlock();
598 bool parseDirectiveSpace(
StringRef IDVal);
607 bool parseDirectiveLEB128(
bool Signed);
613 bool parseDirectiveComm(
bool IsLocal);
615 bool parseDirectiveAbort();
616 bool parseDirectiveInclude();
617 bool parseDirectiveIncbin();
620 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
622 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
624 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
626 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
628 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
629 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
630 bool parseDirectiveElse(
SMLoc DirectiveLoc);
631 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
632 bool parseEscapedString(std::string &
Data)
override;
642 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
643 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
644 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
647 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &
Info,
651 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &
Info);
654 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
657 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
660 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
663 bool parseDirectivePrint(
SMLoc DirectiveLoc);
666 bool parseDirectiveAddrsig();
667 bool parseDirectiveAddrsigSym();
669 void initializeDirectiveKindMap();
687 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
688 CurBuffer(CB ? CB : SM.
getMainFileID()), MacrosEnabledFlag(
true) {
714 PlatformParser->Initialize(*
this);
715 initializeDirectiveKindMap();
717 NumOfMacroInstantiations = 0;
720 AsmParser::~AsmParser() {
721 assert((HadError || ActiveMacros.empty()) &&
722 "Unexpected active macro instantiation!");
729 void AsmParser::printMacroInstantiations() {
731 for (std::vector<MacroInstantiation *>::const_reverse_iterator
732 it = ActiveMacros.rbegin(),
733 ie = ActiveMacros.rend();
736 "while in macro instantiation");
740 printPendingErrors();
742 printMacroInstantiations();
746 if(getTargetParser().getTargetOptions().MCNoWarn)
748 if (getTargetParser().getTargetOptions().MCFatalWarnings)
749 return Error(L, Msg, Range);
751 printMacroInstantiations();
758 printMacroInstantiations();
762 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
763 std::string IncludedFile;
777 bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
779 std::string IncludedFile;
790 if (!Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
791 return Error(Loc,
"expected absolute expression");
793 return Warning(Loc,
"negative count has no effect");
796 getStreamer().EmitBytes(Bytes);
800 void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
813 if (!getTok().getString().empty() && getTok().getString().front() !=
'\n' &&
831 if (ParentIncludeLoc !=
SMLoc()) {
832 jumpToLoc(ParentIncludeLoc);
840 bool AsmParser::enabledGenDwarfForAssembly() {
842 if (!getContext().getGenDwarfForAssembly())
847 if (getContext().getGenDwarfFileNumber() == 0)
848 getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
849 0,
StringRef(), getContext().getMainFileName()));
853 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
855 if (!NoInitialTextSection)
862 AsmCond StartingCondState = TheCondState;
869 if (getContext().getGenDwarfForAssembly()) {
870 MCSection *Sec = getStreamer().getCurrentSectionOnly();
872 MCSymbol *SectionStartSym = getContext().createTempSymbol();
873 getStreamer().EmitLabel(SectionStartSym);
876 bool InsertResult = getContext().addGenDwarfSection(Sec);
877 assert(InsertResult &&
".text section should not have debug info yet");
883 ParseStatementInfo
Info(&AsmStrRewrites);
884 if (!parseStatement(Info,
nullptr))
895 printPendingErrors();
898 if (!getLexer().isAtStartOfStatement())
899 eatToEndOfStatement();
902 getTargetParser().onEndOfFile();
903 printPendingErrors();
906 assert(!hasPendingError() &&
"unexpected error from parseStatement");
908 getTargetParser().flushPendingInstructions(getStreamer());
912 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
914 const auto &LineTables = getContext().getMCDwarfLineTables();
915 if (!LineTables.empty()) {
917 for (
const auto &
File : LineTables.begin()->second.getMCDwarfFiles()) {
918 if (
File.Name.empty() && Index != 0)
919 printError(getTok().getLoc(),
"unassigned file number: " +
921 " for .file directives");
932 for (
const auto &TableEntry : getContext().getSymbols()) {
933 MCSymbol *Sym = TableEntry.getValue();
941 printError(getTok().getLoc(),
"assembler local symbol '" +
942 Sym->
getName() +
"' not defined");
948 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
949 if (std::get<2>(LocSym)->isUndefined()) {
952 CppHashInfo = std::get<1>(LocSym);
953 printError(std::get<0>(LocSym),
"directional label undefined");
960 if (!HadError && !NoFinalize)
963 return HadError || getContext().hadError();
966 bool AsmParser::checkForValidSection() {
967 if (!ParsingInlineAsm && !getStreamer().getCurrentSectionOnly()) {
969 return Error(getTok().getLoc(),
970 "expected section directive before assembly directive");
976 void AsmParser::eatToEndOfStatement() {
985 StringRef AsmParser::parseStringToEndOfStatement() {
986 const char *Start = getTok().getLoc().getPointer();
991 const char *End = getTok().getLoc().getPointer();
995 StringRef AsmParser::parseStringToComma() {
996 const char *Start = getTok().getLoc().getPointer();
1002 const char *End = getTok().getLoc().getPointer();
1011 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1012 if (parseExpression(Res))
1015 return TokError(
"expected ')' in parentheses expression");
1026 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1027 if (parseExpression(Res))
1029 EndLoc = getTok().getEndLoc();
1030 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1041 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1042 SMLoc FirstTokenLoc = getLexer().getLoc();
1044 switch (FirstTokenKind) {
1046 return TokError(
"unknown token in expression");
1052 if (parsePrimaryExpr(Res, EndLoc))
1061 if (parseIdentifier(Identifier)) {
1072 EndLoc = FirstTokenLoc;
1075 return Error(FirstTokenLoc,
"invalid token in expression");
1079 std::pair<StringRef, StringRef>
Split;
1084 SMLoc AtLoc = getLexer().getLoc();
1086 if (parseIdentifier(VName))
1087 return Error(AtLoc,
"expected symbol variant after '@'");
1089 Split = std::make_pair(Identifier, VName);
1092 Split = Identifier.
split(
'@');
1097 parseIdentifier(VName);
1100 "unexpected token in variant, expected ')'"))
1102 Split = std::make_pair(Identifier, VName);
1109 if (SymbolName.empty())
1110 return Error(getLexer().getLoc(),
"expected a symbol reference");
1115 if (!Split.second.empty()) {
1118 SymbolName = Split.first;
1123 "invalid variant '" + Split.second +
"'");
1127 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
1133 bool DoInline = isa<MCConstantExpr>(V) && !Variant;
1134 if (
auto TV = dyn_cast<MCTargetExpr>(V))
1135 DoInline = TV->inlineAssignedExpr();
1138 return Error(EndLoc,
"unexpected modifier on variable reference");
1149 return TokError(
"literal value out of range for directive");
1151 SMLoc Loc = getTok().getLoc();
1152 int64_t
IntVal = getTok().getIntVal();
1160 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1162 if (Split.first.size() != IDVal.
size()) {
1165 return TokError(
"invalid variant '" + Split.second +
"'");
1166 IDVal = Split.first;
1168 if (IDVal ==
"f" || IDVal ==
"b") {
1173 return Error(Loc,
"directional label undefined");
1174 DirLabels.
push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1201 return parseParenExpr(Res, EndLoc);
1203 if (!PlatformParser->HasBracketExpressions())
1204 return TokError(
"brackets expression not supported on this target");
1206 return parseBracketExpr(Res, EndLoc);
1209 if (parsePrimaryExpr(Res, EndLoc))
1215 if (parsePrimaryExpr(Res, EndLoc))
1221 if (parsePrimaryExpr(Res, EndLoc))
1253 return TokError(
"expected '(' after operator");
1255 if (parseExpression(Res, EndLoc))
1258 return TokError(
"expected ')'");
1260 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1265 bool AsmParser::parseExpression(
const MCExpr *&Res) {
1267 return parseExpression(Res, EndLoc);
1271 AsmParser::applyModifierToExpr(
const MCExpr *
E,
1274 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
1288 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
1289 "' (already modified)");
1306 const MCExpr *LHS = applyModifierToExpr(BE->
getLHS(), Variant);
1307 const MCExpr *RHS = applyModifierToExpr(BE->
getRHS(), Variant);
1337 "Argument to the function cannot be a NULL value");
1339 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1340 (*CharPtr !=
'\0')) {
1341 if (*CharPtr ==
'!')
1345 if (*CharPtr ==
'>') {
1355 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1356 if (AltMacroStr[Pos] ==
'!')
1358 Res += AltMacroStr[Pos];
1373 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1376 if (getTargetParser().parsePrimaryExpr(Res, EndLoc) ||
1377 parseBinOpRHS(1, Res, EndLoc))
1387 return TokError(
"unexpected symbol modifier following '@'");
1392 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1394 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1396 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1397 "' (no symbols present)");
1407 if (Res->evaluateAsAbsolute(Value))
1413 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1415 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1418 bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1420 if (parseParenExpr(Res, EndLoc))
1423 for (; ParenDepth > 0; --ParenDepth) {
1424 if (parseBinOpRHS(1, Res, EndLoc))
1429 if (ParenDepth - 1 > 0) {
1430 EndLoc = getTok().getEndLoc();
1432 "expected ')' in parentheses expression"))
1439 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1443 if (parseExpression(Expr))
1446 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1447 return Error(StartLoc,
"expected absolute expression");
1454 bool ShouldUseLogicalShr) {
1532 bool ShouldUseLogicalShr) {
1615 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1620 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(),
Kind);
1624 if (TokPrec < Precedence)
1631 if (getTargetParser().parsePrimaryExpr(RHS, EndLoc))
1637 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(),
Dummy);
1638 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1650 bool AsmParser::parseStatement(ParseStatementInfo &
Info,
1652 assert(!hasPendingError() &&
"parseStatement started with pending error");
1658 if (getTok().getString().empty() || getTok().getString().front() ==
'\r' ||
1659 getTok().getString().front() ==
'\n')
1668 int64_t LocalLabelVal = -1;
1670 return parseCppHashLineFilenameComment(IDLoc);
1673 LocalLabelVal = getTok().getIntVal();
1674 if (LocalLabelVal < 0) {
1675 if (!TheCondState.
Ignore) {
1677 return Error(IDLoc,
"unexpected token at start of statement");
1681 IDVal = getTok().getString();
1684 if (!TheCondState.
Ignore) {
1686 return Error(IDLoc,
"unexpected token at start of statement");
1704 getTargetParser().starIsStartOfStatement()) {
1708 }
else if (parseIdentifier(IDVal)) {
1709 if (!TheCondState.
Ignore) {
1711 return Error(IDLoc,
"unexpected token at start of statement");
1720 DirectiveKindMap.find(IDVal);
1721 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1723 : DirKindIt->getValue();
1734 return parseDirectiveIf(IDLoc, DirKind);
1736 return parseDirectiveIfb(IDLoc,
true);
1738 return parseDirectiveIfb(IDLoc,
false);
1740 return parseDirectiveIfc(IDLoc,
true);
1742 return parseDirectiveIfeqs(IDLoc,
true);
1744 return parseDirectiveIfc(IDLoc,
false);
1746 return parseDirectiveIfeqs(IDLoc,
false);
1748 return parseDirectiveIfdef(IDLoc,
true);
1751 return parseDirectiveIfdef(IDLoc,
false);
1753 return parseDirectiveElseIf(IDLoc);
1755 return parseDirectiveElse(IDLoc);
1757 return parseDirectiveEndIf(IDLoc);
1762 if (TheCondState.
Ignore) {
1763 eatToEndOfStatement();
1772 if (!getTargetParser().isLabel(ID))
1774 if (checkForValidSection())
1782 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1790 if (LocalLabelVal == -1) {
1791 if (ParsingInlineAsm && SI) {
1795 "We should have an internal name here.");
1796 Info.AsmRewrites->emplace_back(
AOK_Label, IDLoc, IDVal.
size(),
1798 IDVal = RewrittenLabel;
1800 Sym = getContext().getOrCreateSymbol(IDVal);
1808 StringRef CommentStr = parseStringToEndOfStatement();
1819 getTargetParser().doBeforeLabelEmit(Sym);
1822 if (!getTargetParser().isParsingInlineAsm())
1827 if (enabledGenDwarfForAssembly())
1831 getTargetParser().onLabelParsed(Sym);
1837 if (!getTargetParser().equalIsAsmAssignment())
1842 return parseAssignment(IDVal,
true);
1849 if (areMacrosEnabled())
1850 if (
const MCAsmMacro *M = getContext().lookupMacro(IDVal)) {
1851 return handleMacroEntry(M, IDLoc);
1869 getTargetParser().flushPendingInstructions(getStreamer());
1871 SMLoc StartTokLoc = getTok().getLoc();
1872 bool TPDirectiveReturn = getTargetParser().ParseDirective(ID);
1874 if (hasPendingError())
1881 if (TPDirectiveReturn && StartTokLoc != getTok().getLoc())
1884 if (!TPDirectiveReturn || StartTokLoc != getTok().getLoc())
1889 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1890 ExtensionDirectiveMap.
lookup(IDVal);
1892 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1901 return parseDirectiveSet(IDVal,
true);
1903 return parseDirectiveSet(IDVal,
false);
1905 return parseDirectiveAscii(IDVal,
false);
1908 return parseDirectiveAscii(IDVal,
true);
1911 return parseDirectiveValue(IDVal, 1);
1917 return parseDirectiveValue(IDVal, 2);
1922 return parseDirectiveValue(IDVal, 4);
1925 return parseDirectiveValue(IDVal, 8);
1927 return parseDirectiveValue(
1928 IDVal, getContext().getAsmInfo()->getCodePointerSize());
1930 return parseDirectiveOctaValue(IDVal);
1939 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1940 return parseDirectiveAlign(IsPow2, 1);
1943 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1944 return parseDirectiveAlign(IsPow2, 4);
1947 return parseDirectiveAlign(
false, 1);
1949 return parseDirectiveAlign(
false, 2);
1951 return parseDirectiveAlign(
false, 4);
1953 return parseDirectiveAlign(
true, 1);
1955 return parseDirectiveAlign(
true, 2);
1957 return parseDirectiveAlign(
true, 4);
1959 return parseDirectiveOrg();
1961 return parseDirectiveFill();
1963 return parseDirectiveZero();
1965 eatToEndOfStatement();
1969 return parseDirectiveSymbolAttribute(
MCSA_Global);
1970 case DK_LAZY_REFERENCE:
1972 case DK_NO_DEAD_STRIP:
1974 case DK_SYMBOL_RESOLVER:
1976 case DK_PRIVATE_EXTERN:
1980 case DK_WEAK_DEFINITION:
1982 case DK_WEAK_REFERENCE:
1984 case DK_WEAK_DEF_CAN_BE_HIDDEN:
1988 return parseDirectiveComm(
false);
1990 return parseDirectiveComm(
true);
1992 return parseDirectiveAbort();
1994 return parseDirectiveInclude();
1996 return parseDirectiveIncbin();
1999 return TokError(
Twine(IDVal) +
2000 " not currently supported for this target");
2002 return parseDirectiveRept(IDLoc, IDVal);
2004 return parseDirectiveIrp(IDLoc);
2006 return parseDirectiveIrpc(IDLoc);
2008 return parseDirectiveEndr(IDLoc);
2009 case DK_BUNDLE_ALIGN_MODE:
2010 return parseDirectiveBundleAlignMode();
2011 case DK_BUNDLE_LOCK:
2012 return parseDirectiveBundleLock();
2013 case DK_BUNDLE_UNLOCK:
2014 return parseDirectiveBundleUnlock();
2016 return parseDirectiveLEB128(
true);
2018 return parseDirectiveLEB128(
false);
2021 return parseDirectiveSpace(IDVal);
2023 return parseDirectiveFile(IDLoc);
2025 return parseDirectiveLine();
2027 return parseDirectiveLoc();
2029 return parseDirectiveStabs();
2031 return parseDirectiveCVFile();
2033 return parseDirectiveCVFuncId();
2034 case DK_CV_INLINE_SITE_ID:
2035 return parseDirectiveCVInlineSiteId();
2037 return parseDirectiveCVLoc();
2038 case DK_CV_LINETABLE:
2039 return parseDirectiveCVLinetable();
2040 case DK_CV_INLINE_LINETABLE:
2041 return parseDirectiveCVInlineLinetable();
2042 case DK_CV_DEF_RANGE:
2043 return parseDirectiveCVDefRange();
2045 return parseDirectiveCVString();
2046 case DK_CV_STRINGTABLE:
2047 return parseDirectiveCVStringTable();
2048 case DK_CV_FILECHECKSUMS:
2049 return parseDirectiveCVFileChecksums();
2050 case DK_CV_FILECHECKSUM_OFFSET:
2051 return parseDirectiveCVFileChecksumOffset();
2052 case DK_CV_FPO_DATA:
2053 return parseDirectiveCVFPOData();
2054 case DK_CFI_SECTIONS:
2055 return parseDirectiveCFISections();
2056 case DK_CFI_STARTPROC:
2057 return parseDirectiveCFIStartProc();
2058 case DK_CFI_ENDPROC:
2059 return parseDirectiveCFIEndProc();
2060 case DK_CFI_DEF_CFA:
2061 return parseDirectiveCFIDefCfa(IDLoc);
2062 case DK_CFI_DEF_CFA_OFFSET:
2063 return parseDirectiveCFIDefCfaOffset();
2064 case DK_CFI_ADJUST_CFA_OFFSET:
2065 return parseDirectiveCFIAdjustCfaOffset();
2066 case DK_CFI_DEF_CFA_REGISTER:
2067 return parseDirectiveCFIDefCfaRegister(IDLoc);
2069 return parseDirectiveCFIOffset(IDLoc);
2070 case DK_CFI_REL_OFFSET:
2071 return parseDirectiveCFIRelOffset(IDLoc);
2072 case DK_CFI_PERSONALITY:
2073 return parseDirectiveCFIPersonalityOrLsda(
true);
2075 return parseDirectiveCFIPersonalityOrLsda(
false);
2076 case DK_CFI_REMEMBER_STATE:
2077 return parseDirectiveCFIRememberState();
2078 case DK_CFI_RESTORE_STATE:
2079 return parseDirectiveCFIRestoreState();
2080 case DK_CFI_SAME_VALUE:
2081 return parseDirectiveCFISameValue(IDLoc);
2082 case DK_CFI_RESTORE:
2083 return parseDirectiveCFIRestore(IDLoc);
2085 return parseDirectiveCFIEscape();
2086 case DK_CFI_RETURN_COLUMN:
2087 return parseDirectiveCFIReturnColumn(IDLoc);
2088 case DK_CFI_SIGNAL_FRAME:
2089 return parseDirectiveCFISignalFrame();
2090 case DK_CFI_UNDEFINED:
2091 return parseDirectiveCFIUndefined(IDLoc);
2092 case DK_CFI_REGISTER:
2093 return parseDirectiveCFIRegister(IDLoc);
2094 case DK_CFI_WINDOW_SAVE:
2095 return parseDirectiveCFIWindowSave();
2098 return parseDirectiveMacrosOnOff(IDVal);
2100 return parseDirectiveMacro(IDLoc);
2103 return parseDirectiveAltmacro(IDVal);
2105 return parseDirectiveExitMacro(IDVal);
2108 return parseDirectiveEndMacro(IDVal);
2110 return parseDirectivePurgeMacro(IDLoc);
2112 return parseDirectiveEnd(IDLoc);
2114 return parseDirectiveError(IDLoc,
false);
2116 return parseDirectiveError(IDLoc,
true);
2118 return parseDirectiveWarning(IDLoc);
2120 return parseDirectiveReloc(IDLoc);
2123 return parseDirectiveDCB(IDVal, 2);
2125 return parseDirectiveDCB(IDVal, 1);
2129 return parseDirectiveDCB(IDVal, 4);
2134 return TokError(
Twine(IDVal) +
2135 " not currently supported for this target");
2138 return parseDirectiveDS(IDVal, 2);
2140 return parseDirectiveDS(IDVal, 1);
2142 return parseDirectiveDS(IDVal, 8);
2145 return parseDirectiveDS(IDVal, 4);
2148 return parseDirectiveDS(IDVal, 12);
2150 return parseDirectivePrint(IDLoc);
2152 return parseDirectiveAddrsig();
2153 case DK_ADDRSIG_SYM:
2154 return parseDirectiveAddrsigSym();
2157 return Error(IDLoc,
"unknown directive");
2161 if (ParsingInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2162 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2163 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2166 if (ParsingInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2167 return parseDirectiveMSAlign(IDLoc, Info);
2169 if (ParsingInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2170 Info.AsmRewrites->emplace_back(
AOK_EVEN, IDLoc, 4);
2171 if (checkForValidSection())
2175 std::string OpcodeStr = IDVal.
lower();
2177 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, ID,
2178 Info.ParsedOperands);
2179 Info.ParseError = ParseHadError;
2182 if (getShowParsedOperands()) {
2185 OS <<
"parsed instruction: [";
2186 for (
unsigned i = 0; i != Info.ParsedOperands.size(); ++i) {
2189 Info.ParsedOperands[i]->print(OS);
2197 if (hasPendingError() || ParseHadError)
2202 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2203 getContext().getGenDwarfSectionSyms().count(
2204 getStreamer().getCurrentSectionOnly())) {
2206 if (ActiveMacros.empty())
2209 Line = SrcMgr.
FindLineNumber(ActiveMacros.front()->InstantiationLoc,
2210 ActiveMacros.front()->ExitBuffer);
2215 if (!CppHashInfo.Filename.empty()) {
2216 unsigned FileNumber = getStreamer().EmitDwarfFileDirective(
2218 getContext().setGenDwarfFileNumber(FileNumber);
2220 unsigned CppHashLocLineNo =
2222 Line = CppHashInfo.LineNumber - 1 + (Line - CppHashLocLineNo);
2225 getStreamer().EmitDwarfLocDirective(
2226 getContext().getGenDwarfFileNumber(), Line, 0,
2232 if (!ParseHadError) {
2234 if (getTargetParser().MatchAndEmitInstruction(
2235 IDLoc, Info.Opcode, Info.ParsedOperands, Out, ErrorInfo,
2236 getTargetParser().isParsingInlineAsm()))
2262 bool AsmParser::parseCppHashLineFilenameComment(
SMLoc L) {
2267 "Lexing Cpp line comment: Expected Integer");
2268 int64_t LineNumber = getTok().getIntVal();
2271 "Lexing Cpp line comment: Expected String");
2272 StringRef Filename = getTok().getString();
2276 Filename = Filename.
substr(1, Filename.
size() - 2);
2279 CppHashInfo.Loc = L;
2280 CppHashInfo.Filename = Filename;
2281 CppHashInfo.LineNumber = LineNumber;
2282 CppHashInfo.Buf = CurBuffer;
2289 const AsmParser *Parser =
static_cast<const AsmParser *
>(
Context);
2295 unsigned CppHashBuf =
2296 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2301 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2310 if (!Parser->CppHashInfo.LineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
2311 DiagBuf != CppHashBuf) {
2312 if (Parser->SavedDiagHandler)
2313 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2315 Diag.
print(
nullptr, OS);
2322 const std::string &Filename = Parser->CppHashInfo.Filename;
2325 int CppHashLocLineNo =
2326 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2328 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2334 if (Parser->SavedDiagHandler)
2335 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
2337 NewDiag.print(
nullptr, OS);
2345 return isalnum(static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2352 bool EnableAtPseudoVariable,
SMLoc L) {
2353 unsigned NParameters = Parameters.
size();
2354 bool HasVararg = NParameters ? Parameters.
back().
Vararg :
false;
2355 if ((!IsDarwin || NParameters != 0) && NParameters != A.
size())
2356 return Error(L,
"Wrong number of arguments");
2360 while (!Body.
empty()) {
2362 std::size_t End = Body.
size(), Pos = 0;
2363 for (; Pos != End; ++Pos) {
2365 if (IsDarwin && !NParameters) {
2367 if (Body[Pos] !=
'$' || Pos + 1 == End)
2370 char Next = Body[Pos + 1];
2371 if (Next ==
'$' || Next ==
'n' ||
2372 isdigit(static_cast<unsigned char>(Next)))
2376 if (Body[Pos] ==
'\\' && Pos + 1 != End)
2382 OS << Body.
slice(0, Pos);
2388 if (IsDarwin && !NParameters) {
2389 switch (Body[Pos + 1]) {
2403 unsigned Index = Body[Pos + 1] -
'0';
2404 if (Index >= A.
size())
2408 for (
const AsmToken &Token : A[Index])
2409 OS << Token.getString();
2415 unsigned I = Pos + 1;
2418 if (EnableAtPseudoVariable && Body[I] ==
'@' && I + 1 != End)
2424 const char *Begin = Body.
data() + Pos + 1;
2428 if (Argument ==
"@") {
2429 OS << NumOfMacroInstantiations;
2432 for (; Index < NParameters; ++
Index)
2433 if (Parameters[Index].
Name == Argument)
2436 if (Index == NParameters) {
2437 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
2440 OS <<
'\\' << Argument;
2444 bool VarargParameter = HasVararg && Index == (NParameters - 1);
2445 for (
const AsmToken &Token : A[Index])
2453 if (AltMacroMode && Token.getString().front() ==
'%' &&
2456 OS << Token.getIntVal();
2459 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2466 OS << Token.getString();
2468 OS << Token.getStringContents();
2470 Pos += 1 + Argument.
size();
2481 MacroInstantiation::MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
2482 size_t CondStackDepth)
2483 : InstantiationLoc(IL), ExitBuffer(EB), ExitLoc(EL),
2484 CondStackDepth(CondStackDepth) {}
2518 class AsmLexerSkipSpaceRAII {
2520 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2524 ~AsmLexerSkipSpaceRAII() {
2534 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2538 StringRef Str = parseStringToEndOfStatement();
2544 unsigned ParenLevel = 0;
2547 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2554 return TokError(
"unexpected token in macro instantiation");
2556 if (ParenLevel == 0) {
2571 MA.push_back(getTok());
2597 MA.push_back(getTok());
2601 if (ParenLevel != 0)
2602 return TokError(
"unbalanced parentheses in macro argument");
2607 bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2608 MCAsmMacroArguments &A) {
2609 const unsigned NParameters = M ? M->
Parameters.size() : 0;
2610 bool NamedParametersFound =
false;
2614 FALocs.
resize(NParameters);
2619 bool HasVararg = NParameters ? M->
Parameters.back().Vararg :
false;
2620 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2626 if (parseIdentifier(FA.
Name))
2627 return Error(IDLoc,
"invalid argument identifier for formal argument");
2630 return TokError(
"expected '=' after formal parameter identifier");
2634 NamedParametersFound =
true;
2636 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2638 if (NamedParametersFound && FA.
Name.
empty())
2639 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2644 const MCExpr *AbsoluteExp;
2648 if (parseExpression(AbsoluteExp, EndLoc))
2650 if (!AbsoluteExp->evaluateAsAbsolute(Value,
2651 getStreamer().getAssemblerPtr()))
2652 return Error(StrLoc,
"expected absolute expression");
2656 StringRef(StrChar, EndChar - StrChar), Value);
2657 FA.
Value.push_back(newToken);
2662 jumpToLoc(EndLoc, CurBuffer);
2667 FA.
Value.push_back(newToken);
2668 }
else if(parseMacroArgument(FA.
Value, Vararg))
2671 unsigned PI = Parameter;
2674 for (FAI = 0; FAI < NParameters; ++FAI)
2678 if (FAI >= NParameters) {
2679 assert(M &&
"expected macro to be defined");
2680 return Error(IDLoc,
"parameter named '" + FA.
Name +
2681 "' does not exist for macro '" + M->
Name +
"'");
2686 if (!FA.
Value.empty()) {
2691 if (FALocs.
size() <= PI)
2694 FALocs[PI] = Lexer.
getLoc();
2701 bool Failure =
false;
2702 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2703 if (A[FAI].
empty()) {
2705 Error(FALocs[FAI].isValid() ? FALocs[FAI] : Lexer.
getLoc(),
2706 "missing value for required parameter " 2722 return TokError(
"too many positional arguments");
2725 bool AsmParser::handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc) {
2729 if (ActiveMacros.size() == MaxNestingDepth) {
2730 std::ostringstream MaxNestingDepthError;
2731 MaxNestingDepthError <<
"macros cannot be nested more than " 2732 << MaxNestingDepth <<
" levels deep." 2733 <<
" Use -asm-macro-max-nesting-depth to increase " 2735 return TokError(MaxNestingDepthError.str());
2738 MCAsmMacroArguments A;
2739 if (parseMacroArguments(M, A))
2748 if (expandMacro(OS, Body, M->
Parameters, A,
true, getTok().getLoc()))
2753 OS <<
".endmacro\n";
2755 std::unique_ptr<MemoryBuffer> Instantiation =
2760 MacroInstantiation *
MI =
new MacroInstantiation(
2761 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
2762 ActiveMacros.push_back(MI);
2764 ++NumOfMacroInstantiations;
2774 void AsmParser::handleMacroExit() {
2776 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2780 delete ActiveMacros.back();
2781 ActiveMacros.pop_back();
2784 bool AsmParser::parseAssignment(
StringRef Name,
bool allow_redef,
2810 bool AsmParser::parseIdentifier(
StringRef &Res) {
2817 SMLoc PrefixLoc = getLexer().getLoc();
2843 Res = getTok().getIdentifier();
2854 bool AsmParser::parseDirectiveSet(
StringRef IDVal,
bool allow_redef) {
2856 if (check(parseIdentifier(Name),
"expected identifier") ||
2857 parseToken(
AsmToken::Comma) || parseAssignment(Name, allow_redef,
true))
2858 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2862 bool AsmParser::parseEscapedString(std::string &
Data) {
2867 StringRef Str = getTok().getStringContents();
2868 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
2869 if (Str[i] !=
'\\') {
2878 return TokError(
"unexpected backslash at end of string");
2881 if ((
unsigned)(Str[i] -
'0') <= 7) {
2883 unsigned Value = Str[i] -
'0';
2885 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2887 Value = Value * 8 + (Str[i] -
'0');
2889 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2891 Value = Value * 8 + (Str[i] -
'0');
2896 return TokError(
"invalid octal escape sequence (out of range)");
2898 Data += (
unsigned char)Value;
2906 return TokError(
"invalid escape sequence (unrecognized character)");
2908 case 'b': Data +=
'\b';
break;
2909 case 'f': Data +=
'\f';
break;
2910 case 'n': Data +=
'\n';
break;
2911 case 'r': Data +=
'\r';
break;
2912 case 't': Data +=
'\t';
break;
2913 case '"': Data +=
'"';
break;
2914 case '\\': Data +=
'\\';
break;
2924 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
2925 auto parseOp = [&]() ->
bool {
2927 if (checkForValidSection() || parseEscapedString(Data))
2929 getStreamer().EmitBytes(Data);
2931 getStreamer().EmitBytes(
StringRef(
"\0", 1));
2935 if (parseMany(parseOp))
2936 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2942 bool AsmParser::parseDirectiveReloc(
SMLoc DirectiveLoc) {
2944 const MCExpr *Expr =
nullptr;
2945 int64_t OffsetValue;
2948 if (parseExpression(Offset))
2951 if ((Offset->evaluateAsAbsolute(OffsetValue,
2952 getStreamer().getAssemblerPtr()) &&
2953 check(OffsetValue < 0, OffsetLoc,
"expression is negative")) ||
2956 OffsetLoc,
"expected non-negative number or a label")) ||
2968 if (parseExpression(Expr))
2973 return Error(ExprLoc,
"expression must be relocatable");
2977 "unexpected token in .reloc directive"))
2982 if (getStreamer().EmitRelocDirective(*Offset, Name, Expr, DirectiveLoc, STI))
2983 return Error(NameLoc,
"unknown relocation name");
2990 bool AsmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
2991 auto parseOp = [&]() ->
bool {
2993 SMLoc ExprLoc = getLexer().getLoc();
2994 if (checkForValidSection() || parseExpression(Value))
2997 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2998 assert(Size <= 8 &&
"Invalid size");
2999 uint64_t IntValue = MCE->getValue();
3000 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
3001 return Error(ExprLoc,
"out of range literal value");
3002 getStreamer().EmitIntValue(IntValue, Size);
3004 getStreamer().EmitValue(Value, Size, ExprLoc);
3008 if (parseMany(parseOp))
3009 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3016 return Asm.TokError(
"unknown token in expression");
3017 SMLoc ExprLoc = Asm.getTok().getLoc();
3018 APInt IntValue = Asm.getTok().getAPIntVal();
3020 if (!IntValue.
isIntN(128))
3021 return Asm.Error(ExprLoc,
"out of range literal value");
3022 if (!IntValue.
isIntN(64)) {
3035 bool AsmParser::parseDirectiveOctaValue(
StringRef IDVal) {
3036 auto parseOp = [&]() ->
bool {
3037 if (checkForValidSection())
3043 getStreamer().EmitIntValue(lo, 8);
3044 getStreamer().EmitIntValue(hi, 8);
3046 getStreamer().EmitIntValue(hi, 8);
3047 getStreamer().EmitIntValue(lo, 8);
3052 if (parseMany(parseOp))
3053 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3068 return TokError(Lexer.
getErr());
3071 return TokError(
"unexpected token in directive");
3082 return TokError(
"invalid floating point literal");
3085 return TokError(
"invalid floating point literal");
3099 bool AsmParser::parseDirectiveRealValue(
StringRef IDVal,
3101 auto parseOp = [&]() ->
bool {
3103 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3110 if (parseMany(parseOp))
3111 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3117 bool AsmParser::parseDirectiveZero() {
3120 if (checkForValidSection() || parseExpression(NumBytes))
3126 if (parseAbsoluteExpression(Val))
3131 "unexpected token in '.zero' directive"))
3133 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3140 bool AsmParser::parseDirectiveFill() {
3143 if (checkForValidSection() || parseExpression(NumValues))
3146 int64_t FillSize = 1;
3147 int64_t FillExpr = 0;
3149 SMLoc SizeLoc, ExprLoc;
3152 SizeLoc = getTok().getLoc();
3153 if (parseAbsoluteExpression(FillSize))
3156 ExprLoc = getTok().getLoc();
3157 if (parseAbsoluteExpression(FillExpr))
3162 "unexpected token in '.fill' directive"))
3166 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3170 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3175 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3177 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3184 bool AsmParser::parseDirectiveOrg() {
3187 if (checkForValidSection() || parseExpression(Offset))
3191 int64_t FillExpr = 0;
3193 if (parseAbsoluteExpression(FillExpr))
3194 return addErrorSuffix(
" in '.org' directive");
3196 return addErrorSuffix(
" in '.org' directive");
3198 getStreamer().emitValueToOffset(Offset, FillExpr, OffsetLoc);
3204 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
3205 SMLoc AlignmentLoc = getLexer().getLoc();
3208 bool HasFillExpr =
false;
3209 int64_t FillExpr = 0;
3210 int64_t MaxBytesToFill = 0;
3212 auto parseAlign = [&]() ->
bool {
3213 if (parseAbsoluteExpression(Alignment))
3221 if (parseAbsoluteExpression(FillExpr))
3225 if (parseTokenLoc(MaxBytesLoc) ||
3226 parseAbsoluteExpression(MaxBytesToFill))
3232 if (checkForValidSection())
3233 return addErrorSuffix(
" in directive");
3236 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3240 return addErrorSuffix(
" in directive");
3243 bool ReturnVal =
false;
3248 if (Alignment >= 32) {
3249 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3253 Alignment = 1ULL << Alignment;
3261 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3266 if (MaxBytesToFill < 1) {
3267 ReturnVal |=
Error(MaxBytesLoc,
3268 "alignment directive can never be satisfied in this " 3269 "many bytes, ignoring maximum bytes expression");
3273 if (MaxBytesToFill >= Alignment) {
3274 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and " 3283 assert(Section &&
"must have section to emit alignment");
3286 ValueSize == 1 && UseCodeAlign) {
3287 getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
3290 getStreamer().EmitValueToAlignment(Alignment, FillExpr, ValueSize,
3300 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
3302 int64_t FileNumber = -1;
3304 FileNumber = getTok().getIntVal();
3308 return TokError(
"negative file number");
3316 "unexpected token in '.file' directive") ||
3317 parseEscapedString(Path))
3322 std::string FilenameData;
3324 if (check(FileNumber == -1,
3325 "explicit path specified, but no file number") ||
3326 parseEscapedString(FilenameData))
3328 Filename = FilenameData;
3334 uint64_t MD5Hi, MD5Lo;
3335 bool HasMD5 =
false;
3338 bool HasSource =
false;
3339 std::string SourceString;
3344 "unexpected token in '.file' directive") ||
3345 parseIdentifier(Keyword))
3347 if (Keyword ==
"md5") {
3349 if (check(FileNumber == -1,
3350 "MD5 checksum specified, but no file number") ||
3353 }
else if (Keyword ==
"source") {
3355 if (check(FileNumber == -1,
3356 "source specified, but no file number") ||
3358 "unexpected token in '.file' directive") ||
3359 parseEscapedString(SourceString))
3362 return TokError(
"unexpected token in '.file' directive");
3366 if (FileNumber == -1) {
3370 if (getContext().getAsmInfo()->hasSingleParameterDotFile())
3371 getStreamer().EmitFileDirective(Filename);
3384 for (
unsigned i = 0; i != 8; ++i) {
3385 CKMem->
Bytes[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3386 CKMem->
Bytes[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3390 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3391 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3392 Source =
StringRef(SourceBuf, SourceString.size());
3394 if (FileNumber == 0) {
3396 return Warning(DirectiveLoc,
"file 0 not supported prior to DWARF-5");
3397 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
3400 FileNumber, Directory, Filename, CKMem, Source);
3403 FileNumber = FileNumOrErr.
get();
3408 ReportedInconsistentMD5 =
true;
3409 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3418 bool AsmParser::parseDirectiveLine() {
3421 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
3427 "unexpected token in '.line' directive"))
3440 bool AsmParser::parseDirectiveLoc() {
3441 int64_t FileNumber = 0, LineNumber = 0;
3442 SMLoc Loc = getTok().getLoc();
3443 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
3445 "file number less than one in '.loc' directive") ||
3446 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
3447 "unassigned file number in '.loc' directive"))
3452 LineNumber = getTok().getIntVal();
3454 return TokError(
"line number less than zero in '.loc' directive");
3458 int64_t ColumnPos = 0;
3460 ColumnPos = getTok().getIntVal();
3462 return TokError(
"column position less than zero in '.loc' directive");
3468 int64_t Discriminator = 0;
3470 auto parseLocOp = [&]() ->
bool {
3472 SMLoc Loc = getTok().getLoc();
3473 if (parseIdentifier(Name))
3474 return TokError(
"unexpected token in '.loc' directive");
3476 if (Name ==
"basic_block")
3478 else if (Name ==
"prologue_end")
3480 else if (Name ==
"epilogue_begin")
3482 else if (Name ==
"is_stmt") {
3483 Loc = getTok().getLoc();
3485 if (parseExpression(Value))
3488 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3489 int Value = MCE->getValue();
3492 else if (Value == 1)
3495 return Error(Loc,
"is_stmt value not 0 or 1");
3497 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3499 }
else if (Name ==
"isa") {
3500 Loc = getTok().getLoc();
3502 if (parseExpression(Value))
3505 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3506 int Value = MCE->getValue();
3508 return Error(Loc,
"isa number less than zero");
3511 return Error(Loc,
"isa number not a constant value");
3513 }
else if (Name ==
"discriminator") {
3514 if (parseAbsoluteExpression(Discriminator))
3517 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3522 if (parseMany(parseLocOp,
false ))
3525 getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3533 bool AsmParser::parseDirectiveStabs() {
3534 return TokError(
"unsupported directive '.stabs'");
3539 bool AsmParser::parseDirectiveCVFile() {
3540 SMLoc FileNumberLoc = getTok().getLoc();
3542 std::string Filename;
3543 std::string Checksum;
3546 if (parseIntToken(FileNumber,
3547 "expected file number in '.cv_file' directive") ||
3548 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3550 "unexpected token in '.cv_file' directive") ||
3551 parseEscapedString(Filename))
3555 "unexpected token in '.cv_file' directive") ||
3556 parseEscapedString(Checksum) ||
3557 parseIntToken(ChecksumKind,
3558 "expected checksum kind in '.cv_file' directive") ||
3560 "unexpected token in '.cv_file' directive"))
3565 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3566 memcpy(CKMem, Checksum.data(), Checksum.size());
3570 if (!getStreamer().EmitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
3571 static_cast<uint8_t>(ChecksumKind)))
3572 return Error(FileNumberLoc,
"file number already allocated");
3577 bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3580 return parseTokenLoc(Loc) ||
3581 parseIntToken(FunctionId,
"expected function id in '" + DirectiveName +
3583 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3584 "expected function id within range [0, UINT_MAX)");
3587 bool AsmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
3589 return parseTokenLoc(Loc) ||
3590 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
3592 check(FileNumber < 1, Loc,
"file number less than one in '" +
3593 DirectiveName +
"' directive") ||
3594 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3595 "unassigned file number in '" + DirectiveName +
"' directive");
3602 bool AsmParser::parseDirectiveCVFuncId() {
3603 SMLoc FunctionIdLoc = getTok().getLoc();
3606 if (parseCVFunctionId(FunctionId,
".cv_func_id") ||
3608 "unexpected token in '.cv_func_id' directive"))
3611 if (!getStreamer().EmitCVFuncIdDirective(FunctionId))
3612 return Error(FunctionIdLoc,
"function id already allocated");
3625 bool AsmParser::parseDirectiveCVInlineSiteId() {
3626 SMLoc FunctionIdLoc = getTok().getLoc();
3634 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3639 getTok().getIdentifier() !=
"within"),
3640 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3645 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3650 getTok().getIdentifier() !=
"inlined_at"),
3651 "expected 'inlined_at' identifier in '.cv_inline_site_id' " 3657 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3658 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3663 IACol = getTok().getIntVal();
3668 "unexpected token in '.cv_inline_site_id' directive"))
3671 if (!getStreamer().EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3672 IALine, IACol, FunctionIdLoc))
3673 return Error(FunctionIdLoc,
"function id already allocated");
3685 bool AsmParser::parseDirectiveCVLoc() {
3686 SMLoc DirectiveLoc = getTok().getLoc();
3687 int64_t FunctionId, FileNumber;
3688 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3689 parseCVFileId(FileNumber,
".cv_loc"))
3692 int64_t LineNumber = 0;
3694 LineNumber = getTok().getIntVal();
3696 return TokError(
"line number less than zero in '.cv_loc' directive");
3700 int64_t ColumnPos = 0;
3702 ColumnPos = getTok().getIntVal();
3704 return TokError(
"column position less than zero in '.cv_loc' directive");
3708 bool PrologueEnd =
false;
3709 uint64_t IsStmt = 0;
3711 auto parseOp = [&]() ->
bool {
3713 SMLoc Loc = getTok().getLoc();
3714 if (parseIdentifier(Name))
3715 return TokError(
"unexpected token in '.cv_loc' directive");
3716 if (Name ==
"prologue_end")
3718 else if (Name ==
"is_stmt") {
3719 Loc = getTok().getLoc();
3721 if (parseExpression(Value))
3725 if (
const auto *MCE = dyn_cast<MCConstantExpr>(Value))
3726 IsStmt = MCE->getValue();
3729 return Error(Loc,
"is_stmt value not 0 or 1");
3731 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3736 if (parseMany(parseOp,
false ))
3739 getStreamer().EmitCVLocDirective(FunctionId, FileNumber, LineNumber,
3740 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
3747 bool AsmParser::parseDirectiveCVLinetable() {
3750 SMLoc Loc = getTok().getLoc();
3751 if (parseCVFunctionId(FunctionId,
".cv_linetable") ||
3753 "unexpected token in '.cv_linetable' directive") ||
3754 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3755 "expected identifier in directive") ||
3757 "unexpected token in '.cv_linetable' directive") ||
3758 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3759 "expected identifier in directive"))
3762 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3763 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3765 getStreamer().EmitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3771 bool AsmParser::parseDirectiveCVInlineLinetable() {
3772 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3774 SMLoc Loc = getTok().getLoc();
3775 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3776 parseTokenLoc(Loc) ||
3779 "expected SourceField in '.cv_inline_linetable' directive") ||
3780 check(SourceFileId <= 0, Loc,
3781 "File id less than zero in '.cv_inline_linetable' directive") ||
3782 parseTokenLoc(Loc) ||
3785 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
3786 check(SourceLineNum < 0, Loc,
3787 "Line number less than zero in '.cv_inline_linetable' directive") ||
3788 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3789 "expected identifier in directive") ||
3790 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3791 "expected identifier in directive"))
3797 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3798 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3799 getStreamer().EmitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3800 SourceLineNum, FnStartSym,
3807 bool AsmParser::parseDirectiveCVDefRange() {
3809 std::vector<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
3811 Loc = getLexer().getLoc();
3813 if (parseIdentifier(GapStartName))
3814 return Error(Loc,
"expected identifier in directive");
3815 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
3817 Loc = getLexer().getLoc();
3819 if (parseIdentifier(GapEndName))
3820 return Error(Loc,
"expected identifier in directive");
3821 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
3823 Ranges.push_back({GapStartSym, GapEndSym});
3826 std::string FixedSizePortion;
3828 parseEscapedString(FixedSizePortion))
3831 getStreamer().EmitCVDefRangeDirective(Ranges, FixedSizePortion);
3837 bool AsmParser::parseDirectiveCVString() {
3839 if (checkForValidSection() || parseEscapedString(Data))
3840 return addErrorSuffix(
" in '.cv_string' directive");
3843 std::pair<StringRef, unsigned> Insertion =
3844 getCVContext().addToStringTable(Data);
3845 getStreamer().EmitIntValue(Insertion.second, 4);
3851 bool AsmParser::parseDirectiveCVStringTable() {
3852 getStreamer().EmitCVStringTableDirective();
3858 bool AsmParser::parseDirectiveCVFileChecksums() {
3859 getStreamer().EmitCVFileChecksumsDirective();
3865 bool AsmParser::parseDirectiveCVFileChecksumOffset() {
3867 if (parseIntToken(FileNo,
"expected identifier in directive"))
3871 getStreamer().EmitCVFileChecksumOffsetDirective(FileNo);
3877 bool AsmParser::parseDirectiveCVFPOData() {
3878 SMLoc DirLoc = getLexer().getLoc();
3880 if (parseIdentifier(ProcName))
3881 return TokError(
"expected symbol name");
3882 if (parseEOL(
"unexpected tokens"))
3883 return addErrorSuffix(
" in '.cv_fpo_data' directive");
3884 MCSymbol *ProcSym = getContext().getOrCreateSymbol(ProcName);
3885 getStreamer().EmitCVFPOData(ProcSym, DirLoc);
3891 bool AsmParser::parseDirectiveCFISections() {
3896 if (parseIdentifier(Name))
3897 return TokError(
"Expected an identifier");
3899 if (Name ==
".eh_frame")
3901 else if (Name ==
".debug_frame")
3907 if (parseIdentifier(Name))
3908 return TokError(
"Expected an identifier");
3910 if (Name ==
".eh_frame")
3912 else if (Name ==
".debug_frame")
3916 getStreamer().EmitCFISections(EH, Debug);
3922 bool AsmParser::parseDirectiveCFIStartProc() {
3925 if (check(parseIdentifier(Simple) || Simple !=
"simple",
3926 "unexpected token") ||
3928 return addErrorSuffix(
" in '.cfi_startproc' directive");
3936 getStreamer().EmitCFIStartProc(!Simple.
empty(), Lexer.
getLoc());
3942 bool AsmParser::parseDirectiveCFIEndProc() {
3943 getStreamer().EmitCFIEndProc();
3948 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
3949 SMLoc DirectiveLoc) {
3953 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
3955 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
3957 return parseAbsoluteExpression(Register);
3964 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
3965 int64_t Register = 0,
Offset = 0;
3966 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3968 parseAbsoluteExpression(
Offset))
3971 getStreamer().EmitCFIDefCfa(Register,
Offset);
3977 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
3979 if (parseAbsoluteExpression(Offset))
3982 getStreamer().EmitCFIDefCfaOffset(Offset);
3988 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
3989 int64_t Register1 = 0, Register2 = 0;
3990 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) ||
3992 parseRegisterOrRegisterNumber(Register2, DirectiveLoc))
3995 getStreamer().EmitCFIRegister(Register1, Register2);
4001 bool AsmParser::parseDirectiveCFIWindowSave() {
4002 getStreamer().EmitCFIWindowSave();
4008 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
4009 int64_t Adjustment = 0;
4010 if (parseAbsoluteExpression(Adjustment))
4013 getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
4019 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
4020 int64_t Register = 0;
4021 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4024 getStreamer().EmitCFIDefCfaRegister(Register);
4030 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
4031 int64_t Register = 0;
4034 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
4036 parseAbsoluteExpression(Offset))
4039 getStreamer().EmitCFIOffset(Register, Offset);
4045 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
4046 int64_t Register = 0,
Offset = 0;
4048 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
4050 parseAbsoluteExpression(
Offset))
4053 getStreamer().EmitCFIRelOffset(Register,
Offset);
4058 if (Encoding & ~0xff)
4064 const unsigned Format = Encoding & 0xf;
4071 const unsigned Application = Encoding & 0x70;
4083 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4084 int64_t Encoding = 0;
4085 if (parseAbsoluteExpression(Encoding))
4093 check(parseIdentifier(Name),
"expected identifier in directive"))
4096 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4099 getStreamer().EmitCFIPersonality(Sym, Encoding);
4101 getStreamer().EmitCFILsda(Sym, Encoding);
4107 bool AsmParser::parseDirectiveCFIRememberState() {
4108 getStreamer().EmitCFIRememberState();
4114 bool AsmParser::parseDirectiveCFIRestoreState() {
4115 getStreamer().EmitCFIRestoreState();
4121 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
4122 int64_t Register = 0;
4124 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4127 getStreamer().EmitCFISameValue(Register);
4133 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
4134 int64_t Register = 0;
4135 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4138 getStreamer().EmitCFIRestore(Register);
4144 bool AsmParser::parseDirectiveCFIEscape() {
4147 if (parseAbsoluteExpression(CurrValue))
4150 Values.push_back((uint8_t)CurrValue);
4155 if (parseAbsoluteExpression(CurrValue))
4158 Values.push_back((uint8_t)CurrValue);
4161 getStreamer().EmitCFIEscape(Values);
4167 bool AsmParser::parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc) {
4168 int64_t Register = 0;
4169 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4171 getStreamer().EmitCFIReturnColumn(Register);
4177 bool AsmParser::parseDirectiveCFISignalFrame() {
4179 "unexpected token in '.cfi_signal_frame'"))
4182 getStreamer().EmitCFISignalFrame();
4188 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
4189 int64_t Register = 0;
4191 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4194 getStreamer().EmitCFIUndefined(Register);
4201 bool AsmParser::parseDirectiveAltmacro(
StringRef Directive) {
4203 return TokError(
"unexpected token in '" + Directive +
"' directive");
4204 AltMacroMode = (Directive ==
".altmacro");
4211 bool AsmParser::parseDirectiveMacrosOnOff(
StringRef Directive) {
4213 "unexpected token in '" + Directive +
"' directive"))
4216 setMacrosEnabled(Directive ==
".macros_on");
4222 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
4224 if (parseIdentifier(Name))
4225 return TokError(
"expected identifier in '.macro' directive");
4233 if (!Parameters.empty() && Parameters.back().Vararg)
4235 "Vararg parameter '" + Parameters.back().Name +
4236 "' should be last one in the list of parameters.");
4239 if (parseIdentifier(Parameter.
Name))
4240 return TokError(
"expected identifier in '.macro' directive");
4244 if (CurrParam.Name.equals(Parameter.
Name))
4245 return TokError(
"macro '" + Name +
"' has multiple parameters" 4246 " named '" + Parameter.
Name +
"'");
4254 QualLoc = Lexer.
getLoc();
4255 if (parseIdentifier(Qualifier))
4256 return Error(QualLoc,
"missing parameter qualifier for " 4257 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4259 if (Qualifier ==
"req")
4261 else if (Qualifier ==
"vararg")
4264 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier " 4265 "for '" + Parameter.
Name +
"' in macro '" + Name +
"'");
4273 ParamLoc = Lexer.
getLoc();
4274 if (parseMacroArgument(Parameter.
Value,
false ))
4278 Warning(ParamLoc,
"pointless default value for required parameter " 4279 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4282 Parameters.push_back(std::move(Parameter));
4292 AsmToken EndToken, StartToken = getTok();
4293 unsigned MacroDepth = 0;
4303 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4307 if (getTok().getIdentifier() ==
".endm" ||
4308 getTok().getIdentifier() ==
".endmacro") {
4309 if (MacroDepth == 0) {
4310 EndToken = getTok();
4313 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4320 }
else if (getTok().getIdentifier() ==
".macro") {
4328 eatToEndOfStatement();
4331 if (getContext().lookupMacro(Name)) {
4332 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4338 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4342 getContext().defineMacro(Name, std::move(Macro));
4360 void AsmParser::checkForBadMacro(
SMLoc DirectiveLoc,
StringRef Name,
4365 unsigned NParameters = Parameters.
size();
4366 if (NParameters == 0)
4369 bool NamedParametersFound =
false;
4370 bool PositionalParametersFound =
false;
4375 while (!Body.
empty()) {
4377 std::size_t End = Body.
size(), Pos = 0;
4378 for (; Pos != End; ++Pos) {
4381 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4385 if (Body[Pos] !=
'$' || Pos + 1 == End)
4387 char Next = Body[Pos + 1];
4388 if (Next ==
'$' || Next ==
'n' ||
4389 isdigit(static_cast<unsigned char>(Next)))
4397 if (Body[Pos] ==
'$') {
4398 switch (Body[Pos + 1]) {
4405 PositionalParametersFound =
true;
4410 PositionalParametersFound =
true;
4416 unsigned I = Pos + 1;
4420 const char *Begin = Body.
data() + Pos + 1;
4423 for (; Index < NParameters; ++
Index)
4424 if (Parameters[Index].Name == Argument)
4427 if (Index == NParameters) {
4428 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4434 NamedParametersFound =
true;
4435 Pos += 1 + Argument.
size();
4442 if (!NamedParametersFound && PositionalParametersFound)
4443 Warning(DirectiveLoc,
"macro defined with named parameters which are not " 4444 "used in macro body, possible positional parameter " 4445 "found in body which will have no effect");
4450 bool AsmParser::parseDirectiveExitMacro(
StringRef Directive) {
4452 "unexpected token in '" + Directive +
"' directive"))
4455 if (!isInsideMacroInstantiation())
4456 return TokError(
"unexpected '" + Directive +
"' in file, " 4457 "no current macro definition");
4460 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4461 TheCondState = TheCondStack.back();
4462 TheCondStack.pop_back();
4472 bool AsmParser::parseDirectiveEndMacro(
StringRef Directive) {
4474 return TokError(
"unexpected token in '" + Directive +
"' directive");
4478 if (isInsideMacroInstantiation()) {
4485 return TokError(
"unexpected '" + Directive +
"' in file, " 4486 "no current macro definition");
4491 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
4494 if (parseTokenLoc(Loc) ||
4495 check(parseIdentifier(Name), Loc,
4496 "expected identifier in '.purgem' directive") ||
4498 "unexpected token in '.purgem' directive"))
4501 if (!getContext().lookupMacro(Name))
4502 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4504 getContext().undefineMacro(Name);
4506 <<
"Un-defining macro: " << Name <<
"\n");
4512 bool AsmParser::parseDirectiveBundleAlignMode() {
4515 SMLoc ExprLoc = getLexer().getLoc();
4516 int64_t AlignSizePow2;
4517 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4519 "in '.bundle_align_mode' " 4521 check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
4522 "invalid bundle alignment size (expected between 0 and 30)"))
4527 getStreamer().EmitBundleAlignMode(static_cast<unsigned>(AlignSizePow2));
4533 bool AsmParser::parseDirectiveBundleLock() {
4534 if (checkForValidSection())
4536 bool AlignToEnd =
false;
4539 SMLoc Loc = getTok().getLoc();
4540 const char *kInvalidOptionError =
4541 "invalid option for '.bundle_lock' directive";
4544 if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
4545 check(Option !=
"align_to_end", Loc, kInvalidOptionError) ||
4547 "unexpected token after '.bundle_lock' directive option"))
4552 getStreamer().EmitBundleLock(AlignToEnd);
4558 bool AsmParser::parseDirectiveBundleUnlock() {
4559 if (checkForValidSection() ||
4561 "unexpected token in '.bundle_unlock' directive"))
4564 getStreamer().EmitBundleUnlock();
4570 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
4573 if (checkForValidSection() || parseExpression(NumBytes))
4576 int64_t FillExpr = 0;
4578 if (parseAbsoluteExpression(FillExpr))
4579 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4581 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4584 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4591 bool AsmParser::parseDirectiveDCB(
StringRef IDVal,
unsigned Size) {
4594 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4597 if (NumValues < 0) {
4598 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4603 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4607 SMLoc ExprLoc = getLexer().getLoc();
4608 if (parseExpression(Value))
4612 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
4613 assert(Size <= 8 &&
"Invalid size");
4614 uint64_t IntValue = MCE->getValue();
4615 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
4616 return Error(ExprLoc,
"literal value out of range for directive");
4617 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4618 getStreamer().EmitIntValue(IntValue, Size);
4620 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4621 getStreamer().EmitValue(Value, Size, ExprLoc);
4625 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4636 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4639 if (NumValues < 0) {
4640 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4645 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4649 if (parseRealValue(Semantics, AsInt))
4653 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4656 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4665 bool AsmParser::parseDirectiveDS(
StringRef IDVal,
unsigned Size) {
4668 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4671 if (NumValues < 0) {
4672 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4677 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4680 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4681 getStreamer().emitFill(Size, 0);
4688 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4689 if (checkForValidSection())
4692 auto parseOp = [&]() ->
bool {
4694 if (parseExpression(Value))
4697 getStreamer().EmitSLEB128Value(Value);
4699 getStreamer().EmitULEB128Value(Value);
4703 if (parseMany(parseOp))
4704 return addErrorSuffix(
" in directive");
4711 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4712 auto parseOp = [&]() ->
bool {
4714 SMLoc Loc = getTok().getLoc();
4715 if (parseIdentifier(Name))
4716 return Error(Loc,
"expected identifier");
4717 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4721 return Error(Loc,
"non-local symbol required");
4723 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
4724 return Error(Loc,
"unable to emit symbol attribute");
4728 if (parseMany(parseOp))
4729 return addErrorSuffix(
" in directive");
4735 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4736 if (checkForValidSection())
4739 SMLoc IDLoc = getLexer().getLoc();
4741 if (parseIdentifier(Name))
4742 return TokError(
"expected identifier in directive");
4745 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4748 return TokError(
"unexpected token in directive");
4752 SMLoc SizeLoc = getLexer().getLoc();
4753 if (parseAbsoluteExpression(Size))
4756 int64_t Pow2Alignment = 0;
4757 SMLoc Pow2AlignmentLoc;
4760 Pow2AlignmentLoc = getLexer().getLoc();
4761 if (parseAbsoluteExpression(Pow2Alignment))
4766 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4772 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4773 Pow2Alignment =
Log2_64(Pow2Alignment);
4778 "unexpected token in '.comm' or '.lcomm' directive"))
4784 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't " 4785 "be less than zero");
4790 if (Pow2Alignment < 0)
4791 return Error(Pow2AlignmentLoc,
"invalid '.comm' or '.lcomm' directive " 4792 "alignment, can't be less than zero");
4796 return Error(IDLoc,
"invalid symbol redefinition");
4800 getStreamer().EmitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4804 getStreamer().EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4810 bool AsmParser::parseDirectiveAbort() {
4812 SMLoc Loc = getLexer().getLoc();
4814 StringRef Str = parseStringToEndOfStatement();
4816 "unexpected token in '.abort' directive"))
4820 return Error(Loc,
".abort detected. Assembly stopping.");
4822 return Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
4830 bool AsmParser::parseDirectiveInclude() {
4832 std::string Filename;
4833 SMLoc IncludeLoc = getTok().getLoc();
4836 "expected string in '.include' directive") ||
4837 parseEscapedString(Filename) ||
4839 "unexpected token in '.include' directive") ||
4842 check(enterIncludeFile(Filename), IncludeLoc,
4843 "Could not find include file '" + Filename +
"'"))
4851 bool AsmParser::parseDirectiveIncbin() {
4853 std::string Filename;
4854 SMLoc IncbinLoc = getTok().getLoc();
4856 "expected string in '.incbin' directive") ||
4857 parseEscapedString(Filename))
4861 const MCExpr *Count =
nullptr;
4862 SMLoc SkipLoc, CountLoc;
4867 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
4871 CountLoc = getTok().getLoc();
4872 if (parseExpression(Count))
4878 "unexpected token in '.incbin' directive"))
4881 if (check(Skip < 0, SkipLoc,
"skip is negative"))
4885 if (processIncbinFile(Filename, Skip, Count, CountLoc))
4886 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
4892 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
4893 TheCondStack.push_back(TheCondState);
4895 if (TheCondState.
Ignore) {
4896 eatToEndOfStatement();
4899 if (parseAbsoluteExpression(ExprValue) ||
4901 "unexpected token in '.if' directive"))
4911 ExprValue = ExprValue == 0;
4914 ExprValue = ExprValue >= 0;
4917 ExprValue = ExprValue > 0;
4920 ExprValue = ExprValue <= 0;
4923 ExprValue = ExprValue < 0;
4927 TheCondState.
CondMet = ExprValue;
4936 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
4937 TheCondStack.push_back(TheCondState);
4940 if (TheCondState.
Ignore) {
4941 eatToEndOfStatement();
4943 StringRef Str = parseStringToEndOfStatement();
4946 "unexpected token in '.ifb' directive"))
4959 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4960 TheCondStack.push_back(TheCondState);
4963 if (TheCondState.
Ignore) {
4964 eatToEndOfStatement();
4968 if (parseToken(
AsmToken::Comma,
"unexpected token in '.ifc' directive"))
4971 StringRef Str2 = parseStringToEndOfStatement();
4974 "unexpected token in '.ifc' directive"))
4986 bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4989 return TokError(
"expected string parameter for '.ifeqs' directive");
4990 return TokError(
"expected string parameter for '.ifnes' directive");
4993 StringRef String1 = getTok().getStringContents();
4999 "expected comma after first string for '.ifeqs' directive");
5000 return TokError(
"expected comma after first string for '.ifnes' directive");
5007 return TokError(
"expected string parameter for '.ifeqs' directive");
5008 return TokError(
"expected string parameter for '.ifnes' directive");
5011 StringRef String2 = getTok().getStringContents();
5014 TheCondStack.push_back(TheCondState);
5016 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5024 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
5026 TheCondStack.push_back(TheCondState);
5029 if (TheCondState.
Ignore) {
5030 eatToEndOfStatement();
5032 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5036 MCSymbol *Sym = getContext().lookupSymbol(Name);
5050 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
5053 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an" 5054 " .if or an .elseif");
5057 bool LastIgnoreState =
false;
5058 if (!TheCondStack.empty())
5059 LastIgnoreState = TheCondStack.back().Ignore;
5060 if (LastIgnoreState || TheCondState.
CondMet) {
5061 TheCondState.
Ignore =
true;
5062 eatToEndOfStatement();
5065 if (parseAbsoluteExpression(ExprValue))
5069 "unexpected token in '.elseif' directive"))
5072 TheCondState.
CondMet = ExprValue;
5081 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
5083 "unexpected token in '.else' directive"))
5088 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow " 5089 " an .if or an .elseif");
5091 bool LastIgnoreState =
false;
5092 if (!TheCondStack.empty())
5093 LastIgnoreState = TheCondStack.back().Ignore;
5094 if (LastIgnoreState || TheCondState.
CondMet)
5095 TheCondState.
Ignore =
true;
5097 TheCondState.
Ignore =
false;
5104 bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
5106 "unexpected token in '.end' directive"))
5118 bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
5119 if (!TheCondStack.empty()) {
5120 if (TheCondStack.back().Ignore) {
5121 eatToEndOfStatement();
5127 return Error(L,
".err encountered");
5129 StringRef Message =
".error directive invoked in source file";
5132 return TokError(
".error argument must be a string");
5134 Message = getTok().getStringContents();
5138 return Error(L, Message);
5143 bool AsmParser::parseDirectiveWarning(
SMLoc L) {
5144 if (!TheCondStack.empty()) {
5145 if (TheCondStack.back().Ignore) {
5146 eatToEndOfStatement();
5151 StringRef Message =
".warning directive invoked in source file";
5155 return TokError(
".warning argument must be a string");
5157 Message = getTok().getStringContents();
5160 "expected end of statement in '.warning' directive"))
5169 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
5171 "unexpected token in '.endif' directive"))
5175 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow " 5177 if (!TheCondStack.empty()) {
5178 TheCondState = TheCondStack.back();
5179 TheCondStack.pop_back();
5185 void AsmParser::initializeDirectiveKindMap() {
5186 DirectiveKindMap[
".set"] = DK_SET;
5187 DirectiveKindMap[
".equ"] = DK_EQU;
5188 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5189 DirectiveKindMap[
".ascii"] = DK_ASCII;
5190 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5191 DirectiveKindMap[
".string"] = DK_STRING;
5192 DirectiveKindMap[
".byte"] = DK_BYTE;
5193 DirectiveKindMap[
".short"] = DK_SHORT;
5194 DirectiveKindMap[
".value"] = DK_VALUE;
5195 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5196 DirectiveKindMap[
".long"] = DK_LONG;
5197 DirectiveKindMap[
".int"] = DK_INT;
5198 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5199 DirectiveKindMap[
".quad"] = DK_QUAD;
5200 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5201 DirectiveKindMap[
".octa"] = DK_OCTA;
5202 DirectiveKindMap[
".single"] = DK_SINGLE;
5203 DirectiveKindMap[
".float"] = DK_FLOAT;
5204 DirectiveKindMap[
".double"] = DK_DOUBLE;
5205 DirectiveKindMap[
".align"] = DK_ALIGN;
5206 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5207 DirectiveKindMap[
".balign"] = DK_BALIGN;
5208 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5209 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5210 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5211 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5212 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5213 DirectiveKindMap[
".org"] = DK_ORG;
5214 DirectiveKindMap[
".fill"] = DK_FILL;
5215 DirectiveKindMap[
".zero"] = DK_ZERO;
5216 DirectiveKindMap[
".extern"] = DK_EXTERN;
5217 DirectiveKindMap[
".globl"] = DK_GLOBL;
5218 DirectiveKindMap[
".global"] = DK_GLOBAL;
5219 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5220 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5221 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5222 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5223 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5224 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5225 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5226 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5227 DirectiveKindMap[
".comm"] = DK_COMM;
5228 DirectiveKindMap[
".common"] = DK_COMMON;
5229 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5230 DirectiveKindMap[
".abort"] = DK_ABORT;
5231 DirectiveKindMap[
".include"] = DK_INCLUDE;
5232 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5233 DirectiveKindMap[
".code16"] = DK_CODE16;
5234 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5235 DirectiveKindMap[
".rept"] = DK_REPT;
5236 DirectiveKindMap[
".rep"] = DK_REPT;
5237 DirectiveKindMap[
".irp"] = DK_IRP;
5238 DirectiveKindMap[
".irpc"] = DK_IRPC;
5239 DirectiveKindMap[
".endr"] = DK_ENDR;
5240 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5241 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5242 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5243 DirectiveKindMap[
".if"] = DK_IF;
5244 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5245 DirectiveKindMap[
".ifge"] = DK_IFGE;
5246 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5247 DirectiveKindMap[
".ifle"] = DK_IFLE;
5248 DirectiveKindMap[
".iflt"] = DK_IFLT;
5249 DirectiveKindMap[
".ifne"] = DK_IFNE;
5250 DirectiveKindMap[
".ifb"] = DK_IFB;
5251 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5252 DirectiveKindMap[
".ifc"] = DK_IFC;
5253 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5254 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5255 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5256 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5257 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5258 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5259 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5260 DirectiveKindMap[
".else"] = DK_ELSE;
5261 DirectiveKindMap[
".end"] = DK_END;
5262 DirectiveKindMap[
".endif"] = DK_ENDIF;
5263 DirectiveKindMap[
".skip"] = DK_SKIP;
5264 DirectiveKindMap[
".space"] = DK_SPACE;
5265 DirectiveKindMap[
".file"] = DK_FILE;
5266 DirectiveKindMap[
".line"] = DK_LINE;
5267 DirectiveKindMap[
".loc"] = DK_LOC;
5268 DirectiveKindMap[
".stabs"] = DK_STABS;
5269 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5270 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5271 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5272 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5273 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5274 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5275 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5276 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5277 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5278 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5279 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5280 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5281 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5282 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5283 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5284 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5285 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5286 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5287 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5288 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5289 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5290 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5291 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5292 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5293 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5294 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5295 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5296 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5297 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5298 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5299 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5300 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5301 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5302 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5303 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5304 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5305 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5306 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5307 DirectiveKindMap[
".macro"] = DK_MACRO;
5308 DirectiveKindMap[
".exitm"] = DK_EXITM;
5309 DirectiveKindMap[
".endm"] = DK_ENDM;
5310 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5311 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5312 DirectiveKindMap[
".err"] = DK_ERR;
5313 DirectiveKindMap[
".error"] = DK_ERROR;
5314 DirectiveKindMap[
".warning"] = DK_WARNING;
5315 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5316 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5317 DirectiveKindMap[
".reloc"] = DK_RELOC;
5318 DirectiveKindMap[
".dc"] = DK_DC;
5319 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5320 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5321 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5322 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5323 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5324 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5325 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5326 DirectiveKindMap[
".dcb"] = DK_DCB;
5327 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5328 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5329 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5330 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5331 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5332 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5333 DirectiveKindMap[
".ds"] = DK_DS;
5334 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5335 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5336 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5337 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5338 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5339 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5340 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5341 DirectiveKindMap[
".print"] = DK_PRINT;
5342 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5343 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5347 AsmToken EndToken, StartToken = getTok();
5349 unsigned NestLevel = 0;
5353 printError(DirectiveLoc,
"no matching '.endr' in definition");
5358 (getTok().getIdentifier() ==
".rep" ||
5359 getTok().getIdentifier() ==
".rept" ||
5360 getTok().getIdentifier() ==
".irp" ||
5361 getTok().getIdentifier() ==
".irpc")) {
5367 if (NestLevel == 0) {
5368 EndToken = getTok();
5371 printError(getTok().getLoc(),
5372 "unexpected token in '.endr' directive");
5381 eatToEndOfStatement();
5390 return &MacroLikeBodies.back();
5393 void AsmParser::instantiateMacroLikeBody(
MCAsmMacro *M,
SMLoc DirectiveLoc,
5397 std::unique_ptr<MemoryBuffer> Instantiation =
5402 MacroInstantiation *
MI =
new MacroInstantiation(
5403 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
5404 ActiveMacros.push_back(MI);
5414 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
5416 SMLoc CountLoc = getTok().getLoc();
5417 if (parseExpression(CountExpr))
5421 if (!CountExpr->evaluateAsAbsolute(Count, getStreamer().getAssemblerPtr())) {
5422 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5425 if (check(Count < 0, CountLoc,
"Count is negative") ||
5427 "unexpected token in '" + Dir +
"' directive"))
5431 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5441 if (expandMacro(OS, M->
Body,
None,
None,
false, getTok().getLoc()))
5444 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5451 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
5453 MCAsmMacroArguments A;
5454 if (check(parseIdentifier(Parameter.
Name),
5455 "expected identifier in '.irp' directive") ||
5457 parseMacroArguments(
nullptr, A) ||
5462 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5471 for (
const MCAsmMacroArgument &
Arg : A) {
5474 if (expandMacro(OS, M->
Body, Parameter,
Arg,
true, getTok().getLoc()))
5478 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5485 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
5487 MCAsmMacroArguments A;
5489 if (check(parseIdentifier(Parameter.
Name),
5490 "expected identifier in '.irpc' directive") ||
5492 parseMacroArguments(
nullptr, A))
5495 if (A.size() != 1 || A.front().size() != 1)
5496 return TokError(
"unexpected token in '.irpc' directive");
5503 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5513 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5514 MCAsmMacroArgument
Arg;
5519 if (expandMacro(OS, M->
Body, Parameter, Arg,
true, getTok().getLoc()))
5523 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5528 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
5529 if (ActiveMacros.empty())
5530 return TokError(
"unmatched '.endr' directive");
5540 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
5543 SMLoc ExprLoc = getLexer().getLoc();
5544 if (parseExpression(Value))
5548 return Error(ExprLoc,
"unexpected expression in _emit");
5549 uint64_t IntValue = MCE->
getValue();
5551 return Error(ExprLoc,
"literal value out of range for directive");
5553 Info.AsmRewrites->emplace_back(
AOK_Emit, IDLoc, Len);
5557 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
5559 SMLoc ExprLoc = getLexer().getLoc();
5560 if (parseExpression(Value))
5564 return Error(ExprLoc,
"unexpected expression in align");
5565 uint64_t IntValue = MCE->
getValue();
5567 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5573 bool AsmParser::parseDirectivePrint(
SMLoc DirectiveLoc) {
5577 return Error(DirectiveLoc,
"expected double quoted string after .print");
5584 bool AsmParser::parseDirectiveAddrsig() {
5585 getStreamer().EmitAddrsig();
5589 bool AsmParser::parseDirectiveAddrsigSym() {
5591 if (check(parseIdentifier(Name),
5592 "expected identifier in '.addrsig_sym' directive"))
5594 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
5595 getStreamer().EmitAddrsigSym(Sym);
5622 bool AsmParser::parseMSInlineAsm(
5623 void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs,
5624 unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5642 unsigned InputIdx = 0;
5643 unsigned OutputIdx = 0;
5646 if (parseCurlyBlockScope(AsmStrRewrites))
5649 ParseStatementInfo
Info(&AsmStrRewrites);
5650 bool StatementErr = parseStatement(Info, &SI);
5652 if (StatementErr || Info.ParseError) {
5654 printPendingErrors();
5659 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5661 if (Info.Opcode == ~0U)
5667 for (
unsigned i = 1, e = Info.ParsedOperands.size(); i != e; ++i) {
5671 if (Operand.
isImm())
5676 !getTargetParser().OmitRegisterFromClobberLists(Operand.
getReg())) {
5686 if (SymName.
empty())
5693 bool isOutput = (i == 1) && Desc.
mayStore();
5712 ClobberRegs.
insert(ClobberRegs.
end(), ImpDefs.begin(), ImpDefs.end());
5716 NumOutputs = OutputDecls.
size();
5717 NumInputs = InputDecls.
size();
5721 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
5723 Clobbers.
assign(ClobberRegs.
size(), std::string());
5724 for (
unsigned I = 0, E = ClobberRegs.
size();
I !=
E; ++
I) {
5730 if (NumOutputs || NumInputs) {
5731 unsigned NumExprs = NumOutputs + NumInputs;
5732 OpDecls.resize(NumExprs);
5733 Constraints.
resize(NumExprs);
5734 for (
unsigned i = 0; i < NumOutputs; ++i) {
5735 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
5736 Constraints[i] = OutputConstraints[i];
5738 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) {
5739 OpDecls[j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
5740 Constraints[j] = InputConstraints[i];
5745 std::string AsmStringIR;
5749 const char *AsmStart = ASMString.
begin();
5750 const char *AsmEnd = ASMString.
end();
5752 for (
const AsmRewrite &AR : AsmStrRewrites) {
5756 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
5759 if (
unsigned Len = Loc - AsmStart)
5764 AsmStart = Loc + AR.Len;
5768 unsigned AdditionalSkip = 0;
5774 assert(AR.IntelExp.isValid() &&
"cannot write invalid intel expression");
5775 if (AR.IntelExp.NeedBracs)
5777 if (AR.IntelExp.hasBaseReg())
5778 OS << AR.IntelExp.BaseReg;
5779 if (AR.IntelExp.hasIndexReg())
5780 OS << (AR.IntelExp.hasBaseReg() ?
" + " :
"")
5781 << AR.IntelExp.IndexReg;
5782 if (AR.IntelExp.Scale > 1)
5783 OS <<
" * $$" << AR.IntelExp.Scale;
5784 if (AR.IntelExp.Imm || !AR.IntelExp.hasRegs())
5785 OS << (AR.IntelExp.hasRegs() ?
" + $$" :
"$$") << AR.IntelExp.Imm;
5786 if (AR.IntelExp.NeedBracs)
5793 OS <<
'$' << InputIdx++;
5796 OS <<
'$' << OutputIdx++;
5801 case 8: OS <<
"byte ptr ";
break;
5802 case 16: OS <<
"word ptr ";
break;
5803 case 32: OS <<
"dword ptr ";
break;
5804 case 64: OS <<
"qword ptr ";
break;
5805 case 80: OS <<
"xword ptr ";
break;
5806 case 128: OS <<
"xmmword ptr ";
break;
5807 case 256: OS <<
"ymmword ptr ";
break;
5817 if (getContext().getAsmInfo()->getAlignmentIsInBytes())
5822 unsigned Val = AR.Val;
5824 assert(Val < 10 &&
"Expected alignment less then 2^10.");
5825 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
5837 AsmStart = Loc + AR.Len + AdditionalSkip;
5841 if (AsmStart != AsmEnd)
5842 OS <<
StringRef(AsmStart, AsmEnd - AsmStart);
5844 AsmString = OS.
str();
5849 namespace MCParserUtils {
5872 Sym, static_cast<const MCUnaryExpr *>(Value)->getSubExpr());
5885 return Parser.
TokError(
"missing expression");
5903 return Parser.
Error(EqualLoc,
"Recursive use of '" + Name +
"'");
5910 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
5912 return Parser.
Error(EqualLoc,
"invalid assignment to '" + Name +
"'");
5914 return Parser.
Error(EqualLoc,
5915 "invalid reassignment of non-absolute variable '" +
5917 }
else if (Name ==
".") {
5935 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)...
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.
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.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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.
uint16_t getDwarfVersion() const
Error takeError()
Take ownership of the stored error.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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.
opStatus convertFromString(StringRef, roundingMode)
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.
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.
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.
AsmCond - Class to support conditional assembly.
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
virtual StringRef getSymName()
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
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)
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool shouldUseLogicalShr() const
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
virtual void * getOpDecl()
static const fltSemantics & IEEEdouble() LLVM_READNONE
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
StringRef getConstraint()
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
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).
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
size_t size() const
size - Get the array size.
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."))
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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.
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...
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Promote Memory to Register
MCSymbol * getBeginSymbol()
StringRef str()
Return a StringRef for the vector contents.
bool isUsed() const
isUsed - Check if this is used.
reference get()
Returns a reference to the stored T value.
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.
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)
amdgpu Simplify well known AMD library false Value Value * Arg
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...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
SMLoc getParentIncludeLoc(unsigned i) const
void emplace_back(ArgTypes &&... Args)
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
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
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))
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
SMLoc getErrLoc()
Get the current error location.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
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.
APInt bitcastToAPInt() const
Target specific expression.
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
Represents a location in source code.
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
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.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
const SourceMgr * getSourceMgr() const
virtual bool isReg() const =0
isReg - Is this a register operand?
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.