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;
123 std::unique_ptr<MCAsmParserExtension> LFIParser;
125 std::optional<SMLoc> CFIStartProcLoc;
131 AsmCond TheCondState;
132 std::vector<AsmCond> TheCondStack;
137 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
140 std::vector<MacroInstantiation*> ActiveMacros;
143 std::deque<MCAsmMacro> MacroLikeBodies;
146 unsigned MacrosEnabledFlag : 1;
149 unsigned NumOfMacroInstantiations = 0;
152 struct CppHashInfoTy {
157 CppHashInfoTy() : LineNumber(0), Buf(0) {}
159 CppHashInfoTy CppHashInfo;
162 bool HadCppHashFilename =
false;
167 SmallSet<StringRef, 2> LTODiscardSymbols;
170 unsigned AssemblerDialect = ~0
U;
173 bool IsDarwin =
false;
176 bool ParsingMSInlineAsm =
false;
179 bool ReportedInconsistentMD5 =
false;
182 bool AltMacroMode =
false;
185 virtual bool parseStatement(ParseStatementInfo &Info,
186 MCAsmParserSemaCallback *SI);
191 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
192 StringRef IDVal, AsmToken
ID,
198 bool enabledGenDwarfForAssembly();
201 AsmParser(SourceMgr &
SM, MCContext &Ctx, MCStreamer &Out,
202 const MCAsmInfo &MAI,
unsigned CB);
203 AsmParser(
const AsmParser &) =
delete;
204 AsmParser &operator=(
const AsmParser &) =
delete;
205 ~AsmParser()
override;
207 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
209 void addDirectiveHandler(StringRef Directive,
210 ExtensionDirectiveHandler Handler)
override {
211 ExtensionDirectiveMap[Directive] = std::move(Handler);
214 void addAliasForDirective(StringRef Directive, StringRef Alias)
override {
215 DirectiveKindMap[Directive.
lower()] = DirectiveKindMap[Alias.
lower()];
221 CodeViewContext &getCVContext() {
return Ctx.getCVContext(); }
223 unsigned getAssemblerDialect()
override {
224 if (AssemblerDialect == ~0U)
225 return MAI.getAssemblerDialect();
227 return AssemblerDialect;
229 void setAssemblerDialect(
unsigned i)
override {
230 AssemblerDialect = i;
233 void Note(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
234 bool Warning(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
235 bool printError(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
237 const AsmToken &Lex()
override;
239 void setParsingMSInlineAsm(
bool V)
override {
240 ParsingMSInlineAsm =
V;
243 Lexer.setLexMasmIntegers(V);
245 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
247 bool discardLTOSymbol(StringRef Name)
const override {
248 return LTODiscardSymbols.contains(Name);
251 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
253 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
254 SmallVectorImpl<std::string> &Constraints,
255 SmallVectorImpl<std::string> &Clobbers,
256 const MCInstrInfo *MII, MCInstPrinter *IP,
257 MCAsmParserSemaCallback &SI)
override;
259 bool parseExpression(
const MCExpr *&Res);
260 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
261 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
262 AsmTypeInfo *TypeInfo)
override;
263 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
264 bool parseAbsoluteExpression(int64_t &Res)
override;
268 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
272 bool parseIdentifier(StringRef &Res)
override;
273 void eatToEndOfStatement()
override;
275 bool checkForValidSection()
override;
280 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
281 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
283 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
285 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
290 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
293 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
296 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
302 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
305 void handleMacroExit();
308 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
311 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
313 void printMacroInstantiations();
315 SMRange
Range = {})
const {
322 bool enterIncludeFile(
const std::string &
Filename);
326 bool processIncbinFile(
const std::string &
Filename, int64_t Skip = 0,
327 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
335 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
340 StringRef parseStringToEndOfStatement()
override;
344 StringRef parseStringToComma();
346 enum class AssignmentKind {
353 bool parseAssignment(StringRef Name, AssignmentKind Kind);
358 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
359 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
360 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
362 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
364 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
365 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
436 DK_WEAK_DEF_CAN_BE_HIDDEN,
477 DK_CV_INLINE_SITE_ID,
480 DK_CV_INLINE_LINETABLE,
485 DK_CV_FILECHECKSUM_OFFSET,
491 DK_CFI_DEF_CFA_OFFSET,
492 DK_CFI_ADJUST_CFA_OFFSET,
493 DK_CFI_DEF_CFA_REGISTER,
494 DK_CFI_LLVM_DEF_ASPACE_CFA,
499 DK_CFI_REMEMBER_STATE,
500 DK_CFI_RESTORE_STATE,
504 DK_CFI_RETURN_COLUMN,
531 DK_LTO_SET_CONDITIONAL,
532 DK_CFI_MTE_TAGGED_FRAME,
540 StringMap<DirectiveKind> DirectiveKindMap;
543 enum CVDefRangeType {
545 CVDR_DEFRANGE_REGISTER,
546 CVDR_DEFRANGE_FRAMEPOINTER_REL,
547 CVDR_DEFRANGE_SUBFIELD_REGISTER,
548 CVDR_DEFRANGE_REGISTER_REL
553 StringMap<CVDefRangeType> CVDefRangeTypeMap;
556 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
557 bool parseDirectiveBase64();
558 bool parseDirectiveReloc(SMLoc DirectiveLoc);
559 bool parseDirectiveValue(StringRef IDVal,
561 bool parseDirectiveOctaValue(StringRef IDVal);
562 bool parseDirectiveRealValue(StringRef IDVal,
563 const fltSemantics &);
564 bool parseDirectiveFill();
565 bool parseDirectiveZero();
567 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
568 bool parseDirectiveOrg();
570 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
571 bool parseDirectivePrefAlign();
574 bool parseDirectiveFile(SMLoc DirectiveLoc);
575 bool parseDirectiveLine();
576 bool parseDirectiveLoc();
577 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
578 bool parseDirectiveStabs();
582 bool parseDirectiveCVFile();
583 bool parseDirectiveCVFuncId();
584 bool parseDirectiveCVInlineSiteId();
585 bool parseDirectiveCVLoc();
586 bool parseDirectiveCVLinetable();
587 bool parseDirectiveCVInlineLinetable();
588 bool parseDirectiveCVDefRange();
589 bool parseDirectiveCVString();
590 bool parseDirectiveCVStringTable();
591 bool parseDirectiveCVFileChecksums();
592 bool parseDirectiveCVFileChecksumOffset();
593 bool parseDirectiveCVFPOData();
596 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
597 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
598 bool parseDirectiveCFISections();
599 bool parseDirectiveCFIStartProc();
600 bool parseDirectiveCFIEndProc();
601 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
602 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
603 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
604 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
605 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
606 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
607 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
608 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
609 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
610 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
611 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
612 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
613 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
614 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
615 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
616 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
617 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
618 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
621 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
622 bool parseDirectiveExitMacro(StringRef Directive);
623 bool parseDirectiveEndMacro(StringRef Directive);
624 bool parseDirectiveMacro(SMLoc DirectiveLoc);
625 bool parseDirectiveMacrosOnOff(StringRef Directive);
627 bool parseDirectiveAltmacro(StringRef Directive);
630 bool parseDirectiveSpace(StringRef IDVal);
633 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
634 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
636 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
639 bool parseDirectiveLEB128(
bool Signed);
645 bool parseDirectiveComm(
bool IsLocal);
647 bool parseDirectiveAbort(SMLoc DirectiveLoc);
648 bool parseDirectiveInclude();
649 bool parseDirectiveIncbin();
652 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
654 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
656 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
658 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
660 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
661 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
662 bool parseDirectiveElse(SMLoc DirectiveLoc);
663 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
664 bool parseEscapedString(std::string &
Data)
override;
665 bool parseAngleBracketString(std::string &
Data)
override;
668 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
669 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
670 raw_svector_ostream &OS);
671 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
672 bool parseDirectiveIrp(SMLoc DirectiveLoc);
673 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
674 bool parseDirectiveEndr(SMLoc DirectiveLoc);
677 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,
681 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
684 bool parseDirectiveEnd(SMLoc DirectiveLoc);
687 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
690 bool parseDirectiveWarning(SMLoc DirectiveLoc);
693 bool parseDirectivePrint(SMLoc DirectiveLoc);
696 bool parseDirectivePseudoProbe();
699 bool parseDirectiveLTODiscard();
702 bool parseDirectiveAddrsig();
703 bool parseDirectiveAddrsigSym();
705 void initializeDirectiveKindMap();
706 void initializeCVDefRangeTypeMap();
709class HLASMAsmParser final :
public AsmParser {
714 void lexLeadingSpaces() {
719 bool parseAsHLASMLabel(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI);
720 bool parseAsMachineInstruction(ParseStatementInfo &Info,
721 MCAsmParserSemaCallback *SI);
724 HLASMAsmParser(SourceMgr &
SM, MCContext &Ctx, MCStreamer &Out,
725 const MCAsmInfo &MAI,
unsigned CB = 0)
726 : AsmParser(
SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
727 Lexer.setSkipSpace(
false);
728 Lexer.setAllowHashInIdentifier(
true);
729 Lexer.setLexHLASMIntegers(
true);
730 Lexer.setLexHLASMStrings(
true);
733 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
735 bool parseStatement(ParseStatementInfo &Info,
736 MCAsmParserSemaCallback *SI)
override;
749 :
MCAsmParser(Ctx, Out,
SM, MAI), CurBuffer(CB ? CB :
SM.getMainFileID()),
750 MacrosEnabledFlag(
true) {
753 SavedDiagHandler =
SrcMgr.getDiagHandler();
754 SavedDiagContext =
SrcMgr.getDiagContext();
762 switch (Ctx.getObjectFileType()) {
763 case MCContext::IsCOFF:
764 PlatformParser.reset(createCOFFAsmParser());
766 case MCContext::IsMachO:
767 PlatformParser.reset(createDarwinAsmParser());
770 case MCContext::IsELF:
771 PlatformParser.reset(createELFAsmParser());
773 case MCContext::IsGOFF:
774 PlatformParser.reset(createGOFFAsmParser());
776 case MCContext::IsSPIRV:
778 "Need to implement createSPIRVAsmParser for SPIRV format.");
780 case MCContext::IsWasm:
781 PlatformParser.reset(createWasmAsmParser());
783 case MCContext::IsXCOFF:
784 PlatformParser.reset(createXCOFFAsmParser());
786 case MCContext::IsDXContainer:
787 report_fatal_error(
"DXContainer is not supported yet");
791 PlatformParser->Initialize(*
this);
793 LFIParser.reset(createLFIAsmParser(Out.getLFIRewriter()));
794 LFIParser->Initialize(*this);
796 initializeDirectiveKindMap();
797 initializeCVDefRangeTypeMap();
800AsmParser::~AsmParser() {
801 assert((HadError || ActiveMacros.empty()) &&
802 "Unexpected active macro instantiation!");
811void AsmParser::printMacroInstantiations() {
813 for (MacroInstantiation *M :
reverse(ActiveMacros))
815 "while in macro instantiation");
818void AsmParser::Note(SMLoc L,
const Twine &Msg, SMRange
Range) {
819 printPendingErrors();
821 printMacroInstantiations();
824bool AsmParser::Warning(SMLoc L,
const Twine &Msg, SMRange
Range) {
825 if(getTargetParser().getTargetOptions().MCNoWarn)
827 if (getTargetParser().getTargetOptions().MCFatalWarnings)
830 printMacroInstantiations();
834bool AsmParser::printError(SMLoc L,
const Twine &Msg, SMRange
Range) {
837 printMacroInstantiations();
841bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
842 std::string IncludedFile;
856bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
857 const MCExpr *
Count, SMLoc Loc) {
859 if (SymbolScanningMode)
862 std::string IncludedFile;
873 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
874 return Error(Loc,
"expected absolute expression");
876 return Warning(Loc,
"negative count has no effect");
879 getStreamer().emitBytes(Bytes);
883void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
889const AsmToken &AsmParser::Lex() {
896 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
901 const AsmToken *tok = &Lexer.
Lex();
914 if (ParentIncludeLoc != SMLoc()) {
915 jumpToLoc(ParentIncludeLoc);
923bool AsmParser::enabledGenDwarfForAssembly() {
930 if (
getContext().getGenDwarfFileNumber() == 0) {
931 const MCDwarfFile &RootFile =
932 getContext().getMCDwarfLineTable(0).getRootFile();
933 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
940bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
941 LTODiscardSymbols.
clear();
944 if (!NoInitialTextSection)
951 AsmCond StartingCondState = TheCondState;
959 MCSection *Sec = getStreamer().getCurrentSectionOnly();
962 getStreamer().emitLabel(SectionStartSym);
965 bool InsertResult =
getContext().addGenDwarfSection(Sec);
966 assert(InsertResult &&
".text section should not have debug info yet");
970 getTargetParser().onBeginOfFile();
974 ParseStatementInfo
Info(&AsmStrRewrites);
975 bool HasError = parseStatement(Info,
nullptr);
984 printPendingErrors();
987 if (HasError && !getLexer().justConsumedEOL())
988 eatToEndOfStatement();
991 getTargetParser().onEndOfFile();
992 printPendingErrors();
995 assert(!hasPendingError() &&
"unexpected error from parseStatement");
999 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1001 const auto &LineTables =
getContext().getMCDwarfLineTables();
1002 if (!LineTables.empty()) {
1004 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1005 if (
File.Name.empty() && Index != 0)
1006 printError(getTok().getLoc(),
"unassigned file number: " +
1008 " for .file directives");
1020 MCSymbol *Sym = TableEntry.getValue().Symbol;
1029 printError(getTok().getLoc(),
"assembler local symbol '" +
1030 Sym->
getName() +
"' not defined");
1036 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1037 if (std::get<2>(LocSym)->isUndefined()) {
1040 CppHashInfo = std::get<1>(LocSym);
1041 printError(std::get<0>(LocSym),
"directional label undefined");
1047 if (!HadError && !NoFinalize) {
1049 TS->emitConstantPools();
1057bool AsmParser::checkForValidSection() {
1058 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1060 return Error(getTok().getLoc(),
1061 "expected section directive before assembly directive");
1067void AsmParser::eatToEndOfStatement() {
1076StringRef AsmParser::parseStringToEndOfStatement() {
1077 const char *
Start = getTok().getLoc().getPointer();
1083 return StringRef(Start, End - Start);
1086StringRef AsmParser::parseStringToComma() {
1087 const char *
Start = getTok().getLoc().getPointer();
1093 const char *End = getTok().getLoc().getPointer();
1094 return StringRef(Start, End - Start);
1102bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1103 if (parseExpression(Res))
1106 return parseRParen();
1114bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1115 if (parseExpression(Res))
1117 EndLoc = getTok().getEndLoc();
1118 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1129bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1130 AsmTypeInfo *TypeInfo) {
1131 SMLoc FirstTokenLoc = getLexer().getLoc();
1133 switch (FirstTokenKind) {
1135 return TokError(
"unknown token in expression");
1141 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1151 if (parseIdentifier(Identifier)) {
1155 bool ShouldGenerateTempSymbol =
false;
1158 ShouldGenerateTempSymbol =
true;
1160 if (!ShouldGenerateTempSymbol)
1161 return Error(FirstTokenLoc,
"invalid token in expression");
1170 EndLoc = FirstTokenLoc;
1175 std::pair<StringRef, StringRef>
Split;
1180 SMLoc AtLoc = getLexer().getLoc();
1182 if (parseIdentifier(VName))
1183 return Error(AtLoc,
"expected symbol variant after '@'");
1185 Split = std::make_pair(Identifier, VName);
1193 parseIdentifier(VName);
1196 Split = std::make_pair(Identifier, VName);
1204 return Error(getLexer().getLoc(),
"expected a symbol reference");
1208 if (!
Split.second.empty()) {
1210 if (MaybeSpecifier) {
1212 Spec = *MaybeSpecifier;
1215 "invalid variant '" +
Split.second +
"'");
1230 DoInline = TV->inlineAssignedExpr();
1233 return Error(EndLoc,
"unexpected modifier on variable reference");
1244 return TokError(
"literal value out of range for directive");
1246 SMLoc Loc = getTok().getLoc();
1247 int64_t
IntVal = getTok().getIntVal();
1253 StringRef IDVal = getTok().getString();
1255 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1257 if (
Split.first.size() != IDVal.
size()) {
1260 return TokError(
"invalid variant '" +
Split.second +
"'");
1261 IDVal =
Split.first;
1264 if (IDVal ==
"f" || IDVal ==
"b") {
1269 return Error(Loc,
"directional label undefined");
1270 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1278 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1279 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
1287 return TokError(
"cannot use . as current PC");
1300 return parseParenExpr(Res, EndLoc);
1302 if (!PlatformParser->HasBracketExpressions())
1303 return TokError(
"brackets expression not supported on this target");
1305 return parseBracketExpr(Res, EndLoc);
1308 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1314 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1320 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1327bool AsmParser::parseExpression(
const MCExpr *&Res) {
1329 return parseExpression(Res, EndLoc);
1339 switch (E->getKind()) {
1350 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1351 "' (already modified)");
1402 "Argument to the function cannot be a NULL value");
1404 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1405 (*CharPtr !=
'\0')) {
1406 if (*CharPtr ==
'!')
1410 if (*CharPtr ==
'>') {
1420 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1421 if (AltMacroStr[Pos] ==
'!')
1423 Res += AltMacroStr[Pos];
1431 return TokError(
"expected specifier following '@'");
1433 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1435 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1455bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1458 auto &TS = getTargetParser();
1459 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1467 return TokError(
"unexpected symbol modifier following '@'");
1471 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1473 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1475 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1476 "' (no symbols present)");
1486 if (Res->evaluateAsAbsolute(
Value))
1492bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1494 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1497bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1500 SMLoc StartLoc = Lexer.
getLoc();
1501 if (parseExpression(Expr))
1504 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1505 return Error(StartLoc,
"expected absolute expression");
1512 bool ShouldUseLogicalShr) {
1589 bool ShouldUseLogicalShr) {
1678bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1680 SMLoc StartLoc = Lexer.
getLoc();
1683 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1687 if (TokPrec < Precedence)
1694 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1700 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1701 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1713bool AsmParser::parseStatement(ParseStatementInfo &Info,
1714 MCAsmParserSemaCallback *SI) {
1715 assert(!hasPendingError() &&
"parseStatement started with pending error");
1721 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1722 getTok().getString().
front() ==
'\n')
1728 AsmToken
ID = getTok();
1729 SMLoc IDLoc =
ID.getLoc();
1731 int64_t LocalLabelVal = -1;
1732 StartTokLoc =
ID.getLoc();
1734 return parseCppHashLineFilenameComment(IDLoc,
1735 !isInsideMacroInstantiation());
1739 LocalLabelVal = getTok().getIntVal();
1740 if (LocalLabelVal < 0) {
1741 if (!TheCondState.
Ignore) {
1743 return Error(IDLoc,
"unexpected token at start of statement");
1747 IDVal = getTok().getString();
1750 if (!TheCondState.
Ignore) {
1752 return Error(IDLoc,
"unexpected token at start of statement");
1760 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1762 IDVal =
ID.getString();
1763 }
else if (parseIdentifier(IDVal)) {
1764 if (!TheCondState.
Ignore) {
1766 return Error(IDLoc,
"unexpected token at start of statement");
1775 DirectiveKindMap.find(IDVal.
lower());
1776 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1778 : DirKindIt->getValue();
1789 return parseDirectiveIf(IDLoc, DirKind);
1791 return parseDirectiveIfb(IDLoc,
true);
1793 return parseDirectiveIfb(IDLoc,
false);
1795 return parseDirectiveIfc(IDLoc,
true);
1797 return parseDirectiveIfeqs(IDLoc,
true);
1799 return parseDirectiveIfc(IDLoc,
false);
1801 return parseDirectiveIfeqs(IDLoc,
false);
1803 return parseDirectiveIfdef(IDLoc,
true);
1806 return parseDirectiveIfdef(IDLoc,
false);
1808 return parseDirectiveElseIf(IDLoc);
1810 return parseDirectiveElse(IDLoc);
1812 return parseDirectiveEndIf(IDLoc);
1817 if (TheCondState.
Ignore) {
1818 eatToEndOfStatement();
1828 if (checkForValidSection())
1835 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1843 if (LocalLabelVal == -1) {
1844 if (ParsingMSInlineAsm && SI) {
1845 StringRef RewrittenLabel =
1846 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1848 "We should have an internal name here.");
1851 IDVal = RewrittenLabel;
1861 StringRef CommentStr = parseStringToEndOfStatement();
1872 if (MAI.
isMachO() && CFIStartProcLoc) {
1873 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1874 if (SymM->isExternal() && !SymM->isAltEntry())
1875 return Error(StartTokLoc,
"non-private labels cannot appear between "
1876 ".cfi_startproc / .cfi_endproc pairs") &&
1877 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1880 if (discardLTOSymbol(IDVal))
1883 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1886 if (!getTargetParser().isParsingMSInlineAsm())
1891 if (enabledGenDwarfForAssembly())
1895 getTargetParser().onLabelParsed(Sym);
1904 return parseAssignment(IDVal, AssignmentKind::Equal);
1908 if (areMacrosEnabled())
1909 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1910 return handleMacroEntry(M, IDLoc);
1927 getTargetParser().flushPendingInstructions(getStreamer());
1929 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
1931 "Should only return Failure iff there was an error");
1939 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1940 ExtensionDirectiveMap.
lookup(IDVal);
1942 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1951 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1953 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1954 case DK_LTO_SET_CONDITIONAL:
1955 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1957 return parseDirectiveAscii(IDVal,
false);
1960 return parseDirectiveAscii(IDVal,
true);
1962 return parseDirectiveBase64();
1965 return parseDirectiveValue(IDVal, 1);
1971 return parseDirectiveValue(IDVal, 2);
1976 return parseDirectiveValue(IDVal, 4);
1979 return parseDirectiveValue(IDVal, 8);
1981 return parseDirectiveValue(
1982 IDVal,
getContext().getAsmInfo()->getCodePointerSize());
1984 return parseDirectiveOctaValue(IDVal);
1988 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1991 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1993 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1994 return parseDirectiveAlign(IsPow2, 1);
1997 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1998 return parseDirectiveAlign(IsPow2, 4);
2001 return parseDirectiveAlign(
false, 1);
2003 return parseDirectiveAlign(
false, 2);
2005 return parseDirectiveAlign(
false, 4);
2007 return parseDirectiveAlign(
true, 1);
2009 return parseDirectiveAlign(
true, 2);
2011 return parseDirectiveAlign(
true, 4);
2013 return parseDirectivePrefAlign();
2015 return parseDirectiveOrg();
2017 return parseDirectiveFill();
2019 return parseDirectiveZero();
2021 eatToEndOfStatement();
2025 return parseDirectiveSymbolAttribute(
MCSA_Global);
2026 case DK_LAZY_REFERENCE:
2028 case DK_NO_DEAD_STRIP:
2030 case DK_SYMBOL_RESOLVER:
2032 case DK_PRIVATE_EXTERN:
2036 case DK_WEAK_DEFINITION:
2038 case DK_WEAK_REFERENCE:
2040 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2043 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2046 return parseDirectiveComm(
false);
2048 return parseDirectiveComm(
true);
2050 return parseDirectiveAbort(IDLoc);
2052 return parseDirectiveInclude();
2054 return parseDirectiveIncbin();
2057 return TokError(Twine(IDVal) +
2058 " not currently supported for this target");
2060 return parseDirectiveRept(IDLoc, IDVal);
2062 return parseDirectiveIrp(IDLoc);
2064 return parseDirectiveIrpc(IDLoc);
2066 return parseDirectiveEndr(IDLoc);
2068 return parseDirectiveLEB128(
true);
2070 return parseDirectiveLEB128(
false);
2073 return parseDirectiveSpace(IDVal);
2075 return parseDirectiveFile(IDLoc);
2077 return parseDirectiveLine();
2079 return parseDirectiveLoc();
2081 return parseDirectiveLocLabel(IDLoc);
2083 return parseDirectiveStabs();
2085 return parseDirectiveCVFile();
2087 return parseDirectiveCVFuncId();
2088 case DK_CV_INLINE_SITE_ID:
2089 return parseDirectiveCVInlineSiteId();
2091 return parseDirectiveCVLoc();
2092 case DK_CV_LINETABLE:
2093 return parseDirectiveCVLinetable();
2094 case DK_CV_INLINE_LINETABLE:
2095 return parseDirectiveCVInlineLinetable();
2096 case DK_CV_DEF_RANGE:
2097 return parseDirectiveCVDefRange();
2099 return parseDirectiveCVString();
2100 case DK_CV_STRINGTABLE:
2101 return parseDirectiveCVStringTable();
2102 case DK_CV_FILECHECKSUMS:
2103 return parseDirectiveCVFileChecksums();
2104 case DK_CV_FILECHECKSUM_OFFSET:
2105 return parseDirectiveCVFileChecksumOffset();
2106 case DK_CV_FPO_DATA:
2107 return parseDirectiveCVFPOData();
2108 case DK_CFI_SECTIONS:
2109 return parseDirectiveCFISections();
2110 case DK_CFI_STARTPROC:
2111 return parseDirectiveCFIStartProc();
2112 case DK_CFI_ENDPROC:
2113 return parseDirectiveCFIEndProc();
2114 case DK_CFI_DEF_CFA:
2115 return parseDirectiveCFIDefCfa(IDLoc);
2116 case DK_CFI_DEF_CFA_OFFSET:
2117 return parseDirectiveCFIDefCfaOffset(IDLoc);
2118 case DK_CFI_ADJUST_CFA_OFFSET:
2119 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2120 case DK_CFI_DEF_CFA_REGISTER:
2121 return parseDirectiveCFIDefCfaRegister(IDLoc);
2122 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2123 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2125 return parseDirectiveCFIOffset(IDLoc);
2126 case DK_CFI_REL_OFFSET:
2127 return parseDirectiveCFIRelOffset(IDLoc);
2128 case DK_CFI_PERSONALITY:
2129 return parseDirectiveCFIPersonalityOrLsda(
true);
2131 return parseDirectiveCFIPersonalityOrLsda(
false);
2132 case DK_CFI_REMEMBER_STATE:
2133 return parseDirectiveCFIRememberState(IDLoc);
2134 case DK_CFI_RESTORE_STATE:
2135 return parseDirectiveCFIRestoreState(IDLoc);
2136 case DK_CFI_SAME_VALUE:
2137 return parseDirectiveCFISameValue(IDLoc);
2138 case DK_CFI_RESTORE:
2139 return parseDirectiveCFIRestore(IDLoc);
2141 return parseDirectiveCFIEscape(IDLoc);
2142 case DK_CFI_RETURN_COLUMN:
2143 return parseDirectiveCFIReturnColumn(IDLoc);
2144 case DK_CFI_SIGNAL_FRAME:
2145 return parseDirectiveCFISignalFrame(IDLoc);
2146 case DK_CFI_UNDEFINED:
2147 return parseDirectiveCFIUndefined(IDLoc);
2148 case DK_CFI_REGISTER:
2149 return parseDirectiveCFIRegister(IDLoc);
2150 case DK_CFI_WINDOW_SAVE:
2151 return parseDirectiveCFIWindowSave(IDLoc);
2153 return parseDirectiveCFILabel(IDLoc);
2154 case DK_CFI_VAL_OFFSET:
2155 return parseDirectiveCFIValOffset(IDLoc);
2158 return parseDirectiveMacrosOnOff(IDVal);
2160 return parseDirectiveMacro(IDLoc);
2163 return parseDirectiveAltmacro(IDVal);
2165 return parseDirectiveExitMacro(IDVal);
2168 return parseDirectiveEndMacro(IDVal);
2170 return parseDirectivePurgeMacro(IDLoc);
2172 return parseDirectiveEnd(IDLoc);
2174 return parseDirectiveError(IDLoc,
false);
2176 return parseDirectiveError(IDLoc,
true);
2178 return parseDirectiveWarning(IDLoc);
2180 return parseDirectiveReloc(IDLoc);
2183 return parseDirectiveDCB(IDVal, 2);
2185 return parseDirectiveDCB(IDVal, 1);
2187 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2189 return parseDirectiveDCB(IDVal, 4);
2191 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2194 return TokError(Twine(IDVal) +
2195 " not currently supported for this target");
2198 return parseDirectiveDS(IDVal, 2);
2200 return parseDirectiveDS(IDVal, 1);
2202 return parseDirectiveDS(IDVal, 8);
2205 return parseDirectiveDS(IDVal, 4);
2208 return parseDirectiveDS(IDVal, 12);
2210 return parseDirectivePrint(IDLoc);
2212 return parseDirectiveAddrsig();
2213 case DK_ADDRSIG_SYM:
2214 return parseDirectiveAddrsigSym();
2215 case DK_PSEUDO_PROBE:
2216 return parseDirectivePseudoProbe();
2217 case DK_LTO_DISCARD:
2218 return parseDirectiveLTODiscard();
2220 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2223 return Error(IDLoc,
"unknown directive");
2227 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2228 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2229 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2232 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2233 return parseDirectiveMSAlign(IDLoc, Info);
2235 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2237 if (checkForValidSection())
2240 return parseAndMatchAndEmitTargetInstruction(Info, IDVal,
ID, IDLoc);
2243bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2248 std::string OpcodeStr = IDVal.
lower();
2249 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2250 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr,
ID,
2251 Info.ParsedOperands);
2252 Info.ParseError = ParseHadError;
2255 if (getShowParsedOperands()) {
2256 SmallString<256> Str;
2257 raw_svector_ostream OS(Str);
2258 OS <<
"parsed instruction: [";
2259 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2262 Info.ParsedOperands[i]->print(OS, MAI);
2270 if (hasPendingError() || ParseHadError)
2275 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2277 getStreamer().getCurrentSectionOnly())) {
2279 if (ActiveMacros.empty())
2283 ActiveMacros.front()->ExitBuffer);
2288 if (!CppHashInfo.Filename.empty()) {
2289 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2290 0, StringRef(), CppHashInfo.Filename);
2291 getContext().setGenDwarfFileNumber(FileNumber);
2293 unsigned CppHashLocLineNo =
2295 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2298 getStreamer().emitDwarfLocDirective(
2299 getContext().getGenDwarfFileNumber(), Line, 0,
2305 if (!ParseHadError) {
2307 if (getTargetParser().matchAndEmitInstruction(
2308 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2309 getTargetParser().isParsingMSInlineAsm()))
2317AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2322 SMLoc StartLoc = Lexer.
getLoc();
2335bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2340 "Lexing Cpp line comment: Expected Integer");
2341 int64_t LineNumber = getTok().getIntVal();
2344 "Lexing Cpp line comment: Expected String");
2345 StringRef
Filename = getTok().getString();
2356 CppHashInfo.Loc =
L;
2358 CppHashInfo.LineNumber = LineNumber;
2359 CppHashInfo.Buf = CurBuffer;
2360 if (!HadCppHashFilename) {
2361 HadCppHashFilename =
true;
2371 std::nullopt, std::nullopt);
2379void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2380 auto *Parser =
static_cast<AsmParser *
>(
Context);
2381 raw_ostream &OS =
errs();
2384 SMLoc DiagLoc = Diag.
getLoc();
2386 unsigned CppHashBuf =
2387 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2392 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2401 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2402 if (Parser->SavedDiagHandler)
2403 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2405 Parser->getContext().diagnose(Diag);
2412 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2415 int CppHashLocLineNo =
2416 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2418 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2424 if (Parser->SavedDiagHandler)
2425 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2427 Parser->getContext().diagnose(NewDiag);
2435 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2439bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2442 bool EnableAtPseudoVariable) {
2444 auto expandArg = [&](
unsigned Index) {
2445 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2446 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2447 for (
const AsmToken &Token :
A[Index])
2455 if (AltMacroMode && Token.getString().front() ==
'%' &&
2458 OS << Token.getIntVal();
2461 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2468 OS << Token.getString();
2470 OS << Token.getStringContents();
2475 StringRef Body =
Macro.Body;
2476 size_t I = 0, End = Body.
size();
2478 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2480 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2481 OS << NumOfMacroInstantiations;
2485 if (Body[
I + 1] ==
'+') {
2490 if (Body[
I + 1] ==
'(' && Body[
I + 2] ==
')') {
2499 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2503 if (Parameters[Index].Name == Argument)
2505 if (Index == NParameters)
2514 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2516 switch (Body[
I + 1]) {
2532 unsigned Index = Body[
I + 1] -
'0';
2533 if (Index <
A.size())
2534 for (
const AsmToken &Token :
A[Index])
2535 OS << Token.getString();
2550 StringRef Token(Body.
data() + Start,
I - Start);
2554 if (Parameters[Index].Name == Token)
2556 if (Index != NParameters) {
2558 if (
I != End && Body[
I] ==
'&')
2602class AsmLexerSkipSpaceRAII {
2604 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2608 ~AsmLexerSkipSpaceRAII() {
2618bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2622 StringRef Str = parseStringToEndOfStatement();
2628 unsigned ParenLevel = 0;
2631 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2638 return TokError(
"unexpected token in macro instantiation");
2640 if (ParenLevel == 0) {
2653 MA.push_back(getTok());
2677 MA.push_back(getTok());
2681 if (ParenLevel != 0)
2682 return TokError(
"unbalanced parentheses in macro argument");
2687bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2688 MCAsmMacroArguments &
A) {
2689 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2690 bool NamedParametersFound =
false;
2691 SmallVector<SMLoc, 4> FALocs;
2693 A.resize(NParameters);
2694 FALocs.
resize(NParameters);
2699 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2700 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2702 SMLoc IDLoc = Lexer.
getLoc();
2703 MCAsmMacroParameter FA;
2706 if (parseIdentifier(FA.
Name))
2707 return Error(IDLoc,
"invalid argument identifier for formal argument");
2710 return TokError(
"expected '=' after formal parameter identifier");
2714 NamedParametersFound =
true;
2716 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2718 if (NamedParametersFound && FA.
Name.
empty())
2719 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2721 SMLoc StrLoc = Lexer.
getLoc();
2724 const MCExpr *AbsoluteExp;
2728 if (parseExpression(AbsoluteExp, EndLoc))
2730 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2731 getStreamer().getAssemblerPtr()))
2732 return Error(StrLoc,
"expected absolute expression");
2736 StringRef(StrChar, EndChar - StrChar),
Value);
2737 FA.
Value.push_back(newToken);
2742 jumpToLoc(EndLoc, CurBuffer);
2746 StringRef(StrChar, EndChar - StrChar));
2747 FA.
Value.push_back(newToken);
2748 }
else if(parseMacroArgument(FA.
Value, Vararg))
2754 for (FAI = 0; FAI < NParameters; ++FAI)
2755 if (
M->Parameters[FAI].Name == FA.
Name)
2758 if (FAI >= NParameters) {
2759 assert(M &&
"expected macro to be defined");
2760 return Error(IDLoc,
"parameter named '" + FA.
Name +
2761 "' does not exist for macro '" +
M->Name +
"'");
2766 if (!FA.
Value.empty()) {
2771 if (FALocs.
size() <= PI)
2774 FALocs[PI] = Lexer.
getLoc();
2782 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2784 if (
M->Parameters[FAI].Required) {
2786 "missing value for required parameter "
2787 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2791 if (!
M->Parameters[FAI].Value.empty())
2792 A[FAI] =
M->Parameters[FAI].Value;
2801 return TokError(
"too many positional arguments");
2804bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2808 if (ActiveMacros.size() == MaxNestingDepth) {
2809 std::ostringstream MaxNestingDepthError;
2810 MaxNestingDepthError <<
"macros cannot be nested more than "
2811 << MaxNestingDepth <<
" levels deep."
2812 <<
" Use -asm-macro-max-nesting-depth to increase "
2814 return TokError(MaxNestingDepthError.str());
2817 MCAsmMacroArguments
A;
2818 if (parseMacroArguments(M,
A))
2823 SmallString<256> Buf;
2824 raw_svector_ostream OS(Buf);
2826 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2827 return Error(getTok().getLoc(),
"Wrong number of arguments");
2828 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2833 OS <<
".endmacro\n";
2835 std::unique_ptr<MemoryBuffer> Instantiation =
2840 MacroInstantiation *
MI =
new MacroInstantiation{
2841 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2842 ActiveMacros.push_back(
MI);
2844 ++NumOfMacroInstantiations;
2854void AsmParser::handleMacroExit() {
2856 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2864 delete ActiveMacros.back();
2865 ActiveMacros.pop_back();
2868bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2870 const MCExpr *
Value;
2871 SMLoc ExprLoc = getTok().getLoc();
2873 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2885 if (discardLTOSymbol(Name))
2890 case AssignmentKind::Equal:
2893 case AssignmentKind::Set:
2894 case AssignmentKind::Equiv:
2898 case AssignmentKind::LTOSetConditional:
2900 return Error(ExprLoc,
"expected identifier");
2912bool AsmParser::parseIdentifier(StringRef &Res) {
2919 SMLoc PrefixLoc = getLexer().getLoc();
2931 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2937 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2945 Res = getTok().getIdentifier();
2957bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2959 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2960 parseAssignment(Name, Kind))
2965bool AsmParser::parseEscapedString(std::string &
Data) {
2970 StringRef Str = getTok().getStringContents();
2971 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
2972 if (Str[i] !=
'\\') {
2973 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
2975 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
2979 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
2990 return TokError(
"unexpected backslash at end of string");
2993 if (Str[i] ==
'x' || Str[i] ==
'X') {
2994 size_t length = Str.size();
2995 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
2996 return TokError(
"invalid hexadecimal escape sequence");
3001 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3009 if ((
unsigned)(Str[i] -
'0') <= 7) {
3011 unsigned Value = Str[i] -
'0';
3013 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3017 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3024 return TokError(
"invalid octal escape sequence (out of range)");
3034 return TokError(
"invalid escape sequence (unrecognized character)");
3036 case 'b':
Data +=
'\b';
break;
3037 case 'f':
Data +=
'\f';
break;
3038 case 'n':
Data +=
'\n';
break;
3039 case 'r':
Data +=
'\r';
break;
3040 case 't':
Data +=
'\t';
break;
3041 case '"':
Data +=
'"';
break;
3042 case '\\':
Data +=
'\\';
break;
3050bool AsmParser::parseAngleBracketString(std::string &
Data) {
3051 SMLoc EndLoc, StartLoc = getTok().getLoc();
3053 const char *StartChar = StartLoc.
getPointer() + 1;
3054 const char *EndChar = EndLoc.
getPointer() - 1;
3055 jumpToLoc(EndLoc, CurBuffer);
3068bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3069 auto parseOp = [&]() ->
bool {
3071 if (checkForValidSection())
3076 if (parseEscapedString(
Data))
3078 getStreamer().emitBytes(
Data);
3081 getStreamer().emitBytes(StringRef(
"\0", 1));
3085 return parseMany(parseOp);
3090bool AsmParser::parseDirectiveBase64() {
3091 auto parseOp = [&]() ->
bool {
3092 if (checkForValidSection())
3099 std::vector<char> Decoded;
3100 std::string
const str = getTok().getStringContents().str();
3101 if (check(str.empty(),
"expected nonempty string")) {
3108 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3111 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3116 return check(parseMany(parseOp),
"expected string");
3121bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3123 const MCExpr *Expr =
nullptr;
3125 if (parseExpression(
Offset))
3137 SMLoc ExprLoc = Lexer.
getLoc();
3138 if (parseExpression(Expr))
3143 return Error(ExprLoc,
"expression must be relocatable");
3149 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3155bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3156 auto parseOp = [&]() ->
bool {
3157 const MCExpr *
Value;
3158 SMLoc ExprLoc = getLexer().getLoc();
3159 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3164 uint64_t IntValue = MCE->getValue();
3166 return Error(ExprLoc,
"out of range literal value");
3167 getStreamer().emitIntValue(IntValue,
Size);
3169 getStreamer().emitValue(
Value,
Size, ExprLoc);
3173 return parseMany(parseOp);
3179 return Asm.TokError(
"unknown token in expression");
3180 SMLoc ExprLoc = Asm.getTok().getLoc();
3181 APInt IntValue = Asm.getTok().getAPIntVal();
3183 if (!IntValue.
isIntN(128))
3184 return Asm.Error(ExprLoc,
"out of range literal value");
3185 if (!IntValue.
isIntN(64)) {
3198bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3199 auto parseOp = [&]() ->
bool {
3200 if (checkForValidSection())
3206 getStreamer().emitInt64(lo);
3207 getStreamer().emitInt64(hi);
3209 getStreamer().emitInt64(hi);
3210 getStreamer().emitInt64(lo);
3215 return parseMany(parseOp);
3218bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3229 return TokError(Lexer.
getErr());
3232 return TokError(
"unexpected token in directive");
3236 StringRef IDVal = getTok().getString();
3244 return TokError(
"invalid floating point literal");
3246 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3248 return TokError(
"invalid floating point literal");
3255 Res =
Value.bitcastToAPInt();
3262bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3263 const fltSemantics &Semantics) {
3264 auto parseOp = [&]() ->
bool {
3266 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3273 return parseMany(parseOp);
3278bool AsmParser::parseDirectiveZero() {
3279 SMLoc NumBytesLoc = Lexer.
getLoc();
3280 const MCExpr *NumBytes;
3281 if (checkForValidSection() || parseExpression(NumBytes))
3287 if (parseAbsoluteExpression(Val))
3293 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3300bool AsmParser::parseDirectiveFill() {
3301 SMLoc NumValuesLoc = Lexer.
getLoc();
3302 const MCExpr *NumValues;
3303 if (checkForValidSection() || parseExpression(NumValues))
3306 int64_t FillSize = 1;
3307 int64_t FillExpr = 0;
3309 SMLoc SizeLoc, ExprLoc;
3312 SizeLoc = getTok().getLoc();
3313 if (parseAbsoluteExpression(FillSize))
3316 ExprLoc = getTok().getLoc();
3317 if (parseAbsoluteExpression(FillExpr))
3325 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3329 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3334 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3336 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3343bool AsmParser::parseDirectiveOrg() {
3345 SMLoc OffsetLoc = Lexer.
getLoc();
3346 if (checkForValidSection() || parseExpression(
Offset))
3350 int64_t FillExpr = 0;
3352 if (parseAbsoluteExpression(FillExpr))
3357 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3363bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3364 SMLoc AlignmentLoc = getLexer().getLoc();
3367 bool HasFillExpr =
false;
3368 int64_t FillExpr = 0;
3369 int64_t MaxBytesToFill = 0;
3372 auto parseAlign = [&]() ->
bool {
3373 if (parseAbsoluteExpression(Alignment))
3381 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3385 if (parseTokenLoc(MaxBytesLoc) ||
3386 parseAbsoluteExpression(MaxBytesToFill))
3392 if (checkForValidSection())
3396 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3403 bool ReturnVal =
false;
3408 if (Alignment >= 32) {
3409 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3413 Alignment = 1ULL << Alignment;
3421 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3425 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3426 Alignment = 1u << 31;
3432 if (MaxBytesToFill < 1) {
3433 ReturnVal |=
Error(MaxBytesLoc,
3434 "alignment directive can never be satisfied in this "
3435 "many bytes, ignoring maximum bytes expression");
3439 if (MaxBytesToFill >= Alignment) {
3440 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3446 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3447 assert(Section &&
"must have section to emit alignment");
3449 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3451 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3459 getStreamer().emitCodeAlignment(
3460 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3463 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3470bool AsmParser::parseDirectivePrefAlign() {
3471 SMLoc AlignmentLoc = getLexer().getLoc();
3473 if (checkForValidSection() || parseAbsoluteExpression(Alignment))
3479 return Error(AlignmentLoc,
"alignment must be a power of 2");
3480 getStreamer().emitPrefAlign(
Align(Alignment));
3488bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3490 int64_t FileNumber = -1;
3492 FileNumber = getTok().getIntVal();
3496 return TokError(
"negative file number");
3503 if (parseEscapedString(Path))
3506 StringRef Directory;
3508 std::string FilenameData;
3510 if (check(FileNumber == -1,
3511 "explicit path specified, but no file number") ||
3512 parseEscapedString(FilenameData))
3520 uint64_t MD5Hi, MD5Lo;
3521 bool HasMD5 =
false;
3523 std::optional<StringRef>
Source;
3524 bool HasSource =
false;
3525 std::string SourceString;
3530 "unexpected token in '.file' directive") ||
3531 parseIdentifier(Keyword))
3533 if (Keyword ==
"md5") {
3535 if (check(FileNumber == -1,
3536 "MD5 checksum specified, but no file number") ||
3539 }
else if (Keyword ==
"source") {
3541 if (check(FileNumber == -1,
3542 "source specified, but no file number") ||
3544 "unexpected token in '.file' directive") ||
3545 parseEscapedString(SourceString))
3548 return TokError(
"unexpected token in '.file' directive");
3552 if (FileNumber == -1) {
3556 if (
getContext().getAsmInfo()->hasSingleParameterDotFile())
3557 getStreamer().emitFileDirective(
Filename);
3567 std::optional<MD5::MD5Result> CKMem;
3570 for (
unsigned i = 0; i != 8; ++i) {
3571 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3572 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3577 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3578 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3579 Source = StringRef(SourceBuf, SourceString.size());
3581 if (FileNumber == 0) {
3585 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3587 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3588 FileNumber, Directory,
Filename, CKMem, Source);
3595 ReportedInconsistentMD5 =
true;
3596 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3605bool AsmParser::parseDirectiveLine() {
3617bool AsmParser::parseDirectiveLoc() {
3618 int64_t FileNumber = 0, LineNumber = 0;
3619 SMLoc Loc = getTok().getLoc();
3620 if (parseIntToken(FileNumber) ||
3622 "file number less than one in '.loc' directive") ||
3623 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3624 "unassigned file number in '.loc' directive"))
3629 LineNumber = getTok().getIntVal();
3631 return TokError(
"line number less than zero in '.loc' directive");
3635 int64_t ColumnPos = 0;
3637 ColumnPos = getTok().getIntVal();
3639 return TokError(
"column position less than zero in '.loc' directive");
3643 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3648 auto parseLocOp = [&]() ->
bool {
3650 SMLoc Loc = getTok().getLoc();
3651 if (parseIdentifier(Name))
3652 return TokError(
"unexpected token in '.loc' directive");
3654 if (Name ==
"basic_block")
3656 else if (Name ==
"prologue_end")
3658 else if (Name ==
"epilogue_begin")
3660 else if (Name ==
"is_stmt") {
3661 Loc = getTok().getLoc();
3662 const MCExpr *
Value;
3663 if (parseExpression(
Value))
3667 int Value = MCE->getValue();
3669 Flags &= ~DWARF2_FLAG_IS_STMT;
3670 else if (
Value == 1)
3673 return Error(Loc,
"is_stmt value not 0 or 1");
3675 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3677 }
else if (Name ==
"isa") {
3678 Loc = getTok().getLoc();
3679 const MCExpr *
Value;
3680 if (parseExpression(
Value))
3684 int Value = MCE->getValue();
3686 return Error(Loc,
"isa number less than zero");
3689 return Error(Loc,
"isa number not a constant value");
3691 }
else if (Name ==
"discriminator") {
3692 if (parseAbsoluteExpression(Discriminator))
3695 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3700 if (parseMany(parseLocOp,
false ))
3703 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3704 Isa, Discriminator, StringRef());
3711bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3713 DirectiveLoc = Lexer.
getLoc();
3714 if (parseIdentifier(Name))
3715 return TokError(
"expected identifier");
3718 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3724bool AsmParser::parseDirectiveStabs() {
3725 return TokError(
"unsupported directive '.stabs'");
3730bool AsmParser::parseDirectiveCVFile() {
3731 SMLoc FileNumberLoc = getTok().getLoc();
3734 std::string Checksum;
3737 if (parseIntToken(FileNumber,
"expected file number") ||
3738 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3740 "unexpected token in '.cv_file' directive") ||
3745 "unexpected token in '.cv_file' directive") ||
3746 parseEscapedString(Checksum) ||
3747 parseIntToken(ChecksumKind,
3748 "expected checksum kind in '.cv_file' directive") ||
3754 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3755 memcpy(CKMem, Checksum.data(), Checksum.size());
3756 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3759 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3760 static_cast<uint8_t
>(ChecksumKind)))
3761 return Error(FileNumberLoc,
"file number already allocated");
3766bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3767 StringRef DirectiveName) {
3769 return parseTokenLoc(Loc) ||
3770 parseIntToken(FunctionId,
"expected function id") ||
3771 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3772 "expected function id within range [0, UINT_MAX)");
3775bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3777 return parseTokenLoc(Loc) ||
3778 parseIntToken(FileNumber,
"expected file number") ||
3779 check(FileNumber < 1, Loc,
3780 "file number less than one in '" + DirectiveName +
3782 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3783 "unassigned file number in '" + DirectiveName +
"' directive");
3790bool AsmParser::parseDirectiveCVFuncId() {
3791 SMLoc FunctionIdLoc = getTok().getLoc();
3794 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3797 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3798 return Error(FunctionIdLoc,
"function id already allocated");
3811bool AsmParser::parseDirectiveCVInlineSiteId() {
3812 SMLoc FunctionIdLoc = getTok().getLoc();
3820 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3825 getTok().getIdentifier() !=
"within"),
3826 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3831 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3836 getTok().getIdentifier() !=
"inlined_at"),
3837 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3843 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3844 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3849 IACol = getTok().getIntVal();
3856 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3857 IALine, IACol, FunctionIdLoc))
3858 return Error(FunctionIdLoc,
"function id already allocated");
3870bool AsmParser::parseDirectiveCVLoc() {
3871 SMLoc DirectiveLoc = getTok().getLoc();
3872 int64_t FunctionId, FileNumber;
3873 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3874 parseCVFileId(FileNumber,
".cv_loc"))
3877 int64_t LineNumber = 0;
3879 LineNumber = getTok().getIntVal();
3881 return TokError(
"line number less than zero in '.cv_loc' directive");
3885 int64_t ColumnPos = 0;
3887 ColumnPos = getTok().getIntVal();
3889 return TokError(
"column position less than zero in '.cv_loc' directive");
3893 bool PrologueEnd =
false;
3894 uint64_t IsStmt = 0;
3896 auto parseOp = [&]() ->
bool {
3898 SMLoc Loc = getTok().getLoc();
3899 if (parseIdentifier(Name))
3900 return TokError(
"unexpected token in '.cv_loc' directive");
3901 if (Name ==
"prologue_end")
3903 else if (Name ==
"is_stmt") {
3904 Loc = getTok().getLoc();
3905 const MCExpr *
Value;
3906 if (parseExpression(
Value))
3911 IsStmt = MCE->getValue();
3914 return Error(Loc,
"is_stmt value not 0 or 1");
3916 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3921 if (parseMany(parseOp,
false ))
3924 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3925 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3932bool AsmParser::parseDirectiveCVLinetable() {
3935 SMLoc Loc = getTok().getLoc();
3936 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3937 parseTokenLoc(Loc) ||
3938 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
3939 parseComma() || parseTokenLoc(Loc) ||
3940 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
3943 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3949bool AsmParser::parseDirectiveCVInlineLinetable() {
3950 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3952 SMLoc Loc = getTok().getLoc();
3953 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3954 parseTokenLoc(Loc) ||
3955 parseIntToken(SourceFileId,
"expected SourceField") ||
3956 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
3957 parseTokenLoc(Loc) ||
3958 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
3959 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
3960 parseTokenLoc(Loc) ||
3961 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
3962 parseTokenLoc(Loc) ||
3963 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
3969 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3970 SourceLineNum, FnStartSym,
3975void AsmParser::initializeCVDefRangeTypeMap() {
3976 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
3977 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
3978 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
3979 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
3984bool AsmParser::parseDirectiveCVDefRange() {
3986 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
3988 Loc = getLexer().getLoc();
3991 return Error(Loc,
"expected identifier in directive");
3993 Loc = getLexer().getLoc();
3996 return Error(Loc,
"expected identifier in directive");
3998 Ranges.push_back({GapStartSym, GapEndSym});
4001 StringRef CVDefRangeTypeStr;
4004 "expected comma before def_range type in .cv_def_range directive") ||
4005 parseIdentifier(CVDefRangeTypeStr))
4006 return Error(Loc,
"expected def_range type in directive");
4009 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4010 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4012 : CVTypeIt->getValue();
4014 case CVDR_DEFRANGE_REGISTER: {
4016 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4017 ".cv_def_range directive") ||
4018 parseAbsoluteExpression(DRRegister))
4019 return Error(Loc,
"expected register number");
4021 codeview::DefRangeRegisterHeader DRHdr;
4024 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4027 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4030 "expected comma before offset in .cv_def_range directive") ||
4031 parseAbsoluteExpression(DROffset))
4032 return Error(Loc,
"expected offset value");
4034 codeview::DefRangeFramePointerRelHeader DRHdr;
4036 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4039 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4041 int64_t DROffsetInParent;
4042 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4043 ".cv_def_range directive") ||
4044 parseAbsoluteExpression(DRRegister))
4045 return Error(Loc,
"expected register number");
4047 "expected comma before offset in .cv_def_range directive") ||
4048 parseAbsoluteExpression(DROffsetInParent))
4049 return Error(Loc,
"expected offset value");
4051 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4055 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4058 case CVDR_DEFRANGE_REGISTER_REL: {
4061 int64_t DRBasePointerOffset;
4062 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4063 ".cv_def_range directive") ||
4064 parseAbsoluteExpression(DRRegister))
4065 return Error(Loc,
"expected register value");
4068 "expected comma before flag value in .cv_def_range directive") ||
4069 parseAbsoluteExpression(DRFlags))
4070 return Error(Loc,
"expected flag value");
4071 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4072 "in .cv_def_range directive") ||
4073 parseAbsoluteExpression(DRBasePointerOffset))
4074 return Error(Loc,
"expected base pointer offset value");
4076 codeview::DefRangeRegisterRelHeader DRHdr;
4078 DRHdr.
Flags = DRFlags;
4080 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4084 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4091bool AsmParser::parseDirectiveCVString() {
4093 if (checkForValidSection() || parseEscapedString(
Data))
4097 std::pair<StringRef, unsigned> Insertion =
4098 getCVContext().addToStringTable(
Data);
4099 getStreamer().emitInt32(Insertion.second);
4105bool AsmParser::parseDirectiveCVStringTable() {
4106 getStreamer().emitCVStringTableDirective();
4112bool AsmParser::parseDirectiveCVFileChecksums() {
4113 getStreamer().emitCVFileChecksumsDirective();
4119bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4121 if (parseIntToken(FileNo))
4125 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4131bool AsmParser::parseDirectiveCVFPOData() {
4132 SMLoc DirLoc = getLexer().getLoc();
4135 return TokError(
"expected symbol name");
4138 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4144bool AsmParser::parseDirectiveCFISections() {
4148 bool SFrame =
false;
4152 if (parseIdentifier(Name))
4153 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4154 if (Name ==
".eh_frame")
4156 else if (Name ==
".debug_frame")
4158 else if (Name ==
".sframe")
4166 getStreamer().emitCFISections(EH,
Debug, SFrame);
4172bool AsmParser::parseDirectiveCFIStartProc() {
4173 CFIStartProcLoc = StartTokLoc;
4177 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4178 "unexpected token") ||
4188 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4194bool AsmParser::parseDirectiveCFIEndProc() {
4195 CFIStartProcLoc = std::nullopt;
4200 getStreamer().emitCFIEndProc();
4205bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4206 SMLoc DirectiveLoc) {
4210 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4214 return parseAbsoluteExpression(
Register);
4221bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4223 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4224 parseAbsoluteExpression(
Offset) || parseEOL())
4233bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4235 if (parseAbsoluteExpression(
Offset) || parseEOL())
4238 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4244bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4245 int64_t Register1 = 0, Register2 = 0;
4246 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4247 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4250 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4256bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4259 getStreamer().emitCFIWindowSave(DirectiveLoc);
4265bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4266 int64_t Adjustment = 0;
4267 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4270 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4276bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4278 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4281 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4287bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4289 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4290 parseAbsoluteExpression(
Offset) || parseComma() ||
4301bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4305 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4306 parseAbsoluteExpression(
Offset) || parseEOL())
4315bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4318 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4319 parseAbsoluteExpression(
Offset) || parseEOL())
4327 if (Encoding & ~0xff)
4333 const unsigned Format = Encoding & 0xf;
4340 const unsigned Application = Encoding & 0x70;
4352bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4353 int64_t Encoding = 0;
4354 if (parseAbsoluteExpression(Encoding))
4362 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4366 getStreamer().emitCFIPersonality(Sym, Encoding);
4368 getStreamer().emitCFILsda(Sym, Encoding);
4374bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4377 getStreamer().emitCFIRememberState(DirectiveLoc);
4383bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4386 getStreamer().emitCFIRestoreState(DirectiveLoc);
4392bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4395 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4398 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4404bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4406 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4409 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4415bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4418 if (parseAbsoluteExpression(CurrValue))
4421 Values.push_back((uint8_t)CurrValue);
4426 if (parseAbsoluteExpression(CurrValue))
4429 Values.push_back((uint8_t)CurrValue);
4432 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4438bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4440 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4442 getStreamer().emitCFIReturnColumn(
Register);
4448bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4452 getStreamer().emitCFISignalFrame();
4458bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4461 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4464 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4470bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4473 if (parseIdentifier(Name))
4474 return TokError(
"expected identifier");
4477 getStreamer().emitCFILabelDirective(Loc, Name);
4483bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4487 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4488 parseAbsoluteExpression(
Offset) || parseEOL())
4498bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4501 AltMacroMode = (Directive ==
".altmacro");
4508bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4511 setMacrosEnabled(Directive ==
".macros_on");
4517bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4519 if (parseIdentifier(Name))
4520 return TokError(
"expected identifier in '.macro' directive");
4529 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4531 "' should be the last parameter");
4535 return TokError(
"expected identifier in '.macro' directive");
4538 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4540 return TokError(
"macro '" + Name +
"' has multiple parameters"
4549 QualLoc = Lexer.
getLoc();
4550 if (parseIdentifier(Qualifier))
4551 return Error(QualLoc,
"missing parameter qualifier for "
4552 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4554 if (Qualifier ==
"req")
4556 else if (Qualifier ==
"vararg")
4559 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4560 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4568 ParamLoc = Lexer.
getLoc();
4569 if (parseMacroArgument(
Parameter.Value,
false ))
4573 Warning(ParamLoc,
"pointless default value for required parameter "
4574 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4587 AsmToken EndToken, StartToken = getTok();
4588 unsigned MacroDepth = 0;
4598 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4603 if (getTok().getIdentifier() ==
".endm" ||
4604 getTok().getIdentifier() ==
".endmacro") {
4605 if (MacroDepth == 0) {
4606 EndToken = getTok();
4609 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4616 }
else if (getTok().getIdentifier() ==
".macro") {
4622 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4626 eatToEndOfStatement();
4630 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4635 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4636 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4637 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4658void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4664 if (NParameters == 0)
4667 bool NamedParametersFound =
false;
4668 bool PositionalParametersFound =
false;
4673 while (!Body.
empty()) {
4675 std::size_t End = Body.
size(), Pos = 0;
4676 for (; Pos != End; ++Pos) {
4679 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4683 if (Body[Pos] !=
'$' || Pos + 1 == End)
4685 char Next = Body[Pos + 1];
4687 isdigit(
static_cast<unsigned char>(
Next)))
4695 if (Body[Pos] ==
'$') {
4696 switch (Body[Pos + 1]) {
4703 PositionalParametersFound =
true;
4708 PositionalParametersFound =
true;
4714 unsigned I = Pos + 1;
4718 const char *Begin = Body.
data() + Pos + 1;
4719 StringRef
Argument(Begin,
I - (Pos + 1));
4722 if (Parameters[Index].Name == Argument)
4725 if (Index == NParameters) {
4726 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4732 NamedParametersFound =
true;
4740 if (!NamedParametersFound && PositionalParametersFound)
4741 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4742 "used in macro body, possible positional parameter "
4743 "found in body which will have no effect");
4748bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4752 if (!isInsideMacroInstantiation())
4753 return TokError(
"unexpected '" + Directive +
"' in file, "
4754 "no current macro definition");
4757 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4758 TheCondState = TheCondStack.back();
4759 TheCondStack.pop_back();
4769bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4771 return TokError(
"unexpected token in '" + Directive +
"' directive");
4775 if (isInsideMacroInstantiation()) {
4782 return TokError(
"unexpected '" + Directive +
"' in file, "
4783 "no current macro definition");
4788bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4791 if (parseTokenLoc(Loc) ||
4792 check(parseIdentifier(Name), Loc,
4793 "expected identifier in '.purgem' directive") ||
4798 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4802 <<
"Un-defining macro: " << Name <<
"\n");
4808bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4809 SMLoc NumBytesLoc = Lexer.
getLoc();
4810 const MCExpr *NumBytes;
4811 if (checkForValidSection() || parseExpression(NumBytes))
4814 int64_t FillExpr = 0;
4816 if (parseAbsoluteExpression(FillExpr))
4822 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4829bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
4830 SMLoc NumValuesLoc = Lexer.
getLoc();
4832 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4835 if (NumValues < 0) {
4836 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4843 const MCExpr *
Value;
4844 SMLoc ExprLoc = getLexer().getLoc();
4845 if (parseExpression(
Value))
4851 uint64_t IntValue = MCE->getValue();
4853 return Error(ExprLoc,
"literal value out of range for directive");
4854 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4855 getStreamer().emitIntValue(IntValue,
Size);
4857 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4858 getStreamer().emitValue(
Value,
Size, ExprLoc);
4866bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
4867 SMLoc NumValuesLoc = Lexer.
getLoc();
4869 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4872 if (NumValues < 0) {
4873 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4881 if (parseRealValue(Semantics, AsInt) || parseEOL())
4884 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4893bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
4894 SMLoc NumValuesLoc = Lexer.
getLoc();
4896 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4900 if (NumValues < 0) {
4901 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4905 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4906 getStreamer().emitFill(
Size, 0);
4913bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4914 if (checkForValidSection())
4917 auto parseOp = [&]() ->
bool {
4918 const MCExpr *
Value;
4919 if (parseExpression(
Value))
4922 getStreamer().emitSLEB128Value(
Value);
4924 getStreamer().emitULEB128Value(
Value);
4928 return parseMany(parseOp);
4933bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4934 auto parseOp = [&]() ->
bool {
4936 SMLoc Loc = getTok().getLoc();
4937 if (parseIdentifier(Name))
4938 return Error(Loc,
"expected identifier");
4940 if (discardLTOSymbol(Name))
4948 return Error(Loc,
"non-local symbol required");
4950 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
4951 return Error(Loc,
"unable to emit symbol attribute");
4955 return parseMany(parseOp);
4960bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4961 if (checkForValidSection())
4964 SMLoc IDLoc = getLexer().getLoc();
4967 return TokError(
"expected identifier in directive");
4973 SMLoc SizeLoc = getLexer().getLoc();
4974 if (parseAbsoluteExpression(
Size))
4977 int64_t Pow2Alignment = 0;
4978 SMLoc Pow2AlignmentLoc;
4981 Pow2AlignmentLoc = getLexer().getLoc();
4982 if (parseAbsoluteExpression(Pow2Alignment))
4987 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4993 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4994 Pow2Alignment =
Log2_64(Pow2Alignment);
5004 return Error(SizeLoc,
"size must be non-negative");
5008 return Error(IDLoc,
"invalid symbol redefinition");
5012 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5013 Align(1ULL << Pow2Alignment));
5017 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
5023bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5024 StringRef Str = parseStringToEndOfStatement();
5029 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5032 return Error(DirectiveLoc,
5033 ".abort '" + Str +
"' detected. Assembly stopping");
5038bool AsmParser::parseDirectiveInclude() {
5041 SMLoc IncludeLoc = getTok().getLoc();
5044 "expected string in '.include' directive") ||
5047 "unexpected token in '.include' directive") ||
5050 check(enterIncludeFile(
Filename), IncludeLoc,
5051 "Could not find include file '" +
Filename +
"'"))
5059bool AsmParser::parseDirectiveIncbin() {
5062 SMLoc IncbinLoc = getTok().getLoc();
5064 "expected string in '.incbin' directive") ||
5069 const MCExpr *
Count =
nullptr;
5070 SMLoc SkipLoc, CountLoc;
5075 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5079 CountLoc = getTok().getLoc();
5080 if (parseExpression(
Count))
5088 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5093 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5099bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5100 TheCondStack.push_back(TheCondState);
5102 if (TheCondState.
Ignore) {
5103 eatToEndOfStatement();
5106 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5116 ExprValue = ExprValue == 0;
5119 ExprValue = ExprValue >= 0;
5122 ExprValue = ExprValue > 0;
5125 ExprValue = ExprValue <= 0;
5128 ExprValue = ExprValue < 0;
5132 TheCondState.
CondMet = ExprValue;
5141bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5142 TheCondStack.push_back(TheCondState);
5145 if (TheCondState.
Ignore) {
5146 eatToEndOfStatement();
5148 StringRef Str = parseStringToEndOfStatement();
5153 TheCondState.
CondMet = ExpectBlank == Str.empty();
5163bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5164 TheCondStack.push_back(TheCondState);
5167 if (TheCondState.
Ignore) {
5168 eatToEndOfStatement();
5170 StringRef Str1 = parseStringToComma();
5175 StringRef Str2 = parseStringToEndOfStatement();
5189bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5190 TheCondStack.push_back(TheCondState);
5193 if (TheCondState.
Ignore) {
5194 eatToEndOfStatement();
5198 return TokError(
"expected string parameter for '.ifeqs' directive");
5199 return TokError(
"expected string parameter for '.ifnes' directive");
5202 StringRef String1 = getTok().getStringContents();
5208 "expected comma after first string for '.ifeqs' directive");
5210 "expected comma after first string for '.ifnes' directive");
5217 return TokError(
"expected string parameter for '.ifeqs' directive");
5218 return TokError(
"expected string parameter for '.ifnes' directive");
5221 StringRef String2 = getTok().getStringContents();
5224 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5233bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5235 TheCondStack.push_back(TheCondState);
5238 if (TheCondState.
Ignore) {
5239 eatToEndOfStatement();
5241 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5259bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5262 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5263 " .if or an .elseif");
5266 bool LastIgnoreState =
false;
5267 if (!TheCondStack.empty())
5268 LastIgnoreState = TheCondStack.back().Ignore;
5269 if (LastIgnoreState || TheCondState.
CondMet) {
5270 TheCondState.
Ignore =
true;
5271 eatToEndOfStatement();
5274 if (parseAbsoluteExpression(ExprValue))
5280 TheCondState.
CondMet = ExprValue;
5289bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5295 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5296 " an .if or an .elseif");
5298 bool LastIgnoreState =
false;
5299 if (!TheCondStack.empty())
5300 LastIgnoreState = TheCondStack.back().Ignore;
5301 if (LastIgnoreState || TheCondState.
CondMet)
5302 TheCondState.
Ignore =
true;
5304 TheCondState.
Ignore =
false;
5311bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5324bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5325 if (!TheCondStack.empty()) {
5326 if (TheCondStack.back().Ignore) {
5327 eatToEndOfStatement();
5333 return Error(L,
".err encountered");
5335 StringRef Message =
".error directive invoked in source file";
5338 return TokError(
".error argument must be a string");
5340 Message = getTok().getStringContents();
5344 return Error(L, Message);
5349bool AsmParser::parseDirectiveWarning(SMLoc L) {
5350 if (!TheCondStack.empty()) {
5351 if (TheCondStack.back().Ignore) {
5352 eatToEndOfStatement();
5357 StringRef Message =
".warning directive invoked in source file";
5361 return TokError(
".warning argument must be a string");
5363 Message = getTok().getStringContents();
5374bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5379 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5381 if (!TheCondStack.empty()) {
5382 TheCondState = TheCondStack.back();
5383 TheCondStack.pop_back();
5389void AsmParser::initializeDirectiveKindMap() {
5396 DirectiveKindMap[
".set"] = DK_SET;
5397 DirectiveKindMap[
".equ"] = DK_EQU;
5398 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5399 DirectiveKindMap[
".ascii"] = DK_ASCII;
5400 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5401 DirectiveKindMap[
".string"] = DK_STRING;
5402 DirectiveKindMap[
".byte"] = DK_BYTE;
5403 DirectiveKindMap[
".base64"] = DK_BASE64;
5404 DirectiveKindMap[
".short"] = DK_SHORT;
5405 DirectiveKindMap[
".value"] = DK_VALUE;
5406 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5407 DirectiveKindMap[
".long"] = DK_LONG;
5408 DirectiveKindMap[
".int"] = DK_INT;
5409 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5410 DirectiveKindMap[
".quad"] = DK_QUAD;
5411 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5412 DirectiveKindMap[
".octa"] = DK_OCTA;
5413 DirectiveKindMap[
".single"] = DK_SINGLE;
5414 DirectiveKindMap[
".float"] = DK_FLOAT;
5415 DirectiveKindMap[
".double"] = DK_DOUBLE;
5416 DirectiveKindMap[
".align"] = DK_ALIGN;
5417 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5418 DirectiveKindMap[
".balign"] = DK_BALIGN;
5419 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5420 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5421 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5422 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5423 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5424 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5425 DirectiveKindMap[
".org"] = DK_ORG;
5426 DirectiveKindMap[
".fill"] = DK_FILL;
5427 DirectiveKindMap[
".zero"] = DK_ZERO;
5428 DirectiveKindMap[
".extern"] = DK_EXTERN;
5429 DirectiveKindMap[
".globl"] = DK_GLOBL;
5430 DirectiveKindMap[
".global"] = DK_GLOBAL;
5431 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5432 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5433 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5434 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5435 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5436 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5437 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5438 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5439 DirectiveKindMap[
".cold"] = DK_COLD;
5440 DirectiveKindMap[
".comm"] = DK_COMM;
5441 DirectiveKindMap[
".common"] = DK_COMMON;
5442 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5443 DirectiveKindMap[
".abort"] = DK_ABORT;
5444 DirectiveKindMap[
".include"] = DK_INCLUDE;
5445 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5446 DirectiveKindMap[
".code16"] = DK_CODE16;
5447 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5448 DirectiveKindMap[
".rept"] = DK_REPT;
5449 DirectiveKindMap[
".rep"] = DK_REPT;
5450 DirectiveKindMap[
".irp"] = DK_IRP;
5451 DirectiveKindMap[
".irpc"] = DK_IRPC;
5452 DirectiveKindMap[
".endr"] = DK_ENDR;
5453 DirectiveKindMap[
".if"] = DK_IF;
5454 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5455 DirectiveKindMap[
".ifge"] = DK_IFGE;
5456 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5457 DirectiveKindMap[
".ifle"] = DK_IFLE;
5458 DirectiveKindMap[
".iflt"] = DK_IFLT;
5459 DirectiveKindMap[
".ifne"] = DK_IFNE;
5460 DirectiveKindMap[
".ifb"] = DK_IFB;
5461 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5462 DirectiveKindMap[
".ifc"] = DK_IFC;
5463 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5464 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5465 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5466 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5467 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5468 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5469 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5470 DirectiveKindMap[
".else"] = DK_ELSE;
5471 DirectiveKindMap[
".end"] = DK_END;
5472 DirectiveKindMap[
".endif"] = DK_ENDIF;
5473 DirectiveKindMap[
".skip"] = DK_SKIP;
5474 DirectiveKindMap[
".space"] = DK_SPACE;
5475 DirectiveKindMap[
".file"] = DK_FILE;
5476 DirectiveKindMap[
".line"] = DK_LINE;
5477 DirectiveKindMap[
".loc"] = DK_LOC;
5478 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5479 DirectiveKindMap[
".stabs"] = DK_STABS;
5480 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5481 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5482 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5483 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5484 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5485 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5486 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5487 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5488 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5489 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5490 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5491 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5492 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5493 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5494 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5495 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5496 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5497 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5498 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5499 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5500 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5501 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5502 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5503 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5504 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5505 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5506 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5507 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5508 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5509 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5510 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5511 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5512 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5513 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5514 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5515 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5516 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5517 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5518 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5519 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5520 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5521 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5522 DirectiveKindMap[
".macro"] = DK_MACRO;
5523 DirectiveKindMap[
".exitm"] = DK_EXITM;
5524 DirectiveKindMap[
".endm"] = DK_ENDM;
5525 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5526 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5527 DirectiveKindMap[
".err"] = DK_ERR;
5528 DirectiveKindMap[
".error"] = DK_ERROR;
5529 DirectiveKindMap[
".warning"] = DK_WARNING;
5530 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5531 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5532 DirectiveKindMap[
".reloc"] = DK_RELOC;
5533 DirectiveKindMap[
".dc"] = DK_DC;
5534 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5535 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5536 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5537 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5538 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5539 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5540 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5541 DirectiveKindMap[
".dcb"] = DK_DCB;
5542 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5543 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5544 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5545 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5546 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5547 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5548 DirectiveKindMap[
".ds"] = DK_DS;
5549 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5550 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5551 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5552 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5553 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5554 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5555 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5556 DirectiveKindMap[
".print"] = DK_PRINT;
5557 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5558 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5559 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5560 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5561 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5562 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5565MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5566 AsmToken EndToken, StartToken = getTok();
5568 unsigned NestLevel = 0;
5572 printError(DirectiveLoc,
"no matching '.endr' in definition");
5577 StringRef Ident = getTok().getIdentifier();
5578 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5581 }
else if (Ident ==
".endr") {
5582 if (NestLevel == 0) {
5583 EndToken = getTok();
5587 printError(getTok().getLoc(),
"expected newline");
5595 eatToEndOfStatement();
5600 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5604 return &MacroLikeBodies.back();
5607void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5608 raw_svector_ostream &OS) {
5611 std::unique_ptr<MemoryBuffer> Instantiation =
5616 MacroInstantiation *
MI =
new MacroInstantiation{
5617 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5618 ActiveMacros.push_back(
MI);
5628bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5629 const MCExpr *CountExpr;
5630 SMLoc CountLoc = getTok().getLoc();
5631 if (parseExpression(CountExpr))
5635 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5636 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5639 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5643 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5649 SmallString<256> Buf;
5650 raw_svector_ostream OS(Buf);
5653 if (expandMacro(OS, *M, {}, {},
false))
5656 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5663bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5665 MCAsmMacroArguments
A;
5666 if (check(parseIdentifier(
Parameter.Name),
5667 "expected identifier in '.irp' directive") ||
5668 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5672 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5678 SmallString<256> Buf;
5679 raw_svector_ostream OS(Buf);
5681 for (
const MCAsmMacroArgument &Arg :
A) {
5684 if (expandMacro(OS, *M, Parameter, Arg,
true))
5688 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5695bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5697 MCAsmMacroArguments
A;
5699 if (check(parseIdentifier(
Parameter.Name),
5700 "expected identifier in '.irpc' directive") ||
5701 parseComma() || parseMacroArguments(
nullptr,
A))
5704 if (
A.size() != 1 ||
A.front().size() != 1)
5705 return TokError(
"unexpected token in '.irpc' directive");
5710 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5716 SmallString<256> Buf;
5717 raw_svector_ostream OS(Buf);
5720 :
A[0][0].getString();
5721 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5722 MCAsmMacroArgument Arg;
5727 if (expandMacro(OS, *M, Parameter, Arg,
true))
5731 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5736bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5737 if (ActiveMacros.empty())
5738 return TokError(
"unmatched '.endr' directive");
5748bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
5750 const MCExpr *
Value;
5751 SMLoc ExprLoc = getLexer().getLoc();
5752 if (parseExpression(
Value))
5756 return Error(ExprLoc,
"unexpected expression in _emit");
5757 uint64_t IntValue = MCE->
getValue();
5759 return Error(ExprLoc,
"literal value out of range for directive");
5765bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
5766 const MCExpr *
Value;
5767 SMLoc ExprLoc = getLexer().getLoc();
5768 if (parseExpression(
Value))
5772 return Error(ExprLoc,
"unexpected expression in align");
5773 uint64_t IntValue = MCE->
getValue();
5775 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5781bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5782 const AsmToken StrTok = getTok();
5785 return Error(DirectiveLoc,
"expected double quoted string after .print");
5792bool AsmParser::parseDirectiveAddrsig() {
5795 getStreamer().emitAddrsig();
5799bool AsmParser::parseDirectiveAddrsigSym() {
5801 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
5803 getStreamer().emitAddrsigSym(Sym);
5807bool AsmParser::parseDirectivePseudoProbe() {
5813 if (parseIntToken(
Guid))
5815 if (parseIntToken(Index))
5817 if (parseIntToken(
Type))
5819 if (parseIntToken(Attr))
5831 int64_t CallerGuid = 0;
5833 CallerGuid = getTok().getIntVal();
5841 int64_t CallerProbeId = 0;
5843 CallerProbeId = getTok().getIntVal();
5853 if (parseIdentifier(FnName))
5854 return Error(getLexer().getLoc(),
"expected identifier");
5860 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
5861 InlineStack, FnSym);
5870bool AsmParser::parseDirectiveLTODiscard() {
5871 auto ParseOp = [&]() ->
bool {
5873 SMLoc Loc = getTok().getLoc();
5874 if (parseIdentifier(Name))
5875 return Error(Loc,
"expected identifier");
5876 LTODiscardSymbols.
insert(Name);
5880 LTODiscardSymbols.
clear();
5881 return parseMany(ParseOp);
5907bool AsmParser::parseMSInlineAsm(
5908 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
5909 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5910 SmallVectorImpl<std::string> &Constraints,
5911 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
5912 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
5913 SmallVector<void *, 4> InputDecls;
5914 SmallVector<void *, 4> OutputDecls;
5917 SmallVector<std::string, 4> InputConstraints;
5918 SmallVector<std::string, 4> OutputConstraints;
5927 unsigned InputIdx = 0;
5928 unsigned OutputIdx = 0;
5931 if (parseCurlyBlockScope(AsmStrRewrites))
5934 ParseStatementInfo
Info(&AsmStrRewrites);
5935 bool StatementErr = parseStatement(Info, &SI);
5937 if (StatementErr ||
Info.ParseError) {
5939 printPendingErrors();
5944 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5946 if (
Info.Opcode == ~0U)
5952 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
5953 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
5957 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
5958 unsigned NumDefs =
Desc.getNumDefs();
5967 if (SymName.
empty())
5975 if (Operand.
isImm()) {
5983 bool isOutput = (i == 1) &&
Desc.mayStore();
5990 OutputConstraints.
push_back((
"=" + Constraint).str());
5997 if (
Desc.operands()[i - 1].isBranchTarget())
6011 NumOutputs = OutputDecls.
size();
6012 NumInputs = InputDecls.
size();
6017 Clobbers.
assign(ClobberRegs.
size(), std::string());
6018 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6019 raw_string_ostream OS(Clobbers[
I]);
6024 if (NumOutputs || NumInputs) {
6025 unsigned NumExprs = NumOutputs + NumInputs;
6026 OpDecls.resize(NumExprs);
6027 Constraints.
resize(NumExprs);
6028 for (
unsigned i = 0; i < NumOutputs; ++i) {
6029 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6030 Constraints[i] = OutputConstraints[i];
6032 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6033 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6034 Constraints[
j] = InputConstraints[i];
6039 std::string AsmStringIR;
6040 raw_string_ostream OS(AsmStringIR);
6041 StringRef ASMString =
6043 const char *AsmStart = ASMString.
begin();
6044 const char *AsmEnd = ASMString.
end();
6046 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6047 const AsmRewrite &AR = *
I;
6054 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6057 if (
unsigned Len = Loc - AsmStart)
6058 OS << StringRef(AsmStart, Len);
6062 AsmStart = Loc + AR.
Len;
6066 unsigned AdditionalSkip = 0;
6088 size_t OffsetLen = OffsetName.
size();
6089 auto rewrite_it = std::find_if(
6090 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6091 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6092 (FusingAR.Kind == AOK_Input ||
6093 FusingAR.Kind == AOK_CallInput);
6095 if (rewrite_it == AsmStrRewrites.
end()) {
6096 OS <<
"offset " << OffsetName;
6098 OS <<
"${" << InputIdx++ <<
":P}";
6099 rewrite_it->Done =
true;
6101 OS <<
'$' << InputIdx++;
6102 rewrite_it->Done =
true;
6115 OS <<
"${" << InputIdx++ <<
":P}";
6117 OS <<
'$' << InputIdx++;
6120 OS <<
"${" << InputIdx++ <<
":P}";
6124 OS <<
"${" << OutputIdx++ <<
":P}";
6126 OS <<
'$' << OutputIdx++;
6131 case 8: OS <<
"byte ptr ";
break;
6132 case 16: OS <<
"word ptr ";
break;
6133 case 32: OS <<
"dword ptr ";
break;
6134 case 64: OS <<
"qword ptr ";
break;
6135 case 80: OS <<
"xword ptr ";
break;
6136 case 128: OS <<
"xmmword ptr ";
break;
6137 case 256: OS <<
"ymmword ptr ";
break;
6147 if (
getContext().getAsmInfo()->getAlignmentIsInBytes())
6152 unsigned Val = AR.
Val;
6154 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6155 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6167 AsmStart = Loc + AR.
Len + AdditionalSkip;
6171 if (AsmStart != AsmEnd)
6172 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6174 AsmString = std::move(AsmStringIR);
6178bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6179 MCAsmParserSemaCallback *SI) {
6180 AsmToken LabelTok = getTok();
6181 SMLoc LabelLoc = LabelTok.
getLoc();
6184 if (parseIdentifier(LabelVal))
6185 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6190 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6199 return Error(LabelLoc,
6200 "Cannot have just a label for an HLASM inline asm statement");
6210 if (enabledGenDwarfForAssembly())
6217bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6218 MCAsmParserSemaCallback *SI) {
6219 AsmToken OperationEntryTok = Lexer.
getTok();
6220 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6221 StringRef OperationEntryVal;
6224 if (parseIdentifier(OperationEntryVal))
6225 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6231 return parseAndMatchAndEmitTargetInstruction(
6232 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6235bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6236 MCAsmParserSemaCallback *SI) {
6237 assert(!hasPendingError() &&
"parseStatement started with pending error");
6240 bool ShouldParseAsHLASMLabel =
false;
6249 ShouldParseAsHLASMLabel =
true;
6255 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6256 getTok().getString().
front() ==
'\n')
6271 if (getTok().getString().
front() ==
'\n' ||
6272 getTok().getString().
front() ==
'\r') {
6281 if (ShouldParseAsHLASMLabel) {
6284 if (parseAsHLASMLabel(Info, SI)) {
6287 eatToEndOfStatement();
6292 return parseAsMachineInstruction(Info, SI);
6304 return Parser.
TokError(
"missing expression");
6310 return Parser.
Error(
6311 EqualLoc,
"relocation specifier not permitted in symbol equating");
6319 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6325 }
else if (Name ==
".") {
6340 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6341 return new HLASMAsmParser(
SM,
C, Out, MAI, CB);
6343 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")
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
static constexpr unsigned SM(unsigned Version)
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()
MCLFIRewriter * getLFIRewriter()
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.