81typedef std::vector<AsmToken> MCAsmMacroArgument;
82typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
86struct MacroInstantiation {
88 SMLoc InstantiationLoc;
97 size_t CondStackDepth;
100struct ParseStatementInfo {
105 unsigned Opcode = ~0
U;
108 bool ParseError =
false;
110 SmallVectorImpl<AsmRewrite> *AsmRewrites =
nullptr;
112 ParseStatementInfo() =
delete;
113 ParseStatementInfo(SmallVectorImpl<AsmRewrite> *rewrites)
114 : AsmRewrites(rewrites) {}
121 void *SavedDiagContext;
122 std::unique_ptr<MCAsmParserExtension> PlatformParser;
124 std::optional<SMLoc> CFIStartProcLoc;
130 AsmCond TheCondState;
131 std::vector<AsmCond> TheCondStack;
136 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
139 std::vector<MacroInstantiation*> ActiveMacros;
142 std::deque<MCAsmMacro> MacroLikeBodies;
145 unsigned MacrosEnabledFlag : 1;
148 unsigned NumOfMacroInstantiations = 0;
151 struct CppHashInfoTy {
156 CppHashInfoTy() : LineNumber(0), Buf(0) {}
158 CppHashInfoTy CppHashInfo;
161 bool HadCppHashFilename =
false;
166 SmallSet<StringRef, 2> LTODiscardSymbols;
169 unsigned AssemblerDialect = ~0
U;
172 bool IsDarwin =
false;
175 bool ParsingMSInlineAsm =
false;
178 bool ReportedInconsistentMD5 =
false;
181 bool AltMacroMode =
false;
184 virtual bool parseStatement(ParseStatementInfo &
Info,
185 MCAsmParserSemaCallback *SI);
190 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &
Info,
191 StringRef IDVal, AsmToken
ID,
197 bool enabledGenDwarfForAssembly();
200 AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
201 const MCAsmInfo &MAI,
unsigned CB);
202 AsmParser(
const AsmParser &) =
delete;
203 AsmParser &operator=(
const AsmParser &) =
delete;
204 ~AsmParser()
override;
206 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
208 void addDirectiveHandler(StringRef Directive,
209 ExtensionDirectiveHandler Handler)
override {
210 ExtensionDirectiveMap[Directive] = Handler;
213 void addAliasForDirective(StringRef Directive, StringRef Alias)
override {
214 DirectiveKindMap[Directive.
lower()] = DirectiveKindMap[Alias.
lower()];
220 CodeViewContext &getCVContext() {
return Ctx.getCVContext(); }
222 unsigned getAssemblerDialect()
override {
223 if (AssemblerDialect == ~0U)
224 return MAI.getAssemblerDialect();
226 return AssemblerDialect;
228 void setAssemblerDialect(
unsigned i)
override {
229 AssemblerDialect = i;
232 void Note(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
233 bool Warning(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
234 bool printError(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
236 const AsmToken &Lex()
override;
238 void setParsingMSInlineAsm(
bool V)
override {
239 ParsingMSInlineAsm =
V;
242 Lexer.setLexMasmIntegers(V);
244 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
246 bool discardLTOSymbol(StringRef Name)
const override {
247 return LTODiscardSymbols.contains(Name);
250 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
252 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
253 SmallVectorImpl<std::string> &Constraints,
254 SmallVectorImpl<std::string> &Clobbers,
255 const MCInstrInfo *MII, MCInstPrinter *IP,
256 MCAsmParserSemaCallback &SI)
override;
258 bool parseExpression(
const MCExpr *&Res);
259 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
260 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
261 AsmTypeInfo *TypeInfo)
override;
262 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
263 bool parseAbsoluteExpression(int64_t &Res)
override;
267 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
271 bool parseIdentifier(StringRef &Res)
override;
272 void eatToEndOfStatement()
override;
274 bool checkForValidSection()
override;
279 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
280 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
282 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
284 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
289 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
292 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
295 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
301 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
304 void handleMacroExit();
307 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
310 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
312 void printMacroInstantiations();
314 SMRange
Range = {})
const {
321 bool enterIncludeFile(
const std::string &
Filename);
325 bool processIncbinFile(
const std::string &
Filename, int64_t Skip = 0,
326 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
334 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
339 StringRef parseStringToEndOfStatement()
override;
343 StringRef parseStringToComma();
345 enum class AssignmentKind {
352 bool parseAssignment(StringRef Name, AssignmentKind Kind);
357 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
358 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
359 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
361 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
363 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
364 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
435 DK_WEAK_DEF_CAN_BE_HIDDEN,
476 DK_CV_INLINE_SITE_ID,
479 DK_CV_INLINE_LINETABLE,
484 DK_CV_FILECHECKSUM_OFFSET,
490 DK_CFI_DEF_CFA_OFFSET,
491 DK_CFI_ADJUST_CFA_OFFSET,
492 DK_CFI_DEF_CFA_REGISTER,
493 DK_CFI_LLVM_DEF_ASPACE_CFA,
498 DK_CFI_REMEMBER_STATE,
499 DK_CFI_RESTORE_STATE,
503 DK_CFI_RETURN_COLUMN,
530 DK_LTO_SET_CONDITIONAL,
531 DK_CFI_MTE_TAGGED_FRAME,
539 StringMap<DirectiveKind> DirectiveKindMap;
542 enum CVDefRangeType {
544 CVDR_DEFRANGE_REGISTER,
545 CVDR_DEFRANGE_FRAMEPOINTER_REL,
546 CVDR_DEFRANGE_SUBFIELD_REGISTER,
547 CVDR_DEFRANGE_REGISTER_REL
552 StringMap<CVDefRangeType> CVDefRangeTypeMap;
555 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
556 bool parseDirectiveBase64();
557 bool parseDirectiveReloc(SMLoc DirectiveLoc);
558 bool parseDirectiveValue(StringRef IDVal,
560 bool parseDirectiveOctaValue(StringRef IDVal);
561 bool parseDirectiveRealValue(StringRef IDVal,
562 const fltSemantics &);
563 bool parseDirectiveFill();
564 bool parseDirectiveZero();
566 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
567 bool parseDirectiveOrg();
569 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
570 bool parseDirectivePrefAlign();
573 bool parseDirectiveFile(SMLoc DirectiveLoc);
574 bool parseDirectiveLine();
575 bool parseDirectiveLoc();
576 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
577 bool parseDirectiveStabs();
581 bool parseDirectiveCVFile();
582 bool parseDirectiveCVFuncId();
583 bool parseDirectiveCVInlineSiteId();
584 bool parseDirectiveCVLoc();
585 bool parseDirectiveCVLinetable();
586 bool parseDirectiveCVInlineLinetable();
587 bool parseDirectiveCVDefRange();
588 bool parseDirectiveCVString();
589 bool parseDirectiveCVStringTable();
590 bool parseDirectiveCVFileChecksums();
591 bool parseDirectiveCVFileChecksumOffset();
592 bool parseDirectiveCVFPOData();
595 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
596 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
597 bool parseDirectiveCFISections();
598 bool parseDirectiveCFIStartProc();
599 bool parseDirectiveCFIEndProc();
600 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
601 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
602 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
603 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
604 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
605 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
606 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
607 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
608 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
609 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
610 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
611 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
612 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
613 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
614 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
615 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
616 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
617 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
620 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
621 bool parseDirectiveExitMacro(StringRef Directive);
622 bool parseDirectiveEndMacro(StringRef Directive);
623 bool parseDirectiveMacro(SMLoc DirectiveLoc);
624 bool parseDirectiveMacrosOnOff(StringRef Directive);
626 bool parseDirectiveAltmacro(StringRef Directive);
629 bool parseDirectiveSpace(StringRef IDVal);
632 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
633 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
635 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
638 bool parseDirectiveLEB128(
bool Signed);
644 bool parseDirectiveComm(
bool IsLocal);
646 bool parseDirectiveAbort(SMLoc DirectiveLoc);
647 bool parseDirectiveInclude();
648 bool parseDirectiveIncbin();
651 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
653 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
655 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
657 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
659 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
660 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
661 bool parseDirectiveElse(SMLoc DirectiveLoc);
662 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
663 bool parseEscapedString(std::string &
Data)
override;
664 bool parseAngleBracketString(std::string &
Data)
override;
667 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
668 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
669 raw_svector_ostream &OS);
670 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
671 bool parseDirectiveIrp(SMLoc DirectiveLoc);
672 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
673 bool parseDirectiveEndr(SMLoc DirectiveLoc);
676 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &
Info,
680 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &
Info);
683 bool parseDirectiveEnd(SMLoc DirectiveLoc);
686 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
689 bool parseDirectiveWarning(SMLoc DirectiveLoc);
692 bool parseDirectivePrint(SMLoc DirectiveLoc);
695 bool parseDirectivePseudoProbe();
698 bool parseDirectiveLTODiscard();
701 bool parseDirectiveAddrsig();
702 bool parseDirectiveAddrsigSym();
704 void initializeDirectiveKindMap();
705 void initializeCVDefRangeTypeMap();
708class HLASMAsmParser final :
public AsmParser {
713 void lexLeadingSpaces() {
718 bool parseAsHLASMLabel(ParseStatementInfo &
Info, MCAsmParserSemaCallback *SI);
719 bool parseAsMachineInstruction(ParseStatementInfo &
Info,
720 MCAsmParserSemaCallback *SI);
723 HLASMAsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
724 const MCAsmInfo &MAI,
unsigned CB = 0)
725 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
726 Lexer.setSkipSpace(
false);
727 Lexer.setAllowHashInIdentifier(
true);
728 Lexer.setLexHLASMIntegers(
true);
729 Lexer.setLexHLASMStrings(
true);
732 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
734 bool parseStatement(ParseStatementInfo &
Info,
735 MCAsmParserSemaCallback *SI)
override;
748 :
MCAsmParser(Ctx, Out, SM, MAI), CurBuffer(CB ? CB : SM.getMainFileID()),
749 MacrosEnabledFlag(
true) {
752 SavedDiagHandler =
SrcMgr.getDiagHandler();
753 SavedDiagContext =
SrcMgr.getDiagContext();
761 switch (Ctx.getObjectFileType()) {
762 case MCContext::IsCOFF:
763 PlatformParser.reset(createCOFFAsmParser());
765 case MCContext::IsMachO:
766 PlatformParser.reset(createDarwinAsmParser());
769 case MCContext::IsELF:
770 PlatformParser.reset(createELFAsmParser());
772 case MCContext::IsGOFF:
773 PlatformParser.reset(createGOFFAsmParser());
775 case MCContext::IsSPIRV:
777 "Need to implement createSPIRVAsmParser for SPIRV format.");
779 case MCContext::IsWasm:
780 PlatformParser.reset(createWasmAsmParser());
782 case MCContext::IsXCOFF:
783 PlatformParser.reset(createXCOFFAsmParser());
785 case MCContext::IsDXContainer:
786 report_fatal_error(
"DXContainer is not supported yet");
790 PlatformParser->Initialize(*
this);
791 initializeDirectiveKindMap();
792 initializeCVDefRangeTypeMap();
795AsmParser::~AsmParser() {
796 assert((HadError || ActiveMacros.empty()) &&
797 "Unexpected active macro instantiation!");
806void AsmParser::printMacroInstantiations() {
808 for (MacroInstantiation *M :
reverse(ActiveMacros))
810 "while in macro instantiation");
813void AsmParser::Note(SMLoc L,
const Twine &Msg, SMRange
Range) {
814 printPendingErrors();
816 printMacroInstantiations();
819bool AsmParser::Warning(SMLoc L,
const Twine &Msg, SMRange
Range) {
820 if(getTargetParser().getTargetOptions().MCNoWarn)
822 if (getTargetParser().getTargetOptions().MCFatalWarnings)
825 printMacroInstantiations();
829bool AsmParser::printError(SMLoc L,
const Twine &Msg, SMRange
Range) {
832 printMacroInstantiations();
836bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
837 std::string IncludedFile;
851bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
852 const MCExpr *
Count, SMLoc Loc) {
853 std::string IncludedFile;
864 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
865 return Error(Loc,
"expected absolute expression");
867 return Warning(Loc,
"negative count has no effect");
870 getStreamer().emitBytes(Bytes);
874void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
880const AsmToken &AsmParser::Lex() {
887 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
892 const AsmToken *tok = &Lexer.
Lex();
905 if (ParentIncludeLoc != SMLoc()) {
906 jumpToLoc(ParentIncludeLoc);
914bool AsmParser::enabledGenDwarfForAssembly() {
921 if (
getContext().getGenDwarfFileNumber() == 0) {
922 const MCDwarfFile &RootFile =
923 getContext().getMCDwarfLineTable(0).getRootFile();
924 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
931bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
932 LTODiscardSymbols.
clear();
935 if (!NoInitialTextSection)
942 AsmCond StartingCondState = TheCondState;
950 MCSection *Sec = getStreamer().getCurrentSectionOnly();
953 getStreamer().emitLabel(SectionStartSym);
956 bool InsertResult =
getContext().addGenDwarfSection(Sec);
957 assert(InsertResult &&
".text section should not have debug info yet");
961 getTargetParser().onBeginOfFile();
965 ParseStatementInfo
Info(&AsmStrRewrites);
966 bool HasError = parseStatement(
Info,
nullptr);
975 printPendingErrors();
978 if (HasError && !getLexer().justConsumedEOL())
979 eatToEndOfStatement();
982 getTargetParser().onEndOfFile();
983 printPendingErrors();
986 assert(!hasPendingError() &&
"unexpected error from parseStatement");
990 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
992 const auto &LineTables =
getContext().getMCDwarfLineTables();
993 if (!LineTables.empty()) {
995 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
996 if (
File.Name.empty() && Index != 0)
997 printError(getTok().getLoc(),
"unassigned file number: " +
999 " for .file directives");
1011 MCSymbol *Sym = TableEntry.getValue().Symbol;
1020 printError(getTok().getLoc(),
"assembler local symbol '" +
1021 Sym->
getName() +
"' not defined");
1027 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1028 if (std::get<2>(LocSym)->isUndefined()) {
1031 CppHashInfo = std::get<1>(LocSym);
1032 printError(std::get<0>(LocSym),
"directional label undefined");
1038 if (!HadError && !NoFinalize) {
1040 TS->emitConstantPools();
1048bool AsmParser::checkForValidSection() {
1049 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1051 return Error(getTok().getLoc(),
1052 "expected section directive before assembly directive");
1058void AsmParser::eatToEndOfStatement() {
1067StringRef AsmParser::parseStringToEndOfStatement() {
1068 const char *
Start = getTok().getLoc().getPointer();
1074 return StringRef(Start, End - Start);
1077StringRef AsmParser::parseStringToComma() {
1078 const char *
Start = getTok().getLoc().getPointer();
1084 const char *End = getTok().getLoc().getPointer();
1085 return StringRef(Start, End - Start);
1093bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1094 if (parseExpression(Res))
1097 return parseRParen();
1105bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1106 if (parseExpression(Res))
1108 EndLoc = getTok().getEndLoc();
1109 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1120bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1121 AsmTypeInfo *TypeInfo) {
1122 SMLoc FirstTokenLoc = getLexer().getLoc();
1124 switch (FirstTokenKind) {
1126 return TokError(
"unknown token in expression");
1132 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1142 if (parseIdentifier(Identifier)) {
1146 bool ShouldGenerateTempSymbol =
false;
1149 ShouldGenerateTempSymbol =
true;
1151 if (!ShouldGenerateTempSymbol)
1152 return Error(FirstTokenLoc,
"invalid token in expression");
1161 EndLoc = FirstTokenLoc;
1166 std::pair<StringRef, StringRef>
Split;
1171 SMLoc AtLoc = getLexer().getLoc();
1173 if (parseIdentifier(VName))
1174 return Error(AtLoc,
"expected symbol variant after '@'");
1176 Split = std::make_pair(Identifier, VName);
1184 parseIdentifier(VName);
1187 Split = std::make_pair(Identifier, VName);
1195 return Error(getLexer().getLoc(),
"expected a symbol reference");
1199 if (!
Split.second.empty()) {
1201 if (MaybeSpecifier) {
1203 Spec = *MaybeSpecifier;
1206 "invalid variant '" +
Split.second +
"'");
1221 DoInline = TV->inlineAssignedExpr();
1224 return Error(EndLoc,
"unexpected modifier on variable reference");
1235 return TokError(
"literal value out of range for directive");
1237 SMLoc Loc = getTok().getLoc();
1238 int64_t
IntVal = getTok().getIntVal();
1244 StringRef IDVal = getTok().getString();
1246 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1248 if (
Split.first.size() != IDVal.
size()) {
1251 return TokError(
"invalid variant '" +
Split.second +
"'");
1252 IDVal =
Split.first;
1255 if (IDVal ==
"f" || IDVal ==
"b") {
1260 return Error(Loc,
"directional label undefined");
1261 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1269 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1270 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
1278 return TokError(
"cannot use . as current PC");
1291 return parseParenExpr(Res, EndLoc);
1293 if (!PlatformParser->HasBracketExpressions())
1294 return TokError(
"brackets expression not supported on this target");
1296 return parseBracketExpr(Res, EndLoc);
1299 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1305 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1311 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1318bool AsmParser::parseExpression(
const MCExpr *&Res) {
1320 return parseExpression(Res, EndLoc);
1330 switch (E->getKind()) {
1341 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1342 "' (already modified)");
1393 "Argument to the function cannot be a NULL value");
1395 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1396 (*CharPtr !=
'\0')) {
1397 if (*CharPtr ==
'!')
1401 if (*CharPtr ==
'>') {
1411 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1412 if (AltMacroStr[Pos] ==
'!')
1414 Res += AltMacroStr[Pos];
1422 return TokError(
"expected specifier following '@'");
1424 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1426 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1446bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1449 auto &TS = getTargetParser();
1450 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1458 return TokError(
"unexpected symbol modifier following '@'");
1462 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1464 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1466 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1467 "' (no symbols present)");
1477 if (Res->evaluateAsAbsolute(
Value))
1483bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1485 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1488bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1491 SMLoc StartLoc = Lexer.
getLoc();
1492 if (parseExpression(Expr))
1495 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1496 return Error(StartLoc,
"expected absolute expression");
1503 bool ShouldUseLogicalShr) {
1580 bool ShouldUseLogicalShr) {
1669bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1671 SMLoc StartLoc = Lexer.
getLoc();
1674 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1678 if (TokPrec < Precedence)
1685 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1691 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1692 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1704bool AsmParser::parseStatement(ParseStatementInfo &
Info,
1705 MCAsmParserSemaCallback *SI) {
1706 assert(!hasPendingError() &&
"parseStatement started with pending error");
1712 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1713 getTok().getString().
front() ==
'\n')
1719 AsmToken
ID = getTok();
1720 SMLoc IDLoc =
ID.getLoc();
1722 int64_t LocalLabelVal = -1;
1723 StartTokLoc =
ID.getLoc();
1725 return parseCppHashLineFilenameComment(IDLoc,
1726 !isInsideMacroInstantiation());
1730 LocalLabelVal = getTok().getIntVal();
1731 if (LocalLabelVal < 0) {
1732 if (!TheCondState.
Ignore) {
1734 return Error(IDLoc,
"unexpected token at start of statement");
1738 IDVal = getTok().getString();
1741 if (!TheCondState.
Ignore) {
1743 return Error(IDLoc,
"unexpected token at start of statement");
1751 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1753 IDVal =
ID.getString();
1754 }
else if (parseIdentifier(IDVal)) {
1755 if (!TheCondState.
Ignore) {
1757 return Error(IDLoc,
"unexpected token at start of statement");
1766 DirectiveKindMap.find(IDVal.
lower());
1767 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1769 : DirKindIt->getValue();
1780 return parseDirectiveIf(IDLoc, DirKind);
1782 return parseDirectiveIfb(IDLoc,
true);
1784 return parseDirectiveIfb(IDLoc,
false);
1786 return parseDirectiveIfc(IDLoc,
true);
1788 return parseDirectiveIfeqs(IDLoc,
true);
1790 return parseDirectiveIfc(IDLoc,
false);
1792 return parseDirectiveIfeqs(IDLoc,
false);
1794 return parseDirectiveIfdef(IDLoc,
true);
1797 return parseDirectiveIfdef(IDLoc,
false);
1799 return parseDirectiveElseIf(IDLoc);
1801 return parseDirectiveElse(IDLoc);
1803 return parseDirectiveEndIf(IDLoc);
1808 if (TheCondState.
Ignore) {
1809 eatToEndOfStatement();
1819 if (checkForValidSection())
1826 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1834 if (LocalLabelVal == -1) {
1835 if (ParsingMSInlineAsm && SI) {
1836 StringRef RewrittenLabel =
1837 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1839 "We should have an internal name here.");
1842 IDVal = RewrittenLabel;
1852 StringRef CommentStr = parseStringToEndOfStatement();
1863 if (MAI.
isMachO() && CFIStartProcLoc) {
1864 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1865 if (SymM->isExternal() && !SymM->isAltEntry())
1866 return Error(StartTokLoc,
"non-private labels cannot appear between "
1867 ".cfi_startproc / .cfi_endproc pairs") &&
1868 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1871 if (discardLTOSymbol(IDVal))
1874 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1877 if (!getTargetParser().isParsingMSInlineAsm())
1882 if (enabledGenDwarfForAssembly())
1886 getTargetParser().onLabelParsed(Sym);
1895 return parseAssignment(IDVal, AssignmentKind::Equal);
1899 if (areMacrosEnabled())
1900 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1901 return handleMacroEntry(M, IDLoc);
1918 getTargetParser().flushPendingInstructions(getStreamer());
1920 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
1922 "Should only return Failure iff there was an error");
1930 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1931 ExtensionDirectiveMap.
lookup(IDVal);
1933 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1942 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1944 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1945 case DK_LTO_SET_CONDITIONAL:
1946 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1948 return parseDirectiveAscii(IDVal,
false);
1951 return parseDirectiveAscii(IDVal,
true);
1953 return parseDirectiveBase64();
1956 return parseDirectiveValue(IDVal, 1);
1962 return parseDirectiveValue(IDVal, 2);
1967 return parseDirectiveValue(IDVal, 4);
1970 return parseDirectiveValue(IDVal, 8);
1972 return parseDirectiveValue(
1973 IDVal,
getContext().getAsmInfo()->getCodePointerSize());
1975 return parseDirectiveOctaValue(IDVal);
1979 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1982 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1984 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1985 return parseDirectiveAlign(IsPow2, 1);
1988 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1989 return parseDirectiveAlign(IsPow2, 4);
1992 return parseDirectiveAlign(
false, 1);
1994 return parseDirectiveAlign(
false, 2);
1996 return parseDirectiveAlign(
false, 4);
1998 return parseDirectiveAlign(
true, 1);
2000 return parseDirectiveAlign(
true, 2);
2002 return parseDirectiveAlign(
true, 4);
2004 return parseDirectivePrefAlign();
2006 return parseDirectiveOrg();
2008 return parseDirectiveFill();
2010 return parseDirectiveZero();
2012 eatToEndOfStatement();
2016 return parseDirectiveSymbolAttribute(
MCSA_Global);
2017 case DK_LAZY_REFERENCE:
2019 case DK_NO_DEAD_STRIP:
2021 case DK_SYMBOL_RESOLVER:
2023 case DK_PRIVATE_EXTERN:
2027 case DK_WEAK_DEFINITION:
2029 case DK_WEAK_REFERENCE:
2031 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2034 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2037 return parseDirectiveComm(
false);
2039 return parseDirectiveComm(
true);
2041 return parseDirectiveAbort(IDLoc);
2043 return parseDirectiveInclude();
2045 return parseDirectiveIncbin();
2048 return TokError(Twine(IDVal) +
2049 " not currently supported for this target");
2051 return parseDirectiveRept(IDLoc, IDVal);
2053 return parseDirectiveIrp(IDLoc);
2055 return parseDirectiveIrpc(IDLoc);
2057 return parseDirectiveEndr(IDLoc);
2059 return parseDirectiveLEB128(
true);
2061 return parseDirectiveLEB128(
false);
2064 return parseDirectiveSpace(IDVal);
2066 return parseDirectiveFile(IDLoc);
2068 return parseDirectiveLine();
2070 return parseDirectiveLoc();
2072 return parseDirectiveLocLabel(IDLoc);
2074 return parseDirectiveStabs();
2076 return parseDirectiveCVFile();
2078 return parseDirectiveCVFuncId();
2079 case DK_CV_INLINE_SITE_ID:
2080 return parseDirectiveCVInlineSiteId();
2082 return parseDirectiveCVLoc();
2083 case DK_CV_LINETABLE:
2084 return parseDirectiveCVLinetable();
2085 case DK_CV_INLINE_LINETABLE:
2086 return parseDirectiveCVInlineLinetable();
2087 case DK_CV_DEF_RANGE:
2088 return parseDirectiveCVDefRange();
2090 return parseDirectiveCVString();
2091 case DK_CV_STRINGTABLE:
2092 return parseDirectiveCVStringTable();
2093 case DK_CV_FILECHECKSUMS:
2094 return parseDirectiveCVFileChecksums();
2095 case DK_CV_FILECHECKSUM_OFFSET:
2096 return parseDirectiveCVFileChecksumOffset();
2097 case DK_CV_FPO_DATA:
2098 return parseDirectiveCVFPOData();
2099 case DK_CFI_SECTIONS:
2100 return parseDirectiveCFISections();
2101 case DK_CFI_STARTPROC:
2102 return parseDirectiveCFIStartProc();
2103 case DK_CFI_ENDPROC:
2104 return parseDirectiveCFIEndProc();
2105 case DK_CFI_DEF_CFA:
2106 return parseDirectiveCFIDefCfa(IDLoc);
2107 case DK_CFI_DEF_CFA_OFFSET:
2108 return parseDirectiveCFIDefCfaOffset(IDLoc);
2109 case DK_CFI_ADJUST_CFA_OFFSET:
2110 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2111 case DK_CFI_DEF_CFA_REGISTER:
2112 return parseDirectiveCFIDefCfaRegister(IDLoc);
2113 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2114 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2116 return parseDirectiveCFIOffset(IDLoc);
2117 case DK_CFI_REL_OFFSET:
2118 return parseDirectiveCFIRelOffset(IDLoc);
2119 case DK_CFI_PERSONALITY:
2120 return parseDirectiveCFIPersonalityOrLsda(
true);
2122 return parseDirectiveCFIPersonalityOrLsda(
false);
2123 case DK_CFI_REMEMBER_STATE:
2124 return parseDirectiveCFIRememberState(IDLoc);
2125 case DK_CFI_RESTORE_STATE:
2126 return parseDirectiveCFIRestoreState(IDLoc);
2127 case DK_CFI_SAME_VALUE:
2128 return parseDirectiveCFISameValue(IDLoc);
2129 case DK_CFI_RESTORE:
2130 return parseDirectiveCFIRestore(IDLoc);
2132 return parseDirectiveCFIEscape(IDLoc);
2133 case DK_CFI_RETURN_COLUMN:
2134 return parseDirectiveCFIReturnColumn(IDLoc);
2135 case DK_CFI_SIGNAL_FRAME:
2136 return parseDirectiveCFISignalFrame(IDLoc);
2137 case DK_CFI_UNDEFINED:
2138 return parseDirectiveCFIUndefined(IDLoc);
2139 case DK_CFI_REGISTER:
2140 return parseDirectiveCFIRegister(IDLoc);
2141 case DK_CFI_WINDOW_SAVE:
2142 return parseDirectiveCFIWindowSave(IDLoc);
2144 return parseDirectiveCFILabel(IDLoc);
2145 case DK_CFI_VAL_OFFSET:
2146 return parseDirectiveCFIValOffset(IDLoc);
2149 return parseDirectiveMacrosOnOff(IDVal);
2151 return parseDirectiveMacro(IDLoc);
2154 return parseDirectiveAltmacro(IDVal);
2156 return parseDirectiveExitMacro(IDVal);
2159 return parseDirectiveEndMacro(IDVal);
2161 return parseDirectivePurgeMacro(IDLoc);
2163 return parseDirectiveEnd(IDLoc);
2165 return parseDirectiveError(IDLoc,
false);
2167 return parseDirectiveError(IDLoc,
true);
2169 return parseDirectiveWarning(IDLoc);
2171 return parseDirectiveReloc(IDLoc);
2174 return parseDirectiveDCB(IDVal, 2);
2176 return parseDirectiveDCB(IDVal, 1);
2178 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2180 return parseDirectiveDCB(IDVal, 4);
2182 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2185 return TokError(Twine(IDVal) +
2186 " not currently supported for this target");
2189 return parseDirectiveDS(IDVal, 2);
2191 return parseDirectiveDS(IDVal, 1);
2193 return parseDirectiveDS(IDVal, 8);
2196 return parseDirectiveDS(IDVal, 4);
2199 return parseDirectiveDS(IDVal, 12);
2201 return parseDirectivePrint(IDLoc);
2203 return parseDirectiveAddrsig();
2204 case DK_ADDRSIG_SYM:
2205 return parseDirectiveAddrsigSym();
2206 case DK_PSEUDO_PROBE:
2207 return parseDirectivePseudoProbe();
2208 case DK_LTO_DISCARD:
2209 return parseDirectiveLTODiscard();
2211 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2214 return Error(IDLoc,
"unknown directive");
2218 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2219 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2220 return parseDirectiveMSEmit(IDLoc,
Info, IDVal.
size());
2223 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2224 return parseDirectiveMSAlign(IDLoc,
Info);
2226 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2228 if (checkForValidSection())
2231 return parseAndMatchAndEmitTargetInstruction(
Info, IDVal,
ID, IDLoc);
2234bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &
Info,
2239 std::string OpcodeStr = IDVal.
lower();
2240 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2241 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr,
ID,
2242 Info.ParsedOperands);
2243 Info.ParseError = ParseHadError;
2246 if (getShowParsedOperands()) {
2247 SmallString<256> Str;
2248 raw_svector_ostream OS(Str);
2249 OS <<
"parsed instruction: [";
2250 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2253 Info.ParsedOperands[i]->print(OS, MAI);
2261 if (hasPendingError() || ParseHadError)
2266 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2268 getStreamer().getCurrentSectionOnly())) {
2270 if (ActiveMacros.empty())
2274 ActiveMacros.front()->ExitBuffer);
2279 if (!CppHashInfo.Filename.empty()) {
2280 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2281 0, StringRef(), CppHashInfo.Filename);
2282 getContext().setGenDwarfFileNumber(FileNumber);
2284 unsigned CppHashLocLineNo =
2286 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2289 getStreamer().emitDwarfLocDirective(
2290 getContext().getGenDwarfFileNumber(), Line, 0,
2296 if (!ParseHadError) {
2298 if (getTargetParser().matchAndEmitInstruction(
2299 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2300 getTargetParser().isParsingMSInlineAsm()))
2308AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2313 SMLoc StartLoc = Lexer.
getLoc();
2326bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2331 "Lexing Cpp line comment: Expected Integer");
2332 int64_t LineNumber = getTok().getIntVal();
2335 "Lexing Cpp line comment: Expected String");
2336 StringRef
Filename = getTok().getString();
2347 CppHashInfo.Loc =
L;
2349 CppHashInfo.LineNumber = LineNumber;
2350 CppHashInfo.Buf = CurBuffer;
2351 if (!HadCppHashFilename) {
2352 HadCppHashFilename =
true;
2362 std::nullopt, std::nullopt);
2370void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2371 auto *Parser =
static_cast<AsmParser *
>(
Context);
2372 raw_ostream &OS =
errs();
2375 SMLoc DiagLoc = Diag.
getLoc();
2377 unsigned CppHashBuf =
2378 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2383 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2392 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2393 if (Parser->SavedDiagHandler)
2394 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2396 Parser->getContext().diagnose(Diag);
2403 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2406 int CppHashLocLineNo =
2407 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2409 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2415 if (Parser->SavedDiagHandler)
2416 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2418 Parser->getContext().diagnose(NewDiag);
2426 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2430bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2433 bool EnableAtPseudoVariable) {
2435 auto expandArg = [&](
unsigned Index) {
2436 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2437 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2438 for (
const AsmToken &Token :
A[Index])
2446 if (AltMacroMode && Token.getString().front() ==
'%' &&
2449 OS << Token.getIntVal();
2452 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2459 OS << Token.getString();
2461 OS << Token.getStringContents();
2466 StringRef Body =
Macro.Body;
2467 size_t I = 0, End = Body.
size();
2469 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2471 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2472 OS << NumOfMacroInstantiations;
2476 if (Body[
I + 1] ==
'+') {
2481 if (Body[
I + 1] ==
'(' && Body[
I + 2] ==
')') {
2490 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2494 if (Parameters[Index].Name == Argument)
2496 if (Index == NParameters)
2505 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2507 switch (Body[
I + 1]) {
2523 unsigned Index = Body[
I + 1] -
'0';
2524 if (Index <
A.size())
2525 for (
const AsmToken &Token :
A[Index])
2526 OS << Token.getString();
2541 StringRef Token(Body.
data() + Start,
I - Start);
2545 if (Parameters[Index].Name == Token)
2547 if (Index != NParameters) {
2549 if (
I != End && Body[
I] ==
'&')
2593class AsmLexerSkipSpaceRAII {
2595 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2599 ~AsmLexerSkipSpaceRAII() {
2609bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2613 StringRef Str = parseStringToEndOfStatement();
2619 unsigned ParenLevel = 0;
2622 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2629 return TokError(
"unexpected token in macro instantiation");
2631 if (ParenLevel == 0) {
2644 MA.push_back(getTok());
2668 MA.push_back(getTok());
2672 if (ParenLevel != 0)
2673 return TokError(
"unbalanced parentheses in macro argument");
2678bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2679 MCAsmMacroArguments &
A) {
2680 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2681 bool NamedParametersFound =
false;
2682 SmallVector<SMLoc, 4> FALocs;
2684 A.resize(NParameters);
2685 FALocs.
resize(NParameters);
2690 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2691 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2693 SMLoc IDLoc = Lexer.
getLoc();
2694 MCAsmMacroParameter FA;
2697 if (parseIdentifier(FA.
Name))
2698 return Error(IDLoc,
"invalid argument identifier for formal argument");
2701 return TokError(
"expected '=' after formal parameter identifier");
2705 NamedParametersFound =
true;
2707 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2709 if (NamedParametersFound && FA.
Name.
empty())
2710 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2712 SMLoc StrLoc = Lexer.
getLoc();
2715 const MCExpr *AbsoluteExp;
2719 if (parseExpression(AbsoluteExp, EndLoc))
2721 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2722 getStreamer().getAssemblerPtr()))
2723 return Error(StrLoc,
"expected absolute expression");
2727 StringRef(StrChar, EndChar - StrChar),
Value);
2728 FA.
Value.push_back(newToken);
2733 jumpToLoc(EndLoc, CurBuffer);
2737 StringRef(StrChar, EndChar - StrChar));
2738 FA.
Value.push_back(newToken);
2739 }
else if(parseMacroArgument(FA.
Value, Vararg))
2745 for (FAI = 0; FAI < NParameters; ++FAI)
2746 if (
M->Parameters[FAI].Name == FA.
Name)
2749 if (FAI >= NParameters) {
2750 assert(M &&
"expected macro to be defined");
2751 return Error(IDLoc,
"parameter named '" + FA.
Name +
2752 "' does not exist for macro '" +
M->Name +
"'");
2757 if (!FA.
Value.empty()) {
2762 if (FALocs.
size() <= PI)
2765 FALocs[PI] = Lexer.
getLoc();
2773 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2775 if (
M->Parameters[FAI].Required) {
2777 "missing value for required parameter "
2778 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2782 if (!
M->Parameters[FAI].Value.empty())
2783 A[FAI] =
M->Parameters[FAI].Value;
2792 return TokError(
"too many positional arguments");
2795bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2799 if (ActiveMacros.size() == MaxNestingDepth) {
2800 std::ostringstream MaxNestingDepthError;
2801 MaxNestingDepthError <<
"macros cannot be nested more than "
2802 << MaxNestingDepth <<
" levels deep."
2803 <<
" Use -asm-macro-max-nesting-depth to increase "
2805 return TokError(MaxNestingDepthError.str());
2808 MCAsmMacroArguments
A;
2809 if (parseMacroArguments(M,
A))
2814 SmallString<256> Buf;
2815 raw_svector_ostream OS(Buf);
2817 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2818 return Error(getTok().getLoc(),
"Wrong number of arguments");
2819 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2824 OS <<
".endmacro\n";
2826 std::unique_ptr<MemoryBuffer> Instantiation =
2831 MacroInstantiation *
MI =
new MacroInstantiation{
2832 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2833 ActiveMacros.push_back(
MI);
2835 ++NumOfMacroInstantiations;
2845void AsmParser::handleMacroExit() {
2847 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2855 delete ActiveMacros.back();
2856 ActiveMacros.pop_back();
2859bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2861 const MCExpr *
Value;
2862 SMLoc ExprLoc = getTok().getLoc();
2864 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2876 if (discardLTOSymbol(Name))
2881 case AssignmentKind::Equal:
2884 case AssignmentKind::Set:
2885 case AssignmentKind::Equiv:
2889 case AssignmentKind::LTOSetConditional:
2891 return Error(ExprLoc,
"expected identifier");
2903bool AsmParser::parseIdentifier(StringRef &Res) {
2910 SMLoc PrefixLoc = getLexer().getLoc();
2922 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2928 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2936 Res = getTok().getIdentifier();
2948bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2950 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2951 parseAssignment(Name, Kind))
2956bool AsmParser::parseEscapedString(std::string &
Data) {
2961 StringRef Str = getTok().getStringContents();
2962 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
2963 if (Str[i] !=
'\\') {
2964 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
2966 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
2970 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
2981 return TokError(
"unexpected backslash at end of string");
2984 if (Str[i] ==
'x' || Str[i] ==
'X') {
2985 size_t length = Str.size();
2986 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
2987 return TokError(
"invalid hexadecimal escape sequence");
2992 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3000 if ((
unsigned)(Str[i] -
'0') <= 7) {
3002 unsigned Value = Str[i] -
'0';
3004 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3008 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3015 return TokError(
"invalid octal escape sequence (out of range)");
3025 return TokError(
"invalid escape sequence (unrecognized character)");
3027 case 'b':
Data +=
'\b';
break;
3028 case 'f':
Data +=
'\f';
break;
3029 case 'n':
Data +=
'\n';
break;
3030 case 'r':
Data +=
'\r';
break;
3031 case 't':
Data +=
'\t';
break;
3032 case '"':
Data +=
'"';
break;
3033 case '\\':
Data +=
'\\';
break;
3041bool AsmParser::parseAngleBracketString(std::string &
Data) {
3042 SMLoc EndLoc, StartLoc = getTok().getLoc();
3044 const char *StartChar = StartLoc.
getPointer() + 1;
3045 const char *EndChar = EndLoc.
getPointer() - 1;
3046 jumpToLoc(EndLoc, CurBuffer);
3059bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3060 auto parseOp = [&]() ->
bool {
3062 if (checkForValidSection())
3067 if (parseEscapedString(
Data))
3069 getStreamer().emitBytes(
Data);
3072 getStreamer().emitBytes(StringRef(
"\0", 1));
3076 return parseMany(parseOp);
3081bool AsmParser::parseDirectiveBase64() {
3082 auto parseOp = [&]() ->
bool {
3083 if (checkForValidSection())
3090 std::vector<char> Decoded;
3091 std::string
const str = getTok().getStringContents().str();
3092 if (check(str.empty(),
"expected nonempty string")) {
3099 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3102 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3107 return check(parseMany(parseOp),
"expected string");
3112bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3114 const MCExpr *Expr =
nullptr;
3116 if (parseExpression(
Offset))
3128 SMLoc ExprLoc = Lexer.
getLoc();
3129 if (parseExpression(Expr))
3134 return Error(ExprLoc,
"expression must be relocatable");
3140 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3146bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3147 auto parseOp = [&]() ->
bool {
3148 const MCExpr *
Value;
3149 SMLoc ExprLoc = getLexer().getLoc();
3150 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3155 uint64_t IntValue = MCE->getValue();
3157 return Error(ExprLoc,
"out of range literal value");
3158 getStreamer().emitIntValue(IntValue,
Size);
3160 getStreamer().emitValue(
Value,
Size, ExprLoc);
3164 return parseMany(parseOp);
3170 return Asm.TokError(
"unknown token in expression");
3171 SMLoc ExprLoc = Asm.getTok().getLoc();
3172 APInt IntValue = Asm.getTok().getAPIntVal();
3174 if (!IntValue.
isIntN(128))
3175 return Asm.Error(ExprLoc,
"out of range literal value");
3176 if (!IntValue.
isIntN(64)) {
3189bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3190 auto parseOp = [&]() ->
bool {
3191 if (checkForValidSection())
3197 getStreamer().emitInt64(lo);
3198 getStreamer().emitInt64(hi);
3200 getStreamer().emitInt64(hi);
3201 getStreamer().emitInt64(lo);
3206 return parseMany(parseOp);
3209bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3220 return TokError(Lexer.
getErr());
3223 return TokError(
"unexpected token in directive");
3227 StringRef IDVal = getTok().getString();
3235 return TokError(
"invalid floating point literal");
3237 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3239 return TokError(
"invalid floating point literal");
3246 Res =
Value.bitcastToAPInt();
3253bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3254 const fltSemantics &Semantics) {
3255 auto parseOp = [&]() ->
bool {
3257 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3264 return parseMany(parseOp);
3269bool AsmParser::parseDirectiveZero() {
3270 SMLoc NumBytesLoc = Lexer.
getLoc();
3271 const MCExpr *NumBytes;
3272 if (checkForValidSection() || parseExpression(NumBytes))
3278 if (parseAbsoluteExpression(Val))
3284 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3291bool AsmParser::parseDirectiveFill() {
3292 SMLoc NumValuesLoc = Lexer.
getLoc();
3293 const MCExpr *NumValues;
3294 if (checkForValidSection() || parseExpression(NumValues))
3297 int64_t FillSize = 1;
3298 int64_t FillExpr = 0;
3300 SMLoc SizeLoc, ExprLoc;
3303 SizeLoc = getTok().getLoc();
3304 if (parseAbsoluteExpression(FillSize))
3307 ExprLoc = getTok().getLoc();
3308 if (parseAbsoluteExpression(FillExpr))
3316 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3320 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3325 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3327 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3334bool AsmParser::parseDirectiveOrg() {
3336 SMLoc OffsetLoc = Lexer.
getLoc();
3337 if (checkForValidSection() || parseExpression(
Offset))
3341 int64_t FillExpr = 0;
3343 if (parseAbsoluteExpression(FillExpr))
3348 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3354bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3355 SMLoc AlignmentLoc = getLexer().getLoc();
3358 bool HasFillExpr =
false;
3359 int64_t FillExpr = 0;
3360 int64_t MaxBytesToFill = 0;
3363 auto parseAlign = [&]() ->
bool {
3364 if (parseAbsoluteExpression(Alignment))
3372 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3376 if (parseTokenLoc(MaxBytesLoc) ||
3377 parseAbsoluteExpression(MaxBytesToFill))
3383 if (checkForValidSection())
3387 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3394 bool ReturnVal =
false;
3399 if (Alignment >= 32) {
3400 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3404 Alignment = 1ULL << Alignment;
3412 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3416 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3417 Alignment = 1u << 31;
3423 if (MaxBytesToFill < 1) {
3424 ReturnVal |=
Error(MaxBytesLoc,
3425 "alignment directive can never be satisfied in this "
3426 "many bytes, ignoring maximum bytes expression");
3430 if (MaxBytesToFill >= Alignment) {
3431 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3437 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3438 assert(Section &&
"must have section to emit alignment");
3440 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3442 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3450 getStreamer().emitCodeAlignment(
3451 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3454 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3461bool AsmParser::parseDirectivePrefAlign() {
3462 SMLoc AlignmentLoc = getLexer().getLoc();
3464 if (checkForValidSection() || parseAbsoluteExpression(Alignment))
3470 return Error(AlignmentLoc,
"alignment must be a power of 2");
3471 getStreamer().emitPrefAlign(
Align(Alignment));
3479bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3481 int64_t FileNumber = -1;
3483 FileNumber = getTok().getIntVal();
3487 return TokError(
"negative file number");
3494 if (parseEscapedString(Path))
3497 StringRef Directory;
3499 std::string FilenameData;
3501 if (check(FileNumber == -1,
3502 "explicit path specified, but no file number") ||
3503 parseEscapedString(FilenameData))
3511 uint64_t MD5Hi, MD5Lo;
3512 bool HasMD5 =
false;
3514 std::optional<StringRef>
Source;
3515 bool HasSource =
false;
3516 std::string SourceString;
3521 "unexpected token in '.file' directive") ||
3522 parseIdentifier(Keyword))
3524 if (Keyword ==
"md5") {
3526 if (check(FileNumber == -1,
3527 "MD5 checksum specified, but no file number") ||
3530 }
else if (Keyword ==
"source") {
3532 if (check(FileNumber == -1,
3533 "source specified, but no file number") ||
3535 "unexpected token in '.file' directive") ||
3536 parseEscapedString(SourceString))
3539 return TokError(
"unexpected token in '.file' directive");
3543 if (FileNumber == -1) {
3547 if (
getContext().getAsmInfo()->hasSingleParameterDotFile())
3548 getStreamer().emitFileDirective(
Filename);
3558 std::optional<MD5::MD5Result> CKMem;
3561 for (
unsigned i = 0; i != 8; ++i) {
3562 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3563 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3568 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3569 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3570 Source = StringRef(SourceBuf, SourceString.size());
3572 if (FileNumber == 0) {
3576 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3578 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3579 FileNumber, Directory,
Filename, CKMem, Source);
3586 ReportedInconsistentMD5 =
true;
3587 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3596bool AsmParser::parseDirectiveLine() {
3608bool AsmParser::parseDirectiveLoc() {
3609 int64_t FileNumber = 0, LineNumber = 0;
3610 SMLoc Loc = getTok().getLoc();
3611 if (parseIntToken(FileNumber) ||
3613 "file number less than one in '.loc' directive") ||
3614 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3615 "unassigned file number in '.loc' directive"))
3620 LineNumber = getTok().getIntVal();
3622 return TokError(
"line number less than zero in '.loc' directive");
3626 int64_t ColumnPos = 0;
3628 ColumnPos = getTok().getIntVal();
3630 return TokError(
"column position less than zero in '.loc' directive");
3634 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3639 auto parseLocOp = [&]() ->
bool {
3641 SMLoc Loc = getTok().getLoc();
3642 if (parseIdentifier(Name))
3643 return TokError(
"unexpected token in '.loc' directive");
3645 if (Name ==
"basic_block")
3647 else if (Name ==
"prologue_end")
3649 else if (Name ==
"epilogue_begin")
3651 else if (Name ==
"is_stmt") {
3652 Loc = getTok().getLoc();
3653 const MCExpr *
Value;
3654 if (parseExpression(
Value))
3658 int Value = MCE->getValue();
3660 Flags &= ~DWARF2_FLAG_IS_STMT;
3661 else if (
Value == 1)
3664 return Error(Loc,
"is_stmt value not 0 or 1");
3666 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3668 }
else if (Name ==
"isa") {
3669 Loc = getTok().getLoc();
3670 const MCExpr *
Value;
3671 if (parseExpression(
Value))
3675 int Value = MCE->getValue();
3677 return Error(Loc,
"isa number less than zero");
3680 return Error(Loc,
"isa number not a constant value");
3682 }
else if (Name ==
"discriminator") {
3683 if (parseAbsoluteExpression(Discriminator))
3686 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3691 if (parseMany(parseLocOp,
false ))
3694 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3695 Isa, Discriminator, StringRef());
3702bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3704 DirectiveLoc = Lexer.
getLoc();
3705 if (parseIdentifier(Name))
3706 return TokError(
"expected identifier");
3709 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3715bool AsmParser::parseDirectiveStabs() {
3716 return TokError(
"unsupported directive '.stabs'");
3721bool AsmParser::parseDirectiveCVFile() {
3722 SMLoc FileNumberLoc = getTok().getLoc();
3725 std::string Checksum;
3728 if (parseIntToken(FileNumber,
"expected file number") ||
3729 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3731 "unexpected token in '.cv_file' directive") ||
3736 "unexpected token in '.cv_file' directive") ||
3737 parseEscapedString(Checksum) ||
3738 parseIntToken(ChecksumKind,
3739 "expected checksum kind in '.cv_file' directive") ||
3745 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3746 memcpy(CKMem, Checksum.data(), Checksum.size());
3747 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3750 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3751 static_cast<uint8_t
>(ChecksumKind)))
3752 return Error(FileNumberLoc,
"file number already allocated");
3757bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3758 StringRef DirectiveName) {
3760 return parseTokenLoc(Loc) ||
3761 parseIntToken(FunctionId,
"expected function id") ||
3762 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3763 "expected function id within range [0, UINT_MAX)");
3766bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3768 return parseTokenLoc(Loc) ||
3769 parseIntToken(FileNumber,
"expected file number") ||
3770 check(FileNumber < 1, Loc,
3771 "file number less than one in '" + DirectiveName +
3773 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3774 "unassigned file number in '" + DirectiveName +
"' directive");
3781bool AsmParser::parseDirectiveCVFuncId() {
3782 SMLoc FunctionIdLoc = getTok().getLoc();
3785 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3788 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3789 return Error(FunctionIdLoc,
"function id already allocated");
3802bool AsmParser::parseDirectiveCVInlineSiteId() {
3803 SMLoc FunctionIdLoc = getTok().getLoc();
3811 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3816 getTok().getIdentifier() !=
"within"),
3817 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3822 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3827 getTok().getIdentifier() !=
"inlined_at"),
3828 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3834 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3835 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3840 IACol = getTok().getIntVal();
3847 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3848 IALine, IACol, FunctionIdLoc))
3849 return Error(FunctionIdLoc,
"function id already allocated");
3861bool AsmParser::parseDirectiveCVLoc() {
3862 SMLoc DirectiveLoc = getTok().getLoc();
3863 int64_t FunctionId, FileNumber;
3864 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3865 parseCVFileId(FileNumber,
".cv_loc"))
3868 int64_t LineNumber = 0;
3870 LineNumber = getTok().getIntVal();
3872 return TokError(
"line number less than zero in '.cv_loc' directive");
3876 int64_t ColumnPos = 0;
3878 ColumnPos = getTok().getIntVal();
3880 return TokError(
"column position less than zero in '.cv_loc' directive");
3884 bool PrologueEnd =
false;
3885 uint64_t IsStmt = 0;
3887 auto parseOp = [&]() ->
bool {
3889 SMLoc Loc = getTok().getLoc();
3890 if (parseIdentifier(Name))
3891 return TokError(
"unexpected token in '.cv_loc' directive");
3892 if (Name ==
"prologue_end")
3894 else if (Name ==
"is_stmt") {
3895 Loc = getTok().getLoc();
3896 const MCExpr *
Value;
3897 if (parseExpression(
Value))
3902 IsStmt = MCE->getValue();
3905 return Error(Loc,
"is_stmt value not 0 or 1");
3907 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3912 if (parseMany(parseOp,
false ))
3915 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3916 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3923bool AsmParser::parseDirectiveCVLinetable() {
3926 SMLoc Loc = getTok().getLoc();
3927 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3928 parseTokenLoc(Loc) ||
3929 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
3930 parseComma() || parseTokenLoc(Loc) ||
3931 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
3934 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3940bool AsmParser::parseDirectiveCVInlineLinetable() {
3941 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3943 SMLoc Loc = getTok().getLoc();
3944 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3945 parseTokenLoc(Loc) ||
3946 parseIntToken(SourceFileId,
"expected SourceField") ||
3947 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
3948 parseTokenLoc(Loc) ||
3949 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
3950 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
3951 parseTokenLoc(Loc) ||
3952 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
3953 parseTokenLoc(Loc) ||
3954 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
3960 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3961 SourceLineNum, FnStartSym,
3966void AsmParser::initializeCVDefRangeTypeMap() {
3967 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
3968 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
3969 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
3970 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
3975bool AsmParser::parseDirectiveCVDefRange() {
3977 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
3979 Loc = getLexer().getLoc();
3982 return Error(Loc,
"expected identifier in directive");
3984 Loc = getLexer().getLoc();
3987 return Error(Loc,
"expected identifier in directive");
3989 Ranges.push_back({GapStartSym, GapEndSym});
3992 StringRef CVDefRangeTypeStr;
3995 "expected comma before def_range type in .cv_def_range directive") ||
3996 parseIdentifier(CVDefRangeTypeStr))
3997 return Error(Loc,
"expected def_range type in directive");
4000 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4001 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4003 : CVTypeIt->getValue();
4005 case CVDR_DEFRANGE_REGISTER: {
4007 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4008 ".cv_def_range directive") ||
4009 parseAbsoluteExpression(DRRegister))
4010 return Error(Loc,
"expected register number");
4012 codeview::DefRangeRegisterHeader DRHdr;
4015 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4018 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4021 "expected comma before offset in .cv_def_range directive") ||
4022 parseAbsoluteExpression(DROffset))
4023 return Error(Loc,
"expected offset value");
4025 codeview::DefRangeFramePointerRelHeader DRHdr;
4027 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4030 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4032 int64_t DROffsetInParent;
4033 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4034 ".cv_def_range directive") ||
4035 parseAbsoluteExpression(DRRegister))
4036 return Error(Loc,
"expected register number");
4038 "expected comma before offset in .cv_def_range directive") ||
4039 parseAbsoluteExpression(DROffsetInParent))
4040 return Error(Loc,
"expected offset value");
4042 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4046 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4049 case CVDR_DEFRANGE_REGISTER_REL: {
4052 int64_t DRBasePointerOffset;
4053 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4054 ".cv_def_range directive") ||
4055 parseAbsoluteExpression(DRRegister))
4056 return Error(Loc,
"expected register value");
4059 "expected comma before flag value in .cv_def_range directive") ||
4060 parseAbsoluteExpression(DRFlags))
4061 return Error(Loc,
"expected flag value");
4062 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4063 "in .cv_def_range directive") ||
4064 parseAbsoluteExpression(DRBasePointerOffset))
4065 return Error(Loc,
"expected base pointer offset value");
4067 codeview::DefRangeRegisterRelHeader DRHdr;
4069 DRHdr.
Flags = DRFlags;
4071 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4075 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4082bool AsmParser::parseDirectiveCVString() {
4084 if (checkForValidSection() || parseEscapedString(
Data))
4088 std::pair<StringRef, unsigned> Insertion =
4089 getCVContext().addToStringTable(
Data);
4090 getStreamer().emitInt32(Insertion.second);
4096bool AsmParser::parseDirectiveCVStringTable() {
4097 getStreamer().emitCVStringTableDirective();
4103bool AsmParser::parseDirectiveCVFileChecksums() {
4104 getStreamer().emitCVFileChecksumsDirective();
4110bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4112 if (parseIntToken(FileNo))
4116 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4122bool AsmParser::parseDirectiveCVFPOData() {
4123 SMLoc DirLoc = getLexer().getLoc();
4126 return TokError(
"expected symbol name");
4129 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4135bool AsmParser::parseDirectiveCFISections() {
4139 bool SFrame =
false;
4143 if (parseIdentifier(Name))
4144 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4145 if (Name ==
".eh_frame")
4147 else if (Name ==
".debug_frame")
4149 else if (Name ==
".sframe")
4157 getStreamer().emitCFISections(EH,
Debug, SFrame);
4163bool AsmParser::parseDirectiveCFIStartProc() {
4164 CFIStartProcLoc = StartTokLoc;
4168 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4169 "unexpected token") ||
4179 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4185bool AsmParser::parseDirectiveCFIEndProc() {
4186 CFIStartProcLoc = std::nullopt;
4191 getStreamer().emitCFIEndProc();
4196bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4197 SMLoc DirectiveLoc) {
4201 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4205 return parseAbsoluteExpression(
Register);
4212bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4214 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4215 parseAbsoluteExpression(
Offset) || parseEOL())
4224bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4226 if (parseAbsoluteExpression(
Offset) || parseEOL())
4229 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4235bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4236 int64_t Register1 = 0, Register2 = 0;
4237 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4238 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4241 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4247bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4250 getStreamer().emitCFIWindowSave(DirectiveLoc);
4256bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4257 int64_t Adjustment = 0;
4258 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4261 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4267bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4269 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4272 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4278bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4280 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4281 parseAbsoluteExpression(
Offset) || parseComma() ||
4292bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4296 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4297 parseAbsoluteExpression(
Offset) || parseEOL())
4306bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4309 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4310 parseAbsoluteExpression(
Offset) || parseEOL())
4318 if (Encoding & ~0xff)
4324 const unsigned Format = Encoding & 0xf;
4331 const unsigned Application = Encoding & 0x70;
4343bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4344 int64_t Encoding = 0;
4345 if (parseAbsoluteExpression(Encoding))
4353 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4357 getStreamer().emitCFIPersonality(Sym, Encoding);
4359 getStreamer().emitCFILsda(Sym, Encoding);
4365bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4368 getStreamer().emitCFIRememberState(DirectiveLoc);
4374bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4377 getStreamer().emitCFIRestoreState(DirectiveLoc);
4383bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4386 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4389 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4395bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4397 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4400 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4406bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4409 if (parseAbsoluteExpression(CurrValue))
4412 Values.push_back((uint8_t)CurrValue);
4417 if (parseAbsoluteExpression(CurrValue))
4420 Values.push_back((uint8_t)CurrValue);
4423 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4429bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4431 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4433 getStreamer().emitCFIReturnColumn(
Register);
4439bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4443 getStreamer().emitCFISignalFrame();
4449bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4452 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4455 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4461bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4464 if (parseIdentifier(Name))
4465 return TokError(
"expected identifier");
4468 getStreamer().emitCFILabelDirective(Loc, Name);
4474bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4478 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4479 parseAbsoluteExpression(
Offset) || parseEOL())
4489bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4492 AltMacroMode = (Directive ==
".altmacro");
4499bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4502 setMacrosEnabled(Directive ==
".macros_on");
4508bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4510 if (parseIdentifier(Name))
4511 return TokError(
"expected identifier in '.macro' directive");
4520 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4522 "' should be the last parameter");
4526 return TokError(
"expected identifier in '.macro' directive");
4529 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4531 return TokError(
"macro '" + Name +
"' has multiple parameters"
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 +
"'");
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();
4600 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4607 }
else if (getTok().getIdentifier() ==
".macro") {
4613 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4617 eatToEndOfStatement();
4621 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4626 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4627 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4628 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4649void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
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];
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;
4710 StringRef
Argument(Begin,
I - (Pos + 1));
4713 if (Parameters[Index].Name == Argument)
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");
4739bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
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();
4760bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4762 return TokError(
"unexpected token in '" + Directive +
"' directive");
4766 if (isInsideMacroInstantiation()) {
4773 return TokError(
"unexpected '" + Directive +
"' in file, "
4774 "no current macro definition");
4779bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4782 if (parseTokenLoc(Loc) ||
4783 check(parseIdentifier(Name), Loc,
4784 "expected identifier in '.purgem' directive") ||
4789 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4793 <<
"Un-defining macro: " << Name <<
"\n");
4799bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4800 SMLoc NumBytesLoc = Lexer.
getLoc();
4801 const MCExpr *NumBytes;
4802 if (checkForValidSection() || parseExpression(NumBytes))
4805 int64_t FillExpr = 0;
4807 if (parseAbsoluteExpression(FillExpr))
4813 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4820bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
4821 SMLoc NumValuesLoc = Lexer.
getLoc();
4823 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4826 if (NumValues < 0) {
4827 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4834 const MCExpr *
Value;
4835 SMLoc ExprLoc = getLexer().getLoc();
4836 if (parseExpression(
Value))
4842 uint64_t IntValue = MCE->getValue();
4844 return Error(ExprLoc,
"literal value out of range for directive");
4845 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4846 getStreamer().emitIntValue(IntValue,
Size);
4848 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4849 getStreamer().emitValue(
Value,
Size, ExprLoc);
4857bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
4858 SMLoc NumValuesLoc = Lexer.
getLoc();
4860 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4863 if (NumValues < 0) {
4864 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4872 if (parseRealValue(Semantics, AsInt) || parseEOL())
4875 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4884bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
4885 SMLoc NumValuesLoc = Lexer.
getLoc();
4887 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4891 if (NumValues < 0) {
4892 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4896 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4897 getStreamer().emitFill(
Size, 0);
4904bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4905 if (checkForValidSection())
4908 auto parseOp = [&]() ->
bool {
4909 const MCExpr *
Value;
4910 if (parseExpression(
Value))
4913 getStreamer().emitSLEB128Value(
Value);
4915 getStreamer().emitULEB128Value(
Value);
4919 return parseMany(parseOp);
4924bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4925 auto parseOp = [&]() ->
bool {
4927 SMLoc Loc = getTok().getLoc();
4928 if (parseIdentifier(Name))
4929 return Error(Loc,
"expected identifier");
4931 if (discardLTOSymbol(Name))
4939 return Error(Loc,
"non-local symbol required");
4941 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
4942 return Error(Loc,
"unable to emit symbol attribute");
4946 return parseMany(parseOp);
4951bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4952 if (checkForValidSection())
4955 SMLoc IDLoc = getLexer().getLoc();
4958 return TokError(
"expected identifier in directive");
4964 SMLoc SizeLoc = getLexer().getLoc();
4965 if (parseAbsoluteExpression(
Size))
4968 int64_t Pow2Alignment = 0;
4969 SMLoc Pow2AlignmentLoc;
4972 Pow2AlignmentLoc = getLexer().getLoc();
4973 if (parseAbsoluteExpression(Pow2Alignment))
4978 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4984 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4985 Pow2Alignment =
Log2_64(Pow2Alignment);
4995 return Error(SizeLoc,
"size must be non-negative");
4999 return Error(IDLoc,
"invalid symbol redefinition");
5003 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5004 Align(1ULL << Pow2Alignment));
5008 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
5014bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5015 StringRef Str = parseStringToEndOfStatement();
5020 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5023 return Error(DirectiveLoc,
5024 ".abort '" + Str +
"' detected. Assembly stopping");
5029bool AsmParser::parseDirectiveInclude() {
5032 SMLoc IncludeLoc = getTok().getLoc();
5035 "expected string in '.include' directive") ||
5038 "unexpected token in '.include' directive") ||
5041 check(enterIncludeFile(
Filename), IncludeLoc,
5042 "Could not find include file '" +
Filename +
"'"))
5050bool AsmParser::parseDirectiveIncbin() {
5053 SMLoc IncbinLoc = getTok().getLoc();
5055 "expected string in '.incbin' directive") ||
5060 const MCExpr *
Count =
nullptr;
5061 SMLoc SkipLoc, CountLoc;
5066 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5070 CountLoc = getTok().getLoc();
5071 if (parseExpression(
Count))
5079 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5084 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5090bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5091 TheCondStack.push_back(TheCondState);
5093 if (TheCondState.
Ignore) {
5094 eatToEndOfStatement();
5097 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5107 ExprValue = ExprValue == 0;
5110 ExprValue = ExprValue >= 0;
5113 ExprValue = ExprValue > 0;
5116 ExprValue = ExprValue <= 0;
5119 ExprValue = ExprValue < 0;
5123 TheCondState.
CondMet = ExprValue;
5132bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5133 TheCondStack.push_back(TheCondState);
5136 if (TheCondState.
Ignore) {
5137 eatToEndOfStatement();
5139 StringRef Str = parseStringToEndOfStatement();
5144 TheCondState.
CondMet = ExpectBlank == Str.empty();
5154bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5155 TheCondStack.push_back(TheCondState);
5158 if (TheCondState.
Ignore) {
5159 eatToEndOfStatement();
5161 StringRef Str1 = parseStringToComma();
5166 StringRef Str2 = parseStringToEndOfStatement();
5180bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5181 TheCondStack.push_back(TheCondState);
5184 if (TheCondState.
Ignore) {
5185 eatToEndOfStatement();
5189 return TokError(
"expected string parameter for '.ifeqs' directive");
5190 return TokError(
"expected string parameter for '.ifnes' directive");
5193 StringRef String1 = getTok().getStringContents();
5199 "expected comma after first string for '.ifeqs' directive");
5201 "expected comma after first string for '.ifnes' directive");
5208 return TokError(
"expected string parameter for '.ifeqs' directive");
5209 return TokError(
"expected string parameter for '.ifnes' directive");
5212 StringRef String2 = getTok().getStringContents();
5215 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5224bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5226 TheCondStack.push_back(TheCondState);
5229 if (TheCondState.
Ignore) {
5230 eatToEndOfStatement();
5232 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5250bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5253 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5254 " .if or an .elseif");
5257 bool LastIgnoreState =
false;
5258 if (!TheCondStack.empty())
5259 LastIgnoreState = TheCondStack.back().Ignore;
5260 if (LastIgnoreState || TheCondState.
CondMet) {
5261 TheCondState.
Ignore =
true;
5262 eatToEndOfStatement();
5265 if (parseAbsoluteExpression(ExprValue))
5271 TheCondState.
CondMet = ExprValue;
5280bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5286 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5287 " an .if or an .elseif");
5289 bool LastIgnoreState =
false;
5290 if (!TheCondStack.empty())
5291 LastIgnoreState = TheCondStack.back().Ignore;
5292 if (LastIgnoreState || TheCondState.
CondMet)
5293 TheCondState.
Ignore =
true;
5295 TheCondState.
Ignore =
false;
5302bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5315bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5316 if (!TheCondStack.empty()) {
5317 if (TheCondStack.back().Ignore) {
5318 eatToEndOfStatement();
5324 return Error(L,
".err encountered");
5326 StringRef Message =
".error directive invoked in source file";
5329 return TokError(
".error argument must be a string");
5331 Message = getTok().getStringContents();
5335 return Error(L, Message);
5340bool AsmParser::parseDirectiveWarning(SMLoc L) {
5341 if (!TheCondStack.empty()) {
5342 if (TheCondStack.back().Ignore) {
5343 eatToEndOfStatement();
5348 StringRef Message =
".warning directive invoked in source file";
5352 return TokError(
".warning argument must be a string");
5354 Message = getTok().getStringContents();
5365bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5370 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5372 if (!TheCondStack.empty()) {
5373 TheCondState = TheCondStack.back();
5374 TheCondStack.pop_back();
5380void AsmParser::initializeDirectiveKindMap() {
5387 DirectiveKindMap[
".set"] = DK_SET;
5388 DirectiveKindMap[
".equ"] = DK_EQU;
5389 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5390 DirectiveKindMap[
".ascii"] = DK_ASCII;
5391 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5392 DirectiveKindMap[
".string"] = DK_STRING;
5393 DirectiveKindMap[
".byte"] = DK_BYTE;
5394 DirectiveKindMap[
".base64"] = DK_BASE64;
5395 DirectiveKindMap[
".short"] = DK_SHORT;
5396 DirectiveKindMap[
".value"] = DK_VALUE;
5397 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5398 DirectiveKindMap[
".long"] = DK_LONG;
5399 DirectiveKindMap[
".int"] = DK_INT;
5400 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5401 DirectiveKindMap[
".quad"] = DK_QUAD;
5402 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5403 DirectiveKindMap[
".octa"] = DK_OCTA;
5404 DirectiveKindMap[
".single"] = DK_SINGLE;
5405 DirectiveKindMap[
".float"] = DK_FLOAT;
5406 DirectiveKindMap[
".double"] = DK_DOUBLE;
5407 DirectiveKindMap[
".align"] = DK_ALIGN;
5408 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5409 DirectiveKindMap[
".balign"] = DK_BALIGN;
5410 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5411 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5412 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5413 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5414 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5415 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5416 DirectiveKindMap[
".org"] = DK_ORG;
5417 DirectiveKindMap[
".fill"] = DK_FILL;
5418 DirectiveKindMap[
".zero"] = DK_ZERO;
5419 DirectiveKindMap[
".extern"] = DK_EXTERN;
5420 DirectiveKindMap[
".globl"] = DK_GLOBL;
5421 DirectiveKindMap[
".global"] = DK_GLOBAL;
5422 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5423 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5424 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5425 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5426 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5427 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5428 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5429 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5430 DirectiveKindMap[
".cold"] = DK_COLD;
5431 DirectiveKindMap[
".comm"] = DK_COMM;
5432 DirectiveKindMap[
".common"] = DK_COMMON;
5433 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5434 DirectiveKindMap[
".abort"] = DK_ABORT;
5435 DirectiveKindMap[
".include"] = DK_INCLUDE;
5436 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5437 DirectiveKindMap[
".code16"] = DK_CODE16;
5438 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5439 DirectiveKindMap[
".rept"] = DK_REPT;
5440 DirectiveKindMap[
".rep"] = DK_REPT;
5441 DirectiveKindMap[
".irp"] = DK_IRP;
5442 DirectiveKindMap[
".irpc"] = DK_IRPC;
5443 DirectiveKindMap[
".endr"] = DK_ENDR;
5444 DirectiveKindMap[
".if"] = DK_IF;
5445 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5446 DirectiveKindMap[
".ifge"] = DK_IFGE;
5447 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5448 DirectiveKindMap[
".ifle"] = DK_IFLE;
5449 DirectiveKindMap[
".iflt"] = DK_IFLT;
5450 DirectiveKindMap[
".ifne"] = DK_IFNE;
5451 DirectiveKindMap[
".ifb"] = DK_IFB;
5452 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5453 DirectiveKindMap[
".ifc"] = DK_IFC;
5454 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5455 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5456 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5457 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5458 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5459 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5460 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5461 DirectiveKindMap[
".else"] = DK_ELSE;
5462 DirectiveKindMap[
".end"] = DK_END;
5463 DirectiveKindMap[
".endif"] = DK_ENDIF;
5464 DirectiveKindMap[
".skip"] = DK_SKIP;
5465 DirectiveKindMap[
".space"] = DK_SPACE;
5466 DirectiveKindMap[
".file"] = DK_FILE;
5467 DirectiveKindMap[
".line"] = DK_LINE;
5468 DirectiveKindMap[
".loc"] = DK_LOC;
5469 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5470 DirectiveKindMap[
".stabs"] = DK_STABS;
5471 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5472 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5473 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5474 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5475 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5476 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5477 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5478 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5479 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5480 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5481 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5482 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5483 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5484 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5485 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5486 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5487 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5488 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5489 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5490 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5491 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5492 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5493 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5494 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5495 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5496 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5497 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5498 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5499 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5500 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5501 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5502 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5503 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5504 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5505 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5506 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5507 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5508 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5509 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5510 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5511 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5512 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5513 DirectiveKindMap[
".macro"] = DK_MACRO;
5514 DirectiveKindMap[
".exitm"] = DK_EXITM;
5515 DirectiveKindMap[
".endm"] = DK_ENDM;
5516 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5517 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5518 DirectiveKindMap[
".err"] = DK_ERR;
5519 DirectiveKindMap[
".error"] = DK_ERROR;
5520 DirectiveKindMap[
".warning"] = DK_WARNING;
5521 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5522 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5523 DirectiveKindMap[
".reloc"] = DK_RELOC;
5524 DirectiveKindMap[
".dc"] = DK_DC;
5525 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5526 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5527 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5528 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5529 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5530 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5531 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5532 DirectiveKindMap[
".dcb"] = DK_DCB;
5533 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5534 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5535 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5536 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5537 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5538 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5539 DirectiveKindMap[
".ds"] = DK_DS;
5540 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5541 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5542 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5543 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5544 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5545 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5546 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5547 DirectiveKindMap[
".print"] = DK_PRINT;
5548 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5549 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5550 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5551 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5552 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5553 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5556MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5557 AsmToken EndToken, StartToken = getTok();
5559 unsigned NestLevel = 0;
5563 printError(DirectiveLoc,
"no matching '.endr' in definition");
5568 StringRef Ident = getTok().getIdentifier();
5569 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5572 }
else if (Ident ==
".endr") {
5573 if (NestLevel == 0) {
5574 EndToken = getTok();
5578 printError(getTok().getLoc(),
"expected newline");
5586 eatToEndOfStatement();
5591 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5595 return &MacroLikeBodies.back();
5598void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5599 raw_svector_ostream &OS) {
5602 std::unique_ptr<MemoryBuffer> Instantiation =
5607 MacroInstantiation *
MI =
new MacroInstantiation{
5608 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5609 ActiveMacros.push_back(
MI);
5619bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5620 const MCExpr *CountExpr;
5621 SMLoc CountLoc = getTok().getLoc();
5622 if (parseExpression(CountExpr))
5626 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5627 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5630 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5634 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5640 SmallString<256> Buf;
5641 raw_svector_ostream OS(Buf);
5644 if (expandMacro(OS, *M, {}, {},
false))
5647 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5654bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5656 MCAsmMacroArguments
A;
5657 if (check(parseIdentifier(
Parameter.Name),
5658 "expected identifier in '.irp' directive") ||
5659 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5663 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5669 SmallString<256> Buf;
5670 raw_svector_ostream OS(Buf);
5672 for (
const MCAsmMacroArgument &Arg :
A) {
5675 if (expandMacro(OS, *M, Parameter, Arg,
true))
5679 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5686bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5688 MCAsmMacroArguments
A;
5690 if (check(parseIdentifier(
Parameter.Name),
5691 "expected identifier in '.irpc' directive") ||
5692 parseComma() || parseMacroArguments(
nullptr,
A))
5695 if (
A.size() != 1 ||
A.front().size() != 1)
5696 return TokError(
"unexpected token in '.irpc' directive");
5701 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5707 SmallString<256> Buf;
5708 raw_svector_ostream OS(Buf);
5711 :
A[0][0].getString();
5712 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5713 MCAsmMacroArgument Arg;
5718 if (expandMacro(OS, *M, Parameter, Arg,
true))
5722 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5727bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5728 if (ActiveMacros.empty())
5729 return TokError(
"unmatched '.endr' directive");
5739bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &
Info,
5741 const MCExpr *
Value;
5742 SMLoc ExprLoc = getLexer().getLoc();
5743 if (parseExpression(
Value))
5747 return Error(ExprLoc,
"unexpected expression in _emit");
5748 uint64_t IntValue = MCE->
getValue();
5750 return Error(ExprLoc,
"literal value out of range for directive");
5756bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &
Info) {
5757 const MCExpr *
Value;
5758 SMLoc ExprLoc = getLexer().getLoc();
5759 if (parseExpression(
Value))
5763 return Error(ExprLoc,
"unexpected expression in align");
5764 uint64_t IntValue = MCE->
getValue();
5766 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5772bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5773 const AsmToken StrTok = getTok();
5776 return Error(DirectiveLoc,
"expected double quoted string after .print");
5783bool AsmParser::parseDirectiveAddrsig() {
5786 getStreamer().emitAddrsig();
5790bool AsmParser::parseDirectiveAddrsigSym() {
5792 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
5794 getStreamer().emitAddrsigSym(Sym);
5798bool AsmParser::parseDirectivePseudoProbe() {
5804 if (parseIntToken(
Guid))
5806 if (parseIntToken(Index))
5808 if (parseIntToken(
Type))
5810 if (parseIntToken(Attr))
5822 int64_t CallerGuid = 0;
5824 CallerGuid = getTok().getIntVal();
5832 int64_t CallerProbeId = 0;
5834 CallerProbeId = getTok().getIntVal();
5844 if (parseIdentifier(FnName))
5845 return Error(getLexer().getLoc(),
"expected identifier");
5851 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
5852 InlineStack, FnSym);
5861bool AsmParser::parseDirectiveLTODiscard() {
5862 auto ParseOp = [&]() ->
bool {
5864 SMLoc Loc = getTok().getLoc();
5865 if (parseIdentifier(Name))
5866 return Error(Loc,
"expected identifier");
5867 LTODiscardSymbols.
insert(Name);
5871 LTODiscardSymbols.
clear();
5872 return parseMany(ParseOp);
5898bool AsmParser::parseMSInlineAsm(
5899 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
5900 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5901 SmallVectorImpl<std::string> &Constraints,
5902 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
5903 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
5904 SmallVector<void *, 4> InputDecls;
5905 SmallVector<void *, 4> OutputDecls;
5908 SmallVector<std::string, 4> InputConstraints;
5909 SmallVector<std::string, 4> OutputConstraints;
5918 unsigned InputIdx = 0;
5919 unsigned OutputIdx = 0;
5922 if (parseCurlyBlockScope(AsmStrRewrites))
5925 ParseStatementInfo
Info(&AsmStrRewrites);
5926 bool StatementErr = parseStatement(
Info, &SI);
5928 if (StatementErr ||
Info.ParseError) {
5930 printPendingErrors();
5935 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5937 if (
Info.Opcode == ~0U)
5943 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
5944 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
5948 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
5949 unsigned NumDefs =
Desc.getNumDefs();
5958 if (SymName.
empty())
5966 if (Operand.
isImm()) {
5974 bool isOutput = (i == 1) &&
Desc.mayStore();
5981 OutputConstraints.
push_back((
"=" + Constraint).str());
5988 if (
Desc.operands()[i - 1].isBranchTarget())
6002 NumOutputs = OutputDecls.
size();
6003 NumInputs = InputDecls.
size();
6008 Clobbers.
assign(ClobberRegs.
size(), std::string());
6009 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6010 raw_string_ostream OS(Clobbers[
I]);
6015 if (NumOutputs || NumInputs) {
6016 unsigned NumExprs = NumOutputs + NumInputs;
6017 OpDecls.resize(NumExprs);
6018 Constraints.
resize(NumExprs);
6019 for (
unsigned i = 0; i < NumOutputs; ++i) {
6020 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6021 Constraints[i] = OutputConstraints[i];
6023 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6024 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6025 Constraints[
j] = InputConstraints[i];
6030 std::string AsmStringIR;
6031 raw_string_ostream OS(AsmStringIR);
6032 StringRef ASMString =
6034 const char *AsmStart = ASMString.
begin();
6035 const char *AsmEnd = ASMString.
end();
6037 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6038 const AsmRewrite &AR = *
I;
6045 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6048 if (
unsigned Len = Loc - AsmStart)
6049 OS << StringRef(AsmStart, Len);
6053 AsmStart = Loc + AR.
Len;
6057 unsigned AdditionalSkip = 0;
6079 size_t OffsetLen = OffsetName.
size();
6080 auto rewrite_it = std::find_if(
6081 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6082 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6083 (FusingAR.Kind == AOK_Input ||
6084 FusingAR.Kind == AOK_CallInput);
6086 if (rewrite_it == AsmStrRewrites.
end()) {
6087 OS <<
"offset " << OffsetName;
6089 OS <<
"${" << InputIdx++ <<
":P}";
6090 rewrite_it->Done =
true;
6092 OS <<
'$' << InputIdx++;
6093 rewrite_it->Done =
true;
6106 OS <<
"${" << InputIdx++ <<
":P}";
6108 OS <<
'$' << InputIdx++;
6111 OS <<
"${" << InputIdx++ <<
":P}";
6115 OS <<
"${" << OutputIdx++ <<
":P}";
6117 OS <<
'$' << OutputIdx++;
6122 case 8: OS <<
"byte ptr ";
break;
6123 case 16: OS <<
"word ptr ";
break;
6124 case 32: OS <<
"dword ptr ";
break;
6125 case 64: OS <<
"qword ptr ";
break;
6126 case 80: OS <<
"xword ptr ";
break;
6127 case 128: OS <<
"xmmword ptr ";
break;
6128 case 256: OS <<
"ymmword ptr ";
break;
6138 if (
getContext().getAsmInfo()->getAlignmentIsInBytes())
6143 unsigned Val = AR.
Val;
6145 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6146 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6158 AsmStart = Loc + AR.
Len + AdditionalSkip;
6162 if (AsmStart != AsmEnd)
6163 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6165 AsmString = std::move(AsmStringIR);
6169bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &
Info,
6170 MCAsmParserSemaCallback *SI) {
6171 AsmToken LabelTok = getTok();
6172 SMLoc LabelLoc = LabelTok.
getLoc();
6175 if (parseIdentifier(LabelVal))
6176 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6181 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6190 return Error(LabelLoc,
6191 "Cannot have just a label for an HLASM inline asm statement");
6201 if (enabledGenDwarfForAssembly())
6208bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &
Info,
6209 MCAsmParserSemaCallback *SI) {
6210 AsmToken OperationEntryTok = Lexer.
getTok();
6211 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6212 StringRef OperationEntryVal;
6215 if (parseIdentifier(OperationEntryVal))
6216 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6222 return parseAndMatchAndEmitTargetInstruction(
6223 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6226bool HLASMAsmParser::parseStatement(ParseStatementInfo &
Info,
6227 MCAsmParserSemaCallback *SI) {
6228 assert(!hasPendingError() &&
"parseStatement started with pending error");
6231 bool ShouldParseAsHLASMLabel =
false;
6240 ShouldParseAsHLASMLabel =
true;
6246 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6247 getTok().getString().
front() ==
'\n')
6262 if (getTok().getString().
front() ==
'\n' ||
6263 getTok().getString().
front() ==
'\r') {
6272 if (ShouldParseAsHLASMLabel) {
6275 if (parseAsHLASMLabel(
Info, SI)) {
6278 eatToEndOfStatement();
6283 return parseAsMachineInstruction(
Info, SI);
6295 return Parser.
TokError(
"missing expression");
6301 return Parser.
Error(
6302 EqualLoc,
"relocation specifier not permitted in symbol equating");
6310 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6316 }
else if (Name ==
".") {
6331 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6332 return new HLASMAsmParser(SM,
C, Out, MAI, CB);
6334 return new AsmParser(SM,
C, Out, MAI, CB);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static Expected< std::vector< unsigned > > getSymbols(SymbolicFile *Obj, uint16_t Index, raw_ostream &SymNames, SymMap *SymMap)
static bool isValidEncoding(int64_t Encoding)
static bool isAngleBracketString(SMLoc &StrLoc, SMLoc &EndLoc)
This function checks if the next token is <string> type or arithmetic.
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static unsigned getGNUBinOpPrecedence(const MCAsmInfo &MAI, AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static std::string angleBracketString(StringRef AltMacroStr)
creating a string without the escape characters '!'.
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
static bool parseHexOcta(AsmParser &Asm, uint64_t &hi, uint64_t &lo)
static bool isOperator(AsmToken::TokenKind kind)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
This file contains constants used for implementing Dwarf debug support.
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_BASIC_BLOCK
#define DWARF2_LINE_DEFAULT_IS_STMT
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$....
Promote Memory to Register
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Class for arbitrary precision integers.
LLVM_ABI APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
unsigned getBitWidth() const
Return the number of bits in the APInt.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
ConditionalAssemblyType TheCond
SMLoc getLoc() const
Get the current source location.
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool getAllowAtInIdentifier()
void UnLex(AsmToken const &Token)
AsmToken::TokenKind getKind() const
Get the kind of current token.
const MCAsmInfo & getMAI() const
const AsmToken & getTok() const
Get the current (last) lexed token.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
SMLoc getErrLoc()
Get the current error location.
const std::string & getErr()
Get the current error string.
const AsmToken & Lex()
Consume the next token from the input stream and return it.
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
LLVM_ABI void setBuffer(StringRef Buf, const char *ptr=nullptr, bool EndStatementAtEOF=true)
Set buffer to be lexed.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
LLVM_ABI size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)
Look ahead an arbitrary number of tokens.
LLVM_ABI SMLoc getLoc() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
bool is(TokenKind K) const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Error takeError()
Take ownership of the stored error.
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
bool isLittleEndian() const
True if the target is little endian.
bool useAtForSpecifier() const
bool doesAllowAtInName() const
StringRef getPrivateLabelPrefix() const
std::optional< uint32_t > getSpecifierForName(StringRef Name) const
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
bool shouldUseLogicalShr() const
StringRef getCommentString() const
bool hasSubsectionsViaSymbols() const
bool getCOMMDirectiveAlignmentIsInBytes() const
virtual bool useCodeAlign(const MCSection &Sec) const
bool useParensForSpecifier() const
bool getDollarIsPC() const
virtual ~MCAsmParserSemaCallback()
Generic assembler parser interface, for use by target specific assembly parsers.
bool Error(SMLoc L, const Twine &Msg, SMRange Range={})
Return an error at the location L, with the message Msg.
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
bool parseAtSpecifier(const MCExpr *&Res, SMLoc &EndLoc)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
const MCExpr * applySpecifier(const MCExpr *E, uint32_t Variant)
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
bool TokError(const Twine &Msg, SMRange Range={})
Report an error at the current lexer location.
MCStreamer & getStreamer()
MCTargetAsmParser & getTargetParser() const
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
@ AShr
Arithmetic shift right.
@ LShr
Logical shift right.
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
@ Xor
Bitwise exclusive or.
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
@ NE
Inequality comparison.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
void * allocate(unsigned Size, unsigned Align=8)
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
bool getGenDwarfForAssembly()
void setGenDwarfForAssembly(bool Value)
void setDwarfVersion(uint16_t v)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_ABI MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
LLVM_ABI MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
uint16_t getDwarfVersion() const
const MCAsmInfo * getAsmInfo() const
LLVM_ABI MCSymbol * cloneSymbol(MCSymbol &Sym)
Clone a symbol for the .set directive, replacing it in the symbol table.
LLVM_ABI MCSymbol * parseSymbol(const Twine &Name)
Variant of getOrCreateSymbol that handles backslash-escaped symbols.
LLVM_ABI MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
virtual void printRegName(raw_ostream &OS, MCRegister Reg)
Print the assembler register name.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
virtual bool isMemUseUpRegs() const
isMemUseUpRegs - Is memory operand use up regs, for example, intel MS inline asm may use ARR[baseReg ...
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label?
virtual MCRegister getReg() const =0
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable,...
virtual StringRef getSymName()
virtual bool isImm() const =0
isImm - Is this an immediate operand?
unsigned getMCOperandNum()
StringRef getConstraint()
virtual void * getOpDecl()
void setBeginSymbol(MCSymbol *Sym)
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI)
Create the default sections and set the initial one.
void setStartTokLocPtr(const SMLoc *Loc)
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
MCTargetStreamer * getTargetStreamer()
virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc)
Emit some number of copies of Value until the byte offset Offset is reached.
virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol, but only if Value is also emitted.
void finish(SMLoc EndLoc=SMLoc())
Finish emission of machine code.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
uint16_t getSpecifier() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
bool isRedefinable() const
Check if this symbol is redefinable.
void setRedefinable(bool Value)
Mark this symbol as redefinable.
void redefineIfPossible()
Prepare this symbol to be redefined.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Unary assembler expressions.
Opcode getOpcode() const
Get the kind of this unary expression.
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getSubExpr() const
Get the child of this unary expression.
static const MCUnaryExpr * createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
StringRef getBuffer() const
constexpr bool isFailure() const
constexpr bool isSuccess() const
SourceMgr::DiagKind getKind() const
StringRef getLineContents() const
StringRef getMessage() const
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
const SourceMgr * getSourceMgr() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
constexpr bool isValid() const
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
unsigned getMainFileID() const
const MemoryBuffer * getMemoryBuffer(unsigned i) const
LLVM_ABI void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
SMLoc getParentIncludeLoc(unsigned i) const
LLVM_ABI void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
LLVM_ABI unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
LLVM_ABI unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
StringMapIterBase< ValueTy, true > const_iterator
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
LLVM_ABI std::string lower() const
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
LLVM Value Representation.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
std::variant< std::monostate, DecisionParameters, BranchParameters > Parameters
The type of MC/DC-specific parameters.
@ Parameter
An inlay hint that is for a parameter.
Context & getContext() const
LLVM_ABI Instruction & front() const
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
FunctionAddr VTableAddr Value
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation. The return string is half the size of ...
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
std::tuple< uint64_t, uint32_t > InlineSite
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
auto unique(Range &&R, Predicate P)
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
cl::opt< unsigned > AsmMacroMaxNestingDepth
SmallVector< InlineSite, 8 > MCPseudoProbeInlineStack
const char AsmRewritePrecedence[]
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool hasDiscriminator(uint32_t Flags)
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
FunctionAddr VTableAddr Count
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ABI llvm::Error decodeBase64(llvm::StringRef Input, std::vector< char > &Output)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance for parsing assembly similar to gas syntax.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
@ Sub
Subtraction of integers.
FunctionAddr VTableAddr Next
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
void consumeError(Error Err)
Consume a Error without doing anything.
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
ArrayRef< int > hi(ArrayRef< int > Vuu)
ArrayRef< int > lo(ArrayRef< int > Vuu)
std::vector< AsmToken > Value
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
std::optional< StringRef > Source
The source code of the file.