80typedef std::vector<AsmToken> MCAsmMacroArgument;
81typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
84struct MacroInstantiation {
86 SMLoc InstantiationLoc;
95 size_t CondStackDepth;
98struct ParseStatementInfo {
103 unsigned Opcode = ~0
U;
106 bool ParseError =
false;
109 std::optional<std::string> ExitValue;
113 ParseStatementInfo() =
delete;
115 : AsmRewrites(rewrites) {}
128 bool Initializable =
true;
129 unsigned Alignment = 0;
130 unsigned AlignmentSize = 0;
131 unsigned NextOffset = 0;
133 std::vector<FieldInfo> Fields;
136 FieldInfo &addField(
StringRef FieldName, FieldType FT,
137 unsigned FieldAlignmentSize);
139 StructInfo() =
default;
140 StructInfo(
StringRef StructName,
bool Union,
unsigned AlignmentValue);
148struct StructInitializer;
152 IntFieldInfo() =
default;
156struct RealFieldInfo {
159 RealFieldInfo() =
default;
163struct StructFieldInfo {
164 std::vector<StructInitializer> Initializers;
165 StructInfo Structure;
167 StructFieldInfo() =
default;
168 StructFieldInfo(std::vector<StructInitializer> V, StructInfo S);
171class FieldInitializer {
175 IntFieldInfo IntInfo;
176 RealFieldInfo RealInfo;
177 StructFieldInfo StructInfo;
181 FieldInitializer(FieldType FT);
185 FieldInitializer(std::vector<StructInitializer> &&Initializers,
186 struct StructInfo Structure);
188 FieldInitializer(
const FieldInitializer &Initializer);
189 FieldInitializer(FieldInitializer &&Initializer);
191 FieldInitializer &operator=(
const FieldInitializer &Initializer);
192 FieldInitializer &operator=(FieldInitializer &&Initializer);
195struct StructInitializer {
196 std::vector<FieldInitializer> FieldInitializers;
207 unsigned LengthOf = 0;
212 FieldInitializer Contents;
214 FieldInfo(FieldType FT) : Contents(FT) {}
217StructFieldInfo::StructFieldInfo(std::vector<StructInitializer> V,
219 Initializers = std::move(V);
223StructInfo::StructInfo(
StringRef StructName,
bool Union,
224 unsigned AlignmentValue)
227FieldInfo &StructInfo::addField(
StringRef FieldName, FieldType FT,
228 unsigned FieldAlignmentSize) {
229 if (!FieldName.
empty())
230 FieldsByName[FieldName.
lower()] = Fields.size();
231 Fields.emplace_back(FT);
232 FieldInfo &
Field = Fields.back();
234 llvm::alignTo(NextOffset, std::min(Alignment, FieldAlignmentSize));
238 AlignmentSize = std::max(AlignmentSize, FieldAlignmentSize);
242FieldInitializer::~FieldInitializer() {
245 IntInfo.~IntFieldInfo();
248 RealInfo.~RealFieldInfo();
251 StructInfo.~StructFieldInfo();
256FieldInitializer::FieldInitializer(FieldType FT) : FT(FT) {
259 new (&IntInfo) IntFieldInfo();
262 new (&RealInfo) RealFieldInfo();
265 new (&StructInfo) StructFieldInfo();
272 new (&IntInfo) IntFieldInfo(std::move(Values));
277 new (&RealInfo) RealFieldInfo(std::move(AsIntValues));
280FieldInitializer::FieldInitializer(
281 std::vector<StructInitializer> &&Initializers,
struct StructInfo Structure)
283 new (&StructInfo) StructFieldInfo(std::move(Initializers), Structure);
286FieldInitializer::FieldInitializer(
const FieldInitializer &Initializer)
287 : FT(Initializer.FT) {
290 new (&IntInfo) IntFieldInfo(Initializer.IntInfo);
293 new (&RealInfo) RealFieldInfo(Initializer.RealInfo);
296 new (&StructInfo) StructFieldInfo(Initializer.StructInfo);
301FieldInitializer::FieldInitializer(FieldInitializer &&Initializer)
302 : FT(Initializer.FT) {
305 new (&IntInfo) IntFieldInfo(Initializer.IntInfo);
308 new (&RealInfo) RealFieldInfo(Initializer.RealInfo);
311 new (&StructInfo) StructFieldInfo(Initializer.StructInfo);
317FieldInitializer::operator=(
const FieldInitializer &Initializer) {
318 if (FT != Initializer.FT) {
321 IntInfo.~IntFieldInfo();
324 RealInfo.~RealFieldInfo();
327 StructInfo.~StructFieldInfo();
334 IntInfo = Initializer.IntInfo;
337 RealInfo = Initializer.RealInfo;
340 StructInfo = Initializer.StructInfo;
346FieldInitializer &FieldInitializer::operator=(FieldInitializer &&Initializer) {
347 if (FT != Initializer.FT) {
350 IntInfo.~IntFieldInfo();
353 RealInfo.~RealFieldInfo();
356 StructInfo.~StructFieldInfo();
363 IntInfo = Initializer.IntInfo;
366 RealInfo = Initializer.RealInfo;
369 StructInfo = Initializer.StructInfo;
386 void *SavedDiagContext;
387 std::unique_ptr<MCAsmParserExtension> PlatformParser;
399 std::vector<AsmCond> TheCondStack;
408 enum RedefinableKind { NOT_REDEFINABLE, WARN_ON_REDEFINITION, REDEFINABLE };
411 RedefinableKind Redefinable = REDEFINABLE;
413 std::string TextValue;
427 std::vector<MacroInstantiation*> ActiveMacros;
430 std::deque<MCAsmMacro> MacroLikeBodies;
433 unsigned NumOfMacroInstantiations;
436 struct CppHashInfoTy {
441 CppHashInfoTy() : LineNumber(0), Buf(0) {}
443 CppHashInfoTy CppHashInfo;
453 unsigned AssemblerDialect = 1U;
456 bool IsDarwin =
false;
459 bool ParsingMSInlineAsm =
false;
462 bool ReportedInconsistentMD5 =
false;
465 unsigned AngleBracketDepth = 0
U;
472 const MCAsmInfo &MAI,
struct tm TM,
unsigned CB = 0);
473 MasmParser(
const MasmParser &) =
delete;
474 MasmParser &
operator=(
const MasmParser &) =
delete;
475 ~MasmParser()
override;
477 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
480 ExtensionDirectiveHandler Handler)
override {
481 ExtensionDirectiveMap[
Directive] = Handler;
482 if (!DirectiveKindMap.contains(
Directive)) {
483 DirectiveKindMap[
Directive] = DK_HANDLER_DIRECTIVE;
488 DirectiveKindMap[
Directive] = DirectiveKindMap[Alias];
502 if (AssemblerDialect == ~0U)
505 return AssemblerDialect;
508 AssemblerDialect = i;
513 SMRange Range = std::nullopt)
override;
515 SMRange Range = std::nullopt)
override;
517 enum ExpandKind { ExpandMacros, DoNotExpandMacros };
522 ParsingMSInlineAsm =
V;
553 SMLoc &EndLoc)
override;
562 enum IdentifierPositionKind { StandardPosition, StartOfStatement };
575 const AsmToken peekTok(
bool ShouldSkipSpace =
true);
577 bool parseStatement(ParseStatementInfo &Info,
580 bool parseCppHashLineFilenameComment(
SMLoc L);
585 const std::vector<std::string> &Locals,
SMLoc L);
588 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
594 bool handleMacroEntry(
605 void handleMacroExit();
614 parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A,
617 void printMacroInstantiations();
619 bool expandStatement(
SMLoc Loc);
622 SMRange Range = std::nullopt)
const {
634 bool enabledGenDwarfForAssembly();
637 bool enterIncludeFile(
const std::string &Filename);
645 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0,
646 bool EndStatementAtEOF =
true);
660 bool parseTextItem(std::string &
Data);
665 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
666 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
667 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
669 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
671 bool parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName);
672 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
677 DK_HANDLER_DIRECTIVE,
742 DK_CV_INLINE_SITE_ID,
745 DK_CV_INLINE_LINETABLE,
750 DK_CV_FILECHECKSUM_OFFSET,
756 DK_CFI_DEF_CFA_OFFSET,
757 DK_CFI_ADJUST_CFA_OFFSET,
758 DK_CFI_DEF_CFA_REGISTER,
763 DK_CFI_REMEMBER_STATE,
764 DK_CFI_RESTORE_STATE,
768 DK_CFI_RETURN_COLUMN,
806 bool isMacroLikeDirective();
809 enum CVDefRangeType {
811 CVDR_DEFRANGE_REGISTER,
812 CVDR_DEFRANGE_FRAMEPOINTER_REL,
813 CVDR_DEFRANGE_SUBFIELD_REGISTER,
814 CVDR_DEFRANGE_REGISTER_REL
847 const MCExpr *evaluateBuiltinValue(BuiltinSymbol Symbol,
SMLoc StartLoc);
849 std::optional<std::string> evaluateBuiltinTextMacro(BuiltinSymbol Symbol,
853 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
857 bool parseScalarInitializer(
unsigned Size,
859 unsigned StringPadLength = 0);
860 bool parseScalarInstList(
863 bool emitIntegralValues(
unsigned Size,
unsigned *Count =
nullptr);
866 bool parseDirectiveNamedValue(
StringRef TypeName,
unsigned Size,
870 bool emitRealValues(
const fltSemantics &Semantics,
unsigned *Count =
nullptr);
874 bool parseRealInstList(
877 bool parseDirectiveNamedRealValue(
StringRef TypeName,
882 bool parseOptionalAngleBracketOpen();
883 bool parseAngleBracketClose(
const Twine &Msg =
"expected '>'");
885 bool parseFieldInitializer(
const FieldInfo &
Field,
886 FieldInitializer &Initializer);
887 bool parseFieldInitializer(
const FieldInfo &
Field,
888 const IntFieldInfo &Contents,
889 FieldInitializer &Initializer);
890 bool parseFieldInitializer(
const FieldInfo &
Field,
891 const RealFieldInfo &Contents,
892 FieldInitializer &Initializer);
893 bool parseFieldInitializer(
const FieldInfo &
Field,
894 const StructFieldInfo &Contents,
895 FieldInitializer &Initializer);
897 bool parseStructInitializer(
const StructInfo &Structure,
898 StructInitializer &Initializer);
899 bool parseStructInstList(
900 const StructInfo &Structure, std::vector<StructInitializer> &Initializers,
903 bool emitFieldValue(
const FieldInfo &
Field);
904 bool emitFieldValue(
const FieldInfo &
Field,
const IntFieldInfo &Contents);
905 bool emitFieldValue(
const FieldInfo &
Field,
const RealFieldInfo &Contents);
906 bool emitFieldValue(
const FieldInfo &
Field,
const StructFieldInfo &Contents);
908 bool emitFieldInitializer(
const FieldInfo &
Field,
909 const FieldInitializer &Initializer);
910 bool emitFieldInitializer(
const FieldInfo &
Field,
911 const IntFieldInfo &Contents,
912 const IntFieldInfo &Initializer);
913 bool emitFieldInitializer(
const FieldInfo &
Field,
914 const RealFieldInfo &Contents,
915 const RealFieldInfo &Initializer);
916 bool emitFieldInitializer(
const FieldInfo &
Field,
917 const StructFieldInfo &Contents,
918 const StructFieldInfo &Initializer);
920 bool emitStructInitializer(
const StructInfo &Structure,
921 const StructInitializer &Initializer);
924 bool emitStructValues(
const StructInfo &Structure,
unsigned *Count =
nullptr);
925 bool addStructField(
StringRef Name,
const StructInfo &Structure);
926 bool parseDirectiveStructValue(
const StructInfo &Structure,
928 bool parseDirectiveNamedStructValue(
const StructInfo &Structure,
934 DirectiveKind DirKind,
SMLoc NameLoc);
936 bool parseDirectiveOrg();
938 bool emitAlignTo(int64_t Alignment);
939 bool parseDirectiveAlign();
940 bool parseDirectiveEven();
943 bool parseDirectiveFile(
SMLoc DirectiveLoc);
944 bool parseDirectiveLine();
945 bool parseDirectiveLoc();
946 bool parseDirectiveStabs();
950 bool parseDirectiveCVFile();
951 bool parseDirectiveCVFuncId();
952 bool parseDirectiveCVInlineSiteId();
953 bool parseDirectiveCVLoc();
954 bool parseDirectiveCVLinetable();
955 bool parseDirectiveCVInlineLinetable();
956 bool parseDirectiveCVDefRange();
957 bool parseDirectiveCVString();
958 bool parseDirectiveCVStringTable();
959 bool parseDirectiveCVFileChecksums();
960 bool parseDirectiveCVFileChecksumOffset();
961 bool parseDirectiveCVFPOData();
964 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
965 bool parseDirectiveCFIWindowSave(
SMLoc DirectiveLoc);
966 bool parseDirectiveCFISections();
967 bool parseDirectiveCFIStartProc();
968 bool parseDirectiveCFIEndProc();
969 bool parseDirectiveCFIDefCfaOffset(
SMLoc DirectiveLoc);
970 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
971 bool parseDirectiveCFIAdjustCfaOffset(
SMLoc DirectiveLoc);
972 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
973 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
974 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
975 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
976 bool parseDirectiveCFIRememberState(
SMLoc DirectiveLoc);
977 bool parseDirectiveCFIRestoreState(
SMLoc DirectiveLoc);
978 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
979 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
980 bool parseDirectiveCFIEscape(
SMLoc DirectiveLoc);
981 bool parseDirectiveCFIReturnColumn(
SMLoc DirectiveLoc);
982 bool parseDirectiveCFISignalFrame();
983 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
986 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
996 bool parseDirectiveNestedEnds();
998 bool parseDirectiveExtern();
1004 bool parseDirectiveComm(
bool IsLocal);
1006 bool parseDirectiveComment(
SMLoc DirectiveLoc);
1008 bool parseDirectiveInclude();
1011 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
1013 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
1016 bool parseDirectiveIfidn(
SMLoc DirectiveLoc,
bool ExpectEqual,
1017 bool CaseInsensitive);
1019 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
1021 bool parseDirectiveElseIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
1023 bool parseDirectiveElseIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
1025 bool parseDirectiveElseIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
1028 bool parseDirectiveElseIfidn(
SMLoc DirectiveLoc,
bool ExpectEqual,
1029 bool CaseInsensitive);
1030 bool parseDirectiveElse(
SMLoc DirectiveLoc);
1031 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
1044 bool parseDirectiveWhile(
SMLoc DirectiveLoc);
1047 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &Info,
1051 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &Info);
1054 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
1057 bool parseDirectiveError(
SMLoc DirectiveLoc);
1059 bool parseDirectiveErrorIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
1061 bool parseDirectiveErrorIfdef(
SMLoc DirectiveLoc,
bool ExpectDefined);
1064 bool parseDirectiveErrorIfidn(
SMLoc DirectiveLoc,
bool ExpectEqual,
1065 bool CaseInsensitive);
1067 bool parseDirectiveErrorIfe(
SMLoc DirectiveLoc,
bool ExpectZero);
1070 bool parseDirectiveRadix(
SMLoc DirectiveLoc);
1073 bool parseDirectiveEcho(
SMLoc DirectiveLoc);
1075 void initializeDirectiveKindMap();
1076 void initializeCVDefRangeTypeMap();
1077 void initializeBuiltinSymbolMap();
1094 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
1095 CurBuffer(CB ? CB : SM.getMainFileID()),
TM(
TM) {
1103 EndStatementAtEOFStack.push_back(
true);
1115 initializeDirectiveKindMap();
1116 PlatformParser->Initialize(*
this);
1117 initializeCVDefRangeTypeMap();
1118 initializeBuiltinSymbolMap();
1120 NumOfMacroInstantiations = 0;
1123MasmParser::~MasmParser() {
1124 assert((HadError || ActiveMacros.empty()) &&
1125 "Unexpected active macro instantiation!");
1132void MasmParser::printMacroInstantiations() {
1134 for (std::vector<MacroInstantiation *>::const_reverse_iterator
1135 it = ActiveMacros.rbegin(),
1136 ie = ActiveMacros.rend();
1139 "while in macro instantiation");
1143 printPendingErrors();
1145 printMacroInstantiations();
1149 if (getTargetParser().getTargetOptions().MCNoWarn)
1151 if (getTargetParser().getTargetOptions().MCFatalWarnings)
1152 return Error(L, Msg, Range);
1154 printMacroInstantiations();
1161 printMacroInstantiations();
1165bool MasmParser::enterIncludeFile(
const std::string &Filename) {
1166 std::string IncludedFile;
1174 EndStatementAtEOFStack.push_back(
true);
1178void MasmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer,
1179 bool EndStatementAtEOF) {
1185bool MasmParser::expandMacros() {
1195 if (handleMacroInvocation(M, MacroLoc)) {
1202 std::optional<std::string> ExpandedValue;
1203 auto BuiltinIt = BuiltinSymbolMap.find(IDLower);
1204 if (BuiltinIt != BuiltinSymbolMap.end()) {
1206 evaluateBuiltinTextMacro(BuiltinIt->getValue(), Tok.
getLoc());
1208 auto VarIt = Variables.
find(IDLower);
1209 if (VarIt != Variables.
end() && VarIt->getValue().IsText) {
1210 ExpandedValue = VarIt->getValue().TextValue;
1216 std::unique_ptr<MemoryBuffer> Instantiation =
1224 EndStatementAtEOFStack.push_back(
false);
1229const AsmToken &MasmParser::Lex(ExpandKind ExpandNextToken) {
1236 if (!getTok().getString().empty() && getTok().getString().front() !=
'\n' &&
1245 if (StartOfStatement) {
1280 if (ParentIncludeLoc !=
SMLoc()) {
1281 EndStatementAtEOFStack.pop_back();
1282 jumpToLoc(ParentIncludeLoc, 0, EndStatementAtEOFStack.back());
1285 EndStatementAtEOFStack.pop_back();
1286 assert(EndStatementAtEOFStack.empty());
1292const AsmToken MasmParser::peekTok(
bool ShouldSkipSpace) {
1296 size_t ReadCount = Lexer.
peekTokens(Buf, ShouldSkipSpace);
1298 if (ReadCount == 0) {
1302 if (ParentIncludeLoc !=
SMLoc()) {
1303 EndStatementAtEOFStack.pop_back();
1304 jumpToLoc(ParentIncludeLoc, 0, EndStatementAtEOFStack.back());
1305 return peekTok(ShouldSkipSpace);
1307 EndStatementAtEOFStack.pop_back();
1308 assert(EndStatementAtEOFStack.empty());
1315bool MasmParser::enabledGenDwarfForAssembly() {
1317 if (!getContext().getGenDwarfForAssembly())
1322 if (getContext().getGenDwarfFileNumber() == 0) {
1325 if (!FirstCppHashFilename.
empty())
1326 getContext().setMCLineTableRootFile(
1327 0, getContext().getCompilationDir(), FirstCppHashFilename,
1328 std::nullopt, std::nullopt);
1330 getContext().getMCDwarfLineTable(0).getRootFile();
1331 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
1332 0, getContext().getCompilationDir(), RootFile.
Name,
1338bool MasmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
1340 if (!NoInitialTextSection)
1347 AsmCond StartingCondState = TheCondState;
1354 if (getContext().getGenDwarfForAssembly()) {
1355 MCSection *Sec = getStreamer().getCurrentSectionOnly();
1357 MCSymbol *SectionStartSym = getContext().createTempSymbol();
1358 getStreamer().emitLabel(SectionStartSym);
1361 bool InsertResult = getContext().addGenDwarfSection(Sec);
1362 assert(InsertResult &&
".text section should not have debug info yet");
1366 getTargetParser().onBeginOfFile();
1375 ParseStatementInfo
Info(&AsmStrRewrites);
1376 bool Parsed = parseStatement(Info,
nullptr);
1386 printPendingErrors();
1389 if (Parsed && !getLexer().isAtStartOfStatement())
1390 eatToEndOfStatement();
1393 getTargetParser().onEndOfFile();
1394 printPendingErrors();
1397 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1399 getTargetParser().flushPendingInstructions(getStreamer());
1403 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1405 const auto &LineTables = getContext().getMCDwarfLineTables();
1406 if (!LineTables.empty()) {
1408 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1410 printError(getTok().getLoc(),
"unassigned file number: " +
1412 " for .file directives");
1428 if (
Sym->isTemporary() && !
Sym->isVariable() && !
Sym->isDefined())
1432 printError(getTok().getLoc(),
"assembler local symbol '" +
1433 Sym->getName() +
"' not defined");
1439 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1440 if (std::get<2>(LocSym)->isUndefined()) {
1443 CppHashInfo = std::get<1>(LocSym);
1444 printError(std::get<0>(LocSym),
"directional label undefined");
1451 if (!HadError && !NoFinalize)
1454 return HadError || getContext().hadError();
1457bool MasmParser::checkForValidSection() {
1458 if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) {
1460 return Error(getTok().getLoc(),
1461 "expected section directive before assembly directive");
1467void MasmParser::eatToEndOfStatement() {
1471 if (ParentIncludeLoc ==
SMLoc()) {
1475 EndStatementAtEOFStack.pop_back();
1476 jumpToLoc(ParentIncludeLoc, 0, EndStatementAtEOFStack.back());
1490 const char *Start = getTok().getLoc().getPointer();
1491 while (Lexer.
isNot(EndTok)) {
1494 if (ParentIncludeLoc ==
SMLoc()) {
1497 Refs.
emplace_back(Start, getTok().getLoc().getPointer() - Start);
1499 EndStatementAtEOFStack.pop_back();
1500 jumpToLoc(ParentIncludeLoc, 0, EndStatementAtEOFStack.back());
1502 Start = getTok().getLoc().getPointer();
1507 Refs.
emplace_back(Start, getTok().getLoc().getPointer() - Start);
1515 Str.append(S.str());
1520StringRef MasmParser::parseStringToEndOfStatement() {
1521 const char *Start = getTok().getLoc().getPointer();
1526 const char *
End = getTok().getLoc().getPointer();
1535bool MasmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1536 if (parseExpression(Res))
1539 return parseRParen();
1547bool MasmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
1548 if (parseExpression(Res))
1550 EndLoc = getTok().getEndLoc();
1551 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1564bool MasmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc,
1566 SMLoc FirstTokenLoc = getLexer().getLoc();
1568 switch (FirstTokenKind) {
1570 return TokError(
"unknown token in expression");
1576 if (parsePrimaryExpr(Res, EndLoc,
nullptr))
1584 if (parseIdentifier(Identifier)) {
1595 EndLoc = FirstTokenLoc;
1598 return Error(FirstTokenLoc,
"invalid token in expression");
1603 if (parsePrimaryExpr(Res, EndLoc,
nullptr))
1611 bool Before =
Identifier.equals_insensitive(
"@b");
1612 MCSymbol *
Sym = getContext().getDirectionalLocalSymbol(0, Before);
1613 if (Before &&
Sym->isUndefined())
1614 return Error(FirstTokenLoc,
"Expected @@ label before @B reference");
1619 std::pair<StringRef, StringRef>
Split;
1625 parseIdentifier(VName);
1628 "unexpected token in variant, expected ')'"))
1630 Split = std::make_pair(Identifier, VName);
1638 return Error(getLexer().getLoc(),
"expected a symbol reference");
1643 if (!
Split.second.empty()) {
1651 "invalid variant '" +
Split.second +
"'");
1658 if (
Split.second.empty()) {
1661 if (lookUpField(SymbolName,
Split.second, Info)) {
1662 std::pair<StringRef, StringRef> BaseMember =
Split.second.split(
'.');
1664 lookUpField(
Base, Member, Info);
1672 MCSymbol *
Sym = getContext().getInlineAsmLabel(SymbolName);
1675 auto BuiltinIt = BuiltinSymbolMap.find(
SymbolName.lower());
1676 const BuiltinSymbol
Symbol = (BuiltinIt == BuiltinSymbolMap.end())
1678 : BuiltinIt->getValue();
1679 if (Symbol != BI_NO_SYMBOL) {
1680 const MCExpr *
Value = evaluateBuiltinValue(Symbol, FirstTokenLoc);
1690 if (VarIt != Variables.
end())
1692 Sym = getContext().getOrCreateSymbol(SymbolName);
1697 if (
Sym->isVariable()) {
1698 auto V =
Sym->getVariableValue(
false);
1699 bool DoInline = isa<MCConstantExpr>(V) && !
Variant;
1700 if (
auto TV = dyn_cast<MCTargetExpr>(V))
1701 DoInline = TV->inlineAssignedExpr();
1704 return Error(EndLoc,
"unexpected modifier on variable reference");
1705 Res =
Sym->getVariableValue(
false);
1721 if (
Info.Type.Name.empty()) {
1723 if (TypeIt != KnownType.
end()) {
1724 Info.Type = TypeIt->second;
1728 *TypeInfo =
Info.Type;
1733 return TokError(
"literal value out of range for directive");
1735 int64_t
IntVal = getTok().getIntVal();
1743 SMLoc ValueLoc = getTok().getLoc();
1745 if (parseEscapedString(
Value))
1747 if (
Value.size() > 8)
1748 return Error(ValueLoc,
"literal value out of range");
1750 for (
const unsigned char CharVal :
Value)
1751 IntValue = (IntValue << 8) | CharVal;
1756 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1775 return parseParenExpr(Res, EndLoc);
1777 if (!PlatformParser->HasBracketExpressions())
1778 return TokError(
"brackets expression not supported on this target");
1780 return parseBracketExpr(Res, EndLoc);
1783 if (parsePrimaryExpr(Res, EndLoc,
nullptr))
1789 if (parsePrimaryExpr(Res, EndLoc,
nullptr))
1795 if (parsePrimaryExpr(Res, EndLoc,
nullptr))
1827 return TokError(
"expected '(' after operator");
1829 if (parseExpression(Res, EndLoc))
1833 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1838bool MasmParser::parseExpression(
const MCExpr *&Res) {
1840 return parseExpression(Res, EndLoc);
1851 "Argument to the function cannot be a NULL value");
1853 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1854 (*CharPtr !=
'\0')) {
1855 if (*CharPtr ==
'!')
1859 if (*CharPtr ==
'>') {
1869 for (
size_t Pos = 0; Pos < BracketContents.
size(); Pos++) {
1870 if (BracketContents[Pos] ==
'!')
1872 Res += BracketContents[Pos];
1887bool MasmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1890 if (getTargetParser().parsePrimaryExpr(Res, EndLoc) ||
1891 parseBinOpRHS(1, Res, EndLoc))
1897 if (Res->evaluateAsAbsolute(
Value))
1903bool MasmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1905 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1908bool MasmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1910 if (parseParenExpr(Res, EndLoc))
1913 for (; ParenDepth > 0; --ParenDepth) {
1914 if (parseBinOpRHS(1, Res, EndLoc))
1919 if (ParenDepth - 1 > 0) {
1920 EndLoc = getTok().getEndLoc();
1928bool MasmParser::parseAbsoluteExpression(int64_t &Res) {
1932 if (parseExpression(Expr))
1935 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1936 return Error(StartLoc,
"expected absolute expression");
1943 bool ShouldUseLogicalShr,
1944 bool EndExpressionAtGreater) {
1972 if (EndExpressionAtGreater)
2013 if (EndExpressionAtGreater)
2024 AngleBracketDepth > 0);
2029bool MasmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
2051 unsigned TokPrec = getBinOpPrecedence(TokKind, Kind);
2055 if (TokPrec < Precedence)
2062 if (getTargetParser().parsePrimaryExpr(RHS, EndLoc))
2068 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
2069 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
2082bool MasmParser::parseStatement(ParseStatementInfo &Info,
2084 assert(!hasPendingError() &&
"parseStatement started with pending error");
2090 if (getTok().getString().empty() || getTok().getString().front() ==
'\r' ||
2091 getTok().getString().front() ==
'\n')
2100 SMLoc ExpansionLoc = getTok().getLoc();
2111 return parseCppHashLineFilenameComment(IDLoc);
2118 IDVal = getTok().getString();
2121 return Error(IDLoc,
"unexpected token at start of statement");
2122 }
else if (parseIdentifier(IDVal, StartOfStatement)) {
2123 if (!TheCondState.
Ignore) {
2125 return Error(IDLoc,
"unexpected token at start of statement");
2134 DirectiveKindMap.find(IDVal.
lower());
2135 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
2137 : DirKindIt->getValue();
2143 return parseDirectiveIf(IDLoc, DirKind);
2145 return parseDirectiveIfb(IDLoc,
true);
2147 return parseDirectiveIfb(IDLoc,
false);
2149 return parseDirectiveIfdef(IDLoc,
true);
2151 return parseDirectiveIfdef(IDLoc,
false);
2153 return parseDirectiveIfidn(IDLoc,
false,
2156 return parseDirectiveIfidn(IDLoc,
false,
2159 return parseDirectiveIfidn(IDLoc,
true,
2162 return parseDirectiveIfidn(IDLoc,
true,
2166 return parseDirectiveElseIf(IDLoc, DirKind);
2168 return parseDirectiveElseIfb(IDLoc,
true);
2170 return parseDirectiveElseIfb(IDLoc,
false);
2172 return parseDirectiveElseIfdef(IDLoc,
true);
2174 return parseDirectiveElseIfdef(IDLoc,
false);
2176 return parseDirectiveElseIfidn(IDLoc,
false,
2179 return parseDirectiveElseIfidn(IDLoc,
false,
2182 return parseDirectiveElseIfidn(IDLoc,
true,
2185 return parseDirectiveElseIfidn(IDLoc,
true,
2188 return parseDirectiveElse(IDLoc);
2190 return parseDirectiveEndIf(IDLoc);
2195 if (TheCondState.
Ignore) {
2196 eatToEndOfStatement();
2206 if (checkForValidSection())
2214 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
2222 if (ParsingMSInlineAsm && SI) {
2224 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
2226 "We should have an internal name here.");
2229 IDVal = RewrittenLabel;
2232 if (IDVal ==
"@@") {
2235 Sym = getContext().getOrCreateSymbol(IDVal);
2254 getTargetParser().doBeforeLabelEmit(
Sym, IDLoc);
2257 if (!getTargetParser().isParsingMSInlineAsm())
2262 if (enabledGenDwarfForAssembly())
2266 getTargetParser().onLabelParsed(
Sym);
2273 return handleMacroEntry(M, IDLoc);
2278 if (DirKind != DK_NO_DIRECTIVE) {
2290 getTargetParser().flushPendingInstructions(getStreamer());
2296 return parseDirectiveNestedEnds();
2301 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
2304 return (*Handler.second)(Handler.first, IDVal, IDLoc);
2310 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
2312 "Should only return Failure iff there was an error");
2324 return parseDirectiveAscii(IDVal,
false);
2327 return parseDirectiveAscii(IDVal,
true);
2331 return parseDirectiveValue(IDVal, 1);
2335 return parseDirectiveValue(IDVal, 2);
2339 return parseDirectiveValue(IDVal, 4);
2342 return parseDirectiveValue(IDVal, 6);
2346 return parseDirectiveValue(IDVal, 8);
2348 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle(), 4);
2350 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble(), 8);
2352 return parseDirectiveRealValue(IDVal, APFloat::x87DoubleExtended(), 10);
2355 return parseDirectiveNestedStruct(IDVal, DirKind);
2357 return parseDirectiveNestedEnds();
2359 return parseDirectiveAlign();
2361 return parseDirectiveEven();
2363 return parseDirectiveOrg();
2365 return parseDirectiveExtern();
2367 return parseDirectiveSymbolAttribute(
MCSA_Global);
2369 return parseDirectiveComm(
false);
2371 return parseDirectiveComment(IDLoc);
2373 return parseDirectiveInclude();
2375 return parseDirectiveRepeat(IDLoc, IDVal);
2377 return parseDirectiveWhile(IDLoc);
2379 return parseDirectiveFor(IDLoc, IDVal);
2381 return parseDirectiveForc(IDLoc, IDVal);
2383 return parseDirectiveFile(IDLoc);
2385 return parseDirectiveLine();
2387 return parseDirectiveLoc();
2389 return parseDirectiveStabs();
2391 return parseDirectiveCVFile();
2393 return parseDirectiveCVFuncId();
2394 case DK_CV_INLINE_SITE_ID:
2395 return parseDirectiveCVInlineSiteId();
2397 return parseDirectiveCVLoc();
2398 case DK_CV_LINETABLE:
2399 return parseDirectiveCVLinetable();
2400 case DK_CV_INLINE_LINETABLE:
2401 return parseDirectiveCVInlineLinetable();
2402 case DK_CV_DEF_RANGE:
2403 return parseDirectiveCVDefRange();
2405 return parseDirectiveCVString();
2406 case DK_CV_STRINGTABLE:
2407 return parseDirectiveCVStringTable();
2408 case DK_CV_FILECHECKSUMS:
2409 return parseDirectiveCVFileChecksums();
2410 case DK_CV_FILECHECKSUM_OFFSET:
2411 return parseDirectiveCVFileChecksumOffset();
2412 case DK_CV_FPO_DATA:
2413 return parseDirectiveCVFPOData();
2414 case DK_CFI_SECTIONS:
2415 return parseDirectiveCFISections();
2416 case DK_CFI_STARTPROC:
2417 return parseDirectiveCFIStartProc();
2418 case DK_CFI_ENDPROC:
2419 return parseDirectiveCFIEndProc();
2420 case DK_CFI_DEF_CFA:
2421 return parseDirectiveCFIDefCfa(IDLoc);
2422 case DK_CFI_DEF_CFA_OFFSET:
2423 return parseDirectiveCFIDefCfaOffset(IDLoc);
2424 case DK_CFI_ADJUST_CFA_OFFSET:
2425 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2426 case DK_CFI_DEF_CFA_REGISTER:
2427 return parseDirectiveCFIDefCfaRegister(IDLoc);
2429 return parseDirectiveCFIOffset(IDLoc);
2430 case DK_CFI_REL_OFFSET:
2431 return parseDirectiveCFIRelOffset(IDLoc);
2432 case DK_CFI_PERSONALITY:
2433 return parseDirectiveCFIPersonalityOrLsda(
true);
2435 return parseDirectiveCFIPersonalityOrLsda(
false);
2436 case DK_CFI_REMEMBER_STATE:
2437 return parseDirectiveCFIRememberState(IDLoc);
2438 case DK_CFI_RESTORE_STATE:
2439 return parseDirectiveCFIRestoreState(IDLoc);
2440 case DK_CFI_SAME_VALUE:
2441 return parseDirectiveCFISameValue(IDLoc);
2442 case DK_CFI_RESTORE:
2443 return parseDirectiveCFIRestore(IDLoc);
2445 return parseDirectiveCFIEscape(IDLoc);
2446 case DK_CFI_RETURN_COLUMN:
2447 return parseDirectiveCFIReturnColumn(IDLoc);
2448 case DK_CFI_SIGNAL_FRAME:
2449 return parseDirectiveCFISignalFrame();
2450 case DK_CFI_UNDEFINED:
2451 return parseDirectiveCFIUndefined(IDLoc);
2452 case DK_CFI_REGISTER:
2453 return parseDirectiveCFIRegister(IDLoc);
2454 case DK_CFI_WINDOW_SAVE:
2455 return parseDirectiveCFIWindowSave(IDLoc);
2457 Info.ExitValue =
"";
2458 return parseDirectiveExitMacro(IDLoc, IDVal, *
Info.ExitValue);
2460 Info.ExitValue =
"";
2461 return parseDirectiveEndMacro(IDVal);
2463 return parseDirectivePurgeMacro(IDLoc);
2465 return parseDirectiveEnd(IDLoc);
2467 return parseDirectiveError(IDLoc);
2469 return parseDirectiveErrorIfb(IDLoc,
true);
2471 return parseDirectiveErrorIfb(IDLoc,
false);
2473 return parseDirectiveErrorIfdef(IDLoc,
true);
2475 return parseDirectiveErrorIfdef(IDLoc,
false);
2477 return parseDirectiveErrorIfidn(IDLoc,
false,
2480 return parseDirectiveErrorIfidn(IDLoc,
false,
2483 return parseDirectiveErrorIfidn(IDLoc,
true,
2486 return parseDirectiveErrorIfidn(IDLoc,
true,
2489 return parseDirectiveErrorIfe(IDLoc,
true);
2491 return parseDirectiveErrorIfe(IDLoc,
false);
2493 return parseDirectiveRadix(IDLoc);
2495 return parseDirectiveEcho(IDLoc);
2498 return Error(IDLoc,
"unknown directive");
2502 auto IDIt = Structs.
find(IDVal.
lower());
2503 if (IDIt != Structs.
end())
2504 return parseDirectiveStructValue(IDIt->getValue(), IDVal,
2512 const AsmToken afterNextTok = peekTok();
2523 getTargetParser().flushPendingInstructions(getStreamer());
2529 return parseDirectiveEnds(IDVal, IDLoc);
2534 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
2536 if (Handler.first) {
2539 return (*Handler.second)(Handler.first, nextVal, nextLoc);
2544 DirKindIt = DirectiveKindMap.find(nextVal.
lower());
2545 DirKind = (DirKindIt == DirectiveKindMap.end())
2547 : DirKindIt->getValue();
2555 return parseDirectiveEquate(nextVal, IDVal, DirKind, IDLoc);
2566 return parseDirectiveNamedValue(nextVal, 1, IDVal, IDLoc);
2577 return parseDirectiveNamedValue(nextVal, 2, IDVal, IDLoc);
2588 return parseDirectiveNamedValue(nextVal, 4, IDVal, IDLoc);
2598 return parseDirectiveNamedValue(nextVal, 6, IDVal, IDLoc);
2609 return parseDirectiveNamedValue(nextVal, 8, IDVal, IDLoc);
2612 return parseDirectiveNamedRealValue(nextVal, APFloat::IEEEsingle(), 4,
2616 return parseDirectiveNamedRealValue(nextVal, APFloat::IEEEdouble(), 8,
2620 return parseDirectiveNamedRealValue(nextVal, APFloat::x87DoubleExtended(),
2625 return parseDirectiveStruct(nextVal, DirKind, IDVal, IDLoc);
2628 return parseDirectiveEnds(IDVal, IDLoc);
2631 return parseDirectiveMacro(IDVal, IDLoc);
2635 auto NextIt = Structs.
find(nextVal.
lower());
2636 if (NextIt != Structs.
end()) {
2638 return parseDirectiveNamedStructValue(NextIt->getValue(),
2639 nextVal, nextLoc, IDVal);
2643 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2644 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2645 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2648 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2649 return parseDirectiveMSAlign(IDLoc, Info);
2651 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2653 if (checkForValidSection())
2657 std::string OpcodeStr = IDVal.
lower();
2659 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr,
ID,
2660 Info.ParsedOperands);
2661 Info.ParseError = ParseHadError;
2664 if (getShowParsedOperands()) {
2667 OS <<
"parsed instruction: [";
2668 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2671 Info.ParsedOperands[i]->print(
OS);
2679 if (hasPendingError() || ParseHadError)
2684 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2685 getContext().getGenDwarfSectionSyms().
count(
2686 getStreamer().getCurrentSectionOnly())) {
2688 if (ActiveMacros.empty())
2692 ActiveMacros.front()->ExitBuffer);
2697 if (!CppHashInfo.Filename.empty()) {
2698 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2700 getContext().setGenDwarfFileNumber(FileNumber);
2702 unsigned CppHashLocLineNo =
2704 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2707 getStreamer().emitDwarfLocDirective(
2708 getContext().getGenDwarfFileNumber(), Line, 0,
2714 if (!ParseHadError) {
2716 if (getTargetParser().MatchAndEmitInstruction(
2718 getTargetParser().isParsingMSInlineAsm()))
2725bool MasmParser::parseCurlyBlockScope(
2744bool MasmParser::parseCppHashLineFilenameComment(
SMLoc L) {
2749 "Lexing Cpp line comment: Expected Integer");
2750 int64_t LineNumber = getTok().getIntVal();
2753 "Lexing Cpp line comment: Expected String");
2762 CppHashInfo.Loc =
L;
2764 CppHashInfo.LineNumber = LineNumber;
2765 CppHashInfo.Buf = CurBuffer;
2766 if (FirstCppHashFilename.
empty())
2773void MasmParser::DiagHandler(
const SMDiagnostic &Diag,
void *Context) {
2774 const MasmParser *Parser =
static_cast<const MasmParser *
>(
Context);
2780 unsigned CppHashBuf =
2781 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2786 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2795 if (!Parser->CppHashInfo.LineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
2796 DiagBuf != CppHashBuf) {
2797 if (Parser->SavedDiagHandler)
2798 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2807 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2810 int CppHashLocLineNo =
2811 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2813 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2819 if (Parser->SavedDiagHandler)
2820 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
2822 NewDiag.print(
nullptr,
OS);
2828 return isAlnum(
C) ||
C ==
'_' ||
C ==
'$' ||
C ==
'@' ||
C ==
'?';
2834 const std::vector<std::string> &Locals,
SMLoc L) {
2835 unsigned NParameters = Parameters.
size();
2836 if (NParameters !=
A.size())
2837 return Error(L,
"Wrong number of arguments");
2849 std::optional<char> CurrentQuote;
2850 while (!Body.
empty()) {
2852 std::size_t
End = Body.
size(), Pos = 0;
2853 std::size_t IdentifierPos =
End;
2854 for (; Pos !=
End; ++Pos) {
2857 if (Body[Pos] ==
'&')
2862 if (IdentifierPos ==
End)
2863 IdentifierPos = Pos;
2865 IdentifierPos =
End;
2869 if (!CurrentQuote) {
2870 if (Body[Pos] ==
'\'' || Body[Pos] ==
'"')
2871 CurrentQuote = Body[Pos];
2872 }
else if (Body[Pos] == CurrentQuote) {
2873 if (Pos + 1 !=
End && Body[Pos + 1] == CurrentQuote) {
2878 CurrentQuote.reset();
2882 if (IdentifierPos !=
End) {
2885 Pos = IdentifierPos;
2886 IdentifierPos =
End;
2897 bool InitialAmpersand = (Body[
I] ==
'&');
2898 if (InitialAmpersand) {
2905 const char *Begin = Body.
data() + Pos;
2907 const std::string ArgumentLower =
Argument.lower();
2911 if (Parameters[
Index].
Name.equals_insensitive(ArgumentLower))
2914 if (
Index == NParameters) {
2915 if (InitialAmpersand)
2917 auto it = LocalSymbols.
find(ArgumentLower);
2918 if (it != LocalSymbols.
end())
2934 OS << Token.getIntVal();
2936 OS << Token.getString();
2940 if (Pos <
End && Body[Pos] ==
'&') {
2983class AsmLexerSkipSpaceRAII {
2985 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2989 ~AsmLexerSkipSpaceRAII() {
3000 MCAsmMacroArgument &MA,
3003 if (Lexer.
isNot(EndTok)) {
3014 const char *StrChar = StrLoc.
getPointer() + 1;
3015 const char *EndChar = EndLoc.
getPointer() - 1;
3016 jumpToLoc(EndLoc, CurBuffer, EndStatementAtEOFStack.back());
3023 unsigned ParenLevel = 0;
3026 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
3033 return TokError(
"unexpected token");
3035 if (ParenLevel == 0) {
3049 MA.push_back(getTok());
3075 MA.push_back(getTok());
3079 if (ParenLevel != 0)
3080 return TokError(
"unbalanced parentheses in argument");
3082 if (MA.empty() && MP) {
3084 return TokError(
"missing value for required parameter '" + MP->
Name +
3094bool MasmParser::parseMacroArguments(
const MCAsmMacro *M,
3095 MCAsmMacroArguments &
A,
3097 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
3098 bool NamedParametersFound =
false;
3101 A.resize(NParameters);
3102 FALocs.
resize(NParameters);
3107 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
3113 if (parseIdentifier(FA.
Name))
3114 return Error(IDLoc,
"invalid argument identifier for formal argument");
3117 return TokError(
"expected '=' after formal parameter identifier");
3121 NamedParametersFound =
true;
3124 if (NamedParametersFound && FA.
Name.
empty())
3125 return Error(IDLoc,
"cannot mix positional and keyword arguments");
3127 unsigned PI = Parameter;
3129 assert(M &&
"expected macro to be defined");
3131 for (FAI = 0; FAI < NParameters; ++FAI)
3132 if (
M->Parameters[FAI].Name == FA.
Name)
3135 if (FAI >= NParameters) {
3136 return Error(IDLoc,
"parameter named '" + FA.
Name +
3137 "' does not exist for macro '" +
M->Name +
"'");
3142 if (M && PI < NParameters)
3143 MP = &
M->Parameters[PI];
3148 const MCExpr *AbsoluteExp;
3152 if (parseExpression(AbsoluteExp, EndLoc))
3154 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
3155 getStreamer().getAssemblerPtr()))
3156 return Error(StrLoc,
"expected absolute expression");
3161 FA.
Value.push_back(newToken);
3162 }
else if (parseMacroArgument(MP, FA.
Value, EndTok)) {
3164 return addErrorSuffix(
" in '" +
M->Name +
"' macro");
3169 if (!FA.
Value.empty()) {
3174 if (FALocs.
size() <= PI)
3177 FALocs[PI] = Lexer.
getLoc();
3183 if (Lexer.
is(EndTok)) {
3185 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
3186 if (
A[FAI].empty()) {
3187 if (
M->Parameters[FAI].Required) {
3189 "missing value for required parameter "
3191 M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
3195 if (!
M->Parameters[FAI].Value.empty())
3196 A[FAI] =
M->Parameters[FAI].Value;
3206 return TokError(
"too many positional arguments");
3214 if (ActiveMacros.size() == MaxNestingDepth) {
3215 std::ostringstream MaxNestingDepthError;
3216 MaxNestingDepthError <<
"macros cannot be nested more than "
3217 << MaxNestingDepth <<
" levels deep."
3218 <<
" Use -asm-macro-max-nesting-depth to increase "
3220 return TokError(MaxNestingDepthError.str());
3223 MCAsmMacroArguments
A;
3224 if (parseMacroArguments(M,
A, ArgumentEndTok))
3233 if (expandMacro(
OS, Body,
M->Parameters,
A,
M->Locals, getTok().getLoc()))
3240 std::unique_ptr<MemoryBuffer> Instantiation =
3245 MacroInstantiation *
MI =
new MacroInstantiation{
3246 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
3247 ActiveMacros.push_back(
MI);
3249 ++NumOfMacroInstantiations;
3254 EndStatementAtEOFStack.push_back(
true);
3260void MasmParser::handleMacroExit() {
3262 EndStatementAtEOFStack.pop_back();
3263 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer,
3264 EndStatementAtEOFStack.back());
3268 delete ActiveMacros.back();
3269 ActiveMacros.pop_back();
3272bool MasmParser::handleMacroInvocation(
const MCAsmMacro *M,
SMLoc NameLoc) {
3274 return Error(NameLoc,
"cannot invoke macro procedure as function");
3277 "' requires arguments in parentheses") ||
3282 std::string ExitValue;
3285 ParseStatementInfo
Info(&AsmStrRewrites);
3286 bool Parsed = parseStatement(Info,
nullptr);
3288 if (!Parsed &&
Info.ExitValue) {
3289 ExitValue = std::move(*
Info.ExitValue);
3301 printPendingErrors();
3304 if (Parsed && !getLexer().isAtStartOfStatement())
3305 eatToEndOfStatement();
3314 std::unique_ptr<MemoryBuffer> MacroValue =
3322 EndStatementAtEOFStack.push_back(
false);
3331bool MasmParser::parseIdentifier(
StringRef &Res,
3332 IdentifierPositionKind Position) {
3339 SMLoc PrefixLoc = getLexer().getLoc();
3364 Res = getTok().getIdentifier();
3368 ExpandKind ExpandNextToken = ExpandMacros;
3369 if (Position == StartOfStatement &&
3371 .CaseLower(
"echo",
true)
3372 .CasesLower(
"ifdef",
"ifndef",
"elseifdef",
"elseifndef",
true)
3374 ExpandNextToken = DoNotExpandMacros;
3376 Lex(ExpandNextToken);
3387 DirectiveKind DirKind,
SMLoc NameLoc) {
3388 auto BuiltinIt = BuiltinSymbolMap.find(
Name.lower());
3389 if (BuiltinIt != BuiltinSymbolMap.end())
3390 return Error(NameLoc,
"cannot redefine a built-in symbol");
3392 Variable &Var = Variables[
Name.lower()];
3393 if (Var.Name.empty()) {
3398 if (DirKind == DK_EQU || DirKind == DK_TEXTEQU) {
3401 std::string TextItem;
3402 if (!parseTextItem(TextItem)) {
3406 auto parseItem = [&]() ->
bool {
3407 if (parseTextItem(TextItem))
3408 return TokError(
"expected text item");
3413 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3415 if (!Var.IsText || Var.TextValue !=
Value) {
3416 switch (Var.Redefinable) {
3417 case Variable::NOT_REDEFINABLE:
3418 return Error(getTok().getLoc(),
"invalid variable redefinition");
3419 case Variable::WARN_ON_REDEFINITION:
3421 "', already defined on the command line")) {
3430 Var.TextValue =
Value;
3431 Var.Redefinable = Variable::REDEFINABLE;
3436 if (DirKind == DK_TEXTEQU)
3437 return TokError(
"expected <text> in '" +
Twine(IDVal) +
"' directive");
3442 if (parseExpression(Expr, EndLoc))
3443 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3448 if (!Expr->evaluateAsAbsolute(
Value, getStreamer().getAssemblerPtr())) {
3449 if (DirKind == DK_ASSIGN)
3452 "expected absolute expression; not all symbols have known values",
3453 {StartLoc, EndLoc});
3456 if (!Var.IsText || Var.TextValue != ExprAsString) {
3457 switch (Var.Redefinable) {
3458 case Variable::NOT_REDEFINABLE:
3459 return Error(getTok().getLoc(),
"invalid variable redefinition");
3460 case Variable::WARN_ON_REDEFINITION:
3462 "', already defined on the command line")) {
3472 Var.TextValue = ExprAsString.
str();
3473 Var.Redefinable = Variable::REDEFINABLE;
3478 MCSymbol *
Sym = getContext().getOrCreateSymbol(Var.Name);
3481 Sym->isVariable() ? dyn_cast_or_null<MCConstantExpr>(
3482 Sym->getVariableValue(
false))
3484 if (Var.IsText || !PrevValue || PrevValue->
getValue() !=
Value) {
3485 switch (Var.Redefinable) {
3486 case Variable::NOT_REDEFINABLE:
3487 return Error(getTok().getLoc(),
"invalid variable redefinition");
3488 case Variable::WARN_ON_REDEFINITION:
3490 "', already defined on the command line")) {
3500 Var.TextValue.clear();
3501 Var.Redefinable = (DirKind == DK_ASSIGN) ? Variable::REDEFINABLE
3502 : Variable::NOT_REDEFINABLE;
3504 Sym->setRedefinable(Var.Redefinable != Variable::NOT_REDEFINABLE);
3505 Sym->setVariableValue(Expr);
3506 Sym->setExternal(
false);
3511bool MasmParser::parseEscapedString(std::string &
Data) {
3516 char Quote = getTok().getString().front();
3517 StringRef Str = getTok().getStringContents();
3518 Data.reserve(Str.size());
3519 for (
size_t i = 0, e = Str.size(); i != e; ++i) {
3520 Data.push_back(Str[i]);
3521 if (Str[i] == Quote) {
3525 if (i + 1 == Str.size())
3526 return Error(getTok().getLoc(),
"missing quotation mark in string");
3527 if (Str[i + 1] == Quote)
3536bool MasmParser::parseAngleBracketString(std::string &
Data) {
3537 SMLoc EndLoc, StartLoc = getTok().getLoc();
3539 const char *StartChar = StartLoc.
getPointer() + 1;
3540 const char *EndChar = EndLoc.
getPointer() - 1;
3541 jumpToLoc(EndLoc, CurBuffer, EndStatementAtEOFStack.back());
3552bool MasmParser::parseTextItem(std::string &
Data) {
3553 switch (getTok().getKind()) {
3560 Data = std::to_string(Res);
3567 return parseAngleBracketString(
Data);
3571 SMLoc StartLoc = getTok().getLoc();
3572 if (parseIdentifier(
ID))
3576 bool Expanded =
false;
3579 auto BuiltinIt = BuiltinSymbolMap.find(
ID.lower());
3580 if (BuiltinIt != BuiltinSymbolMap.end()) {
3581 std::optional<std::string> BuiltinText =
3582 evaluateBuiltinTextMacro(BuiltinIt->getValue(), StartLoc);
3587 Data = std::move(*BuiltinText);
3594 auto VarIt = Variables.
find(
ID.lower());
3595 if (VarIt != Variables.
end()) {
3596 const Variable &Var = VarIt->getValue();
3601 Data = Var.TextValue;
3624bool MasmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
3625 auto parseOp = [&]() ->
bool {
3627 if (checkForValidSection() || parseEscapedString(
Data))
3629 getStreamer().emitBytes(
Data);
3631 getStreamer().emitBytes(
StringRef(
"\0", 1));
3635 if (parseMany(parseOp))
3636 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3644 int64_t IntValue = MCE->getValue();
3646 return Error(MCE->getLoc(),
"out of range literal value");
3647 getStreamer().emitIntValue(IntValue,
Size);
3652 getStreamer().emitIntValue(0,
Size);
3660bool MasmParser::parseScalarInitializer(
unsigned Size,
3662 unsigned StringPadLength) {
3665 if (parseEscapedString(
Value))
3668 for (
const unsigned char CharVal :
Value)
3672 for (
size_t i =
Value.size(); i < StringPadLength; ++i)
3676 if (parseExpression(
Value))
3679 getTok().getString().equals_insensitive(
"dup")) {
3684 "cannot repeat value a non-constant number of times");
3685 const int64_t Repetitions = MCE->
getValue();
3686 if (Repetitions < 0)
3688 "cannot repeat value a negative number of times");
3692 "parentheses required for 'dup' contents") ||
3693 parseScalarInstList(
Size, DuplicatedValues) || parseRParen())
3696 for (
int i = 0; i < Repetitions; ++i)
3705bool MasmParser::parseScalarInstList(
unsigned Size,
3708 while (getTok().
isNot(EndToken) &&
3711 parseScalarInitializer(
Size, Values);
3721bool MasmParser::emitIntegralValues(
unsigned Size,
unsigned *Count) {
3723 if (checkForValidSection() || parseScalarInstList(
Size, Values))
3726 for (
const auto *
Value : Values) {
3730 *Count = Values.size();
3736 StructInfo &
Struct = StructInProgress.
back();
3738 IntFieldInfo &IntInfo =
Field.Contents.IntInfo;
3742 if (parseScalarInstList(
Size, IntInfo.Values))
3745 Field.SizeOf =
Field.Type * IntInfo.Values.size();
3746 Field.LengthOf = IntInfo.Values.size();
3749 Struct.NextOffset = FieldEnd;
3757bool MasmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
3758 if (StructInProgress.
empty()) {
3760 if (emitIntegralValues(
Size))
3761 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3762 }
else if (addIntegralField(
"",
Size)) {
3763 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3771bool MasmParser::parseDirectiveNamedValue(
StringRef TypeName,
unsigned Size,
3773 if (StructInProgress.
empty()) {
3776 getStreamer().emitLabel(
Sym);
3778 if (emitIntegralValues(
Size, &Count))
3779 return addErrorSuffix(
" in '" +
Twine(TypeName) +
"' directive");
3785 Type.Length = Count;
3787 }
else if (addIntegralField(
Name,
Size)) {
3788 return addErrorSuffix(
" in '" +
Twine(TypeName) +
"' directive");
3797 return Asm.TokError(
"unknown token in expression");
3798 SMLoc ExprLoc = Asm.getTok().getLoc();
3799 APInt IntValue = Asm.getTok().getAPIntVal();
3801 if (!IntValue.
isIntN(128))
3802 return Asm.Error(ExprLoc,
"out of range literal value");
3803 if (!IntValue.
isIntN(64)) {
3819 SignLoc = getLexer().getLoc();
3823 SignLoc = getLexer().getLoc();
3828 return TokError(Lexer.
getErr());
3831 return TokError(
"unexpected token in directive");
3844 return TokError(
"invalid floating point literal");
3848 unsigned SizeInBits =
Value.getSizeInBits(Semantics);
3849 if (SizeInBits != (IDVal.
size() << 2))
3850 return TokError(
"invalid floating point literal");
3855 Res =
APInt(SizeInBits, IDVal, 16);
3857 return Warning(SignLoc,
"MASM-style hex floats ignore explicit sign");
3860 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3862 return TokError(
"invalid floating point literal");
3870 Res =
Value.bitcastToAPInt();
3875bool MasmParser::parseRealInstList(
const fltSemantics &Semantics,
3878 while (getTok().
isNot(EndToken) ||
3881 const AsmToken NextTok = peekTok();
3890 "cannot repeat value a non-constant number of times");
3891 const int64_t Repetitions = MCE->
getValue();
3892 if (Repetitions < 0)
3894 "cannot repeat value a negative number of times");
3898 "parentheses required for 'dup' contents") ||
3899 parseRealInstList(Semantics, DuplicatedValues) || parseRParen())
3902 for (
int i = 0; i < Repetitions; ++i)
3903 ValuesAsInt.
append(DuplicatedValues.
begin(), DuplicatedValues.
end());
3906 if (parseRealValue(Semantics, AsInt))
3921bool MasmParser::emitRealValues(
const fltSemantics &Semantics,
3923 if (checkForValidSection())
3927 if (parseRealInstList(Semantics, ValuesAsInt))
3930 for (
const APInt &AsInt : ValuesAsInt) {
3931 getStreamer().emitIntValue(AsInt);
3934 *Count = ValuesAsInt.size();
3941 StructInfo &
Struct = StructInProgress.
back();
3943 RealFieldInfo &RealInfo =
Field.Contents.RealInfo;
3947 if (parseRealInstList(Semantics, RealInfo.AsIntValues))
3950 Field.Type = RealInfo.AsIntValues.back().getBitWidth() / 8;
3951 Field.LengthOf = RealInfo.AsIntValues.size();
3956 Struct.NextOffset = FieldEnd;
3964bool MasmParser::parseDirectiveRealValue(
StringRef IDVal,
3967 if (StructInProgress.
empty()) {
3969 if (emitRealValues(Semantics))
3970 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3971 }
else if (addRealField(
"", Semantics,
Size)) {
3972 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
3979bool MasmParser::parseDirectiveNamedRealValue(
StringRef TypeName,
3983 if (StructInProgress.
empty()) {
3986 getStreamer().emitLabel(
Sym);
3988 if (emitRealValues(Semantics, &Count))
3989 return addErrorSuffix(
" in '" + TypeName +
"' directive");
3995 Type.Length = Count;
3997 }
else if (addRealField(
Name, Semantics,
Size)) {
3998 return addErrorSuffix(
" in '" + TypeName +
"' directive");
4003bool MasmParser::parseOptionalAngleBracketOpen() {
4006 AngleBracketDepth++;
4010 AngleBracketDepth++;
4014 AngleBracketDepth++;
4021bool MasmParser::parseAngleBracketClose(
const Twine &Msg) {
4028 AngleBracketDepth--;
4032bool MasmParser::parseFieldInitializer(
const FieldInfo &
Field,
4033 const IntFieldInfo &Contents,
4034 FieldInitializer &Initializer) {
4035 SMLoc Loc = getTok().getLoc();
4040 return Error(Loc,
"Cannot initialize scalar field with array value");
4044 }
else if (parseOptionalAngleBracketOpen()) {
4046 return Error(Loc,
"Cannot initialize scalar field with array value");
4048 parseAngleBracketClose())
4050 }
else if (
Field.LengthOf > 1 &&
Field.Type > 1) {
4051 return Error(Loc,
"Cannot initialize array field with scalar value");
4052 }
else if (parseScalarInitializer(
Field.Type, Values,
4058 return Error(Loc,
"Initializer too long for field; expected at most " +
4059 std::to_string(
Field.LengthOf) +
" elements, got " +
4060 std::to_string(Values.
size()));
4063 Values.
append(Contents.Values.begin() + Values.
size(), Contents.Values.end());
4065 Initializer = FieldInitializer(std::move(Values));
4069bool MasmParser::parseFieldInitializer(
const FieldInfo &
Field,
4070 const RealFieldInfo &Contents,
4071 FieldInitializer &Initializer) {
4073 switch (
Field.Type) {
4075 Semantics = &APFloat::IEEEsingle();
4078 Semantics = &APFloat::IEEEdouble();
4081 Semantics = &APFloat::x87DoubleExtended();
4087 SMLoc Loc = getTok().getLoc();
4091 if (
Field.LengthOf == 1)
4092 return Error(Loc,
"Cannot initialize scalar field with array value");
4096 }
else if (parseOptionalAngleBracketOpen()) {
4097 if (
Field.LengthOf == 1)
4098 return Error(Loc,
"Cannot initialize scalar field with array value");
4100 parseAngleBracketClose())
4102 }
else if (
Field.LengthOf > 1) {
4103 return Error(Loc,
"Cannot initialize array field with scalar value");
4106 if (parseRealValue(*Semantics, AsIntValues.
back()))
4110 if (AsIntValues.
size() >
Field.LengthOf) {
4111 return Error(Loc,
"Initializer too long for field; expected at most " +
4112 std::to_string(
Field.LengthOf) +
" elements, got " +
4113 std::to_string(AsIntValues.
size()));
4116 AsIntValues.
append(Contents.AsIntValues.begin() + AsIntValues.
size(),
4117 Contents.AsIntValues.end());
4119 Initializer = FieldInitializer(std::move(AsIntValues));
4123bool MasmParser::parseFieldInitializer(
const FieldInfo &
Field,
4124 const StructFieldInfo &Contents,
4125 FieldInitializer &Initializer) {
4126 SMLoc Loc = getTok().getLoc();
4128 std::vector<StructInitializer> Initializers;
4129 if (
Field.LengthOf > 1) {
4131 if (parseStructInstList(Contents.Structure, Initializers,
4135 }
else if (parseOptionalAngleBracketOpen()) {
4136 if (parseStructInstList(Contents.Structure, Initializers,
4138 parseAngleBracketClose())
4141 return Error(Loc,
"Cannot initialize array field with scalar value");
4144 Initializers.emplace_back();
4145 if (parseStructInitializer(Contents.Structure, Initializers.back()))
4149 if (Initializers.size() >
Field.LengthOf) {
4150 return Error(Loc,
"Initializer too long for field; expected at most " +
4151 std::to_string(
Field.LengthOf) +
" elements, got " +
4152 std::to_string(Initializers.size()));
4155 Initializers.insert(Initializers.end(),
4156 Contents.Initializers.begin() + Initializers.size(),
4157 Contents.Initializers.end());
4159 Initializer = FieldInitializer(std::move(Initializers), Contents.Structure);
4163bool MasmParser::parseFieldInitializer(
const FieldInfo &
Field,
4164 FieldInitializer &Initializer) {
4165 switch (
Field.Contents.FT) {
4167 return parseFieldInitializer(
Field,
Field.Contents.IntInfo, Initializer);
4169 return parseFieldInitializer(
Field,
Field.Contents.RealInfo, Initializer);
4171 return parseFieldInitializer(
Field,
Field.Contents.StructInfo, Initializer);
4176bool MasmParser::parseStructInitializer(
const StructInfo &Structure,
4177 StructInitializer &Initializer) {
4178 const AsmToken FirstToken = getTok();
4180 std::optional<AsmToken::TokenKind> EndToken;
4183 }
else if (parseOptionalAngleBracketOpen()) {
4185 AngleBracketDepth++;
4192 return Error(FirstToken.
getLoc(),
"Expected struct initializer");
4195 auto &FieldInitializers = Initializer.FieldInitializers;
4196 size_t FieldIndex = 0;
4199 while (getTok().
isNot(*EndToken) && FieldIndex < Structure.Fields.size()) {
4200 const FieldInfo &
Field = Structure.Fields[FieldIndex++];
4204 FieldInitializers.push_back(
Field.Contents);
4208 FieldInitializers.emplace_back(
Field.Contents.FT);
4209 if (parseFieldInitializer(
Field, FieldInitializers.back()))
4213 SMLoc CommaLoc = getTok().getLoc();
4216 if (FieldIndex == Structure.Fields.size())
4217 return Error(CommaLoc,
"'" + Structure.Name +
4218 "' initializer initializes too many fields");
4224 FieldInitializers.push_back(
Field.Contents);
4228 return parseAngleBracketClose();
4230 return parseToken(*EndToken);
4236bool MasmParser::parseStructInstList(
4237 const StructInfo &Structure, std::vector<StructInitializer> &Initializers,
4239 while (getTok().
isNot(EndToken) ||
4242 const AsmToken NextTok = peekTok();
4251 "cannot repeat value a non-constant number of times");
4252 const int64_t Repetitions = MCE->
getValue();
4253 if (Repetitions < 0)
4255 "cannot repeat value a negative number of times");
4257 std::vector<StructInitializer> DuplicatedValues;
4259 "parentheses required for 'dup' contents") ||
4260 parseStructInstList(Structure, DuplicatedValues) || parseRParen())
4263 for (
int i = 0; i < Repetitions; ++i)
4266 Initializers.emplace_back();
4267 if (parseStructInitializer(Structure, Initializers.back()))
4280bool MasmParser::emitFieldValue(
const FieldInfo &
Field,
4281 const IntFieldInfo &Contents) {
4290bool MasmParser::emitFieldValue(
const FieldInfo &
Field,
4291 const RealFieldInfo &Contents) {
4292 for (
const APInt &AsInt : Contents.AsIntValues) {
4299bool MasmParser::emitFieldValue(
const FieldInfo &
Field,
4300 const StructFieldInfo &Contents) {
4301 for (
const auto &Initializer : Contents.Initializers) {
4303 for (
const auto &SubField : Contents.Structure.Fields) {
4304 getStreamer().emitZeros(SubField.Offset -
Offset);
4305 Offset = SubField.Offset + SubField.SizeOf;
4306 emitFieldInitializer(SubField, Initializer.FieldInitializers[
Index++]);
4312bool MasmParser::emitFieldValue(
const FieldInfo &
Field) {
4313 switch (
Field.Contents.FT) {
4315 return emitFieldValue(
Field,
Field.Contents.IntInfo);
4317 return emitFieldValue(
Field,
Field.Contents.RealInfo);
4319 return emitFieldValue(
Field,
Field.Contents.StructInfo);
4324bool MasmParser::emitFieldInitializer(
const FieldInfo &
Field,
4325 const IntFieldInfo &Contents,
4326 const IntFieldInfo &Initializer) {
4327 for (
const auto &
Value : Initializer.Values) {
4332 for (
const auto &
Value :
4340bool MasmParser::emitFieldInitializer(
const FieldInfo &
Field,
4341 const RealFieldInfo &Contents,
4342 const RealFieldInfo &Initializer) {
4343 for (
const auto &AsInt : Initializer.AsIntValues) {
4348 for (
const auto &AsInt :
4356bool MasmParser::emitFieldInitializer(
const FieldInfo &
Field,
4357 const StructFieldInfo &Contents,
4358 const StructFieldInfo &Initializer) {
4359 for (
const auto &
Init : Initializer.Initializers) {
4360 if (emitStructInitializer(Contents.Structure,
Init))
4365 Initializer.Initializers.size())) {
4366 if (emitStructInitializer(Contents.Structure,
Init))
4372bool MasmParser::emitFieldInitializer(
const FieldInfo &
Field,
4373 const FieldInitializer &Initializer) {
4374 switch (
Field.Contents.FT) {
4376 return emitFieldInitializer(
Field,
Field.Contents.IntInfo,
4377 Initializer.IntInfo);
4379 return emitFieldInitializer(
Field,
Field.Contents.RealInfo,
4380 Initializer.RealInfo);
4382 return emitFieldInitializer(
Field,
Field.Contents.StructInfo,
4383 Initializer.StructInfo);
4388bool MasmParser::emitStructInitializer(
const StructInfo &Structure,
4389 const StructInitializer &Initializer) {
4390 if (!Structure.Initializable)
4391 return Error(getLexer().getLoc(),
4392 "cannot initialize a value of type '" + Structure.Name +
4393 "'; 'org' was used in the type's declaration");
4395 for (
const auto &
Init : Initializer.FieldInitializers) {
4396 const auto &
Field = Structure.Fields[
Index++];
4404 Structure.Fields, Initializer.FieldInitializers.size())) {
4407 if (emitFieldValue(
Field))
4411 if (
Offset != Structure.Size)
4412 getStreamer().emitZeros(Structure.Size -
Offset);
4417bool MasmParser::emitStructValues(
const StructInfo &Structure,
4419 std::vector<StructInitializer> Initializers;
4420 if (parseStructInstList(Structure, Initializers))
4423 for (
const auto &Initializer : Initializers) {
4424 if (emitStructInitializer(Structure, Initializer))
4429 *Count = Initializers.size();
4434bool MasmParser::addStructField(
StringRef Name,
const StructInfo &Structure) {
4435 StructInfo &OwningStruct = StructInProgress.
back();
4437 OwningStruct.addField(
Name, FT_STRUCT, Structure.AlignmentSize);
4438 StructFieldInfo &StructInfo =
Field.Contents.StructInfo;
4440 StructInfo.Structure = Structure;
4443 if (parseStructInstList(Structure, StructInfo.Initializers))
4446 Field.LengthOf = StructInfo.Initializers.size();
4450 if (!OwningStruct.IsUnion) {
4451 OwningStruct.NextOffset = FieldEnd;
4453 OwningStruct.Size = std::max(OwningStruct.Size, FieldEnd);
4461bool MasmParser::parseDirectiveStructValue(
const StructInfo &Structure,
4463 if (StructInProgress.
empty()) {
4464 if (emitStructValues(Structure))
4466 }
else if (addStructField(
"", Structure)) {
4467 return addErrorSuffix(
" in '" +
Twine(
Directive) +
"' directive");
4475bool MasmParser::parseDirectiveNamedStructValue(
const StructInfo &Structure,
4478 if (StructInProgress.
empty()) {
4481 getStreamer().emitLabel(
Sym);
4483 if (emitStructValues(Structure, &Count))
4486 Type.Name = Structure.Name;
4487 Type.Size = Structure.Size * Count;
4488 Type.ElementSize = Structure.Size;
4489 Type.Length = Count;
4491 }
else if (addStructField(
Name, Structure)) {
4492 return addErrorSuffix(
" in '" +
Twine(
Directive) +
"' directive");
4510 int64_t AlignmentValue = 1;
4513 parseAbsoluteExpression(AlignmentValue)) {
4514 return addErrorSuffix(
" in alignment value for '" +
Twine(
Directive) +
4518 return Error(NextTok.
getLoc(),
"alignment must be a power of two; was " +
4519 std::to_string(AlignmentValue));
4525 QualifierLoc = getTok().getLoc();
4526 if (parseIdentifier(Qualifier))
4527 return addErrorSuffix(
" in '" +
Twine(
Directive) +
"' directive");
4528 if (!
Qualifier.equals_insensitive(
"nonunique"))
4529 return Error(QualifierLoc,
"Unrecognized qualifier for '" +
4531 "' directive; expected none or NONUNIQUE");
4535 return addErrorSuffix(
" in '" +
Twine(
Directive) +
"' directive");
4546 DirectiveKind DirKind) {
4547 if (StructInProgress.
empty())
4548 return TokError(
"missing name in top-level '" +
Twine(
Directive) +
4553 Name = getTok().getIdentifier();
4557 return addErrorSuffix(
" in '" +
Twine(
Directive) +
"' directive");
4561 StructInProgress.
reserve(StructInProgress.
size() + 1);
4563 StructInProgress.
back().Alignment);
4568 if (StructInProgress.
empty())
4569 return Error(NameLoc,
"ENDS directive without matching STRUC/STRUCT/UNION");
4570 if (StructInProgress.
size() > 1)
4571 return Error(NameLoc,
"unexpected name in nested ENDS directive");
4572 if (StructInProgress.
back().Name.compare_insensitive(
Name))
4573 return Error(NameLoc,
"mismatched name in ENDS directive; expected '" +
4574 StructInProgress.
back().Name +
"'");
4575 StructInfo Structure = StructInProgress.
pop_back_val();
4579 Structure.Size, std::min(Structure.Alignment, Structure.AlignmentSize));
4580 Structs[
Name.lower()] = Structure;
4583 return addErrorSuffix(
" in ENDS directive");
4588bool MasmParser::parseDirectiveNestedEnds() {
4589 if (StructInProgress.
empty())
4590 return TokError(
"ENDS directive without matching STRUC/STRUCT/UNION");
4591 if (StructInProgress.
size() == 1)
4592 return TokError(
"missing name in top-level ENDS directive");
4595 return addErrorSuffix(
" in nested ENDS directive");
4597 StructInfo Structure = StructInProgress.
pop_back_val();
4599 Structure.Size =
llvm::alignTo(Structure.Size, Structure.Alignment);
4601 StructInfo &ParentStruct = StructInProgress.
back();
4602 if (Structure.Name.empty()) {
4605 const size_t OldFields = ParentStruct.Fields.size();
4606 ParentStruct.Fields.insert(
4607 ParentStruct.Fields.end(),
4608 std::make_move_iterator(Structure.Fields.begin()),
4609 std::make_move_iterator(Structure.Fields.end()));
4610 for (
const auto &FieldByName : Structure.FieldsByName) {
4611 ParentStruct.FieldsByName[FieldByName.getKey()] =
4612 FieldByName.getValue() + OldFields;
4615 unsigned FirstFieldOffset = 0;
4616 if (!Structure.Fields.empty() && !ParentStruct.IsUnion) {
4618 ParentStruct.NextOffset,
4619 std::min(ParentStruct.Alignment, Structure.AlignmentSize));
4622 if (ParentStruct.IsUnion) {
4623 ParentStruct.Size = std::max(ParentStruct.Size, Structure.Size);
4628 const unsigned StructureEnd = FirstFieldOffset + Structure.Size;
4629 if (!ParentStruct.IsUnion) {
4630 ParentStruct.NextOffset = StructureEnd;
4632 ParentStruct.Size = std::max(ParentStruct.Size, StructureEnd);
4635 FieldInfo &
Field = ParentStruct.addField(Structure.Name, FT_STRUCT,
4636 Structure.AlignmentSize);
4637 StructFieldInfo &StructInfo =
Field.Contents.StructInfo;
4643 if (!ParentStruct.IsUnion) {
4644 ParentStruct.NextOffset = StructureEnd;
4646 ParentStruct.Size = std::max(ParentStruct.Size, StructureEnd);
4648 StructInfo.Structure = Structure;
4649 StructInfo.Initializers.emplace_back();
4650 auto &FieldInitializers = StructInfo.Initializers.back().FieldInitializers;
4651 for (
const auto &SubField : Structure.Fields) {
4652 FieldInitializers.push_back(SubField.Contents);
4661bool MasmParser::parseDirectiveOrg() {
4664 if (checkForValidSection() || parseExpression(
Offset))
4667 return addErrorSuffix(
" in 'org' directive");
4669 if (StructInProgress.
empty()) {
4671 if (checkForValidSection())
4672 return addErrorSuffix(
" in 'org' directive");
4674 getStreamer().emitValueToOffset(
Offset, 0, OffsetLoc);
4677 StructInfo &Structure = StructInProgress.
back();
4679 if (!
Offset->evaluateAsAbsolute(OffsetRes, getStreamer().getAssemblerPtr()))
4680 return Error(OffsetLoc,
4681 "expected absolute expression in 'org' directive");
4685 "expected non-negative value in struct's 'org' directive; was " +
4686 std::to_string(OffsetRes));
4687 Structure.NextOffset =
static_cast<unsigned>(OffsetRes);
4690 Structure.Initializable =
false;
4696bool MasmParser::emitAlignTo(int64_t Alignment) {
4697 if (StructInProgress.
empty()) {
4699 if (checkForValidSection())
4705 assert(Section &&
"must have section to emit alignment");
4706 if (
Section->useCodeAlign()) {
4707 getStreamer().emitCodeAlignment(
Align(Alignment),
4708 &getTargetParser().getSTI(),
4712 getStreamer().emitValueToAlignment(
Align(Alignment), 0,
4718 StructInfo &Structure = StructInProgress.
back();
4719 Structure.NextOffset =
llvm::alignTo(Structure.NextOffset, Alignment);
4727bool MasmParser::parseDirectiveAlign() {
4728 SMLoc AlignmentLoc = getLexer().getLoc();
4734 "align directive with no operand is ignored") &&
4737 if (parseAbsoluteExpression(Alignment) || parseEOL())
4738 return addErrorSuffix(
" in align directive");
4741 bool ReturnVal =
false;
4748 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2; was " +
4749 std::to_string(Alignment));
4751 if (emitAlignTo(Alignment))
4752 ReturnVal |= addErrorSuffix(
" in align directive");
4759bool MasmParser::parseDirectiveEven() {
4760 if (parseEOL() || emitAlignTo(2))
4761 return addErrorSuffix(
" in even directive");
4769bool MasmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
4771 int64_t FileNumber = -1;
4773 FileNumber = getTok().getIntVal();
4777 return TokError(
"negative file number");
4785 "unexpected token in '.file' directive") ||
4786 parseEscapedString(Path))
4791 std::string FilenameData;
4793 if (
check(FileNumber == -1,
4794 "explicit path specified, but no file number") ||
4795 parseEscapedString(FilenameData))
4804 bool HasMD5 =
false;
4806 std::optional<StringRef>
Source;
4807 bool HasSource =
false;
4808 std::string SourceString;
4813 "unexpected token in '.file' directive") ||
4814 parseIdentifier(Keyword))
4816 if (Keyword ==
"md5") {
4818 if (
check(FileNumber == -1,
4819 "MD5 checksum specified, but no file number") ||
4822 }
else if (Keyword ==
"source") {
4824 if (
check(FileNumber == -1,
4825 "source specified, but no file number") ||
4827 "unexpected token in '.file' directive") ||
4828 parseEscapedString(SourceString))
4831 return TokError(
"unexpected token in '.file' directive");
4835 if (FileNumber == -1) {
4839 if (getContext().getAsmInfo()->hasSingleParameterDotFile())
4840 getStreamer().emitFileDirective(Filename);
4850 std::optional<MD5::MD5Result> CKMem;
4853 for (
unsigned i = 0; i != 8; ++i) {
4854 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
4855 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
4860 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
4861 memcpy(SourceBuf, SourceString.data(), SourceString.size());
4864 if (FileNumber == 0) {
4866 return Warning(DirectiveLoc,
"file 0 not supported prior to DWARF-5");
4867 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
4870 FileNumber, Directory, Filename, CKMem, Source);
4877 ReportedInconsistentMD5 =
true;
4878 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
4887bool MasmParser::parseDirectiveLine() {
4890 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
4908bool MasmParser::parseDirectiveLoc() {
4909 int64_t FileNumber = 0, LineNumber = 0;
4910 SMLoc Loc = getTok().getLoc();
4911 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
4913 "file number less than one in '.loc' directive") ||
4914 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
4915 "unassigned file number in '.loc' directive"))
4920 LineNumber = getTok().getIntVal();
4922 return TokError(
"line number less than zero in '.loc' directive");
4926 int64_t ColumnPos = 0;
4928 ColumnPos = getTok().getIntVal();
4930 return TokError(
"column position less than zero in '.loc' directive");
4934 auto PrevFlags = getContext().getCurrentDwarfLoc().getFlags();
4939 auto parseLocOp = [&]() ->
bool {
4941 SMLoc Loc = getTok().getLoc();
4942 if (parseIdentifier(
Name))
4943 return TokError(
"unexpected token in '.loc' directive");
4945 if (
Name ==
"basic_block")
4947 else if (
Name ==
"prologue_end")
4949 else if (
Name ==
"epilogue_begin")
4951 else if (
Name ==
"is_stmt") {
4952 Loc = getTok().getLoc();
4954 if (parseExpression(
Value))
4960 Flags &= ~DWARF2_FLAG_IS_STMT;
4961 else if (
Value == 1)
4964 return Error(Loc,
"is_stmt value not 0 or 1");
4966 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
4968 }
else if (
Name ==
"isa") {
4969 Loc = getTok().getLoc();
4971 if (parseExpression(
Value))
4977 return Error(Loc,
"isa number less than zero");
4980 return Error(Loc,
"isa number not a constant value");
4982 }
else if (
Name ==
"discriminator") {
4983 if (parseAbsoluteExpression(Discriminator))
4986 return Error(Loc,
"unknown sub-directive in '.loc' directive");
4991 if (parseMany(parseLocOp,
false ))
4994 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
5002bool MasmParser::parseDirectiveStabs() {
5003 return TokError(
"unsupported directive '.stabs'");
5008bool MasmParser::parseDirectiveCVFile() {
5009 SMLoc FileNumberLoc = getTok().getLoc();
5012 std::string Checksum;
5015 if (parseIntToken(FileNumber,
5016 "expected file number in '.cv_file' directive") ||
5017 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
5019 "unexpected token in '.cv_file' directive") ||
5020 parseEscapedString(Filename))
5024 "unexpected token in '.cv_file' directive") ||
5025 parseEscapedString(Checksum) ||
5026 parseIntToken(ChecksumKind,
5027 "expected checksum kind in '.cv_file' directive") ||
5032 Checksum = fromHex(Checksum);
5033 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
5034 memcpy(CKMem, Checksum.data(), Checksum.size());
5038 if (!getStreamer().emitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
5039 static_cast<uint8_t
>(ChecksumKind)))
5040 return Error(FileNumberLoc,
"file number already allocated");
5045bool MasmParser::parseCVFunctionId(int64_t &FunctionId,
5048 return parseTokenLoc(Loc) ||
5049 parseIntToken(FunctionId,
"expected function id in '" + DirectiveName +
5051 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
5052 "expected function id within range [0, UINT_MAX)");
5055bool MasmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
5057 return parseTokenLoc(Loc) ||
5058 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
5060 check(FileNumber < 1, Loc,
"file number less than one in '" +
5061 DirectiveName +
"' directive") ||
5062 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
5063 "unassigned file number in '" + DirectiveName +
"' directive");
5070bool MasmParser::parseDirectiveCVFuncId() {
5071 SMLoc FunctionIdLoc = getTok().getLoc();
5074 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
5077 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
5078 return Error(FunctionIdLoc,
"function id already allocated");
5091bool MasmParser::parseDirectiveCVInlineSiteId() {
5092 SMLoc FunctionIdLoc = getTok().getLoc();
5100 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
5105 getTok().getIdentifier() !=
"within"),
5106 "expected 'within' identifier in '.cv_inline_site_id' directive"))
5111 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
5116 getTok().getIdentifier() !=
"inlined_at"),
5117 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
5123 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
5124 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
5129 IACol = getTok().getIntVal();
5136 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
5137 IALine, IACol, FunctionIdLoc))
5138 return Error(FunctionIdLoc,
"function id already allocated");
5150bool MasmParser::parseDirectiveCVLoc() {
5151 SMLoc DirectiveLoc = getTok().getLoc();
5152 int64_t FunctionId, FileNumber;
5153 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
5154 parseCVFileId(FileNumber,
".cv_loc"))
5157 int64_t LineNumber = 0;
5159 LineNumber = getTok().getIntVal();
5161 return TokError(
"line number less than zero in '.cv_loc' directive");
5165 int64_t ColumnPos = 0;
5167 ColumnPos = getTok().getIntVal();
5169 return TokError(
"column position less than zero in '.cv_loc' directive");
5173 bool PrologueEnd =
false;
5176 auto parseOp = [&]() ->
bool {
5178 SMLoc Loc = getTok().getLoc();
5179 if (parseIdentifier(
Name))
5180 return TokError(
"unexpected token in '.cv_loc' directive");
5181 if (
Name ==
"prologue_end")
5183 else if (
Name ==
"is_stmt") {
5184 Loc = getTok().getLoc();
5186 if (parseExpression(
Value))
5190 if (
const auto *MCE = dyn_cast<MCConstantExpr>(
Value))
5194 return Error(Loc,
"is_stmt value not 0 or 1");
5196 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
5201 if (parseMany(parseOp,
false ))
5204 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
5205 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
5212bool MasmParser::parseDirectiveCVLinetable() {
5215 SMLoc Loc = getTok().getLoc();
5216 if (parseCVFunctionId(FunctionId,
".cv_linetable") ||
5218 "unexpected token in '.cv_linetable' directive") ||
5219 parseTokenLoc(Loc) ||
check(parseIdentifier(FnStartName), Loc,
5220 "expected identifier in directive") ||
5222 "unexpected token in '.cv_linetable' directive") ||
5223 parseTokenLoc(Loc) ||
check(parseIdentifier(FnEndName), Loc,
5224 "expected identifier in directive"))
5227 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
5228 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
5230 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
5236bool MasmParser::parseDirectiveCVInlineLinetable() {
5237 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
5239 SMLoc Loc = getTok().getLoc();
5240 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
5241 parseTokenLoc(Loc) ||
5244 "expected SourceField in '.cv_inline_linetable' directive") ||
5245 check(SourceFileId <= 0, Loc,
5246 "File id less than zero in '.cv_inline_linetable' directive") ||
5247 parseTokenLoc(Loc) ||
5250 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
5251 check(SourceLineNum < 0, Loc,
5252 "Line number less than zero in '.cv_inline_linetable' directive") ||
5253 parseTokenLoc(Loc) ||
check(parseIdentifier(FnStartName), Loc,
5254 "expected identifier in directive") ||
5255 parseTokenLoc(Loc) ||
check(parseIdentifier(FnEndName), Loc,
5256 "expected identifier in directive"))
5262 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
5263 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
5264 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
5265 SourceLineNum, FnStartSym,
5270void MasmParser::initializeCVDefRangeTypeMap() {
5271 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
5272 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
5273 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
5274 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
5279bool MasmParser::parseDirectiveCVDefRange() {
5281 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
5283 Loc = getLexer().getLoc();
5285 if (parseIdentifier(GapStartName))
5286 return Error(Loc,
"expected identifier in directive");
5287 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
5289 Loc = getLexer().getLoc();
5291 if (parseIdentifier(GapEndName))
5292 return Error(Loc,
"expected identifier in directive");
5293 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
5295 Ranges.push_back({GapStartSym, GapEndSym});
5301 "expected comma before def_range type in .cv_def_range directive") ||
5302 parseIdentifier(CVDefRangeTypeStr))
5303 return Error(Loc,
"expected def_range type in directive");
5306 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
5307 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
5309 : CVTypeIt->getValue();
5311 case CVDR_DEFRANGE_REGISTER: {
5313 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
5314 ".cv_def_range directive") ||
5315 parseAbsoluteExpression(DRRegister))
5316 return Error(Loc,
"expected register number");
5321 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
5324 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
5327 "expected comma before offset in .cv_def_range directive") ||
5328 parseAbsoluteExpression(DROffset))
5329 return Error(Loc,
"expected offset value");
5333 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
5336 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
5338 int64_t DROffsetInParent;
5339 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
5340 ".cv_def_range directive") ||
5341 parseAbsoluteExpression(DRRegister))
5342 return Error(Loc,
"expected register number");
5344 "expected comma before offset in .cv_def_range directive") ||
5345 parseAbsoluteExpression(DROffsetInParent))
5346 return Error(Loc,
"expected offset value");
5352 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
5355 case CVDR_DEFRANGE_REGISTER_REL: {
5358 int64_t DRBasePointerOffset;
5359 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
5360 ".cv_def_range directive") ||
5361 parseAbsoluteExpression(DRRegister))
5362 return Error(Loc,
"expected register value");
5365 "expected comma before flag value in .cv_def_range directive") ||
5366 parseAbsoluteExpression(DRFlags))
5367 return Error(Loc,
"expected flag value");
5368 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
5369 "in .cv_def_range directive") ||
5370 parseAbsoluteExpression(DRBasePointerOffset))
5371 return Error(Loc,
"expected base pointer offset value");
5375 DRHdr.
Flags = DRFlags;
5377 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
5381 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
5388bool MasmParser::parseDirectiveCVString() {
5390 if (checkForValidSection() || parseEscapedString(
Data))
5391 return addErrorSuffix(
" in '.cv_string' directive");
5394 std::pair<StringRef, unsigned> Insertion =
5395 getCVContext().addToStringTable(
Data);
5396 getStreamer().emitIntValue(Insertion.second, 4);
5402bool MasmParser::parseDirectiveCVStringTable() {
5403 getStreamer().emitCVStringTableDirective();
5409bool MasmParser::parseDirectiveCVFileChecksums() {
5410 getStreamer().emitCVFileChecksumsDirective();
5416bool MasmParser::parseDirectiveCVFileChecksumOffset() {
5418 if (parseIntToken(FileNo,
"expected identifier in directive"))
5422 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
5428bool MasmParser::parseDirectiveCVFPOData() {
5429 SMLoc DirLoc = getLexer().getLoc();
5431 if (parseIdentifier(ProcName))
5432 return TokError(
"expected symbol name");
5433 if (parseEOL(
"unexpected tokens"))
5434 return addErrorSuffix(
" in '.cv_fpo_data' directive");
5435 MCSymbol *ProcSym = getContext().getOrCreateSymbol(ProcName);
5436 getStreamer().emitCVFPOData(ProcSym, DirLoc);
5442bool MasmParser::parseDirectiveCFISections() {