82 typedef std::vector<AsmToken> MCAsmMacroArgument;
83 typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
87 struct MacroInstantiation {
89 SMLoc InstantiationLoc;
98 size_t CondStackDepth;
101 struct ParseStatementInfo {
106 unsigned Opcode = ~0U;
109 bool ParseError =
false;
113 ParseStatementInfo() =
delete;
115 : AsmRewrites(rewrites) {}
127 void *SavedDiagContext;
128 std::unique_ptr<MCAsmParserExtension> PlatformParser;
136 std::vector<AsmCond> TheCondStack;
144 std::vector<MacroInstantiation*> ActiveMacros;
147 std::deque<MCAsmMacro> MacroLikeBodies;
150 unsigned MacrosEnabledFlag : 1;
153 unsigned NumOfMacroInstantiations;
156 struct CppHashInfoTy {
161 CppHashInfoTy() : LineNumber(0), Buf(0) {}
163 CppHashInfoTy CppHashInfo;
174 unsigned AssemblerDialect = ~0U;
177 bool IsDarwin =
false;
180 bool ParsingMSInlineAsm =
false;
183 bool ReportedInconsistentMD5 =
false;
186 bool AltMacroMode =
false;
189 virtual bool parseStatement(ParseStatementInfo &
Info,
195 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &
Info,
202 bool enabledGenDwarfForAssembly();
207 AsmParser(
const AsmParser &) =
delete;
208 AsmParser &
operator=(
const AsmParser &) =
delete;
209 ~AsmParser()
override;
211 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
214 ExtensionDirectiveHandler Handler)
override {
215 ExtensionDirectiveMap[
Directive] = Handler;
219 DirectiveKindMap[
Directive.lower()] = DirectiveKindMap[Alias.
lower()];
226 MCAsmLexer &getLexer()
override {
return Lexer; }
227 MCContext &getContext()
override {
return Ctx; }
228 MCStreamer &getStreamer()
override {
return Out; }
232 unsigned getAssemblerDialect()
override {
233 if (AssemblerDialect == ~0U)
236 return AssemblerDialect;
238 void setAssemblerDialect(
unsigned i)
override {
239 AssemblerDialect =
i;
248 void setParsingMSInlineAsm(
bool V)
override {
249 ParsingMSInlineAsm = V;
254 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
260 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
268 bool parseExpression(
const MCExpr *&Res);
269 bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
270 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc,
272 bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
273 bool parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
274 SMLoc &EndLoc)
override;
275 bool parseAbsoluteExpression(int64_t &Res)
override;
283 bool parseIdentifier(
StringRef &Res)
override;
284 void eatToEndOfStatement()
override;
286 bool checkForValidSection()
override;
292 bool parseCppHashLineFilenameComment(
SMLoc L,
bool SaveLocInfo =
true);
302 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
305 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
308 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
317 void handleMacroExit();
320 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
323 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &A);
325 void printMacroInstantiations();
334 bool enterIncludeFile(
const std::string &Filename);
338 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
347 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
352 StringRef parseStringToEndOfStatement()
override;
358 enum class AssignmentKind {
370 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
371 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
372 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
374 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
376 bool parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName);
377 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
436 DK_BUNDLE_ALIGN_MODE,
450 DK_WEAK_DEF_CAN_BE_HIDDEN,
490 DK_CV_INLINE_SITE_ID,
493 DK_CV_INLINE_LINETABLE,
498 DK_CV_FILECHECKSUM_OFFSET,
504 DK_CFI_DEF_CFA_OFFSET,
505 DK_CFI_ADJUST_CFA_OFFSET,
506 DK_CFI_DEF_CFA_REGISTER,
507 DK_CFI_LLVM_DEF_ASPACE_CFA,
512 DK_CFI_REMEMBER_STATE,
513 DK_CFI_RESTORE_STATE,
517 DK_CFI_RETURN_COLUMN,
542 DK_LTO_SET_CONDITIONAL,
551 enum CVDefRangeType {
553 CVDR_DEFRANGE_REGISTER,
554 CVDR_DEFRANGE_FRAMEPOINTER_REL,
555 CVDR_DEFRANGE_SUBFIELD_REGISTER,
556 CVDR_DEFRANGE_REGISTER_REL
564 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
565 bool parseDirectiveReloc(
SMLoc DirectiveLoc);
566 bool parseDirectiveValue(
StringRef IDVal,
568 bool parseDirectiveOctaValue(
StringRef IDVal);
569 bool parseDirectiveRealValue(
StringRef IDVal,
571 bool parseDirectiveFill();
572 bool parseDirectiveZero();
574 bool parseDirectiveSet(
StringRef IDVal, AssignmentKind
Kind);
575 bool parseDirectiveOrg();
577 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
580 bool parseDirectiveFile(
SMLoc DirectiveLoc);
581 bool parseDirectiveLine();
582 bool parseDirectiveLoc();
583 bool parseDirectiveStabs();
587 bool parseDirectiveCVFile();
588 bool parseDirectiveCVFuncId();
589 bool parseDirectiveCVInlineSiteId();
590 bool parseDirectiveCVLoc();
591 bool parseDirectiveCVLinetable();
592 bool parseDirectiveCVInlineLinetable();
593 bool parseDirectiveCVDefRange();
594 bool parseDirectiveCVString();
595 bool parseDirectiveCVStringTable();
596 bool parseDirectiveCVFileChecksums();
597 bool parseDirectiveCVFileChecksumOffset();
598 bool parseDirectiveCVFPOData();
601 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
602 bool parseDirectiveCFIWindowSave();
603 bool parseDirectiveCFISections();
604 bool parseDirectiveCFIStartProc();
605 bool parseDirectiveCFIEndProc();
606 bool parseDirectiveCFIDefCfaOffset();
607 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
608 bool parseDirectiveCFIAdjustCfaOffset();
609 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
610 bool parseDirectiveCFILLVMDefAspaceCfa(
SMLoc DirectiveLoc);
611 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
612 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
613 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
614 bool parseDirectiveCFIRememberState();
615 bool parseDirectiveCFIRestoreState();
616 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
617 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
618 bool parseDirectiveCFIEscape();
619 bool parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc);
620 bool parseDirectiveCFISignalFrame();
621 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
624 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
627 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
632 bool parseDirectiveBundleAlignMode();
634 bool parseDirectiveBundleLock();
636 bool parseDirectiveBundleUnlock();
639 bool parseDirectiveSpace(
StringRef IDVal);
642 bool parseDirectiveDCB(
StringRef IDVal,
unsigned Size);
645 bool parseDirectiveDS(
StringRef IDVal,
unsigned Size);
648 bool parseDirectiveLEB128(
bool Signed);
654 bool parseDirectiveComm(
bool IsLocal);
656 bool parseDirectiveAbort();
657 bool parseDirectiveInclude();
658 bool parseDirectiveIncbin();
661 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
663 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
665 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
667 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
669 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
670 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
671 bool parseDirectiveElse(
SMLoc DirectiveLoc);
672 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
673 bool parseEscapedString(std::string &
Data)
override;
674 bool parseAngleBracketString(std::string &
Data)
override;
684 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
685 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
686 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
689 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &
Info,
693 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &
Info);
696 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
699 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
702 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
705 bool parseDirectivePrint(
SMLoc DirectiveLoc);
708 bool parseDirectivePseudoProbe();
711 bool parseDirectiveLTODiscard();
714 bool parseDirectiveAddrsig();
715 bool parseDirectiveAddrsigSym();
717 void initializeDirectiveKindMap();
718 void initializeCVDefRangeTypeMap();
721 class HLASMAsmParser final :
public AsmParser {
726 void lexLeadingSpaces() {
732 bool parseAsMachineInstruction(ParseStatementInfo &
Info,
738 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
747 bool parseStatement(ParseStatementInfo &
Info,
768 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
769 CurBuffer(CB ? CB : SM.getMainFileID()), MacrosEnabledFlag(
true) {
782 case MCContext::IsCOFF:
785 case MCContext::IsMachO:
789 case MCContext::IsELF:
792 case MCContext::IsGOFF:
795 case MCContext::IsSPIRV:
797 "Need to implement createSPIRVAsmParser for SPIRV format.");
799 case MCContext::IsWasm:
802 case MCContext::IsXCOFF:
805 case MCContext::IsDXContainer:
810 PlatformParser->Initialize(*
this);
811 initializeDirectiveKindMap();
812 initializeCVDefRangeTypeMap();
814 NumOfMacroInstantiations = 0;
817 AsmParser::~AsmParser() {
818 assert((HadError || ActiveMacros.empty()) &&
819 "Unexpected active macro instantiation!");
828 void AsmParser::printMacroInstantiations() {
830 for (std::vector<MacroInstantiation *>::const_reverse_iterator
831 it = ActiveMacros.rbegin(),
832 ie = ActiveMacros.rend();
834 printMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
835 "while in macro instantiation");
839 printPendingErrors();
840 printMessage(L, SourceMgr::DK_Note,
Msg, Range);
841 printMacroInstantiations();
845 if(getTargetParser().getTargetOptions().MCNoWarn)
847 if (getTargetParser().getTargetOptions().MCFatalWarnings)
849 printMessage(L, SourceMgr::DK_Warning,
Msg, Range);
850 printMacroInstantiations();
856 printMessage(L, SourceMgr::DK_Error,
Msg, Range);
857 printMacroInstantiations();
861 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
862 std::string IncludedFile;
876 bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
878 std::string IncludedFile;
889 if (!Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
890 return Error(Loc,
"expected absolute expression");
892 return Warning(Loc,
"negative count has no effect");
895 getStreamer().emitBytes(Bytes);
899 void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
910 if (getTok().
is(AsmToken::EndOfStatement)) {
912 if (!getTok().getString().
empty() && getTok().getString().front() !=
'\n' &&
920 while (tok->
is(AsmToken::Comment)) {
930 if (ParentIncludeLoc !=
SMLoc()) {
931 jumpToLoc(ParentIncludeLoc);
939 bool AsmParser::enabledGenDwarfForAssembly() {
941 if (!getContext().getGenDwarfForAssembly())
946 if (getContext().getGenDwarfFileNumber() == 0) {
949 if (!FirstCppHashFilename.
empty())
950 getContext().setMCLineTableRootFile(0,
951 getContext().getCompilationDir(),
952 FirstCppHashFilename,
955 getContext().getMCDwarfLineTable(0).getRootFile();
956 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
957 0, getContext().getCompilationDir(), RootFile.
Name,
963 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
964 LTODiscardSymbols.
clear();
967 if (!NoInitialTextSection)
974 AsmCond StartingCondState = TheCondState;
981 if (getContext().getGenDwarfForAssembly()) {
982 MCSection *Sec = getStreamer().getCurrentSectionOnly();
984 MCSymbol *SectionStartSym = getContext().createTempSymbol();
985 getStreamer().emitLabel(SectionStartSym);
988 bool InsertResult = getContext().addGenDwarfSection(Sec);
989 assert(InsertResult &&
".text section should not have debug info yet");
993 getTargetParser().onBeginOfFile();
997 ParseStatementInfo
Info(&AsmStrRewrites);
998 bool Parsed = parseStatement(
Info,
nullptr);
1008 printPendingErrors();
1011 if (Parsed && !getLexer().isAtStartOfStatement())
1012 eatToEndOfStatement();
1015 getTargetParser().onEndOfFile();
1016 printPendingErrors();
1019 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1021 getTargetParser().flushPendingInstructions(getStreamer());
1025 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1027 const auto &LineTables = getContext().getMCDwarfLineTables();
1028 if (!LineTables.empty()) {
1030 for (
const auto &
File : LineTables.begin()->second.getMCDwarfFiles()) {
1032 printError(getTok().getLoc(),
"unassigned file number: " +
1034 " for .file directives");
1045 for (
const auto &TableEntry : getContext().
getSymbols()) {
1046 MCSymbol *Sym = TableEntry.getValue();
1054 printError(getTok().getLoc(),
"assembler local symbol '" +
1055 Sym->
getName() +
"' not defined");
1061 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1062 if (std::get<2>(LocSym)->isUndefined()) {
1065 CppHashInfo = std::get<1>(LocSym);
1066 printError(std::get<0>(LocSym),
"directional label undefined");
1072 if (!HadError && !NoFinalize) {
1074 TS->emitConstantPools();
1079 return HadError || getContext().hadError();
1082 bool AsmParser::checkForValidSection() {
1083 if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) {
1085 return Error(getTok().getLoc(),
1086 "expected section directive before assembly directive");
1092 void AsmParser::eatToEndOfStatement() {
1097 if (Lexer.
is(AsmToken::EndOfStatement))
1101 StringRef AsmParser::parseStringToEndOfStatement() {
1102 const char *Start = getTok().getLoc().getPointer();
1107 const char *End = getTok().getLoc().getPointer();
1111 StringRef AsmParser::parseStringToComma() {
1112 const char *Start = getTok().getLoc().getPointer();
1114 while (Lexer.
isNot(AsmToken::EndOfStatement) &&
1118 const char *End = getTok().getLoc().getPointer();
1127 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1128 if (parseExpression(Res))
1131 return parseRParen();
1139 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1140 if (parseExpression(Res))
1142 EndLoc = getTok().getEndLoc();
1143 if (parseToken(AsmToken::RBrac,
"expected ']' in brackets expression"))
1154 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc,
1156 SMLoc FirstTokenLoc = getLexer().getLoc();
1158 switch (FirstTokenKind) {
1160 return TokError(
"unknown token in expression");
1164 case AsmToken::Exclaim:
1166 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1168 Res = MCUnaryExpr::createLNot(Res, getContext(), FirstTokenLoc);
1170 case AsmToken::Dollar:
1171 case AsmToken::Star:
1179 if (getTok().
is(AsmToken::Dollar) || getTok().
is(AsmToken::Star)) {
1180 bool ShouldGenerateTempSymbol =
false;
1183 ShouldGenerateTempSymbol =
true;
1185 if (!ShouldGenerateTempSymbol)
1186 return Error(FirstTokenLoc,
"invalid token in expression");
1194 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None,
1196 EndLoc = FirstTokenLoc;
1201 std::pair<StringRef, StringRef> Split;
1204 if (Lexer.
is(AsmToken::At)) {
1206 SMLoc AtLoc = getLexer().getLoc();
1208 if (parseIdentifier(VName))
1209 return Error(AtLoc,
"expected symbol variant after '@'");
1216 }
else if (Lexer.
is(AsmToken::LParen)) {
1219 parseIdentifier(VName);
1225 EndLoc = SMLoc::getFromPointer(
Identifier.end());
1230 return Error(getLexer().getLoc(),
"expected a symbol reference");
1235 if (!Split.second.empty()) {
1236 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
1237 if (Variant != MCSymbolRefExpr::VK_Invalid) {
1240 Variant = MCSymbolRefExpr::VK_None;
1242 return Error(SMLoc::getFromPointer(Split.second.begin()),
1243 "invalid variant '" + Split.second +
"'");
1249 Sym = getContext().getOrCreateSymbol(
1256 bool DoInline = isa<MCConstantExpr>(V) && !
Variant;
1257 if (
auto TV = dyn_cast<MCTargetExpr>(V))
1258 DoInline = TV->inlineAssignedExpr();
1261 return Error(EndLoc,
"unexpected modifier on variable reference");
1268 Res = MCSymbolRefExpr::create(Sym, Variant, getContext(), FirstTokenLoc);
1271 case AsmToken::BigNum:
1272 return TokError(
"literal value out of range for directive");
1274 SMLoc Loc = getTok().getLoc();
1275 int64_t
IntVal = getTok().getIntVal();
1276 Res = MCConstantExpr::create(
IntVal, getContext());
1283 std::pair<StringRef, StringRef> Split = IDVal.
split(
'@');
1285 if (Split.first.size() != IDVal.
size()) {
1286 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
1287 if (Variant == MCSymbolRefExpr::VK_Invalid)
1288 return TokError(
"invalid variant '" + Split.second +
"'");
1289 IDVal = Split.first;
1291 if (IDVal ==
"f" || IDVal ==
"b") {
1294 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
1296 return Error(Loc,
"directional label undefined");
1297 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1304 case AsmToken::Real: {
1305 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1307 Res = MCConstantExpr::create(
IntVal, getContext());
1312 case AsmToken::Dot: {
1314 return TokError(
"cannot use . as current PC");
1320 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
1325 case AsmToken::LParen:
1327 return parseParenExpr(Res, EndLoc);
1328 case AsmToken::LBrac:
1329 if (!PlatformParser->HasBracketExpressions())
1330 return TokError(
"brackets expression not supported on this target");
1332 return parseBracketExpr(Res, EndLoc);
1333 case AsmToken::Minus:
1335 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1337 Res = MCUnaryExpr::createMinus(Res, getContext(), FirstTokenLoc);
1339 case AsmToken::Plus:
1341 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1343 Res = MCUnaryExpr::createPlus(Res, getContext(), FirstTokenLoc);
1345 case AsmToken::Tilde:
1347 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1349 Res = MCUnaryExpr::createNot(Res, getContext(), FirstTokenLoc);
1353 case AsmToken::PercentCall16:
1354 case AsmToken::PercentCall_Hi:
1355 case AsmToken::PercentCall_Lo:
1356 case AsmToken::PercentDtprel_Hi:
1357 case AsmToken::PercentDtprel_Lo:
1358 case AsmToken::PercentGot:
1359 case AsmToken::PercentGot_Disp:
1360 case AsmToken::PercentGot_Hi:
1361 case AsmToken::PercentGot_Lo:
1362 case AsmToken::PercentGot_Ofst:
1363 case AsmToken::PercentGot_Page:
1364 case AsmToken::PercentGottprel:
1365 case AsmToken::PercentGp_Rel:
1366 case AsmToken::PercentHi:
1367 case AsmToken::PercentHigher:
1368 case AsmToken::PercentHighest:
1369 case AsmToken::PercentLo:
1370 case AsmToken::PercentNeg:
1371 case AsmToken::PercentPcrel_Hi:
1372 case AsmToken::PercentPcrel_Lo:
1373 case AsmToken::PercentTlsgd:
1374 case AsmToken::PercentTlsldm:
1375 case AsmToken::PercentTprel_Hi:
1376 case AsmToken::PercentTprel_Lo:
1378 if (Lexer.
isNot(AsmToken::LParen))
1379 return TokError(
"expected '(' after operator");
1381 if (parseExpression(Res, EndLoc))
1385 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1390 bool AsmParser::parseExpression(
const MCExpr *&Res) {
1392 return parseExpression(Res, EndLoc);
1396 AsmParser::applyModifierToExpr(
const MCExpr *
E,
1399 const MCExpr *NewE = getTargetParser().applyModifierToExpr(
E, Variant, Ctx);
1404 switch (
E->getKind()) {
1409 case MCExpr::SymbolRef: {
1412 if (SRE->
getKind() != MCSymbolRefExpr::VK_None) {
1413 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
1414 "' (already modified)");
1418 return MCSymbolRefExpr::create(&SRE->
getSymbol(), Variant, getContext());
1421 case MCExpr::Unary: {
1426 return MCUnaryExpr::create(UE->
getOpcode(), Sub, getContext());
1429 case MCExpr::Binary: {
1462 "Argument to the function cannot be a NULL value");
1464 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1465 (*CharPtr !=
'\0')) {
1466 if (*CharPtr ==
'!')
1470 if (*CharPtr ==
'>') {
1480 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1481 if (AltMacroStr[Pos] ==
'!')
1483 Res += AltMacroStr[Pos];
1498 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1501 if (getTargetParser().parsePrimaryExpr(Res, EndLoc) ||
1502 parseBinOpRHS(1, Res, EndLoc))
1508 if (Lexer.
getKind() == AsmToken::At) {
1512 return TokError(
"unexpected symbol modifier following '@'");
1515 MCSymbolRefExpr::getVariantKindForName(getTok().getIdentifier());
1516 if (Variant == MCSymbolRefExpr::VK_Invalid)
1517 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1519 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1521 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1522 "' (no symbols present)");
1532 if (Res->evaluateAsAbsolute(
Value))
1533 Res = MCConstantExpr::create(
Value, getContext());
1538 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1540 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1543 bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1545 if (parseParenExpr(Res, EndLoc))
1548 for (; ParenDepth > 0; --ParenDepth) {
1549 if (parseBinOpRHS(1, Res, EndLoc))
1554 if (ParenDepth - 1 > 0) {
1555 EndLoc = getTok().getEndLoc();
1563 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1567 if (parseExpression(Expr))
1570 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1571 return Error(StartLoc,
"expected absolute expression");
1578 bool ShouldUseLogicalShr) {
1584 case AsmToken::AmpAmp:
1585 Kind = MCBinaryExpr::LAnd;
1587 case AsmToken::PipePipe:
1588 Kind = MCBinaryExpr::LOr;
1592 case AsmToken::Pipe:
1593 Kind = MCBinaryExpr::Or;
1595 case AsmToken::Caret:
1596 Kind = MCBinaryExpr::Xor;
1599 Kind = MCBinaryExpr::And;
1606 case AsmToken::ExclaimEqual:
1607 case AsmToken::LessGreater:
1613 case AsmToken::LessEqual:
1614 Kind = MCBinaryExpr::LTE;
1616 case AsmToken::Greater:
1619 case AsmToken::GreaterEqual:
1620 Kind = MCBinaryExpr::GTE;
1624 case AsmToken::LessLess:
1625 Kind = MCBinaryExpr::Shl;
1627 case AsmToken::GreaterGreater:
1628 Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
1632 case AsmToken::Plus:
1635 case AsmToken::Minus:
1636 Kind = MCBinaryExpr::Sub;
1640 case AsmToken::Star:
1643 case AsmToken::Slash:
1644 Kind = MCBinaryExpr::Div;
1646 case AsmToken::Percent:
1655 bool ShouldUseLogicalShr) {
1661 case AsmToken::AmpAmp:
1662 Kind = MCBinaryExpr::LAnd;
1664 case AsmToken::PipePipe:
1665 Kind = MCBinaryExpr::LOr;
1672 case AsmToken::ExclaimEqual:
1673 case AsmToken::LessGreater:
1679 case AsmToken::LessEqual:
1680 Kind = MCBinaryExpr::LTE;
1682 case AsmToken::Greater:
1685 case AsmToken::GreaterEqual:
1686 Kind = MCBinaryExpr::GTE;
1690 case AsmToken::Plus:
1693 case AsmToken::Minus:
1694 Kind = MCBinaryExpr::Sub;
1699 case AsmToken::Pipe:
1700 Kind = MCBinaryExpr::Or;
1702 case AsmToken::Exclaim:
1707 Kind = MCBinaryExpr::OrNot;
1709 case AsmToken::Caret:
1710 Kind = MCBinaryExpr::Xor;
1713 Kind = MCBinaryExpr::And;
1717 case AsmToken::Star:
1720 case AsmToken::Slash:
1721 Kind = MCBinaryExpr::Div;
1723 case AsmToken::Percent:
1726 case AsmToken::LessLess:
1727 Kind = MCBinaryExpr::Shl;
1729 case AsmToken::GreaterGreater:
1730 Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
1744 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1749 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(),
Kind);
1753 if (TokPrec < Precedence)
1760 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1766 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(),
Dummy);
1767 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1771 Res = MCBinaryExpr::create(
Kind, Res,
RHS, getContext(), StartLoc);
1779 bool AsmParser::parseStatement(ParseStatementInfo &
Info,
1781 assert(!hasPendingError() &&
"parseStatement started with pending error");
1783 while (Lexer.
is(AsmToken::Space))
1785 if (Lexer.
is(AsmToken::EndOfStatement)) {
1787 if (getTok().getString().
empty() || getTok().getString().front() ==
'\r' ||
1788 getTok().getString().front() ==
'\n')
1797 int64_t LocalLabelVal = -1;
1798 StartTokLoc =
ID.getLoc();
1799 if (Lexer.
is(AsmToken::HashDirective))
1800 return parseCppHashLineFilenameComment(IDLoc,
1801 !isInsideMacroInstantiation());
1805 LocalLabelVal = getTok().getIntVal();
1806 if (LocalLabelVal < 0) {
1807 if (!TheCondState.
Ignore) {
1809 return Error(IDLoc,
"unexpected token at start of statement");
1813 IDVal = getTok().getString();
1815 if (Lexer.
getKind() != AsmToken::Colon) {
1816 if (!TheCondState.
Ignore) {
1818 return Error(IDLoc,
"unexpected token at start of statement");
1822 }
else if (Lexer.
is(AsmToken::Dot)) {
1826 }
else if (Lexer.
is(AsmToken::LCurly)) {
1831 }
else if (Lexer.
is(AsmToken::RCurly)) {
1835 }
else if (Lexer.
is(AsmToken::Star) &&
1836 getTargetParser().starIsStartOfStatement()) {
1840 }
else if (parseIdentifier(IDVal)) {
1841 if (!TheCondState.
Ignore) {
1843 return Error(IDLoc,
"unexpected token at start of statement");
1852 DirectiveKindMap.find(IDVal.
lower());
1853 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1855 : DirKindIt->getValue();
1866 return parseDirectiveIf(IDLoc, DirKind);
1868 return parseDirectiveIfb(IDLoc,
true);
1870 return parseDirectiveIfb(IDLoc,
false);
1872 return parseDirectiveIfc(IDLoc,
true);
1874 return parseDirectiveIfeqs(IDLoc,
true);
1876 return parseDirectiveIfc(IDLoc,
false);
1878 return parseDirectiveIfeqs(IDLoc,
false);
1880 return parseDirectiveIfdef(IDLoc,
true);
1883 return parseDirectiveIfdef(IDLoc,
false);
1885 return parseDirectiveElseIf(IDLoc);
1887 return parseDirectiveElse(IDLoc);
1889 return parseDirectiveEndIf(IDLoc);
1894 if (TheCondState.
Ignore) {
1895 eatToEndOfStatement();
1903 case AsmToken::Colon: {
1904 if (!getTargetParser().isLabel(
ID))
1906 if (checkForValidSection())
1914 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1922 if (LocalLabelVal == -1) {
1923 if (ParsingMSInlineAsm &&
SI) {
1925 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1927 "We should have an internal name here.");
1930 IDVal = RewrittenLabel;
1932 Sym = getContext().getOrCreateSymbol(IDVal);
1939 if (getTok().
is(AsmToken::Hash)) {
1940 StringRef CommentStr = parseStringToEndOfStatement();
1942 Lexer.
UnLex(
AsmToken(AsmToken::EndOfStatement, CommentStr));
1947 if (getTok().
is(AsmToken::EndOfStatement)) {
1951 if (discardLTOSymbol(IDVal))
1954 getTargetParser().doBeforeLabelEmit(Sym);
1957 if (!getTargetParser().isParsingMSInlineAsm())
1962 if (enabledGenDwarfForAssembly())
1963 MCGenDwarfLabelEntry::Make(Sym, &getStreamer(), getSourceManager(),
1966 getTargetParser().onLabelParsed(Sym);
1972 if (!getTargetParser().equalIsAsmAssignment())
1984 if (areMacrosEnabled())
1985 if (
const MCAsmMacro *
M = getContext().lookupMacro(IDVal)) {
1986 return handleMacroEntry(
M, IDLoc);
2004 getTargetParser().flushPendingInstructions(getStreamer());
2006 SMLoc StartTokLoc = getTok().getLoc();
2007 bool TPDirectiveReturn = getTargetParser().ParseDirective(
ID);
2009 if (hasPendingError())
2016 if (TPDirectiveReturn && StartTokLoc != getTok().getLoc())
2019 if (!TPDirectiveReturn || StartTokLoc != getTok().getLoc())
2024 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
2025 ExtensionDirectiveMap.
lookup(IDVal);
2027 return (*Handler.second)(Handler.first, IDVal, IDLoc);
2036 return parseDirectiveSet(IDVal, AssignmentKind::Set);
2038 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
2039 case DK_LTO_SET_CONDITIONAL:
2040 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
2042 return parseDirectiveAscii(IDVal,
false);
2045 return parseDirectiveAscii(IDVal,
true);
2048 return parseDirectiveValue(IDVal, 1);
2054 return parseDirectiveValue(IDVal, 2);
2059 return parseDirectiveValue(IDVal, 4);
2062 return parseDirectiveValue(IDVal, 8);
2064 return parseDirectiveValue(
2065 IDVal, getContext().getAsmInfo()->getCodePointerSize());
2067 return parseDirectiveOctaValue(IDVal);
2071 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
2074 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
2076 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
2077 return parseDirectiveAlign(IsPow2, 1);
2080 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
2081 return parseDirectiveAlign(IsPow2, 4);
2084 return parseDirectiveAlign(
false, 1);
2086 return parseDirectiveAlign(
false, 2);
2088 return parseDirectiveAlign(
false, 4);
2090 return parseDirectiveAlign(
true, 1);
2092 return parseDirectiveAlign(
true, 2);
2094 return parseDirectiveAlign(
true, 4);
2096 return parseDirectiveOrg();
2098 return parseDirectiveFill();
2100 return parseDirectiveZero();
2102 eatToEndOfStatement();
2106 return parseDirectiveSymbolAttribute(
MCSA_Global);
2107 case DK_LAZY_REFERENCE:
2109 case DK_NO_DEAD_STRIP:
2111 case DK_SYMBOL_RESOLVER:
2113 case DK_PRIVATE_EXTERN:
2117 case DK_WEAK_DEFINITION:
2119 case DK_WEAK_REFERENCE:
2121 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2124 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2127 return parseDirectiveComm(
false);
2129 return parseDirectiveComm(
true);
2131 return parseDirectiveAbort();
2133 return parseDirectiveInclude();
2135 return parseDirectiveIncbin();
2138 return TokError(
Twine(IDVal) +
2139 " not currently supported for this target");
2141 return parseDirectiveRept(IDLoc, IDVal);
2143 return parseDirectiveIrp(IDLoc);
2145 return parseDirectiveIrpc(IDLoc);
2147 return parseDirectiveEndr(IDLoc);
2148 case DK_BUNDLE_ALIGN_MODE:
2149 return parseDirectiveBundleAlignMode();
2150 case DK_BUNDLE_LOCK:
2151 return parseDirectiveBundleLock();
2152 case DK_BUNDLE_UNLOCK:
2153 return parseDirectiveBundleUnlock();
2155 return parseDirectiveLEB128(
true);
2157 return parseDirectiveLEB128(
false);
2160 return parseDirectiveSpace(IDVal);
2162 return parseDirectiveFile(IDLoc);
2164 return parseDirectiveLine();
2166 return parseDirectiveLoc();
2168 return parseDirectiveStabs();
2170 return parseDirectiveCVFile();
2172 return parseDirectiveCVFuncId();
2173 case DK_CV_INLINE_SITE_ID:
2174 return parseDirectiveCVInlineSiteId();
2176 return parseDirectiveCVLoc();
2177 case DK_CV_LINETABLE:
2178 return parseDirectiveCVLinetable();
2179 case DK_CV_INLINE_LINETABLE:
2180 return parseDirectiveCVInlineLinetable();
2181 case DK_CV_DEF_RANGE:
2182 return parseDirectiveCVDefRange();
2184 return parseDirectiveCVString();
2185 case DK_CV_STRINGTABLE:
2186 return parseDirectiveCVStringTable();
2187 case DK_CV_FILECHECKSUMS:
2188 return parseDirectiveCVFileChecksums();
2189 case DK_CV_FILECHECKSUM_OFFSET:
2190 return parseDirectiveCVFileChecksumOffset();
2191 case DK_CV_FPO_DATA:
2192 return parseDirectiveCVFPOData();
2193 case DK_CFI_SECTIONS:
2194 return parseDirectiveCFISections();
2195 case DK_CFI_STARTPROC:
2196 return parseDirectiveCFIStartProc();
2197 case DK_CFI_ENDPROC:
2198 return parseDirectiveCFIEndProc();
2199 case DK_CFI_DEF_CFA:
2200 return parseDirectiveCFIDefCfa(IDLoc);
2201 case DK_CFI_DEF_CFA_OFFSET:
2202 return parseDirectiveCFIDefCfaOffset();
2203 case DK_CFI_ADJUST_CFA_OFFSET:
2204 return parseDirectiveCFIAdjustCfaOffset();
2205 case DK_CFI_DEF_CFA_REGISTER:
2206 return parseDirectiveCFIDefCfaRegister(IDLoc);
2207 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2208 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2210 return parseDirectiveCFIOffset(IDLoc);
2211 case DK_CFI_REL_OFFSET:
2212 return parseDirectiveCFIRelOffset(IDLoc);
2213 case DK_CFI_PERSONALITY:
2214 return parseDirectiveCFIPersonalityOrLsda(
true);
2216 return parseDirectiveCFIPersonalityOrLsda(
false);
2217 case DK_CFI_REMEMBER_STATE:
2218 return parseDirectiveCFIRememberState();
2219 case DK_CFI_RESTORE_STATE:
2220 return parseDirectiveCFIRestoreState();
2221 case DK_CFI_SAME_VALUE:
2222 return parseDirectiveCFISameValue(IDLoc);
2223 case DK_CFI_RESTORE:
2224 return parseDirectiveCFIRestore(IDLoc);
2226 return parseDirectiveCFIEscape();
2227 case DK_CFI_RETURN_COLUMN:
2228 return parseDirectiveCFIReturnColumn(IDLoc);
2229 case DK_CFI_SIGNAL_FRAME:
2230 return parseDirectiveCFISignalFrame();
2231 case DK_CFI_UNDEFINED:
2232 return parseDirectiveCFIUndefined(IDLoc);
2233 case DK_CFI_REGISTER:
2234 return parseDirectiveCFIRegister(IDLoc);
2235 case DK_CFI_WINDOW_SAVE:
2236 return parseDirectiveCFIWindowSave();
2239 return parseDirectiveMacrosOnOff(IDVal);
2241 return parseDirectiveMacro(IDLoc);
2244 return parseDirectiveAltmacro(IDVal);
2246 return parseDirectiveExitMacro(IDVal);
2249 return parseDirectiveEndMacro(IDVal);
2251 return parseDirectivePurgeMacro(IDLoc);
2253 return parseDirectiveEnd(IDLoc);
2255 return parseDirectiveError(IDLoc,
false);
2257 return parseDirectiveError(IDLoc,
true);
2259 return parseDirectiveWarning(IDLoc);
2261 return parseDirectiveReloc(IDLoc);
2264 return parseDirectiveDCB(IDVal, 2);
2266 return parseDirectiveDCB(IDVal, 1);
2268 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2270 return parseDirectiveDCB(IDVal, 4);
2272 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2275 return TokError(
Twine(IDVal) +
2276 " not currently supported for this target");
2279 return parseDirectiveDS(IDVal, 2);
2281 return parseDirectiveDS(IDVal, 1);
2283 return parseDirectiveDS(IDVal, 8);
2286 return parseDirectiveDS(IDVal, 4);
2289 return parseDirectiveDS(IDVal, 12);
2291 return parseDirectivePrint(IDLoc);
2293 return parseDirectiveAddrsig();
2294 case DK_ADDRSIG_SYM:
2295 return parseDirectiveAddrsigSym();
2296 case DK_PSEUDO_PROBE:
2297 return parseDirectivePseudoProbe();
2298 case DK_LTO_DISCARD:
2299 return parseDirectiveLTODiscard();
2302 return Error(IDLoc,
"unknown directive");
2306 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2307 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2308 return parseDirectiveMSEmit(IDLoc,
Info, IDVal.
size());
2311 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2312 return parseDirectiveMSAlign(IDLoc,
Info);
2314 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2316 if (checkForValidSection())
2319 return parseAndMatchAndEmitTargetInstruction(
Info, IDVal,
ID, IDLoc);
2322 bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &
Info,
2327 std::string OpcodeStr = IDVal.
lower();
2329 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr,
ID,
2330 Info.ParsedOperands);
2331 Info.ParseError = ParseHadError;
2334 if (getShowParsedOperands()) {
2337 OS <<
"parsed instruction: [";
2338 for (
unsigned i = 0;
i !=
Info.ParsedOperands.size(); ++
i) {
2341 Info.ParsedOperands[
i]->print(OS);
2345 printMessage(IDLoc, SourceMgr::DK_Note, OS.str());
2349 if (hasPendingError() || ParseHadError)
2354 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2355 getContext().getGenDwarfSectionSyms().
count(
2356 getStreamer().getCurrentSectionOnly())) {
2358 if (ActiveMacros.empty())
2362 ActiveMacros.front()->ExitBuffer);
2367 if (!CppHashInfo.Filename.empty()) {
2368 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2370 getContext().setGenDwarfFileNumber(FileNumber);
2372 unsigned CppHashLocLineNo =
2374 Line = CppHashInfo.LineNumber - 1 + (Line - CppHashLocLineNo);
2377 getStreamer().emitDwarfLocDirective(
2378 getContext().getGenDwarfFileNumber(), Line, 0,
2384 if (!ParseHadError) {
2386 if (getTargetParser().MatchAndEmitInstruction(
2388 getTargetParser().isParsingMSInlineAsm()))
2398 if (Lexer.
isNot(AsmToken::LCurly) && Lexer.
isNot(AsmToken::RCurly))
2403 if (Lexer.
is(AsmToken::EndOfStatement))
2414 bool AsmParser::parseCppHashLineFilenameComment(
SMLoc L,
bool SaveLocInfo) {
2419 "Lexing Cpp line comment: Expected Integer");
2420 int64_t LineNumber = getTok().getIntVal();
2423 "Lexing Cpp line comment: Expected String");
2424 StringRef Filename = getTok().getString();
2431 Filename = Filename.
substr(1, Filename.
size() - 2);
2435 CppHashInfo.Loc = L;
2436 CppHashInfo.Filename = Filename;
2437 CppHashInfo.LineNumber = LineNumber;
2438 CppHashInfo.Buf = CurBuffer;
2439 if (FirstCppHashFilename.
empty())
2440 FirstCppHashFilename = Filename;
2447 auto *Parser =
static_cast<AsmParser *
>(
Context);
2453 unsigned CppHashBuf =
2454 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2459 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2468 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2469 if (Parser->SavedDiagHandler)
2470 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2472 Parser->getContext().diagnose(Diag);
2479 const std::string &Filename = std::string(Parser->CppHashInfo.Filename);
2482 int CppHashLocLineNo =
2483 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2485 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2491 if (Parser->SavedDiagHandler)
2492 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2494 Parser->getContext().diagnose(NewDiag);
2502 return isalnum(
static_cast<unsigned char>(
c)) ||
c ==
'_' ||
c ==
'$' ||
2509 bool EnableAtPseudoVariable,
SMLoc L) {
2510 unsigned NParameters = Parameters.
size();
2511 bool HasVararg = NParameters ? Parameters.
back().
Vararg :
false;
2512 if ((!IsDarwin || NParameters != 0) && NParameters !=
A.size())
2513 return Error(L,
"Wrong number of arguments");
2517 while (!Body.
empty()) {
2519 std::size_t End = Body.
size(), Pos = 0;
2520 for (; Pos != End; ++Pos) {
2522 if (IsDarwin && !NParameters) {
2524 if (Body[Pos] !=
'$' || Pos + 1 == End)
2527 char Next = Body[Pos + 1];
2528 if (Next ==
'$' || Next ==
'n' ||
2529 isdigit(
static_cast<unsigned char>(Next)))
2533 if (Body[Pos] ==
'\\' && Pos + 1 != End)
2539 OS << Body.
slice(0, Pos);
2545 if (IsDarwin && !NParameters) {
2546 switch (Body[Pos + 1]) {
2560 unsigned Index = Body[Pos + 1] -
'0';
2566 OS << Token.getString();
2572 unsigned I = Pos + 1;
2575 if (EnableAtPseudoVariable && Body[
I] ==
'@' &&
I + 1 != End)
2581 const char *Begin = Body.
data() + Pos + 1;
2586 OS << NumOfMacroInstantiations;
2593 if (
Index == NParameters) {
2594 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
2601 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2610 if (AltMacroMode && Token.getString().front() ==
'%' &&
2613 OS << Token.getIntVal();
2616 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2623 OS << Token.getString();
2625 OS << Token.getStringContents();
2642 case AsmToken::Plus:
2643 case AsmToken::Minus:
2644 case AsmToken::Tilde:
2645 case AsmToken::Slash:
2646 case AsmToken::Star:
2650 case AsmToken::Pipe:
2651 case AsmToken::PipePipe:
2652 case AsmToken::Caret:
2654 case AsmToken::AmpAmp:
2655 case AsmToken::Exclaim:
2656 case AsmToken::ExclaimEqual:
2658 case AsmToken::LessEqual:
2659 case AsmToken::LessLess:
2660 case AsmToken::LessGreater:
2661 case AsmToken::Greater:
2662 case AsmToken::GreaterEqual:
2663 case AsmToken::GreaterGreater:
2670 class AsmLexerSkipSpaceRAII {
2672 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2676 ~AsmLexerSkipSpaceRAII() {
2686 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2689 if (Lexer.
isNot(AsmToken::EndOfStatement)) {
2690 StringRef Str = parseStringToEndOfStatement();
2696 unsigned ParenLevel = 0;
2699 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2706 return TokError(
"unexpected token in macro instantiation");
2708 if (ParenLevel == 0) {
2713 if (Lexer.
is(AsmToken::Space)) {
2723 MA.push_back(getTok());
2727 if (Lexer.
is(AsmToken::Space))
2739 if (Lexer.
is(AsmToken::EndOfStatement))
2743 if (Lexer.
is(AsmToken::LParen))
2745 else if (Lexer.
is(AsmToken::RParen) && ParenLevel)
2749 MA.push_back(getTok());
2753 if (ParenLevel != 0)
2754 return TokError(
"unbalanced parentheses in macro argument");
2759 bool AsmParser::parseMacroArguments(
const MCAsmMacro *
M,
2760 MCAsmMacroArguments &
A) {
2761 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2762 bool NamedParametersFound =
false;
2765 A.resize(NParameters);
2766 FALocs.
resize(NParameters);
2771 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2772 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2778 if (parseIdentifier(FA.
Name))
2779 return Error(IDLoc,
"invalid argument identifier for formal argument");
2782 return TokError(
"expected '=' after formal parameter identifier");
2786 NamedParametersFound =
true;
2788 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2790 if (NamedParametersFound && FA.
Name.
empty())
2791 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2795 if (AltMacroMode && Lexer.
is(AsmToken::Percent)) {
2796 const MCExpr *AbsoluteExp;
2800 if (parseExpression(AbsoluteExp, EndLoc))
2802 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2803 getStreamer().getAssemblerPtr()))
2804 return Error(StrLoc,
"expected absolute expression");
2809 FA.
Value.push_back(newToken);
2814 jumpToLoc(EndLoc, CurBuffer);
2819 FA.
Value.push_back(newToken);
2820 }
else if(parseMacroArgument(FA.
Value, Vararg))
2823 unsigned PI = Parameter;
2826 for (FAI = 0; FAI < NParameters; ++FAI)
2827 if (
M->Parameters[FAI].Name == FA.
Name)
2830 if (FAI >= NParameters) {
2831 assert(
M &&
"expected macro to be defined");
2832 return Error(IDLoc,
"parameter named '" + FA.
Name +
2833 "' does not exist for macro '" +
M->Name +
"'");
2838 if (!FA.
Value.empty()) {
2843 if (FALocs.size() <= PI)
2846 FALocs[PI] = Lexer.
getLoc();
2852 if (Lexer.
is(AsmToken::EndOfStatement)) {
2854 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2856 if (
M->Parameters[FAI].Required) {
2858 "missing value for required parameter "
2859 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2863 if (!
M->Parameters[FAI].Value.empty())
2864 A[FAI] =
M->Parameters[FAI].Value;
2874 return TokError(
"too many positional arguments");
2881 if (ActiveMacros.size() == MaxNestingDepth) {
2882 std::ostringstream MaxNestingDepthError;
2883 MaxNestingDepthError <<
"macros cannot be nested more than "
2884 << MaxNestingDepth <<
" levels deep."
2885 <<
" Use -asm-macro-max-nesting-depth to increase "
2887 return TokError(MaxNestingDepthError.str());
2890 MCAsmMacroArguments
A;
2891 if (parseMacroArguments(
M,
A))
2900 if (expandMacro(OS, Body,
M->Parameters,
A,
true, getTok().getLoc()))
2905 OS <<
".endmacro\n";
2907 std::unique_ptr<MemoryBuffer> Instantiation =
2908 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
2912 MacroInstantiation *
MI =
new MacroInstantiation{
2913 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2914 ActiveMacros.push_back(
MI);
2916 ++NumOfMacroInstantiations;
2926 void AsmParser::handleMacroExit() {
2928 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2932 delete ActiveMacros.back();
2933 ActiveMacros.pop_back();
2939 SMLoc ExprLoc = getTok().getLoc();
2953 if (discardLTOSymbol(
Name))
2961 case AssignmentKind::Set:
2962 case AssignmentKind::Equiv:
2966 case AssignmentKind::LTOSetConditional:
2967 if (
Value->getKind() != MCExpr::SymbolRef)
2968 return Error(ExprLoc,
"expected identifier");
2980 bool AsmParser::parseIdentifier(
StringRef &Res) {
2986 if (Lexer.
is(AsmToken::Dollar) || Lexer.
is(AsmToken::At)) {
2987 SMLoc PrefixLoc = getLexer().getLoc();
2999 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
3013 Res = getTok().getIdentifier();
3025 bool AsmParser::parseDirectiveSet(
StringRef IDVal, AssignmentKind
Kind) {
3027 if (
check(parseIdentifier(
Name),
"expected identifier") || parseComma() ||
3033 bool AsmParser::parseEscapedString(std::string &
Data) {
3038 StringRef Str = getTok().getStringContents();
3039 for (
unsigned i = 0,
e = Str.size();
i !=
e; ++
i) {
3040 if (Str[
i] !=
'\\') {
3049 return TokError(
"unexpected backslash at end of string");
3052 if (Str[
i] ==
'x' || Str[
i] ==
'X') {
3053 size_t length = Str.size();
3055 return TokError(
"invalid hexadecimal escape sequence");
3068 if ((
unsigned)(Str[
i] -
'0') <= 7) {
3070 unsigned Value = Str[
i] -
'0';
3072 if (
i + 1 !=
e && ((
unsigned)(Str[
i + 1] -
'0')) <= 7) {
3076 if (
i + 1 !=
e && ((
unsigned)(Str[
i + 1] -
'0')) <= 7) {
3083 return TokError(
"invalid octal escape sequence (out of range)");
3093 return TokError(
"invalid escape sequence (unrecognized character)");
3095 case 'b':
Data +=
'\b';
break;
3096 case 'f':
Data +=
'\f';
break;
3097 case 'n':
Data +=
'\n';
break;
3098 case 'r':
Data +=
'\r';
break;
3099 case 't':
Data +=
'\t';
break;
3100 case '"':
Data +=
'"';
break;
3101 case '\\':
Data +=
'\\';
break;
3109 bool AsmParser::parseAngleBracketString(std::string &
Data) {
3110 SMLoc EndLoc, StartLoc = getTok().getLoc();
3112 const char *StartChar = StartLoc.
getPointer() + 1;
3113 const char *EndChar = EndLoc.
getPointer() - 1;
3114 jumpToLoc(EndLoc, CurBuffer);
3127 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
3128 auto parseOp = [&]() ->
bool {
3130 if (checkForValidSection())
3135 if (parseEscapedString(
Data))
3137 getStreamer().emitBytes(
Data);
3140 getStreamer().emitBytes(
StringRef(
"\0", 1));
3144 return parseMany(parseOp);
3149 bool AsmParser::parseDirectiveReloc(
SMLoc DirectiveLoc) {
3151 const MCExpr *Expr =
nullptr;
3154 if (parseExpression(
Offset))
3167 if (parseExpression(Expr))
3172 return Error(ExprLoc,
"expression must be relocatable");
3180 if (
Optional<std::pair<bool, std::string>> Err =
3181 getStreamer().emitRelocDirective(*
Offset,
Name, Expr, DirectiveLoc,
3183 return Error(Err->first ? NameLoc : OffsetLoc, Err->second);
3190 bool AsmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
3191 auto parseOp = [&]() ->
bool {
3193 SMLoc ExprLoc = getLexer().getLoc();
3194 if (checkForValidSection() || parseExpression(
Value))
3199 uint64_t IntValue = MCE->getValue();
3201 return Error(ExprLoc,
"out of range literal value");
3202 getStreamer().emitIntValue(IntValue,
Size);
3204 getStreamer().emitValue(
Value,
Size, ExprLoc);
3208 return parseMany(parseOp);
3213 Asm.getTok().isNot(AsmToken::BigNum))
3214 return Asm.TokError(
"unknown token in expression");
3215 SMLoc ExprLoc =
Asm.getTok().getLoc();
3216 APInt IntValue =
Asm.getTok().getAPIntVal();
3218 if (!IntValue.
isIntN(128))
3219 return Asm.Error(ExprLoc,
"out of range literal value");
3220 if (!IntValue.
isIntN(64)) {
3233 bool AsmParser::parseDirectiveOctaValue(
StringRef IDVal) {
3234 auto parseOp = [&]() ->
bool {
3235 if (checkForValidSection())
3241 getStreamer().emitInt64(lo);
3242 getStreamer().emitInt64(hi);
3244 getStreamer().emitInt64(hi);
3245 getStreamer().emitInt64(lo);
3250 return parseMany(parseOp);
3257 if (getLexer().
is(AsmToken::Minus)) {
3260 }
else if (getLexer().
is(AsmToken::Plus))
3264 return TokError(Lexer.
getErr());
3267 return TokError(
"unexpected token in directive");
3275 Value = APFloat::getInf(Semantics);
3277 Value = APFloat::getNaN(Semantics,
false, ~0);
3279 return TokError(
"invalid floating point literal");
3281 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3283 return TokError(
"invalid floating point literal");
3290 Res =
Value.bitcastToAPInt();
3297 bool AsmParser::parseDirectiveRealValue(
StringRef IDVal,
3299 auto parseOp = [&]() ->
bool {
3301 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3308 return parseMany(parseOp);
3313 bool AsmParser::parseDirectiveZero() {
3316 if (checkForValidSection() || parseExpression(NumBytes))
3322 if (parseAbsoluteExpression(Val))
3328 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3335 bool AsmParser::parseDirectiveFill() {
3338 if (checkForValidSection() || parseExpression(NumValues))
3341 int64_t FillSize = 1;
3342 int64_t FillExpr = 0;
3344 SMLoc SizeLoc, ExprLoc;
3347 SizeLoc = getTok().getLoc();
3348 if (parseAbsoluteExpression(FillSize))
3351 ExprLoc = getTok().getLoc();
3352 if (parseAbsoluteExpression(FillExpr))
3360 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3364 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3369 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3371 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3378 bool AsmParser::parseDirectiveOrg() {
3381 if (checkForValidSection() || parseExpression(
Offset))
3385 int64_t FillExpr = 0;
3387 if (parseAbsoluteExpression(FillExpr))
3392 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3398 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
3399 SMLoc AlignmentLoc = getLexer().getLoc();
3402 bool HasFillExpr =
false;
3403 int64_t FillExpr = 0;
3404 int64_t MaxBytesToFill = 0;
3406 auto parseAlign = [&]() ->
bool {
3407 if (parseAbsoluteExpression(Alignment))
3415 if (parseAbsoluteExpression(FillExpr))
3419 if (parseTokenLoc(MaxBytesLoc) ||
3420 parseAbsoluteExpression(MaxBytesToFill))
3426 if (checkForValidSection())
3429 if (IsPow2 && (ValueSize == 1) && getTok().
is(AsmToken::EndOfStatement)) {
3430 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3437 bool ReturnVal =
false;
3442 if (Alignment >= 32) {
3443 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3455 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3457 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3462 if (MaxBytesToFill < 1) {
3463 ReturnVal |=
Error(MaxBytesLoc,
3464 "alignment directive can never be satisfied in this "
3465 "many bytes, ignoring maximum bytes expression");
3469 if (MaxBytesToFill >= Alignment) {
3470 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3480 bool useCodeAlign =
Section->useCodeAlign();
3481 if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) &&
3482 ValueSize == 1 && useCodeAlign) {
3483 getStreamer().emitCodeAlignment(Alignment, &getTargetParser().getSTI(),
3487 getStreamer().emitValueToAlignment(Alignment, FillExpr, ValueSize,
3497 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
3499 int64_t FileNumber = -1;
3501 FileNumber = getTok().getIntVal();
3505 return TokError(
"negative file number");
3512 if (parseEscapedString(Path))
3517 std::string FilenameData;
3519 if (
check(FileNumber == -1,
3520 "explicit path specified, but no file number") ||
3521 parseEscapedString(FilenameData))
3523 Filename = FilenameData;
3530 bool HasMD5 =
false;
3533 bool HasSource =
false;
3534 std::string SourceString;
3536 while (!parseOptionalToken(AsmToken::EndOfStatement)) {
3539 "unexpected token in '.file' directive") ||
3540 parseIdentifier(Keyword))
3542 if (Keyword ==
"md5") {
3544 if (
check(FileNumber == -1,
3545 "MD5 checksum specified, but no file number") ||
3548 }
else if (Keyword ==
"source") {
3550 if (
check(FileNumber == -1,
3551 "source specified, but no file number") ||
3553 "unexpected token in '.file' directive") ||
3554 parseEscapedString(SourceString))
3557 return TokError(
"unexpected token in '.file' directive");
3561 if (FileNumber == -1) {
3565 if (getContext().getAsmInfo()->hasSingleParameterDotFile())
3566 getStreamer().emitFileDirective(Filename);
3579 for (
unsigned i = 0;
i != 8; ++
i) {
3580 Sum[
i] = uint8_t(MD5Hi >> ((7 -
i) * 8));
3581 Sum[
i + 8] = uint8_t(MD5Lo >> ((7 -
i) * 8));
3586 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3587 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3590 if (FileNumber == 0) {
3594 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem,
Source);
3597 FileNumber, Directory, Filename, CKMem,
Source);
3604 ReportedInconsistentMD5 =
true;
3605 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3614 bool AsmParser::parseDirectiveLine() {
3617 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
3632 bool AsmParser::parseDirectiveLoc() {
3633 int64_t FileNumber = 0, LineNumber = 0;
3634 SMLoc Loc = getTok().getLoc();
3635 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
3637 "file number less than one in '.loc' directive") ||
3638 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
3639 "unassigned file number in '.loc' directive"))
3644 LineNumber = getTok().getIntVal();
3646 return TokError(
"line number less than zero in '.loc' directive");
3650 int64_t ColumnPos = 0;
3652 ColumnPos = getTok().getIntVal();
3654 return TokError(
"column position less than zero in '.loc' directive");
3658 auto PrevFlags = getContext().getCurrentDwarfLoc().getFlags();
3661 int64_t Discriminator = 0;
3663 auto parseLocOp = [&]() ->
bool {
3665 SMLoc Loc = getTok().getLoc();
3666 if (parseIdentifier(
Name))
3667 return TokError(
"unexpected token in '.loc' directive");
3669 if (
Name ==
"basic_block")
3671 else if (
Name ==
"prologue_end")
3673 else if (
Name ==
"epilogue_begin")
3675 else if (
Name ==
"is_stmt") {
3676 Loc = getTok().getLoc();
3678 if (parseExpression(
Value))
3682 int Value = MCE->getValue();
3685 else if (
Value == 1)
3688 return Error(Loc,
"is_stmt value not 0 or 1");
3690 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3692 }
else if (
Name ==
"isa") {
3693 Loc = getTok().getLoc();
3695 if (parseExpression(
Value))
3699 int Value = MCE->getValue();
3701 return Error(Loc,
"isa number less than zero");
3704 return Error(Loc,
"isa number not a constant value");
3706 }
else if (
Name ==
"discriminator") {
3707 if (parseAbsoluteExpression(Discriminator))
3710 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3715 if (parseMany(parseLocOp,
false ))
3718 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3726 bool AsmParser::parseDirectiveStabs() {
3727 return TokError(
"unsupported directive '.stabs'");
3732 bool AsmParser::parseDirectiveCVFile() {
3733 SMLoc FileNumberLoc = getTok().getLoc();
3735 std::string Filename;
3736 std::string Checksum;
3739 if (parseIntToken(FileNumber,
3740 "expected file number in '.cv_file' directive") ||
3741 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3743 "unexpected token in '.cv_file' directive") ||
3744 parseEscapedString(Filename))
3746 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
3748 "unexpected token in '.cv_file' directive") ||
3749 parseEscapedString(Checksum) ||
3751 "expected checksum kind in '.cv_file' directive") ||
3752 parseToken(AsmToken::EndOfStatement,
3753 "unexpected token in '.cv_file' directive"))
3757 Checksum = fromHex(Checksum);
3758 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3759 memcpy(CKMem, Checksum.data(), Checksum.size());
3763 if (!getStreamer().EmitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
3765 return Error(FileNumberLoc,
"file number already allocated");
3770 bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3773 return parseTokenLoc(Loc) ||
3774 parseIntToken(FunctionId,
"expected function id in '" + DirectiveName +
3776 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3777 "expected function id within range [0, UINT_MAX)");
3780 bool AsmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
3782 return parseTokenLoc(Loc) ||
3783 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
3785 check(FileNumber < 1, Loc,
"file number less than one in '" +
3786 DirectiveName +
"' directive") ||
3787 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3788 "unassigned file number in '" + DirectiveName +
"' directive");
3795 bool AsmParser::parseDirectiveCVFuncId() {
3796 SMLoc FunctionIdLoc = getTok().getLoc();
3799 if (parseCVFunctionId(FunctionId,
".cv_func_id") ||
3800 parseToken(AsmToken::EndOfStatement,
3801 "unexpected token in '.cv_func_id' directive"))
3804 if (!getStreamer().EmitCVFuncIdDirective(FunctionId))
3805 return Error(FunctionIdLoc,
"function id already allocated");
3818 bool AsmParser::parseDirectiveCVInlineSiteId() {
3819 SMLoc FunctionIdLoc = getTok().getLoc();
3827 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3832 getTok().getIdentifier() !=
"within"),
3833 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3838 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3843 getTok().getIdentifier() !=
"inlined_at"),
3844 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3850 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3851 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3856 IACol = getTok().getIntVal();
3860 if (parseToken(AsmToken::EndOfStatement,
3861 "unexpected token in '.cv_inline_site_id' directive"))
3864 if (!getStreamer().EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3865 IALine, IACol, FunctionIdLoc))
3866 return Error(FunctionIdLoc,
"function id already allocated");
3878 bool AsmParser::parseDirectiveCVLoc() {
3879 SMLoc DirectiveLoc = getTok().getLoc();
3880 int64_t FunctionId, FileNumber;
3881 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3882 parseCVFileId(FileNumber,
".cv_loc"))
3885 int64_t LineNumber = 0;
3887 LineNumber = getTok().getIntVal();
3889 return TokError(
"line number less than zero in '.cv_loc' directive");
3893 int64_t ColumnPos = 0;
3895 ColumnPos = getTok().getIntVal();
3897 return TokError(
"column position less than zero in '.cv_loc' directive");
3901 bool PrologueEnd =
false;
3904 auto parseOp = [&]() ->
bool {
3906 SMLoc Loc = getTok().getLoc();
3907 if (parseIdentifier(
Name))
3908 return TokError(
"unexpected token in '.cv_loc' directive");
3909 if (
Name ==
"prologue_end")
3911 else if (
Name ==
"is_stmt") {
3912 Loc = getTok().getLoc();
3914 if (parseExpression(
Value))
3918 if (
const auto *MCE = dyn_cast<MCConstantExpr>(
Value))
3919 IsStmt = MCE->getValue();
3922 return Error(Loc,
"is_stmt value not 0 or 1");
3924 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3929 if (parseMany(parseOp,
false ))
3932 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3933 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
3940 bool AsmParser::parseDirectiveCVLinetable() {
3943 SMLoc Loc = getTok().getLoc();
3944 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3945 parseTokenLoc(Loc) ||
3946 check(parseIdentifier(FnStartName), Loc,
3947 "expected identifier in directive") ||
3948 parseComma() || parseTokenLoc(Loc) ||
3949 check(parseIdentifier(FnEndName), Loc,
3950 "expected identifier in directive"))
3953 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3954 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3956 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3962 bool AsmParser::parseDirectiveCVInlineLinetable() {
3963 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3965 SMLoc Loc = getTok().getLoc();
3966 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3967 parseTokenLoc(Loc) ||
3970 "expected SourceField in '.cv_inline_linetable' directive") ||
3971 check(SourceFileId <= 0, Loc,
3972 "File id less than zero in '.cv_inline_linetable' directive") ||
3973 parseTokenLoc(Loc) ||
3976 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
3977 check(SourceLineNum < 0, Loc,
3978 "Line number less than zero in '.cv_inline_linetable' directive") ||
3979 parseTokenLoc(Loc) ||
check(parseIdentifier(FnStartName), Loc,
3980 "expected identifier in directive") ||
3981 parseTokenLoc(Loc) ||
check(parseIdentifier(FnEndName), Loc,
3982 "expected identifier in directive"))
3985 if (parseToken(AsmToken::EndOfStatement,
"Expected End of Statement"))
3988 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3989 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3990 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3991 SourceLineNum, FnStartSym,
3996 void AsmParser::initializeCVDefRangeTypeMap() {
3997 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
3998 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
3999 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4000 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4005 bool AsmParser::parseDirectiveCVDefRange() {
4007 std::vector<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
4009 Loc = getLexer().getLoc();
4011 if (parseIdentifier(GapStartName))
4012 return Error(Loc,
"expected identifier in directive");
4013 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
4015 Loc = getLexer().getLoc();
4017 if (parseIdentifier(GapEndName))
4018 return Error(Loc,
"expected identifier in directive");
4019 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
4021 Ranges.push_back({GapStartSym, GapEndSym});
4027 "expected comma before def_range type in .cv_def_range directive") ||
4028 parseIdentifier(CVDefRangeTypeStr))
4029 return Error(Loc,
"expected def_range type in directive");
4032 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4033 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4035 : CVTypeIt->getValue();
4037 case CVDR_DEFRANGE_REGISTER: {
4039 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4040 ".cv_def_range directive") ||
4041 parseAbsoluteExpression(DRRegister))
4042 return Error(Loc,
"expected register number");
4047 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4050 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4053 "expected comma before offset in .cv_def_range directive") ||
4054 parseAbsoluteExpression(DROffset))
4055 return Error(Loc,
"expected offset value");
4059 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4062 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4064 int64_t DROffsetInParent;
4065 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4066 ".cv_def_range directive") ||
4067 parseAbsoluteExpression(DRRegister))
4068 return Error(Loc,
"expected register number");
4070 "expected comma before offset in .cv_def_range directive") ||
4071 parseAbsoluteExpression(DROffsetInParent))
4072 return Error(Loc,
"expected offset value");
4078 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4081 case CVDR_DEFRANGE_REGISTER_REL: {
4084 int64_t DRBasePointerOffset;
4085 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4086 ".cv_def_range directive") ||
4087 parseAbsoluteExpression(DRRegister))
4088 return Error(Loc,
"expected register value");
4091 "expected comma before flag value in .cv_def_range directive") ||
4092 parseAbsoluteExpression(DRFlags))
4093 return Error(Loc,
"expected flag value");
4094 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4095 "in .cv_def_range directive") ||
4096 parseAbsoluteExpression(DRBasePointerOffset))
4097 return Error(Loc,
"expected base pointer offset value");
4101 DRHdr.
Flags = DRFlags;
4103 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4107 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4114 bool AsmParser::parseDirectiveCVString() {
4116 if (checkForValidSection() || parseEscapedString(
Data))
4120 std::pair<StringRef, unsigned> Insertion =
4121 getCVContext().addToStringTable(
Data);
4122 getStreamer().emitInt32(Insertion.second);
4128 bool AsmParser::parseDirectiveCVStringTable() {
4129 getStreamer().emitCVStringTableDirective();
4135 bool AsmParser::parseDirectiveCVFileChecksums() {
4136 getStreamer().emitCVFileChecksumsDirective();
4142 bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4144 if (parseIntToken(FileNo,
"expected identifier in directive"))
4146 if (parseToken(AsmToken::EndOfStatement,
"Expected End of Statement"))
4148 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4154 bool AsmParser::parseDirectiveCVFPOData() {
4155 SMLoc DirLoc = getLexer().getLoc();
4157 if (parseIdentifier(ProcName))
4158 return TokError(
"expected symbol name");
4161 MCSymbol *ProcSym = getContext().getOrCreateSymbol(ProcName);
4162 getStreamer().EmitCVFPOData(ProcSym, DirLoc);
4168 bool AsmParser::parseDirectiveCFISections() {
4173 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
4175 if (parseIdentifier(
Name))
4176 return TokError(
"expected .eh_frame or .debug_frame");
4177 if (
Name ==
".eh_frame")
4179 else if (
Name ==
".debug_frame")
4181 if (parseOptionalToken(AsmToken::EndOfStatement))
4187 getStreamer().emitCFISections(EH,
Debug);
4193 bool AsmParser::parseDirectiveCFIStartProc() {
4195 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
4196 if (
check(parseIdentifier(Simple) || Simple !=
"simple",
4197 "unexpected token") ||
4207 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4213 bool AsmParser::parseDirectiveCFIEndProc() {
4216 getStreamer().emitCFIEndProc();
4221 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4222 SMLoc DirectiveLoc) {
4226 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4228 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
4230 return parseAbsoluteExpression(
Register);
4237 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
4239 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4240 parseAbsoluteExpression(
Offset) || parseEOL())
4249 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
4251 if (parseAbsoluteExpression(
Offset) || parseEOL())
4254 getStreamer().emitCFIDefCfaOffset(
Offset);
4260 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
4261 int64_t Register1 = 0, Register2 = 0;
4262 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4263 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4266 getStreamer().emitCFIRegister(Register1, Register2);
4272 bool AsmParser::parseDirectiveCFIWindowSave() {
4275 getStreamer().emitCFIWindowSave();
4281 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
4282 int64_t Adjustment = 0;
4283 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4286 getStreamer().emitCFIAdjustCfaOffset(Adjustment);
4292 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
4294 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4297 getStreamer().emitCFIDefCfaRegister(
Register);
4303 bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(
SMLoc DirectiveLoc) {
4305 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4306 parseAbsoluteExpression(
Offset) || parseComma() ||
4316 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
4320 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4321 parseAbsoluteExpression(
Offset) || parseEOL())
4330 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
4333 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4334 parseAbsoluteExpression(
Offset) || parseEOL())
4342 if (Encoding & ~0xff)
4348 const unsigned Format = Encoding & 0xf;
4355 const unsigned Application = Encoding & 0x70;
4367 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4368 int64_t Encoding = 0;
4369 if (parseAbsoluteExpression(Encoding))
4377 check(parseIdentifier(
Name),
"expected identifier in directive") ||
4384 getStreamer().emitCFIPersonality(Sym, Encoding);
4386 getStreamer().emitCFILsda(Sym, Encoding);
4392 bool AsmParser::parseDirectiveCFIRememberState() {
4395 getStreamer().emitCFIRememberState();
4401 bool AsmParser::parseDirectiveCFIRestoreState() {
4404 getStreamer().emitCFIRestoreState();
4410 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
4413 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4416 getStreamer().emitCFISameValue(
Register);
4422 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
4424 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4427 getStreamer().emitCFIRestore(
Register);
4433 bool AsmParser::parseDirectiveCFIEscape() {
4436 if (parseAbsoluteExpression(CurrValue))
4439 Values.push_back((uint8_t)CurrValue);
4444 if (parseAbsoluteExpression(CurrValue))
4447 Values.push_back((uint8_t)CurrValue);
4450 getStreamer().emitCFIEscape(Values);
4456 bool AsmParser::parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc) {
4458 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4460 getStreamer().emitCFIReturnColumn(
Register);
4466 bool AsmParser::parseDirectiveCFISignalFrame() {
4470 getStreamer().emitCFISignalFrame();
4476 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
4479 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4482 getStreamer().emitCFIUndefined(
Register);
4492 AltMacroMode = (
Directive ==
".altmacro");
4502 setMacrosEnabled(
Directive ==
".macros_on");
4508 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
4510 if (parseIdentifier(
Name))
4511 return TokError(
"expected identifier in '.macro' directive");
4517 while (getLexer().
isNot(AsmToken::EndOfStatement)) {
4519 if (!Parameters.empty() && Parameters.back().Vararg)
4520 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4521 Parameters.back().Name +
4522 "' should be the last parameter");
4525 if (parseIdentifier(Parameter.
Name))
4526 return TokError(
"expected identifier in '.macro' directive");
4530 if (CurrParam.Name.equals(Parameter.
Name))
4531 return TokError(
"macro '" +
Name +
"' has multiple parameters"
4532 " named '" + Parameter.
Name +
"'");
4534 if (Lexer.
is(AsmToken::Colon)) {
4540 QualLoc = Lexer.
getLoc();
4541 if (parseIdentifier(Qualifier))
4542 return Error(QualLoc,
"missing parameter qualifier for "
4543 "'" + Parameter.
Name +
"' in macro '" +
Name +
"'");
4545 if (Qualifier ==
"req")
4547 else if (Qualifier ==
"vararg")
4550 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4551 "for '" + Parameter.
Name +
"' in macro '" +
Name +
"'");
4559 ParamLoc = Lexer.
getLoc();
4560 if (parseMacroArgument(Parameter.
Value,
false ))
4564 Warning(ParamLoc,
"pointless default value for required parameter "
4565 "'" + Parameter.
Name +
"' in macro '" +
Name +
"'");
4568 Parameters.push_back(
std::move(Parameter));
4578 AsmToken EndToken, StartToken = getTok();
4579 unsigned MacroDepth = 0;
4589 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4594 if (getTok().getIdentifier() ==
".endm" ||
4595 getTok().getIdentifier() ==
".endmacro") {
4596 if (MacroDepth == 0) {
4597 EndToken = getTok();
4599 if (getLexer().
isNot(AsmToken::EndOfStatement))
4600 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4607 }
else if (getTok().getIdentifier() ==
".macro") {
4612 }
else if (Lexer.
is(AsmToken::HashDirective)) {
4613 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4617 eatToEndOfStatement();
4620 if (getContext().lookupMacro(
Name)) {
4621 return Error(DirectiveLoc,
"macro '" +
Name +
"' is already defined");
4627 checkForBadMacro(DirectiveLoc,
Name, Body, Parameters);
4654 unsigned NParameters = Parameters.
size();
4655 if (NParameters == 0)
4658 bool NamedParametersFound =
false;
4659 bool PositionalParametersFound =
false;
4664 while (!Body.
empty()) {
4666 std::size_t End = Body.
size(), Pos = 0;
4667 for (; Pos != End; ++Pos) {
4670 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4674 if (Body[Pos] !=
'$' || Pos + 1 == End)
4676 char Next = Body[Pos + 1];
4677 if (Next ==
'$' || Next ==
'n' ||
4678 isdigit(
static_cast<unsigned char>(Next)))
4686 if (Body[Pos] ==
'$') {
4687 switch (Body[Pos + 1]) {
4694 PositionalParametersFound =
true;
4699 PositionalParametersFound =
true;
4705 unsigned I = Pos + 1;
4709 const char *Begin = Body.
data() + Pos + 1;
4716 if (
Index == NParameters) {
4717 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4723 NamedParametersFound =
true;
4731 if (!NamedParametersFound && PositionalParametersFound)
4732 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4733 "used in macro body, possible positional parameter "
4734 "found in body which will have no effect");
4743 if (!isInsideMacroInstantiation())
4744 return TokError(
"unexpected '" +
Directive +
"' in file, "
4745 "no current macro definition");
4748 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4749 TheCondState = TheCondStack.back();
4750 TheCondStack.pop_back();
4761 if (getLexer().
isNot(AsmToken::EndOfStatement))
4762 return TokError(
"unexpected token in '" +
Directive +
"' directive");
4766 if (isInsideMacroInstantiation()) {
4773 return TokError(
"unexpected '" +
Directive +
"' in file, "
4774 "no current macro definition");
4779 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
4782 if (parseTokenLoc(Loc) ||
4784 "expected identifier in '.purgem' directive") ||
4788 if (!getContext().lookupMacro(
Name))
4789 return Error(DirectiveLoc,
"macro '" +
Name +
"' is not defined");
4791 getContext().undefineMacro(
Name);
4793 <<
"Un-defining macro: " <<
Name <<
"\n");
4799 bool AsmParser::parseDirectiveBundleAlignMode() {
4802 SMLoc ExprLoc = getLexer().getLoc();
4803 int64_t AlignSizePow2;
4804 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4806 check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
4807 "invalid bundle alignment size (expected between 0 and 30)"))
4812 getStreamer().emitBundleAlignMode(
static_cast<unsigned>(AlignSizePow2));
4818 bool AsmParser::parseDirectiveBundleLock() {
4819 if (checkForValidSection())
4821 bool AlignToEnd =
false;
4824 SMLoc Loc = getTok().getLoc();
4825 const char *kInvalidOptionError =
4826 "invalid option for '.bundle_lock' directive";
4828 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
4829 if (
check(parseIdentifier(
Option), Loc, kInvalidOptionError) ||
4830 check(
Option !=
"align_to_end", Loc, kInvalidOptionError) || parseEOL())
4835 getStreamer().emitBundleLock(AlignToEnd);
4841 bool AsmParser::parseDirectiveBundleUnlock() {
4842 if (checkForValidSection() || parseEOL())
4845 getStreamer().emitBundleUnlock();
4851 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
4854 if (checkForValidSection() || parseExpression(NumBytes))
4857 int64_t FillExpr = 0;
4859 if (parseAbsoluteExpression(FillExpr))
4865 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4872 bool AsmParser::parseDirectiveDCB(
StringRef IDVal,
unsigned Size) {
4875 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4878 if (NumValues < 0) {
4879 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4887 SMLoc ExprLoc = getLexer().getLoc();
4888 if (parseExpression(
Value))
4894 uint64_t IntValue = MCE->getValue();
4896 return Error(ExprLoc,
"literal value out of range for directive");
4898 getStreamer().emitIntValue(IntValue,
Size);
4901 getStreamer().emitValue(
Value,
Size, ExprLoc);
4912 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4915 if (NumValues < 0) {
4916 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4924 if (parseRealValue(Semantics, AsInt) || parseEOL())
4936 bool AsmParser::parseDirectiveDS(
StringRef IDVal,
unsigned Size) {
4939 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4943 if (NumValues < 0) {
4944 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4949 getStreamer().emitFill(
Size, 0);
4956 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4957 if (checkForValidSection())
4960 auto parseOp = [&]() ->
bool {
4962 if (parseExpression(
Value))
4965 getStreamer().emitSLEB128Value(
Value);
4967 getStreamer().emitULEB128Value(
Value);
4971 return parseMany(parseOp);
4976 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4977 auto parseOp = [&]() ->
bool {
4979 SMLoc Loc = getTok().getLoc();
4980 if (parseIdentifier(
Name))
4981 return Error(Loc,
"expected identifier");
4983 if (discardLTOSymbol(
Name))
4990 return Error(Loc,
"non-local symbol required");
4992 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
4993 return Error(Loc,
"unable to emit symbol attribute");
4997 return parseMany(parseOp);
5002 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5003 if (checkForValidSection())
5006 SMLoc IDLoc = getLexer().getLoc();
5008 if (parseIdentifier(
Name))
5009 return TokError(
"expected identifier in directive");
5018 SMLoc SizeLoc = getLexer().getLoc();
5019 if (parseAbsoluteExpression(
Size))
5022 int64_t Pow2Alignment = 0;
5023 SMLoc Pow2AlignmentLoc;
5026 Pow2AlignmentLoc = getLexer().getLoc();
5027 if (parseAbsoluteExpression(Pow2Alignment))
5032 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5035 if ((!IsLocal && Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) ||
5038 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5039 Pow2Alignment =
Log2_64(Pow2Alignment);
5049 return Error(SizeLoc,
"size must be non-negative");
5053 return Error(IDLoc,
"invalid symbol redefinition");
5057 getStreamer().emitLocalCommonSymbol(Sym,
Size, 1 << Pow2Alignment);
5061 getStreamer().emitCommonSymbol(Sym,
Size, 1 << Pow2Alignment);
5067 bool AsmParser::parseDirectiveAbort() {
5069 SMLoc Loc = getLexer().getLoc();
5071 StringRef Str = parseStringToEndOfStatement();
5076 return Error(Loc,
".abort detected. Assembly stopping.");
5078 return Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
5086 bool AsmParser::parseDirectiveInclude() {
5088 std::string Filename;
5089 SMLoc IncludeLoc = getTok().getLoc();
5092 "expected string in '.include' directive") ||
5093 parseEscapedString(Filename) ||
5094 check(getTok().
isNot(AsmToken::EndOfStatement),
5095 "unexpected token in '.include' directive") ||
5098 check(enterIncludeFile(Filename), IncludeLoc,
5099 "Could not find include file '" + Filename +
"'"))
5107 bool AsmParser::parseDirectiveIncbin() {
5109 std::string Filename;
5110 SMLoc IncbinLoc = getTok().getLoc();
5112 "expected string in '.incbin' directive") ||
5113 parseEscapedString(Filename))
5117 const MCExpr *Count =
nullptr;
5118 SMLoc SkipLoc, CountLoc;
5123 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5127 CountLoc = getTok().getLoc();
5128 if (parseExpression(Count))
5136 if (
check(Skip < 0, SkipLoc,
"skip is negative"))
5140 if (processIncbinFile(Filename, Skip, Count, CountLoc))
5141 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
5147 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
5148 TheCondStack.push_back(TheCondState);
5149 TheCondState.
TheCond = AsmCond::IfCond;
5150 if (TheCondState.
Ignore) {
5151 eatToEndOfStatement();
5154 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5164 ExprValue = ExprValue == 0;
5167 ExprValue = ExprValue >= 0;
5170 ExprValue = ExprValue > 0;
5173 ExprValue = ExprValue <= 0;
5176 ExprValue = ExprValue < 0;
5180 TheCondState.
CondMet = ExprValue;
5189 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
5190 TheCondStack.push_back(TheCondState);
5191 TheCondState.
TheCond = AsmCond::IfCond;
5193 if (TheCondState.
Ignore) {
5194 eatToEndOfStatement();
5196 StringRef Str = parseStringToEndOfStatement();
5201 TheCondState.
CondMet = ExpectBlank == Str.empty();
5211 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
5212 TheCondStack.push_back(TheCondState);
5213 TheCondState.
TheCond = AsmCond::IfCond;
5215 if (TheCondState.
Ignore) {
5216 eatToEndOfStatement();
5223 StringRef Str2 = parseStringToEndOfStatement();
5237 bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
5240 return TokError(
"expected string parameter for '.ifeqs' directive");
5241 return TokError(
"expected string parameter for '.ifnes' directive");
5244 StringRef String1 = getTok().getStringContents();
5250 "expected comma after first string for '.ifeqs' directive");
5251 return TokError(
"expected comma after first string for '.ifnes' directive");
5258 return TokError(
"expected string parameter for '.ifeqs' directive");
5259 return TokError(
"expected string parameter for '.ifnes' directive");
5262 StringRef String2 = getTok().getStringContents();
5265 TheCondStack.push_back(TheCondState);
5266 TheCondState.
TheCond = AsmCond::IfCond;
5267 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5275 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
5277 TheCondStack.push_back(TheCondState);
5278 TheCondState.
TheCond = AsmCond::IfCond;
5280 if (TheCondState.
Ignore) {
5281 eatToEndOfStatement();
5283 if (
check(parseIdentifier(
Name),
"expected identifier after '.ifdef'") ||
5301 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
5302 if (TheCondState.
TheCond != AsmCond::IfCond &&
5303 TheCondState.
TheCond != AsmCond::ElseIfCond)
5304 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5305 " .if or an .elseif");
5306 TheCondState.
TheCond = AsmCond::ElseIfCond;
5308 bool LastIgnoreState =
false;
5309 if (!TheCondStack.empty())
5310 LastIgnoreState = TheCondStack.back().Ignore;
5311 if (LastIgnoreState || TheCondState.
CondMet) {
5312 TheCondState.
Ignore =
true;
5313 eatToEndOfStatement();
5316 if (parseAbsoluteExpression(ExprValue))
5322 TheCondState.
CondMet = ExprValue;
5331 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
5335 if (TheCondState.
TheCond != AsmCond::IfCond &&
5336 TheCondState.
TheCond != AsmCond::ElseIfCond)
5337 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5338 " an .if or an .elseif");
5339 TheCondState.
TheCond = AsmCond::ElseCond;
5340 bool LastIgnoreState =
false;
5341 if (!TheCondStack.empty())
5342 LastIgnoreState = TheCondStack.back().Ignore;
5343 if (LastIgnoreState || TheCondState.
CondMet)
5344 TheCondState.
Ignore =
true;
5346 TheCondState.
Ignore =
false;
5353 bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
5366 bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
5367 if (!TheCondStack.empty()) {
5368 if (TheCondStack.back().Ignore) {
5369 eatToEndOfStatement();
5375 return Error(L,
".err encountered");
5377 StringRef Message =
".error directive invoked in source file";
5378 if (Lexer.
isNot(AsmToken::EndOfStatement)) {
5380 return TokError(
".error argument must be a string");
5382 Message = getTok().getStringContents();
5386 return Error(L, Message);
5391 bool AsmParser::parseDirectiveWarning(
SMLoc L) {
5392 if (!TheCondStack.empty()) {
5393 if (TheCondStack.back().Ignore) {
5394 eatToEndOfStatement();
5399 StringRef Message =
".warning directive invoked in source file";
5401 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
5403 return TokError(
".warning argument must be a string");
5405 Message = getTok().getStringContents();
5416 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
5420 if ((TheCondState.
TheCond == AsmCond::NoCond) || TheCondStack.empty())
5421 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5423 if (!TheCondStack.empty()) {
5424 TheCondState = TheCondStack.back();
5425 TheCondStack.pop_back();
5431 void AsmParser::initializeDirectiveKindMap() {
5438 DirectiveKindMap[
".set"] = DK_SET;
5439 DirectiveKindMap[
".equ"] = DK_EQU;
5440 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5441 DirectiveKindMap[
".ascii"] = DK_ASCII;
5442 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5443 DirectiveKindMap[
".string"] = DK_STRING;
5444 DirectiveKindMap[
".byte"] = DK_BYTE;
5445 DirectiveKindMap[
".short"] = DK_SHORT;
5446 DirectiveKindMap[
".value"] = DK_VALUE;
5447 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5448 DirectiveKindMap[
".long"] = DK_LONG;
5449 DirectiveKindMap[
".int"] = DK_INT;
5450 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5451 DirectiveKindMap[
".quad"] = DK_QUAD;
5452 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5453 DirectiveKindMap[
".octa"] = DK_OCTA;
5454 DirectiveKindMap[
".single"] = DK_SINGLE;
5455 DirectiveKindMap[
".float"] = DK_FLOAT;
5456 DirectiveKindMap[
".double"] = DK_DOUBLE;
5457 DirectiveKindMap[
".align"] = DK_ALIGN;
5458 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5459 DirectiveKindMap[
".balign"] = DK_BALIGN;
5460 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5461 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5462 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5463 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5464 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5465 DirectiveKindMap[
".org"] = DK_ORG;
5466 DirectiveKindMap[
".fill"] = DK_FILL;
5467 DirectiveKindMap[
".zero"] = DK_ZERO;
5468 DirectiveKindMap[
".extern"] = DK_EXTERN;
5469 DirectiveKindMap[
".globl"] = DK_GLOBL;
5470 DirectiveKindMap[
".global"] = DK_GLOBAL;
5471 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5472 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5473 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5474 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5475 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5476 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5477 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5478 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5479 DirectiveKindMap[
".cold"] = DK_COLD;
5480 DirectiveKindMap[
".comm"] = DK_COMM;
5481 DirectiveKindMap[
".common"] = DK_COMMON;
5482 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5483 DirectiveKindMap[
".abort"] = DK_ABORT;
5484 DirectiveKindMap[
".include"] = DK_INCLUDE;
5485 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5486 DirectiveKindMap[
".code16"] = DK_CODE16;
5487 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5488 DirectiveKindMap[
".rept"] = DK_REPT;
5489 DirectiveKindMap[
".rep"] = DK_REPT;
5490 DirectiveKindMap[
".irp"] = DK_IRP;
5491 DirectiveKindMap[
".irpc"] = DK_IRPC;
5492 DirectiveKindMap[
".endr"] = DK_ENDR;
5493 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5494 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5495 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5496 DirectiveKindMap[
".if"] = DK_IF;
5497 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5498 DirectiveKindMap[
".ifge"] = DK_IFGE;
5499 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5500 DirectiveKindMap[
".ifle"] = DK_IFLE;
5501 DirectiveKindMap[
".iflt"] = DK_IFLT;
5502 DirectiveKindMap[
".ifne"] = DK_IFNE;
5503 DirectiveKindMap[
".ifb"] = DK_IFB;
5504 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5505 DirectiveKindMap[
".ifc"] = DK_IFC;
5506 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5507 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5508 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5509 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5510 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5511 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5512 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5513 DirectiveKindMap[
".else"] = DK_ELSE;
5514 DirectiveKindMap[
".end"] = DK_END;
5515 DirectiveKindMap[
".endif"] = DK_ENDIF;
5516 DirectiveKindMap[
".skip"] = DK_SKIP;
5517 DirectiveKindMap[
".space"] = DK_SPACE;
5518 DirectiveKindMap[
".file"] = DK_FILE;
5519 DirectiveKindMap[
".line"] = DK_LINE;
5520 DirectiveKindMap[
".loc"] = DK_LOC;
5521 DirectiveKindMap[
".stabs"] = DK_STABS;
5522 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5523 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5524 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5525 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5526 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5527 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5528 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5529 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5530 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5531 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5532 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5533 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5534 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5535 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5536 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5537 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5538 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5539 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5540 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5541 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5542 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5543 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5544 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5545 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5546 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5547 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5548 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5549 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5550 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5551 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5552 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5553 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5554 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5555 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5556 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5557 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5558 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5559 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5560 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5561 DirectiveKindMap[
".macro"] = DK_MACRO;
5562 DirectiveKindMap[
".exitm"] = DK_EXITM;
5563 DirectiveKindMap[
".endm"] = DK_ENDM;
5564 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5565 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5566 DirectiveKindMap[
".err"] = DK_ERR;
5567 DirectiveKindMap[
".error"] = DK_ERROR;
5568 DirectiveKindMap[
".warning"] = DK_WARNING;
5569 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5570 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5571 DirectiveKindMap[
".reloc"] = DK_RELOC;
5572 DirectiveKindMap[
".dc"] = DK_DC;
5573 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5574 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5575 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5576 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5577 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5578 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5579 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5580 DirectiveKindMap[
".dcb"] = DK_DCB;
5581 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5582 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5583 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5584 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5585 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5586 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5587 DirectiveKindMap[
".ds"] = DK_DS;
5588 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5589 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5590 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5591 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5592 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5593 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5594 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5595 DirectiveKindMap[
".print"] = DK_PRINT;
5596 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5597 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5598 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5599 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5600 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5604 AsmToken EndToken, StartToken = getTok();
5606 unsigned NestLevel = 0;
5610 printError(DirectiveLoc,
"no matching '.endr' in definition");
5615 (getTok().getIdentifier() ==
".rep" ||
5616 getTok().getIdentifier() ==
".rept" ||
5617 getTok().getIdentifier() ==
".irp" ||
5618 getTok().getIdentifier() ==
".irpc")) {
5624 if (NestLevel == 0) {
5625 EndToken = getTok();
5627 if (Lexer.
isNot(AsmToken::EndOfStatement)) {
5628 printError(getTok().getLoc(),
5629 "unexpected token in '.endr' directive");
5638 eatToEndOfStatement();
5647 return &MacroLikeBodies.back();
5650 void AsmParser::instantiateMacroLikeBody(
MCAsmMacro *
M,
SMLoc DirectiveLoc,
5654 std::unique_ptr<MemoryBuffer> Instantiation =
5655 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
5659 MacroInstantiation *
MI =
new MacroInstantiation{
5660 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5661 ActiveMacros.push_back(
MI);
5671 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
5673 SMLoc CountLoc = getTok().getLoc();
5674 if (parseExpression(CountExpr))
5678 if (!CountExpr->evaluateAsAbsolute(Count, getStreamer().getAssemblerPtr())) {
5679 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5682 if (
check(Count < 0, CountLoc,
"Count is negative") || parseEOL())
5696 if (expandMacro(OS,
M->Body,
None,
None,
false, getTok().getLoc()))
5699 instantiateMacroLikeBody(
M, DirectiveLoc, OS);
5706 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
5708 MCAsmMacroArguments
A;
5709 if (
check(parseIdentifier(Parameter.
Name),
5710 "expected identifier in '.irp' directive") ||
5711 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5724 for (
const MCAsmMacroArgument &
Arg :
A) {
5727 if (expandMacro(OS,
M->Body, Parameter,
Arg,
true, getTok().getLoc()))
5731 instantiateMacroLikeBody(
M, DirectiveLoc, OS);
5738 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
5740 MCAsmMacroArguments
A;
5742 if (
check(parseIdentifier(Parameter.
Name),
5743 "expected identifier in '.irpc' directive") ||
5744 parseComma() || parseMacroArguments(
nullptr,
A))
5747 if (
A.size() != 1 ||
A.front().size() != 1)
5748 return TokError(
"unexpected token in '.irpc' directive");
5762 StringRef Values =
A.front().front().getString();
5763 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5764 MCAsmMacroArgument
Arg;
5769 if (expandMacro(OS,
M->Body, Parameter,
Arg,
true, getTok().getLoc()))
5773 instantiateMacroLikeBody(
M, DirectiveLoc, OS);
5778 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
5779 if (ActiveMacros.empty())
5780 return TokError(
"unmatched '.endr' directive");
5784 assert(getLexer().
is(AsmToken::EndOfStatement));
5790 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &
Info,
5793 SMLoc ExprLoc = getLexer().getLoc();
5794 if (parseExpression(
Value))
5798 return Error(ExprLoc,
"unexpected expression in _emit");
5801 return Error(ExprLoc,
"literal value out of range for directive");
5807 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &
Info) {
5809 SMLoc ExprLoc = getLexer().getLoc();
5810 if (parseExpression(
Value))
5814 return Error(ExprLoc,
"unexpected expression in align");
5817 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5823 bool AsmParser::parseDirectivePrint(
SMLoc DirectiveLoc) {
5827 return Error(DirectiveLoc,
"expected double quoted string after .print");
5834 bool AsmParser::parseDirectiveAddrsig() {
5837 getStreamer().emitAddrsig();
5841 bool AsmParser::parseDirectiveAddrsigSym() {
5843 if (
check(parseIdentifier(
Name),
"expected identifier") || parseEOL())
5846 getStreamer().emitAddrsigSym(Sym);
5850 bool AsmParser::parseDirectivePseudoProbe() {
5857 if (parseIntToken(Guid,
"unexpected token in '.pseudoprobe' directive"))
5862 if (parseIntToken(
Index,
"unexpected token in '.pseudoprobe' directive"))
5867 if (parseIntToken(
Type,
"unexpected token in '.pseudoprobe' directive"))
5872 if (parseIntToken(Attr,
"unexpected token in '.pseudoprobe' directive"))
5879 while (getLexer().
is(AsmToken::At)) {
5883 int64_t CallerGuid = 0;
5885 if (parseIntToken(CallerGuid,
5886 "unexpected token in '.pseudoprobe' directive"))
5891 if (getLexer().
is(AsmToken::Colon))
5894 int64_t CallerProbeId = 0;
5896 if (parseIntToken(CallerProbeId,
5897 "unexpected token in '.pseudoprobe' directive"))
5902 InlineStack.push_back(Site);
5908 getStreamer().emitPseudoProbe(Guid,
Index,
Type, Attr, InlineStack);
5917 bool AsmParser::parseDirectiveLTODiscard() {
5918 auto ParseOp = [&]() ->
bool {
5920 SMLoc Loc = getTok().getLoc();
5921 if (parseIdentifier(
Name))
5922 return Error(Loc,
"expected identifier");
5927 LTODiscardSymbols.
clear();
5928 return parseMany(ParseOp);
5954 bool AsmParser::parseMSInlineAsm(
5955 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,