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;
186 AsmParser(
const AsmParser &) =
delete;
187 AsmParser &operator=(
const AsmParser &) =
delete;
188 ~AsmParser()
override;
190 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
192 void addDirectiveHandler(
StringRef Directive,
193 ExtensionDirectiveHandler Handler)
override {
194 ExtensionDirectiveMap[Directive] = Handler;
198 DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
205 MCAsmLexer &getLexer()
override {
return Lexer; }
206 MCContext &getContext()
override {
return Ctx; }
207 MCStreamer &getStreamer()
override {
return Out; }
211 unsigned getAssemblerDialect()
override {
212 if (AssemblerDialect == ~0U)
215 return AssemblerDialect;
217 void setAssemblerDialect(
unsigned i)
override {
218 AssemblerDialect = i;
227 void setParsingInlineAsm(
bool V)
override {
228 ParsingInlineAsm = V;
231 bool isParsingInlineAsm()
override {
return ParsingInlineAsm; }
233 bool parseMSInlineAsm(
void *AsmLoc, std::string &AsmString,
234 unsigned &NumOutputs,
unsigned &NumInputs,
241 bool parseExpression(
const MCExpr *&Res);
242 bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
243 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
244 bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
245 bool parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
246 SMLoc &EndLoc)
override;
247 bool parseAbsoluteExpression(int64_t &Res)
override;
255 bool parseIdentifier(
StringRef &Res)
override;
256 void eatToEndOfStatement()
override;
258 bool checkForValidSection()
override;
263 bool isAltmacroString(
SMLoc &StrLoc,
SMLoc &EndLoc);
264 void altMacroString(
StringRef AltMacroStr, std::string &Res);
265 bool parseStatement(ParseStatementInfo &Info,
268 bool parseCppHashLineFilenameComment(
SMLoc L);
278 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
281 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
284 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
293 void handleMacroExit();
296 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
299 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &A);
301 void printMacroInstantiations();
312 bool enabledGenDwarfForAssembly();
315 bool enterIncludeFile(
const std::string &Filename);
319 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
328 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
333 StringRef parseStringToEndOfStatement()
override;
340 bool NoDeadStrip =
false);
345 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
346 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
347 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
349 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
351 bool parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName);
352 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
411 DK_BUNDLE_ALIGN_MODE,
425 DK_WEAK_DEF_CAN_BE_HIDDEN,
464 DK_CV_INLINE_SITE_ID,
467 DK_CV_INLINE_LINETABLE,
471 DK_CV_FILECHECKSUM_OFFSET,
477 DK_CFI_DEF_CFA_OFFSET,
478 DK_CFI_ADJUST_CFA_OFFSET,
479 DK_CFI_DEF_CFA_REGISTER,
484 DK_CFI_REMEMBER_STATE,
485 DK_CFI_RESTORE_STATE,
489 DK_CFI_RETURN_COLUMN,
519 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
520 bool parseDirectiveReloc(
SMLoc DirectiveLoc);
521 bool parseDirectiveValue(
StringRef IDVal,
523 bool parseDirectiveOctaValue(
StringRef IDVal);
524 bool parseDirectiveRealValue(
StringRef IDVal,
526 bool parseDirectiveFill();
527 bool parseDirectiveZero();
529 bool parseDirectiveSet(
StringRef IDVal,
bool allow_redef);
530 bool parseDirectiveOrg();
532 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
535 bool parseDirectiveFile(
SMLoc DirectiveLoc);
536 bool parseDirectiveLine();
537 bool parseDirectiveLoc();
538 bool parseDirectiveStabs();
542 bool parseDirectiveCVFile();
543 bool parseDirectiveCVFuncId();
544 bool parseDirectiveCVInlineSiteId();
545 bool parseDirectiveCVLoc();
546 bool parseDirectiveCVLinetable();
547 bool parseDirectiveCVInlineLinetable();
548 bool parseDirectiveCVDefRange();
549 bool parseDirectiveCVStringTable();
550 bool parseDirectiveCVFileChecksums();
551 bool parseDirectiveCVFileChecksumOffset();
552 bool parseDirectiveCVFPOData();
555 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
556 bool parseDirectiveCFIWindowSave();
557 bool parseDirectiveCFISections();
558 bool parseDirectiveCFIStartProc();
559 bool parseDirectiveCFIEndProc();
560 bool parseDirectiveCFIDefCfaOffset();
561 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
562 bool parseDirectiveCFIAdjustCfaOffset();
563 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
564 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
565 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
566 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
567 bool parseDirectiveCFIRememberState();
568 bool parseDirectiveCFIRestoreState();
569 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
570 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
571 bool parseDirectiveCFIEscape();
572 bool parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc);
573 bool parseDirectiveCFISignalFrame();
574 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
577 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
578 bool parseDirectiveExitMacro(
StringRef Directive);
579 bool parseDirectiveEndMacro(
StringRef Directive);
580 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
581 bool parseDirectiveMacrosOnOff(
StringRef Directive);
583 bool parseDirectiveAltmacro(
StringRef Directive);
585 bool parseDirectiveBundleAlignMode();
587 bool parseDirectiveBundleLock();
589 bool parseDirectiveBundleUnlock();
592 bool parseDirectiveSpace(
StringRef IDVal);
601 bool parseDirectiveLEB128(
bool Signed);
607 bool parseDirectiveComm(
bool IsLocal);
609 bool parseDirectiveAbort();
610 bool parseDirectiveInclude();
611 bool parseDirectiveIncbin();
614 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
616 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
618 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
620 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
622 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
623 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
624 bool parseDirectiveElse(
SMLoc DirectiveLoc);
625 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
626 bool parseEscapedString(std::string &
Data)
override;
636 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
637 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
638 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
641 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &Info,
645 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &Info);
648 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
651 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
654 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
657 bool parseDirectivePrint(
SMLoc DirectiveLoc);
660 bool parseDirectiveAddrsig();
661 bool parseDirectiveAddrsigSym();
663 void initializeDirectiveKindMap();
680 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
681 CurBuffer(CB ? CB : SM.
getMainFileID()), MacrosEnabledFlag(
true) {
710 PlatformParser->Initialize(*
this);
711 initializeDirectiveKindMap();
713 NumOfMacroInstantiations = 0;
716 AsmParser::~AsmParser() {
717 assert((HadError || ActiveMacros.empty()) &&
718 "Unexpected active macro instantiation!");
725 void AsmParser::printMacroInstantiations() {
727 for (std::vector<MacroInstantiation *>::const_reverse_iterator
728 it = ActiveMacros.rbegin(),
729 ie = ActiveMacros.rend();
732 "while in macro instantiation");
736 printPendingErrors();
738 printMacroInstantiations();
742 if(getTargetParser().getTargetOptions().MCNoWarn)
744 if (getTargetParser().getTargetOptions().MCFatalWarnings)
745 return Error(L, Msg, Range);
747 printMacroInstantiations();
754 printMacroInstantiations();
758 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
759 std::string IncludedFile;
773 bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
775 std::string IncludedFile;
786 if (!Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
787 return Error(Loc,
"expected absolute expression");
789 return Warning(Loc,
"negative count has no effect");
792 getStreamer().EmitBytes(Bytes);
796 void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
809 if (!getTok().getString().empty() && getTok().getString().front() !=
'\n' &&
827 if (ParentIncludeLoc !=
SMLoc()) {
828 jumpToLoc(ParentIncludeLoc);
836 bool AsmParser::enabledGenDwarfForAssembly() {
838 if (!getContext().getGenDwarfForAssembly())
843 if (getContext().getGenDwarfFileNumber() == 0)
844 getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
845 0,
StringRef(), getContext().getMainFileName()));
849 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
851 if (!NoInitialTextSection)
858 AsmCond StartingCondState = TheCondState;
865 if (getContext().getGenDwarfForAssembly()) {
866 MCSection *Sec = getStreamer().getCurrentSectionOnly();
868 MCSymbol *SectionStartSym = getContext().createTempSymbol();
869 getStreamer().EmitLabel(SectionStartSym);
872 bool InsertResult = getContext().addGenDwarfSection(Sec);
873 assert(InsertResult &&
".text section should not have debug info yet");
879 ParseStatementInfo Info(&AsmStrRewrites);
880 if (!parseStatement(Info,
nullptr))
891 printPendingErrors();
894 if (!getLexer().isAtStartOfStatement())
895 eatToEndOfStatement();
899 assert(!hasPendingError() &&
"unexpected error from parseStatement");
901 getTargetParser().flushPendingInstructions(getStreamer());
905 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
907 const auto &LineTables = getContext().getMCDwarfLineTables();
908 if (!LineTables.empty()) {
910 for (
const auto &
File : LineTables.begin()->second.getMCDwarfFiles()) {
911 if (
File.Name.empty() && Index != 0)
912 printError(getTok().getLoc(),
"unassigned file number: " +
914 " for .file directives");
925 for (
const auto &TableEntry : getContext().getSymbols()) {
926 MCSymbol *Sym = TableEntry.getValue();
934 printError(getTok().getLoc(),
"assembler local symbol '" +
935 Sym->
getName() +
"' not defined");
941 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
942 if (std::get<2>(LocSym)->isUndefined()) {
945 CppHashInfo = std::get<1>(LocSym);
946 printError(std::get<0>(LocSym),
"directional label undefined");
953 if (!HadError && !NoFinalize)
956 return HadError || getContext().hadError();
959 bool AsmParser::checkForValidSection() {
960 if (!ParsingInlineAsm && !getStreamer().getCurrentSectionOnly()) {
962 return Error(getTok().getLoc(),
963 "expected section directive before assembly directive");
969 void AsmParser::eatToEndOfStatement() {
978 StringRef AsmParser::parseStringToEndOfStatement() {
979 const char *Start = getTok().getLoc().getPointer();
984 const char *End = getTok().getLoc().getPointer();
988 StringRef AsmParser::parseStringToComma() {
989 const char *Start = getTok().getLoc().getPointer();
995 const char *End = getTok().getLoc().getPointer();
1004 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1005 if (parseExpression(Res))
1008 return TokError(
"expected ')' in parentheses expression");
1019 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1020 if (parseExpression(Res))
1022 EndLoc = getTok().getEndLoc();
1023 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1034 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1035 SMLoc FirstTokenLoc = getLexer().getLoc();
1037 switch (FirstTokenKind) {
1039 return TokError(
"unknown token in expression");
1045 if (parsePrimaryExpr(Res, EndLoc))
1054 if (parseIdentifier(Identifier)) {
1065 EndLoc = FirstTokenLoc;
1068 return Error(FirstTokenLoc,
"invalid token in expression");
1072 std::pair<StringRef, StringRef>
Split;
1077 SMLoc AtLoc = getLexer().getLoc();
1079 if (parseIdentifier(VName))
1080 return Error(AtLoc,
"expected symbol variant after '@'");
1082 Split = std::make_pair(Identifier, VName);
1085 Split = Identifier.
split(
'@');
1090 parseIdentifier(VName);
1093 "unexpected token in variant, expected ')'"))
1095 Split = std::make_pair(Identifier, VName);
1102 if (SymbolName.empty())
1108 if (!Split.second.empty()) {
1111 SymbolName = Split.first;
1116 "invalid variant '" + Split.second +
"'");
1120 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
1126 bool DoInline = isa<MCConstantExpr>(V);
1127 if (
auto TV = dyn_cast<MCTargetExpr>(V))
1128 DoInline = TV->inlineAssignedExpr();
1131 return Error(EndLoc,
"unexpected modifier on variable reference");
1142 return TokError(
"literal value out of range for directive");
1144 SMLoc Loc = getTok().getLoc();
1145 int64_t
IntVal = getTok().getIntVal();
1153 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1155 if (Split.first.size() != IDVal.
size()) {
1158 return TokError(
"invalid variant '" + Split.second +
"'");
1159 IDVal = Split.first;
1161 if (IDVal ==
"f" || IDVal ==
"b") {
1166 return Error(Loc,
"directional label undefined");
1167 DirLabels.
push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1194 return parseParenExpr(Res, EndLoc);
1196 if (!PlatformParser->HasBracketExpressions())
1197 return TokError(
"brackets expression not supported on this target");
1199 return parseBracketExpr(Res, EndLoc);
1202 if (parsePrimaryExpr(Res, EndLoc))
1208 if (parsePrimaryExpr(Res, EndLoc))
1214 if (parsePrimaryExpr(Res, EndLoc))
1246 return TokError(
"expected '(' after operator");
1248 if (parseExpression(Res, EndLoc))
1251 return TokError(
"expected ')'");
1253 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1258 bool AsmParser::parseExpression(
const MCExpr *&Res) {
1260 return parseExpression(Res, EndLoc);
1264 AsmParser::applyModifierToExpr(
const MCExpr *
E,
1267 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
1281 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
1282 "' (already modified)");
1299 const MCExpr *LHS = applyModifierToExpr(BE->
getLHS(), Variant);
1300 const MCExpr *RHS = applyModifierToExpr(BE->
getRHS(), Variant);
1327 bool AsmParser::isAltmacroString(
SMLoc &StrLoc,
SMLoc &EndLoc) {
1329 "Argument to the function cannot be a NULL value");
1331 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1332 (*CharPtr !=
'\0')) {
1333 if (*CharPtr ==
'!')
1337 if (*CharPtr ==
'>') {
1345 void AsmParser::altMacroString(
StringRef AltMacroStr,std::string &Res) {
1346 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1347 if (AltMacroStr[Pos] ==
'!')
1349 Res += AltMacroStr[Pos];
1363 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1366 if (getTargetParser().parsePrimaryExpr(Res, EndLoc) ||
1367 parseBinOpRHS(1, Res, EndLoc))
1377 return TokError(
"unexpected symbol modifier following '@'");
1382 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1384 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1386 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1387 "' (no symbols present)");
1397 if (Res->evaluateAsAbsolute(Value))
1403 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1405 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1408 bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1410 if (parseParenExpr(Res, EndLoc))
1413 for (; ParenDepth > 0; --ParenDepth) {
1414 if (parseBinOpRHS(1, Res, EndLoc))
1419 if (ParenDepth - 1 > 0) {
1420 EndLoc = getTok().getEndLoc();
1422 "expected ')' in parentheses expression"))
1429 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1433 if (parseExpression(Expr))
1436 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1437 return Error(StartLoc,
"expected absolute expression");
1444 bool ShouldUseLogicalShr) {
1522 bool ShouldUseLogicalShr) {
1605 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1610 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(),
Kind);
1614 if (TokPrec < Precedence)
1621 if (getTargetParser().parsePrimaryExpr(RHS, EndLoc))
1627 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(),
Dummy);
1628 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1640 bool AsmParser::parseStatement(ParseStatementInfo &Info,
1642 assert(!hasPendingError() &&
"parseStatement started with pending error");
1648 if (getTok().getString().empty() || getTok().getString().front() ==
'\r' ||
1649 getTok().getString().front() ==
'\n')
1658 int64_t LocalLabelVal = -1;
1660 return parseCppHashLineFilenameComment(IDLoc);
1663 LocalLabelVal = getTok().getIntVal();
1664 if (LocalLabelVal < 0) {
1665 if (!TheCondState.
Ignore) {
1667 return Error(IDLoc,
"unexpected token at start of statement");
1671 IDVal = getTok().getString();
1674 if (!TheCondState.
Ignore) {
1676 return Error(IDLoc,
"unexpected token at start of statement");
1694 getTargetParser().starIsStartOfStatement()) {
1698 }
else if (parseIdentifier(IDVal)) {
1699 if (!TheCondState.
Ignore) {
1701 return Error(IDLoc,
"unexpected token at start of statement");
1710 DirectiveKindMap.find(IDVal);
1711 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1713 : DirKindIt->getValue();
1724 return parseDirectiveIf(IDLoc, DirKind);
1726 return parseDirectiveIfb(IDLoc,
true);
1728 return parseDirectiveIfb(IDLoc,
false);
1730 return parseDirectiveIfc(IDLoc,
true);
1732 return parseDirectiveIfeqs(IDLoc,
true);
1734 return parseDirectiveIfc(IDLoc,
false);
1736 return parseDirectiveIfeqs(IDLoc,
false);
1738 return parseDirectiveIfdef(IDLoc,
true);
1741 return parseDirectiveIfdef(IDLoc,
false);
1743 return parseDirectiveElseIf(IDLoc);
1745 return parseDirectiveElse(IDLoc);
1747 return parseDirectiveEndIf(IDLoc);
1752 if (TheCondState.
Ignore) {
1753 eatToEndOfStatement();
1762 if (!getTargetParser().isLabel(ID))
1764 if (checkForValidSection())
1772 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1780 if (LocalLabelVal == -1) {
1781 if (ParsingInlineAsm && SI) {
1785 "We should have an internal name here.");
1786 Info.AsmRewrites->emplace_back(
AOK_Label, IDLoc, IDVal.
size(),
1788 IDVal = RewrittenLabel;
1790 Sym = getContext().getOrCreateSymbol(IDVal);
1798 StringRef CommentStr = parseStringToEndOfStatement();
1810 if (!getTargetParser().isParsingInlineAsm())
1815 if (enabledGenDwarfForAssembly())
1819 getTargetParser().onLabelParsed(Sym);
1825 if (!getTargetParser().equalIsAsmAssignment())
1830 return parseAssignment(IDVal,
true);
1837 if (areMacrosEnabled())
1838 if (
const MCAsmMacro *M = getContext().lookupMacro(IDVal)) {
1839 return handleMacroEntry(M, IDLoc);
1845 if (IDVal[0] ==
'.' && IDVal !=
".") {
1857 getTargetParser().flushPendingInstructions(getStreamer());
1859 SMLoc StartTokLoc = getTok().getLoc();
1860 bool TPDirectiveReturn = getTargetParser().ParseDirective(ID);
1862 if (hasPendingError())
1869 if (TPDirectiveReturn && StartTokLoc != getTok().getLoc())
1872 if (!TPDirectiveReturn || StartTokLoc != getTok().getLoc())
1877 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1878 ExtensionDirectiveMap.
lookup(IDVal);
1880 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1889 return parseDirectiveSet(IDVal,
true);
1891 return parseDirectiveSet(IDVal,
false);
1893 return parseDirectiveAscii(IDVal,
false);
1896 return parseDirectiveAscii(IDVal,
true);
1899 return parseDirectiveValue(IDVal, 1);
1905 return parseDirectiveValue(IDVal, 2);
1910 return parseDirectiveValue(IDVal, 4);
1913 return parseDirectiveValue(IDVal, 8);
1915 return parseDirectiveValue(
1916 IDVal, getContext().getAsmInfo()->getCodePointerSize());
1918 return parseDirectiveOctaValue(IDVal);
1927 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1928 return parseDirectiveAlign(IsPow2, 1);
1931 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1932 return parseDirectiveAlign(IsPow2, 4);
1935 return parseDirectiveAlign(
false, 1);
1937 return parseDirectiveAlign(
false, 2);
1939 return parseDirectiveAlign(
false, 4);
1941 return parseDirectiveAlign(
true, 1);
1943 return parseDirectiveAlign(
true, 2);
1945 return parseDirectiveAlign(
true, 4);
1947 return parseDirectiveOrg();
1949 return parseDirectiveFill();
1951 return parseDirectiveZero();
1953 eatToEndOfStatement();
1957 return parseDirectiveSymbolAttribute(
MCSA_Global);
1958 case DK_LAZY_REFERENCE:
1960 case DK_NO_DEAD_STRIP:
1962 case DK_SYMBOL_RESOLVER:
1964 case DK_PRIVATE_EXTERN:
1968 case DK_WEAK_DEFINITION:
1970 case DK_WEAK_REFERENCE:
1972 case DK_WEAK_DEF_CAN_BE_HIDDEN:
1976 return parseDirectiveComm(
false);
1978 return parseDirectiveComm(
true);
1980 return parseDirectiveAbort();
1982 return parseDirectiveInclude();
1984 return parseDirectiveIncbin();
1987 return TokError(
Twine(IDVal) +
1988 " not currently supported for this target");
1990 return parseDirectiveRept(IDLoc, IDVal);
1992 return parseDirectiveIrp(IDLoc);
1994 return parseDirectiveIrpc(IDLoc);
1996 return parseDirectiveEndr(IDLoc);
1997 case DK_BUNDLE_ALIGN_MODE:
1998 return parseDirectiveBundleAlignMode();
1999 case DK_BUNDLE_LOCK:
2000 return parseDirectiveBundleLock();
2001 case DK_BUNDLE_UNLOCK:
2002 return parseDirectiveBundleUnlock();
2004 return parseDirectiveLEB128(
true);
2006 return parseDirectiveLEB128(
false);
2009 return parseDirectiveSpace(IDVal);
2011 return parseDirectiveFile(IDLoc);
2013 return parseDirectiveLine();
2015 return parseDirectiveLoc();
2017 return parseDirectiveStabs();
2019 return parseDirectiveCVFile();
2021 return parseDirectiveCVFuncId();
2022 case DK_CV_INLINE_SITE_ID:
2023 return parseDirectiveCVInlineSiteId();
2025 return parseDirectiveCVLoc();
2026 case DK_CV_LINETABLE:
2027 return parseDirectiveCVLinetable();
2028 case DK_CV_INLINE_LINETABLE:
2029 return parseDirectiveCVInlineLinetable();
2030 case DK_CV_DEF_RANGE:
2031 return parseDirectiveCVDefRange();
2032 case DK_CV_STRINGTABLE:
2033 return parseDirectiveCVStringTable();
2034 case DK_CV_FILECHECKSUMS:
2035 return parseDirectiveCVFileChecksums();
2036 case DK_CV_FILECHECKSUM_OFFSET:
2037 return parseDirectiveCVFileChecksumOffset();
2038 case DK_CV_FPO_DATA:
2039 return parseDirectiveCVFPOData();
2040 case DK_CFI_SECTIONS:
2041 return parseDirectiveCFISections();
2042 case DK_CFI_STARTPROC:
2043 return parseDirectiveCFIStartProc();
2044 case DK_CFI_ENDPROC:
2045 return parseDirectiveCFIEndProc();
2046 case DK_CFI_DEF_CFA:
2047 return parseDirectiveCFIDefCfa(IDLoc);
2048 case DK_CFI_DEF_CFA_OFFSET:
2049 return parseDirectiveCFIDefCfaOffset();
2050 case DK_CFI_ADJUST_CFA_OFFSET:
2051 return parseDirectiveCFIAdjustCfaOffset();
2052 case DK_CFI_DEF_CFA_REGISTER:
2053 return parseDirectiveCFIDefCfaRegister(IDLoc);
2055 return parseDirectiveCFIOffset(IDLoc);
2056 case DK_CFI_REL_OFFSET:
2057 return parseDirectiveCFIRelOffset(IDLoc);
2058 case DK_CFI_PERSONALITY:
2059 return parseDirectiveCFIPersonalityOrLsda(
true);
2061 return parseDirectiveCFIPersonalityOrLsda(
false);
2062 case DK_CFI_REMEMBER_STATE:
2063 return parseDirectiveCFIRememberState();
2064 case DK_CFI_RESTORE_STATE:
2065 return parseDirectiveCFIRestoreState();
2066 case DK_CFI_SAME_VALUE:
2067 return parseDirectiveCFISameValue(IDLoc);
2068 case DK_CFI_RESTORE:
2069 return parseDirectiveCFIRestore(IDLoc);
2071 return parseDirectiveCFIEscape();
2072 case DK_CFI_RETURN_COLUMN:
2073 return parseDirectiveCFIReturnColumn(IDLoc);
2074 case DK_CFI_SIGNAL_FRAME:
2075 return parseDirectiveCFISignalFrame();
2076 case DK_CFI_UNDEFINED:
2077 return parseDirectiveCFIUndefined(IDLoc);
2078 case DK_CFI_REGISTER:
2079 return parseDirectiveCFIRegister(IDLoc);
2080 case DK_CFI_WINDOW_SAVE:
2081 return parseDirectiveCFIWindowSave();
2084 return parseDirectiveMacrosOnOff(IDVal);
2086 return parseDirectiveMacro(IDLoc);
2089 return parseDirectiveAltmacro(IDVal);
2091 return parseDirectiveExitMacro(IDVal);
2094 return parseDirectiveEndMacro(IDVal);
2096 return parseDirectivePurgeMacro(IDLoc);
2098 return parseDirectiveEnd(IDLoc);
2100 return parseDirectiveError(IDLoc,
false);
2102 return parseDirectiveError(IDLoc,
true);
2104 return parseDirectiveWarning(IDLoc);
2106 return parseDirectiveReloc(IDLoc);
2109 return parseDirectiveDCB(IDVal, 2);
2111 return parseDirectiveDCB(IDVal, 1);
2115 return parseDirectiveDCB(IDVal, 4);
2120 return TokError(
Twine(IDVal) +
2121 " not currently supported for this target");
2124 return parseDirectiveDS(IDVal, 2);
2126 return parseDirectiveDS(IDVal, 1);
2128 return parseDirectiveDS(IDVal, 8);
2131 return parseDirectiveDS(IDVal, 4);
2134 return parseDirectiveDS(IDVal, 12);
2136 return parseDirectivePrint(IDLoc);
2138 return parseDirectiveAddrsig();
2139 case DK_ADDRSIG_SYM:
2140 return parseDirectiveAddrsigSym();
2143 return Error(IDLoc,
"unknown directive");
2147 if (ParsingInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2148 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2149 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2152 if (ParsingInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2153 return parseDirectiveMSAlign(IDLoc, Info);
2155 if (ParsingInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2156 Info.AsmRewrites->emplace_back(
AOK_EVEN, IDLoc, 4);
2157 if (checkForValidSection())
2161 std::string OpcodeStr = IDVal.
lower();
2163 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, ID,
2164 Info.ParsedOperands);
2165 Info.ParseError = ParseHadError;
2168 if (getShowParsedOperands()) {
2171 OS <<
"parsed instruction: [";
2172 for (
unsigned i = 0; i != Info.ParsedOperands.size(); ++i) {
2175 Info.ParsedOperands[i]->print(OS);
2183 if (hasPendingError() || ParseHadError)
2188 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2189 getContext().getGenDwarfSectionSyms().count(
2190 getStreamer().getCurrentSectionOnly())) {
2192 if (ActiveMacros.empty())
2195 Line = SrcMgr.
FindLineNumber(ActiveMacros.front()->InstantiationLoc,
2196 ActiveMacros.front()->ExitBuffer);
2201 if (!CppHashInfo.Filename.empty()) {
2202 unsigned FileNumber = getStreamer().EmitDwarfFileDirective(
2204 getContext().setGenDwarfFileNumber(FileNumber);
2206 unsigned CppHashLocLineNo =
2208 Line = CppHashInfo.LineNumber - 1 + (Line - CppHashLocLineNo);
2211 getStreamer().EmitDwarfLocDirective(
2212 getContext().getGenDwarfFileNumber(), Line, 0,
2218 if (!ParseHadError) {
2220 if (getTargetParser().MatchAndEmitInstruction(
2221 IDLoc, Info.Opcode, Info.ParsedOperands, Out, ErrorInfo,
2222 getTargetParser().isParsingInlineAsm()))
2248 bool AsmParser::parseCppHashLineFilenameComment(
SMLoc L) {
2253 "Lexing Cpp line comment: Expected Integer");
2254 int64_t LineNumber = getTok().getIntVal();
2257 "Lexing Cpp line comment: Expected String");
2258 StringRef Filename = getTok().getString();
2262 Filename = Filename.
substr(1, Filename.
size() - 2);
2265 CppHashInfo.Loc = L;
2266 CppHashInfo.Filename = Filename;
2267 CppHashInfo.LineNumber = LineNumber;
2268 CppHashInfo.Buf = CurBuffer;
2275 const AsmParser *Parser =
static_cast<const AsmParser *
>(
Context);
2281 unsigned CppHashBuf =
2282 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2287 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2296 if (!Parser->CppHashInfo.LineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
2297 DiagBuf != CppHashBuf) {
2298 if (Parser->SavedDiagHandler)
2299 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2301 Diag.
print(
nullptr, OS);
2308 const std::string &Filename = Parser->CppHashInfo.Filename;
2311 int CppHashLocLineNo =
2312 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2314 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2320 if (Parser->SavedDiagHandler)
2321 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
2323 NewDiag.print(
nullptr, OS);
2331 return isalnum(static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2338 bool EnableAtPseudoVariable,
SMLoc L) {
2339 unsigned NParameters = Parameters.
size();
2340 bool HasVararg = NParameters ? Parameters.
back().
Vararg :
false;
2341 if ((!IsDarwin || NParameters != 0) && NParameters != A.
size())
2342 return Error(L,
"Wrong number of arguments");
2346 while (!Body.
empty()) {
2348 std::size_t End = Body.
size(), Pos = 0;
2349 for (; Pos != End; ++Pos) {
2351 if (IsDarwin && !NParameters) {
2353 if (Body[Pos] !=
'$' || Pos + 1 == End)
2356 char Next = Body[Pos + 1];
2357 if (Next ==
'$' || Next ==
'n' ||
2358 isdigit(static_cast<unsigned char>(Next)))
2362 if (Body[Pos] ==
'\\' && Pos + 1 != End)
2368 OS << Body.
slice(0, Pos);
2374 if (IsDarwin && !NParameters) {
2375 switch (Body[Pos + 1]) {
2389 unsigned Index = Body[Pos + 1] -
'0';
2390 if (Index >= A.
size())
2394 for (
const AsmToken &Token : A[Index])
2395 OS << Token.getString();
2401 unsigned I = Pos + 1;
2404 if (EnableAtPseudoVariable && Body[I] ==
'@' && I + 1 != End)
2410 const char *Begin = Body.
data() + Pos + 1;
2414 if (Argument ==
"@") {
2415 OS << NumOfMacroInstantiations;
2418 for (; Index < NParameters; ++
Index)
2419 if (Parameters[Index].
Name == Argument)
2422 if (Index == NParameters) {
2423 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
2426 OS <<
'\\' << Argument;
2430 bool VarargParameter = HasVararg && Index == (NParameters - 1);
2431 for (
const AsmToken &Token : A[Index])
2440 OS << Token.getIntVal();
2444 (*(Token.getString().begin()) ==
'<') &&
2447 altMacroString(Token.getStringContents(), Res);
2453 OS << Token.getString();
2455 OS << Token.getStringContents();
2457 Pos += 1 + Argument.
size();
2468 MacroInstantiation::MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
2469 size_t CondStackDepth)
2470 : InstantiationLoc(IL), ExitBuffer(EB), ExitLoc(EL),
2471 CondStackDepth(CondStackDepth) {}
2505 class AsmLexerSkipSpaceRAII {
2507 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2511 ~AsmLexerSkipSpaceRAII() {
2521 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2525 StringRef Str = parseStringToEndOfStatement();
2531 unsigned ParenLevel = 0;
2534 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2541 return TokError(
"unexpected token in macro instantiation");
2543 if (ParenLevel == 0) {
2558 MA.push_back(getTok());
2584 MA.push_back(getTok());
2588 if (ParenLevel != 0)
2589 return TokError(
"unbalanced parentheses in macro argument");
2594 bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2595 MCAsmMacroArguments &A) {
2596 const unsigned NParameters = M ? M->
Parameters.size() : 0;
2597 bool NamedParametersFound =
false;
2601 FALocs.
resize(NParameters);
2606 bool HasVararg = NParameters ? M->
Parameters.back().Vararg :
false;
2607 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2613 if (parseIdentifier(FA.
Name))
2614 return Error(IDLoc,
"invalid argument identifier for formal argument");
2617 return TokError(
"expected '=' after formal parameter identifier");
2621 NamedParametersFound =
true;
2623 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2625 if (NamedParametersFound && FA.
Name.
empty())
2626 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2631 const MCExpr *AbsoluteExp;
2635 if (parseExpression(AbsoluteExp, EndLoc))
2637 if (!AbsoluteExp->evaluateAsAbsolute(Value,
2638 getStreamer().getAssemblerPtr()))
2639 return Error(StrLoc,
"expected absolute expression");
2643 FA.
Value.push_back(newToken);
2645 isAltmacroString(StrLoc, EndLoc)) {
2648 jumpToLoc(EndLoc, CurBuffer);
2652 FA.
Value.push_back(newToken);
2653 }
else if(parseMacroArgument(FA.
Value, Vararg))
2656 unsigned PI = Parameter;
2659 for (FAI = 0; FAI < NParameters; ++FAI)
2663 if (FAI >= NParameters) {
2664 assert(M &&
"expected macro to be defined");
2665 return Error(IDLoc,
"parameter named '" + FA.
Name +
2666 "' does not exist for macro '" + M->
Name +
"'");
2671 if (!FA.
Value.empty()) {
2676 if (FALocs.
size() <= PI)
2679 FALocs[PI] = Lexer.
getLoc();
2686 bool Failure =
false;
2687 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2688 if (A[FAI].empty()) {
2690 Error(FALocs[FAI].isValid() ? FALocs[FAI] : Lexer.
getLoc(),
2691 "missing value for required parameter " 2707 return TokError(
"too many positional arguments");
2710 bool AsmParser::handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc) {
2714 if (ActiveMacros.size() == MaxNestingDepth) {
2715 std::ostringstream MaxNestingDepthError;
2716 MaxNestingDepthError <<
"macros cannot be nested more than " 2717 << MaxNestingDepth <<
" levels deep." 2718 <<
" Use -asm-macro-max-nesting-depth to increase " 2720 return TokError(MaxNestingDepthError.str());
2723 MCAsmMacroArguments A;
2724 if (parseMacroArguments(M, A))
2733 if (expandMacro(OS, Body, M->
Parameters, A,
true, getTok().getLoc()))
2738 OS <<
".endmacro\n";
2740 std::unique_ptr<MemoryBuffer> Instantiation =
2745 MacroInstantiation *
MI =
new MacroInstantiation(
2746 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
2747 ActiveMacros.push_back(MI);
2749 ++NumOfMacroInstantiations;
2759 void AsmParser::handleMacroExit() {
2761 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2765 delete ActiveMacros.back();
2766 ActiveMacros.pop_back();
2769 bool AsmParser::parseAssignment(
StringRef Name,
bool allow_redef,
2795 bool AsmParser::parseIdentifier(
StringRef &Res) {
2802 SMLoc PrefixLoc = getLexer().getLoc();
2828 Res = getTok().getIdentifier();
2839 bool AsmParser::parseDirectiveSet(
StringRef IDVal,
bool allow_redef) {
2841 if (check(parseIdentifier(Name),
"expected identifier") ||
2842 parseToken(
AsmToken::Comma) || parseAssignment(Name, allow_redef,
true))
2843 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2847 bool AsmParser::parseEscapedString(std::string &
Data) {
2852 StringRef Str = getTok().getStringContents();
2853 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
2854 if (Str[i] !=
'\\') {
2863 return TokError(
"unexpected backslash at end of string");
2866 if ((
unsigned)(Str[i] -
'0') <= 7) {
2868 unsigned Value = Str[i] -
'0';
2870 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2872 Value = Value * 8 + (Str[i] -
'0');
2874 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2876 Value = Value * 8 + (Str[i] -
'0');
2881 return TokError(
"invalid octal escape sequence (out of range)");
2883 Data += (
unsigned char)Value;
2891 return TokError(
"invalid escape sequence (unrecognized character)");
2893 case 'b': Data +=
'\b';
break;
2894 case 'f': Data +=
'\f';
break;
2895 case 'n': Data +=
'\n';
break;
2896 case 'r': Data +=
'\r';
break;
2897 case 't': Data +=
'\t';
break;
2898 case '"': Data +=
'"';
break;
2899 case '\\': Data +=
'\\';
break;
2909 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
2910 auto parseOp = [&]() ->
bool {
2912 if (checkForValidSection() || parseEscapedString(Data))
2914 getStreamer().EmitBytes(Data);
2916 getStreamer().EmitBytes(
StringRef(
"\0", 1));
2920 if (parseMany(parseOp))
2921 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2927 bool AsmParser::parseDirectiveReloc(
SMLoc DirectiveLoc) {
2929 const MCExpr *Expr =
nullptr;
2932 int64_t OffsetValue;
2935 if (parseExpression(Offset))
2938 if (check(!Offset->evaluateAsAbsolute(OffsetValue,
2939 getStreamer().getAssemblerPtr()),
2940 OffsetLoc,
"expression is not a constant value") ||
2941 check(OffsetValue < 0, OffsetLoc,
"expression is negative") ||
2953 if (parseExpression(Expr))
2958 return Error(ExprLoc,
"expression must be relocatable");
2962 "unexpected token in .reloc directive"))
2967 if (getStreamer().EmitRelocDirective(*Offset, Name, Expr, DirectiveLoc, STI))
2968 return Error(NameLoc,
"unknown relocation name");
2975 bool AsmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
2976 auto parseOp = [&]() ->
bool {
2978 SMLoc ExprLoc = getLexer().getLoc();
2979 if (checkForValidSection() || parseExpression(Value))
2982 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2983 assert(Size <= 8 &&
"Invalid size");
2984 uint64_t IntValue = MCE->getValue();
2985 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
2986 return Error(ExprLoc,
"out of range literal value");
2987 getStreamer().EmitIntValue(IntValue, Size);
2989 getStreamer().EmitValue(Value, Size, ExprLoc);
2993 if (parseMany(parseOp))
2994 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3001 return Asm.TokError(
"unknown token in expression");
3002 SMLoc ExprLoc = Asm.getTok().getLoc();
3003 APInt IntValue = Asm.getTok().getAPIntVal();
3005 if (!IntValue.
isIntN(128))
3006 return Asm.Error(ExprLoc,
"out of range literal value");
3007 if (!IntValue.
isIntN(64)) {
3020 bool AsmParser::parseDirectiveOctaValue(
StringRef IDVal) {
3021 auto parseOp = [&]() ->
bool {
3022 if (checkForValidSection())
3028 getStreamer().EmitIntValue(lo, 8);
3029 getStreamer().EmitIntValue(hi, 8);
3031 getStreamer().EmitIntValue(hi, 8);
3032 getStreamer().EmitIntValue(lo, 8);
3037 if (parseMany(parseOp))
3038 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3053 return TokError(Lexer.
getErr());
3056 return TokError(
"unexpected token in directive");
3067 return TokError(
"invalid floating point literal");
3070 return TokError(
"invalid floating point literal");
3084 bool AsmParser::parseDirectiveRealValue(
StringRef IDVal,
3086 auto parseOp = [&]() ->
bool {
3088 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3095 if (parseMany(parseOp))
3096 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3102 bool AsmParser::parseDirectiveZero() {
3105 if (checkForValidSection() || parseExpression(NumBytes))
3111 if (parseAbsoluteExpression(Val))
3116 "unexpected token in '.zero' directive"))
3118 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3125 bool AsmParser::parseDirectiveFill() {
3128 if (checkForValidSection() || parseExpression(NumValues))
3131 int64_t FillSize = 1;
3132 int64_t FillExpr = 0;
3134 SMLoc SizeLoc, ExprLoc;
3137 SizeLoc = getTok().getLoc();
3138 if (parseAbsoluteExpression(FillSize))
3141 ExprLoc = getTok().getLoc();
3142 if (parseAbsoluteExpression(FillExpr))
3147 "unexpected token in '.fill' directive"))
3151 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3155 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3160 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3162 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3169 bool AsmParser::parseDirectiveOrg() {
3172 if (checkForValidSection() || parseExpression(Offset))
3176 int64_t FillExpr = 0;
3178 if (parseAbsoluteExpression(FillExpr))
3179 return addErrorSuffix(
" in '.org' directive");
3181 return addErrorSuffix(
" in '.org' directive");
3183 getStreamer().emitValueToOffset(Offset, FillExpr, OffsetLoc);
3189 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
3190 SMLoc AlignmentLoc = getLexer().getLoc();
3193 bool HasFillExpr =
false;
3194 int64_t FillExpr = 0;
3195 int64_t MaxBytesToFill = 0;
3197 auto parseAlign = [&]() ->
bool {
3198 if (parseAbsoluteExpression(Alignment))
3206 if (parseAbsoluteExpression(FillExpr))
3210 if (parseTokenLoc(MaxBytesLoc) ||
3211 parseAbsoluteExpression(MaxBytesToFill))
3217 if (checkForValidSection())
3218 return addErrorSuffix(
" in directive");
3221 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3225 return addErrorSuffix(
" in directive");
3228 bool ReturnVal =
false;
3233 if (Alignment >= 32) {
3234 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3238 Alignment = 1ULL << Alignment;
3246 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3251 if (MaxBytesToFill < 1) {
3252 ReturnVal |=
Error(MaxBytesLoc,
3253 "alignment directive can never be satisfied in this " 3254 "many bytes, ignoring maximum bytes expression");
3258 if (MaxBytesToFill >= Alignment) {
3259 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and " 3268 assert(Section &&
"must have section to emit alignment");
3271 ValueSize == 1 && UseCodeAlign) {
3272 getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
3275 getStreamer().EmitValueToAlignment(Alignment, FillExpr, ValueSize,
3285 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
3287 int64_t FileNumber = -1;
3289 FileNumber = getTok().getIntVal();
3293 return TokError(
"negative file number");
3301 "unexpected token in '.file' directive") ||
3302 parseEscapedString(Path))
3307 std::string FilenameData;
3309 if (check(FileNumber == -1,
3310 "explicit path specified, but no file number") ||
3311 parseEscapedString(FilenameData))
3313 Filename = FilenameData;
3319 uint64_t MD5Hi, MD5Lo;
3320 bool HasMD5 =
false;
3323 bool HasSource =
false;
3324 std::string SourceString;
3329 "unexpected token in '.file' directive") ||
3330 parseIdentifier(Keyword))
3332 if (Keyword ==
"md5") {
3334 if (check(FileNumber == -1,
3335 "MD5 checksum specified, but no file number") ||
3338 }
else if (Keyword ==
"source") {
3340 if (check(FileNumber == -1,
3341 "source specified, but no file number") ||
3343 "unexpected token in '.file' directive") ||
3344 parseEscapedString(SourceString))
3347 return TokError(
"unexpected token in '.file' directive");
3359 if (FileNumber == -1)
3360 getStreamer().EmitFileDirective(Filename);
3365 for (
unsigned i = 0; i != 8; ++i) {
3366 CKMem->
Bytes[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3367 CKMem->
Bytes[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3371 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3372 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3373 Source =
StringRef(SourceBuf, SourceString.size());
3375 if (FileNumber == 0) {
3377 return Warning(DirectiveLoc,
"file 0 not supported prior to DWARF-5");
3378 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
3381 FileNumber, Directory, Filename, CKMem, Source);
3384 FileNumber = FileNumOrErr.
get();
3389 ReportedInconsistentMD5 =
true;
3390 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3399 bool AsmParser::parseDirectiveLine() {
3402 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
3408 "unexpected token in '.line' directive"))
3421 bool AsmParser::parseDirectiveLoc() {
3422 int64_t FileNumber = 0, LineNumber = 0;
3423 SMLoc Loc = getTok().getLoc();
3424 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
3426 "file number less than one in '.loc' directive") ||
3427 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
3428 "unassigned file number in '.loc' directive"))
3433 LineNumber = getTok().getIntVal();
3435 return TokError(
"line number less than zero in '.loc' directive");
3439 int64_t ColumnPos = 0;
3441 ColumnPos = getTok().getIntVal();
3443 return TokError(
"column position less than zero in '.loc' directive");
3449 int64_t Discriminator = 0;
3451 auto parseLocOp = [&]() ->
bool {
3453 SMLoc Loc = getTok().getLoc();
3454 if (parseIdentifier(Name))
3455 return TokError(
"unexpected token in '.loc' directive");
3457 if (Name ==
"basic_block")
3459 else if (Name ==
"prologue_end")
3461 else if (Name ==
"epilogue_begin")
3463 else if (Name ==
"is_stmt") {
3464 Loc = getTok().getLoc();
3466 if (parseExpression(Value))
3469 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3470 int Value = MCE->getValue();
3473 else if (Value == 1)
3476 return Error(Loc,
"is_stmt value not 0 or 1");
3478 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3480 }
else if (Name ==
"isa") {
3481 Loc = getTok().getLoc();
3483 if (parseExpression(Value))
3486 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3487 int Value = MCE->getValue();
3489 return Error(Loc,
"isa number less than zero");
3492 return Error(Loc,
"isa number not a constant value");
3494 }
else if (Name ==
"discriminator") {
3495 if (parseAbsoluteExpression(Discriminator))
3498 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3503 if (parseMany(parseLocOp,
false ))
3506 getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3514 bool AsmParser::parseDirectiveStabs() {
3515 return TokError(
"unsupported directive '.stabs'");
3520 bool AsmParser::parseDirectiveCVFile() {
3521 SMLoc FileNumberLoc = getTok().getLoc();
3523 std::string Filename;
3524 std::string Checksum;
3527 if (parseIntToken(FileNumber,
3528 "expected file number in '.cv_file' directive") ||
3529 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3531 "unexpected token in '.cv_file' directive") ||
3532 parseEscapedString(Filename))
3536 "unexpected token in '.cv_file' directive") ||
3537 parseEscapedString(Checksum) ||
3538 parseIntToken(ChecksumKind,
3539 "expected checksum kind in '.cv_file' directive") ||
3541 "unexpected token in '.cv_file' directive"))
3546 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3547 memcpy(CKMem, Checksum.data(), Checksum.size());
3551 if (!getStreamer().EmitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
3552 static_cast<uint8_t>(ChecksumKind)))
3553 return Error(FileNumberLoc,
"file number already allocated");
3558 bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3561 return parseTokenLoc(Loc) ||
3562 parseIntToken(FunctionId,
"expected function id in '" + DirectiveName +
3564 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3565 "expected function id within range [0, UINT_MAX)");
3568 bool AsmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
3570 return parseTokenLoc(Loc) ||
3571 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
3573 check(FileNumber < 1, Loc,
"file number less than one in '" +
3574 DirectiveName +
"' directive") ||
3575 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3576 "unassigned file number in '" + DirectiveName +
"' directive");
3583 bool AsmParser::parseDirectiveCVFuncId() {
3584 SMLoc FunctionIdLoc = getTok().getLoc();
3587 if (parseCVFunctionId(FunctionId,
".cv_func_id") ||
3589 "unexpected token in '.cv_func_id' directive"))
3592 if (!getStreamer().EmitCVFuncIdDirective(FunctionId))
3593 return Error(FunctionIdLoc,
"function id already allocated");
3606 bool AsmParser::parseDirectiveCVInlineSiteId() {
3607 SMLoc FunctionIdLoc = getTok().getLoc();
3615 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3620 getTok().getIdentifier() !=
"within"),
3621 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3626 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3631 getTok().getIdentifier() !=
"inlined_at"),
3632 "expected 'inlined_at' identifier in '.cv_inline_site_id' " 3638 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3639 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3644 IACol = getTok().getIntVal();
3649 "unexpected token in '.cv_inline_site_id' directive"))
3652 if (!getStreamer().EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3653 IALine, IACol, FunctionIdLoc))
3654 return Error(FunctionIdLoc,
"function id already allocated");
3666 bool AsmParser::parseDirectiveCVLoc() {
3667 SMLoc DirectiveLoc = getTok().getLoc();
3668 int64_t FunctionId, FileNumber;
3669 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3670 parseCVFileId(FileNumber,
".cv_loc"))
3673 int64_t LineNumber = 0;
3675 LineNumber = getTok().getIntVal();
3677 return TokError(
"line number less than zero in '.cv_loc' directive");
3681 int64_t ColumnPos = 0;
3683 ColumnPos = getTok().getIntVal();
3685 return TokError(
"column position less than zero in '.cv_loc' directive");
3689 bool PrologueEnd =
false;
3690 uint64_t IsStmt = 0;
3692 auto parseOp = [&]() ->
bool {
3694 SMLoc Loc = getTok().getLoc();
3695 if (parseIdentifier(Name))
3696 return TokError(
"unexpected token in '.cv_loc' directive");
3697 if (Name ==
"prologue_end")
3699 else if (Name ==
"is_stmt") {
3700 Loc = getTok().getLoc();
3702 if (parseExpression(Value))
3706 if (
const auto *MCE = dyn_cast<MCConstantExpr>(Value))
3707 IsStmt = MCE->getValue();
3710 return Error(Loc,
"is_stmt value not 0 or 1");
3712 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3717 if (parseMany(parseOp,
false ))
3720 getStreamer().EmitCVLocDirective(FunctionId, FileNumber, LineNumber,
3721 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
3728 bool AsmParser::parseDirectiveCVLinetable() {
3731 SMLoc Loc = getTok().getLoc();
3732 if (parseCVFunctionId(FunctionId,
".cv_linetable") ||
3734 "unexpected token in '.cv_linetable' directive") ||
3735 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3736 "expected identifier in directive") ||
3738 "unexpected token in '.cv_linetable' directive") ||
3739 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3740 "expected identifier in directive"))
3743 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3744 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3746 getStreamer().EmitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3752 bool AsmParser::parseDirectiveCVInlineLinetable() {
3753 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3755 SMLoc Loc = getTok().getLoc();
3756 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3757 parseTokenLoc(Loc) ||
3760 "expected SourceField in '.cv_inline_linetable' directive") ||
3761 check(SourceFileId <= 0, Loc,
3762 "File id less than zero in '.cv_inline_linetable' directive") ||
3763 parseTokenLoc(Loc) ||
3766 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
3767 check(SourceLineNum < 0, Loc,
3768 "Line number less than zero in '.cv_inline_linetable' directive") ||
3769 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3770 "expected identifier in directive") ||
3771 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3772 "expected identifier in directive"))
3778 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3779 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3780 getStreamer().EmitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3781 SourceLineNum, FnStartSym,
3788 bool AsmParser::parseDirectiveCVDefRange() {
3790 std::vector<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
3792 Loc = getLexer().getLoc();
3794 if (parseIdentifier(GapStartName))
3795 return Error(Loc,
"expected identifier in directive");
3796 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
3798 Loc = getLexer().getLoc();
3800 if (parseIdentifier(GapEndName))
3801 return Error(Loc,
"expected identifier in directive");
3802 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
3804 Ranges.push_back({GapStartSym, GapEndSym});
3807 std::string FixedSizePortion;
3809 parseEscapedString(FixedSizePortion))
3812 getStreamer().EmitCVDefRangeDirective(Ranges, FixedSizePortion);
3818 bool AsmParser::parseDirectiveCVStringTable() {
3819 getStreamer().EmitCVStringTableDirective();
3825 bool AsmParser::parseDirectiveCVFileChecksums() {
3826 getStreamer().EmitCVFileChecksumsDirective();
3832 bool AsmParser::parseDirectiveCVFileChecksumOffset() {
3834 if (parseIntToken(FileNo,
"expected identifier in directive"))
3838 getStreamer().EmitCVFileChecksumOffsetDirective(FileNo);
3844 bool AsmParser::parseDirectiveCVFPOData() {
3845 SMLoc DirLoc = getLexer().getLoc();
3847 if (parseIdentifier(ProcName))
3848 return TokError(
"expected symbol name");
3849 if (parseEOL(
"unexpected tokens"))
3850 return addErrorSuffix(
" in '.cv_fpo_data' directive");
3851 MCSymbol *ProcSym = getContext().getOrCreateSymbol(ProcName);
3852 getStreamer().EmitCVFPOData(ProcSym, DirLoc);
3858 bool AsmParser::parseDirectiveCFISections() {
3863 if (parseIdentifier(Name))
3864 return TokError(
"Expected an identifier");
3866 if (Name ==
".eh_frame")
3868 else if (Name ==
".debug_frame")
3874 if (parseIdentifier(Name))
3875 return TokError(
"Expected an identifier");
3877 if (Name ==
".eh_frame")
3879 else if (Name ==
".debug_frame")
3883 getStreamer().EmitCFISections(EH, Debug);
3889 bool AsmParser::parseDirectiveCFIStartProc() {
3892 if (check(parseIdentifier(Simple) || Simple !=
"simple",
3893 "unexpected token") ||
3895 return addErrorSuffix(
" in '.cfi_startproc' directive");
3898 getStreamer().EmitCFIStartProc(!Simple.
empty());
3904 bool AsmParser::parseDirectiveCFIEndProc() {
3905 getStreamer().EmitCFIEndProc();
3910 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
3911 SMLoc DirectiveLoc) {
3915 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
3917 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
3919 return parseAbsoluteExpression(Register);
3926 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
3927 int64_t Register = 0,
Offset = 0;
3928 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3930 parseAbsoluteExpression(
Offset))
3933 getStreamer().EmitCFIDefCfa(Register,
Offset);
3939 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
3941 if (parseAbsoluteExpression(Offset))
3944 getStreamer().EmitCFIDefCfaOffset(Offset);
3950 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
3951 int64_t Register1 = 0, Register2 = 0;
3952 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) ||
3954 parseRegisterOrRegisterNumber(Register2, DirectiveLoc))
3957 getStreamer().EmitCFIRegister(Register1, Register2);
3963 bool AsmParser::parseDirectiveCFIWindowSave() {
3964 getStreamer().EmitCFIWindowSave();
3970 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
3971 int64_t Adjustment = 0;
3972 if (parseAbsoluteExpression(Adjustment))
3975 getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
3981 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
3982 int64_t Register = 0;
3983 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3986 getStreamer().EmitCFIDefCfaRegister(Register);
3992 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
3993 int64_t Register = 0;
3996 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3998 parseAbsoluteExpression(Offset))
4001 getStreamer().EmitCFIOffset(Register, Offset);
4007 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
4008 int64_t Register = 0,
Offset = 0;
4010 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
4012 parseAbsoluteExpression(
Offset))
4015 getStreamer().EmitCFIRelOffset(Register,
Offset);
4020 if (Encoding & ~0xff)
4026 const unsigned Format = Encoding & 0xf;
4033 const unsigned Application = Encoding & 0x70;
4045 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4046 int64_t Encoding = 0;
4047 if (parseAbsoluteExpression(Encoding))
4055 check(parseIdentifier(Name),
"expected identifier in directive"))
4058 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4061 getStreamer().EmitCFIPersonality(Sym, Encoding);
4063 getStreamer().EmitCFILsda(Sym, Encoding);
4069 bool AsmParser::parseDirectiveCFIRememberState() {
4070 getStreamer().EmitCFIRememberState();
4076 bool AsmParser::parseDirectiveCFIRestoreState() {
4077 getStreamer().EmitCFIRestoreState();
4083 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
4084 int64_t Register = 0;
4086 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4089 getStreamer().EmitCFISameValue(Register);
4095 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
4096 int64_t Register = 0;
4097 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4100 getStreamer().EmitCFIRestore(Register);
4106 bool AsmParser::parseDirectiveCFIEscape() {
4109 if (parseAbsoluteExpression(CurrValue))
4112 Values.push_back((uint8_t)CurrValue);
4117 if (parseAbsoluteExpression(CurrValue))
4120 Values.push_back((uint8_t)CurrValue);
4123 getStreamer().EmitCFIEscape(Values);
4129 bool AsmParser::parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc) {
4130 int64_t Register = 0;
4131 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4133 getStreamer().EmitCFIReturnColumn(Register);
4139 bool AsmParser::parseDirectiveCFISignalFrame() {
4141 "unexpected token in '.cfi_signal_frame'"))
4144 getStreamer().EmitCFISignalFrame();
4150 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
4151 int64_t Register = 0;
4153 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
4156 getStreamer().EmitCFIUndefined(Register);
4163 bool AsmParser::parseDirectiveAltmacro(
StringRef Directive) {
4165 return TokError(
"unexpected token in '" + Directive +
"' directive");
4166 if (Directive ==
".altmacro")
4167 getLexer().SetAltMacroMode(
true);
4169 getLexer().SetAltMacroMode(
false);
4176 bool AsmParser::parseDirectiveMacrosOnOff(
StringRef Directive) {
4178 "unexpected token in '" + Directive +
"' directive"))
4181 setMacrosEnabled(Directive ==
".macros_on");
4187 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
4189 if (parseIdentifier(Name))
4190 return TokError(
"expected identifier in '.macro' directive");
4198 if (!Parameters.empty() && Parameters.back().Vararg)
4200 "Vararg parameter '" + Parameters.back().Name +
4201 "' should be last one in the list of parameters.");
4204 if (parseIdentifier(Parameter.
Name))
4205 return TokError(
"expected identifier in '.macro' directive");
4209 if (CurrParam.Name.equals(Parameter.
Name))
4210 return TokError(
"macro '" + Name +
"' has multiple parameters" 4211 " named '" + Parameter.
Name +
"'");
4219 QualLoc = Lexer.
getLoc();
4220 if (parseIdentifier(Qualifier))
4221 return Error(QualLoc,
"missing parameter qualifier for " 4222 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4224 if (Qualifier ==
"req")
4226 else if (Qualifier ==
"vararg")
4229 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier " 4230 "for '" + Parameter.
Name +
"' in macro '" + Name +
"'");
4238 ParamLoc = Lexer.
getLoc();
4239 if (parseMacroArgument(Parameter.
Value,
false ))
4243 Warning(ParamLoc,
"pointless default value for required parameter " 4244 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4247 Parameters.push_back(std::move(Parameter));
4257 AsmToken EndToken, StartToken = getTok();
4258 unsigned MacroDepth = 0;
4268 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4272 if (getTok().getIdentifier() ==
".endm" ||
4273 getTok().getIdentifier() ==
".endmacro") {
4274 if (MacroDepth == 0) {
4275 EndToken = getTok();
4278 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4285 }
else if (getTok().getIdentifier() ==
".macro") {
4293 eatToEndOfStatement();
4296 if (getContext().lookupMacro(Name)) {
4297 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4303 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4307 getContext().defineMacro(Name, std::move(Macro));
4325 void AsmParser::checkForBadMacro(
SMLoc DirectiveLoc,
StringRef Name,
4330 unsigned NParameters = Parameters.
size();
4331 if (NParameters == 0)
4334 bool NamedParametersFound =
false;
4335 bool PositionalParametersFound =
false;
4340 while (!Body.
empty()) {
4342 std::size_t End = Body.
size(), Pos = 0;
4343 for (; Pos != End; ++Pos) {
4346 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4350 if (Body[Pos] !=
'$' || Pos + 1 == End)
4352 char Next = Body[Pos + 1];
4353 if (Next ==
'$' || Next ==
'n' ||
4354 isdigit(static_cast<unsigned char>(Next)))
4362 if (Body[Pos] ==
'$') {
4363 switch (Body[Pos + 1]) {
4370 PositionalParametersFound =
true;
4375 PositionalParametersFound =
true;
4381 unsigned I = Pos + 1;
4385 const char *Begin = Body.
data() + Pos + 1;
4388 for (; Index < NParameters; ++
Index)
4389 if (Parameters[Index].Name == Argument)
4392 if (Index == NParameters) {
4393 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4399 NamedParametersFound =
true;
4400 Pos += 1 + Argument.
size();
4407 if (!NamedParametersFound && PositionalParametersFound)
4408 Warning(DirectiveLoc,
"macro defined with named parameters which are not " 4409 "used in macro body, possible positional parameter " 4410 "found in body which will have no effect");
4415 bool AsmParser::parseDirectiveExitMacro(
StringRef Directive) {
4417 "unexpected token in '" + Directive +
"' directive"))
4420 if (!isInsideMacroInstantiation())
4421 return TokError(
"unexpected '" + Directive +
"' in file, " 4422 "no current macro definition");
4425 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4426 TheCondState = TheCondStack.back();
4427 TheCondStack.pop_back();
4437 bool AsmParser::parseDirectiveEndMacro(
StringRef Directive) {
4439 return TokError(
"unexpected token in '" + Directive +
"' directive");
4443 if (isInsideMacroInstantiation()) {
4450 return TokError(
"unexpected '" + Directive +
"' in file, " 4451 "no current macro definition");
4456 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
4459 if (parseTokenLoc(Loc) ||
4460 check(parseIdentifier(Name), Loc,
4461 "expected identifier in '.purgem' directive") ||
4463 "unexpected token in '.purgem' directive"))
4466 if (!getContext().lookupMacro(Name))
4467 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4469 getContext().undefineMacro(Name);
4471 <<
"Un-defining macro: " << Name <<
"\n");
4477 bool AsmParser::parseDirectiveBundleAlignMode() {
4480 SMLoc ExprLoc = getLexer().getLoc();
4481 int64_t AlignSizePow2;
4482 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4484 "in '.bundle_align_mode' " 4486 check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
4487 "invalid bundle alignment size (expected between 0 and 30)"))
4492 getStreamer().EmitBundleAlignMode(static_cast<unsigned>(AlignSizePow2));
4498 bool AsmParser::parseDirectiveBundleLock() {
4499 if (checkForValidSection())
4501 bool AlignToEnd =
false;
4504 SMLoc Loc = getTok().getLoc();
4505 const char *kInvalidOptionError =
4506 "invalid option for '.bundle_lock' directive";
4509 if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
4510 check(Option !=
"align_to_end", Loc, kInvalidOptionError) ||
4512 "unexpected token after '.bundle_lock' directive option"))
4517 getStreamer().EmitBundleLock(AlignToEnd);
4523 bool AsmParser::parseDirectiveBundleUnlock() {
4524 if (checkForValidSection() ||
4526 "unexpected token in '.bundle_unlock' directive"))
4529 getStreamer().EmitBundleUnlock();
4535 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
4538 if (checkForValidSection() || parseExpression(NumBytes))
4541 int64_t FillExpr = 0;
4543 if (parseAbsoluteExpression(FillExpr))
4544 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4546 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4549 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4556 bool AsmParser::parseDirectiveDCB(
StringRef IDVal,
unsigned Size) {
4559 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4562 if (NumValues < 0) {
4563 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4568 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4572 SMLoc ExprLoc = getLexer().getLoc();
4573 if (parseExpression(Value))
4577 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
4578 assert(Size <= 8 &&
"Invalid size");
4579 uint64_t IntValue = MCE->getValue();
4580 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
4581 return Error(ExprLoc,
"literal value out of range for directive");
4582 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4583 getStreamer().EmitIntValue(IntValue, Size);
4585 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4586 getStreamer().EmitValue(Value, Size, ExprLoc);
4590 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4601 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4604 if (NumValues < 0) {
4605 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4610 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4614 if (parseRealValue(Semantics, AsInt))
4618 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4621 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4630 bool AsmParser::parseDirectiveDS(
StringRef IDVal,
unsigned Size) {
4633 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4636 if (NumValues < 0) {
4637 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4642 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4645 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4646 getStreamer().emitFill(Size, 0);
4653 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4654 if (checkForValidSection())
4657 auto parseOp = [&]() ->
bool {
4659 if (parseExpression(Value))
4662 getStreamer().EmitSLEB128Value(Value);
4664 getStreamer().EmitULEB128Value(Value);
4668 if (parseMany(parseOp))
4669 return addErrorSuffix(
" in directive");
4676 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4677 auto parseOp = [&]() ->
bool {
4679 SMLoc Loc = getTok().getLoc();
4680 if (parseIdentifier(Name))
4681 return Error(Loc,
"expected identifier");
4682 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4686 return Error(Loc,
"non-local symbol required");
4688 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
4689 return Error(Loc,
"unable to emit symbol attribute");
4693 if (parseMany(parseOp))
4694 return addErrorSuffix(
" in directive");
4700 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4701 if (checkForValidSection())
4704 SMLoc IDLoc = getLexer().getLoc();
4706 if (parseIdentifier(Name))
4707 return TokError(
"expected identifier in directive");
4710 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4713 return TokError(
"unexpected token in directive");
4717 SMLoc SizeLoc = getLexer().getLoc();
4718 if (parseAbsoluteExpression(Size))
4721 int64_t Pow2Alignment = 0;
4722 SMLoc Pow2AlignmentLoc;
4725 Pow2AlignmentLoc = getLexer().getLoc();
4726 if (parseAbsoluteExpression(Pow2Alignment))
4731 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4737 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4738 Pow2Alignment =
Log2_64(Pow2Alignment);
4743 "unexpected token in '.comm' or '.lcomm' directive"))
4749 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't " 4750 "be less than zero");
4755 if (Pow2Alignment < 0)
4756 return Error(Pow2AlignmentLoc,
"invalid '.comm' or '.lcomm' directive " 4757 "alignment, can't be less than zero");
4761 return Error(IDLoc,
"invalid symbol redefinition");
4765 getStreamer().EmitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4769 getStreamer().EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4775 bool AsmParser::parseDirectiveAbort() {
4777 SMLoc Loc = getLexer().getLoc();
4779 StringRef Str = parseStringToEndOfStatement();
4781 "unexpected token in '.abort' directive"))
4785 return Error(Loc,
".abort detected. Assembly stopping.");
4787 return Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
4795 bool AsmParser::parseDirectiveInclude() {
4797 std::string Filename;
4798 SMLoc IncludeLoc = getTok().getLoc();
4801 "expected string in '.include' directive") ||
4802 parseEscapedString(Filename) ||
4804 "unexpected token in '.include' directive") ||
4807 check(enterIncludeFile(Filename), IncludeLoc,
4808 "Could not find include file '" + Filename +
"'"))
4816 bool AsmParser::parseDirectiveIncbin() {
4818 std::string Filename;
4819 SMLoc IncbinLoc = getTok().getLoc();
4821 "expected string in '.incbin' directive") ||
4822 parseEscapedString(Filename))
4826 const MCExpr *Count =
nullptr;
4827 SMLoc SkipLoc, CountLoc;
4832 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
4836 CountLoc = getTok().getLoc();
4837 if (parseExpression(Count))
4843 "unexpected token in '.incbin' directive"))
4846 if (check(Skip < 0, SkipLoc,
"skip is negative"))
4850 if (processIncbinFile(Filename, Skip, Count, CountLoc))
4851 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
4857 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
4858 TheCondStack.push_back(TheCondState);
4860 if (TheCondState.
Ignore) {
4861 eatToEndOfStatement();
4864 if (parseAbsoluteExpression(ExprValue) ||
4866 "unexpected token in '.if' directive"))
4876 ExprValue = ExprValue == 0;
4879 ExprValue = ExprValue >= 0;
4882 ExprValue = ExprValue > 0;
4885 ExprValue = ExprValue <= 0;
4888 ExprValue = ExprValue < 0;
4892 TheCondState.
CondMet = ExprValue;
4901 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
4902 TheCondStack.push_back(TheCondState);
4905 if (TheCondState.
Ignore) {
4906 eatToEndOfStatement();
4908 StringRef Str = parseStringToEndOfStatement();
4911 "unexpected token in '.ifb' directive"))
4924 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4925 TheCondStack.push_back(TheCondState);
4928 if (TheCondState.
Ignore) {
4929 eatToEndOfStatement();
4933 if (parseToken(
AsmToken::Comma,
"unexpected token in '.ifc' directive"))
4936 StringRef Str2 = parseStringToEndOfStatement();
4939 "unexpected token in '.ifc' directive"))
4951 bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4954 return TokError(
"expected string parameter for '.ifeqs' directive");
4955 return TokError(
"expected string parameter for '.ifnes' directive");
4958 StringRef String1 = getTok().getStringContents();
4964 "expected comma after first string for '.ifeqs' directive");
4965 return TokError(
"expected comma after first string for '.ifnes' directive");
4972 return TokError(
"expected string parameter for '.ifeqs' directive");
4973 return TokError(
"expected string parameter for '.ifnes' directive");
4976 StringRef String2 = getTok().getStringContents();
4979 TheCondStack.push_back(TheCondState);
4981 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
4989 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
4991 TheCondStack.push_back(TheCondState);
4994 if (TheCondState.
Ignore) {
4995 eatToEndOfStatement();
4997 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5001 MCSymbol *Sym = getContext().lookupSymbol(Name);
5015 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
5018 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an" 5019 " .if or an .elseif");
5022 bool LastIgnoreState =
false;
5023 if (!TheCondStack.empty())
5024 LastIgnoreState = TheCondStack.back().Ignore;
5025 if (LastIgnoreState || TheCondState.
CondMet) {
5026 TheCondState.
Ignore =
true;
5027 eatToEndOfStatement();
5030 if (parseAbsoluteExpression(ExprValue))
5034 "unexpected token in '.elseif' directive"))
5037 TheCondState.
CondMet = ExprValue;
5046 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
5048 "unexpected token in '.else' directive"))
5053 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow " 5054 " an .if or an .elseif");
5056 bool LastIgnoreState =
false;
5057 if (!TheCondStack.empty())
5058 LastIgnoreState = TheCondStack.back().Ignore;
5059 if (LastIgnoreState || TheCondState.
CondMet)
5060 TheCondState.
Ignore =
true;
5062 TheCondState.
Ignore =
false;
5069 bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
5071 "unexpected token in '.end' directive"))
5083 bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
5084 if (!TheCondStack.empty()) {
5085 if (TheCondStack.back().Ignore) {
5086 eatToEndOfStatement();
5092 return Error(L,
".err encountered");
5094 StringRef Message =
".error directive invoked in source file";
5097 return TokError(
".error argument must be a string");
5099 Message = getTok().getStringContents();
5103 return Error(L, Message);
5108 bool AsmParser::parseDirectiveWarning(
SMLoc L) {
5109 if (!TheCondStack.empty()) {
5110 if (TheCondStack.back().Ignore) {
5111 eatToEndOfStatement();
5116 StringRef Message =
".warning directive invoked in source file";
5120 return TokError(
".warning argument must be a string");
5122 Message = getTok().getStringContents();
5125 "expected end of statement in '.warning' directive"))
5134 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
5136 "unexpected token in '.endif' directive"))
5140 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow " 5142 if (!TheCondStack.empty()) {
5143 TheCondState = TheCondStack.back();
5144 TheCondStack.pop_back();
5150 void AsmParser::initializeDirectiveKindMap() {
5151 DirectiveKindMap[
".set"] = DK_SET;
5152 DirectiveKindMap[
".equ"] = DK_EQU;
5153 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5154 DirectiveKindMap[
".ascii"] = DK_ASCII;
5155 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5156 DirectiveKindMap[
".string"] = DK_STRING;
5157 DirectiveKindMap[
".byte"] = DK_BYTE;
5158 DirectiveKindMap[
".short"] = DK_SHORT;
5159 DirectiveKindMap[
".value"] = DK_VALUE;
5160 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5161 DirectiveKindMap[
".long"] = DK_LONG;
5162 DirectiveKindMap[
".int"] = DK_INT;
5163 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5164 DirectiveKindMap[
".quad"] = DK_QUAD;
5165 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5166 DirectiveKindMap[
".octa"] = DK_OCTA;
5167 DirectiveKindMap[
".single"] = DK_SINGLE;
5168 DirectiveKindMap[
".float"] = DK_FLOAT;
5169 DirectiveKindMap[
".double"] = DK_DOUBLE;
5170 DirectiveKindMap[
".align"] = DK_ALIGN;
5171 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5172 DirectiveKindMap[
".balign"] = DK_BALIGN;
5173 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5174 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5175 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5176 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5177 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5178 DirectiveKindMap[
".org"] = DK_ORG;
5179 DirectiveKindMap[
".fill"] = DK_FILL;
5180 DirectiveKindMap[
".zero"] = DK_ZERO;
5181 DirectiveKindMap[
".extern"] = DK_EXTERN;
5182 DirectiveKindMap[
".globl"] = DK_GLOBL;
5183 DirectiveKindMap[
".global"] = DK_GLOBAL;
5184 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5185 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5186 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5187 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5188 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5189 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5190 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5191 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5192 DirectiveKindMap[
".comm"] = DK_COMM;
5193 DirectiveKindMap[
".common"] = DK_COMMON;
5194 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5195 DirectiveKindMap[
".abort"] = DK_ABORT;
5196 DirectiveKindMap[
".include"] = DK_INCLUDE;
5197 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5198 DirectiveKindMap[
".code16"] = DK_CODE16;
5199 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5200 DirectiveKindMap[
".rept"] = DK_REPT;
5201 DirectiveKindMap[
".rep"] = DK_REPT;
5202 DirectiveKindMap[
".irp"] = DK_IRP;
5203 DirectiveKindMap[
".irpc"] = DK_IRPC;
5204 DirectiveKindMap[
".endr"] = DK_ENDR;
5205 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5206 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5207 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5208 DirectiveKindMap[
".if"] = DK_IF;
5209 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5210 DirectiveKindMap[
".ifge"] = DK_IFGE;
5211 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5212 DirectiveKindMap[
".ifle"] = DK_IFLE;
5213 DirectiveKindMap[
".iflt"] = DK_IFLT;
5214 DirectiveKindMap[
".ifne"] = DK_IFNE;
5215 DirectiveKindMap[
".ifb"] = DK_IFB;
5216 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5217 DirectiveKindMap[
".ifc"] = DK_IFC;
5218 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5219 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5220 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5221 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5222 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5223 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5224 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5225 DirectiveKindMap[
".else"] = DK_ELSE;
5226 DirectiveKindMap[
".end"] = DK_END;
5227 DirectiveKindMap[
".endif"] = DK_ENDIF;
5228 DirectiveKindMap[
".skip"] = DK_SKIP;
5229 DirectiveKindMap[
".space"] = DK_SPACE;
5230 DirectiveKindMap[
".file"] = DK_FILE;
5231 DirectiveKindMap[
".line"] = DK_LINE;
5232 DirectiveKindMap[
".loc"] = DK_LOC;
5233 DirectiveKindMap[
".stabs"] = DK_STABS;
5234 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5235 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5236 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5237 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5238 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5239 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5240 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5241 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5242 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5243 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5244 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5245 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5246 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5247 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5248 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5249 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5250 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5251 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5252 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5253 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5254 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5255 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5256 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5257 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5258 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5259 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5260 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5261 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5262 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5263 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5264 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5265 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5266 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5267 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5268 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5269 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5270 DirectiveKindMap[
".macro"] = DK_MACRO;
5271 DirectiveKindMap[
".exitm"] = DK_EXITM;
5272 DirectiveKindMap[
".endm"] = DK_ENDM;
5273 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5274 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5275 DirectiveKindMap[
".err"] = DK_ERR;
5276 DirectiveKindMap[
".error"] = DK_ERROR;
5277 DirectiveKindMap[
".warning"] = DK_WARNING;
5278 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5279 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5280 DirectiveKindMap[
".reloc"] = DK_RELOC;
5281 DirectiveKindMap[
".dc"] = DK_DC;
5282 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5283 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5284 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5285 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5286 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5287 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5288 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5289 DirectiveKindMap[
".dcb"] = DK_DCB;
5290 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5291 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5292 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5293 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5294 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5295 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5296 DirectiveKindMap[
".ds"] = DK_DS;
5297 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5298 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5299 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5300 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5301 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5302 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5303 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5304 DirectiveKindMap[
".print"] = DK_PRINT;
5305 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5306 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5310 AsmToken EndToken, StartToken = getTok();
5312 unsigned NestLevel = 0;
5316 printError(DirectiveLoc,
"no matching '.endr' in definition");
5321 (getTok().getIdentifier() ==
".rep" ||
5322 getTok().getIdentifier() ==
".rept" ||
5323 getTok().getIdentifier() ==
".irp" ||
5324 getTok().getIdentifier() ==
".irpc")) {
5330 if (NestLevel == 0) {
5331 EndToken = getTok();
5334 printError(getTok().getLoc(),
5335 "unexpected token in '.endr' directive");
5344 eatToEndOfStatement();
5353 return &MacroLikeBodies.back();
5356 void AsmParser::instantiateMacroLikeBody(
MCAsmMacro *M,
SMLoc DirectiveLoc,
5360 std::unique_ptr<MemoryBuffer> Instantiation =
5365 MacroInstantiation *
MI =
new MacroInstantiation(
5366 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
5367 ActiveMacros.push_back(MI);
5377 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
5379 SMLoc CountLoc = getTok().getLoc();
5380 if (parseExpression(CountExpr))
5384 if (!CountExpr->evaluateAsAbsolute(Count, getStreamer().getAssemblerPtr())) {
5385 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5388 if (check(Count < 0, CountLoc,
"Count is negative") ||
5390 "unexpected token in '" + Dir +
"' directive"))
5394 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5404 if (expandMacro(OS, M->
Body,
None,
None,
false, getTok().getLoc()))
5407 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5414 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
5416 MCAsmMacroArguments A;
5417 if (check(parseIdentifier(Parameter.
Name),
5418 "expected identifier in '.irp' directive") ||
5420 parseMacroArguments(
nullptr, A) ||
5425 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5434 for (
const MCAsmMacroArgument &
Arg : A) {
5437 if (expandMacro(OS, M->
Body, Parameter,
Arg,
true, getTok().getLoc()))
5441 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5448 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
5450 MCAsmMacroArguments A;
5452 if (check(parseIdentifier(Parameter.
Name),
5453 "expected identifier in '.irpc' directive") ||
5455 parseMacroArguments(
nullptr, A))
5458 if (A.size() != 1 || A.front().size() != 1)
5459 return TokError(
"unexpected token in '.irpc' directive");
5466 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5476 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5477 MCAsmMacroArgument
Arg;
5482 if (expandMacro(OS, M->
Body, Parameter, Arg,
true, getTok().getLoc()))
5486 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5491 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
5492 if (ActiveMacros.empty())
5493 return TokError(
"unmatched '.endr' directive");
5503 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
5506 SMLoc ExprLoc = getLexer().getLoc();
5507 if (parseExpression(Value))
5511 return Error(ExprLoc,
"unexpected expression in _emit");
5512 uint64_t IntValue = MCE->
getValue();
5514 return Error(ExprLoc,
"literal value out of range for directive");
5516 Info.AsmRewrites->emplace_back(
AOK_Emit, IDLoc, Len);
5520 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
5522 SMLoc ExprLoc = getLexer().getLoc();
5523 if (parseExpression(Value))
5527 return Error(ExprLoc,
"unexpected expression in align");
5528 uint64_t IntValue = MCE->
getValue();
5530 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5536 bool AsmParser::parseDirectivePrint(
SMLoc DirectiveLoc) {
5540 return Error(DirectiveLoc,
"expected double quoted string after .print");
5547 bool AsmParser::parseDirectiveAddrsig() {
5548 getStreamer().EmitAddrsig();
5552 bool AsmParser::parseDirectiveAddrsigSym() {
5554 if (check(parseIdentifier(Name),
5555 "expected identifier in '.addrsig_sym' directive"))
5557 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
5558 getStreamer().EmitAddrsigSym(Sym);
5585 bool AsmParser::parseMSInlineAsm(
5586 void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs,
5587 unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5605 unsigned InputIdx = 0;
5606 unsigned OutputIdx = 0;
5609 if (parseCurlyBlockScope(AsmStrRewrites))
5612 ParseStatementInfo Info(&AsmStrRewrites);
5613 bool StatementErr = parseStatement(Info, &SI);
5615 if (StatementErr || Info.ParseError) {
5617 printPendingErrors();
5622 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5624 if (Info.Opcode == ~0U)
5630 for (
unsigned i = 1, e = Info.ParsedOperands.size(); i != e; ++i) {
5634 if (Operand.
isImm())
5639 !getTargetParser().OmitRegisterFromClobberLists(Operand.
getReg())) {
5649 if (SymName.
empty())
5656 bool isOutput = (i == 1) && Desc.
mayStore();
5675 ClobberRegs.
insert(ClobberRegs.
end(), ImpDefs.begin(), ImpDefs.end());
5679 NumOutputs = OutputDecls.
size();
5680 NumInputs = InputDecls.
size();
5684 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
5686 Clobbers.
assign(ClobberRegs.
size(), std::string());
5687 for (
unsigned I = 0, E = ClobberRegs.
size();
I !=
E; ++
I) {
5693 if (NumOutputs || NumInputs) {
5694 unsigned NumExprs = NumOutputs + NumInputs;
5695 OpDecls.resize(NumExprs);
5696 Constraints.
resize(NumExprs);
5697 for (
unsigned i = 0; i < NumOutputs; ++i) {
5698 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
5699 Constraints[i] = OutputConstraints[i];
5701 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) {
5702 OpDecls[j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
5703 Constraints[j] = InputConstraints[i];
5708 std::string AsmStringIR;
5712 const char *AsmStart = ASMString.
begin();
5713 const char *AsmEnd = ASMString.
end();
5715 for (
const AsmRewrite &AR : AsmStrRewrites) {
5719 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
5722 if (
unsigned Len = Loc - AsmStart)
5727 AsmStart = Loc + AR.Len;
5731 unsigned AdditionalSkip = 0;
5737 assert(AR.IntelExp.isValid() &&
"cannot write invalid intel expression");
5738 if (AR.IntelExp.NeedBracs)
5740 if (AR.IntelExp.hasBaseReg())
5741 OS << AR.IntelExp.BaseReg;
5742 if (AR.IntelExp.hasIndexReg())
5743 OS << (AR.IntelExp.hasBaseReg() ?
" + " :
"")
5744 << AR.IntelExp.IndexReg;
5745 if (AR.IntelExp.Scale > 1)
5746 OS <<
" * $$" << AR.IntelExp.Scale;
5747 if (AR.IntelExp.Imm || !AR.IntelExp.hasRegs())
5748 OS << (AR.IntelExp.hasRegs() ?
" + $$" :
"$$") << AR.IntelExp.Imm;
5749 if (AR.IntelExp.NeedBracs)
5756 OS <<
'$' << InputIdx++;
5759 OS <<
'$' << OutputIdx++;
5764 case 8: OS <<
"byte ptr ";
break;
5765 case 16: OS <<
"word ptr ";
break;
5766 case 32: OS <<
"dword ptr ";
break;
5767 case 64: OS <<
"qword ptr ";
break;
5768 case 80: OS <<
"xword ptr ";
break;
5769 case 128: OS <<
"xmmword ptr ";
break;
5770 case 256: OS <<
"ymmword ptr ";
break;
5780 if (getContext().getAsmInfo()->getAlignmentIsInBytes())
5785 unsigned Val = AR.Val;
5787 assert(Val < 10 &&
"Expected alignment less then 2^10.");
5788 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
5800 AsmStart = Loc + AR.Len + AdditionalSkip;
5804 if (AsmStart != AsmEnd)
5805 OS <<
StringRef(AsmStart, AsmEnd - AsmStart);
5807 AsmString = OS.
str();
5812 namespace MCParserUtils {
5835 Sym, static_cast<const MCUnaryExpr *>(Value)->getSubExpr());
5848 return Parser.
TokError(
"missing expression");
5866 return Parser.
Error(EqualLoc,
"Recursive use of '" + Name +
"'");
5873 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
5875 return Parser.
Error(EqualLoc,
"invalid assignment to '" + Name +
"'");
5877 return Parser.
Error(EqualLoc,
5878 "invalid reassignment of non-absolute variable '" +
5880 }
else if (Name ==
".") {
5898 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
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)
void push_back(const T &Elt)
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.
Compute iterated dominance frontiers using a linear time algorithm.
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...
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)...
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
void setParsingMSInlineAsm(bool V)
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
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.
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.
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).
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.
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...
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, unsigned type=0)
Factory for NaN values.
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.
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.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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...
void setBeginSymbol(MCSymbol *Sym)
Holds state from .cv_file and .cv_loc directives for later emission.