81typedef std::vector<AsmToken> MCAsmMacroArgument;
82typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
86struct MacroInstantiation {
88 SMLoc InstantiationLoc;
97 size_t CondStackDepth;
100struct ParseStatementInfo {
105 unsigned Opcode = ~0
U;
108 bool ParseError =
false;
110 SmallVectorImpl<AsmRewrite> *AsmRewrites =
nullptr;
112 ParseStatementInfo() =
delete;
113 ParseStatementInfo(SmallVectorImpl<AsmRewrite> *rewrites)
114 : AsmRewrites(rewrites) {}
121 void *SavedDiagContext;
122 std::unique_ptr<MCAsmParserExtension> PlatformParser;
123 std::unique_ptr<MCAsmParserExtension> LFIParser;
125 std::optional<SMLoc> CFIStartProcLoc;
131 AsmCond TheCondState;
132 std::vector<AsmCond> TheCondStack;
137 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
140 std::vector<MacroInstantiation*> ActiveMacros;
143 std::deque<MCAsmMacro> MacroLikeBodies;
146 unsigned MacrosEnabledFlag : 1;
149 unsigned NumOfMacroInstantiations = 0;
152 struct CppHashInfoTy {
157 CppHashInfoTy() : LineNumber(0), Buf(0) {}
159 CppHashInfoTy CppHashInfo;
162 bool HadCppHashFilename =
false;
167 SmallSet<StringRef, 2> LTODiscardSymbols;
170 unsigned AssemblerDialect = ~0
U;
173 bool IsDarwin =
false;
176 bool ParsingMSInlineAsm =
false;
179 bool ReportedInconsistentMD5 =
false;
182 bool AltMacroMode =
false;
185 virtual bool parseStatement(ParseStatementInfo &Info,
186 MCAsmParserSemaCallback *SI);
191 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
192 StringRef IDVal, AsmToken ID,
198 bool enabledGenDwarfForAssembly();
201 AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
202 const MCAsmInfo &MAI,
unsigned CB);
203 AsmParser(
const AsmParser &) =
delete;
204 AsmParser &operator=(
const AsmParser &) =
delete;
205 ~AsmParser()
override;
207 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
209 void addDirectiveHandler(StringRef Directive,
210 ExtensionDirectiveHandler Handler)
override {
211 ExtensionDirectiveMap[Directive] = std::move(Handler);
214 void addAliasForDirective(StringRef Directive, StringRef Alias)
override {
215 DirectiveKindMap[Directive.
lower()] = DirectiveKindMap[Alias.
lower()];
221 CodeViewContext &getCVContext() {
return Ctx.getCVContext(); }
223 unsigned getAssemblerDialect()
override {
224 if (AssemblerDialect == ~0U)
225 return MAI.getAssemblerDialect();
227 return AssemblerDialect;
229 void setAssemblerDialect(
unsigned i)
override {
230 AssemblerDialect = i;
233 void Note(SMLoc L,
const Twine &
Msg, SMRange
Range = {})
override;
235 bool printError(SMLoc L,
const Twine &
Msg, SMRange
Range = {})
override;
237 const AsmToken &Lex()
override;
239 void setParsingMSInlineAsm(
bool V)
override {
240 ParsingMSInlineAsm =
V;
243 Lexer.setLexMasmIntegers(V);
245 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
247 bool discardLTOSymbol(StringRef Name)
const override {
248 return LTODiscardSymbols.contains(Name);
251 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
253 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
254 SmallVectorImpl<std::string> &Constraints,
255 SmallVectorImpl<std::string> &Clobbers,
256 const MCInstrInfo *MII, MCInstPrinter *IP,
257 MCAsmParserSemaCallback &SI)
override;
259 bool parseExpression(
const MCExpr *&Res);
260 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
261 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
262 AsmTypeInfo *TypeInfo)
override;
263 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
264 bool parseAbsoluteExpression(int64_t &Res)
override;
268 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
272 bool parseIdentifier(StringRef &Res)
override;
273 void eatToEndOfStatement()
override;
275 bool checkForValidSection()
override;
280 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
281 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
283 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
285 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
290 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
293 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
296 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
302 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
305 void handleMacroExit();
308 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
311 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
313 void printMacroInstantiations();
315 SMRange
Range = {})
const {
322 bool enterIncludeFile(
const std::string &
Filename);
326 bool processIncbinFile(
const std::string &
Filename, int64_t Skip = 0,
327 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
335 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
340 StringRef parseStringToEndOfStatement()
override;
344 StringRef parseStringToComma();
346 enum class AssignmentKind {
353 bool parseAssignment(StringRef Name, AssignmentKind Kind);
358 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
359 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
360 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
362 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
364 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
365 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
425 DK_BUNDLE_ALIGN_MODE,
439 DK_WEAK_DEF_CAN_BE_HIDDEN,
480 DK_CV_INLINE_SITE_ID,
483 DK_CV_INLINE_LINETABLE,
488 DK_CV_FILECHECKSUM_OFFSET,
494 DK_CFI_DEF_CFA_OFFSET,
495 DK_CFI_ADJUST_CFA_OFFSET,
496 DK_CFI_DEF_CFA_REGISTER,
497 DK_CFI_LLVM_DEF_ASPACE_CFA,
500 DK_CFI_LLVM_REGISTER_PAIR,
501 DK_CFI_LLVM_VECTOR_REGISTERS,
502 DK_CFI_LLVM_VECTOR_OFFSET,
503 DK_CFI_LLVM_VECTOR_REGISTER_MASK,
506 DK_CFI_REMEMBER_STATE,
507 DK_CFI_RESTORE_STATE,
511 DK_CFI_RETURN_COLUMN,
538 DK_LTO_SET_CONDITIONAL,
539 DK_CFI_MTE_TAGGED_FRAME,
547 StringMap<DirectiveKind> DirectiveKindMap;
550 enum CVDefRangeType {
552 CVDR_DEFRANGE_REGISTER,
553 CVDR_DEFRANGE_FRAMEPOINTER_REL,
554 CVDR_DEFRANGE_SUBFIELD_REGISTER,
555 CVDR_DEFRANGE_REGISTER_REL,
556 CVDR_DEFRANGE_REGISTER_REL_INDIR
561 StringMap<CVDefRangeType> CVDefRangeTypeMap;
564 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
565 bool parseDirectiveBase64();
566 bool parseDirectiveReloc(SMLoc DirectiveLoc);
567 bool parseDirectiveValue(StringRef IDVal,
569 bool parseDirectiveOctaValue(StringRef IDVal);
570 bool parseDirectiveRealValue(StringRef IDVal,
571 const fltSemantics &);
572 bool parseDirectiveFill();
573 bool parseDirectiveZero();
575 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
576 bool parseDirectiveOrg();
578 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
579 bool parseDirectivePrefAlign();
582 bool parseDirectiveFile(SMLoc DirectiveLoc);
583 bool parseDirectiveLine();
584 bool parseDirectiveLoc();
585 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
586 bool parseDirectiveStabs();
590 bool parseDirectiveCVFile();
591 bool parseDirectiveCVFuncId();
592 bool parseDirectiveCVInlineSiteId();
593 bool parseDirectiveCVLoc();
594 bool parseDirectiveCVLinetable();
595 bool parseDirectiveCVInlineLinetable();
596 bool parseDirectiveCVDefRange();
597 bool parseDirectiveCVString();
598 bool parseDirectiveCVStringTable();
599 bool parseDirectiveCVFileChecksums();
600 bool parseDirectiveCVFileChecksumOffset();
601 bool parseDirectiveCVFPOData();
604 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
605 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
606 bool parseDirectiveCFISections();
607 bool parseDirectiveCFIStartProc();
608 bool parseDirectiveCFIEndProc();
609 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
610 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
611 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
612 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
613 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
614 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
615 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
616 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
617 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
618 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
619 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
620 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
621 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
622 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
623 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
624 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
625 bool parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc);
626 bool parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc);
627 bool parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc);
628 bool parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc);
629 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
630 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
633 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
634 bool parseDirectiveExitMacro(StringRef Directive);
635 bool parseDirectiveEndMacro(StringRef Directive);
636 bool parseDirectiveMacro(SMLoc DirectiveLoc);
637 bool parseDirectiveMacrosOnOff(StringRef Directive);
639 bool parseDirectiveAltmacro(StringRef Directive);
642 bool parseDirectiveSpace(StringRef IDVal);
645 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
646 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
648 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
651 bool parseDirectiveLEB128(
bool Signed);
657 bool parseDirectiveComm(
bool IsLocal);
659 bool parseDirectiveAbort(SMLoc DirectiveLoc);
660 bool parseDirectiveInclude();
661 bool parseDirectiveIncbin();
664 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
666 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
668 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
670 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
672 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
673 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
674 bool parseDirectiveElse(SMLoc DirectiveLoc);
675 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
676 bool parseEscapedString(std::string &
Data)
override;
677 bool parseAngleBracketString(std::string &
Data)
override;
680 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
681 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
682 raw_svector_ostream &OS);
683 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
684 bool parseDirectiveIrp(SMLoc DirectiveLoc);
685 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
686 bool parseDirectiveEndr(SMLoc DirectiveLoc);
689 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,
693 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
696 bool parseDirectiveEnd(SMLoc DirectiveLoc);
699 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
702 bool parseDirectiveWarning(SMLoc DirectiveLoc);
705 bool parseDirectivePrint(SMLoc DirectiveLoc);
708 bool parseDirectivePseudoProbe();
711 bool parseDirectiveLTODiscard();
714 bool parseDirectiveAddrsig();
715 bool parseDirectiveAddrsigSym();
718 bool parseDirectiveBundleAlignMode();
720 bool parseDirectiveBundleLock();
722 bool parseDirectiveBundleUnlock();
724 void initializeDirectiveKindMap();
725 void initializeCVDefRangeTypeMap();
728class HLASMAsmParser final :
public AsmParser {
733 void lexLeadingSpaces() {
738 bool parseAsHLASMLabel(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI);
739 bool parseAsMachineInstruction(ParseStatementInfo &Info,
740 MCAsmParserSemaCallback *SI);
743 HLASMAsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
744 const MCAsmInfo &MAI,
unsigned CB = 0)
745 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
746 Lexer.setSkipSpace(
false);
747 Lexer.setAllowHashInIdentifier(
true);
748 Lexer.setLexHLASMIntegers(
true);
749 Lexer.setLexHLASMStrings(
true);
752 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
754 bool parseStatement(ParseStatementInfo &Info,
755 MCAsmParserSemaCallback *SI)
override;
768 :
MCAsmParser(Ctx, Out, SM, MAI), CurBuffer(CB ? CB : SM.getMainFileID()),
769 MacrosEnabledFlag(
true) {
772 SavedDiagHandler =
SrcMgr.getDiagHandler();
773 SavedDiagContext =
SrcMgr.getDiagContext();
781 switch (Ctx.getObjectFileType()) {
782 case MCContext::IsCOFF:
783 PlatformParser.reset(createCOFFAsmParser());
785 case MCContext::IsMachO:
786 PlatformParser.reset(createDarwinAsmParser());
789 case MCContext::IsELF:
790 PlatformParser.reset(createELFAsmParser());
792 case MCContext::IsGOFF:
793 PlatformParser.reset(createGOFFAsmParser());
795 case MCContext::IsSPIRV:
797 "Need to implement createSPIRVAsmParser for SPIRV format.");
799 case MCContext::IsWasm:
800 PlatformParser.reset(createWasmAsmParser());
802 case MCContext::IsXCOFF:
803 PlatformParser.reset(createXCOFFAsmParser());
805 case MCContext::IsDXContainer:
806 report_fatal_error(
"DXContainer is not supported yet");
810 PlatformParser->Initialize(*
this);
812 LFIParser.reset(createLFIAsmParser(Out.getLFIRewriter()));
813 LFIParser->Initialize(*this);
815 initializeDirectiveKindMap();
816 initializeCVDefRangeTypeMap();
819AsmParser::~AsmParser() {
820 assert((HadError || ActiveMacros.empty()) &&
821 "Unexpected active macro instantiation!");
830void AsmParser::printMacroInstantiations() {
832 for (MacroInstantiation *M :
reverse(ActiveMacros))
834 "while in macro instantiation");
837void AsmParser::Note(SMLoc L,
const Twine &
Msg, SMRange
Range) {
838 printPendingErrors();
840 printMacroInstantiations();
843bool AsmParser::Warning(SMLoc L,
const Twine &
Msg, SMRange
Range) {
844 if(getTargetParser().getTargetOptions().MCNoWarn)
846 if (getTargetParser().getTargetOptions().MCFatalWarnings)
849 printMacroInstantiations();
853bool AsmParser::printError(SMLoc L,
const Twine &
Msg, SMRange
Range) {
856 printMacroInstantiations();
860bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
861 std::string IncludedFile;
875bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
876 const MCExpr *
Count, SMLoc Loc) {
878 if (SymbolScanningMode)
884 std::string IncludedFile;
891 StringRef Bytes = (*BufOrErr)->getBuffer();
895 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
896 return Error(Loc,
"expected absolute expression");
898 return Warning(Loc,
"negative count has no effect");
901 getStreamer().emitBytes(Bytes);
905void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
911const AsmToken &AsmParser::Lex() {
918 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
923 const AsmToken *tok = &Lexer.
Lex();
936 if (ParentIncludeLoc != SMLoc()) {
937 jumpToLoc(ParentIncludeLoc);
945bool AsmParser::enabledGenDwarfForAssembly() {
952 if (
getContext().getGenDwarfFileNumber() == 0) {
953 const MCDwarfFile &RootFile =
954 getContext().getMCDwarfLineTable(0).getRootFile();
955 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
962bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
963 LTODiscardSymbols.
clear();
966 if (!NoInitialTextSection)
973 AsmCond StartingCondState = TheCondState;
981 MCSection *Sec = getStreamer().getCurrentSectionOnly();
984 getStreamer().emitLabel(SectionStartSym);
987 bool InsertResult =
getContext().addGenDwarfSection(Sec);
988 assert(InsertResult &&
".text section should not have debug info yet");
992 getTargetParser().onBeginOfFile();
996 ParseStatementInfo
Info(&AsmStrRewrites);
997 bool HasError = parseStatement(Info,
nullptr);
1006 printPendingErrors();
1009 if (HasError && !getLexer().justConsumedEOL())
1010 eatToEndOfStatement();
1013 getTargetParser().onEndOfFile();
1014 printPendingErrors();
1017 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1021 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1023 const auto &LineTables =
getContext().getMCDwarfLineTables();
1024 if (!LineTables.empty()) {
1026 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1027 if (
File.Name.empty() && Index != 0)
1028 printError(getTok().getLoc(),
"unassigned file number: " +
1030 " for .file directives");
1042 MCSymbol *Sym = TableEntry.getValue().Symbol;
1051 printError(getTok().getLoc(),
"assembler local symbol '" +
1052 Sym->
getName() +
"' not defined");
1058 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1059 if (std::get<2>(LocSym)->isUndefined()) {
1062 CppHashInfo = std::get<1>(LocSym);
1063 printError(std::get<0>(LocSym),
"directional label undefined");
1069 if (!HadError && !NoFinalize) {
1071 TS->emitConstantPools();
1079bool AsmParser::checkForValidSection() {
1080 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1082 return Error(getTok().getLoc(),
1083 "expected section directive before assembly directive");
1089void AsmParser::eatToEndOfStatement() {
1098StringRef AsmParser::parseStringToEndOfStatement() {
1099 const char *
Start = getTok().getLoc().getPointer();
1105 return StringRef(Start, End - Start);
1108StringRef AsmParser::parseStringToComma() {
1109 const char *
Start = getTok().getLoc().getPointer();
1115 const char *End = getTok().getLoc().getPointer();
1116 return StringRef(Start, End - Start);
1124bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1125 if (parseExpression(Res))
1128 return parseRParen();
1136bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1137 if (parseExpression(Res))
1139 EndLoc = getTok().getEndLoc();
1140 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1151bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1152 AsmTypeInfo *TypeInfo) {
1153 SMLoc FirstTokenLoc = getLexer().getLoc();
1155 switch (FirstTokenKind) {
1157 return TokError(
"unknown token in expression");
1163 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1173 if (parseIdentifier(Identifier)) {
1177 bool ShouldGenerateTempSymbol =
false;
1180 ShouldGenerateTempSymbol =
true;
1182 if (!ShouldGenerateTempSymbol)
1183 return Error(FirstTokenLoc,
"invalid token in expression");
1192 EndLoc = FirstTokenLoc;
1197 std::pair<StringRef, StringRef>
Split;
1202 SMLoc AtLoc = getLexer().getLoc();
1204 if (parseIdentifier(VName))
1205 return Error(AtLoc,
"expected symbol variant after '@'");
1207 Split = std::make_pair(Identifier, VName);
1215 parseIdentifier(VName);
1218 Split = std::make_pair(Identifier, VName);
1226 return Error(getLexer().getLoc(),
"expected a symbol reference");
1230 if (!
Split.second.empty()) {
1232 if (MaybeSpecifier) {
1234 Spec = *MaybeSpecifier;
1237 "invalid variant '" +
Split.second +
"'");
1252 DoInline = TV->inlineAssignedExpr();
1255 return Error(EndLoc,
"unexpected modifier on variable reference");
1266 return TokError(
"literal value out of range for directive");
1268 SMLoc Loc = getTok().getLoc();
1269 int64_t
IntVal = getTok().getIntVal();
1275 StringRef IDVal = getTok().getString();
1277 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1279 if (
Split.first.size() != IDVal.
size()) {
1282 return TokError(
"invalid variant '" +
Split.second +
"'");
1283 IDVal =
Split.first;
1286 if (IDVal ==
"f" || IDVal ==
"b") {
1291 return Error(Loc,
"directional label undefined");
1292 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1300 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1309 return TokError(
"cannot use . as current PC");
1322 return parseParenExpr(Res, EndLoc);
1324 if (!PlatformParser->HasBracketExpressions())
1325 return TokError(
"brackets expression not supported on this target");
1327 return parseBracketExpr(Res, EndLoc);
1330 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1336 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1342 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1349bool AsmParser::parseExpression(
const MCExpr *&Res) {
1351 return parseExpression(Res, EndLoc);
1361 switch (E->getKind()) {
1372 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1373 "' (already modified)");
1424 "Argument to the function cannot be a NULL value");
1426 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1427 (*CharPtr !=
'\0')) {
1428 if (*CharPtr ==
'!')
1432 if (*CharPtr ==
'>') {
1442 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1443 if (AltMacroStr[Pos] ==
'!')
1445 Res += AltMacroStr[Pos];
1453 return TokError(
"expected specifier following '@'");
1455 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1457 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1477bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1480 auto &TS = getTargetParser();
1481 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1489 return TokError(
"unexpected symbol modifier following '@'");
1493 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1495 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1497 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1498 "' (no symbols present)");
1508 if (Res->evaluateAsAbsolute(
Value))
1514bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1516 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1519bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1522 SMLoc StartLoc = Lexer.
getLoc();
1523 if (parseExpression(Expr))
1526 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1527 return Error(StartLoc,
"expected absolute expression");
1534 bool ShouldUseLogicalShr) {
1611 bool ShouldUseLogicalShr) {
1700bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1702 SMLoc StartLoc = Lexer.
getLoc();
1705 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1709 if (TokPrec < Precedence)
1716 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1722 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1723 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1735bool AsmParser::parseStatement(ParseStatementInfo &Info,
1736 MCAsmParserSemaCallback *SI) {
1737 assert(!hasPendingError() &&
"parseStatement started with pending error");
1743 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1744 getTok().getString().
front() ==
'\n')
1750 AsmToken
ID = getTok();
1751 SMLoc IDLoc =
ID.getLoc();
1753 int64_t LocalLabelVal = -1;
1754 StartTokLoc =
ID.getLoc();
1756 return parseCppHashLineFilenameComment(IDLoc,
1757 !isInsideMacroInstantiation());
1761 LocalLabelVal = getTok().getIntVal();
1762 if (LocalLabelVal < 0) {
1763 if (!TheCondState.
Ignore) {
1765 return Error(IDLoc,
"unexpected token at start of statement");
1769 IDVal = getTok().getString();
1772 if (!TheCondState.
Ignore) {
1774 return Error(IDLoc,
"unexpected token at start of statement");
1782 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1784 IDVal =
ID.getString();
1785 }
else if (parseIdentifier(IDVal)) {
1786 if (!TheCondState.
Ignore) {
1788 return Error(IDLoc,
"unexpected token at start of statement");
1797 DirectiveKindMap.find(IDVal.
lower());
1798 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1800 : DirKindIt->getValue();
1811 return parseDirectiveIf(IDLoc, DirKind);
1813 return parseDirectiveIfb(IDLoc,
true);
1815 return parseDirectiveIfb(IDLoc,
false);
1817 return parseDirectiveIfc(IDLoc,
true);
1819 return parseDirectiveIfeqs(IDLoc,
true);
1821 return parseDirectiveIfc(IDLoc,
false);
1823 return parseDirectiveIfeqs(IDLoc,
false);
1825 return parseDirectiveIfdef(IDLoc,
true);
1828 return parseDirectiveIfdef(IDLoc,
false);
1830 return parseDirectiveElseIf(IDLoc);
1832 return parseDirectiveElse(IDLoc);
1834 return parseDirectiveEndIf(IDLoc);
1839 if (TheCondState.
Ignore) {
1840 eatToEndOfStatement();
1850 if (checkForValidSection())
1857 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1865 if (LocalLabelVal == -1) {
1866 if (ParsingMSInlineAsm && SI) {
1867 StringRef RewrittenLabel =
1868 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1870 "We should have an internal name here.");
1873 IDVal = RewrittenLabel;
1883 StringRef CommentStr = parseStringToEndOfStatement();
1894 if (MAI.
isMachO() && CFIStartProcLoc) {
1895 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1896 if (SymM->isExternal() && !SymM->isAltEntry())
1897 return Error(StartTokLoc,
"non-private labels cannot appear between "
1898 ".cfi_startproc / .cfi_endproc pairs") &&
1899 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1902 if (discardLTOSymbol(IDVal))
1905 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1908 if (!getTargetParser().isParsingMSInlineAsm())
1913 if (enabledGenDwarfForAssembly())
1917 getTargetParser().onLabelParsed(Sym);
1926 return parseAssignment(IDVal, AssignmentKind::Equal);
1930 if (areMacrosEnabled())
1931 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1932 return handleMacroEntry(M, IDLoc);
1949 getTargetParser().flushPendingInstructions(getStreamer());
1951 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(ID);
1953 "Should only return Failure iff there was an error");
1961 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1962 ExtensionDirectiveMap.
lookup(IDVal);
1964 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1973 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1975 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1976 case DK_LTO_SET_CONDITIONAL:
1977 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1979 return parseDirectiveAscii(IDVal,
false);
1982 return parseDirectiveAscii(IDVal,
true);
1984 return parseDirectiveBase64();
1987 return parseDirectiveValue(IDVal, 1);
1993 return parseDirectiveValue(IDVal, 2);
1998 return parseDirectiveValue(IDVal, 4);
2001 return parseDirectiveValue(IDVal, 8);
2003 return parseDirectiveValue(
2004 IDVal,
getContext().getAsmInfo().getCodePointerSize());
2006 return parseDirectiveOctaValue(IDVal);
2010 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
2013 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
2015 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2016 return parseDirectiveAlign(IsPow2, 1);
2019 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2020 return parseDirectiveAlign(IsPow2, 4);
2023 return parseDirectiveAlign(
false, 1);
2025 return parseDirectiveAlign(
false, 2);
2027 return parseDirectiveAlign(
false, 4);
2029 return parseDirectiveAlign(
true, 1);
2031 return parseDirectiveAlign(
true, 2);
2033 return parseDirectiveAlign(
true, 4);
2035 return parseDirectivePrefAlign();
2037 return parseDirectiveOrg();
2039 return parseDirectiveFill();
2041 return parseDirectiveZero();
2043 eatToEndOfStatement();
2047 return parseDirectiveSymbolAttribute(
MCSA_Global);
2048 case DK_LAZY_REFERENCE:
2050 case DK_NO_DEAD_STRIP:
2052 case DK_SYMBOL_RESOLVER:
2054 case DK_PRIVATE_EXTERN:
2058 case DK_WEAK_DEFINITION:
2060 case DK_WEAK_REFERENCE:
2062 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2065 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2068 return parseDirectiveComm(
false);
2070 return parseDirectiveComm(
true);
2072 return parseDirectiveAbort(IDLoc);
2074 return parseDirectiveInclude();
2076 return parseDirectiveIncbin();
2079 return TokError(Twine(IDVal) +
2080 " not currently supported for this target");
2082 return parseDirectiveRept(IDLoc, IDVal);
2084 return parseDirectiveIrp(IDLoc);
2086 return parseDirectiveIrpc(IDLoc);
2088 return parseDirectiveEndr(IDLoc);
2089 case DK_BUNDLE_ALIGN_MODE:
2090 return parseDirectiveBundleAlignMode();
2091 case DK_BUNDLE_LOCK:
2092 return parseDirectiveBundleLock();
2093 case DK_BUNDLE_UNLOCK:
2094 return parseDirectiveBundleUnlock();
2096 return parseDirectiveLEB128(
true);
2098 return parseDirectiveLEB128(
false);
2101 return parseDirectiveSpace(IDVal);
2103 return parseDirectiveFile(IDLoc);
2105 return parseDirectiveLine();
2107 return parseDirectiveLoc();
2109 return parseDirectiveLocLabel(IDLoc);
2111 return parseDirectiveStabs();
2113 return parseDirectiveCVFile();
2115 return parseDirectiveCVFuncId();
2116 case DK_CV_INLINE_SITE_ID:
2117 return parseDirectiveCVInlineSiteId();
2119 return parseDirectiveCVLoc();
2120 case DK_CV_LINETABLE:
2121 return parseDirectiveCVLinetable();
2122 case DK_CV_INLINE_LINETABLE:
2123 return parseDirectiveCVInlineLinetable();
2124 case DK_CV_DEF_RANGE:
2125 return parseDirectiveCVDefRange();
2127 return parseDirectiveCVString();
2128 case DK_CV_STRINGTABLE:
2129 return parseDirectiveCVStringTable();
2130 case DK_CV_FILECHECKSUMS:
2131 return parseDirectiveCVFileChecksums();
2132 case DK_CV_FILECHECKSUM_OFFSET:
2133 return parseDirectiveCVFileChecksumOffset();
2134 case DK_CV_FPO_DATA:
2135 return parseDirectiveCVFPOData();
2136 case DK_CFI_SECTIONS:
2137 return parseDirectiveCFISections();
2138 case DK_CFI_STARTPROC:
2139 return parseDirectiveCFIStartProc();
2140 case DK_CFI_ENDPROC:
2141 return parseDirectiveCFIEndProc();
2142 case DK_CFI_DEF_CFA:
2143 return parseDirectiveCFIDefCfa(IDLoc);
2144 case DK_CFI_DEF_CFA_OFFSET:
2145 return parseDirectiveCFIDefCfaOffset(IDLoc);
2146 case DK_CFI_ADJUST_CFA_OFFSET:
2147 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2148 case DK_CFI_DEF_CFA_REGISTER:
2149 return parseDirectiveCFIDefCfaRegister(IDLoc);
2150 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2151 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2153 return parseDirectiveCFIOffset(IDLoc);
2154 case DK_CFI_REL_OFFSET:
2155 return parseDirectiveCFIRelOffset(IDLoc);
2156 case DK_CFI_LLVM_REGISTER_PAIR:
2157 return parseDirectiveCFILLVMRegisterPair(IDLoc);
2158 case DK_CFI_LLVM_VECTOR_REGISTERS:
2159 return parseDirectiveCFILLVMVectorRegisters(IDLoc);
2160 case DK_CFI_LLVM_VECTOR_OFFSET:
2161 return parseDirectiveCFILLVMVectorOffset(IDLoc);
2162 case DK_CFI_LLVM_VECTOR_REGISTER_MASK:
2163 return parseDirectiveCFILLVMVectorRegisterMask(IDLoc);
2164 case DK_CFI_PERSONALITY:
2165 return parseDirectiveCFIPersonalityOrLsda(
true);
2167 return parseDirectiveCFIPersonalityOrLsda(
false);
2168 case DK_CFI_REMEMBER_STATE:
2169 return parseDirectiveCFIRememberState(IDLoc);
2170 case DK_CFI_RESTORE_STATE:
2171 return parseDirectiveCFIRestoreState(IDLoc);
2172 case DK_CFI_SAME_VALUE:
2173 return parseDirectiveCFISameValue(IDLoc);
2174 case DK_CFI_RESTORE:
2175 return parseDirectiveCFIRestore(IDLoc);
2177 return parseDirectiveCFIEscape(IDLoc);
2178 case DK_CFI_RETURN_COLUMN:
2179 return parseDirectiveCFIReturnColumn(IDLoc);
2180 case DK_CFI_SIGNAL_FRAME:
2181 return parseDirectiveCFISignalFrame(IDLoc);
2182 case DK_CFI_UNDEFINED:
2183 return parseDirectiveCFIUndefined(IDLoc);
2184 case DK_CFI_REGISTER:
2185 return parseDirectiveCFIRegister(IDLoc);
2186 case DK_CFI_WINDOW_SAVE:
2187 return parseDirectiveCFIWindowSave(IDLoc);
2189 return parseDirectiveCFILabel(IDLoc);
2190 case DK_CFI_VAL_OFFSET:
2191 return parseDirectiveCFIValOffset(IDLoc);
2194 return parseDirectiveMacrosOnOff(IDVal);
2196 return parseDirectiveMacro(IDLoc);
2199 return parseDirectiveAltmacro(IDVal);
2201 return parseDirectiveExitMacro(IDVal);
2204 return parseDirectiveEndMacro(IDVal);
2206 return parseDirectivePurgeMacro(IDLoc);
2208 return parseDirectiveEnd(IDLoc);
2210 return parseDirectiveError(IDLoc,
false);
2212 return parseDirectiveError(IDLoc,
true);
2214 return parseDirectiveWarning(IDLoc);
2216 return parseDirectiveReloc(IDLoc);
2219 return parseDirectiveDCB(IDVal, 2);
2221 return parseDirectiveDCB(IDVal, 1);
2223 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2225 return parseDirectiveDCB(IDVal, 4);
2227 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2230 return TokError(Twine(IDVal) +
2231 " not currently supported for this target");
2234 return parseDirectiveDS(IDVal, 2);
2236 return parseDirectiveDS(IDVal, 1);
2238 return parseDirectiveDS(IDVal, 8);
2241 return parseDirectiveDS(IDVal, 4);
2244 return parseDirectiveDS(IDVal, 12);
2246 return parseDirectivePrint(IDLoc);
2248 return parseDirectiveAddrsig();
2249 case DK_ADDRSIG_SYM:
2250 return parseDirectiveAddrsigSym();
2251 case DK_PSEUDO_PROBE:
2252 return parseDirectivePseudoProbe();
2253 case DK_LTO_DISCARD:
2254 return parseDirectiveLTODiscard();
2256 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2259 return Error(IDLoc,
"unknown directive");
2263 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2264 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2265 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2268 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2269 return parseDirectiveMSAlign(IDLoc, Info);
2271 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2273 if (checkForValidSection())
2276 return parseAndMatchAndEmitTargetInstruction(Info, IDVal, ID, IDLoc);
2279bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2284 std::string OpcodeStr = IDVal.
lower();
2285 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2286 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr, ID,
2287 Info.ParsedOperands);
2288 Info.ParseError = ParseHadError;
2291 if (getShowParsedOperands()) {
2292 SmallString<256> Str;
2293 raw_svector_ostream OS(Str);
2294 OS <<
"parsed instruction: [";
2295 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2298 Info.ParsedOperands[i]->print(OS, MAI);
2306 if (hasPendingError() || ParseHadError)
2311 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2313 getStreamer().getCurrentSectionOnly())) {
2315 if (ActiveMacros.empty())
2319 ActiveMacros.front()->ExitBuffer);
2324 if (!CppHashInfo.Filename.empty()) {
2325 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2326 0, StringRef(), CppHashInfo.Filename);
2327 getContext().setGenDwarfFileNumber(FileNumber);
2329 unsigned CppHashLocLineNo =
2331 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2334 getStreamer().emitDwarfLocDirective(
2335 getContext().getGenDwarfFileNumber(), Line, 0,
2341 if (!ParseHadError) {
2343 if (getTargetParser().matchAndEmitInstruction(
2344 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2345 getTargetParser().isParsingMSInlineAsm()))
2353AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2358 SMLoc StartLoc = Lexer.
getLoc();
2371bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2376 "Lexing Cpp line comment: Expected Integer");
2377 int64_t LineNumber = getTok().getIntVal();
2380 "Lexing Cpp line comment: Expected String");
2381 StringRef
Filename = getTok().getString();
2392 CppHashInfo.Loc =
L;
2394 CppHashInfo.LineNumber = LineNumber;
2395 CppHashInfo.Buf = CurBuffer;
2396 if (!HadCppHashFilename) {
2397 HadCppHashFilename =
true;
2407 std::nullopt, std::nullopt);
2415void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2416 auto *Parser =
static_cast<AsmParser *
>(
Context);
2417 raw_ostream &OS =
errs();
2420 SMLoc DiagLoc = Diag.
getLoc();
2422 unsigned CppHashBuf =
2423 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2427 if (!Parser->SavedDiagHandler)
2433 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2434 if (Parser->SavedDiagHandler)
2435 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2437 Parser->getContext().diagnose(Diag);
2444 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2447 int CppHashLocLineNo =
2448 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2450 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2456 if (Parser->SavedDiagHandler)
2457 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2459 Parser->getContext().diagnose(NewDiag);
2470bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2473 bool EnableAtPseudoVariable) {
2475 auto expandArg = [&](
unsigned Index) {
2476 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2477 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2478 for (
const AsmToken &Token :
A[Index])
2486 if (AltMacroMode && Token.getString().front() ==
'%' &&
2489 OS << Token.getIntVal();
2492 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2499 OS << Token.getString();
2501 OS << Token.getStringContents();
2506 StringRef Body =
Macro.Body;
2507 size_t I = 0, End = Body.
size();
2509 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2511 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2512 OS << NumOfMacroInstantiations;
2516 if (Body[
I + 1] ==
'+') {
2521 if (Body[
I + 1] ==
'(' &&
I + 2 != End && Body[
I + 2] ==
')') {
2530 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2534 if (Parameters[Index].Name == Argument)
2536 if (Index == NParameters)
2545 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2547 switch (Body[
I + 1]) {
2563 unsigned Index = Body[
I + 1] -
'0';
2564 if (Index <
A.size())
2565 for (
const AsmToken &Token :
A[Index])
2566 OS << Token.getString();
2581 StringRef Token(Body.
data() + Start,
I - Start);
2585 if (Parameters[Index].Name == Token)
2587 if (Index != NParameters) {
2589 if (
I != End && Body[
I] ==
'&')
2633class AsmLexerSkipSpaceRAII {
2635 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2639 ~AsmLexerSkipSpaceRAII() {
2649bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2653 StringRef Str = parseStringToEndOfStatement();
2659 unsigned ParenLevel = 0;
2662 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2669 return TokError(
"unexpected token in macro instantiation");
2671 if (ParenLevel == 0) {
2684 MA.push_back(getTok());
2708 MA.push_back(getTok());
2712 if (ParenLevel != 0)
2713 return TokError(
"unbalanced parentheses in macro argument");
2718bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2719 MCAsmMacroArguments &
A) {
2720 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2721 bool NamedParametersFound =
false;
2722 SmallVector<SMLoc, 4> FALocs;
2724 A.resize(NParameters);
2725 FALocs.
resize(NParameters);
2730 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2731 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2733 SMLoc IDLoc = Lexer.
getLoc();
2734 MCAsmMacroParameter FA;
2737 if (parseIdentifier(FA.
Name))
2738 return Error(IDLoc,
"invalid argument identifier for formal argument");
2741 return TokError(
"expected '=' after formal parameter identifier");
2745 NamedParametersFound =
true;
2747 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2749 if (NamedParametersFound && FA.
Name.
empty())
2750 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2752 SMLoc StrLoc = Lexer.
getLoc();
2755 const MCExpr *AbsoluteExp;
2759 if (parseExpression(AbsoluteExp, EndLoc))
2761 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2762 getStreamer().getAssemblerPtr()))
2763 return Error(StrLoc,
"expected absolute expression");
2767 StringRef(StrChar, EndChar - StrChar),
Value);
2768 FA.
Value.push_back(newToken);
2773 jumpToLoc(EndLoc, CurBuffer);
2777 StringRef(StrChar, EndChar - StrChar));
2778 FA.
Value.push_back(newToken);
2779 }
else if(parseMacroArgument(FA.
Value, Vararg))
2785 for (FAI = 0; FAI < NParameters; ++FAI)
2786 if (
M->Parameters[FAI].Name == FA.
Name)
2789 if (FAI >= NParameters) {
2790 assert(M &&
"expected macro to be defined");
2791 return Error(IDLoc,
"parameter named '" + FA.
Name +
2792 "' does not exist for macro '" +
M->Name +
"'");
2797 if (!FA.
Value.empty()) {
2802 if (FALocs.
size() <= PI)
2805 FALocs[PI] = Lexer.
getLoc();
2813 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2815 if (
M->Parameters[FAI].Required) {
2817 "missing value for required parameter "
2818 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2822 if (!
M->Parameters[FAI].Value.empty())
2823 A[FAI] =
M->Parameters[FAI].Value;
2832 return TokError(
"too many positional arguments");
2835bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2839 if (ActiveMacros.size() == MaxNestingDepth) {
2840 std::ostringstream MaxNestingDepthError;
2841 MaxNestingDepthError <<
"macros cannot be nested more than "
2842 << MaxNestingDepth <<
" levels deep."
2843 <<
" Use -asm-macro-max-nesting-depth to increase "
2845 return TokError(MaxNestingDepthError.str());
2848 MCAsmMacroArguments
A;
2849 if (parseMacroArguments(M,
A))
2854 SmallString<256> Buf;
2855 raw_svector_ostream OS(Buf);
2857 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2858 return Error(getTok().getLoc(),
"Wrong number of arguments");
2859 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2864 OS <<
".endmacro\n";
2866 std::unique_ptr<MemoryBuffer> Instantiation =
2871 MacroInstantiation *
MI =
new MacroInstantiation{
2872 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2873 ActiveMacros.push_back(
MI);
2875 ++NumOfMacroInstantiations;
2885void AsmParser::handleMacroExit() {
2887 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2895 delete ActiveMacros.back();
2896 ActiveMacros.pop_back();
2899bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2902 if (discardLTOSymbol(Name)) {
2903 eatToEndOfStatement();
2908 const MCExpr *
Value;
2909 SMLoc ExprLoc = getTok().getLoc();
2911 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2925 case AssignmentKind::Equal:
2928 case AssignmentKind::Set:
2929 case AssignmentKind::Equiv:
2933 case AssignmentKind::LTOSetConditional:
2935 return Error(ExprLoc,
"expected identifier");
2947bool AsmParser::parseIdentifier(StringRef &Res) {
2954 SMLoc PrefixLoc = getLexer().getLoc();
2966 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2972 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2980 Res = getTok().getIdentifier();
2992bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2994 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2995 parseAssignment(Name, Kind))
3000bool AsmParser::parseEscapedString(std::string &
Data) {
3005 StringRef Str = getTok().getStringContents();
3006 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
3007 if (Str[i] !=
'\\') {
3008 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
3010 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
3014 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
3025 return TokError(
"unexpected backslash at end of string");
3028 if (Str[i] ==
'x' || Str[i] ==
'X') {
3029 size_t length = Str.size();
3030 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
3031 return TokError(
"invalid hexadecimal escape sequence");
3036 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3044 if ((
unsigned)(Str[i] -
'0') <= 7) {
3046 unsigned Value = Str[i] -
'0';
3048 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3052 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3059 return TokError(
"invalid octal escape sequence (out of range)");
3069 return TokError(
"invalid escape sequence (unrecognized character)");
3071 case 'b':
Data +=
'\b';
break;
3072 case 'f':
Data +=
'\f';
break;
3073 case 'n':
Data +=
'\n';
break;
3074 case 'r':
Data +=
'\r';
break;
3075 case 't':
Data +=
'\t';
break;
3076 case '"':
Data +=
'"';
break;
3077 case '\\':
Data +=
'\\';
break;
3085bool AsmParser::parseAngleBracketString(std::string &
Data) {
3086 SMLoc EndLoc, StartLoc = getTok().getLoc();
3088 const char *StartChar = StartLoc.
getPointer() + 1;
3089 const char *EndChar = EndLoc.
getPointer() - 1;
3090 jumpToLoc(EndLoc, CurBuffer);
3103bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3104 auto parseOp = [&]() ->
bool {
3106 if (checkForValidSection())
3111 if (parseEscapedString(
Data))
3113 getStreamer().emitBytes(
Data);
3116 getStreamer().emitBytes(StringRef(
"\0", 1));
3120 return parseMany(parseOp);
3125bool AsmParser::parseDirectiveBase64() {
3126 auto parseOp = [&]() ->
bool {
3127 if (checkForValidSection())
3134 std::vector<char> Decoded;
3135 std::string
const str = getTok().getStringContents().str();
3136 if (check(str.empty(),
"expected nonempty string")) {
3143 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3146 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3151 return check(parseMany(parseOp),
"expected string");
3156bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3158 const MCExpr *Expr =
nullptr;
3160 if (parseExpression(
Offset))
3172 SMLoc ExprLoc = Lexer.
getLoc();
3173 if (parseExpression(Expr))
3178 return Error(ExprLoc,
"expression must be relocatable");
3184 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3190bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3191 auto parseOp = [&]() ->
bool {
3192 const MCExpr *
Value;
3193 SMLoc ExprLoc = getLexer().getLoc();
3194 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3199 uint64_t IntValue = MCE->getValue();
3201 return Error(ExprLoc,
"out of range literal value");
3202 getStreamer().emitIntValue(IntValue,
Size);
3204 getStreamer().emitValue(
Value,
Size, ExprLoc);
3208 return parseMany(parseOp);
3214 return Asm.TokError(
"unknown token in expression");
3215 SMLoc ExprLoc = Asm.getTok().getLoc();
3216 APInt IntValue = Asm.getTok().getAPIntVal();
3218 if (!IntValue.
isIntN(128))
3219 return Asm.Error(ExprLoc,
"out of range literal value");
3220 if (!IntValue.
isIntN(64)) {
3233bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3234 auto parseOp = [&]() ->
bool {
3235 if (checkForValidSection())
3241 getStreamer().emitInt64(lo);
3242 getStreamer().emitInt64(hi);
3244 getStreamer().emitInt64(hi);
3245 getStreamer().emitInt64(lo);
3250 return parseMany(parseOp);
3253bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3264 return TokError(Lexer.
getErr());
3267 return TokError(
"unexpected token in directive");
3271 StringRef IDVal = getTok().getString();
3279 return TokError(
"invalid floating point literal");
3281 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3283 return TokError(
"invalid floating point literal");
3290 Res =
Value.bitcastToAPInt();
3297bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3298 const fltSemantics &Semantics) {
3299 auto parseOp = [&]() ->
bool {
3301 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3308 return parseMany(parseOp);
3313bool AsmParser::parseDirectiveZero() {
3314 SMLoc NumBytesLoc = Lexer.
getLoc();
3315 const MCExpr *NumBytes;
3316 if (checkForValidSection() || parseExpression(NumBytes))
3322 if (parseAbsoluteExpression(Val))
3328 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3335bool AsmParser::parseDirectiveFill() {
3336 SMLoc NumValuesLoc = Lexer.
getLoc();
3337 const MCExpr *NumValues;
3338 if (checkForValidSection() || parseExpression(NumValues))
3341 int64_t FillSize = 1;
3342 int64_t FillExpr = 0;
3344 SMLoc SizeLoc, ExprLoc;
3347 SizeLoc = getTok().getLoc();
3348 if (parseAbsoluteExpression(FillSize))
3351 ExprLoc = getTok().getLoc();
3352 if (parseAbsoluteExpression(FillExpr))
3360 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3364 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3369 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3371 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3378bool AsmParser::parseDirectiveOrg() {
3380 SMLoc OffsetLoc = Lexer.
getLoc();
3381 if (checkForValidSection() || parseExpression(
Offset))
3385 int64_t FillExpr = 0;
3387 if (parseAbsoluteExpression(FillExpr))
3392 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3398bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3399 SMLoc AlignmentLoc = getLexer().getLoc();
3402 bool HasFillExpr =
false;
3403 int64_t FillExpr = 0;
3404 int64_t MaxBytesToFill = 0;
3407 auto parseAlign = [&]() ->
bool {
3408 if (parseAbsoluteExpression(Alignment))
3416 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3420 if (parseTokenLoc(MaxBytesLoc) ||
3421 parseAbsoluteExpression(MaxBytesToFill))
3427 if (checkForValidSection())
3431 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3438 bool ReturnVal =
false;
3443 if (Alignment >= 32) {
3444 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3456 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3460 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3467 if (MaxBytesToFill < 1) {
3468 ReturnVal |=
Error(MaxBytesLoc,
3469 "alignment directive can never be satisfied in this "
3470 "many bytes, ignoring maximum bytes expression");
3474 if (MaxBytesToFill >= Alignment) {
3475 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3481 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3482 assert(Section &&
"must have section to emit alignment");
3484 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3486 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3494 getStreamer().emitCodeAlignment(
Align(Alignment),
3495 getTargetParser().getSTI(), MaxBytesToFill);
3498 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3505bool AsmParser::parseDirectivePrefAlign() {
3506 SMLoc AlignmentLoc = getLexer().getLoc();
3508 if (checkForValidSection() || parseAbsoluteExpression(Log2Alignment))
3511 if (Log2Alignment < 0 || Log2Alignment > 63)
3512 return Error(AlignmentLoc,
"log2 alignment must be in the range [0, 63]");
3515 SMLoc SymLoc = getLexer().getLoc();
3519 SymLoc = getLexer().getLoc();
3520 if (parseIdentifier(Name))
3521 return Error(SymLoc,
"expected symbol name");
3525 SMLoc FillLoc = getLexer().getLoc();
3529 bool EmitNops =
false;
3531 SMLoc FillLoc2 = getLexer().getLoc();
3533 getLexer().getTok().getIdentifier() ==
"nop") {
3538 if (parseAbsoluteExpression(FillVal))
3540 if (FillVal < 0 || FillVal > 255)
3541 return Error(FillLoc2,
"fill value must be in range [0, 255]");
3542 Fill =
static_cast<uint8_t
>(FillVal);
3547 if ((EmitNops || Fill != 0) &&
3548 getStreamer().getCurrentSectionOnly()->isBssSection())
3549 return Error(FillLoc,
"non-zero fill in BSS section '" +
3550 getStreamer().getCurrentSectionOnly()->
getName() +
3553 getStreamer().emitPrefAlign(
Align(1ULL << Log2Alignment), *End, EmitNops,
3554 Fill, getTargetParser().getSTI());
3561bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3563 int64_t FileNumber = -1;
3565 FileNumber = getTok().getIntVal();
3569 return TokError(
"negative file number");
3576 if (parseEscapedString(Path))
3579 StringRef Directory;
3581 std::string FilenameData;
3583 if (check(FileNumber == -1,
3584 "explicit path specified, but no file number") ||
3585 parseEscapedString(FilenameData))
3594 bool HasMD5 =
false;
3596 std::optional<StringRef>
Source;
3597 bool HasSource =
false;
3598 std::string SourceString;
3603 "unexpected token in '.file' directive") ||
3604 parseIdentifier(Keyword))
3606 if (Keyword ==
"md5") {
3608 if (check(FileNumber == -1,
3609 "MD5 checksum specified, but no file number") ||
3612 }
else if (Keyword ==
"source") {
3614 if (check(FileNumber == -1,
3615 "source specified, but no file number") ||
3617 "unexpected token in '.file' directive") ||
3618 parseEscapedString(SourceString))
3621 return TokError(
"unexpected token in '.file' directive");
3625 if (FileNumber == -1) {
3629 if (
getContext().getAsmInfo().hasSingleParameterDotFile())
3630 getStreamer().emitFileDirective(
Filename);
3640 std::optional<MD5::MD5Result> CKMem;
3643 for (
unsigned i = 0; i != 8; ++i) {
3644 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3645 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3650 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3651 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3652 Source = StringRef(SourceBuf, SourceString.size());
3654 if (FileNumber == 0) {
3658 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3660 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3661 FileNumber, Directory,
Filename, CKMem, Source);
3668 ReportedInconsistentMD5 =
true;
3669 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3678bool AsmParser::parseDirectiveLine() {
3690bool AsmParser::parseDirectiveLoc() {
3691 int64_t FileNumber = 0, LineNumber = 0;
3692 SMLoc Loc = getTok().getLoc();
3693 if (parseIntToken(FileNumber) ||
3695 "file number less than one in '.loc' directive") ||
3696 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3697 "unassigned file number in '.loc' directive"))
3702 LineNumber = getTok().getIntVal();
3704 return TokError(
"line number less than zero in '.loc' directive");
3708 int64_t ColumnPos = 0;
3710 ColumnPos = getTok().getIntVal();
3712 return TokError(
"column position less than zero in '.loc' directive");
3716 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3721 auto parseLocOp = [&]() ->
bool {
3723 SMLoc Loc = getTok().getLoc();
3724 if (parseIdentifier(Name))
3725 return TokError(
"unexpected token in '.loc' directive");
3727 if (Name ==
"basic_block")
3729 else if (Name ==
"prologue_end")
3731 else if (Name ==
"epilogue_begin")
3733 else if (Name ==
"is_stmt") {
3734 Loc = getTok().getLoc();
3735 const MCExpr *
Value;
3736 if (parseExpression(
Value))
3740 int Value = MCE->getValue();
3742 Flags &= ~DWARF2_FLAG_IS_STMT;
3743 else if (
Value == 1)
3746 return Error(Loc,
"is_stmt value not 0 or 1");
3748 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3750 }
else if (Name ==
"isa") {
3751 Loc = getTok().getLoc();
3752 const MCExpr *
Value;
3753 if (parseExpression(
Value))
3757 int Value = MCE->getValue();
3759 return Error(Loc,
"isa number less than zero");
3762 return Error(Loc,
"isa number not a constant value");
3764 }
else if (Name ==
"discriminator") {
3765 if (parseAbsoluteExpression(Discriminator))
3768 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3773 if (parseMany(parseLocOp,
false ))
3776 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3777 Isa, Discriminator, StringRef());
3784bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3786 DirectiveLoc = Lexer.
getLoc();
3787 if (parseIdentifier(Name))
3788 return TokError(
"expected identifier");
3791 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3797bool AsmParser::parseDirectiveStabs() {
3798 return TokError(
"unsupported directive '.stabs'");
3803bool AsmParser::parseDirectiveCVFile() {
3804 SMLoc FileNumberLoc = getTok().getLoc();
3807 std::string Checksum;
3810 if (parseIntToken(FileNumber,
"expected file number") ||
3811 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3813 "unexpected token in '.cv_file' directive") ||
3818 "unexpected token in '.cv_file' directive") ||
3819 parseEscapedString(Checksum) ||
3820 parseIntToken(ChecksumKind,
3821 "expected checksum kind in '.cv_file' directive") ||
3827 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3828 memcpy(CKMem, Checksum.data(), Checksum.size());
3829 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3832 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3833 static_cast<uint8_t
>(ChecksumKind)))
3834 return Error(FileNumberLoc,
"file number already allocated");
3839bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3840 StringRef DirectiveName) {
3842 return parseTokenLoc(Loc) ||
3843 parseIntToken(FunctionId,
"expected function id") ||
3844 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3845 "expected function id within range [0, UINT_MAX)");
3848bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3850 return parseTokenLoc(Loc) ||
3851 parseIntToken(FileNumber,
"expected file number") ||
3852 check(FileNumber < 1, Loc,
3853 "file number less than one in '" + DirectiveName +
3855 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3856 "unassigned file number in '" + DirectiveName +
"' directive");
3863bool AsmParser::parseDirectiveCVFuncId() {
3864 SMLoc FunctionIdLoc = getTok().getLoc();
3867 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3870 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3871 return Error(FunctionIdLoc,
"function id already allocated");
3884bool AsmParser::parseDirectiveCVInlineSiteId() {
3885 SMLoc FunctionIdLoc = getTok().getLoc();
3893 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3898 getTok().getIdentifier() !=
"within"),
3899 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3904 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3909 getTok().getIdentifier() !=
"inlined_at"),
3910 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3916 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3917 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3922 IACol = getTok().getIntVal();
3929 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3930 IALine, IACol, FunctionIdLoc))
3931 return Error(FunctionIdLoc,
"function id already allocated");
3943bool AsmParser::parseDirectiveCVLoc() {
3944 SMLoc DirectiveLoc = getTok().getLoc();
3945 int64_t FunctionId, FileNumber;
3946 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3947 parseCVFileId(FileNumber,
".cv_loc"))
3950 int64_t LineNumber = 0;
3952 LineNumber = getTok().getIntVal();
3954 return TokError(
"line number less than zero in '.cv_loc' directive");
3958 int64_t ColumnPos = 0;
3960 ColumnPos = getTok().getIntVal();
3962 return TokError(
"column position less than zero in '.cv_loc' directive");
3966 bool PrologueEnd =
false;
3969 auto parseOp = [&]() ->
bool {
3971 SMLoc Loc = getTok().getLoc();
3972 if (parseIdentifier(Name))
3973 return TokError(
"unexpected token in '.cv_loc' directive");
3974 if (Name ==
"prologue_end")
3976 else if (Name ==
"is_stmt") {
3977 Loc = getTok().getLoc();
3978 const MCExpr *
Value;
3979 if (parseExpression(
Value))
3984 IsStmt = MCE->getValue();
3987 return Error(Loc,
"is_stmt value not 0 or 1");
3989 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3994 if (parseMany(parseOp,
false ))
3997 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3998 ColumnPos, PrologueEnd, IsStmt, StringRef(),
4005bool AsmParser::parseDirectiveCVLinetable() {
4008 SMLoc Loc = getTok().getLoc();
4009 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
4010 parseTokenLoc(Loc) ||
4011 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
4012 parseComma() || parseTokenLoc(Loc) ||
4013 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
4016 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
4022bool AsmParser::parseDirectiveCVInlineLinetable() {
4023 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
4025 SMLoc Loc = getTok().getLoc();
4026 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
4027 parseTokenLoc(Loc) ||
4028 parseIntToken(SourceFileId,
"expected SourceField") ||
4029 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
4030 parseTokenLoc(Loc) ||
4031 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
4032 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
4033 parseTokenLoc(Loc) ||
4034 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
4035 parseTokenLoc(Loc) ||
4036 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
4042 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
4043 SourceLineNum, FnStartSym,
4048void AsmParser::initializeCVDefRangeTypeMap() {
4049 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
4050 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
4051 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4052 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4053 CVDefRangeTypeMap[
"reg_rel_indir"] = CVDR_DEFRANGE_REGISTER_REL_INDIR;
4058bool AsmParser::parseDirectiveCVDefRange() {
4060 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
4062 Loc = getLexer().getLoc();
4065 return Error(Loc,
"expected identifier in directive");
4067 Loc = getLexer().getLoc();
4070 return Error(Loc,
"expected identifier in directive");
4072 Ranges.push_back({GapStartSym, GapEndSym});
4075 StringRef CVDefRangeTypeStr;
4078 "expected comma before def_range type in .cv_def_range directive") ||
4079 parseIdentifier(CVDefRangeTypeStr))
4080 return Error(Loc,
"expected def_range type in directive");
4083 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4084 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4086 : CVTypeIt->getValue();
4088 case CVDR_DEFRANGE_REGISTER: {
4090 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4091 ".cv_def_range directive") ||
4092 parseAbsoluteExpression(DRRegister))
4093 return Error(Loc,
"expected register number");
4095 codeview::DefRangeRegisterHeader DRHdr;
4098 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4101 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4104 "expected comma before offset in .cv_def_range directive") ||
4105 parseAbsoluteExpression(DROffset))
4106 return Error(Loc,
"expected offset value");
4108 codeview::DefRangeFramePointerRelHeader DRHdr;
4110 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4113 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4115 int64_t DROffsetInParent;
4116 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4117 ".cv_def_range directive") ||
4118 parseAbsoluteExpression(DRRegister))
4119 return Error(Loc,
"expected register number");
4121 "expected comma before offset in .cv_def_range directive") ||
4122 parseAbsoluteExpression(DROffsetInParent))
4123 return Error(Loc,
"expected offset value");
4125 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4129 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4132 case CVDR_DEFRANGE_REGISTER_REL: {
4135 int64_t DRBasePointerOffset;
4136 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4137 ".cv_def_range directive") ||
4138 parseAbsoluteExpression(DRRegister))
4139 return Error(Loc,
"expected register value");
4142 "expected comma before flag value in .cv_def_range directive") ||
4143 parseAbsoluteExpression(DRFlags))
4144 return Error(Loc,
"expected flag value");
4145 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4146 "in .cv_def_range directive") ||
4147 parseAbsoluteExpression(DRBasePointerOffset))
4148 return Error(Loc,
"expected base pointer offset value");
4150 codeview::DefRangeRegisterRelHeader DRHdr;
4152 DRHdr.
Flags = DRFlags;
4154 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4157 case CVDR_DEFRANGE_REGISTER_REL_INDIR: {
4160 int64_t DRBasePointerOffset;
4161 int64_t DROffsetInUdt;
4162 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4163 ".cv_def_range directive") ||
4164 parseAbsoluteExpression(DRRegister))
4165 return Error(Loc,
"expected register value");
4168 "expected comma before flag value in .cv_def_range directive") ||
4169 parseAbsoluteExpression(DRFlags))
4170 return Error(Loc,
"expected flag value");
4171 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4172 "in .cv_def_range directive") ||
4173 parseAbsoluteExpression(DRBasePointerOffset))
4174 return Error(Loc,
"expected base pointer offset value");
4175 if (parseToken(
AsmToken::Comma,
"expected comma before offset in UDT "
4176 "in .cv_def_range directive") ||
4177 parseAbsoluteExpression(DROffsetInUdt))
4178 return Error(Loc,
"expected offset in UDT value");
4180 codeview::DefRangeRegisterRelIndirHeader DRHdr;
4182 DRHdr.
Flags = DRFlags;
4185 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4189 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4196bool AsmParser::parseDirectiveCVString() {
4198 if (checkForValidSection() || parseEscapedString(
Data))
4202 std::pair<StringRef, unsigned> Insertion =
4203 getCVContext().addToStringTable(
Data);
4204 getStreamer().emitInt32(Insertion.second);
4210bool AsmParser::parseDirectiveCVStringTable() {
4211 getStreamer().emitCVStringTableDirective();
4217bool AsmParser::parseDirectiveCVFileChecksums() {
4218 getStreamer().emitCVFileChecksumsDirective();
4224bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4226 if (parseIntToken(FileNo))
4230 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4236bool AsmParser::parseDirectiveCVFPOData() {
4237 SMLoc DirLoc = getLexer().getLoc();
4240 return TokError(
"expected symbol name");
4243 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4249bool AsmParser::parseDirectiveCFISections() {
4253 bool SFrame =
false;
4257 if (parseIdentifier(Name))
4258 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4259 if (Name ==
".eh_frame")
4261 else if (Name ==
".debug_frame")
4263 else if (Name ==
".sframe")
4271 getStreamer().emitCFISections(EH,
Debug, SFrame);
4277bool AsmParser::parseDirectiveCFIStartProc() {
4278 CFIStartProcLoc = StartTokLoc;
4282 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4283 "unexpected token") ||
4293 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4299bool AsmParser::parseDirectiveCFIEndProc() {
4300 CFIStartProcLoc = std::nullopt;
4305 getStreamer().emitCFIEndProc();
4310bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4311 SMLoc DirectiveLoc) {
4315 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4319 return parseAbsoluteExpression(
Register);
4326bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4328 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4329 parseAbsoluteExpression(
Offset) || parseEOL())
4338bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4340 if (parseAbsoluteExpression(
Offset) || parseEOL())
4343 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4349bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4350 int64_t Register1 = 0, Register2 = 0;
4351 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4352 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4355 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4361bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4364 getStreamer().emitCFIWindowSave(DirectiveLoc);
4370bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4371 int64_t Adjustment = 0;
4372 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4375 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4381bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4383 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4386 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4392bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4394 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4395 parseAbsoluteExpression(
Offset) || parseComma() ||
4406bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4410 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4411 parseAbsoluteExpression(
Offset) || parseEOL())
4420bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4423 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4424 parseAbsoluteExpression(
Offset) || parseEOL())
4432 if (Encoding & ~0xff)
4438 const unsigned Format = Encoding & 0xf;
4445 const unsigned Application = Encoding & 0x70;
4457bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4458 int64_t Encoding = 0;
4459 if (parseAbsoluteExpression(Encoding))
4467 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4471 getStreamer().emitCFIPersonality(Sym, Encoding);
4473 getStreamer().emitCFILsda(Sym, Encoding);
4479bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4482 getStreamer().emitCFIRememberState(DirectiveLoc);
4488bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4491 getStreamer().emitCFIRestoreState(DirectiveLoc);
4497bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4500 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4503 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4509bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4511 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4514 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4520bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4523 if (parseAbsoluteExpression(CurrValue))
4526 Values.push_back((uint8_t)CurrValue);
4531 if (parseAbsoluteExpression(CurrValue))
4534 Values.push_back((uint8_t)CurrValue);
4537 getStreamer().emitCFIEscape(
Values, DirectiveLoc);
4543bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4545 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4547 getStreamer().emitCFIReturnColumn(
Register);
4553bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4557 getStreamer().emitCFISignalFrame();
4563bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4566 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4569 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4575bool AsmParser::parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc) {
4577 int64_t R1 = 0,
R2 = 0;
4578 int64_t R1Size = 0, R2Size = 0;
4580 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4581 parseRegisterOrRegisterNumber(R1, DirectiveLoc) || parseComma() ||
4582 parseAbsoluteExpression(R1Size) || parseComma() ||
4583 parseRegisterOrRegisterNumber(
R2, DirectiveLoc) || parseComma() ||
4584 parseAbsoluteExpression(R2Size) || parseEOL())
4587 getStreamer().emitCFILLVMRegisterPair(
Register, R1, R1Size,
R2, R2Size,
4594bool AsmParser::parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc) {
4596 std::vector<MCCFIInstruction::VectorRegisterWithLane> VRs;
4598 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma())
4602 int64_t VectorRegister = 0;
4605 if (parseRegisterOrRegisterNumber(VectorRegister, DirectiveLoc) ||
4606 parseComma() || parseIntToken(Lane,
"expected a lane number") ||
4607 parseComma() || parseAbsoluteExpression(
Size))
4609 VRs.push_back({unsigned(VectorRegister), unsigned(Lane), unsigned(
Size)});
4615 getStreamer().emitCFILLVMVectorRegisters(
Register, std::move(VRs),
4622bool AsmParser::parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc) {
4623 int64_t
Register = 0, MaskRegister = 0;
4624 int64_t RegisterSize = 0, MaskRegisterSize = 0;
4627 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4628 parseAbsoluteExpression(RegisterSize) || parseComma() ||
4629 parseRegisterOrRegisterNumber(MaskRegister, DirectiveLoc) ||
4630 parseComma() || parseAbsoluteExpression(MaskRegisterSize) ||
4631 parseComma() || parseAbsoluteExpression(
Offset) || parseEOL())
4634 getStreamer().emitCFILLVMVectorOffset(
Register, RegisterSize, MaskRegister,
4635 MaskRegisterSize,
Offset, DirectiveLoc);
4642bool AsmParser::parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc) {
4643 int64_t
Register = 0, SpillReg = 0, MaskReg = 0;
4644 int64_t SpillRegLaneSize = 0, MaskRegSize = 0;
4646 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4647 parseRegisterOrRegisterNumber(SpillReg, DirectiveLoc) || parseComma() ||
4648 parseAbsoluteExpression(SpillRegLaneSize) || parseComma() ||
4649 parseRegisterOrRegisterNumber(MaskReg, DirectiveLoc) || parseComma() ||
4650 parseAbsoluteExpression(MaskRegSize) || parseEOL())
4653 getStreamer().emitCFILLVMVectorRegisterMask(
4654 Register, SpillReg, SpillRegLaneSize, MaskReg, MaskRegSize, DirectiveLoc);
4660bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4663 if (parseIdentifier(Name))
4664 return TokError(
"expected identifier");
4667 getStreamer().emitCFILabelDirective(Loc, Name);
4673bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4677 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4678 parseAbsoluteExpression(
Offset) || parseEOL())
4688bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4691 AltMacroMode = (Directive ==
".altmacro");
4698bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4701 setMacrosEnabled(Directive ==
".macros_on");
4707bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4709 if (parseIdentifier(Name))
4710 return TokError(
"expected identifier in '.macro' directive");
4719 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4721 "' should be the last parameter");
4725 return TokError(
"expected identifier in '.macro' directive");
4728 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4730 return TokError(
"macro '" + Name +
"' has multiple parameters"
4739 QualLoc = Lexer.
getLoc();
4740 if (parseIdentifier(Qualifier))
4741 return Error(QualLoc,
"missing parameter qualifier for "
4742 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4744 if (Qualifier ==
"req")
4746 else if (Qualifier ==
"vararg")
4749 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4750 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4758 ParamLoc = Lexer.
getLoc();
4759 if (parseMacroArgument(
Parameter.Value,
false ))
4763 Warning(ParamLoc,
"pointless default value for required parameter "
4764 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4777 AsmToken EndToken, StartToken = getTok();
4778 unsigned MacroDepth = 0;
4788 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4793 if (getTok().getIdentifier() ==
".endm" ||
4794 getTok().getIdentifier() ==
".endmacro") {
4795 if (MacroDepth == 0) {
4796 EndToken = getTok();
4799 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4806 }
else if (getTok().getIdentifier() ==
".macro") {
4812 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4816 eatToEndOfStatement();
4820 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4825 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4826 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4827 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4848void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4854 if (NParameters == 0)
4857 bool NamedParametersFound =
false;
4858 bool PositionalParametersFound =
false;
4863 while (!Body.
empty()) {
4865 std::size_t End = Body.
size(), Pos = 0;
4866 for (; Pos != End; ++Pos) {
4869 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4873 if (Body[Pos] !=
'$' || Pos + 1 == End)
4875 char Next = Body[Pos + 1];
4877 isdigit(
static_cast<unsigned char>(
Next)))
4885 if (Body[Pos] ==
'$') {
4886 switch (Body[Pos + 1]) {
4893 PositionalParametersFound =
true;
4898 PositionalParametersFound =
true;
4908 const char *Begin = Body.
data() + Pos + 1;
4909 StringRef
Argument(Begin,
I - (Pos + 1));
4912 if (Parameters[Index].Name == Argument)
4915 if (Index == NParameters) {
4916 if (Body[Pos + 1] ==
'(' && Pos + 2 != End && Body[Pos + 2] ==
')')
4922 NamedParametersFound =
true;
4930 if (!NamedParametersFound && PositionalParametersFound)
4931 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4932 "used in macro body, possible positional parameter "
4933 "found in body which will have no effect");
4938bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4942 if (!isInsideMacroInstantiation())
4943 return TokError(
"unexpected '" + Directive +
"' in file, "
4944 "no current macro definition");
4947 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4948 TheCondState = TheCondStack.back();
4949 TheCondStack.pop_back();
4959bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4961 return TokError(
"unexpected token in '" + Directive +
"' directive");
4965 if (isInsideMacroInstantiation()) {
4972 return TokError(
"unexpected '" + Directive +
"' in file, "
4973 "no current macro definition");
4978bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4981 if (parseTokenLoc(Loc) ||
4982 check(parseIdentifier(Name), Loc,
4983 "expected identifier in '.purgem' directive") ||
4988 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4992 <<
"Un-defining macro: " << Name <<
"\n");
4998bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4999 SMLoc NumBytesLoc = Lexer.
getLoc();
5000 const MCExpr *NumBytes;
5001 if (checkForValidSection() || parseExpression(NumBytes))
5004 int64_t FillExpr = 0;
5006 if (parseAbsoluteExpression(FillExpr))
5012 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
5019bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
5020 SMLoc NumValuesLoc = Lexer.
getLoc();
5022 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5025 if (NumValues < 0) {
5026 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5033 const MCExpr *
Value;
5034 SMLoc ExprLoc = getLexer().getLoc();
5035 if (parseExpression(
Value))
5041 uint64_t IntValue = MCE->getValue();
5043 return Error(ExprLoc,
"literal value out of range for directive");
5044 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5045 getStreamer().emitIntValue(IntValue,
Size);
5047 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5048 getStreamer().emitValue(
Value,
Size, ExprLoc);
5056bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
5057 SMLoc NumValuesLoc = Lexer.
getLoc();
5059 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5062 if (NumValues < 0) {
5063 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5071 if (parseRealValue(Semantics, AsInt) || parseEOL())
5074 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5083bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
5084 SMLoc NumValuesLoc = Lexer.
getLoc();
5086 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
5090 if (NumValues < 0) {
5091 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5095 for (
uint64_t i = 0, e = NumValues; i !=
e; ++i)
5096 getStreamer().emitFill(
Size, 0);
5103bool AsmParser::parseDirectiveLEB128(
bool Signed) {
5104 if (checkForValidSection())
5107 auto parseOp = [&]() ->
bool {
5108 const MCExpr *
Value;
5109 if (parseExpression(
Value))
5112 getStreamer().emitSLEB128Value(
Value);
5114 getStreamer().emitULEB128Value(
Value);
5118 return parseMany(parseOp);
5123bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
5124 auto parseOp = [&]() ->
bool {
5126 SMLoc Loc = getTok().getLoc();
5127 if (parseIdentifier(Name))
5128 return Error(Loc,
"expected identifier");
5130 if (discardLTOSymbol(Name))
5138 return Error(Loc,
"non-local symbol required");
5140 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
5141 return Error(Loc,
"unable to emit symbol attribute");
5145 return parseMany(parseOp);
5150bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5151 if (checkForValidSection())
5154 SMLoc IDLoc = getLexer().getLoc();
5157 return TokError(
"expected identifier in directive");
5163 SMLoc SizeLoc = getLexer().getLoc();
5164 if (parseAbsoluteExpression(
Size))
5167 int64_t Pow2Alignment = 0;
5168 SMLoc Pow2AlignmentLoc;
5171 Pow2AlignmentLoc = getLexer().getLoc();
5172 if (parseAbsoluteExpression(Pow2Alignment))
5177 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5183 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5184 Pow2Alignment =
Log2_64(Pow2Alignment);
5194 return Error(SizeLoc,
"size must be non-negative");
5198 return Error(IDLoc,
"invalid symbol redefinition");
5202 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5203 Align(1ULL << Pow2Alignment));
5207 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
5213bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5214 StringRef Str = parseStringToEndOfStatement();
5219 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5222 return Error(DirectiveLoc,
5223 ".abort '" + Str +
"' detected. Assembly stopping");
5228bool AsmParser::parseDirectiveInclude() {
5231 SMLoc IncludeLoc = getTok().getLoc();
5234 "expected string in '.include' directive") ||
5237 "unexpected token in '.include' directive") ||
5240 check(enterIncludeFile(
Filename), IncludeLoc,
5241 "Could not find include file '" +
Filename +
"'"))
5249bool AsmParser::parseDirectiveIncbin() {
5252 SMLoc IncbinLoc = getTok().getLoc();
5254 "expected string in '.incbin' directive") ||
5259 const MCExpr *
Count =
nullptr;
5260 SMLoc SkipLoc, CountLoc;
5265 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5269 CountLoc = getTok().getLoc();
5270 if (parseExpression(
Count))
5278 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5283 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5289bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5290 TheCondStack.push_back(TheCondState);
5292 if (TheCondState.
Ignore) {
5293 eatToEndOfStatement();
5296 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5306 ExprValue = ExprValue == 0;
5309 ExprValue = ExprValue >= 0;
5312 ExprValue = ExprValue > 0;
5315 ExprValue = ExprValue <= 0;
5318 ExprValue = ExprValue < 0;
5322 TheCondState.
CondMet = ExprValue;
5331bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5332 TheCondStack.push_back(TheCondState);
5335 if (TheCondState.
Ignore) {
5336 eatToEndOfStatement();
5338 StringRef Str = parseStringToEndOfStatement();
5343 TheCondState.
CondMet = ExpectBlank == Str.empty();
5353bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5354 TheCondStack.push_back(TheCondState);
5357 if (TheCondState.
Ignore) {
5358 eatToEndOfStatement();
5360 StringRef Str1 = parseStringToComma();
5365 StringRef Str2 = parseStringToEndOfStatement();
5379bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5380 TheCondStack.push_back(TheCondState);
5383 if (TheCondState.
Ignore) {
5384 eatToEndOfStatement();
5388 return TokError(
"expected string parameter for '.ifeqs' directive");
5389 return TokError(
"expected string parameter for '.ifnes' directive");
5392 StringRef String1 = getTok().getStringContents();
5398 "expected comma after first string for '.ifeqs' directive");
5400 "expected comma after first string for '.ifnes' directive");
5407 return TokError(
"expected string parameter for '.ifeqs' directive");
5408 return TokError(
"expected string parameter for '.ifnes' directive");
5411 StringRef String2 = getTok().getStringContents();
5414 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5423bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5425 TheCondStack.push_back(TheCondState);
5428 if (TheCondState.
Ignore) {
5429 eatToEndOfStatement();
5431 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5449bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5452 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5453 " .if or an .elseif");
5456 bool LastIgnoreState =
false;
5457 if (!TheCondStack.empty())
5458 LastIgnoreState = TheCondStack.back().Ignore;
5459 if (LastIgnoreState || TheCondState.
CondMet) {
5460 TheCondState.
Ignore =
true;
5461 eatToEndOfStatement();
5464 if (parseAbsoluteExpression(ExprValue))
5470 TheCondState.
CondMet = ExprValue;
5479bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5485 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5486 " an .if or an .elseif");
5488 bool LastIgnoreState =
false;
5489 if (!TheCondStack.empty())
5490 LastIgnoreState = TheCondStack.back().Ignore;
5491 if (LastIgnoreState || TheCondState.
CondMet)
5492 TheCondState.
Ignore =
true;
5494 TheCondState.
Ignore =
false;
5501bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5514bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5515 if (!TheCondStack.empty()) {
5516 if (TheCondStack.back().Ignore) {
5517 eatToEndOfStatement();
5523 return Error(L,
".err encountered");
5525 StringRef Message =
".error directive invoked in source file";
5528 return TokError(
".error argument must be a string");
5530 Message = getTok().getStringContents();
5534 return Error(L, Message);
5539bool AsmParser::parseDirectiveWarning(SMLoc L) {
5540 if (!TheCondStack.empty()) {
5541 if (TheCondStack.back().Ignore) {
5542 eatToEndOfStatement();
5547 StringRef Message =
".warning directive invoked in source file";
5551 return TokError(
".warning argument must be a string");
5553 Message = getTok().getStringContents();
5564bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5569 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5571 if (!TheCondStack.empty()) {
5572 TheCondState = TheCondStack.back();
5573 TheCondStack.pop_back();
5579void AsmParser::initializeDirectiveKindMap() {
5586 DirectiveKindMap[
".set"] = DK_SET;
5587 DirectiveKindMap[
".equ"] = DK_EQU;
5588 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5589 DirectiveKindMap[
".ascii"] = DK_ASCII;
5590 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5591 DirectiveKindMap[
".string"] = DK_STRING;
5592 DirectiveKindMap[
".byte"] = DK_BYTE;
5593 DirectiveKindMap[
".base64"] = DK_BASE64;
5594 DirectiveKindMap[
".short"] = DK_SHORT;
5595 DirectiveKindMap[
".value"] = DK_VALUE;
5596 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5597 DirectiveKindMap[
".long"] = DK_LONG;
5598 DirectiveKindMap[
".int"] = DK_INT;
5599 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5600 DirectiveKindMap[
".quad"] = DK_QUAD;
5601 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5602 DirectiveKindMap[
".octa"] = DK_OCTA;
5603 DirectiveKindMap[
".single"] = DK_SINGLE;
5604 DirectiveKindMap[
".float"] = DK_FLOAT;
5605 DirectiveKindMap[
".double"] = DK_DOUBLE;
5606 DirectiveKindMap[
".align"] = DK_ALIGN;
5607 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5608 DirectiveKindMap[
".balign"] = DK_BALIGN;
5609 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5610 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5611 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5612 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5613 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5614 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5615 DirectiveKindMap[
".org"] = DK_ORG;
5616 DirectiveKindMap[
".fill"] = DK_FILL;
5617 DirectiveKindMap[
".zero"] = DK_ZERO;
5618 DirectiveKindMap[
".extern"] = DK_EXTERN;
5619 DirectiveKindMap[
".globl"] = DK_GLOBL;
5620 DirectiveKindMap[
".global"] = DK_GLOBAL;
5621 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5622 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5623 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5624 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5625 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5626 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5627 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5628 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5629 DirectiveKindMap[
".cold"] = DK_COLD;
5630 DirectiveKindMap[
".comm"] = DK_COMM;
5631 DirectiveKindMap[
".common"] = DK_COMMON;
5632 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5633 DirectiveKindMap[
".abort"] = DK_ABORT;
5634 DirectiveKindMap[
".include"] = DK_INCLUDE;
5635 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5636 DirectiveKindMap[
".code16"] = DK_CODE16;
5637 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5638 DirectiveKindMap[
".rept"] = DK_REPT;
5639 DirectiveKindMap[
".rep"] = DK_REPT;
5640 DirectiveKindMap[
".irp"] = DK_IRP;
5641 DirectiveKindMap[
".irpc"] = DK_IRPC;
5642 DirectiveKindMap[
".endr"] = DK_ENDR;
5643 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
5644 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
5645 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
5646 DirectiveKindMap[
".if"] = DK_IF;
5647 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5648 DirectiveKindMap[
".ifge"] = DK_IFGE;
5649 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5650 DirectiveKindMap[
".ifle"] = DK_IFLE;
5651 DirectiveKindMap[
".iflt"] = DK_IFLT;
5652 DirectiveKindMap[
".ifne"] = DK_IFNE;
5653 DirectiveKindMap[
".ifb"] = DK_IFB;
5654 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5655 DirectiveKindMap[
".ifc"] = DK_IFC;
5656 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5657 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5658 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5659 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5660 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5661 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5662 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5663 DirectiveKindMap[
".else"] = DK_ELSE;
5664 DirectiveKindMap[
".end"] = DK_END;
5665 DirectiveKindMap[
".endif"] = DK_ENDIF;
5666 DirectiveKindMap[
".skip"] = DK_SKIP;
5667 DirectiveKindMap[
".space"] = DK_SPACE;
5668 DirectiveKindMap[
".file"] = DK_FILE;
5669 DirectiveKindMap[
".line"] = DK_LINE;
5670 DirectiveKindMap[
".loc"] = DK_LOC;
5671 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5672 DirectiveKindMap[
".stabs"] = DK_STABS;
5673 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5674 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5675 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5676 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5677 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5678 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5679 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5680 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5681 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5682 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5683 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5684 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5685 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5686 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5687 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5688 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5689 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5690 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5691 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5692 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5693 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5694 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5695 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5696 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5697 DirectiveKindMap[
".cfi_llvm_register_pair"] = DK_CFI_LLVM_REGISTER_PAIR;
5698 DirectiveKindMap[
".cfi_llvm_vector_registers"] = DK_CFI_LLVM_VECTOR_REGISTERS;
5699 DirectiveKindMap[
".cfi_llvm_vector_offset"] = DK_CFI_LLVM_VECTOR_OFFSET;
5700 DirectiveKindMap[
".cfi_llvm_vector_register_mask"] =
5701 DK_CFI_LLVM_VECTOR_REGISTER_MASK;
5702 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5703 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5704 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5705 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5706 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5707 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5708 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5709 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5710 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5711 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5712 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5713 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5714 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5715 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5716 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5717 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5718 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5719 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5720 DirectiveKindMap[
".macro"] = DK_MACRO;
5721 DirectiveKindMap[
".exitm"] = DK_EXITM;
5722 DirectiveKindMap[
".endm"] = DK_ENDM;
5723 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5724 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5725 DirectiveKindMap[
".err"] = DK_ERR;
5726 DirectiveKindMap[
".error"] = DK_ERROR;
5727 DirectiveKindMap[
".warning"] = DK_WARNING;
5728 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5729 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5730 DirectiveKindMap[
".reloc"] = DK_RELOC;
5731 DirectiveKindMap[
".dc"] = DK_DC;
5732 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5733 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5734 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5735 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5736 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5737 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5738 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5739 DirectiveKindMap[
".dcb"] = DK_DCB;
5740 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5741 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5742 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5743 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5744 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5745 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5746 DirectiveKindMap[
".ds"] = DK_DS;
5747 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5748 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5749 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5750 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5751 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5752 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5753 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5754 DirectiveKindMap[
".print"] = DK_PRINT;
5755 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5756 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5757 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5758 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5759 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5760 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5763MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5764 AsmToken EndToken, StartToken = getTok();
5766 unsigned NestLevel = 0;
5770 printError(DirectiveLoc,
"no matching '.endr' in definition");
5775 StringRef Ident = getTok().getIdentifier();
5776 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5779 }
else if (Ident ==
".endr") {
5780 if (NestLevel == 0) {
5781 EndToken = getTok();
5785 printError(getTok().getLoc(),
"expected newline");
5793 eatToEndOfStatement();
5798 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5802 return &MacroLikeBodies.back();
5805void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5806 raw_svector_ostream &OS) {
5809 std::unique_ptr<MemoryBuffer> Instantiation =
5814 MacroInstantiation *
MI =
new MacroInstantiation{
5815 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5816 ActiveMacros.push_back(
MI);
5826bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5827 const MCExpr *CountExpr;
5828 SMLoc CountLoc = getTok().getLoc();
5829 if (parseExpression(CountExpr))
5833 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5834 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5837 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5841 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5847 SmallString<256> Buf;
5848 raw_svector_ostream OS(Buf);
5851 if (expandMacro(OS, *M, {}, {},
false))
5854 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5861bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5863 MCAsmMacroArguments
A;
5864 if (check(parseIdentifier(
Parameter.Name),
5865 "expected identifier in '.irp' directive") ||
5866 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5870 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5876 SmallString<256> Buf;
5877 raw_svector_ostream OS(Buf);
5879 for (
const MCAsmMacroArgument &Arg :
A) {
5882 if (expandMacro(OS, *M, Parameter, Arg,
true))
5886 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5893bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5895 MCAsmMacroArguments
A;
5897 if (check(parseIdentifier(
Parameter.Name),
5898 "expected identifier in '.irpc' directive") ||
5899 parseComma() || parseMacroArguments(
nullptr,
A))
5902 if (
A.size() != 1 ||
A.front().size() != 1)
5903 return TokError(
"unexpected token in '.irpc' directive");
5908 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5914 SmallString<256> Buf;
5915 raw_svector_ostream OS(Buf);
5918 :
A[0][0].getString();
5919 for (std::size_t
I = 0, End =
Values.size();
I != End; ++
I) {
5920 MCAsmMacroArgument Arg;
5925 if (expandMacro(OS, *M, Parameter, Arg,
true))
5929 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5934bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5935 if (ActiveMacros.empty())
5936 return TokError(
"unmatched '.endr' directive");
5946bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
5948 const MCExpr *
Value;
5949 SMLoc ExprLoc = getLexer().getLoc();
5950 if (parseExpression(
Value))
5954 return Error(ExprLoc,
"unexpected expression in _emit");
5957 return Error(ExprLoc,
"literal value out of range for directive");
5963bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
5964 const MCExpr *
Value;
5965 SMLoc ExprLoc = getLexer().getLoc();
5966 if (parseExpression(
Value))
5970 return Error(ExprLoc,
"unexpected expression in align");
5973 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5979bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5980 const AsmToken StrTok = getTok();
5983 return Error(DirectiveLoc,
"expected double quoted string after .print");
5990bool AsmParser::parseDirectiveAddrsig() {
5993 getStreamer().emitAddrsig();
5997bool AsmParser::parseDirectiveAddrsigSym() {
5999 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
6001 getStreamer().emitAddrsigSym(Sym);
6007bool AsmParser::parseDirectiveBundleAlignMode() {
6011 SMLoc ExprLoc = getLexer().getLoc();
6012 int64_t AlignSizePow2;
6013 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
6015 check(AlignSizePow2 < 1 || AlignSizePow2 > 30, ExprLoc,
6016 "invalid bundle alignment size (expected between 1 and 30)"))
6019 getStreamer().emitBundleAlignMode(
Align(1ULL << AlignSizePow2));
6025bool AsmParser::parseDirectiveBundleLock() {
6026 if (checkForValidSection())
6028 bool AlignToEnd =
false;
6031 SMLoc Loc = getTok().getLoc();
6032 const char *InvalidOptionError =
"invalid option for `.bundle_lock`";
6035 if (check(parseIdentifier(Option), Loc, InvalidOptionError) ||
6036 check(Option !=
"align_to_end", Loc, InvalidOptionError) || parseEOL())
6041 getStreamer().emitBundleLock(AlignToEnd, getTargetParser().getSTI());
6047bool AsmParser::parseDirectiveBundleUnlock() {
6048 if (checkForValidSection() || parseEOL())
6051 getStreamer().emitBundleUnlock(getTargetParser().getSTI());
6055bool AsmParser::parseDirectivePseudoProbe() {
6061 if (parseIntToken(
Guid))
6063 if (parseIntToken(Index))
6065 if (parseIntToken(
Type))
6067 if (parseIntToken(Attr))
6079 int64_t CallerGuid = 0;
6081 CallerGuid = getTok().getIntVal();
6089 int64_t CallerProbeId = 0;
6091 CallerProbeId = getTok().getIntVal();
6101 if (parseIdentifier(FnName))
6102 return Error(getLexer().getLoc(),
"expected identifier");
6108 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
6109 InlineStack, FnSym);
6118bool AsmParser::parseDirectiveLTODiscard() {
6119 auto ParseOp = [&]() ->
bool {
6121 SMLoc Loc = getTok().getLoc();
6122 if (parseIdentifier(Name))
6123 return Error(Loc,
"expected identifier");
6124 LTODiscardSymbols.
insert(Name);
6128 LTODiscardSymbols.
clear();
6129 return parseMany(ParseOp);
6155bool AsmParser::parseMSInlineAsm(
6156 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
6157 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
6158 SmallVectorImpl<std::string> &Constraints,
6159 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
6160 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
6161 SmallVector<void *, 4> InputDecls;
6162 SmallVector<void *, 4> OutputDecls;
6163 SmallVector<bool, 4> InputDeclsAddressOf;
6164 SmallVector<bool, 4> OutputDeclsAddressOf;
6165 SmallVector<std::string, 4> InputConstraints;
6166 SmallVector<std::string, 4> OutputConstraints;
6175 unsigned InputIdx = 0;
6176 unsigned OutputIdx = 0;
6179 if (parseCurlyBlockScope(AsmStrRewrites))
6182 ParseStatementInfo
Info(&AsmStrRewrites);
6183 bool StatementErr = parseStatement(Info, &SI);
6185 if (StatementErr ||
Info.ParseError) {
6187 printPendingErrors();
6192 assert(!hasPendingError() &&
"unexpected error from parseStatement");
6194 if (
Info.Opcode == ~0U)
6200 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
6201 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
6205 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
6206 unsigned NumDefs =
Desc.getNumDefs();
6215 if (SymName.
empty())
6223 if (Operand.
isImm()) {
6231 bool isOutput = (i == 1) &&
Desc.mayStore();
6238 OutputConstraints.
push_back((
"=" + Constraint).str());
6245 if (
Desc.operands()[i - 1].isBranchTarget())
6259 NumOutputs = OutputDecls.
size();
6260 NumInputs = InputDecls.
size();
6265 Clobbers.
assign(ClobberRegs.
size(), std::string());
6266 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6267 raw_string_ostream OS(Clobbers[
I]);
6272 if (NumOutputs || NumInputs) {
6273 unsigned NumExprs = NumOutputs + NumInputs;
6274 OpDecls.resize(NumExprs);
6275 Constraints.
resize(NumExprs);
6276 for (
unsigned i = 0; i < NumOutputs; ++i) {
6277 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6278 Constraints[i] = OutputConstraints[i];
6280 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6281 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6282 Constraints[
j] = InputConstraints[i];
6287 std::string AsmStringIR;
6288 raw_string_ostream OS(AsmStringIR);
6289 StringRef ASMString =
6291 const char *AsmStart = ASMString.
begin();
6292 const char *AsmEnd = ASMString.
end();
6294 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6295 const AsmRewrite &AR = *
I;
6302 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6305 if (
unsigned Len = Loc - AsmStart)
6306 OS << StringRef(AsmStart, Len);
6310 AsmStart = Loc + AR.
Len;
6314 unsigned AdditionalSkip = 0;
6336 size_t OffsetLen = OffsetName.
size();
6337 auto rewrite_it = std::find_if(
6338 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6339 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6340 (FusingAR.Kind == AOK_Input ||
6341 FusingAR.Kind == AOK_CallInput);
6343 if (rewrite_it == AsmStrRewrites.
end()) {
6344 OS <<
"offset " << OffsetName;
6346 OS <<
"${" << InputIdx++ <<
":P}";
6347 rewrite_it->Done =
true;
6349 OS <<
'$' << InputIdx++;
6350 rewrite_it->Done =
true;
6363 OS <<
"${" << InputIdx++ <<
":P}";
6365 OS <<
'$' << InputIdx++;
6368 OS <<
"${" << InputIdx++ <<
":P}";
6372 OS <<
"${" << OutputIdx++ <<
":P}";
6374 OS <<
'$' << OutputIdx++;
6379 case 8: OS <<
"byte ptr ";
break;
6380 case 16: OS <<
"word ptr ";
break;
6381 case 32: OS <<
"dword ptr ";
break;
6382 case 64: OS <<
"qword ptr ";
break;
6383 case 80: OS <<
"xword ptr ";
break;
6384 case 128: OS <<
"xmmword ptr ";
break;
6385 case 256: OS <<
"ymmword ptr ";
break;
6395 if (
getContext().getAsmInfo().getAlignmentIsInBytes())
6400 unsigned Val = AR.
Val;
6402 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6403 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6415 AsmStart = Loc + AR.
Len + AdditionalSkip;
6419 if (AsmStart != AsmEnd)
6420 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6422 AsmString = std::move(AsmStringIR);
6426bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6427 MCAsmParserSemaCallback *SI) {
6428 AsmToken LabelTok = getTok();
6429 SMLoc LabelLoc = LabelTok.
getLoc();
6432 if (parseIdentifier(LabelVal))
6433 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6438 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6447 return Error(LabelLoc,
6448 "Cannot have just a label for an HLASM inline asm statement");
6458 if (enabledGenDwarfForAssembly())
6465bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6466 MCAsmParserSemaCallback *SI) {
6467 AsmToken OperationEntryTok = Lexer.
getTok();
6468 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6469 StringRef OperationEntryVal;
6472 if (parseIdentifier(OperationEntryVal))
6473 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6479 return parseAndMatchAndEmitTargetInstruction(
6480 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6483bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6484 MCAsmParserSemaCallback *SI) {
6485 assert(!hasPendingError() &&
"parseStatement started with pending error");
6488 bool ShouldParseAsHLASMLabel =
false;
6497 ShouldParseAsHLASMLabel =
true;
6503 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6504 getTok().getString().
front() ==
'\n')
6519 if (getTok().getString().
front() ==
'\n' ||
6520 getTok().getString().
front() ==
'\r') {
6529 if (ShouldParseAsHLASMLabel) {
6532 if (parseAsHLASMLabel(Info, SI)) {
6535 eatToEndOfStatement();
6540 return parseAsMachineInstruction(Info, SI);
6552 return Parser.
TokError(
"missing expression");
6558 return Parser.
Error(
6559 EqualLoc,
"relocation specifier not permitted in symbol equating");
6567 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6573 }
else if (Name ==
".") {
6588 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6589 return new HLASMAsmParser(SM,
C, Out, MAI, CB);
6591 return new AsmParser(SM,
C, Out, MAI, CB);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static Expected< std::vector< unsigned > > getSymbols(SymbolicFile *Obj, uint16_t Index, raw_ostream &SymNames, SymMap *SymMap)
static bool isValidEncoding(int64_t Encoding)
static bool isMacroArgChar(char C)
static bool isAngleBracketString(SMLoc &StrLoc, SMLoc &EndLoc)
This function checks if the next token is <string> type or arithmetic.
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static unsigned getGNUBinOpPrecedence(const MCAsmInfo &MAI, AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static std::string angleBracketString(StringRef AltMacroStr)
creating a string without the escape characters '!'.
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
static bool parseHexOcta(AsmParser &Asm, uint64_t &hi, uint64_t &lo)
static bool isOperator(AsmToken::TokenKind kind)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
This file contains constants used for implementing Dwarf debug support.
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_BASIC_BLOCK
#define DWARF2_LINE_DEFAULT_IS_STMT
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
Promote Memory to Register
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
static StringRef getName(Value *V)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Class for arbitrary precision integers.
LLVM_ABI APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
unsigned getBitWidth() const
Return the number of bits in the APInt.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
ConditionalAssemblyType TheCond
static bool isIdentifierChar(char C, bool AllowAt, bool AllowHash)
SMLoc getLoc() const
Get the current source location.
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool getAllowAtInIdentifier()
void UnLex(AsmToken const &Token)
AsmToken::TokenKind getKind() const
Get the kind of current token.
const MCAsmInfo & getMAI() const
const AsmToken & getTok() const
Get the current (last) lexed token.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
SMLoc getErrLoc()
Get the current error location.
const std::string & getErr()
Get the current error string.
const AsmToken & Lex()
Consume the next token from the input stream and return it.
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
LLVM_ABI void setBuffer(StringRef Buf, const char *ptr=nullptr, bool EndStatementAtEOF=true)
Set buffer to be lexed.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
LLVM_ABI size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)
Look ahead an arbitrary number of tokens.
LLVM_ABI SMLoc getLoc() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
bool is(TokenKind K) const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Error takeError()
Take ownership of the stored error.
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
bool isLittleEndian() const
True if the target is little endian.
bool useAtForSpecifier() const
bool doesAllowAtInName() const
std::optional< uint32_t > getSpecifierForName(StringRef Name) const
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
bool shouldUseLogicalShr() const
StringRef getCommentString() const
StringRef getInternalSymbolPrefix() const
bool hasSubsectionsViaSymbols() const
bool getCOMMDirectiveAlignmentIsInBytes() const
virtual bool useCodeAlign(const MCSection &Sec) const
bool useParensForSpecifier() const
bool getDollarIsPC() const
virtual ~MCAsmParserSemaCallback()
Generic assembler parser interface, for use by target specific assembly parsers.
bool Error(SMLoc L, const Twine &Msg, SMRange Range={})
Return an error at the location L, with the message Msg.
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
bool parseAtSpecifier(const MCExpr *&Res, SMLoc &EndLoc)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
const MCExpr * applySpecifier(const MCExpr *E, uint32_t Variant)
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
bool TokError(const Twine &Msg, SMRange Range={})
Report an error at the current lexer location.
MCStreamer & getStreamer()
MCTargetAsmParser & getTargetParser() const
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
@ AShr
Arithmetic shift right.
@ LShr
Logical shift right.
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
@ Xor
Bitwise exclusive or.
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
@ NE
Inequality comparison.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
void * allocate(unsigned Size, unsigned Align=8)
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
bool getGenDwarfForAssembly()
void setGenDwarfForAssembly(bool Value)
void setDwarfVersion(uint16_t v)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_ABI MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
LLVM_ABI MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
uint16_t getDwarfVersion() const
LLVM_ABI MCSymbol * cloneSymbol(MCSymbol &Sym)
Clone a symbol for the .set directive, replacing it in the symbol table.
LLVM_ABI MCSymbol * parseSymbol(const Twine &Name)
Variant of getOrCreateSymbol that handles backslash-escaped symbols.
const MCAsmInfo & getAsmInfo() const
LLVM_ABI MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
virtual void printRegName(raw_ostream &OS, MCRegister Reg)
Print the assembler register name.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
virtual bool isMemUseUpRegs() const
isMemUseUpRegs - Is memory operand use up regs, for example, intel MS inline asm may use ARR[baseReg ...
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label?
virtual MCRegister getReg() const =0
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable,...
virtual StringRef getSymName()
virtual bool isImm() const =0
isImm - Is this an immediate operand?
unsigned getMCOperandNum()
StringRef getConstraint()
virtual void * getOpDecl()
void setBeginSymbol(MCSymbol *Sym)
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
void setStartTokLocPtr(const SMLoc *Loc)
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
virtual void initSections(const MCSubtargetInfo &STI)
Create the default sections and set the initial one.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
MCTargetStreamer * getTargetStreamer()
MCLFIRewriter * getLFIRewriter()
virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc)
Emit some number of copies of Value until the byte offset Offset is reached.
virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol, but only if Value is also emitted.
void finish(SMLoc EndLoc=SMLoc())
Finish emission of machine code.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
uint16_t getSpecifier() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
bool isRedefinable() const
Check if this symbol is redefinable.
void setRedefinable(bool Value)
Mark this symbol as redefinable.
void redefineIfPossible()
Prepare this symbol to be redefined.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Unary assembler expressions.
Opcode getOpcode() const
Get the kind of this unary expression.
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getSubExpr() const
Get the child of this unary expression.
static const MCUnaryExpr * createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
StringRef getBuffer() const
constexpr bool isFailure() const
constexpr bool isSuccess() const
SourceMgr::DiagKind getKind() const
StringRef getLineContents() const
StringRef getMessage() const
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
const SourceMgr * getSourceMgr() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
constexpr bool isValid() const
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
LLVM_ABI void printIncludeStackForDiagnostic(SMLoc Loc, raw_ostream &OS) const
Prints the include stack of a buffer unless it is a macro instantiation buffer.
unsigned getMainFileID() const
const MemoryBuffer * getMemoryBuffer(unsigned i) const
LLVM_ABI void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
SMLoc getParentIncludeLoc(unsigned i) const
LLVM_ABI unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
LLVM_ABI ErrorOr< std::unique_ptr< MemoryBuffer > > OpenIncludeFile(const std::string &Filename, std::string &IncludedFile, bool RequiresNullTerminator=true)
Search for a file with the specified name in the current directory or in one of the IncludeDirs,...
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
LLVM_ABI unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
StringMapIterBase< ValueTy, true > const_iterator
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
constexpr size_t size() const
Get the string size.
char front() const
Get the first character in the string.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
LLVM_ABI std::string lower() const
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
LLVM Value Representation.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
LLVM_ABI bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
std::variant< std::monostate, DecisionParameters, BranchParameters > Parameters
The type of MC/DC-specific parameters.
@ Parameter
An inlay hint that is for a parameter.
LLVM_ABI Instruction & front() const
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation. The return string is half the size of ...
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
RelativeUniformCounterPtr Values
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
std::tuple< uint64_t, uint32_t > InlineSite
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
auto unique(Range &&R, Predicate P)
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI SourceMgr SrcMgr
auto reverse(ContainerTy &&C)
cl::opt< unsigned > AsmMacroMaxNestingDepth
SmallVector< InlineSite, 8 > MCPseudoProbeInlineStack
const char AsmRewritePrecedence[]
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool hasDiscriminator(uint32_t Flags)
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ABI llvm::Error decodeBase64(llvm::StringRef Input, std::vector< char > &Output)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance for parsing assembly similar to gas syntax.
@ Sub
Subtraction of integers.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
void consumeError(Error Err)
Consume a Error without doing anything.
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
ArrayRef< int > hi(ArrayRef< int > Vuu)
ArrayRef< int > lo(ArrayRef< int > Vuu)
std::vector< AsmToken > Value
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
std::optional< StringRef > Source
The source code of the file.