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;
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);
425 DK_BUNDLE_ALIGN_MODE,
439 DK_WEAK_DEF_CAN_BE_HIDDEN,
480 DK_CV_INLINE_SITE_ID,
483 DK_CV_INLINE_LINETABLE,
488 DK_CV_FILECHECKSUM_OFFSET,
494 DK_CFI_DEF_CFA_OFFSET,
495 DK_CFI_ADJUST_CFA_OFFSET,
496 DK_CFI_DEF_CFA_REGISTER,
497 DK_CFI_LLVM_DEF_ASPACE_CFA,
500 DK_CFI_LLVM_REGISTER_PAIR,
501 DK_CFI_LLVM_VECTOR_REGISTERS,
502 DK_CFI_LLVM_VECTOR_OFFSET,
503 DK_CFI_LLVM_VECTOR_REGISTER_MASK,
506 DK_CFI_REMEMBER_STATE,
507 DK_CFI_RESTORE_STATE,
511 DK_CFI_RETURN_COLUMN,
538 DK_LTO_SET_CONDITIONAL,
539 DK_CFI_MTE_TAGGED_FRAME,
547 StringMap<DirectiveKind> DirectiveKindMap;
550 enum CVDefRangeType {
552 CVDR_DEFRANGE_REGISTER,
553 CVDR_DEFRANGE_FRAMEPOINTER_REL,
554 CVDR_DEFRANGE_SUBFIELD_REGISTER,
555 CVDR_DEFRANGE_REGISTER_REL,
556 CVDR_DEFRANGE_REGISTER_REL_INDIR
561 StringMap<CVDefRangeType> CVDefRangeTypeMap;
564 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
565 bool parseDirectiveBase64();
566 bool parseDirectiveReloc(SMLoc DirectiveLoc);
567 bool parseDirectiveValue(StringRef IDVal,
569 bool parseDirectiveOctaValue(StringRef IDVal);
570 bool parseDirectiveRealValue(StringRef IDVal,
571 const fltSemantics &);
572 bool parseDirectiveFill();
573 bool parseDirectiveZero();
575 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
576 bool parseDirectiveOrg();
578 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
579 bool parseDirectivePrefAlign();
582 bool parseDirectiveFile(SMLoc DirectiveLoc);
583 bool parseDirectiveLine();
584 bool parseDirectiveLoc();
585 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
586 bool parseDirectiveStabs();
590 bool parseDirectiveCVFile();
591 bool parseDirectiveCVFuncId();
592 bool parseDirectiveCVInlineSiteId();
593 bool parseDirectiveCVLoc();
594 bool parseDirectiveCVLinetable();
595 bool parseDirectiveCVInlineLinetable();
596 bool parseDirectiveCVDefRange();
597 bool parseDirectiveCVString();
598 bool parseDirectiveCVStringTable();
599 bool parseDirectiveCVFileChecksums();
600 bool parseDirectiveCVFileChecksumOffset();
601 bool parseDirectiveCVFPOData();
604 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
605 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
606 bool parseDirectiveCFISections();
607 bool parseDirectiveCFIStartProc();
608 bool parseDirectiveCFIEndProc();
609 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
610 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
611 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
612 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
613 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
614 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
615 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
616 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
617 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
618 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
619 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
620 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
621 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
622 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
623 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
624 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
625 bool parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc);
626 bool parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc);
627 bool parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc);
628 bool parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc);
629 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
630 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
633 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
634 bool parseDirectiveExitMacro(StringRef Directive);
635 bool parseDirectiveEndMacro(StringRef Directive);
636 bool parseDirectiveMacro(SMLoc DirectiveLoc);
637 bool parseDirectiveMacrosOnOff(StringRef Directive);
639 bool parseDirectiveAltmacro(StringRef Directive);
642 bool parseDirectiveSpace(StringRef IDVal);
645 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
646 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
648 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
651 bool parseDirectiveLEB128(
bool Signed);
657 bool parseDirectiveComm(
bool IsLocal);
659 bool parseDirectiveAbort(SMLoc DirectiveLoc);
660 bool parseDirectiveInclude();
661 bool parseDirectiveIncbin();
664 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
666 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
668 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
670 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
672 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
673 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
674 bool parseDirectiveElse(SMLoc DirectiveLoc);
675 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
676 bool parseEscapedString(std::string &
Data)
override;
677 bool parseAngleBracketString(std::string &
Data)
override;
680 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
681 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
682 raw_svector_ostream &OS);
683 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
684 bool parseDirectiveIrp(SMLoc DirectiveLoc);
685 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
686 bool parseDirectiveEndr(SMLoc DirectiveLoc);
689 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,
693 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
696 bool parseDirectiveEnd(SMLoc DirectiveLoc);
699 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
702 bool parseDirectiveWarning(SMLoc DirectiveLoc);
705 bool parseDirectivePrint(SMLoc DirectiveLoc);
708 bool parseDirectivePseudoProbe();
711 bool parseDirectiveLTODiscard();
714 bool parseDirectiveAddrsig();
715 bool parseDirectiveAddrsigSym();
718 bool parseDirectiveBundleAlignMode();
720 bool parseDirectiveBundleLock();
722 bool parseDirectiveBundleUnlock();
724 void initializeDirectiveKindMap();
725 void initializeCVDefRangeTypeMap();
728class HLASMAsmParser final :
public AsmParser {
733 void lexLeadingSpaces() {
738 bool parseAsHLASMLabel(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI);
739 bool parseAsMachineInstruction(ParseStatementInfo &Info,
740 MCAsmParserSemaCallback *SI);
743 HLASMAsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
744 const MCAsmInfo &MAI,
unsigned CB = 0)
745 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
746 Lexer.setSkipSpace(
false);
747 Lexer.setAllowHashInIdentifier(
true);
748 Lexer.setLexHLASMIntegers(
true);
749 Lexer.setLexHLASMStrings(
true);
752 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
754 bool parseStatement(ParseStatementInfo &Info,
755 MCAsmParserSemaCallback *SI)
override;
768 :
MCAsmParser(Ctx,
Out, SM, MAI), CurBuffer(CB ? CB : SM.getMainFileID()),
769 MacrosEnabledFlag(
true) {
772 SavedDiagHandler =
SrcMgr.getDiagHandler();
773 SavedDiagContext =
SrcMgr.getDiagContext();
778 Out.setStartTokLocPtr(&StartTokLoc);
781 switch (Ctx.getObjectFileType()) {
782 case MCContext::IsCOFF:
783 PlatformParser.reset(createCOFFAsmParser());
785 case MCContext::IsMachO:
786 PlatformParser.reset(createDarwinAsmParser());
789 case MCContext::IsELF:
790 PlatformParser.reset(createELFAsmParser());
792 case MCContext::IsGOFF:
793 PlatformParser.reset(createGOFFAsmParser());
795 case MCContext::IsSPIRV:
797 "Need to implement createSPIRVAsmParser for SPIRV format.");
799 case MCContext::IsWasm:
800 PlatformParser.reset(createWasmAsmParser());
802 case MCContext::IsXCOFF:
803 PlatformParser.reset(createXCOFFAsmParser());
805 case MCContext::IsDXContainer:
806 report_fatal_error(
"DXContainer is not supported yet");
810 PlatformParser->Initialize(*
this);
811 if (
Out.getLFIRewriter()) {
812 LFIParser.reset(createLFIAsmParser(Out.getLFIRewriter()));
813 LFIParser->Initialize(*this);
815 initializeDirectiveKindMap();
816 initializeCVDefRangeTypeMap();
819AsmParser::~AsmParser() {
820 assert((HadError || ActiveMacros.empty()) &&
821 "Unexpected active macro instantiation!");
824 Out.setStartTokLocPtr(
nullptr);
830void AsmParser::printMacroInstantiations() {
832 for (MacroInstantiation *M :
reverse(ActiveMacros))
834 "while in macro instantiation");
837void AsmParser::Note(SMLoc L,
const Twine &
Msg, SMRange
Range) {
838 printPendingErrors();
840 printMacroInstantiations();
843bool AsmParser::Warning(SMLoc L,
const Twine &
Msg, SMRange
Range) {
844 if(getTargetParser().getTargetOptions().MCNoWarn)
846 if (getTargetParser().getTargetOptions().MCFatalWarnings)
849 printMacroInstantiations();
853bool AsmParser::printError(SMLoc L,
const Twine &
Msg, SMRange
Range) {
856 printMacroInstantiations();
860bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
861 std::string IncludedFile;
875bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
876 const MCExpr *
Count, SMLoc Loc) {
878 if (SymbolScanningMode)
884 std::string IncludedFile;
891 StringRef Bytes = (*BufOrErr)->getBuffer();
895 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
896 return Error(Loc,
"expected absolute expression");
898 return Warning(Loc,
"negative count has no effect");
901 getStreamer().emitBytes(Bytes);
905void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
911const AsmToken &AsmParser::Lex() {
918 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
920 Out.addExplicitComment(Twine(getTok().getString()));
923 const AsmToken *tok = &Lexer.
Lex();
936 if (ParentIncludeLoc != SMLoc()) {
937 jumpToLoc(ParentIncludeLoc);
945bool AsmParser::enabledGenDwarfForAssembly() {
952 if (
getContext().getGenDwarfFileNumber() == 0) {
953 const MCDwarfFile &RootFile =
954 getContext().getMCDwarfLineTable(0).getRootFile();
955 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
962bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
963 LTODiscardSymbols.
clear();
966 if (!NoInitialTextSection)
967 Out.initSections(getTargetParser().getSTI());
973 AsmCond StartingCondState = TheCondState;
981 MCSection *Sec = getStreamer().getCurrentSectionOnly();
984 getStreamer().emitLabel(SectionStartSym);
987 bool InsertResult =
getContext().addGenDwarfSection(Sec);
988 assert(InsertResult &&
".text section should not have debug info yet");
992 getTargetParser().onBeginOfFile();
996 ParseStatementInfo
Info(&AsmStrRewrites);
997 bool HasError = parseStatement(Info,
nullptr);
1006 printPendingErrors();
1009 if (HasError && !getLexer().justConsumedEOL())
1010 eatToEndOfStatement();
1013 getTargetParser().onEndOfFile();
1014 printPendingErrors();
1017 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1021 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1023 const auto &LineTables =
getContext().getMCDwarfLineTables();
1024 if (!LineTables.empty()) {
1026 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1027 if (
File.Name.empty() && Index != 0)
1028 printError(getTok().getLoc(),
"unassigned file number: " +
1030 " for .file directives");
1042 MCSymbol *Sym = TableEntry.getValue().Symbol;
1051 printError(getTok().getLoc(),
"assembler local symbol '" +
1052 Sym->
getName() +
"' not defined");
1058 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1059 if (std::get<2>(LocSym)->isUndefined()) {
1062 CppHashInfo = std::get<1>(LocSym);
1063 printError(std::get<0>(LocSym),
"directional label undefined");
1069 if (!HadError && !NoFinalize) {
1070 if (
auto *TS =
Out.getTargetStreamer())
1071 TS->emitConstantPools();
1079bool AsmParser::checkForValidSection() {
1080 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1081 Out.initSections(getTargetParser().getSTI());
1082 return Error(getTok().getLoc(),
1083 "expected section directive before assembly directive");
1089void AsmParser::eatToEndOfStatement() {
1098StringRef AsmParser::parseStringToEndOfStatement() {
1099 const char *
Start = getTok().getLoc().getPointer();
1105 return StringRef(Start,
End - Start);
1108StringRef AsmParser::parseStringToComma() {
1109 const char *
Start = getTok().getLoc().getPointer();
1116 return StringRef(Start,
End - Start);
1124bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1125 if (parseExpression(Res))
1128 return parseRParen();
1136bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1137 if (parseExpression(Res))
1139 EndLoc = getTok().getEndLoc();
1140 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1151bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1152 AsmTypeInfo *TypeInfo) {
1153 SMLoc FirstTokenLoc = getLexer().getLoc();
1155 switch (FirstTokenKind) {
1157 return TokError(
"unknown token in expression");
1163 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1173 if (parseIdentifier(Identifier)) {
1177 bool ShouldGenerateTempSymbol =
false;
1180 ShouldGenerateTempSymbol =
true;
1182 if (!ShouldGenerateTempSymbol)
1183 return Error(FirstTokenLoc,
"invalid token in expression");
1192 EndLoc = FirstTokenLoc;
1197 std::pair<StringRef, StringRef>
Split;
1202 SMLoc AtLoc = getLexer().getLoc();
1204 if (parseIdentifier(VName))
1205 return Error(AtLoc,
"expected symbol variant after '@'");
1207 Split = std::make_pair(Identifier, VName);
1215 parseIdentifier(VName);
1218 Split = std::make_pair(Identifier, VName);
1226 return Error(getLexer().getLoc(),
"expected a symbol reference");
1230 if (!
Split.second.empty()) {
1232 if (MaybeSpecifier) {
1234 Spec = *MaybeSpecifier;
1237 "invalid variant '" +
Split.second +
"'");
1252 DoInline = TV->inlineAssignedExpr();
1255 return Error(EndLoc,
"unexpected modifier on variable reference");
1266 return TokError(
"literal value out of range for directive");
1268 SMLoc Loc = getTok().getLoc();
1269 int64_t
IntVal = getTok().getIntVal();
1275 StringRef IDVal = getTok().getString();
1277 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1279 if (
Split.first.size() != IDVal.
size()) {
1282 return TokError(
"invalid variant '" +
Split.second +
"'");
1283 IDVal =
Split.first;
1286 if (IDVal ==
"f" || IDVal ==
"b") {
1291 return Error(Loc,
"directional label undefined");
1292 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1300 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1309 return TokError(
"cannot use . as current PC");
1322 return parseParenExpr(Res, EndLoc);
1324 if (!PlatformParser->HasBracketExpressions())
1325 return TokError(
"brackets expression not supported on this target");
1327 return parseBracketExpr(Res, EndLoc);
1330 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1336 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1342 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1349bool AsmParser::parseExpression(
const MCExpr *&Res) {
1351 return parseExpression(Res, EndLoc);
1361 switch (E->getKind()) {
1372 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1373 "' (already modified)");
1424 "Argument to the function cannot be a NULL value");
1426 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1427 (*CharPtr !=
'\0')) {
1428 if (*CharPtr ==
'!')
1432 if (*CharPtr ==
'>') {
1442 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1443 if (AltMacroStr[Pos] ==
'!')
1445 Res += AltMacroStr[Pos];
1453 return TokError(
"expected specifier following '@'");
1455 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1457 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1477bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1480 auto &TS = getTargetParser();
1481 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1489 return TokError(
"unexpected symbol modifier following '@'");
1493 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1495 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1497 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1498 "' (no symbols present)");
1508 if (Res->evaluateAsAbsolute(
Value))
1514bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1516 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1519bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1522 SMLoc StartLoc = Lexer.
getLoc();
1523 if (parseExpression(Expr))
1526 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1527 return Error(StartLoc,
"expected absolute expression");
1534 bool ShouldUseLogicalShr) {
1611 bool ShouldUseLogicalShr) {
1700bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1702 SMLoc StartLoc = Lexer.
getLoc();
1705 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1709 if (TokPrec < Precedence)
1716 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1722 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1723 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1735bool AsmParser::parseStatement(ParseStatementInfo &Info,
1736 MCAsmParserSemaCallback *SI) {
1737 assert(!hasPendingError() &&
"parseStatement started with pending error");
1743 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1744 getTok().getString().
front() ==
'\n')
1750 AsmToken
ID = getTok();
1751 SMLoc IDLoc =
ID.getLoc();
1753 int64_t LocalLabelVal = -1;
1754 StartTokLoc =
ID.getLoc();
1756 return parseCppHashLineFilenameComment(IDLoc,
1757 !isInsideMacroInstantiation());
1761 LocalLabelVal = getTok().getIntVal();
1762 if (LocalLabelVal < 0) {
1763 if (!TheCondState.
Ignore) {
1765 return Error(IDLoc,
"unexpected token at start of statement");
1769 IDVal = getTok().getString();
1772 if (!TheCondState.
Ignore) {
1774 return Error(IDLoc,
"unexpected token at start of statement");
1782 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1784 IDVal =
ID.getString();
1785 }
else if (parseIdentifier(IDVal)) {
1786 if (!TheCondState.
Ignore) {
1788 return Error(IDLoc,
"unexpected token at start of statement");
1797 DirectiveKindMap.find(IDVal.
lower());
1798 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1800 : DirKindIt->getValue();
1811 return parseDirectiveIf(IDLoc, DirKind);
1813 return parseDirectiveIfb(IDLoc,
true);
1815 return parseDirectiveIfb(IDLoc,
false);
1817 return parseDirectiveIfc(IDLoc,
true);
1819 return parseDirectiveIfeqs(IDLoc,
true);
1821 return parseDirectiveIfc(IDLoc,
false);
1823 return parseDirectiveIfeqs(IDLoc,
false);
1825 return parseDirectiveIfdef(IDLoc,
true);
1828 return parseDirectiveIfdef(IDLoc,
false);
1830 return parseDirectiveElseIf(IDLoc);
1832 return parseDirectiveElse(IDLoc);
1834 return parseDirectiveEndIf(IDLoc);
1839 if (TheCondState.
Ignore) {
1840 eatToEndOfStatement();
1850 if (checkForValidSection())
1857 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1865 if (LocalLabelVal == -1) {
1866 if (ParsingMSInlineAsm && SI) {
1867 StringRef RewrittenLabel =
1868 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1870 "We should have an internal name here.");
1873 IDVal = RewrittenLabel;
1883 StringRef CommentStr = parseStringToEndOfStatement();
1894 if (MAI.
isMachO() && CFIStartProcLoc) {
1895 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1896 if (SymM->isExternal() && !SymM->isAltEntry())
1897 return Error(StartTokLoc,
"non-private labels cannot appear between "
1898 ".cfi_startproc / .cfi_endproc pairs") &&
1899 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1902 if (discardLTOSymbol(IDVal))
1905 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1908 if (!getTargetParser().isParsingMSInlineAsm())
1909 Out.emitLabel(Sym, IDLoc);
1913 if (enabledGenDwarfForAssembly())
1917 getTargetParser().onLabelParsed(Sym);
1926 return parseAssignment(IDVal, AssignmentKind::Equal);
1930 if (areMacrosEnabled())
1931 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1932 return handleMacroEntry(M, IDLoc);
1949 getTargetParser().flushPendingInstructions(getStreamer());
1951 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(ID);
1953 "Should only return Failure iff there was an error");
1961 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1962 ExtensionDirectiveMap.
lookup(IDVal);
1964 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1973 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1975 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1976 case DK_LTO_SET_CONDITIONAL:
1977 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1979 return parseDirectiveAscii(IDVal,
false);
1982 return parseDirectiveAscii(IDVal,
true);
1984 return parseDirectiveBase64();
1987 return parseDirectiveValue(IDVal, 1);
1993 return parseDirectiveValue(IDVal, 2);
1998 return parseDirectiveValue(IDVal, 4);
2001 return parseDirectiveValue(IDVal, 8);
2003 return parseDirectiveValue(
2004 IDVal,
getContext().getAsmInfo().getCodePointerSize());
2006 return parseDirectiveOctaValue(IDVal);
2010 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
2013 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
2015 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2016 return parseDirectiveAlign(IsPow2, 1);
2019 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2020 return parseDirectiveAlign(IsPow2, 4);
2023 return parseDirectiveAlign(
false, 1);
2025 return parseDirectiveAlign(
false, 2);
2027 return parseDirectiveAlign(
false, 4);
2029 return parseDirectiveAlign(
true, 1);
2031 return parseDirectiveAlign(
true, 2);
2033 return parseDirectiveAlign(
true, 4);
2035 return parseDirectivePrefAlign();
2037 return parseDirectiveOrg();
2039 return parseDirectiveFill();
2041 return parseDirectiveZero();
2043 eatToEndOfStatement();
2047 return parseDirectiveSymbolAttribute(
MCSA_Global);
2048 case DK_LAZY_REFERENCE:
2050 case DK_NO_DEAD_STRIP:
2052 case DK_SYMBOL_RESOLVER:
2054 case DK_PRIVATE_EXTERN:
2058 case DK_WEAK_DEFINITION:
2060 case DK_WEAK_REFERENCE:
2062 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2065 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2068 return parseDirectiveComm(
false);
2070 return parseDirectiveComm(
true);
2072 return parseDirectiveAbort(IDLoc);
2074 return parseDirectiveInclude();
2076 return parseDirectiveIncbin();
2079 return TokError(Twine(IDVal) +
2080 " not currently supported for this target");
2082 return parseDirectiveRept(IDLoc, IDVal);
2084 return parseDirectiveIrp(IDLoc);
2086 return parseDirectiveIrpc(IDLoc);
2088 return parseDirectiveEndr(IDLoc);
2089 case DK_BUNDLE_ALIGN_MODE:
2090 return parseDirectiveBundleAlignMode();
2091 case DK_BUNDLE_LOCK:
2092 return parseDirectiveBundleLock();
2093 case DK_BUNDLE_UNLOCK:
2094 return parseDirectiveBundleUnlock();
2096 return parseDirectiveLEB128(
true);
2098 return parseDirectiveLEB128(
false);
2101 return parseDirectiveSpace(IDVal);
2103 return parseDirectiveFile(IDLoc);
2105 return parseDirectiveLine();
2107 return parseDirectiveLoc();
2109 return parseDirectiveLocLabel(IDLoc);
2111 return parseDirectiveStabs();
2113 return parseDirectiveCVFile();
2115 return parseDirectiveCVFuncId();
2116 case DK_CV_INLINE_SITE_ID:
2117 return parseDirectiveCVInlineSiteId();
2119 return parseDirectiveCVLoc();
2120 case DK_CV_LINETABLE:
2121 return parseDirectiveCVLinetable();
2122 case DK_CV_INLINE_LINETABLE:
2123 return parseDirectiveCVInlineLinetable();
2124 case DK_CV_DEF_RANGE:
2125 return parseDirectiveCVDefRange();
2127 return parseDirectiveCVString();
2128 case DK_CV_STRINGTABLE:
2129 return parseDirectiveCVStringTable();
2130 case DK_CV_FILECHECKSUMS:
2131 return parseDirectiveCVFileChecksums();
2132 case DK_CV_FILECHECKSUM_OFFSET:
2133 return parseDirectiveCVFileChecksumOffset();
2134 case DK_CV_FPO_DATA:
2135 return parseDirectiveCVFPOData();
2136 case DK_CFI_SECTIONS:
2137 return parseDirectiveCFISections();
2138 case DK_CFI_STARTPROC:
2139 return parseDirectiveCFIStartProc();
2140 case DK_CFI_ENDPROC:
2141 return parseDirectiveCFIEndProc();
2142 case DK_CFI_DEF_CFA:
2143 return parseDirectiveCFIDefCfa(IDLoc);
2144 case DK_CFI_DEF_CFA_OFFSET:
2145 return parseDirectiveCFIDefCfaOffset(IDLoc);
2146 case DK_CFI_ADJUST_CFA_OFFSET:
2147 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2148 case DK_CFI_DEF_CFA_REGISTER:
2149 return parseDirectiveCFIDefCfaRegister(IDLoc);
2150 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2151 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2153 return parseDirectiveCFIOffset(IDLoc);
2154 case DK_CFI_REL_OFFSET:
2155 return parseDirectiveCFIRelOffset(IDLoc);
2156 case DK_CFI_LLVM_REGISTER_PAIR:
2157 return parseDirectiveCFILLVMRegisterPair(IDLoc);
2158 case DK_CFI_LLVM_VECTOR_REGISTERS:
2159 return parseDirectiveCFILLVMVectorRegisters(IDLoc);
2160 case DK_CFI_LLVM_VECTOR_OFFSET:
2161 return parseDirectiveCFILLVMVectorOffset(IDLoc);
2162 case DK_CFI_LLVM_VECTOR_REGISTER_MASK:
2163 return parseDirectiveCFILLVMVectorRegisterMask(IDLoc);
2164 case DK_CFI_PERSONALITY:
2165 return parseDirectiveCFIPersonalityOrLsda(
true);
2167 return parseDirectiveCFIPersonalityOrLsda(
false);
2168 case DK_CFI_REMEMBER_STATE:
2169 return parseDirectiveCFIRememberState(IDLoc);
2170 case DK_CFI_RESTORE_STATE:
2171 return parseDirectiveCFIRestoreState(IDLoc);
2172 case DK_CFI_SAME_VALUE:
2173 return parseDirectiveCFISameValue(IDLoc);
2174 case DK_CFI_RESTORE:
2175 return parseDirectiveCFIRestore(IDLoc);
2177 return parseDirectiveCFIEscape(IDLoc);
2178 case DK_CFI_RETURN_COLUMN:
2179 return parseDirectiveCFIReturnColumn(IDLoc);
2180 case DK_CFI_SIGNAL_FRAME:
2181 return parseDirectiveCFISignalFrame(IDLoc);
2182 case DK_CFI_UNDEFINED:
2183 return parseDirectiveCFIUndefined(IDLoc);
2184 case DK_CFI_REGISTER:
2185 return parseDirectiveCFIRegister(IDLoc);
2186 case DK_CFI_WINDOW_SAVE:
2187 return parseDirectiveCFIWindowSave(IDLoc);
2189 return parseDirectiveCFILabel(IDLoc);
2190 case DK_CFI_VAL_OFFSET:
2191 return parseDirectiveCFIValOffset(IDLoc);
2194 return parseDirectiveMacrosOnOff(IDVal);
2196 return parseDirectiveMacro(IDLoc);
2199 return parseDirectiveAltmacro(IDVal);
2201 return parseDirectiveExitMacro(IDVal);
2204 return parseDirectiveEndMacro(IDVal);
2206 return parseDirectivePurgeMacro(IDLoc);
2208 return parseDirectiveEnd(IDLoc);
2210 return parseDirectiveError(IDLoc,
false);
2212 return parseDirectiveError(IDLoc,
true);
2214 return parseDirectiveWarning(IDLoc);
2216 return parseDirectiveReloc(IDLoc);
2219 return parseDirectiveDCB(IDVal, 2);
2221 return parseDirectiveDCB(IDVal, 1);
2223 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2225 return parseDirectiveDCB(IDVal, 4);
2227 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2230 return TokError(Twine(IDVal) +
2231 " not currently supported for this target");
2234 return parseDirectiveDS(IDVal, 2);
2236 return parseDirectiveDS(IDVal, 1);
2238 return parseDirectiveDS(IDVal, 8);
2241 return parseDirectiveDS(IDVal, 4);
2244 return parseDirectiveDS(IDVal, 12);
2246 return parseDirectivePrint(IDLoc);
2248 return parseDirectiveAddrsig();
2249 case DK_ADDRSIG_SYM:
2250 return parseDirectiveAddrsigSym();
2251 case DK_PSEUDO_PROBE:
2252 return parseDirectivePseudoProbe();
2253 case DK_LTO_DISCARD:
2254 return parseDirectiveLTODiscard();
2256 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2259 return Error(IDLoc,
"unknown directive");
2263 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2264 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2265 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2268 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2269 return parseDirectiveMSAlign(IDLoc, Info);
2271 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2273 if (checkForValidSection())
2276 return parseAndMatchAndEmitTargetInstruction(Info, IDVal, ID, IDLoc);
2279bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2284 std::string OpcodeStr = IDVal.
lower();
2285 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2286 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr, ID,
2287 Info.ParsedOperands);
2288 Info.ParseError = ParseHadError;
2291 if (getShowParsedOperands()) {
2292 SmallString<256> Str;
2293 raw_svector_ostream OS(Str);
2294 OS <<
"parsed instruction: [";
2295 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2298 Info.ParsedOperands[i]->print(OS, MAI);
2306 if (hasPendingError() || ParseHadError)
2311 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2313 getStreamer().getCurrentSectionOnly())) {
2315 if (ActiveMacros.empty())
2319 ActiveMacros.front()->ExitBuffer);
2324 if (!CppHashInfo.Filename.empty()) {
2325 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2326 0, StringRef(), CppHashInfo.Filename);
2327 getContext().setGenDwarfFileNumber(FileNumber);
2329 unsigned CppHashLocLineNo =
2331 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2334 getStreamer().emitDwarfLocDirective(
2335 getContext().getGenDwarfFileNumber(), Line, 0,
2341 if (!ParseHadError) {
2343 if (getTargetParser().matchAndEmitInstruction(
2344 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2345 getTargetParser().isParsingMSInlineAsm()))
2353AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2358 SMLoc StartLoc = Lexer.
getLoc();
2371bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2376 "Lexing Cpp line comment: Expected Integer");
2377 int64_t LineNumber = getTok().getIntVal();
2380 "Lexing Cpp line comment: Expected String");
2381 StringRef
Filename = getTok().getString();
2392 CppHashInfo.Loc =
L;
2394 CppHashInfo.LineNumber = LineNumber;
2395 CppHashInfo.Buf = CurBuffer;
2396 if (!HadCppHashFilename) {
2397 HadCppHashFilename =
true;
2407 std::nullopt, std::nullopt);
2415void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2416 auto *Parser =
static_cast<AsmParser *
>(
Context);
2417 raw_ostream &OS =
errs();
2420 SMLoc DiagLoc = Diag.
getLoc();
2422 unsigned CppHashBuf =
2423 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2427 if (!Parser->SavedDiagHandler)
2433 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2434 if (Parser->SavedDiagHandler)
2435 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2437 Parser->getContext().diagnose(Diag);
2444 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2447 int CppHashLocLineNo =
2448 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2450 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2456 if (Parser->SavedDiagHandler)
2457 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2459 Parser->getContext().diagnose(NewDiag);
2470bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2473 bool EnableAtPseudoVariable) {
2475 auto expandArg = [&](
unsigned Index) {
2476 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2477 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2478 for (
const AsmToken &Token :
A[Index])
2486 if (AltMacroMode && Token.getString().front() ==
'%' &&
2489 OS << Token.getIntVal();
2492 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2499 OS << Token.getString();
2501 OS << Token.getStringContents();
2506 StringRef Body =
Macro.Body;
2509 if (Body[
I] ==
'\\' &&
I + 1 !=
End) {
2511 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2512 OS << NumOfMacroInstantiations;
2516 if (Body[
I + 1] ==
'+') {
2521 if (Body[
I + 1] ==
'(' &&
I + 2 !=
End && Body[
I + 2] ==
')') {
2530 if (AltMacroMode &&
I !=
End && Body[
I] ==
'&')
2534 if (Parameters[Index].Name == Argument)
2536 if (Index == NParameters)
2545 if (Body[
I] ==
'$' &&
I + 1 !=
End && IsDarwin && !NParameters) {
2547 switch (Body[
I + 1]) {
2563 unsigned Index = Body[
I + 1] -
'0';
2564 if (Index <
A.size())
2565 for (
const AsmToken &Token :
A[Index])
2566 OS << Token.getString();
2581 StringRef Token(Body.
data() + Start,
I - Start);
2585 if (Parameters[Index].Name == Token)
2587 if (Index != NParameters) {
2589 if (
I !=
End && Body[
I] ==
'&')
2633class AsmLexerSkipSpaceRAII {
2635 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2639 ~AsmLexerSkipSpaceRAII() {
2649bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2653 StringRef Str = parseStringToEndOfStatement();
2659 unsigned ParenLevel = 0;
2662 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2669 return TokError(
"unexpected token in macro instantiation");
2671 if (ParenLevel == 0) {
2684 MA.push_back(getTok());
2708 MA.push_back(getTok());
2712 if (ParenLevel != 0)
2713 return TokError(
"unbalanced parentheses in macro argument");
2718bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2719 MCAsmMacroArguments &
A) {
2720 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2721 bool NamedParametersFound =
false;
2722 SmallVector<SMLoc, 4> FALocs;
2724 A.resize(NParameters);
2725 FALocs.
resize(NParameters);
2730 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2731 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2733 SMLoc IDLoc = Lexer.
getLoc();
2734 MCAsmMacroParameter FA;
2737 if (parseIdentifier(FA.
Name))
2738 return Error(IDLoc,
"invalid argument identifier for formal argument");
2741 return TokError(
"expected '=' after formal parameter identifier");
2745 NamedParametersFound =
true;
2747 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2749 if (NamedParametersFound && FA.
Name.
empty())
2750 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2752 SMLoc StrLoc = Lexer.
getLoc();
2755 const MCExpr *AbsoluteExp;
2759 if (parseExpression(AbsoluteExp, EndLoc))
2761 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2762 getStreamer().getAssemblerPtr()))
2763 return Error(StrLoc,
"expected absolute expression");
2767 StringRef(StrChar, EndChar - StrChar),
Value);
2768 FA.
Value.push_back(newToken);
2773 jumpToLoc(EndLoc, CurBuffer);
2777 StringRef(StrChar, EndChar - StrChar));
2778 FA.
Value.push_back(newToken);
2779 }
else if(parseMacroArgument(FA.
Value, Vararg))
2785 for (FAI = 0; FAI < NParameters; ++FAI)
2786 if (
M->Parameters[FAI].Name == FA.
Name)
2789 if (FAI >= NParameters) {
2790 assert(M &&
"expected macro to be defined");
2791 return Error(IDLoc,
"parameter named '" + FA.
Name +
2792 "' does not exist for macro '" +
M->Name +
"'");
2797 if (!FA.
Value.empty()) {
2802 if (FALocs.
size() <= PI)
2805 FALocs[PI] = Lexer.
getLoc();
2813 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2815 if (
M->Parameters[FAI].Required) {
2817 "missing value for required parameter "
2818 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2822 if (!
M->Parameters[FAI].Value.empty())
2823 A[FAI] =
M->Parameters[FAI].Value;
2832 return TokError(
"too many positional arguments");
2835bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2839 if (ActiveMacros.size() == MaxNestingDepth) {
2840 std::ostringstream MaxNestingDepthError;
2841 MaxNestingDepthError <<
"macros cannot be nested more than "
2842 << MaxNestingDepth <<
" levels deep."
2843 <<
" Use -asm-macro-max-nesting-depth to increase "
2845 return TokError(MaxNestingDepthError.str());
2848 MCAsmMacroArguments
A;
2849 if (parseMacroArguments(M,
A))
2854 SmallString<256> Buf;
2855 raw_svector_ostream OS(Buf);
2857 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2858 return Error(getTok().getLoc(),
"Wrong number of arguments");
2859 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2864 OS <<
".endmacro\n";
2866 std::unique_ptr<MemoryBuffer> Instantiation =
2871 MacroInstantiation *
MI =
new MacroInstantiation{
2872 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2873 ActiveMacros.push_back(
MI);
2875 ++NumOfMacroInstantiations;
2885void AsmParser::handleMacroExit() {
2887 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2895 delete ActiveMacros.back();
2896 ActiveMacros.pop_back();
2899bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2902 if (discardLTOSymbol(Name)) {
2903 eatToEndOfStatement();
2908 const MCExpr *
Value;
2909 SMLoc ExprLoc = getTok().getLoc();
2911 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2925 case AssignmentKind::Equal:
2928 case AssignmentKind::Set:
2929 case AssignmentKind::Equiv:
2933 case AssignmentKind::LTOSetConditional:
2935 return Error(ExprLoc,
"expected identifier");
2937 Out.emitConditionalAssignment(Sym,
Value);
2947bool AsmParser::parseIdentifier(StringRef &Res) {
2954 SMLoc PrefixLoc = getLexer().getLoc();
2966 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2972 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2980 Res = getTok().getIdentifier();
2992bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2994 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2995 parseAssignment(Name, Kind))
3000bool AsmParser::parseEscapedString(std::string &
Data) {
3005 StringRef Str = getTok().getStringContents();
3006 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
3007 if (Str[i] !=
'\\') {
3008 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
3010 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
3014 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
3025 return TokError(
"unexpected backslash at end of string");
3028 if (Str[i] ==
'x' || Str[i] ==
'X') {
3029 size_t length = Str.size();
3030 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
3031 return TokError(
"invalid hexadecimal escape sequence");
3036 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3044 if ((
unsigned)(Str[i] -
'0') <= 7) {
3046 unsigned Value = Str[i] -
'0';
3048 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3052 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3059 return TokError(
"invalid octal escape sequence (out of range)");
3069 return TokError(
"invalid escape sequence (unrecognized character)");
3071 case 'b':
Data +=
'\b';
break;
3072 case 'f':
Data +=
'\f';
break;
3073 case 'n':
Data +=
'\n';
break;
3074 case 'r':
Data +=
'\r';
break;
3075 case 't':
Data +=
'\t';
break;
3076 case '"':
Data +=
'"';
break;
3077 case '\\':
Data +=
'\\';
break;
3085bool AsmParser::parseAngleBracketString(std::string &
Data) {
3086 SMLoc EndLoc, StartLoc = getTok().getLoc();
3088 const char *StartChar = StartLoc.
getPointer() + 1;
3089 const char *EndChar = EndLoc.
getPointer() - 1;
3090 jumpToLoc(EndLoc, CurBuffer);
3103bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3104 auto parseOp = [&]() ->
bool {
3106 if (checkForValidSection())
3111 if (parseEscapedString(
Data))
3113 getStreamer().emitBytes(
Data);
3116 getStreamer().emitBytes(StringRef(
"\0", 1));
3120 return parseMany(parseOp);
3125bool AsmParser::parseDirectiveBase64() {
3126 auto parseOp = [&]() ->
bool {
3127 if (checkForValidSection())
3134 std::vector<char> Decoded;
3135 std::string
const str = getTok().getStringContents().str();
3136 if (check(str.empty(),
"expected nonempty string")) {
3143 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3146 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3151 return check(parseMany(parseOp),
"expected string");
3156bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3158 const MCExpr *Expr =
nullptr;
3160 if (parseExpression(
Offset))
3172 SMLoc ExprLoc = Lexer.
getLoc();
3173 if (parseExpression(Expr))
3178 return Error(ExprLoc,
"expression must be relocatable");
3184 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3190bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3191 auto parseOp = [&]() ->
bool {
3192 const MCExpr *
Value;
3193 SMLoc ExprLoc = getLexer().getLoc();
3194 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3199 uint64_t IntValue = MCE->getValue();
3201 return Error(ExprLoc,
"out of range literal value");
3202 getStreamer().emitIntValue(IntValue,
Size);
3204 getStreamer().emitValue(
Value,
Size, ExprLoc);
3208 return parseMany(parseOp);
3214 return Asm.TokError(
"unknown token in expression");
3215 SMLoc ExprLoc = Asm.getTok().getLoc();
3216 APInt IntValue = Asm.getTok().getAPIntVal();
3218 if (!IntValue.
isIntN(128))
3219 return Asm.Error(ExprLoc,
"out of range literal value");
3220 if (!IntValue.
isIntN(64)) {
3233bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3234 auto parseOp = [&]() ->
bool {
3235 if (checkForValidSection())
3241 getStreamer().emitInt64(lo);
3242 getStreamer().emitInt64(hi);
3244 getStreamer().emitInt64(hi);
3245 getStreamer().emitInt64(lo);
3250 return parseMany(parseOp);
3253bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3264 return TokError(Lexer.
getErr());
3267 return TokError(
"unexpected token in directive");
3271 StringRef IDVal = getTok().getString();
3279 return TokError(
"invalid floating point literal");
3281 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3283 return TokError(
"invalid floating point literal");
3290 Res =
Value.bitcastToAPInt();
3297bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3298 const fltSemantics &Semantics) {
3299 auto parseOp = [&]() ->
bool {
3301 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3308 return parseMany(parseOp);
3313bool AsmParser::parseDirectiveZero() {
3314 SMLoc NumBytesLoc = Lexer.
getLoc();
3315 const MCExpr *NumBytes;
3316 if (checkForValidSection() || parseExpression(NumBytes))
3322 if (parseAbsoluteExpression(Val))
3328 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3335bool AsmParser::parseDirectiveFill() {
3336 SMLoc NumValuesLoc = Lexer.
getLoc();
3337 const MCExpr *NumValues;
3338 if (checkForValidSection() || parseExpression(NumValues))
3341 int64_t FillSize = 1;
3342 int64_t FillExpr = 0;
3344 SMLoc SizeLoc, ExprLoc;
3347 SizeLoc = getTok().getLoc();
3348 if (parseAbsoluteExpression(FillSize))
3351 ExprLoc = getTok().getLoc();
3352 if (parseAbsoluteExpression(FillExpr))
3360 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3364 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3369 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3371 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3378bool AsmParser::parseDirectiveOrg() {
3380 SMLoc OffsetLoc = Lexer.
getLoc();
3381 if (checkForValidSection() || parseExpression(
Offset))
3385 int64_t FillExpr = 0;
3387 if (parseAbsoluteExpression(FillExpr))
3392 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3398bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3399 SMLoc AlignmentLoc = getLexer().getLoc();
3402 bool HasFillExpr =
false;
3403 int64_t FillExpr = 0;
3404 int64_t MaxBytesToFill = 0;
3407 auto parseAlign = [&]() ->
bool {
3408 if (parseAbsoluteExpression(Alignment))
3416 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3420 if (parseTokenLoc(MaxBytesLoc) ||
3421 parseAbsoluteExpression(MaxBytesToFill))
3427 if (checkForValidSection())
3431 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3438 bool ReturnVal =
false;
3442 if (Alignment < 0 || Alignment >= 32) {
3443 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3455 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3459 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3466 if (MaxBytesToFill < 1) {
3467 ReturnVal |=
Error(MaxBytesLoc,
3468 "alignment directive can never be satisfied in this "
3469 "many bytes, ignoring maximum bytes expression");
3473 if (MaxBytesToFill >= Alignment) {
3474 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3480 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3481 assert(Section &&
"must have section to emit alignment");
3483 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3485 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3493 getStreamer().emitCodeAlignment(
Align(Alignment),
3494 getTargetParser().getSTI(), MaxBytesToFill);
3497 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3504bool AsmParser::parseDirectivePrefAlign() {
3505 SMLoc AlignmentLoc = getLexer().getLoc();
3507 if (checkForValidSection() || parseAbsoluteExpression(Log2Alignment))
3510 if (Log2Alignment < 0 || Log2Alignment > 63)
3511 return Error(AlignmentLoc,
"log2 alignment must be in the range [0, 63]");
3514 SMLoc SymLoc = getLexer().getLoc();
3518 SymLoc = getLexer().getLoc();
3519 if (parseIdentifier(Name))
3520 return Error(SymLoc,
"expected symbol name");
3524 SMLoc FillLoc = getLexer().getLoc();
3528 bool EmitNops =
false;
3530 SMLoc FillLoc2 = getLexer().getLoc();
3532 getLexer().getTok().getIdentifier() ==
"nop") {
3537 if (parseAbsoluteExpression(FillVal))
3539 if (FillVal < 0 || FillVal > 255)
3540 return Error(FillLoc2,
"fill value must be in range [0, 255]");
3541 Fill =
static_cast<uint8_t
>(FillVal);
3546 if ((EmitNops || Fill != 0) &&
3547 getStreamer().getCurrentSectionOnly()->isBssSection())
3548 return Error(FillLoc,
"non-zero fill in BSS section '" +
3549 getStreamer().getCurrentSectionOnly()->
getName() +
3553 Fill, getTargetParser().getSTI());
3560bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3562 int64_t FileNumber = -1;
3564 FileNumber = getTok().getIntVal();
3568 return TokError(
"negative file number");
3575 if (parseEscapedString(Path))
3578 StringRef Directory;
3580 std::string FilenameData;
3582 if (check(FileNumber == -1,
3583 "explicit path specified, but no file number") ||
3584 parseEscapedString(FilenameData))
3593 bool HasMD5 =
false;
3595 std::optional<StringRef>
Source;
3596 bool HasSource =
false;
3597 std::string SourceString;
3602 "unexpected token in '.file' directive") ||
3603 parseIdentifier(Keyword))
3605 if (Keyword ==
"md5") {
3607 if (check(FileNumber == -1,
3608 "MD5 checksum specified, but no file number") ||
3611 }
else if (Keyword ==
"source") {
3613 if (check(FileNumber == -1,
3614 "source specified, but no file number") ||
3616 "unexpected token in '.file' directive") ||
3617 parseEscapedString(SourceString))
3620 return TokError(
"unexpected token in '.file' directive");
3624 if (FileNumber == -1) {
3628 if (
getContext().getAsmInfo().hasSingleParameterDotFile())
3629 getStreamer().emitFileDirective(
Filename);
3639 std::optional<MD5::MD5Result> CKMem;
3642 for (
unsigned i = 0; i != 8; ++i) {
3643 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3644 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3649 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3650 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3651 Source = StringRef(SourceBuf, SourceString.size());
3653 if (FileNumber == 0) {
3657 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3659 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3660 FileNumber, Directory,
Filename, CKMem, Source);
3667 ReportedInconsistentMD5 =
true;
3668 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3677bool AsmParser::parseDirectiveLine() {
3689bool AsmParser::parseDirectiveLoc() {
3690 int64_t FileNumber = 0, LineNumber = 0;
3691 SMLoc Loc = getTok().getLoc();
3692 if (parseIntToken(FileNumber) ||
3694 "file number less than one in '.loc' directive") ||
3695 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3696 "unassigned file number in '.loc' directive"))
3701 LineNumber = getTok().getIntVal();
3703 return TokError(
"line number less than zero in '.loc' directive");
3707 int64_t ColumnPos = 0;
3709 ColumnPos = getTok().getIntVal();
3711 return TokError(
"column position less than zero in '.loc' directive");
3715 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3720 auto parseLocOp = [&]() ->
bool {
3722 SMLoc Loc = getTok().getLoc();
3723 if (parseIdentifier(Name))
3724 return TokError(
"unexpected token in '.loc' directive");
3726 if (Name ==
"basic_block")
3728 else if (Name ==
"prologue_end")
3730 else if (Name ==
"epilogue_begin")
3732 else if (Name ==
"is_stmt") {
3733 Loc = getTok().getLoc();
3734 const MCExpr *
Value;
3735 if (parseExpression(
Value))
3739 int Value = MCE->getValue();
3741 Flags &= ~DWARF2_FLAG_IS_STMT;
3742 else if (
Value == 1)
3745 return Error(Loc,
"is_stmt value not 0 or 1");
3747 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3749 }
else if (Name ==
"isa") {
3750 Loc = getTok().getLoc();
3751 const MCExpr *
Value;
3752 if (parseExpression(
Value))
3756 int Value = MCE->getValue();
3758 return Error(Loc,
"isa number less than zero");
3761 return Error(Loc,
"isa number not a constant value");
3763 }
else if (Name ==
"discriminator") {
3764 if (parseAbsoluteExpression(Discriminator))
3767 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3772 if (parseMany(parseLocOp,
false ))
3775 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3776 Isa, Discriminator, StringRef());
3783bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3785 DirectiveLoc = Lexer.
getLoc();
3786 if (parseIdentifier(Name))
3787 return TokError(
"expected identifier");
3790 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3796bool AsmParser::parseDirectiveStabs() {
3797 return TokError(
"unsupported directive '.stabs'");
3802bool AsmParser::parseDirectiveCVFile() {
3803 SMLoc FileNumberLoc = getTok().getLoc();
3806 std::string Checksum;
3809 if (parseIntToken(FileNumber,
"expected file number") ||
3810 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3812 "unexpected token in '.cv_file' directive") ||
3817 "unexpected token in '.cv_file' directive") ||
3818 parseEscapedString(Checksum) ||
3819 parseIntToken(ChecksumKind,
3820 "expected checksum kind in '.cv_file' directive") ||
3826 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3827 memcpy(CKMem, Checksum.data(), Checksum.size());
3828 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3831 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3832 static_cast<uint8_t
>(ChecksumKind)))
3833 return Error(FileNumberLoc,
"file number already allocated");
3838bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3839 StringRef DirectiveName) {
3841 return parseTokenLoc(Loc) ||
3842 parseIntToken(FunctionId,
"expected function id") ||
3843 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3844 "expected function id within range [0, UINT_MAX)");
3847bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3849 return parseTokenLoc(Loc) ||
3850 parseIntToken(FileNumber,
"expected file number") ||
3851 check(FileNumber < 1, Loc,
3852 "file number less than one in '" + DirectiveName +
3854 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3855 "unassigned file number in '" + DirectiveName +
"' directive");
3862bool AsmParser::parseDirectiveCVFuncId() {
3863 SMLoc FunctionIdLoc = getTok().getLoc();
3866 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3869 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3870 return Error(FunctionIdLoc,
"function id already allocated");
3883bool AsmParser::parseDirectiveCVInlineSiteId() {
3884 SMLoc FunctionIdLoc = getTok().getLoc();
3892 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3897 getTok().getIdentifier() !=
"within"),
3898 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3903 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3908 getTok().getIdentifier() !=
"inlined_at"),
3909 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3915 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3916 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3921 IACol = getTok().getIntVal();
3928 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3929 IALine, IACol, FunctionIdLoc))
3930 return Error(FunctionIdLoc,
"function id already allocated");
3942bool AsmParser::parseDirectiveCVLoc() {
3943 SMLoc DirectiveLoc = getTok().getLoc();
3944 int64_t FunctionId, FileNumber;
3945 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3946 parseCVFileId(FileNumber,
".cv_loc"))
3949 int64_t LineNumber = 0;
3951 LineNumber = getTok().getIntVal();
3953 return TokError(
"line number less than zero in '.cv_loc' directive");
3957 int64_t ColumnPos = 0;
3959 ColumnPos = getTok().getIntVal();
3961 return TokError(
"column position less than zero in '.cv_loc' directive");
3965 bool PrologueEnd =
false;
3968 auto parseOp = [&]() ->
bool {
3970 SMLoc Loc = getTok().getLoc();
3971 if (parseIdentifier(Name))
3972 return TokError(
"unexpected token in '.cv_loc' directive");
3973 if (Name ==
"prologue_end")
3975 else if (Name ==
"is_stmt") {
3976 Loc = getTok().getLoc();
3977 const MCExpr *
Value;
3978 if (parseExpression(
Value))
3983 IsStmt = MCE->getValue();
3986 return Error(Loc,
"is_stmt value not 0 or 1");
3988 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3993 if (parseMany(parseOp,
false ))
3996 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3997 ColumnPos, PrologueEnd, IsStmt, StringRef(),
4004bool AsmParser::parseDirectiveCVLinetable() {
4007 SMLoc Loc = getTok().getLoc();
4008 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
4009 parseTokenLoc(Loc) ||
4010 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
4011 parseComma() || parseTokenLoc(Loc) ||
4012 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
4015 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
4021bool AsmParser::parseDirectiveCVInlineLinetable() {
4022 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
4024 SMLoc Loc = getTok().getLoc();
4025 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
4026 parseTokenLoc(Loc) ||
4027 parseIntToken(SourceFileId,
"expected SourceField") ||
4028 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
4029 parseTokenLoc(Loc) ||
4030 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
4031 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
4032 parseTokenLoc(Loc) ||
4033 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
4034 parseTokenLoc(Loc) ||
4035 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
4041 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
4042 SourceLineNum, FnStartSym,
4047void AsmParser::initializeCVDefRangeTypeMap() {
4048 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
4049 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
4050 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4051 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4052 CVDefRangeTypeMap[
"reg_rel_indir"] = CVDR_DEFRANGE_REGISTER_REL_INDIR;
4057bool AsmParser::parseDirectiveCVDefRange() {
4059 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
4061 Loc = getLexer().getLoc();
4064 return Error(Loc,
"expected identifier in directive");
4066 Loc = getLexer().getLoc();
4069 return Error(Loc,
"expected identifier in directive");
4071 Ranges.push_back({GapStartSym, GapEndSym});
4074 StringRef CVDefRangeTypeStr;
4077 "expected comma before def_range type in .cv_def_range directive") ||
4078 parseIdentifier(CVDefRangeTypeStr))
4079 return Error(Loc,
"expected def_range type in directive");
4082 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4083 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4085 : CVTypeIt->getValue();
4087 case CVDR_DEFRANGE_REGISTER: {
4089 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4090 ".cv_def_range directive") ||
4091 parseAbsoluteExpression(DRRegister))
4092 return Error(Loc,
"expected register number");
4094 codeview::DefRangeRegisterHeader DRHdr;
4097 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4100 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4103 "expected comma before offset in .cv_def_range directive") ||
4104 parseAbsoluteExpression(DROffset))
4105 return Error(Loc,
"expected offset value");
4107 codeview::DefRangeFramePointerRelHeader DRHdr;
4109 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4112 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4114 int64_t DROffsetInParent;
4115 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4116 ".cv_def_range directive") ||
4117 parseAbsoluteExpression(DRRegister))
4118 return Error(Loc,
"expected register number");
4120 "expected comma before offset in .cv_def_range directive") ||
4121 parseAbsoluteExpression(DROffsetInParent))
4122 return Error(Loc,
"expected offset value");
4124 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4128 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4131 case CVDR_DEFRANGE_REGISTER_REL: {
4134 int64_t DRBasePointerOffset;
4135 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4136 ".cv_def_range directive") ||
4137 parseAbsoluteExpression(DRRegister))
4138 return Error(Loc,
"expected register value");
4141 "expected comma before flag value in .cv_def_range directive") ||
4142 parseAbsoluteExpression(DRFlags))
4143 return Error(Loc,
"expected flag value");
4144 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4145 "in .cv_def_range directive") ||
4146 parseAbsoluteExpression(DRBasePointerOffset))
4147 return Error(Loc,
"expected base pointer offset value");
4149 codeview::DefRangeRegisterRelHeader DRHdr;
4151 DRHdr.
Flags = DRFlags;
4153 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4156 case CVDR_DEFRANGE_REGISTER_REL_INDIR: {
4159 int64_t DRBasePointerOffset;
4160 int64_t DROffsetInUdt;
4161 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4162 ".cv_def_range directive") ||
4163 parseAbsoluteExpression(DRRegister))
4164 return Error(Loc,
"expected register value");
4167 "expected comma before flag value in .cv_def_range directive") ||
4168 parseAbsoluteExpression(DRFlags))
4169 return Error(Loc,
"expected flag value");
4170 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4171 "in .cv_def_range directive") ||
4172 parseAbsoluteExpression(DRBasePointerOffset))
4173 return Error(Loc,
"expected base pointer offset value");
4174 if (parseToken(
AsmToken::Comma,
"expected comma before offset in UDT "
4175 "in .cv_def_range directive") ||
4176 parseAbsoluteExpression(DROffsetInUdt))
4177 return Error(Loc,
"expected offset in UDT value");
4179 codeview::DefRangeRegisterRelIndirHeader DRHdr;
4181 DRHdr.
Flags = DRFlags;
4184 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4188 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4195bool AsmParser::parseDirectiveCVString() {
4197 if (checkForValidSection() || parseEscapedString(
Data))
4201 std::pair<StringRef, unsigned> Insertion =
4202 getCVContext().addToStringTable(
Data);
4203 getStreamer().emitInt32(Insertion.second);
4209bool AsmParser::parseDirectiveCVStringTable() {
4210 getStreamer().emitCVStringTableDirective();
4216bool AsmParser::parseDirectiveCVFileChecksums() {
4217 getStreamer().emitCVFileChecksumsDirective();
4223bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4225 if (parseIntToken(FileNo))
4229 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4235bool AsmParser::parseDirectiveCVFPOData() {
4236 SMLoc DirLoc = getLexer().getLoc();
4239 return TokError(
"expected symbol name");
4242 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4248bool AsmParser::parseDirectiveCFISections() {
4252 bool SFrame =
false;
4256 if (parseIdentifier(Name))
4257 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4258 if (Name ==
".eh_frame")
4260 else if (Name ==
".debug_frame")
4262 else if (Name ==
".sframe")
4270 getStreamer().emitCFISections(EH,
Debug, SFrame);
4276bool AsmParser::parseDirectiveCFIStartProc() {
4277 CFIStartProcLoc = StartTokLoc;
4281 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4282 "unexpected token") ||
4292 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4298bool AsmParser::parseDirectiveCFIEndProc() {
4299 CFIStartProcLoc = std::nullopt;
4304 getStreamer().emitCFIEndProc();
4309bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4310 SMLoc DirectiveLoc) {
4314 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4318 return parseAbsoluteExpression(
Register);
4325bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4327 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4328 parseAbsoluteExpression(
Offset) || parseEOL())
4337bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4339 if (parseAbsoluteExpression(
Offset) || parseEOL())
4342 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4348bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4349 int64_t Register1 = 0, Register2 = 0;
4350 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4351 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4354 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4360bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4363 getStreamer().emitCFIWindowSave(DirectiveLoc);
4369bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4370 int64_t Adjustment = 0;
4371 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4374 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4380bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4382 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4385 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4391bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4393 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4394 parseAbsoluteExpression(
Offset) || parseComma() ||
4405bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4409 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4410 parseAbsoluteExpression(
Offset) || parseEOL())
4419bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4422 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4423 parseAbsoluteExpression(
Offset) || parseEOL())
4431 if (Encoding & ~0xff)
4437 const unsigned Format = Encoding & 0xf;
4444 const unsigned Application = Encoding & 0x70;
4456bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4457 int64_t Encoding = 0;
4458 if (parseAbsoluteExpression(Encoding))
4466 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4470 getStreamer().emitCFIPersonality(Sym, Encoding);
4472 getStreamer().emitCFILsda(Sym, Encoding);
4478bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4481 getStreamer().emitCFIRememberState(DirectiveLoc);
4487bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4490 getStreamer().emitCFIRestoreState(DirectiveLoc);
4496bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4499 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4502 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4508bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4510 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4513 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4519bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4522 if (parseAbsoluteExpression(CurrValue))
4525 Values.push_back((uint8_t)CurrValue);
4530 if (parseAbsoluteExpression(CurrValue))
4533 Values.push_back((uint8_t)CurrValue);
4536 getStreamer().emitCFIEscape(
Values, DirectiveLoc);
4542bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4544 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4546 getStreamer().emitCFIReturnColumn(
Register);
4552bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4556 getStreamer().emitCFISignalFrame();
4562bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4565 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4568 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4574bool AsmParser::parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc) {
4576 int64_t R1 = 0,
R2 = 0;
4577 int64_t R1Size = 0, R2Size = 0;
4579 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4580 parseRegisterOrRegisterNumber(R1, DirectiveLoc) || parseComma() ||
4581 parseAbsoluteExpression(R1Size) || parseComma() ||
4582 parseRegisterOrRegisterNumber(
R2, DirectiveLoc) || parseComma() ||
4583 parseAbsoluteExpression(R2Size) || parseEOL())
4586 getStreamer().emitCFILLVMRegisterPair(
Register, R1, R1Size,
R2, R2Size,
4593bool AsmParser::parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc) {
4595 std::vector<MCCFIInstruction::VectorRegisterWithLane> VRs;
4597 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma())
4601 int64_t VectorRegister = 0;
4604 if (parseRegisterOrRegisterNumber(VectorRegister, DirectiveLoc) ||
4605 parseComma() || parseIntToken(Lane,
"expected a lane number") ||
4606 parseComma() || parseAbsoluteExpression(
Size))
4608 VRs.push_back({unsigned(VectorRegister), unsigned(Lane), unsigned(
Size)});
4614 getStreamer().emitCFILLVMVectorRegisters(
Register, std::move(VRs),
4621bool AsmParser::parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc) {
4622 int64_t
Register = 0, MaskRegister = 0;
4623 int64_t RegisterSize = 0, MaskRegisterSize = 0;
4626 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4627 parseAbsoluteExpression(RegisterSize) || parseComma() ||
4628 parseRegisterOrRegisterNumber(MaskRegister, DirectiveLoc) ||
4629 parseComma() || parseAbsoluteExpression(MaskRegisterSize) ||
4630 parseComma() || parseAbsoluteExpression(
Offset) || parseEOL())
4633 getStreamer().emitCFILLVMVectorOffset(
Register, RegisterSize, MaskRegister,
4634 MaskRegisterSize,
Offset, DirectiveLoc);
4641bool AsmParser::parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc) {
4642 int64_t
Register = 0, SpillReg = 0, MaskReg = 0;
4643 int64_t SpillRegLaneSize = 0, MaskRegSize = 0;
4645 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4646 parseRegisterOrRegisterNumber(SpillReg, DirectiveLoc) || parseComma() ||
4647 parseAbsoluteExpression(SpillRegLaneSize) || parseComma() ||
4648 parseRegisterOrRegisterNumber(MaskReg, DirectiveLoc) || parseComma() ||
4649 parseAbsoluteExpression(MaskRegSize) || parseEOL())
4652 getStreamer().emitCFILLVMVectorRegisterMask(
4653 Register, SpillReg, SpillRegLaneSize, MaskReg, MaskRegSize, DirectiveLoc);
4659bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4662 if (parseIdentifier(Name))
4663 return TokError(
"expected identifier");
4666 getStreamer().emitCFILabelDirective(Loc, Name);
4672bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4676 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4677 parseAbsoluteExpression(
Offset) || parseEOL())
4687bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4690 AltMacroMode = (Directive ==
".altmacro");
4697bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4700 setMacrosEnabled(Directive ==
".macros_on");
4706bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4708 if (parseIdentifier(Name))
4709 return TokError(
"expected identifier in '.macro' directive");
4718 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4720 "' should be the last parameter");
4724 return TokError(
"expected identifier in '.macro' directive");
4727 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4729 return TokError(
"macro '" + Name +
"' has multiple parameters"
4738 QualLoc = Lexer.
getLoc();
4739 if (parseIdentifier(Qualifier))
4740 return Error(QualLoc,
"missing parameter qualifier for "
4741 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4743 if (Qualifier ==
"req")
4745 else if (Qualifier ==
"vararg")
4748 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4749 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4757 ParamLoc = Lexer.
getLoc();
4758 if (parseMacroArgument(
Parameter.Value,
false ))
4762 Warning(ParamLoc,
"pointless default value for required parameter "
4763 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4776 AsmToken EndToken, StartToken = getTok();
4777 unsigned MacroDepth = 0;
4787 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4792 if (getTok().getIdentifier() ==
".endm" ||
4793 getTok().getIdentifier() ==
".endmacro") {
4794 if (MacroDepth == 0) {
4795 EndToken = getTok();
4798 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4805 }
else if (getTok().getIdentifier() ==
".macro") {
4811 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4815 eatToEndOfStatement();
4819 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4824 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4825 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4826 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4847void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4853 if (NParameters == 0)
4856 bool NamedParametersFound =
false;
4857 bool PositionalParametersFound =
false;
4862 while (!Body.
empty()) {
4864 std::size_t
End = Body.
size(), Pos = 0;
4865 for (; Pos !=
End; ++Pos) {
4868 if (Body[Pos] ==
'\\' && Pos + 1 !=
End)
4872 if (Body[Pos] !=
'$' || Pos + 1 ==
End)
4874 char Next = Body[Pos + 1];
4876 isdigit(
static_cast<unsigned char>(
Next)))
4884 if (Body[Pos] ==
'$') {
4885 switch (Body[Pos + 1]) {
4892 PositionalParametersFound =
true;
4897 PositionalParametersFound =
true;
4907 const char *Begin = Body.
data() + Pos + 1;
4908 StringRef
Argument(Begin,
I - (Pos + 1));
4911 if (Parameters[Index].Name == Argument)
4914 if (Index == NParameters) {
4915 if (Body[Pos + 1] ==
'(' && Pos + 2 !=
End && Body[Pos + 2] ==
')')
4921 NamedParametersFound =
true;
4929 if (!NamedParametersFound && PositionalParametersFound)
4930 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4931 "used in macro body, possible positional parameter "
4932 "found in body which will have no effect");
4937bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4941 if (!isInsideMacroInstantiation())
4942 return TokError(
"unexpected '" + Directive +
"' in file, "
4943 "no current macro definition");
4946 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4947 TheCondState = TheCondStack.back();
4948 TheCondStack.pop_back();
4958bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4960 return TokError(
"unexpected token in '" + Directive +
"' directive");
4964 if (isInsideMacroInstantiation()) {
4971 return TokError(
"unexpected '" + Directive +
"' in file, "
4972 "no current macro definition");
4977bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4980 if (parseTokenLoc(Loc) ||
4981 check(parseIdentifier(Name), Loc,
4982 "expected identifier in '.purgem' directive") ||
4987 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4991 <<
"Un-defining macro: " << Name <<
"\n");
4997bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4998 SMLoc NumBytesLoc = Lexer.
getLoc();
4999 const MCExpr *NumBytes;
5000 if (checkForValidSection() || parseExpression(NumBytes))
5003 int64_t FillExpr = 0;
5005 if (parseAbsoluteExpression(FillExpr))
5011 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
5018bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
5019 SMLoc NumValuesLoc = Lexer.
getLoc();
5021 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5024 if (NumValues < 0) {
5025 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5032 const MCExpr *
Value;
5033 SMLoc ExprLoc = getLexer().getLoc();
5034 if (parseExpression(
Value))
5040 uint64_t IntValue = MCE->getValue();
5042 return Error(ExprLoc,
"literal value out of range for directive");
5043 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5044 getStreamer().emitIntValue(IntValue,
Size);
5046 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5047 getStreamer().emitValue(
Value,
Size, ExprLoc);
5055bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
5056 SMLoc NumValuesLoc = Lexer.
getLoc();
5058 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5061 if (NumValues < 0) {
5062 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5070 if (parseRealValue(Semantics, AsInt) || parseEOL())
5073 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5082bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
5083 SMLoc NumValuesLoc = Lexer.
getLoc();
5085 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
5089 if (NumValues < 0) {
5090 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5094 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5095 getStreamer().emitFill(
Size, 0);
5102bool AsmParser::parseDirectiveLEB128(
bool Signed) {
5103 if (checkForValidSection())
5106 auto parseOp = [&]() ->
bool {
5107 const MCExpr *
Value;
5108 if (parseExpression(
Value))
5111 getStreamer().emitSLEB128Value(
Value);
5113 getStreamer().emitULEB128Value(
Value);
5117 return parseMany(parseOp);
5122bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
5123 auto parseOp = [&]() ->
bool {
5125 SMLoc Loc = getTok().getLoc();
5126 if (parseIdentifier(Name))
5127 return Error(Loc,
"expected identifier");
5129 if (discardLTOSymbol(Name))
5137 return Error(Loc,
"non-local symbol required");
5139 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
5140 return Error(Loc,
"unable to emit symbol attribute");
5144 return parseMany(parseOp);
5149bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5150 if (checkForValidSection())
5153 SMLoc IDLoc = getLexer().getLoc();
5156 return TokError(
"expected identifier in directive");
5162 SMLoc SizeLoc = getLexer().getLoc();
5163 if (parseAbsoluteExpression(
Size))
5166 int64_t Pow2Alignment = 0;
5167 SMLoc Pow2AlignmentLoc;
5170 Pow2AlignmentLoc = getLexer().getLoc();
5171 if (parseAbsoluteExpression(Pow2Alignment))
5176 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5182 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5183 Pow2Alignment =
Log2_64(Pow2Alignment);
5184 }
else if (Pow2Alignment < 0 || Pow2Alignment > 63) {
5185 return Error(Pow2AlignmentLoc,
5186 "log2 alignment must be in the range [0, 63]");
5196 return Error(SizeLoc,
"size must be non-negative");
5200 return Error(IDLoc,
"invalid symbol redefinition");
5204 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5215bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5216 StringRef Str = parseStringToEndOfStatement();
5221 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5224 return Error(DirectiveLoc,
5225 ".abort '" + Str +
"' detected. Assembly stopping");
5230bool AsmParser::parseDirectiveInclude() {
5233 SMLoc IncludeLoc = getTok().getLoc();
5236 "expected string in '.include' directive") ||
5239 "unexpected token in '.include' directive") ||
5242 check(enterIncludeFile(
Filename), IncludeLoc,
5243 "Could not find include file '" +
Filename +
"'"))
5251bool AsmParser::parseDirectiveIncbin() {
5254 SMLoc IncbinLoc = getTok().getLoc();
5256 "expected string in '.incbin' directive") ||
5261 const MCExpr *
Count =
nullptr;
5262 SMLoc SkipLoc, CountLoc;
5267 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5271 CountLoc = getTok().getLoc();
5272 if (parseExpression(
Count))
5280 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5285 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5291bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5292 TheCondStack.push_back(TheCondState);
5294 if (TheCondState.
Ignore) {
5295 eatToEndOfStatement();
5298 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5308 ExprValue = ExprValue == 0;
5311 ExprValue = ExprValue >= 0;
5314 ExprValue = ExprValue > 0;
5317 ExprValue = ExprValue <= 0;
5320 ExprValue = ExprValue < 0;
5324 TheCondState.
CondMet = ExprValue;
5333bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5334 TheCondStack.push_back(TheCondState);
5337 if (TheCondState.
Ignore) {
5338 eatToEndOfStatement();
5340 StringRef Str = parseStringToEndOfStatement();
5345 TheCondState.
CondMet = ExpectBlank == Str.empty();
5355bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5356 TheCondStack.push_back(TheCondState);
5359 if (TheCondState.
Ignore) {
5360 eatToEndOfStatement();
5362 StringRef Str1 = parseStringToComma();
5367 StringRef Str2 = parseStringToEndOfStatement();
5381bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5382 TheCondStack.push_back(TheCondState);
5385 if (TheCondState.
Ignore) {
5386 eatToEndOfStatement();
5390 return TokError(
"expected string parameter for '.ifeqs' directive");
5391 return TokError(
"expected string parameter for '.ifnes' directive");
5394 StringRef String1 = getTok().getStringContents();
5400 "expected comma after first string for '.ifeqs' directive");
5402 "expected comma after first string for '.ifnes' directive");
5409 return TokError(
"expected string parameter for '.ifeqs' directive");
5410 return TokError(
"expected string parameter for '.ifnes' directive");
5413 StringRef String2 = getTok().getStringContents();
5416 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5425bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5427 TheCondStack.push_back(TheCondState);
5430 if (TheCondState.
Ignore) {
5431 eatToEndOfStatement();
5433 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5451bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5454 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5455 " .if or an .elseif");
5458 bool LastIgnoreState =
false;
5459 if (!TheCondStack.empty())
5460 LastIgnoreState = TheCondStack.back().Ignore;
5461 if (LastIgnoreState || TheCondState.
CondMet) {
5462 TheCondState.
Ignore =
true;
5463 eatToEndOfStatement();
5466 if (parseAbsoluteExpression(ExprValue))
5472 TheCondState.
CondMet = ExprValue;
5481bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5487 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5488 " an .if or an .elseif");
5490 bool LastIgnoreState =
false;
5491 if (!TheCondStack.empty())
5492 LastIgnoreState = TheCondStack.back().Ignore;
5493 if (LastIgnoreState || TheCondState.
CondMet)
5494 TheCondState.
Ignore =
true;
5496 TheCondState.
Ignore =
false;
5503bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5516bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5517 if (!TheCondStack.empty()) {
5518 if (TheCondStack.back().Ignore) {
5519 eatToEndOfStatement();
5525 return Error(L,
".err encountered");
5527 StringRef Message =
".error directive invoked in source file";
5530 return TokError(
".error argument must be a string");
5532 Message = getTok().getStringContents();
5536 return Error(L, Message);
5541bool AsmParser::parseDirectiveWarning(SMLoc L) {
5542 if (!TheCondStack.empty()) {
5543 if (TheCondStack.back().Ignore) {
5544 eatToEndOfStatement();
5549 StringRef Message =
".warning directive invoked in source file";
5553 return TokError(
".warning argument must be a string");
5555 Message = getTok().getStringContents();
5566bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5571 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5573 if (!TheCondStack.empty()) {
5574 TheCondState = TheCondStack.back();
5575 TheCondStack.pop_back();
5581void AsmParser::initializeDirectiveKindMap() {
5588 DirectiveKindMap[
".set"] = DK_SET;
5589 DirectiveKindMap[
".equ"] = DK_EQU;
5590 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5591 DirectiveKindMap[
".ascii"] = DK_ASCII;
5592 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5593 DirectiveKindMap[
".string"] = DK_STRING;
5594 DirectiveKindMap[
".byte"] = DK_BYTE;
5595 DirectiveKindMap[
".base64"] = DK_BASE64;
5596 DirectiveKindMap[
".short"] = DK_SHORT;
5597 DirectiveKindMap[
".value"] = DK_VALUE;
5598 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5599 DirectiveKindMap[
".long"] = DK_LONG;
5600 DirectiveKindMap[
".int"] = DK_INT;
5601 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5602 DirectiveKindMap[
".quad"] = DK_QUAD;
5603 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5604 DirectiveKindMap[
".octa"] = DK_OCTA;
5605 DirectiveKindMap[
".single"] = DK_SINGLE;
5606 DirectiveKindMap[
".float"] = DK_FLOAT;
5607 DirectiveKindMap[
".double"] = DK_DOUBLE;
5608 DirectiveKindMap[
".align"] = DK_ALIGN;
5609 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5610 DirectiveKindMap[
".balign"] = DK_BALIGN;
5611 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5612 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5613 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5614 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5615 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5616 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5617 DirectiveKindMap[
".org"] = DK_ORG;
5618 DirectiveKindMap[
".fill"] = DK_FILL;
5619 DirectiveKindMap[
".zero"] = DK_ZERO;
5620 DirectiveKindMap[
".extern"] = DK_EXTERN;
5621 DirectiveKindMap[
".globl"] = DK_GLOBL;
5622 DirectiveKindMap[
".global"] = DK_GLOBAL;
5623 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5624 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5625 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5626 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5627 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5628 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5629 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5630 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5631 DirectiveKindMap[
".cold"] = DK_COLD;
5632 DirectiveKindMap[
".comm"] = DK_COMM;
5633 DirectiveKindMap[
".common"] = DK_COMMON;
5634 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5635 DirectiveKindMap[
".abort"] = DK_ABORT;
5636 DirectiveKindMap[
".include"] = DK_INCLUDE;
5637 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5638 DirectiveKindMap[
".code16"] = DK_CODE16;
5639 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5640 DirectiveKindMap[
".rept"] = DK_REPT;
5641 DirectiveKindMap[
".rep"] = DK_REPT;
5642 DirectiveKindMap[
".irp"] = DK_IRP;
5643 DirectiveKindMap[
".irpc"] = DK_IRPC;
5644 DirectiveKindMap[
".endr"] = DK_ENDR;
5645 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5646 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5647 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5648 DirectiveKindMap[
".if"] = DK_IF;
5649 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5650 DirectiveKindMap[
".ifge"] = DK_IFGE;
5651 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5652 DirectiveKindMap[
".ifle"] = DK_IFLE;
5653 DirectiveKindMap[
".iflt"] = DK_IFLT;
5654 DirectiveKindMap[
".ifne"] = DK_IFNE;
5655 DirectiveKindMap[
".ifb"] = DK_IFB;
5656 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5657 DirectiveKindMap[
".ifc"] = DK_IFC;
5658 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5659 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5660 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5661 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5662 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5663 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5664 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5665 DirectiveKindMap[
".else"] = DK_ELSE;
5666 DirectiveKindMap[
".end"] = DK_END;
5667 DirectiveKindMap[
".endif"] = DK_ENDIF;
5668 DirectiveKindMap[
".skip"] = DK_SKIP;
5669 DirectiveKindMap[
".space"] = DK_SPACE;
5670 DirectiveKindMap[
".file"] = DK_FILE;
5671 DirectiveKindMap[
".line"] = DK_LINE;
5672 DirectiveKindMap[
".loc"] = DK_LOC;
5673 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5674 DirectiveKindMap[
".stabs"] = DK_STABS;
5675 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5676 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5677 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5678 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5679 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5680 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5681 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5682 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5683 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5684 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5685 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5686 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5687 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5688 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5689 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5690 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5691 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5692 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5693 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5694 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5695 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5696 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5697 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5698 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5699 DirectiveKindMap[
".cfi_llvm_register_pair"] = DK_CFI_LLVM_REGISTER_PAIR;
5700 DirectiveKindMap[
".cfi_llvm_vector_registers"] = DK_CFI_LLVM_VECTOR_REGISTERS;
5701 DirectiveKindMap[
".cfi_llvm_vector_offset"] = DK_CFI_LLVM_VECTOR_OFFSET;
5702 DirectiveKindMap[
".cfi_llvm_vector_register_mask"] =
5703 DK_CFI_LLVM_VECTOR_REGISTER_MASK;
5704 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5705 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5706 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5707 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5708 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5709 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5710 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5711 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5712 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5713 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5714 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5715 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5716 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5717 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5718 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5719 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5720 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5721 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5722 DirectiveKindMap[
".macro"] = DK_MACRO;
5723 DirectiveKindMap[
".exitm"] = DK_EXITM;
5724 DirectiveKindMap[
".endm"] = DK_ENDM;
5725 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5726 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5727 DirectiveKindMap[
".err"] = DK_ERR;
5728 DirectiveKindMap[
".error"] = DK_ERROR;
5729 DirectiveKindMap[
".warning"] = DK_WARNING;
5730 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5731 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5732 DirectiveKindMap[
".reloc"] = DK_RELOC;
5733 DirectiveKindMap[
".dc"] = DK_DC;
5734 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5735 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5736 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5737 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5738 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5739 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5740 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5741 DirectiveKindMap[
".dcb"] = DK_DCB;
5742 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5743 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5744 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5745 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5746 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5747 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5748 DirectiveKindMap[
".ds"] = DK_DS;
5749 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5750 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5751 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5752 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5753 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5754 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5755 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5756 DirectiveKindMap[
".print"] = DK_PRINT;
5757 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5758 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5759 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5760 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5761 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5762 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5765MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5766 AsmToken EndToken, StartToken = getTok();
5768 unsigned NestLevel = 0;
5772 printError(DirectiveLoc,
"no matching '.endr' in definition");
5777 StringRef Ident = getTok().getIdentifier();
5778 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5781 }
else if (Ident ==
".endr") {
5782 if (NestLevel == 0) {
5783 EndToken = getTok();
5787 printError(getTok().getLoc(),
"expected newline");
5795 eatToEndOfStatement();
5800 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5804 return &MacroLikeBodies.back();
5807void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5808 raw_svector_ostream &OS) {
5811 std::unique_ptr<MemoryBuffer> Instantiation =
5816 MacroInstantiation *
MI =
new MacroInstantiation{
5817 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5818 ActiveMacros.push_back(
MI);
5828bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5829 const MCExpr *CountExpr;
5830 SMLoc CountLoc = getTok().getLoc();
5831 if (parseExpression(CountExpr))
5835 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5836 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5839 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5843 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5849 SmallString<256> Buf;
5850 raw_svector_ostream OS(Buf);
5853 if (expandMacro(OS, *M, {}, {},
false))
5856 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5863bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5865 MCAsmMacroArguments
A;
5866 if (check(parseIdentifier(
Parameter.Name),
5867 "expected identifier in '.irp' directive") ||
5868 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5872 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5878 SmallString<256> Buf;
5879 raw_svector_ostream OS(Buf);
5881 for (
const MCAsmMacroArgument &Arg :
A) {
5884 if (expandMacro(OS, *M, Parameter, Arg,
true))
5888 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5895bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5897 MCAsmMacroArguments
A;
5899 if (check(parseIdentifier(
Parameter.Name),
5900 "expected identifier in '.irpc' directive") ||
5901 parseComma() || parseMacroArguments(
nullptr,
A))
5904 if (
A.size() != 1 ||
A.front().size() != 1)
5905 return TokError(
"unexpected token in '.irpc' directive");
5910 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5916 SmallString<256> Buf;
5917 raw_svector_ostream OS(Buf);
5920 :
A[0][0].getString();
5922 MCAsmMacroArgument Arg;
5927 if (expandMacro(OS, *M, Parameter, Arg,
true))
5931 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5936bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5937 if (ActiveMacros.empty())
5938 return TokError(
"unmatched '.endr' directive");
5948bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
5950 const MCExpr *
Value;
5951 SMLoc ExprLoc = getLexer().getLoc();
5952 if (parseExpression(
Value))
5956 return Error(ExprLoc,
"unexpected expression in _emit");
5959 return Error(ExprLoc,
"literal value out of range for directive");
5965bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
5966 const MCExpr *
Value;
5967 SMLoc ExprLoc = getLexer().getLoc();
5968 if (parseExpression(
Value))
5972 return Error(ExprLoc,
"unexpected expression in align");
5975 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5981bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5982 const AsmToken StrTok = getTok();
5985 return Error(DirectiveLoc,
"expected double quoted string after .print");
5992bool AsmParser::parseDirectiveAddrsig() {
5995 getStreamer().emitAddrsig();
5999bool AsmParser::parseDirectiveAddrsigSym() {
6001 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
6003 getStreamer().emitAddrsigSym(Sym);
6009bool AsmParser::parseDirectiveBundleAlignMode() {
6013 SMLoc ExprLoc = getLexer().getLoc();
6014 int64_t AlignSizePow2;
6015 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
6017 check(AlignSizePow2 < 1 || AlignSizePow2 > 30, ExprLoc,
6018 "invalid bundle alignment size (expected between 1 and 30)"))
6027bool AsmParser::parseDirectiveBundleLock() {
6028 if (checkForValidSection())
6030 bool AlignToEnd =
false;
6033 SMLoc Loc = getTok().getLoc();
6034 const char *InvalidOptionError =
"invalid option for `.bundle_lock`";
6037 if (check(parseIdentifier(Option), Loc, InvalidOptionError) ||
6038 check(Option !=
"align_to_end", Loc, InvalidOptionError) || parseEOL())
6043 getStreamer().emitBundleLock(AlignToEnd, getTargetParser().getSTI());
6049bool AsmParser::parseDirectiveBundleUnlock() {
6050 if (checkForValidSection() || parseEOL())
6053 getStreamer().emitBundleUnlock(getTargetParser().getSTI());
6057bool AsmParser::parseDirectivePseudoProbe() {
6063 if (parseIntToken(
Guid))
6065 if (parseIntToken(Index))
6067 if (parseIntToken(
Type))
6069 if (parseIntToken(Attr))
6081 int64_t CallerGuid = 0;
6083 CallerGuid = getTok().getIntVal();
6091 int64_t CallerProbeId = 0;
6093 CallerProbeId = getTok().getIntVal();
6103 if (parseIdentifier(FnName))
6104 return Error(getLexer().getLoc(),
"expected identifier");
6110 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
6111 InlineStack, FnSym);
6120bool AsmParser::parseDirectiveLTODiscard() {
6121 auto ParseOp = [&]() ->
bool {
6123 SMLoc Loc = getTok().getLoc();
6124 if (parseIdentifier(Name))
6125 return Error(Loc,
"expected identifier");
6126 LTODiscardSymbols.
insert(Name);
6130 LTODiscardSymbols.
clear();
6131 return parseMany(ParseOp);
6157bool AsmParser::parseMSInlineAsm(
6158 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
6159 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
6160 SmallVectorImpl<std::string> &Constraints,
6161 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
6162 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
6163 SmallVector<void *, 4> InputDecls;
6164 SmallVector<void *, 4> OutputDecls;
6165 SmallVector<bool, 4> InputDeclsAddressOf;
6166 SmallVector<bool, 4> OutputDeclsAddressOf;
6167 SmallVector<std::string, 4> InputConstraints;
6168 SmallVector<std::string, 4> OutputConstraints;
6177 unsigned InputIdx = 0;
6178 unsigned OutputIdx = 0;
6181 if (parseCurlyBlockScope(AsmStrRewrites))
6184 ParseStatementInfo
Info(&AsmStrRewrites);
6185 bool StatementErr = parseStatement(Info, &SI);
6187 if (StatementErr ||
Info.ParseError) {
6189 printPendingErrors();
6194 assert(!hasPendingError() &&
"unexpected error from parseStatement");
6196 if (
Info.Opcode == ~0U)
6202 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
6203 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
6207 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
6208 unsigned NumDefs =
Desc.getNumDefs();
6217 if (SymName.
empty())
6225 if (Operand.
isImm()) {
6233 bool isOutput = (i == 1) &&
Desc.mayStore();
6240 OutputConstraints.
push_back((
"=" + Constraint).str());
6247 if (
Desc.operands()[i - 1].isBranchTarget())
6261 NumOutputs = OutputDecls.
size();
6262 NumInputs = InputDecls.
size();
6267 Clobbers.
assign(ClobberRegs.
size(), std::string());
6268 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6269 raw_string_ostream OS(Clobbers[
I]);
6274 if (NumOutputs || NumInputs) {
6275 unsigned NumExprs = NumOutputs + NumInputs;
6276 OpDecls.resize(NumExprs);
6277 Constraints.
resize(NumExprs);
6278 for (
unsigned i = 0; i < NumOutputs; ++i) {
6279 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6280 Constraints[i] = OutputConstraints[i];
6282 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6283 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6284 Constraints[
j] = InputConstraints[i];
6289 std::string AsmStringIR;
6290 raw_string_ostream OS(AsmStringIR);
6291 StringRef ASMString =
6293 const char *AsmStart = ASMString.
begin();
6294 const char *AsmEnd = ASMString.
end();
6296 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6297 const AsmRewrite &AR = *
I;
6304 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6307 if (
unsigned Len = Loc - AsmStart)
6308 OS << StringRef(AsmStart, Len);
6312 AsmStart = Loc + AR.
Len;
6316 unsigned AdditionalSkip = 0;
6338 size_t OffsetLen = OffsetName.
size();
6339 auto rewrite_it = std::find_if(
6340 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6341 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6342 (FusingAR.Kind == AOK_Input ||
6343 FusingAR.Kind == AOK_CallInput);
6345 if (rewrite_it == AsmStrRewrites.
end()) {
6346 OS <<
"offset " << OffsetName;
6348 OS <<
"${" << InputIdx++ <<
":P}";
6349 rewrite_it->Done =
true;
6351 OS <<
'$' << InputIdx++;
6352 rewrite_it->Done =
true;
6365 OS <<
"${" << InputIdx++ <<
":P}";
6367 OS <<
'$' << InputIdx++;
6370 OS <<
"${" << InputIdx++ <<
":P}";
6374 OS <<
"${" << OutputIdx++ <<
":P}";
6376 OS <<
'$' << OutputIdx++;
6381 case 8: OS <<
"byte ptr ";
break;
6382 case 16: OS <<
"word ptr ";
break;
6383 case 32: OS <<
"dword ptr ";
break;
6384 case 64: OS <<
"qword ptr ";
break;
6385 case 80: OS <<
"xword ptr ";
break;
6386 case 128: OS <<
"xmmword ptr ";
break;
6387 case 256: OS <<
"ymmword ptr ";
break;
6397 if (
getContext().getAsmInfo().getAlignmentIsInBytes())
6402 unsigned Val = AR.
Val;
6404 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6405 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6417 AsmStart = Loc + AR.
Len + AdditionalSkip;
6421 if (AsmStart != AsmEnd)
6422 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6424 AsmString = std::move(AsmStringIR);
6428bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6429 MCAsmParserSemaCallback *SI) {
6430 AsmToken LabelTok = getTok();
6431 SMLoc LabelLoc = LabelTok.
getLoc();
6434 if (parseIdentifier(LabelVal))
6435 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6440 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6449 return Error(LabelLoc,
6450 "Cannot have just a label for an HLASM inline asm statement");
6456 Out.emitLabel(Sym, LabelLoc);
6460 if (enabledGenDwarfForAssembly())
6467bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6468 MCAsmParserSemaCallback *SI) {
6469 AsmToken OperationEntryTok = Lexer.
getTok();
6470 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6471 StringRef OperationEntryVal;
6474 if (parseIdentifier(OperationEntryVal))
6475 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6481 return parseAndMatchAndEmitTargetInstruction(
6482 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6485bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6486 MCAsmParserSemaCallback *SI) {
6487 assert(!hasPendingError() &&
"parseStatement started with pending error");
6490 bool ShouldParseAsHLASMLabel =
false;
6499 ShouldParseAsHLASMLabel =
true;
6505 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6506 getTok().getString().
front() ==
'\n')
6521 if (getTok().getString().
front() ==
'\n' ||
6522 getTok().getString().
front() ==
'\r') {
6531 if (ShouldParseAsHLASMLabel) {
6534 if (parseAsHLASMLabel(Info, SI)) {
6537 eatToEndOfStatement();
6542 return parseAsMachineInstruction(Info, SI);
6554 return Parser.
TokError(
"missing expression");
6560 return Parser.
Error(
6561 EqualLoc,
"relocation specifier not permitted in symbol equating");
6569 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6575 }
else if (Name ==
".") {
6590 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6591 return new HLASMAsmParser(SM,
C, Out, MAI, CB);
6593 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 isMacroArgChar(char C)
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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
Promote Memory to Register
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
static StringRef getName(Value *V)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
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
static bool isIdentifierChar(char C, bool AllowAt, bool AllowHash)
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
std::optional< uint32_t > getSpecifierForName(StringRef Name) const
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
bool shouldUseLogicalShr() const
StringRef getCommentString() const
StringRef getInternalSymbolPrefix() 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
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.
const MCAsmInfo & getAsmInfo() const
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 emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc)
Emit some number of copies of Value until the byte offset Offset is reached.
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.
LLVM_ABI void printIncludeStackForDiagnostic(SMLoc Loc, raw_ostream &OS) const
Prints the include stack of a buffer unless it is a macro instantiation buffer.
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 unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
LLVM_ABI ErrorOr< std::unique_ptr< MemoryBuffer > > OpenIncludeFile(const std::string &Filename, std::string &IncludedFile, bool RequiresNullTerminator=true)
Search for a file with the specified name in the current directory or in one of the IncludeDirs,...
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
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
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
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
Get the string size.
char front() const
Get the first character in the string.
constexpr const char * data() const
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.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
LLVM_ABI 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.
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.
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.
RelativeUniformCounterPtr Values
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI SourceMgr SrcMgr
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.
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.
@ Sub
Subtraction of integers.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
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.
@ End
Run the machine verifier once, at the end of the pipeline.
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)
static constexpr Align fromLog2(unsigned Log2Value)
Returns an alignment of 1 << Log2Value bytes.
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.