80typedef std::vector<AsmToken> MCAsmMacroArgument;
81typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
85struct MacroInstantiation {
87 SMLoc InstantiationLoc;
96 size_t CondStackDepth;
99struct ParseStatementInfo {
104 unsigned Opcode = ~0
U;
107 bool ParseError =
false;
109 SmallVectorImpl<AsmRewrite> *AsmRewrites =
nullptr;
111 ParseStatementInfo() =
delete;
112 ParseStatementInfo(SmallVectorImpl<AsmRewrite> *rewrites)
113 : AsmRewrites(rewrites) {}
120 void *SavedDiagContext;
121 std::unique_ptr<MCAsmParserExtension> PlatformParser;
122 std::unique_ptr<MCAsmParserExtension> LFIParser;
124 std::optional<SMLoc> CFIStartProcLoc;
130 AsmCond TheCondState;
131 std::vector<AsmCond> TheCondStack;
136 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
139 std::vector<MacroInstantiation*> ActiveMacros;
142 std::deque<MCAsmMacro> MacroLikeBodies;
145 unsigned MacrosEnabledFlag : 1;
148 unsigned NumOfMacroInstantiations = 0;
151 struct CppHashInfoTy {
156 CppHashInfoTy() : LineNumber(0), Buf(0) {}
158 CppHashInfoTy CppHashInfo;
161 bool HadCppHashFilename =
false;
166 SmallSet<StringRef, 2> LTODiscardSymbols;
169 unsigned AssemblerDialect = ~0
U;
172 bool IsDarwin =
false;
175 bool ParsingMSInlineAsm =
false;
178 bool ReportedInconsistentMD5 =
false;
181 bool AltMacroMode =
false;
184 virtual bool parseStatement(ParseStatementInfo &Info,
185 MCAsmParserSemaCallback *SI);
190 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
191 StringRef IDVal, AsmToken ID,
197 bool enabledGenDwarfForAssembly();
200 AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
201 const MCAsmInfo &MAI,
unsigned CB);
202 AsmParser(
const AsmParser &) =
delete;
203 AsmParser &operator=(
const AsmParser &) =
delete;
204 ~AsmParser()
override;
206 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
208 void addDirectiveHandler(StringRef Directive,
209 ExtensionDirectiveHandler Handler)
override {
210 ExtensionDirectiveMap[Directive] = std::move(Handler);
213 void addAliasForDirective(StringRef Directive, StringRef Alias)
override {
214 DirectiveKindMap[Directive.
lower()] = DirectiveKindMap[Alias.
lower()];
220 CodeViewContext &getCVContext() {
return Ctx.getCVContext(); }
222 unsigned getAssemblerDialect()
override {
223 if (AssemblerDialect == ~0U)
224 return MAI.getAssemblerDialect();
226 return AssemblerDialect;
228 void setAssemblerDialect(
unsigned i)
override {
229 AssemblerDialect = i;
232 void Note(SMLoc L,
const Twine &
Msg, SMRange
Range = {})
override;
234 bool printError(SMLoc L,
const Twine &
Msg, SMRange
Range = {})
override;
236 const AsmToken &Lex()
override;
238 void setParsingMSInlineAsm(
bool V)
override {
239 ParsingMSInlineAsm =
V;
242 Lexer.setLexMasmIntegers(
V);
244 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
246 bool discardLTOSymbol(StringRef Name)
const override {
247 return LTODiscardSymbols.contains(Name);
250 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
252 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
253 SmallVectorImpl<std::string> &Constraints,
254 SmallVectorImpl<std::string> &Clobbers,
255 const MCInstrInfo *MII, MCInstPrinter *IP,
256 MCAsmParserSemaCallback &SI)
override;
258 bool parseExpression(
const MCExpr *&Res);
259 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
260 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
261 AsmTypeInfo *TypeInfo)
override;
262 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
263 bool parseAbsoluteExpression(int64_t &Res)
override;
267 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
271 bool parseIdentifier(StringRef &Res)
override;
272 void eatToEndOfStatement()
override;
274 bool checkForValidSection()
override;
279 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
280 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
282 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
284 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
289 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
292 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
295 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
301 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
304 void handleMacroExit();
307 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
310 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
312 void printMacroInstantiations();
314 SMRange
Range = {})
const {
321 bool enterIncludeFile(
const std::string &
Filename);
325 bool processIncbinFile(
const std::string &
Filename, int64_t Skip = 0,
326 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
334 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
339 StringRef parseStringToEndOfStatement()
override;
343 StringRef parseStringToComma();
345 enum class AssignmentKind {
352 bool parseAssignment(StringRef Name, AssignmentKind Kind);
357 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
358 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
359 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
361 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
363 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
364 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
424 DK_BUNDLE_ALIGN_MODE,
438 DK_WEAK_DEF_CAN_BE_HIDDEN,
479 DK_CV_INLINE_SITE_ID,
482 DK_CV_INLINE_LINETABLE,
487 DK_CV_FILECHECKSUM_OFFSET,
493 DK_CFI_DEF_CFA_OFFSET,
494 DK_CFI_ADJUST_CFA_OFFSET,
495 DK_CFI_DEF_CFA_REGISTER,
496 DK_CFI_LLVM_DEF_ASPACE_CFA,
499 DK_CFI_LLVM_REGISTER_PAIR,
500 DK_CFI_LLVM_VECTOR_REGISTERS,
501 DK_CFI_LLVM_VECTOR_OFFSET,
502 DK_CFI_LLVM_VECTOR_REGISTER_MASK,
505 DK_CFI_REMEMBER_STATE,
506 DK_CFI_RESTORE_STATE,
510 DK_CFI_RETURN_COLUMN,
537 DK_LTO_SET_CONDITIONAL,
538 DK_CFI_MTE_TAGGED_FRAME,
546 StringMap<DirectiveKind> DirectiveKindMap;
549 enum CVDefRangeType {
551 CVDR_DEFRANGE_REGISTER,
552 CVDR_DEFRANGE_FRAMEPOINTER_REL,
553 CVDR_DEFRANGE_SUBFIELD_REGISTER,
554 CVDR_DEFRANGE_REGISTER_REL,
555 CVDR_DEFRANGE_REGISTER_REL_INDIR
560 StringMap<CVDefRangeType> CVDefRangeTypeMap;
563 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
564 bool parseDirectiveBase64();
565 bool parseDirectiveReloc(SMLoc DirectiveLoc);
566 bool parseDirectiveValue(StringRef IDVal,
568 bool parseDirectiveOctaValue(StringRef IDVal);
569 bool parseDirectiveRealValue(StringRef IDVal,
570 const fltSemantics &);
571 bool parseDirectiveFill();
572 bool parseDirectiveZero();
574 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
575 bool parseDirectiveOrg();
577 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
578 bool parseDirectivePrefAlign();
581 bool parseDirectiveFile(SMLoc DirectiveLoc);
582 bool parseDirectiveLine();
583 bool parseDirectiveLoc();
584 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
585 bool parseDirectiveStabs();
589 bool parseDirectiveCVFile();
590 bool parseDirectiveCVFuncId();
591 bool parseDirectiveCVInlineSiteId();
592 bool parseDirectiveCVLoc();
593 bool parseDirectiveCVLinetable();
594 bool parseDirectiveCVInlineLinetable();
595 bool parseDirectiveCVDefRange();
596 bool parseDirectiveCVString();
597 bool parseDirectiveCVStringTable();
598 bool parseDirectiveCVFileChecksums();
599 bool parseDirectiveCVFileChecksumOffset();
600 bool parseDirectiveCVFPOData();
603 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
604 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
605 bool parseDirectiveCFISections();
606 bool parseDirectiveCFIStartProc();
607 bool parseDirectiveCFIEndProc();
608 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
609 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
610 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
611 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
612 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
613 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
614 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
615 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
616 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
617 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
618 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
619 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
620 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
621 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
622 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
623 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
624 bool parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc);
625 bool parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc);
626 bool parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc);
627 bool parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc);
628 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
629 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
632 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
633 bool parseDirectiveExitMacro(StringRef Directive);
634 bool parseDirectiveEndMacro(StringRef Directive);
635 bool parseDirectiveMacro(SMLoc DirectiveLoc);
636 bool parseDirectiveMacrosOnOff(StringRef Directive);
638 bool parseDirectiveAltmacro(StringRef Directive);
641 bool parseDirectiveSpace(StringRef IDVal);
644 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
645 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
647 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
650 bool parseDirectiveLEB128(
bool Signed);
656 bool parseDirectiveComm(
bool IsLocal);
658 bool parseDirectiveAbort(SMLoc DirectiveLoc);
659 bool parseDirectiveInclude();
660 bool parseDirectiveIncbin();
663 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
665 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
667 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
669 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
671 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
672 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
673 bool parseDirectiveElse(SMLoc DirectiveLoc);
674 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
675 bool parseEscapedString(std::string &
Data)
override;
676 bool parseAngleBracketString(std::string &
Data)
override;
679 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
680 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
681 raw_svector_ostream &OS);
682 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
683 bool parseDirectiveIrp(SMLoc DirectiveLoc);
684 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
685 bool parseDirectiveEndr(SMLoc DirectiveLoc);
688 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,
692 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
695 bool parseDirectiveEnd(SMLoc DirectiveLoc);
698 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
701 bool parseDirectiveWarning(SMLoc DirectiveLoc);
704 bool parseDirectivePrint(SMLoc DirectiveLoc);
707 bool parseDirectivePseudoProbe();
710 bool parseDirectiveLTODiscard();
713 bool parseDirectiveAddrsig();
714 bool parseDirectiveAddrsigSym();
717 bool parseDirectiveBundleAlignMode();
719 bool parseDirectiveBundleLock();
721 bool parseDirectiveBundleUnlock();
723 void initializeDirectiveKindMap();
724 void initializeCVDefRangeTypeMap();
727class HLASMAsmParser final :
public AsmParser {
732 void lexLeadingSpaces() {
737 bool parseAsHLASMLabel(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI);
738 bool parseAsMachineInstruction(ParseStatementInfo &Info,
739 MCAsmParserSemaCallback *SI);
742 HLASMAsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
743 const MCAsmInfo &MAI,
unsigned CB = 0)
744 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
745 Lexer.setSkipSpace(
false);
746 Lexer.setAllowHashInIdentifier(
true);
747 Lexer.setLexHLASMIntegers(
true);
748 Lexer.setLexHLASMStrings(
true);
751 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
753 bool parseStatement(ParseStatementInfo &Info,
754 MCAsmParserSemaCallback *SI)
override;
761 :
MCAsmParser(Ctx,
Out, SM, MAI), CurBuffer(CB ? CB : SM.getMainFileID()),
762 MacrosEnabledFlag(
true) {
765 SavedDiagHandler =
SrcMgr.getDiagHandler();
766 SavedDiagContext =
SrcMgr.getDiagContext();
771 Out.setStartTokLocPtr(&StartTokLoc);
774 switch (Ctx.getObjectFileType()) {
775 case MCContext::IsCOFF:
776 PlatformParser.reset(createCOFFAsmParser());
778 case MCContext::IsMachO:
779 PlatformParser.reset(createDarwinAsmParser());
782 case MCContext::IsELF:
783 PlatformParser.reset(createELFAsmParser());
785 case MCContext::IsGOFF:
786 PlatformParser.reset(createGOFFAsmParser());
788 case MCContext::IsSPIRV:
790 "Need to implement createSPIRVAsmParser for SPIRV format.");
792 case MCContext::IsWasm:
793 PlatformParser.reset(createWasmAsmParser());
795 case MCContext::IsXCOFF:
796 PlatformParser.reset(createXCOFFAsmParser());
798 case MCContext::IsDXContainer:
799 report_fatal_error(
"DXContainer is not supported yet");
803 PlatformParser->Initialize(*
this);
804 if (
Out.getLFIRewriter()) {
805 LFIParser.reset(createLFIAsmParser(Out.getLFIRewriter()));
806 LFIParser->Initialize(*this);
808 initializeDirectiveKindMap();
809 initializeCVDefRangeTypeMap();
812AsmParser::~AsmParser() {
813 assert((HadError || ActiveMacros.empty()) &&
814 "Unexpected active macro instantiation!");
817 Out.setStartTokLocPtr(
nullptr);
823void AsmParser::printMacroInstantiations() {
825 for (MacroInstantiation *M :
reverse(ActiveMacros))
827 "while in macro instantiation");
830void AsmParser::Note(SMLoc L,
const Twine &
Msg, SMRange
Range) {
831 printPendingErrors();
833 printMacroInstantiations();
836bool AsmParser::Warning(SMLoc L,
const Twine &
Msg, SMRange
Range) {
842 printMacroInstantiations();
846bool AsmParser::printError(SMLoc L,
const Twine &
Msg, SMRange
Range) {
849 printMacroInstantiations();
853bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
854 std::string IncludedFile;
868bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
869 const MCExpr *
Count, SMLoc Loc) {
871 if (SymbolScanningMode)
877 std::string IncludedFile;
884 StringRef Bytes = (*BufOrErr)->getBuffer();
888 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
889 return Error(Loc,
"expected absolute expression");
891 return Warning(Loc,
"negative count has no effect");
894 getStreamer().emitBytes(Bytes);
898void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
904const AsmToken &AsmParser::Lex() {
911 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
913 Out.addExplicitComment(Twine(getTok().getString()));
916 const AsmToken *tok = &Lexer.
Lex();
929 if (ParentIncludeLoc != SMLoc()) {
930 jumpToLoc(ParentIncludeLoc);
938bool AsmParser::enabledGenDwarfForAssembly() {
945 if (
getContext().getGenDwarfFileNumber() == 0) {
946 const MCDwarfFile &RootFile =
947 getContext().getMCDwarfLineTable(0).getRootFile();
948 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
955bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
956 LTODiscardSymbols.
clear();
959 if (!NoInitialTextSection)
960 Out.initSections(getTargetParser().getSTI());
966 AsmCond StartingCondState = TheCondState;
974 MCSection *Sec = getStreamer().getCurrentSectionOnly();
977 getStreamer().emitLabel(SectionStartSym);
980 bool InsertResult =
getContext().addGenDwarfSection(Sec);
981 assert(InsertResult &&
".text section should not have debug info yet");
985 getTargetParser().onBeginOfFile();
989 ParseStatementInfo
Info(&AsmStrRewrites);
990 bool HasError = parseStatement(Info,
nullptr);
999 printPendingErrors();
1002 if (HasError && !getLexer().justConsumedEOL())
1003 eatToEndOfStatement();
1006 getTargetParser().onEndOfFile();
1007 printPendingErrors();
1010 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1014 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1016 const auto &LineTables =
getContext().getMCDwarfLineTables();
1017 if (!LineTables.empty()) {
1019 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1020 if (
File.Name.empty() && Index != 0)
1021 printError(getTok().getLoc(),
"unassigned file number: " +
1023 " for .file directives");
1035 MCSymbol *Sym = TableEntry.getValue().Symbol;
1044 printError(getTok().getLoc(),
"assembler local symbol '" +
1045 Sym->
getName() +
"' not defined");
1051 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1052 if (std::get<2>(LocSym)->isUndefined()) {
1055 CppHashInfo = std::get<1>(LocSym);
1056 printError(std::get<0>(LocSym),
"directional label undefined");
1062 if (!HadError && !NoFinalize) {
1063 if (
auto *TS =
Out.getTargetStreamer())
1064 TS->emitConstantPools();
1072bool AsmParser::checkForValidSection() {
1073 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1074 Out.initSections(getTargetParser().getSTI());
1075 return Error(getTok().getLoc(),
1076 "expected section directive before assembly directive");
1082void AsmParser::eatToEndOfStatement() {
1091StringRef AsmParser::parseStringToEndOfStatement() {
1092 const char *
Start = getTok().getLoc().getPointer();
1098 return StringRef(Start,
End - Start);
1101StringRef AsmParser::parseStringToComma() {
1102 const char *
Start = getTok().getLoc().getPointer();
1109 return StringRef(Start,
End - Start);
1117bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1118 if (parseExpression(Res))
1121 return parseRParen();
1129bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1130 if (parseExpression(Res))
1132 EndLoc = getTok().getEndLoc();
1133 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1144bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1145 AsmTypeInfo *TypeInfo) {
1146 SMLoc FirstTokenLoc = getLexer().getLoc();
1148 switch (FirstTokenKind) {
1150 return TokError(
"unknown token in expression");
1156 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1166 if (parseIdentifier(Identifier)) {
1170 bool ShouldGenerateTempSymbol =
false;
1173 ShouldGenerateTempSymbol =
true;
1175 if (!ShouldGenerateTempSymbol)
1176 return Error(FirstTokenLoc,
"invalid token in expression");
1185 EndLoc = FirstTokenLoc;
1190 std::pair<StringRef, StringRef>
Split;
1195 SMLoc AtLoc = getLexer().getLoc();
1197 if (parseIdentifier(VName))
1198 return Error(AtLoc,
"expected symbol variant after '@'");
1200 Split = std::make_pair(Identifier, VName);
1208 parseIdentifier(VName);
1211 Split = std::make_pair(Identifier, VName);
1219 return Error(getLexer().getLoc(),
"expected a symbol reference");
1223 if (!
Split.second.empty()) {
1225 if (MaybeSpecifier) {
1227 Spec = *MaybeSpecifier;
1230 "invalid variant '" +
Split.second +
"'");
1245 DoInline = TV->inlineAssignedExpr();
1248 return Error(EndLoc,
"unexpected modifier on variable reference");
1259 return TokError(
"literal value out of range for directive");
1261 SMLoc Loc = getTok().getLoc();
1262 int64_t
IntVal = getTok().getIntVal();
1268 StringRef IDVal = getTok().getString();
1270 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1272 if (
Split.first.size() != IDVal.
size()) {
1275 return TokError(
"invalid variant '" +
Split.second +
"'");
1276 IDVal =
Split.first;
1279 if (IDVal ==
"f" || IDVal ==
"b") {
1284 return Error(Loc,
"directional label undefined");
1285 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1293 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1302 return TokError(
"cannot use . as current PC");
1315 return parseParenExpr(Res, EndLoc);
1317 if (!PlatformParser->HasBracketExpressions())
1318 return TokError(
"brackets expression not supported on this target");
1320 return parseBracketExpr(Res, EndLoc);
1323 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1329 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1335 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1342bool AsmParser::parseExpression(
const MCExpr *&Res) {
1344 return parseExpression(Res, EndLoc);
1354 switch (E->getKind()) {
1365 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1366 "' (already modified)");
1417 "Argument to the function cannot be a NULL value");
1419 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1420 (*CharPtr !=
'\0')) {
1421 if (*CharPtr ==
'!')
1425 if (*CharPtr ==
'>') {
1435 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1436 if (AltMacroStr[Pos] ==
'!')
1438 Res += AltMacroStr[Pos];
1446 return TokError(
"expected specifier following '@'");
1448 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1450 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1470bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1473 auto &TS = getTargetParser();
1474 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1482 return TokError(
"unexpected symbol modifier following '@'");
1486 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1488 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1490 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1491 "' (no symbols present)");
1501 if (Res->evaluateAsAbsolute(
Value))
1507bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1509 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1512bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1515 SMLoc StartLoc = Lexer.
getLoc();
1516 if (parseExpression(Expr))
1519 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1520 return Error(StartLoc,
"expected absolute expression");
1527 bool ShouldUseLogicalShr) {
1604 bool ShouldUseLogicalShr) {
1693bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1695 SMLoc StartLoc = Lexer.
getLoc();
1698 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1702 if (TokPrec < Precedence)
1709 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1715 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1716 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1728bool AsmParser::parseStatement(ParseStatementInfo &Info,
1729 MCAsmParserSemaCallback *SI) {
1730 assert(!hasPendingError() &&
"parseStatement started with pending error");
1736 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1737 getTok().getString().
front() ==
'\n')
1743 AsmToken
ID = getTok();
1744 SMLoc IDLoc =
ID.getLoc();
1746 int64_t LocalLabelVal = -1;
1747 StartTokLoc =
ID.getLoc();
1749 return parseCppHashLineFilenameComment(IDLoc,
1750 !isInsideMacroInstantiation());
1754 LocalLabelVal = getTok().getIntVal();
1755 if (LocalLabelVal < 0) {
1756 if (!TheCondState.
Ignore) {
1758 return Error(IDLoc,
"unexpected token at start of statement");
1762 IDVal = getTok().getString();
1765 if (!TheCondState.
Ignore) {
1767 return Error(IDLoc,
"unexpected token at start of statement");
1775 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1777 IDVal =
ID.getString();
1778 }
else if (parseIdentifier(IDVal)) {
1779 if (!TheCondState.
Ignore) {
1781 return Error(IDLoc,
"unexpected token at start of statement");
1790 DirectiveKindMap.find(IDVal.
lower());
1791 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1793 : DirKindIt->getValue();
1804 return parseDirectiveIf(IDLoc, DirKind);
1806 return parseDirectiveIfb(IDLoc,
true);
1808 return parseDirectiveIfb(IDLoc,
false);
1810 return parseDirectiveIfc(IDLoc,
true);
1812 return parseDirectiveIfeqs(IDLoc,
true);
1814 return parseDirectiveIfc(IDLoc,
false);
1816 return parseDirectiveIfeqs(IDLoc,
false);
1818 return parseDirectiveIfdef(IDLoc,
true);
1821 return parseDirectiveIfdef(IDLoc,
false);
1823 return parseDirectiveElseIf(IDLoc);
1825 return parseDirectiveElse(IDLoc);
1827 return parseDirectiveEndIf(IDLoc);
1832 if (TheCondState.
Ignore) {
1833 eatToEndOfStatement();
1843 if (checkForValidSection())
1850 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1858 if (LocalLabelVal == -1) {
1859 if (ParsingMSInlineAsm && SI) {
1860 StringRef RewrittenLabel =
1861 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1863 "We should have an internal name here.");
1866 IDVal = RewrittenLabel;
1876 StringRef CommentStr = parseStringToEndOfStatement();
1887 if (MAI.
isMachO() && CFIStartProcLoc) {
1888 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1889 if (SymM->isExternal() && !SymM->isAltEntry())
1890 return Error(StartTokLoc,
"non-private labels cannot appear between "
1891 ".cfi_startproc / .cfi_endproc pairs") &&
1892 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1895 if (discardLTOSymbol(IDVal))
1898 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1901 if (!getTargetParser().isParsingMSInlineAsm())
1902 Out.emitLabel(Sym, IDLoc);
1906 if (enabledGenDwarfForAssembly())
1910 getTargetParser().onLabelParsed(Sym);
1919 return parseAssignment(IDVal, AssignmentKind::Equal);
1923 if (areMacrosEnabled())
1924 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1925 return handleMacroEntry(M, IDLoc);
1942 getTargetParser().flushPendingInstructions(getStreamer());
1944 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(ID);
1946 "Should only return Failure iff there was an error");
1954 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1955 ExtensionDirectiveMap.
lookup(IDVal);
1957 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1966 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1968 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1969 case DK_LTO_SET_CONDITIONAL:
1970 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1972 return parseDirectiveAscii(IDVal,
false);
1975 return parseDirectiveAscii(IDVal,
true);
1977 return parseDirectiveBase64();
1980 return parseDirectiveValue(IDVal, 1);
1986 return parseDirectiveValue(IDVal, 2);
1991 return parseDirectiveValue(IDVal, 4);
1994 return parseDirectiveValue(IDVal, 8);
1996 return parseDirectiveValue(
1997 IDVal,
getContext().getAsmInfo().getCodePointerSize());
1999 return parseDirectiveOctaValue(IDVal);
2003 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
2006 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
2008 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2009 return parseDirectiveAlign(IsPow2, 1);
2012 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2013 return parseDirectiveAlign(IsPow2, 4);
2016 return parseDirectiveAlign(
false, 1);
2018 return parseDirectiveAlign(
false, 2);
2020 return parseDirectiveAlign(
false, 4);
2022 return parseDirectiveAlign(
true, 1);
2024 return parseDirectiveAlign(
true, 2);
2026 return parseDirectiveAlign(
true, 4);
2028 return parseDirectivePrefAlign();
2030 return parseDirectiveOrg();
2032 return parseDirectiveFill();
2034 return parseDirectiveZero();
2036 eatToEndOfStatement();
2040 return parseDirectiveSymbolAttribute(
MCSA_Global);
2041 case DK_LAZY_REFERENCE:
2043 case DK_NO_DEAD_STRIP:
2045 case DK_SYMBOL_RESOLVER:
2047 case DK_PRIVATE_EXTERN:
2051 case DK_WEAK_DEFINITION:
2053 case DK_WEAK_REFERENCE:
2055 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2058 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2061 return parseDirectiveComm(
false);
2063 return parseDirectiveComm(
true);
2065 return parseDirectiveAbort(IDLoc);
2067 return parseDirectiveInclude();
2069 return parseDirectiveIncbin();
2072 return TokError(Twine(IDVal) +
2073 " not currently supported for this target");
2075 return parseDirectiveRept(IDLoc, IDVal);
2077 return parseDirectiveIrp(IDLoc);
2079 return parseDirectiveIrpc(IDLoc);
2081 return parseDirectiveEndr(IDLoc);
2082 case DK_BUNDLE_ALIGN_MODE:
2083 return parseDirectiveBundleAlignMode();
2084 case DK_BUNDLE_LOCK:
2085 return parseDirectiveBundleLock();
2086 case DK_BUNDLE_UNLOCK:
2087 return parseDirectiveBundleUnlock();
2089 return parseDirectiveLEB128(
true);
2091 return parseDirectiveLEB128(
false);
2094 return parseDirectiveSpace(IDVal);
2096 return parseDirectiveFile(IDLoc);
2098 return parseDirectiveLine();
2100 return parseDirectiveLoc();
2102 return parseDirectiveLocLabel(IDLoc);
2104 return parseDirectiveStabs();
2106 return parseDirectiveCVFile();
2108 return parseDirectiveCVFuncId();
2109 case DK_CV_INLINE_SITE_ID:
2110 return parseDirectiveCVInlineSiteId();
2112 return parseDirectiveCVLoc();
2113 case DK_CV_LINETABLE:
2114 return parseDirectiveCVLinetable();
2115 case DK_CV_INLINE_LINETABLE:
2116 return parseDirectiveCVInlineLinetable();
2117 case DK_CV_DEF_RANGE:
2118 return parseDirectiveCVDefRange();
2120 return parseDirectiveCVString();
2121 case DK_CV_STRINGTABLE:
2122 return parseDirectiveCVStringTable();
2123 case DK_CV_FILECHECKSUMS:
2124 return parseDirectiveCVFileChecksums();
2125 case DK_CV_FILECHECKSUM_OFFSET:
2126 return parseDirectiveCVFileChecksumOffset();
2127 case DK_CV_FPO_DATA:
2128 return parseDirectiveCVFPOData();
2129 case DK_CFI_SECTIONS:
2130 return parseDirectiveCFISections();
2131 case DK_CFI_STARTPROC:
2132 return parseDirectiveCFIStartProc();
2133 case DK_CFI_ENDPROC:
2134 return parseDirectiveCFIEndProc();
2135 case DK_CFI_DEF_CFA:
2136 return parseDirectiveCFIDefCfa(IDLoc);
2137 case DK_CFI_DEF_CFA_OFFSET:
2138 return parseDirectiveCFIDefCfaOffset(IDLoc);
2139 case DK_CFI_ADJUST_CFA_OFFSET:
2140 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2141 case DK_CFI_DEF_CFA_REGISTER:
2142 return parseDirectiveCFIDefCfaRegister(IDLoc);
2143 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2144 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2146 return parseDirectiveCFIOffset(IDLoc);
2147 case DK_CFI_REL_OFFSET:
2148 return parseDirectiveCFIRelOffset(IDLoc);
2149 case DK_CFI_LLVM_REGISTER_PAIR:
2150 return parseDirectiveCFILLVMRegisterPair(IDLoc);
2151 case DK_CFI_LLVM_VECTOR_REGISTERS:
2152 return parseDirectiveCFILLVMVectorRegisters(IDLoc);
2153 case DK_CFI_LLVM_VECTOR_OFFSET:
2154 return parseDirectiveCFILLVMVectorOffset(IDLoc);
2155 case DK_CFI_LLVM_VECTOR_REGISTER_MASK:
2156 return parseDirectiveCFILLVMVectorRegisterMask(IDLoc);
2157 case DK_CFI_PERSONALITY:
2158 return parseDirectiveCFIPersonalityOrLsda(
true);
2160 return parseDirectiveCFIPersonalityOrLsda(
false);
2161 case DK_CFI_REMEMBER_STATE:
2162 return parseDirectiveCFIRememberState(IDLoc);
2163 case DK_CFI_RESTORE_STATE:
2164 return parseDirectiveCFIRestoreState(IDLoc);
2165 case DK_CFI_SAME_VALUE:
2166 return parseDirectiveCFISameValue(IDLoc);
2167 case DK_CFI_RESTORE:
2168 return parseDirectiveCFIRestore(IDLoc);
2170 return parseDirectiveCFIEscape(IDLoc);
2171 case DK_CFI_RETURN_COLUMN:
2172 return parseDirectiveCFIReturnColumn(IDLoc);
2173 case DK_CFI_SIGNAL_FRAME:
2174 return parseDirectiveCFISignalFrame(IDLoc);
2175 case DK_CFI_UNDEFINED:
2176 return parseDirectiveCFIUndefined(IDLoc);
2177 case DK_CFI_REGISTER:
2178 return parseDirectiveCFIRegister(IDLoc);
2179 case DK_CFI_WINDOW_SAVE:
2180 return parseDirectiveCFIWindowSave(IDLoc);
2182 return parseDirectiveCFILabel(IDLoc);
2183 case DK_CFI_VAL_OFFSET:
2184 return parseDirectiveCFIValOffset(IDLoc);
2187 return parseDirectiveMacrosOnOff(IDVal);
2189 return parseDirectiveMacro(IDLoc);
2192 return parseDirectiveAltmacro(IDVal);
2194 return parseDirectiveExitMacro(IDVal);
2197 return parseDirectiveEndMacro(IDVal);
2199 return parseDirectivePurgeMacro(IDLoc);
2201 return parseDirectiveEnd(IDLoc);
2203 return parseDirectiveError(IDLoc,
false);
2205 return parseDirectiveError(IDLoc,
true);
2207 return parseDirectiveWarning(IDLoc);
2209 return parseDirectiveReloc(IDLoc);
2212 return parseDirectiveDCB(IDVal, 2);
2214 return parseDirectiveDCB(IDVal, 1);
2216 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2218 return parseDirectiveDCB(IDVal, 4);
2220 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2223 return TokError(Twine(IDVal) +
2224 " not currently supported for this target");
2227 return parseDirectiveDS(IDVal, 2);
2229 return parseDirectiveDS(IDVal, 1);
2231 return parseDirectiveDS(IDVal, 8);
2234 return parseDirectiveDS(IDVal, 4);
2237 return parseDirectiveDS(IDVal, 12);
2239 return parseDirectivePrint(IDLoc);
2241 return parseDirectiveAddrsig();
2242 case DK_ADDRSIG_SYM:
2243 return parseDirectiveAddrsigSym();
2244 case DK_PSEUDO_PROBE:
2245 return parseDirectivePseudoProbe();
2246 case DK_LTO_DISCARD:
2247 return parseDirectiveLTODiscard();
2249 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2252 return Error(IDLoc,
"unknown directive");
2256 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2257 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2258 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2261 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2262 return parseDirectiveMSAlign(IDLoc, Info);
2264 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2266 if (checkForValidSection())
2269 return parseAndMatchAndEmitTargetInstruction(Info, IDVal, ID, IDLoc);
2272bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2277 std::string OpcodeStr = IDVal.
lower();
2278 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2279 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr, ID,
2280 Info.ParsedOperands);
2281 Info.ParseError = ParseHadError;
2284 if (getShowParsedOperands()) {
2285 SmallString<256> Str;
2286 raw_svector_ostream OS(Str);
2287 OS <<
"parsed instruction: [";
2288 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2291 Info.ParsedOperands[i]->print(OS, MAI);
2299 if (hasPendingError() || ParseHadError)
2304 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2306 getStreamer().getCurrentSectionOnly())) {
2308 if (ActiveMacros.empty())
2312 ActiveMacros.front()->ExitBuffer);
2317 if (!CppHashInfo.Filename.empty()) {
2318 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2319 0, StringRef(), CppHashInfo.Filename);
2320 getContext().setGenDwarfFileNumber(FileNumber);
2322 unsigned CppHashLocLineNo =
2324 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2327 getStreamer().emitDwarfLocDirective(
2328 getContext().getGenDwarfFileNumber(), Line, 0,
2334 if (!ParseHadError) {
2336 if (getTargetParser().matchAndEmitInstruction(
2337 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2338 getTargetParser().isParsingMSInlineAsm()))
2346AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2351 SMLoc StartLoc = Lexer.
getLoc();
2364bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2369 "Lexing Cpp line comment: Expected Integer");
2370 int64_t LineNumber = getTok().getIntVal();
2373 "Lexing Cpp line comment: Expected String");
2374 StringRef
Filename = getTok().getString();
2385 CppHashInfo.Loc =
L;
2387 CppHashInfo.LineNumber = LineNumber;
2388 CppHashInfo.Buf = CurBuffer;
2389 if (!HadCppHashFilename) {
2390 HadCppHashFilename =
true;
2400 std::nullopt, std::nullopt);
2408void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2409 auto *Parser =
static_cast<AsmParser *
>(
Context);
2410 raw_ostream &OS =
errs();
2413 SMLoc DiagLoc = Diag.
getLoc();
2415 unsigned CppHashBuf =
2416 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2420 if (!Parser->SavedDiagHandler)
2426 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2427 if (Parser->SavedDiagHandler)
2428 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2430 Parser->getContext().diagnose(Diag);
2437 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2440 int CppHashLocLineNo =
2441 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2443 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2449 if (Parser->SavedDiagHandler)
2450 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2452 Parser->getContext().diagnose(NewDiag);
2463bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2466 bool EnableAtPseudoVariable) {
2468 auto expandArg = [&](
unsigned Index) {
2469 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2470 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2471 for (
const AsmToken &Token :
A[Index])
2479 if (AltMacroMode && Token.getString().front() ==
'%' &&
2482 OS << Token.getIntVal();
2485 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2492 OS << Token.getString();
2494 OS << Token.getStringContents();
2499 StringRef Body =
Macro.Body;
2502 if (Body[
I] ==
'\\' &&
I + 1 !=
End) {
2504 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2505 OS << NumOfMacroInstantiations;
2509 if (Body[
I + 1] ==
'+') {
2514 if (Body[
I + 1] ==
'(' &&
I + 2 !=
End && Body[
I + 2] ==
')') {
2523 if (AltMacroMode &&
I !=
End && Body[
I] ==
'&')
2527 if (Parameters[Index].Name == Argument)
2529 if (Index == NParameters)
2538 if (Body[
I] ==
'$' &&
I + 1 !=
End && IsDarwin && !NParameters) {
2540 switch (Body[
I + 1]) {
2556 unsigned Index = Body[
I + 1] -
'0';
2557 if (Index <
A.size())
2558 for (
const AsmToken &Token :
A[Index])
2559 OS << Token.getString();
2574 StringRef Token(Body.
data() + Start,
I - Start);
2578 if (Parameters[Index].Name == Token)
2580 if (Index != NParameters) {
2582 if (
I !=
End && Body[
I] ==
'&')
2626class AsmLexerSkipSpaceRAII {
2628 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2632 ~AsmLexerSkipSpaceRAII() {
2642bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2646 StringRef Str = parseStringToEndOfStatement();
2652 unsigned ParenLevel = 0;
2655 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2662 return TokError(
"unexpected token in macro instantiation");
2664 if (ParenLevel == 0) {
2677 MA.push_back(getTok());
2701 MA.push_back(getTok());
2705 if (ParenLevel != 0)
2706 return TokError(
"unbalanced parentheses in macro argument");
2711bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2712 MCAsmMacroArguments &
A) {
2713 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2714 bool NamedParametersFound =
false;
2715 SmallVector<SMLoc, 4> FALocs;
2717 A.resize(NParameters);
2718 FALocs.
resize(NParameters);
2723 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2724 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2726 SMLoc IDLoc = Lexer.
getLoc();
2727 MCAsmMacroParameter FA;
2730 if (parseIdentifier(FA.
Name))
2731 return Error(IDLoc,
"invalid argument identifier for formal argument");
2734 return TokError(
"expected '=' after formal parameter identifier");
2738 NamedParametersFound =
true;
2740 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2742 if (NamedParametersFound && FA.
Name.
empty())
2743 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2745 SMLoc StrLoc = Lexer.
getLoc();
2748 const MCExpr *AbsoluteExp;
2752 if (parseExpression(AbsoluteExp, EndLoc))
2754 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2755 getStreamer().getAssemblerPtr()))
2756 return Error(StrLoc,
"expected absolute expression");
2760 StringRef(StrChar, EndChar - StrChar),
Value);
2761 FA.
Value.push_back(newToken);
2766 jumpToLoc(EndLoc, CurBuffer);
2770 StringRef(StrChar, EndChar - StrChar));
2771 FA.
Value.push_back(newToken);
2772 }
else if(parseMacroArgument(FA.
Value, Vararg))
2778 for (FAI = 0; FAI < NParameters; ++FAI)
2779 if (
M->Parameters[FAI].Name == FA.
Name)
2782 if (FAI >= NParameters) {
2783 assert(M &&
"expected macro to be defined");
2784 return Error(IDLoc,
"parameter named '" + FA.
Name +
2785 "' does not exist for macro '" +
M->Name +
"'");
2790 if (!FA.
Value.empty()) {
2795 if (FALocs.
size() <= PI)
2798 FALocs[PI] = Lexer.
getLoc();
2806 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2808 if (
M->Parameters[FAI].Required) {
2810 "missing value for required parameter "
2811 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2815 if (!
M->Parameters[FAI].Value.empty())
2816 A[FAI] =
M->Parameters[FAI].Value;
2825 return TokError(
"too many positional arguments");
2828bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2832 if (ActiveMacros.size() == MaxNestingDepth) {
2833 std::ostringstream MaxNestingDepthError;
2834 MaxNestingDepthError <<
"macros cannot be nested more than "
2835 << MaxNestingDepth <<
" levels deep."
2836 <<
" Use -asm-macro-max-nesting-depth to increase "
2838 return TokError(MaxNestingDepthError.str());
2841 MCAsmMacroArguments
A;
2842 if (parseMacroArguments(M,
A))
2847 SmallString<256> Buf;
2848 raw_svector_ostream OS(Buf);
2850 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2851 return Error(getTok().getLoc(),
"Wrong number of arguments");
2852 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2857 OS <<
".endmacro\n";
2859 std::unique_ptr<MemoryBuffer> Instantiation =
2864 MacroInstantiation *
MI =
new MacroInstantiation{
2865 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2866 ActiveMacros.push_back(
MI);
2868 ++NumOfMacroInstantiations;
2878void AsmParser::handleMacroExit() {
2880 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2888 delete ActiveMacros.back();
2889 ActiveMacros.pop_back();
2892bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2895 if (discardLTOSymbol(Name)) {
2896 eatToEndOfStatement();
2901 const MCExpr *
Value;
2902 SMLoc ExprLoc = getTok().getLoc();
2904 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2918 case AssignmentKind::Equal:
2921 case AssignmentKind::Set:
2922 case AssignmentKind::Equiv:
2926 case AssignmentKind::LTOSetConditional:
2928 return Error(ExprLoc,
"expected identifier");
2930 Out.emitConditionalAssignment(Sym,
Value);
2940bool AsmParser::parseIdentifier(StringRef &Res) {
2947 SMLoc PrefixLoc = getLexer().getLoc();
2959 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2965 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2973 Res = getTok().getIdentifier();
2985bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2987 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2988 parseAssignment(Name, Kind))
2993bool AsmParser::parseEscapedString(std::string &
Data) {
2998 StringRef Str = getTok().getStringContents();
2999 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
3000 if (Str[i] !=
'\\') {
3001 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
3003 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
3007 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
3018 return TokError(
"unexpected backslash at end of string");
3021 if (Str[i] ==
'x' || Str[i] ==
'X') {
3022 size_t length = Str.size();
3023 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
3024 return TokError(
"invalid hexadecimal escape sequence");
3029 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3037 if ((
unsigned)(Str[i] -
'0') <= 7) {
3039 unsigned Value = Str[i] -
'0';
3041 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3045 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3052 return TokError(
"invalid octal escape sequence (out of range)");
3062 return TokError(
"invalid escape sequence (unrecognized character)");
3064 case 'b':
Data +=
'\b';
break;
3065 case 'f':
Data +=
'\f';
break;
3066 case 'n':
Data +=
'\n';
break;
3067 case 'r':
Data +=
'\r';
break;
3068 case 't':
Data +=
'\t';
break;
3069 case '"':
Data +=
'"';
break;
3070 case '\\':
Data +=
'\\';
break;
3078bool AsmParser::parseAngleBracketString(std::string &
Data) {
3079 SMLoc EndLoc, StartLoc = getTok().getLoc();
3081 const char *StartChar = StartLoc.
getPointer() + 1;
3082 const char *EndChar = EndLoc.
getPointer() - 1;
3083 jumpToLoc(EndLoc, CurBuffer);
3096bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3097 auto parseOp = [&]() ->
bool {
3099 if (checkForValidSection())
3104 if (parseEscapedString(
Data))
3106 getStreamer().emitBytes(
Data);
3109 getStreamer().emitBytes(StringRef(
"\0", 1));
3113 return parseMany(parseOp);
3118bool AsmParser::parseDirectiveBase64() {
3119 auto parseOp = [&]() ->
bool {
3120 if (checkForValidSection())
3127 std::vector<char> Decoded;
3128 std::string
const str = getTok().getStringContents().str();
3129 if (check(str.empty(),
"expected nonempty string")) {
3136 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3139 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3144 return check(parseMany(parseOp),
"expected string");
3149bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3151 const MCExpr *Expr =
nullptr;
3153 if (parseExpression(
Offset))
3165 SMLoc ExprLoc = Lexer.
getLoc();
3166 if (parseExpression(Expr))
3171 return Error(ExprLoc,
"expression must be relocatable");
3177 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3183bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3184 auto parseOp = [&]() ->
bool {
3185 const MCExpr *
Value;
3186 SMLoc ExprLoc = getLexer().getLoc();
3187 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3192 uint64_t IntValue = MCE->getValue();
3194 return Error(ExprLoc,
"out of range literal value");
3195 getStreamer().emitIntValue(IntValue,
Size);
3197 getStreamer().emitValue(
Value,
Size, ExprLoc);
3201 return parseMany(parseOp);
3207 return Asm.TokError(
"unknown token in expression");
3208 SMLoc ExprLoc = Asm.getTok().getLoc();
3209 APInt IntValue = Asm.getTok().getAPIntVal();
3211 if (!IntValue.
isIntN(128))
3212 return Asm.Error(ExprLoc,
"out of range literal value");
3213 if (!IntValue.
isIntN(64)) {
3226bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3227 auto parseOp = [&]() ->
bool {
3228 if (checkForValidSection())
3234 getStreamer().emitInt64(lo);
3235 getStreamer().emitInt64(hi);
3237 getStreamer().emitInt64(hi);
3238 getStreamer().emitInt64(lo);
3243 return parseMany(parseOp);
3246bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3257 return TokError(Lexer.
getErr());
3260 return TokError(
"unexpected token in directive");
3264 StringRef IDVal = getTok().getString();
3272 return TokError(
"invalid floating point literal");
3274 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3276 return TokError(
"invalid floating point literal");
3283 Res =
Value.bitcastToAPInt();
3290bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3291 const fltSemantics &Semantics) {
3292 auto parseOp = [&]() ->
bool {
3294 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3301 return parseMany(parseOp);
3306bool AsmParser::parseDirectiveZero() {
3307 SMLoc NumBytesLoc = Lexer.
getLoc();
3308 const MCExpr *NumBytes;
3309 if (checkForValidSection() || parseExpression(NumBytes))
3315 if (parseAbsoluteExpression(Val))
3321 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3328bool AsmParser::parseDirectiveFill() {
3329 SMLoc NumValuesLoc = Lexer.
getLoc();
3330 const MCExpr *NumValues;
3331 if (checkForValidSection() || parseExpression(NumValues))
3334 int64_t FillSize = 1;
3335 int64_t FillExpr = 0;
3337 SMLoc SizeLoc, ExprLoc;
3340 SizeLoc = getTok().getLoc();
3341 if (parseAbsoluteExpression(FillSize))
3344 ExprLoc = getTok().getLoc();
3345 if (parseAbsoluteExpression(FillExpr))
3353 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3357 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3362 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3364 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3371bool AsmParser::parseDirectiveOrg() {
3373 SMLoc OffsetLoc = Lexer.
getLoc();
3374 if (checkForValidSection() || parseExpression(
Offset))
3378 int64_t FillExpr = 0;
3380 if (parseAbsoluteExpression(FillExpr))
3385 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3391bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3392 SMLoc AlignmentLoc = getLexer().getLoc();
3395 bool HasFillExpr =
false;
3396 int64_t FillExpr = 0;
3397 int64_t MaxBytesToFill = 0;
3400 auto parseAlign = [&]() ->
bool {
3401 if (parseAbsoluteExpression(Alignment))
3409 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3413 if (parseTokenLoc(MaxBytesLoc) ||
3414 parseAbsoluteExpression(MaxBytesToFill))
3420 if (checkForValidSection())
3424 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3431 bool ReturnVal =
false;
3435 if (Alignment < 0 || Alignment >= 32) {
3436 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3448 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3452 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3459 if (MaxBytesToFill < 1) {
3460 ReturnVal |=
Error(MaxBytesLoc,
3461 "alignment directive can never be satisfied in this "
3462 "many bytes, ignoring maximum bytes expression");
3466 if (MaxBytesToFill >= Alignment) {
3467 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3473 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3474 assert(Section &&
"must have section to emit alignment");
3476 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3478 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3486 getStreamer().emitCodeAlignment(
Align(Alignment),
3487 getTargetParser().getSTI(), MaxBytesToFill);
3490 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3497bool AsmParser::parseDirectivePrefAlign() {
3498 SMLoc AlignmentLoc = getLexer().getLoc();
3500 if (checkForValidSection() || parseAbsoluteExpression(Log2Alignment))
3503 if (Log2Alignment < 0 || Log2Alignment > 63)
3504 return Error(AlignmentLoc,
"log2 alignment must be in the range [0, 63]");
3507 SMLoc SymLoc = getLexer().getLoc();
3511 SymLoc = getLexer().getLoc();
3512 if (parseIdentifier(Name))
3513 return Error(SymLoc,
"expected symbol name");
3517 SMLoc FillLoc = getLexer().getLoc();
3521 bool EmitNops =
false;
3523 SMLoc FillLoc2 = getLexer().getLoc();
3525 getLexer().getTok().getIdentifier() ==
"nop") {
3530 if (parseAbsoluteExpression(FillVal))
3532 if (FillVal < 0 || FillVal > 255)
3533 return Error(FillLoc2,
"fill value must be in range [0, 255]");
3534 Fill =
static_cast<uint8_t
>(FillVal);
3539 if ((EmitNops || Fill != 0) &&
3540 getStreamer().getCurrentSectionOnly()->isBssSection())
3541 return Error(FillLoc,
"non-zero fill in BSS section '" +
3542 getStreamer().getCurrentSectionOnly()->
getName() +
3546 Fill, getTargetParser().getSTI());
3553bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3555 int64_t FileNumber = -1;
3557 FileNumber = getTok().getIntVal();
3561 return TokError(
"negative file number");
3568 if (parseEscapedString(Path))
3571 StringRef Directory;
3573 std::string FilenameData;
3575 if (check(FileNumber == -1,
3576 "explicit path specified, but no file number") ||
3577 parseEscapedString(FilenameData))
3586 bool HasMD5 =
false;
3588 std::optional<StringRef>
Source;
3589 bool HasSource =
false;
3590 std::string SourceString;
3595 "unexpected token in '.file' directive") ||
3596 parseIdentifier(Keyword))
3598 if (Keyword ==
"md5") {
3600 if (check(FileNumber == -1,
3601 "MD5 checksum specified, but no file number") ||
3604 }
else if (Keyword ==
"source") {
3606 if (check(FileNumber == -1,
3607 "source specified, but no file number") ||
3609 "unexpected token in '.file' directive") ||
3610 parseEscapedString(SourceString))
3613 return TokError(
"unexpected token in '.file' directive");
3617 if (FileNumber == -1) {
3621 if (
getContext().getAsmInfo().hasSingleParameterDotFile())
3622 getStreamer().emitFileDirective(
Filename);
3632 std::optional<MD5::MD5Result> CKMem;
3635 for (
unsigned i = 0; i != 8; ++i) {
3636 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3637 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3642 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3643 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3644 Source = StringRef(SourceBuf, SourceString.size());
3646 if (FileNumber == 0) {
3650 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3652 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3653 FileNumber, Directory,
Filename, CKMem, Source);
3660 ReportedInconsistentMD5 =
true;
3661 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3670bool AsmParser::parseDirectiveLine() {
3682bool AsmParser::parseDirectiveLoc() {
3683 int64_t FileNumber = 0, LineNumber = 0;
3684 SMLoc Loc = getTok().getLoc();
3685 if (parseIntToken(FileNumber) ||
3687 "file number less than one in '.loc' directive") ||
3688 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3689 "unassigned file number in '.loc' directive"))
3694 LineNumber = getTok().getIntVal();
3696 return TokError(
"line number less than zero in '.loc' directive");
3700 int64_t ColumnPos = 0;
3702 ColumnPos = getTok().getIntVal();
3704 return TokError(
"column position less than zero in '.loc' directive");
3708 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3713 auto parseLocOp = [&]() ->
bool {
3715 SMLoc Loc = getTok().getLoc();
3716 if (parseIdentifier(Name))
3717 return TokError(
"unexpected token in '.loc' directive");
3719 if (Name ==
"basic_block")
3721 else if (Name ==
"prologue_end")
3723 else if (Name ==
"epilogue_begin")
3725 else if (Name ==
"is_stmt") {
3726 Loc = getTok().getLoc();
3727 const MCExpr *
Value;
3728 if (parseExpression(
Value))
3732 int Value = MCE->getValue();
3734 Flags &= ~DWARF2_FLAG_IS_STMT;
3735 else if (
Value == 1)
3738 return Error(Loc,
"is_stmt value not 0 or 1");
3740 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3742 }
else if (Name ==
"isa") {
3743 Loc = getTok().getLoc();
3744 const MCExpr *
Value;
3745 if (parseExpression(
Value))
3749 int Value = MCE->getValue();
3751 return Error(Loc,
"isa number less than zero");
3754 return Error(Loc,
"isa number not a constant value");
3756 }
else if (Name ==
"discriminator") {
3757 if (parseAbsoluteExpression(Discriminator))
3760 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3765 if (parseMany(parseLocOp,
false ))
3768 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3769 Isa, Discriminator, StringRef());
3776bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3778 DirectiveLoc = Lexer.
getLoc();
3779 if (parseIdentifier(Name))
3780 return TokError(
"expected identifier");
3783 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3789bool AsmParser::parseDirectiveStabs() {
3790 return TokError(
"unsupported directive '.stabs'");
3795bool AsmParser::parseDirectiveCVFile() {
3796 SMLoc FileNumberLoc = getTok().getLoc();
3799 std::string Checksum;
3802 if (parseIntToken(FileNumber,
"expected file number") ||
3803 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3805 "unexpected token in '.cv_file' directive") ||
3810 "unexpected token in '.cv_file' directive") ||
3811 parseEscapedString(Checksum) ||
3812 parseIntToken(ChecksumKind,
3813 "expected checksum kind in '.cv_file' directive") ||
3819 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3820 memcpy(CKMem, Checksum.data(), Checksum.size());
3821 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3824 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3825 static_cast<uint8_t
>(ChecksumKind)))
3826 return Error(FileNumberLoc,
"file number already allocated");
3831bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3832 StringRef DirectiveName) {
3834 return parseTokenLoc(Loc) ||
3835 parseIntToken(FunctionId,
"expected function id") ||
3836 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3837 "expected function id within range [0, UINT_MAX)");
3840bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3842 return parseTokenLoc(Loc) ||
3843 parseIntToken(FileNumber,
"expected file number") ||
3844 check(FileNumber < 1, Loc,
3845 "file number less than one in '" + DirectiveName +
3847 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3848 "unassigned file number in '" + DirectiveName +
"' directive");
3855bool AsmParser::parseDirectiveCVFuncId() {
3856 SMLoc FunctionIdLoc = getTok().getLoc();
3859 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3862 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3863 return Error(FunctionIdLoc,
"function id already allocated");
3876bool AsmParser::parseDirectiveCVInlineSiteId() {
3877 SMLoc FunctionIdLoc = getTok().getLoc();
3885 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3890 getTok().getIdentifier() !=
"within"),
3891 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3896 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3901 getTok().getIdentifier() !=
"inlined_at"),
3902 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3908 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3909 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3914 IACol = getTok().getIntVal();
3921 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3922 IALine, IACol, FunctionIdLoc))
3923 return Error(FunctionIdLoc,
"function id already allocated");
3935bool AsmParser::parseDirectiveCVLoc() {
3936 SMLoc DirectiveLoc = getTok().getLoc();
3937 int64_t FunctionId, FileNumber;
3938 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3939 parseCVFileId(FileNumber,
".cv_loc"))
3942 int64_t LineNumber = 0;
3944 LineNumber = getTok().getIntVal();
3946 return TokError(
"line number less than zero in '.cv_loc' directive");
3950 int64_t ColumnPos = 0;
3952 ColumnPos = getTok().getIntVal();
3954 return TokError(
"column position less than zero in '.cv_loc' directive");
3958 bool PrologueEnd =
false;
3961 auto parseOp = [&]() ->
bool {
3963 SMLoc Loc = getTok().getLoc();
3964 if (parseIdentifier(Name))
3965 return TokError(
"unexpected token in '.cv_loc' directive");
3966 if (Name ==
"prologue_end")
3968 else if (Name ==
"is_stmt") {
3969 Loc = getTok().getLoc();
3970 const MCExpr *
Value;
3971 if (parseExpression(
Value))
3976 IsStmt = MCE->getValue();
3979 return Error(Loc,
"is_stmt value not 0 or 1");
3981 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3986 if (parseMany(parseOp,
false ))
3989 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3990 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3997bool AsmParser::parseDirectiveCVLinetable() {
4000 SMLoc Loc = getTok().getLoc();
4001 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
4002 parseTokenLoc(Loc) ||
4003 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
4004 parseComma() || parseTokenLoc(Loc) ||
4005 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
4008 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
4014bool AsmParser::parseDirectiveCVInlineLinetable() {
4015 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
4017 SMLoc Loc = getTok().getLoc();
4018 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
4019 parseTokenLoc(Loc) ||
4020 parseIntToken(SourceFileId,
"expected SourceField") ||
4021 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
4022 parseTokenLoc(Loc) ||
4023 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
4024 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
4025 parseTokenLoc(Loc) ||
4026 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
4027 parseTokenLoc(Loc) ||
4028 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
4034 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
4035 SourceLineNum, FnStartSym,
4040void AsmParser::initializeCVDefRangeTypeMap() {
4041 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
4042 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
4043 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4044 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4045 CVDefRangeTypeMap[
"reg_rel_indir"] = CVDR_DEFRANGE_REGISTER_REL_INDIR;
4050bool AsmParser::parseDirectiveCVDefRange() {
4052 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
4054 Loc = getLexer().getLoc();
4057 return Error(Loc,
"expected identifier in directive");
4059 Loc = getLexer().getLoc();
4062 return Error(Loc,
"expected identifier in directive");
4064 Ranges.push_back({GapStartSym, GapEndSym});
4067 StringRef CVDefRangeTypeStr;
4070 "expected comma before def_range type in .cv_def_range directive") ||
4071 parseIdentifier(CVDefRangeTypeStr))
4072 return Error(Loc,
"expected def_range type in directive");
4075 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4076 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4078 : CVTypeIt->getValue();
4080 case CVDR_DEFRANGE_REGISTER: {
4082 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4083 ".cv_def_range directive") ||
4084 parseAbsoluteExpression(DRRegister))
4085 return Error(Loc,
"expected register number");
4087 codeview::DefRangeRegisterHeader DRHdr;
4090 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4093 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4096 "expected comma before offset in .cv_def_range directive") ||
4097 parseAbsoluteExpression(DROffset))
4098 return Error(Loc,
"expected offset value");
4100 codeview::DefRangeFramePointerRelHeader DRHdr;
4102 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4105 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4107 int64_t DROffsetInParent;
4108 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4109 ".cv_def_range directive") ||
4110 parseAbsoluteExpression(DRRegister))
4111 return Error(Loc,
"expected register number");
4113 "expected comma before offset in .cv_def_range directive") ||
4114 parseAbsoluteExpression(DROffsetInParent))
4115 return Error(Loc,
"expected offset value");
4117 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4121 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4124 case CVDR_DEFRANGE_REGISTER_REL: {
4127 int64_t DRBasePointerOffset;
4128 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4129 ".cv_def_range directive") ||
4130 parseAbsoluteExpression(DRRegister))
4131 return Error(Loc,
"expected register value");
4134 "expected comma before flag value in .cv_def_range directive") ||
4135 parseAbsoluteExpression(DRFlags))
4136 return Error(Loc,
"expected flag value");
4137 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4138 "in .cv_def_range directive") ||
4139 parseAbsoluteExpression(DRBasePointerOffset))
4140 return Error(Loc,
"expected base pointer offset value");
4142 codeview::DefRangeRegisterRelHeader DRHdr;
4144 DRHdr.
Flags = DRFlags;
4146 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4149 case CVDR_DEFRANGE_REGISTER_REL_INDIR: {
4152 int64_t DRBasePointerOffset;
4153 int64_t DROffsetInUdt;
4154 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4155 ".cv_def_range directive") ||
4156 parseAbsoluteExpression(DRRegister))
4157 return Error(Loc,
"expected register value");
4160 "expected comma before flag value in .cv_def_range directive") ||
4161 parseAbsoluteExpression(DRFlags))
4162 return Error(Loc,
"expected flag value");
4163 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4164 "in .cv_def_range directive") ||
4165 parseAbsoluteExpression(DRBasePointerOffset))
4166 return Error(Loc,
"expected base pointer offset value");
4167 if (parseToken(
AsmToken::Comma,
"expected comma before offset in UDT "
4168 "in .cv_def_range directive") ||
4169 parseAbsoluteExpression(DROffsetInUdt))
4170 return Error(Loc,
"expected offset in UDT value");
4172 codeview::DefRangeRegisterRelIndirHeader DRHdr;
4174 DRHdr.
Flags = DRFlags;
4177 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4181 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4188bool AsmParser::parseDirectiveCVString() {
4190 if (checkForValidSection() || parseEscapedString(
Data))
4194 std::pair<StringRef, unsigned> Insertion =
4195 getCVContext().addToStringTable(
Data);
4196 getStreamer().emitInt32(Insertion.second);
4202bool AsmParser::parseDirectiveCVStringTable() {
4203 getStreamer().emitCVStringTableDirective();
4209bool AsmParser::parseDirectiveCVFileChecksums() {
4210 getStreamer().emitCVFileChecksumsDirective();
4216bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4218 if (parseIntToken(FileNo))
4222 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4228bool AsmParser::parseDirectiveCVFPOData() {
4229 SMLoc DirLoc = getLexer().getLoc();
4232 return TokError(
"expected symbol name");
4235 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4241bool AsmParser::parseDirectiveCFISections() {
4245 bool SFrame =
false;
4249 if (parseIdentifier(Name))
4250 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4251 if (Name ==
".eh_frame")
4253 else if (Name ==
".debug_frame")
4255 else if (Name ==
".sframe")
4263 getStreamer().emitCFISections(EH,
Debug, SFrame);
4269bool AsmParser::parseDirectiveCFIStartProc() {
4270 CFIStartProcLoc = StartTokLoc;
4274 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4275 "unexpected token") ||
4285 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4291bool AsmParser::parseDirectiveCFIEndProc() {
4292 CFIStartProcLoc = std::nullopt;
4297 getStreamer().emitCFIEndProc();
4302bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4303 SMLoc DirectiveLoc) {
4307 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4311 return parseAbsoluteExpression(
Register);
4318bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4320 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4321 parseAbsoluteExpression(
Offset) || parseEOL())
4330bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4332 if (parseAbsoluteExpression(
Offset) || parseEOL())
4335 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4341bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4342 int64_t Register1 = 0, Register2 = 0;
4343 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4344 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4347 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4353bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4356 getStreamer().emitCFIWindowSave(DirectiveLoc);
4362bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4363 int64_t Adjustment = 0;
4364 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4367 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4373bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4375 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4378 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4384bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4386 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4387 parseAbsoluteExpression(
Offset) || parseComma() ||
4398bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4402 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4403 parseAbsoluteExpression(
Offset) || parseEOL())
4412bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4415 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4416 parseAbsoluteExpression(
Offset) || parseEOL())
4424 if (Encoding & ~0xff)
4430 const unsigned Format = Encoding & 0xf;
4437 const unsigned Application = Encoding & 0x70;
4449bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4450 int64_t Encoding = 0;
4451 if (parseAbsoluteExpression(Encoding))
4459 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4463 getStreamer().emitCFIPersonality(Sym, Encoding);
4465 getStreamer().emitCFILsda(Sym, Encoding);
4471bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4474 getStreamer().emitCFIRememberState(DirectiveLoc);
4480bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4483 getStreamer().emitCFIRestoreState(DirectiveLoc);
4489bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4492 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4495 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4501bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4503 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4506 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4512bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4515 if (parseAbsoluteExpression(CurrValue))
4518 Values.push_back((uint8_t)CurrValue);
4523 if (parseAbsoluteExpression(CurrValue))
4526 Values.push_back((uint8_t)CurrValue);
4529 getStreamer().emitCFIEscape(
Values, DirectiveLoc);
4535bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4537 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4539 getStreamer().emitCFIReturnColumn(
Register);
4545bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4549 getStreamer().emitCFISignalFrame();
4555bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4558 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4561 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4567bool AsmParser::parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc) {
4569 int64_t R1 = 0,
R2 = 0;
4570 int64_t R1Size = 0, R2Size = 0;
4572 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4573 parseRegisterOrRegisterNumber(R1, DirectiveLoc) || parseComma() ||
4574 parseAbsoluteExpression(R1Size) || parseComma() ||
4575 parseRegisterOrRegisterNumber(
R2, DirectiveLoc) || parseComma() ||
4576 parseAbsoluteExpression(R2Size) || parseEOL())
4579 getStreamer().emitCFILLVMRegisterPair(
Register, R1, R1Size,
R2, R2Size,
4586bool AsmParser::parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc) {
4588 std::vector<MCCFIInstruction::VectorRegisterWithLane> VRs;
4590 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma())
4594 int64_t VectorRegister = 0;
4597 if (parseRegisterOrRegisterNumber(VectorRegister, DirectiveLoc) ||
4598 parseComma() || parseIntToken(Lane,
"expected a lane number") ||
4599 parseComma() || parseAbsoluteExpression(
Size))
4601 VRs.push_back({unsigned(VectorRegister), unsigned(Lane), unsigned(
Size)});
4607 getStreamer().emitCFILLVMVectorRegisters(
Register, std::move(VRs),
4614bool AsmParser::parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc) {
4615 int64_t
Register = 0, MaskRegister = 0;
4616 int64_t RegisterSize = 0, MaskRegisterSize = 0;
4619 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4620 parseAbsoluteExpression(RegisterSize) || parseComma() ||
4621 parseRegisterOrRegisterNumber(MaskRegister, DirectiveLoc) ||
4622 parseComma() || parseAbsoluteExpression(MaskRegisterSize) ||
4623 parseComma() || parseAbsoluteExpression(
Offset) || parseEOL())
4626 getStreamer().emitCFILLVMVectorOffset(
Register, RegisterSize, MaskRegister,
4627 MaskRegisterSize,
Offset, DirectiveLoc);
4634bool AsmParser::parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc) {
4635 int64_t
Register = 0, SpillReg = 0, MaskReg = 0;
4636 int64_t SpillRegLaneSize = 0, MaskRegSize = 0;
4638 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4639 parseRegisterOrRegisterNumber(SpillReg, DirectiveLoc) || parseComma() ||
4640 parseAbsoluteExpression(SpillRegLaneSize) || parseComma() ||
4641 parseRegisterOrRegisterNumber(MaskReg, DirectiveLoc) || parseComma() ||
4642 parseAbsoluteExpression(MaskRegSize) || parseEOL())
4645 getStreamer().emitCFILLVMVectorRegisterMask(
4646 Register, SpillReg, SpillRegLaneSize, MaskReg, MaskRegSize, DirectiveLoc);
4652bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4655 if (parseIdentifier(Name))
4656 return TokError(
"expected identifier");
4659 getStreamer().emitCFILabelDirective(Loc, Name);
4665bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4669 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4670 parseAbsoluteExpression(
Offset) || parseEOL())
4680bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4683 AltMacroMode = (Directive ==
".altmacro");
4690bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4693 setMacrosEnabled(Directive ==
".macros_on");
4699bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4701 if (parseIdentifier(Name))
4702 return TokError(
"expected identifier in '.macro' directive");
4711 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4713 "' should be the last parameter");
4717 return TokError(
"expected identifier in '.macro' directive");
4720 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4722 return TokError(
"macro '" + Name +
"' has multiple parameters"
4731 QualLoc = Lexer.
getLoc();
4732 if (parseIdentifier(Qualifier))
4733 return Error(QualLoc,
"missing parameter qualifier for "
4734 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4736 if (Qualifier ==
"req")
4738 else if (Qualifier ==
"vararg")
4741 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4742 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4750 ParamLoc = Lexer.
getLoc();
4751 if (parseMacroArgument(
Parameter.Value,
false ))
4755 Warning(ParamLoc,
"pointless default value for required parameter "
4756 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4769 AsmToken EndToken, StartToken = getTok();
4770 unsigned MacroDepth = 0;
4780 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4785 if (getTok().getIdentifier() ==
".endm" ||
4786 getTok().getIdentifier() ==
".endmacro") {
4787 if (MacroDepth == 0) {
4788 EndToken = getTok();
4791 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4798 }
else if (getTok().getIdentifier() ==
".macro") {
4804 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4808 eatToEndOfStatement();
4812 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4817 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4818 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4819 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4840void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4846 if (NParameters == 0)
4849 bool NamedParametersFound =
false;
4850 bool PositionalParametersFound =
false;
4855 while (!Body.
empty()) {
4857 std::size_t
End = Body.
size(), Pos = 0;
4858 for (; Pos !=
End; ++Pos) {
4861 if (Body[Pos] ==
'\\' && Pos + 1 !=
End)
4865 if (Body[Pos] !=
'$' || Pos + 1 ==
End)
4867 char Next = Body[Pos + 1];
4869 isdigit(
static_cast<unsigned char>(
Next)))
4877 if (Body[Pos] ==
'$') {
4878 switch (Body[Pos + 1]) {
4885 PositionalParametersFound =
true;
4890 PositionalParametersFound =
true;
4900 const char *Begin = Body.
data() + Pos + 1;
4901 StringRef
Argument(Begin,
I - (Pos + 1));
4904 if (Parameters[Index].Name == Argument)
4907 if (Index == NParameters) {
4908 if (Body[Pos + 1] ==
'(' && Pos + 2 !=
End && Body[Pos + 2] ==
')')
4914 NamedParametersFound =
true;
4922 if (!NamedParametersFound && PositionalParametersFound)
4923 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4924 "used in macro body, possible positional parameter "
4925 "found in body which will have no effect");
4930bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4934 if (!isInsideMacroInstantiation())
4935 return TokError(
"unexpected '" + Directive +
"' in file, "
4936 "no current macro definition");
4939 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4940 TheCondState = TheCondStack.back();
4941 TheCondStack.pop_back();
4951bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4953 return TokError(
"unexpected token in '" + Directive +
"' directive");
4957 if (isInsideMacroInstantiation()) {
4964 return TokError(
"unexpected '" + Directive +
"' in file, "
4965 "no current macro definition");
4970bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4973 if (parseTokenLoc(Loc) ||
4974 check(parseIdentifier(Name), Loc,
4975 "expected identifier in '.purgem' directive") ||
4980 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4984 <<
"Un-defining macro: " << Name <<
"\n");
4990bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4991 SMLoc NumBytesLoc = Lexer.
getLoc();
4992 const MCExpr *NumBytes;
4993 if (checkForValidSection() || parseExpression(NumBytes))
4996 int64_t FillExpr = 0;
4998 if (parseAbsoluteExpression(FillExpr))
5004 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
5011bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
5012 SMLoc NumValuesLoc = Lexer.
getLoc();
5014 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5017 if (NumValues < 0) {
5018 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5025 const MCExpr *
Value;
5026 SMLoc ExprLoc = getLexer().getLoc();
5027 if (parseExpression(
Value))
5033 uint64_t IntValue = MCE->getValue();
5035 return Error(ExprLoc,
"literal value out of range for directive");
5036 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5037 getStreamer().emitIntValue(IntValue,
Size);
5039 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5040 getStreamer().emitValue(
Value,
Size, ExprLoc);
5048bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
5049 SMLoc NumValuesLoc = Lexer.
getLoc();
5051 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5054 if (NumValues < 0) {
5055 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5063 if (parseRealValue(Semantics, AsInt) || parseEOL())
5066 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5075bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
5076 SMLoc NumValuesLoc = Lexer.
getLoc();
5078 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
5082 if (NumValues < 0) {
5083 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5087 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5088 getStreamer().emitFill(
Size, 0);
5095bool AsmParser::parseDirectiveLEB128(
bool Signed) {
5096 if (checkForValidSection())
5099 auto parseOp = [&]() ->
bool {
5100 const MCExpr *
Value;
5101 if (parseExpression(
Value))
5104 getStreamer().emitSLEB128Value(
Value);
5106 getStreamer().emitULEB128Value(
Value);
5110 return parseMany(parseOp);
5115bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
5116 auto parseOp = [&]() ->
bool {
5118 SMLoc Loc = getTok().getLoc();
5119 if (parseIdentifier(Name))
5120 return Error(Loc,
"expected identifier");
5122 if (discardLTOSymbol(Name))
5130 return Error(Loc,
"non-local symbol required");
5132 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
5133 return Error(Loc,
"unable to emit symbol attribute");
5137 return parseMany(parseOp);
5142bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5143 if (checkForValidSection())
5146 SMLoc IDLoc = getLexer().getLoc();
5149 return TokError(
"expected identifier in directive");
5155 SMLoc SizeLoc = getLexer().getLoc();
5156 if (parseAbsoluteExpression(
Size))
5159 int64_t Pow2Alignment = 0;
5160 SMLoc Pow2AlignmentLoc;
5163 Pow2AlignmentLoc = getLexer().getLoc();
5164 if (parseAbsoluteExpression(Pow2Alignment))
5169 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5175 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5176 Pow2Alignment =
Log2_64(Pow2Alignment);
5177 }
else if (Pow2Alignment < 0 || Pow2Alignment > 63) {
5178 return Error(Pow2AlignmentLoc,
5179 "log2 alignment must be in the range [0, 63]");
5189 return Error(SizeLoc,
"size must be non-negative");
5193 return Error(IDLoc,
"invalid symbol redefinition");
5197 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5208bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5209 StringRef Str = parseStringToEndOfStatement();
5214 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5217 return Error(DirectiveLoc,
5218 ".abort '" + Str +
"' detected. Assembly stopping");
5223bool AsmParser::parseDirectiveInclude() {
5226 SMLoc IncludeLoc = getTok().getLoc();
5229 "expected string in '.include' directive") ||
5232 "unexpected token in '.include' directive") ||
5235 check(enterIncludeFile(
Filename), IncludeLoc,
5236 "Could not find include file '" +
Filename +
"'"))
5244bool AsmParser::parseDirectiveIncbin() {
5247 SMLoc IncbinLoc = getTok().getLoc();
5249 "expected string in '.incbin' directive") ||
5254 const MCExpr *
Count =
nullptr;
5255 SMLoc SkipLoc, CountLoc;
5260 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5264 CountLoc = getTok().getLoc();
5265 if (parseExpression(
Count))
5273 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5278 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5284bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5285 TheCondStack.push_back(TheCondState);
5287 if (TheCondState.
Ignore) {
5288 eatToEndOfStatement();
5291 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5301 ExprValue = ExprValue == 0;
5304 ExprValue = ExprValue >= 0;
5307 ExprValue = ExprValue > 0;
5310 ExprValue = ExprValue <= 0;
5313 ExprValue = ExprValue < 0;
5317 TheCondState.
CondMet = ExprValue;
5326bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5327 TheCondStack.push_back(TheCondState);
5330 if (TheCondState.
Ignore) {
5331 eatToEndOfStatement();
5333 StringRef Str = parseStringToEndOfStatement();
5338 TheCondState.
CondMet = ExpectBlank == Str.empty();
5348bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5349 TheCondStack.push_back(TheCondState);
5352 if (TheCondState.
Ignore) {
5353 eatToEndOfStatement();
5355 StringRef Str1 = parseStringToComma();
5360 StringRef Str2 = parseStringToEndOfStatement();
5374bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5375 TheCondStack.push_back(TheCondState);
5378 if (TheCondState.
Ignore) {
5379 eatToEndOfStatement();
5383 return TokError(
"expected string parameter for '.ifeqs' directive");
5384 return TokError(
"expected string parameter for '.ifnes' directive");
5387 StringRef String1 = getTok().getStringContents();
5393 "expected comma after first string for '.ifeqs' directive");
5395 "expected comma after first string for '.ifnes' directive");
5402 return TokError(
"expected string parameter for '.ifeqs' directive");
5403 return TokError(
"expected string parameter for '.ifnes' directive");
5406 StringRef String2 = getTok().getStringContents();
5409 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5418bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5420 TheCondStack.push_back(TheCondState);
5423 if (TheCondState.
Ignore) {
5424 eatToEndOfStatement();
5426 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5444bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5447 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5448 " .if or an .elseif");
5451 bool LastIgnoreState =
false;
5452 if (!TheCondStack.empty())
5453 LastIgnoreState = TheCondStack.back().Ignore;
5454 if (LastIgnoreState || TheCondState.
CondMet) {
5455 TheCondState.
Ignore =
true;
5456 eatToEndOfStatement();
5459 if (parseAbsoluteExpression(ExprValue))
5465 TheCondState.
CondMet = ExprValue;
5474bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5480 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5481 " an .if or an .elseif");
5483 bool LastIgnoreState =
false;
5484 if (!TheCondStack.empty())
5485 LastIgnoreState = TheCondStack.back().Ignore;
5486 if (LastIgnoreState || TheCondState.
CondMet)
5487 TheCondState.
Ignore =
true;
5489 TheCondState.
Ignore =
false;
5496bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5509bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5510 if (!TheCondStack.empty()) {
5511 if (TheCondStack.back().Ignore) {
5512 eatToEndOfStatement();
5518 return Error(L,
".err encountered");
5520 StringRef Message =
".error directive invoked in source file";
5523 return TokError(
".error argument must be a string");
5525 Message = getTok().getStringContents();
5529 return Error(L, Message);
5534bool AsmParser::parseDirectiveWarning(SMLoc L) {
5535 if (!TheCondStack.empty()) {
5536 if (TheCondStack.back().Ignore) {
5537 eatToEndOfStatement();
5542 StringRef Message =
".warning directive invoked in source file";
5546 return TokError(
".warning argument must be a string");
5548 Message = getTok().getStringContents();
5559bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5564 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5566 if (!TheCondStack.empty()) {
5567 TheCondState = TheCondStack.back();
5568 TheCondStack.pop_back();
5574void AsmParser::initializeDirectiveKindMap() {
5581 DirectiveKindMap[
".set"] = DK_SET;
5582 DirectiveKindMap[
".equ"] = DK_EQU;
5583 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5584 DirectiveKindMap[
".ascii"] = DK_ASCII;
5585 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5586 DirectiveKindMap[
".string"] = DK_STRING;
5587 DirectiveKindMap[
".byte"] = DK_BYTE;
5588 DirectiveKindMap[
".base64"] = DK_BASE64;
5589 DirectiveKindMap[
".short"] = DK_SHORT;
5590 DirectiveKindMap[
".value"] = DK_VALUE;
5591 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5592 DirectiveKindMap[
".long"] = DK_LONG;
5593 DirectiveKindMap[
".int"] = DK_INT;
5594 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5595 DirectiveKindMap[
".quad"] = DK_QUAD;
5596 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5597 DirectiveKindMap[
".octa"] = DK_OCTA;
5598 DirectiveKindMap[
".single"] = DK_SINGLE;
5599 DirectiveKindMap[
".float"] = DK_FLOAT;
5600 DirectiveKindMap[
".double"] = DK_DOUBLE;
5601 DirectiveKindMap[
".align"] = DK_ALIGN;
5602 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5603 DirectiveKindMap[
".balign"] = DK_BALIGN;
5604 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5605 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5606 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5607 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5608 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5609 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5610 DirectiveKindMap[
".org"] = DK_ORG;
5611 DirectiveKindMap[
".fill"] = DK_FILL;
5612 DirectiveKindMap[
".zero"] = DK_ZERO;
5613 DirectiveKindMap[
".extern"] = DK_EXTERN;
5614 DirectiveKindMap[
".globl"] = DK_GLOBL;
5615 DirectiveKindMap[
".global"] = DK_GLOBAL;
5616 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5617 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5618 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5619 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5620 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5621 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5622 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5623 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5624 DirectiveKindMap[
".cold"] = DK_COLD;
5625 DirectiveKindMap[
".comm"] = DK_COMM;
5626 DirectiveKindMap[
".common"] = DK_COMMON;
5627 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5628 DirectiveKindMap[
".abort"] = DK_ABORT;
5629 DirectiveKindMap[
".include"] = DK_INCLUDE;
5630 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5631 DirectiveKindMap[
".code16"] = DK_CODE16;
5632 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5633 DirectiveKindMap[
".rept"] = DK_REPT;
5634 DirectiveKindMap[
".rep"] = DK_REPT;
5635 DirectiveKindMap[
".irp"] = DK_IRP;
5636 DirectiveKindMap[
".irpc"] = DK_IRPC;
5637 DirectiveKindMap[
".endr"] = DK_ENDR;
5638 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5639 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5640 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5641 DirectiveKindMap[
".if"] = DK_IF;
5642 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5643 DirectiveKindMap[
".ifge"] = DK_IFGE;
5644 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5645 DirectiveKindMap[
".ifle"] = DK_IFLE;
5646 DirectiveKindMap[
".iflt"] = DK_IFLT;
5647 DirectiveKindMap[
".ifne"] = DK_IFNE;
5648 DirectiveKindMap[
".ifb"] = DK_IFB;
5649 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5650 DirectiveKindMap[
".ifc"] = DK_IFC;
5651 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5652 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5653 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5654 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5655 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5656 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5657 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5658 DirectiveKindMap[
".else"] = DK_ELSE;
5659 DirectiveKindMap[
".end"] = DK_END;
5660 DirectiveKindMap[
".endif"] = DK_ENDIF;
5661 DirectiveKindMap[
".skip"] = DK_SKIP;
5662 DirectiveKindMap[
".space"] = DK_SPACE;
5663 DirectiveKindMap[
".file"] = DK_FILE;
5664 DirectiveKindMap[
".line"] = DK_LINE;
5665 DirectiveKindMap[
".loc"] = DK_LOC;
5666 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5667 DirectiveKindMap[
".stabs"] = DK_STABS;
5668 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5669 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5670 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5671 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5672 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5673 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5674 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5675 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5676 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5677 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5678 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5679 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5680 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5681 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5682 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5683 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5684 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5685 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5686 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5687 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5688 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5689 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5690 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5691 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5692 DirectiveKindMap[
".cfi_llvm_register_pair"] = DK_CFI_LLVM_REGISTER_PAIR;
5693 DirectiveKindMap[
".cfi_llvm_vector_registers"] = DK_CFI_LLVM_VECTOR_REGISTERS;
5694 DirectiveKindMap[
".cfi_llvm_vector_offset"] = DK_CFI_LLVM_VECTOR_OFFSET;
5695 DirectiveKindMap[
".cfi_llvm_vector_register_mask"] =
5696 DK_CFI_LLVM_VECTOR_REGISTER_MASK;
5697 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5698 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5699 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5700 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5701 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5702 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5703 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5704 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5705 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5706 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5707 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5708 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5709 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5710 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5711 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5712 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5713 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5714 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5715 DirectiveKindMap[
".macro"] = DK_MACRO;
5716 DirectiveKindMap[
".exitm"] = DK_EXITM;
5717 DirectiveKindMap[
".endm"] = DK_ENDM;
5718 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5719 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5720 DirectiveKindMap[
".err"] = DK_ERR;
5721 DirectiveKindMap[
".error"] = DK_ERROR;
5722 DirectiveKindMap[
".warning"] = DK_WARNING;
5723 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5724 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5725 DirectiveKindMap[
".reloc"] = DK_RELOC;
5726 DirectiveKindMap[
".dc"] = DK_DC;
5727 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5728 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5729 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5730 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5731 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5732 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5733 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5734 DirectiveKindMap[
".dcb"] = DK_DCB;
5735 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5736 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5737 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5738 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5739 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5740 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5741 DirectiveKindMap[
".ds"] = DK_DS;
5742 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5743 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5744 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5745 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5746 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5747 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5748 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5749 DirectiveKindMap[
".print"] = DK_PRINT;
5750 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5751 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5752 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5753 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5754 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5755 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5758MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5759 AsmToken EndToken, StartToken = getTok();
5761 unsigned NestLevel = 0;
5765 printError(DirectiveLoc,
"no matching '.endr' in definition");
5770 StringRef Ident = getTok().getIdentifier();
5771 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5774 }
else if (Ident ==
".endr") {
5775 if (NestLevel == 0) {
5776 EndToken = getTok();
5780 printError(getTok().getLoc(),
"expected newline");
5788 eatToEndOfStatement();
5793 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5797 return &MacroLikeBodies.back();
5800void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5801 raw_svector_ostream &OS) {
5804 std::unique_ptr<MemoryBuffer> Instantiation =
5809 MacroInstantiation *
MI =
new MacroInstantiation{
5810 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5811 ActiveMacros.push_back(
MI);
5821bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5822 const MCExpr *CountExpr;
5823 SMLoc CountLoc = getTok().getLoc();
5824 if (parseExpression(CountExpr))
5828 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5829 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5832 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5836 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5842 SmallString<256> Buf;
5843 raw_svector_ostream OS(Buf);
5846 if (expandMacro(OS, *M, {}, {},
false))
5849 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5856bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5858 MCAsmMacroArguments
A;
5859 if (check(parseIdentifier(
Parameter.Name),
5860 "expected identifier in '.irp' directive") ||
5861 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5865 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5871 SmallString<256> Buf;
5872 raw_svector_ostream OS(Buf);
5874 for (
const MCAsmMacroArgument &Arg :
A) {
5877 if (expandMacro(OS, *M, Parameter, Arg,
true))
5881 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5888bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5890 MCAsmMacroArguments
A;
5892 if (check(parseIdentifier(
Parameter.Name),
5893 "expected identifier in '.irpc' directive") ||
5894 parseComma() || parseMacroArguments(
nullptr,
A))
5897 if (
A.size() != 1 ||
A.front().size() != 1)
5898 return TokError(
"unexpected token in '.irpc' directive");
5903 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5909 SmallString<256> Buf;
5910 raw_svector_ostream OS(Buf);
5913 :
A[0][0].getString();
5915 MCAsmMacroArgument Arg;
5920 if (expandMacro(OS, *M, Parameter, Arg,
true))
5924 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5929bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5930 if (ActiveMacros.empty())
5931 return TokError(
"unmatched '.endr' directive");
5941bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
5943 const MCExpr *
Value;
5944 SMLoc ExprLoc = getLexer().getLoc();
5945 if (parseExpression(
Value))
5949 return Error(ExprLoc,
"unexpected expression in _emit");
5952 return Error(ExprLoc,
"literal value out of range for directive");
5958bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
5959 const MCExpr *
Value;
5960 SMLoc ExprLoc = getLexer().getLoc();
5961 if (parseExpression(
Value))
5965 return Error(ExprLoc,
"unexpected expression in align");
5968 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5974bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5975 const AsmToken StrTok = getTok();
5978 return Error(DirectiveLoc,
"expected double quoted string after .print");
5985bool AsmParser::parseDirectiveAddrsig() {
5988 getStreamer().emitAddrsig();
5992bool AsmParser::parseDirectiveAddrsigSym() {
5994 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
5996 getStreamer().emitAddrsigSym(Sym);
6002bool AsmParser::parseDirectiveBundleAlignMode() {
6006 SMLoc ExprLoc = getLexer().getLoc();
6007 int64_t AlignSizePow2;
6008 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
6010 check(AlignSizePow2 < 1 || AlignSizePow2 > 30, ExprLoc,
6011 "invalid bundle alignment size (expected between 1 and 30)"))
6020bool AsmParser::parseDirectiveBundleLock() {
6021 if (checkForValidSection())
6023 bool AlignToEnd =
false;
6026 SMLoc Loc = getTok().getLoc();
6027 const char *InvalidOptionError =
"invalid option for `.bundle_lock`";
6030 if (check(parseIdentifier(Option), Loc, InvalidOptionError) ||
6031 check(Option !=
"align_to_end", Loc, InvalidOptionError) || parseEOL())
6036 getStreamer().emitBundleLock(AlignToEnd, getTargetParser().getSTI());
6042bool AsmParser::parseDirectiveBundleUnlock() {
6043 if (checkForValidSection() || parseEOL())
6046 getStreamer().emitBundleUnlock(getTargetParser().getSTI());
6050bool AsmParser::parseDirectivePseudoProbe() {
6056 if (parseIntToken(
Guid))
6058 if (parseIntToken(Index))
6060 if (parseIntToken(
Type))
6062 if (parseIntToken(Attr))
6074 int64_t CallerGuid = 0;
6076 CallerGuid = getTok().getIntVal();
6084 int64_t CallerProbeId = 0;
6086 CallerProbeId = getTok().getIntVal();
6096 if (parseIdentifier(FnName))
6097 return Error(getLexer().getLoc(),
"expected identifier");
6103 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
6104 InlineStack, FnSym);
6113bool AsmParser::parseDirectiveLTODiscard() {
6114 auto ParseOp = [&]() ->
bool {
6116 SMLoc Loc = getTok().getLoc();
6117 if (parseIdentifier(Name))
6118 return Error(Loc,
"expected identifier");
6119 LTODiscardSymbols.
insert(Name);
6123 LTODiscardSymbols.
clear();
6124 return parseMany(ParseOp);
6150bool AsmParser::parseMSInlineAsm(
6151 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
6152 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
6153 SmallVectorImpl<std::string> &Constraints,
6154 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
6155 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
6156 SmallVector<void *, 4> InputDecls;
6157 SmallVector<void *, 4> OutputDecls;
6158 SmallVector<bool, 4> InputDeclsAddressOf;
6159 SmallVector<bool, 4> OutputDeclsAddressOf;
6160 SmallVector<std::string, 4> InputConstraints;
6161 SmallVector<std::string, 4> OutputConstraints;
6170 unsigned InputIdx = 0;
6171 unsigned OutputIdx = 0;
6174 if (parseCurlyBlockScope(AsmStrRewrites))
6177 ParseStatementInfo
Info(&AsmStrRewrites);
6178 bool StatementErr = parseStatement(Info, &SI);
6180 if (StatementErr ||
Info.ParseError) {
6182 printPendingErrors();
6187 assert(!hasPendingError() &&
"unexpected error from parseStatement");
6189 if (
Info.Opcode == ~0U)
6195 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
6196 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
6200 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
6201 unsigned NumDefs =
Desc.getNumDefs();
6210 if (SymName.
empty())
6218 if (Operand.
isImm()) {
6226 bool isOutput = (i == 1) &&
Desc.mayStore();
6233 OutputConstraints.
push_back((
"=" + Constraint).str());
6240 if (
Desc.operands()[i - 1].isBranchTarget())
6254 NumOutputs = OutputDecls.
size();
6255 NumInputs = InputDecls.
size();
6260 Clobbers.
assign(ClobberRegs.
size(), std::string());
6261 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6262 raw_string_ostream OS(Clobbers[
I]);
6267 if (NumOutputs || NumInputs) {
6268 unsigned NumExprs = NumOutputs + NumInputs;
6269 OpDecls.resize(NumExprs);
6270 Constraints.
resize(NumExprs);
6271 for (
unsigned i = 0; i < NumOutputs; ++i) {
6272 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6273 Constraints[i] = OutputConstraints[i];
6275 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6276 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6277 Constraints[
j] = InputConstraints[i];
6282 std::string AsmStringIR;
6283 raw_string_ostream OS(AsmStringIR);
6284 StringRef ASMString =
6286 const char *AsmStart = ASMString.
begin();
6287 const char *AsmEnd = ASMString.
end();
6289 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6290 const AsmRewrite &AR = *
I;
6297 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6300 if (
unsigned Len = Loc - AsmStart)
6301 OS << StringRef(AsmStart, Len);
6305 AsmStart = Loc + AR.
Len;
6309 unsigned AdditionalSkip = 0;
6331 size_t OffsetLen = OffsetName.
size();
6332 auto rewrite_it = std::find_if(
6333 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6334 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6335 (FusingAR.Kind == AOK_Input ||
6336 FusingAR.Kind == AOK_CallInput);
6338 if (rewrite_it == AsmStrRewrites.
end()) {
6339 OS <<
"offset " << OffsetName;
6341 OS <<
"${" << InputIdx++ <<
":P}";
6342 rewrite_it->Done =
true;
6344 OS <<
'$' << InputIdx++;
6345 rewrite_it->Done =
true;
6358 OS <<
"${" << InputIdx++ <<
":P}";
6360 OS <<
'$' << InputIdx++;
6363 OS <<
"${" << InputIdx++ <<
":P}";
6367 OS <<
"${" << OutputIdx++ <<
":P}";
6369 OS <<
'$' << OutputIdx++;
6374 case 8: OS <<
"byte ptr ";
break;
6375 case 16: OS <<
"word ptr ";
break;
6376 case 32: OS <<
"dword ptr ";
break;
6377 case 64: OS <<
"qword ptr ";
break;
6378 case 80: OS <<
"xword ptr ";
break;
6379 case 128: OS <<
"xmmword ptr ";
break;
6380 case 256: OS <<
"ymmword ptr ";
break;
6390 if (
getContext().getAsmInfo().getAlignmentIsInBytes())
6395 unsigned Val = AR.
Val;
6397 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6398 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6410 AsmStart = Loc + AR.
Len + AdditionalSkip;
6414 if (AsmStart != AsmEnd)
6415 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6417 AsmString = std::move(AsmStringIR);
6421bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6422 MCAsmParserSemaCallback *SI) {
6423 AsmToken LabelTok = getTok();
6424 SMLoc LabelLoc = LabelTok.
getLoc();
6427 if (parseIdentifier(LabelVal))
6428 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6433 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6442 return Error(LabelLoc,
6443 "Cannot have just a label for an HLASM inline asm statement");
6449 Out.emitLabel(Sym, LabelLoc);
6453 if (enabledGenDwarfForAssembly())
6460bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6461 MCAsmParserSemaCallback *SI) {
6462 AsmToken OperationEntryTok = Lexer.
getTok();
6463 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6464 StringRef OperationEntryVal;
6467 if (parseIdentifier(OperationEntryVal))
6468 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6474 return parseAndMatchAndEmitTargetInstruction(
6475 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6478bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6479 MCAsmParserSemaCallback *SI) {
6480 assert(!hasPendingError() &&
"parseStatement started with pending error");
6483 bool ShouldParseAsHLASMLabel =
false;
6492 ShouldParseAsHLASMLabel =
true;
6498 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6499 getTok().getString().
front() ==
'\n')
6514 if (getTok().getString().
front() ==
'\n' ||
6515 getTok().getString().
front() ==
'\r') {
6524 if (ShouldParseAsHLASMLabel) {
6527 if (parseAsHLASMLabel(Info, SI)) {
6530 eatToEndOfStatement();
6535 return parseAsMachineInstruction(Info, SI);
6547 return Parser.
TokError(
"missing expression");
6553 return Parser.
Error(
6554 EqualLoc,
"relocation specifier not permitted in symbol equating");
6562 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6568 }
else if (Name ==
".") {
6583 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6584 return new HLASMAsmParser(SM,
C, Out, MAI, CB);
6586 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
unsigned getAsmMacroMaxNestingDepth() 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.
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
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)
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.