81typedef std::vector<AsmToken> MCAsmMacroArgument;
82typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
86struct MacroInstantiation {
88 SMLoc InstantiationLoc;
97 size_t CondStackDepth;
100struct ParseStatementInfo {
105 unsigned Opcode = ~0
U;
108 bool ParseError =
false;
110 SmallVectorImpl<AsmRewrite> *AsmRewrites =
nullptr;
112 ParseStatementInfo() =
delete;
113 ParseStatementInfo(SmallVectorImpl<AsmRewrite> *rewrites)
114 : AsmRewrites(rewrites) {}
121 void *SavedDiagContext;
122 std::unique_ptr<MCAsmParserExtension> PlatformParser;
123 std::unique_ptr<MCAsmParserExtension> LFIParser;
125 std::optional<SMLoc> CFIStartProcLoc;
131 AsmCond TheCondState;
132 std::vector<AsmCond> TheCondStack;
137 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
140 std::vector<MacroInstantiation*> ActiveMacros;
143 std::deque<MCAsmMacro> MacroLikeBodies;
146 unsigned MacrosEnabledFlag : 1;
149 unsigned NumOfMacroInstantiations = 0;
152 struct CppHashInfoTy {
157 CppHashInfoTy() : LineNumber(0), Buf(0) {}
159 CppHashInfoTy CppHashInfo;
162 bool HadCppHashFilename =
false;
167 SmallSet<StringRef, 2> LTODiscardSymbols;
170 unsigned AssemblerDialect = ~0
U;
173 bool IsDarwin =
false;
176 bool ParsingMSInlineAsm =
false;
179 bool ReportedInconsistentMD5 =
false;
182 bool AltMacroMode =
false;
185 virtual bool parseStatement(ParseStatementInfo &Info,
186 MCAsmParserSemaCallback *SI);
191 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
192 StringRef IDVal, AsmToken
ID,
198 bool enabledGenDwarfForAssembly();
201 AsmParser(SourceMgr &
SM, MCContext &Ctx, MCStreamer &Out,
202 const MCAsmInfo &MAI,
unsigned CB);
203 AsmParser(
const AsmParser &) =
delete;
204 AsmParser &operator=(
const AsmParser &) =
delete;
205 ~AsmParser()
override;
207 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
209 void addDirectiveHandler(StringRef Directive,
210 ExtensionDirectiveHandler Handler)
override {
211 ExtensionDirectiveMap[Directive] = std::move(Handler);
214 void addAliasForDirective(StringRef Directive, StringRef Alias)
override {
215 DirectiveKindMap[Directive.
lower()] = DirectiveKindMap[Alias.
lower()];
221 CodeViewContext &getCVContext() {
return Ctx.getCVContext(); }
223 unsigned getAssemblerDialect()
override {
224 if (AssemblerDialect == ~0U)
225 return MAI.getAssemblerDialect();
227 return AssemblerDialect;
229 void setAssemblerDialect(
unsigned i)
override {
230 AssemblerDialect = i;
233 void Note(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
234 bool Warning(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
235 bool printError(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
237 const AsmToken &Lex()
override;
239 void setParsingMSInlineAsm(
bool V)
override {
240 ParsingMSInlineAsm =
V;
243 Lexer.setLexMasmIntegers(V);
245 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
247 bool discardLTOSymbol(StringRef Name)
const override {
248 return LTODiscardSymbols.contains(Name);
251 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
253 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
254 SmallVectorImpl<std::string> &Constraints,
255 SmallVectorImpl<std::string> &Clobbers,
256 const MCInstrInfo *MII, MCInstPrinter *IP,
257 MCAsmParserSemaCallback &SI)
override;
259 bool parseExpression(
const MCExpr *&Res);
260 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
261 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
262 AsmTypeInfo *TypeInfo)
override;
263 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
264 bool parseAbsoluteExpression(int64_t &Res)
override;
268 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
272 bool parseIdentifier(StringRef &Res)
override;
273 void eatToEndOfStatement()
override;
275 bool checkForValidSection()
override;
280 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
281 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
283 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
285 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
290 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
293 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
296 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
302 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
305 void handleMacroExit();
308 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
311 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
313 void printMacroInstantiations();
315 SMRange
Range = {})
const {
322 bool enterIncludeFile(
const std::string &
Filename);
326 bool processIncbinFile(
const std::string &
Filename, int64_t Skip = 0,
327 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
335 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
340 StringRef parseStringToEndOfStatement()
override;
344 StringRef parseStringToComma();
346 enum class AssignmentKind {
353 bool parseAssignment(StringRef Name, AssignmentKind Kind);
358 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
359 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
360 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
362 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
364 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
365 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
436 DK_WEAK_DEF_CAN_BE_HIDDEN,
477 DK_CV_INLINE_SITE_ID,
480 DK_CV_INLINE_LINETABLE,
485 DK_CV_FILECHECKSUM_OFFSET,
491 DK_CFI_DEF_CFA_OFFSET,
492 DK_CFI_ADJUST_CFA_OFFSET,
493 DK_CFI_DEF_CFA_REGISTER,
494 DK_CFI_LLVM_DEF_ASPACE_CFA,
499 DK_CFI_REMEMBER_STATE,
500 DK_CFI_RESTORE_STATE,
504 DK_CFI_RETURN_COLUMN,
531 DK_LTO_SET_CONDITIONAL,
532 DK_CFI_MTE_TAGGED_FRAME,
540 StringMap<DirectiveKind> DirectiveKindMap;
543 enum CVDefRangeType {
545 CVDR_DEFRANGE_REGISTER,
546 CVDR_DEFRANGE_FRAMEPOINTER_REL,
547 CVDR_DEFRANGE_SUBFIELD_REGISTER,
548 CVDR_DEFRANGE_REGISTER_REL,
549 CVDR_DEFRANGE_REGISTER_REL_INDIR
554 StringMap<CVDefRangeType> CVDefRangeTypeMap;
557 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
558 bool parseDirectiveBase64();
559 bool parseDirectiveReloc(SMLoc DirectiveLoc);
560 bool parseDirectiveValue(StringRef IDVal,
562 bool parseDirectiveOctaValue(StringRef IDVal);
563 bool parseDirectiveRealValue(StringRef IDVal,
564 const fltSemantics &);
565 bool parseDirectiveFill();
566 bool parseDirectiveZero();
568 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
569 bool parseDirectiveOrg();
571 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
572 bool parseDirectivePrefAlign();
575 bool parseDirectiveFile(SMLoc DirectiveLoc);
576 bool parseDirectiveLine();
577 bool parseDirectiveLoc();
578 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
579 bool parseDirectiveStabs();
583 bool parseDirectiveCVFile();
584 bool parseDirectiveCVFuncId();
585 bool parseDirectiveCVInlineSiteId();
586 bool parseDirectiveCVLoc();
587 bool parseDirectiveCVLinetable();
588 bool parseDirectiveCVInlineLinetable();
589 bool parseDirectiveCVDefRange();
590 bool parseDirectiveCVString();
591 bool parseDirectiveCVStringTable();
592 bool parseDirectiveCVFileChecksums();
593 bool parseDirectiveCVFileChecksumOffset();
594 bool parseDirectiveCVFPOData();
597 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
598 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
599 bool parseDirectiveCFISections();
600 bool parseDirectiveCFIStartProc();
601 bool parseDirectiveCFIEndProc();
602 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
603 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
604 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
605 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
606 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
607 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
608 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
609 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
610 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
611 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
612 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
613 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
614 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
615 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
616 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
617 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
618 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
619 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
622 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
623 bool parseDirectiveExitMacro(StringRef Directive);
624 bool parseDirectiveEndMacro(StringRef Directive);
625 bool parseDirectiveMacro(SMLoc DirectiveLoc);
626 bool parseDirectiveMacrosOnOff(StringRef Directive);
628 bool parseDirectiveAltmacro(StringRef Directive);
631 bool parseDirectiveSpace(StringRef IDVal);
634 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
635 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
637 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
640 bool parseDirectiveLEB128(
bool Signed);
646 bool parseDirectiveComm(
bool IsLocal);
648 bool parseDirectiveAbort(SMLoc DirectiveLoc);
649 bool parseDirectiveInclude();
650 bool parseDirectiveIncbin();
653 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
655 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
657 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
659 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
661 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
662 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
663 bool parseDirectiveElse(SMLoc DirectiveLoc);
664 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
665 bool parseEscapedString(std::string &
Data)
override;
666 bool parseAngleBracketString(std::string &
Data)
override;
669 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
670 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
671 raw_svector_ostream &OS);
672 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
673 bool parseDirectiveIrp(SMLoc DirectiveLoc);
674 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
675 bool parseDirectiveEndr(SMLoc DirectiveLoc);
678 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,
682 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
685 bool parseDirectiveEnd(SMLoc DirectiveLoc);
688 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
691 bool parseDirectiveWarning(SMLoc DirectiveLoc);
694 bool parseDirectivePrint(SMLoc DirectiveLoc);
697 bool parseDirectivePseudoProbe();
700 bool parseDirectiveLTODiscard();
703 bool parseDirectiveAddrsig();
704 bool parseDirectiveAddrsigSym();
706 void initializeDirectiveKindMap();
707 void initializeCVDefRangeTypeMap();
710class HLASMAsmParser final :
public AsmParser {
715 void lexLeadingSpaces() {
720 bool parseAsHLASMLabel(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI);
721 bool parseAsMachineInstruction(ParseStatementInfo &Info,
722 MCAsmParserSemaCallback *SI);
725 HLASMAsmParser(SourceMgr &
SM, MCContext &Ctx, MCStreamer &Out,
726 const MCAsmInfo &MAI,
unsigned CB = 0)
727 : AsmParser(
SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
728 Lexer.setSkipSpace(
false);
729 Lexer.setAllowHashInIdentifier(
true);
730 Lexer.setLexHLASMIntegers(
true);
731 Lexer.setLexHLASMStrings(
true);
734 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
736 bool parseStatement(ParseStatementInfo &Info,
737 MCAsmParserSemaCallback *SI)
override;
750 :
MCAsmParser(Ctx, Out,
SM, MAI), CurBuffer(CB ? CB :
SM.getMainFileID()),
751 MacrosEnabledFlag(
true) {
754 SavedDiagHandler =
SrcMgr.getDiagHandler();
755 SavedDiagContext =
SrcMgr.getDiagContext();
763 switch (Ctx.getObjectFileType()) {
764 case MCContext::IsCOFF:
765 PlatformParser.reset(createCOFFAsmParser());
767 case MCContext::IsMachO:
768 PlatformParser.reset(createDarwinAsmParser());
771 case MCContext::IsELF:
772 PlatformParser.reset(createELFAsmParser());
774 case MCContext::IsGOFF:
775 PlatformParser.reset(createGOFFAsmParser());
777 case MCContext::IsSPIRV:
779 "Need to implement createSPIRVAsmParser for SPIRV format.");
781 case MCContext::IsWasm:
782 PlatformParser.reset(createWasmAsmParser());
784 case MCContext::IsXCOFF:
785 PlatformParser.reset(createXCOFFAsmParser());
787 case MCContext::IsDXContainer:
788 report_fatal_error(
"DXContainer is not supported yet");
792 PlatformParser->Initialize(*
this);
794 LFIParser.reset(createLFIAsmParser(Out.getLFIRewriter()));
795 LFIParser->Initialize(*this);
797 initializeDirectiveKindMap();
798 initializeCVDefRangeTypeMap();
801AsmParser::~AsmParser() {
802 assert((HadError || ActiveMacros.empty()) &&
803 "Unexpected active macro instantiation!");
812void AsmParser::printMacroInstantiations() {
814 for (MacroInstantiation *M :
reverse(ActiveMacros))
816 "while in macro instantiation");
819void AsmParser::Note(SMLoc L,
const Twine &Msg, SMRange
Range) {
820 printPendingErrors();
822 printMacroInstantiations();
825bool AsmParser::Warning(SMLoc L,
const Twine &Msg, SMRange
Range) {
826 if(getTargetParser().getTargetOptions().MCNoWarn)
828 if (getTargetParser().getTargetOptions().MCFatalWarnings)
831 printMacroInstantiations();
835bool AsmParser::printError(SMLoc L,
const Twine &Msg, SMRange
Range) {
838 printMacroInstantiations();
842bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
843 std::string IncludedFile;
857bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
858 const MCExpr *
Count, SMLoc Loc) {
860 if (SymbolScanningMode)
863 std::string IncludedFile;
874 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
875 return Error(Loc,
"expected absolute expression");
877 return Warning(Loc,
"negative count has no effect");
880 getStreamer().emitBytes(Bytes);
884void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
890const AsmToken &AsmParser::Lex() {
897 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
902 const AsmToken *tok = &Lexer.
Lex();
915 if (ParentIncludeLoc != SMLoc()) {
916 jumpToLoc(ParentIncludeLoc);
924bool AsmParser::enabledGenDwarfForAssembly() {
931 if (
getContext().getGenDwarfFileNumber() == 0) {
932 const MCDwarfFile &RootFile =
933 getContext().getMCDwarfLineTable(0).getRootFile();
934 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
941bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
942 LTODiscardSymbols.
clear();
945 if (!NoInitialTextSection)
952 AsmCond StartingCondState = TheCondState;
960 MCSection *Sec = getStreamer().getCurrentSectionOnly();
963 getStreamer().emitLabel(SectionStartSym);
966 bool InsertResult =
getContext().addGenDwarfSection(Sec);
967 assert(InsertResult &&
".text section should not have debug info yet");
971 getTargetParser().onBeginOfFile();
975 ParseStatementInfo
Info(&AsmStrRewrites);
976 bool HasError = parseStatement(Info,
nullptr);
985 printPendingErrors();
988 if (HasError && !getLexer().justConsumedEOL())
989 eatToEndOfStatement();
992 getTargetParser().onEndOfFile();
993 printPendingErrors();
996 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1000 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1002 const auto &LineTables =
getContext().getMCDwarfLineTables();
1003 if (!LineTables.empty()) {
1005 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1006 if (
File.Name.empty() && Index != 0)
1007 printError(getTok().getLoc(),
"unassigned file number: " +
1009 " for .file directives");
1021 MCSymbol *Sym = TableEntry.getValue().Symbol;
1030 printError(getTok().getLoc(),
"assembler local symbol '" +
1031 Sym->
getName() +
"' not defined");
1037 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1038 if (std::get<2>(LocSym)->isUndefined()) {
1041 CppHashInfo = std::get<1>(LocSym);
1042 printError(std::get<0>(LocSym),
"directional label undefined");
1048 if (!HadError && !NoFinalize) {
1050 TS->emitConstantPools();
1058bool AsmParser::checkForValidSection() {
1059 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1061 return Error(getTok().getLoc(),
1062 "expected section directive before assembly directive");
1068void AsmParser::eatToEndOfStatement() {
1077StringRef AsmParser::parseStringToEndOfStatement() {
1078 const char *
Start = getTok().getLoc().getPointer();
1084 return StringRef(Start, End - Start);
1087StringRef AsmParser::parseStringToComma() {
1088 const char *
Start = getTok().getLoc().getPointer();
1094 const char *End = getTok().getLoc().getPointer();
1095 return StringRef(Start, End - Start);
1103bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1104 if (parseExpression(Res))
1107 return parseRParen();
1115bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1116 if (parseExpression(Res))
1118 EndLoc = getTok().getEndLoc();
1119 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1130bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1131 AsmTypeInfo *TypeInfo) {
1132 SMLoc FirstTokenLoc = getLexer().getLoc();
1134 switch (FirstTokenKind) {
1136 return TokError(
"unknown token in expression");
1142 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1152 if (parseIdentifier(Identifier)) {
1156 bool ShouldGenerateTempSymbol =
false;
1159 ShouldGenerateTempSymbol =
true;
1161 if (!ShouldGenerateTempSymbol)
1162 return Error(FirstTokenLoc,
"invalid token in expression");
1171 EndLoc = FirstTokenLoc;
1176 std::pair<StringRef, StringRef>
Split;
1181 SMLoc AtLoc = getLexer().getLoc();
1183 if (parseIdentifier(VName))
1184 return Error(AtLoc,
"expected symbol variant after '@'");
1186 Split = std::make_pair(Identifier, VName);
1194 parseIdentifier(VName);
1197 Split = std::make_pair(Identifier, VName);
1205 return Error(getLexer().getLoc(),
"expected a symbol reference");
1209 if (!
Split.second.empty()) {
1211 if (MaybeSpecifier) {
1213 Spec = *MaybeSpecifier;
1216 "invalid variant '" +
Split.second +
"'");
1231 DoInline = TV->inlineAssignedExpr();
1234 return Error(EndLoc,
"unexpected modifier on variable reference");
1245 return TokError(
"literal value out of range for directive");
1247 SMLoc Loc = getTok().getLoc();
1248 int64_t
IntVal = getTok().getIntVal();
1254 StringRef IDVal = getTok().getString();
1256 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1258 if (
Split.first.size() != IDVal.
size()) {
1261 return TokError(
"invalid variant '" +
Split.second +
"'");
1262 IDVal =
Split.first;
1265 if (IDVal ==
"f" || IDVal ==
"b") {
1270 return Error(Loc,
"directional label undefined");
1271 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1279 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1280 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
1288 return TokError(
"cannot use . as current PC");
1301 return parseParenExpr(Res, EndLoc);
1303 if (!PlatformParser->HasBracketExpressions())
1304 return TokError(
"brackets expression not supported on this target");
1306 return parseBracketExpr(Res, EndLoc);
1309 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1315 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1321 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1328bool AsmParser::parseExpression(
const MCExpr *&Res) {
1330 return parseExpression(Res, EndLoc);
1340 switch (E->getKind()) {
1351 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1352 "' (already modified)");
1403 "Argument to the function cannot be a NULL value");
1405 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1406 (*CharPtr !=
'\0')) {
1407 if (*CharPtr ==
'!')
1411 if (*CharPtr ==
'>') {
1421 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1422 if (AltMacroStr[Pos] ==
'!')
1424 Res += AltMacroStr[Pos];
1432 return TokError(
"expected specifier following '@'");
1434 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1436 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1456bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1459 auto &TS = getTargetParser();
1460 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1468 return TokError(
"unexpected symbol modifier following '@'");
1472 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1474 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1476 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1477 "' (no symbols present)");
1487 if (Res->evaluateAsAbsolute(
Value))
1493bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1495 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1498bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1501 SMLoc StartLoc = Lexer.
getLoc();
1502 if (parseExpression(Expr))
1505 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1506 return Error(StartLoc,
"expected absolute expression");
1513 bool ShouldUseLogicalShr) {
1590 bool ShouldUseLogicalShr) {
1679bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1681 SMLoc StartLoc = Lexer.
getLoc();
1684 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1688 if (TokPrec < Precedence)
1695 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1701 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1702 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1714bool AsmParser::parseStatement(ParseStatementInfo &Info,
1715 MCAsmParserSemaCallback *SI) {
1716 assert(!hasPendingError() &&
"parseStatement started with pending error");
1722 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1723 getTok().getString().
front() ==
'\n')
1729 AsmToken
ID = getTok();
1730 SMLoc IDLoc =
ID.getLoc();
1732 int64_t LocalLabelVal = -1;
1733 StartTokLoc =
ID.getLoc();
1735 return parseCppHashLineFilenameComment(IDLoc,
1736 !isInsideMacroInstantiation());
1740 LocalLabelVal = getTok().getIntVal();
1741 if (LocalLabelVal < 0) {
1742 if (!TheCondState.
Ignore) {
1744 return Error(IDLoc,
"unexpected token at start of statement");
1748 IDVal = getTok().getString();
1751 if (!TheCondState.
Ignore) {
1753 return Error(IDLoc,
"unexpected token at start of statement");
1761 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1763 IDVal =
ID.getString();
1764 }
else if (parseIdentifier(IDVal)) {
1765 if (!TheCondState.
Ignore) {
1767 return Error(IDLoc,
"unexpected token at start of statement");
1776 DirectiveKindMap.find(IDVal.
lower());
1777 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1779 : DirKindIt->getValue();
1790 return parseDirectiveIf(IDLoc, DirKind);
1792 return parseDirectiveIfb(IDLoc,
true);
1794 return parseDirectiveIfb(IDLoc,
false);
1796 return parseDirectiveIfc(IDLoc,
true);
1798 return parseDirectiveIfeqs(IDLoc,
true);
1800 return parseDirectiveIfc(IDLoc,
false);
1802 return parseDirectiveIfeqs(IDLoc,
false);
1804 return parseDirectiveIfdef(IDLoc,
true);
1807 return parseDirectiveIfdef(IDLoc,
false);
1809 return parseDirectiveElseIf(IDLoc);
1811 return parseDirectiveElse(IDLoc);
1813 return parseDirectiveEndIf(IDLoc);
1818 if (TheCondState.
Ignore) {
1819 eatToEndOfStatement();
1829 if (checkForValidSection())
1836 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1844 if (LocalLabelVal == -1) {
1845 if (ParsingMSInlineAsm && SI) {
1846 StringRef RewrittenLabel =
1847 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1849 "We should have an internal name here.");
1852 IDVal = RewrittenLabel;
1862 StringRef CommentStr = parseStringToEndOfStatement();
1873 if (MAI.
isMachO() && CFIStartProcLoc) {
1874 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1875 if (SymM->isExternal() && !SymM->isAltEntry())
1876 return Error(StartTokLoc,
"non-private labels cannot appear between "
1877 ".cfi_startproc / .cfi_endproc pairs") &&
1878 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1881 if (discardLTOSymbol(IDVal))
1884 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1887 if (!getTargetParser().isParsingMSInlineAsm())
1892 if (enabledGenDwarfForAssembly())
1896 getTargetParser().onLabelParsed(Sym);
1905 return parseAssignment(IDVal, AssignmentKind::Equal);
1909 if (areMacrosEnabled())
1910 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1911 return handleMacroEntry(M, IDLoc);
1928 getTargetParser().flushPendingInstructions(getStreamer());
1930 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
1932 "Should only return Failure iff there was an error");
1940 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1941 ExtensionDirectiveMap.
lookup(IDVal);
1943 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1952 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1954 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1955 case DK_LTO_SET_CONDITIONAL:
1956 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1958 return parseDirectiveAscii(IDVal,
false);
1961 return parseDirectiveAscii(IDVal,
true);
1963 return parseDirectiveBase64();
1966 return parseDirectiveValue(IDVal, 1);
1972 return parseDirectiveValue(IDVal, 2);
1977 return parseDirectiveValue(IDVal, 4);
1980 return parseDirectiveValue(IDVal, 8);
1982 return parseDirectiveValue(
1983 IDVal,
getContext().getAsmInfo()->getCodePointerSize());
1985 return parseDirectiveOctaValue(IDVal);
1989 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1992 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1994 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1995 return parseDirectiveAlign(IsPow2, 1);
1998 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1999 return parseDirectiveAlign(IsPow2, 4);
2002 return parseDirectiveAlign(
false, 1);
2004 return parseDirectiveAlign(
false, 2);
2006 return parseDirectiveAlign(
false, 4);
2008 return parseDirectiveAlign(
true, 1);
2010 return parseDirectiveAlign(
true, 2);
2012 return parseDirectiveAlign(
true, 4);
2014 return parseDirectivePrefAlign();
2016 return parseDirectiveOrg();
2018 return parseDirectiveFill();
2020 return parseDirectiveZero();
2022 eatToEndOfStatement();
2026 return parseDirectiveSymbolAttribute(
MCSA_Global);
2027 case DK_LAZY_REFERENCE:
2029 case DK_NO_DEAD_STRIP:
2031 case DK_SYMBOL_RESOLVER:
2033 case DK_PRIVATE_EXTERN:
2037 case DK_WEAK_DEFINITION:
2039 case DK_WEAK_REFERENCE:
2041 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2044 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2047 return parseDirectiveComm(
false);
2049 return parseDirectiveComm(
true);
2051 return parseDirectiveAbort(IDLoc);
2053 return parseDirectiveInclude();
2055 return parseDirectiveIncbin();
2058 return TokError(Twine(IDVal) +
2059 " not currently supported for this target");
2061 return parseDirectiveRept(IDLoc, IDVal);
2063 return parseDirectiveIrp(IDLoc);
2065 return parseDirectiveIrpc(IDLoc);
2067 return parseDirectiveEndr(IDLoc);
2069 return parseDirectiveLEB128(
true);
2071 return parseDirectiveLEB128(
false);
2074 return parseDirectiveSpace(IDVal);
2076 return parseDirectiveFile(IDLoc);
2078 return parseDirectiveLine();
2080 return parseDirectiveLoc();
2082 return parseDirectiveLocLabel(IDLoc);
2084 return parseDirectiveStabs();
2086 return parseDirectiveCVFile();
2088 return parseDirectiveCVFuncId();
2089 case DK_CV_INLINE_SITE_ID:
2090 return parseDirectiveCVInlineSiteId();
2092 return parseDirectiveCVLoc();
2093 case DK_CV_LINETABLE:
2094 return parseDirectiveCVLinetable();
2095 case DK_CV_INLINE_LINETABLE:
2096 return parseDirectiveCVInlineLinetable();
2097 case DK_CV_DEF_RANGE:
2098 return parseDirectiveCVDefRange();
2100 return parseDirectiveCVString();
2101 case DK_CV_STRINGTABLE:
2102 return parseDirectiveCVStringTable();
2103 case DK_CV_FILECHECKSUMS:
2104 return parseDirectiveCVFileChecksums();
2105 case DK_CV_FILECHECKSUM_OFFSET:
2106 return parseDirectiveCVFileChecksumOffset();
2107 case DK_CV_FPO_DATA:
2108 return parseDirectiveCVFPOData();
2109 case DK_CFI_SECTIONS:
2110 return parseDirectiveCFISections();
2111 case DK_CFI_STARTPROC:
2112 return parseDirectiveCFIStartProc();
2113 case DK_CFI_ENDPROC:
2114 return parseDirectiveCFIEndProc();
2115 case DK_CFI_DEF_CFA:
2116 return parseDirectiveCFIDefCfa(IDLoc);
2117 case DK_CFI_DEF_CFA_OFFSET:
2118 return parseDirectiveCFIDefCfaOffset(IDLoc);
2119 case DK_CFI_ADJUST_CFA_OFFSET:
2120 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2121 case DK_CFI_DEF_CFA_REGISTER:
2122 return parseDirectiveCFIDefCfaRegister(IDLoc);
2123 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2124 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2126 return parseDirectiveCFIOffset(IDLoc);
2127 case DK_CFI_REL_OFFSET:
2128 return parseDirectiveCFIRelOffset(IDLoc);
2129 case DK_CFI_PERSONALITY:
2130 return parseDirectiveCFIPersonalityOrLsda(
true);
2132 return parseDirectiveCFIPersonalityOrLsda(
false);
2133 case DK_CFI_REMEMBER_STATE:
2134 return parseDirectiveCFIRememberState(IDLoc);
2135 case DK_CFI_RESTORE_STATE:
2136 return parseDirectiveCFIRestoreState(IDLoc);
2137 case DK_CFI_SAME_VALUE:
2138 return parseDirectiveCFISameValue(IDLoc);
2139 case DK_CFI_RESTORE:
2140 return parseDirectiveCFIRestore(IDLoc);
2142 return parseDirectiveCFIEscape(IDLoc);
2143 case DK_CFI_RETURN_COLUMN:
2144 return parseDirectiveCFIReturnColumn(IDLoc);
2145 case DK_CFI_SIGNAL_FRAME:
2146 return parseDirectiveCFISignalFrame(IDLoc);
2147 case DK_CFI_UNDEFINED:
2148 return parseDirectiveCFIUndefined(IDLoc);
2149 case DK_CFI_REGISTER:
2150 return parseDirectiveCFIRegister(IDLoc);
2151 case DK_CFI_WINDOW_SAVE:
2152 return parseDirectiveCFIWindowSave(IDLoc);
2154 return parseDirectiveCFILabel(IDLoc);
2155 case DK_CFI_VAL_OFFSET:
2156 return parseDirectiveCFIValOffset(IDLoc);
2159 return parseDirectiveMacrosOnOff(IDVal);
2161 return parseDirectiveMacro(IDLoc);
2164 return parseDirectiveAltmacro(IDVal);
2166 return parseDirectiveExitMacro(IDVal);
2169 return parseDirectiveEndMacro(IDVal);
2171 return parseDirectivePurgeMacro(IDLoc);
2173 return parseDirectiveEnd(IDLoc);
2175 return parseDirectiveError(IDLoc,
false);
2177 return parseDirectiveError(IDLoc,
true);
2179 return parseDirectiveWarning(IDLoc);
2181 return parseDirectiveReloc(IDLoc);
2184 return parseDirectiveDCB(IDVal, 2);
2186 return parseDirectiveDCB(IDVal, 1);
2188 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2190 return parseDirectiveDCB(IDVal, 4);
2192 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2195 return TokError(Twine(IDVal) +
2196 " not currently supported for this target");
2199 return parseDirectiveDS(IDVal, 2);
2201 return parseDirectiveDS(IDVal, 1);
2203 return parseDirectiveDS(IDVal, 8);
2206 return parseDirectiveDS(IDVal, 4);
2209 return parseDirectiveDS(IDVal, 12);
2211 return parseDirectivePrint(IDLoc);
2213 return parseDirectiveAddrsig();
2214 case DK_ADDRSIG_SYM:
2215 return parseDirectiveAddrsigSym();
2216 case DK_PSEUDO_PROBE:
2217 return parseDirectivePseudoProbe();
2218 case DK_LTO_DISCARD:
2219 return parseDirectiveLTODiscard();
2221 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2224 return Error(IDLoc,
"unknown directive");
2228 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2229 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2230 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2233 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2234 return parseDirectiveMSAlign(IDLoc, Info);
2236 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2238 if (checkForValidSection())
2241 return parseAndMatchAndEmitTargetInstruction(Info, IDVal,
ID, IDLoc);
2244bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2249 std::string OpcodeStr = IDVal.
lower();
2250 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2251 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr,
ID,
2252 Info.ParsedOperands);
2253 Info.ParseError = ParseHadError;
2256 if (getShowParsedOperands()) {
2257 SmallString<256> Str;
2258 raw_svector_ostream OS(Str);
2259 OS <<
"parsed instruction: [";
2260 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2263 Info.ParsedOperands[i]->print(OS, MAI);
2271 if (hasPendingError() || ParseHadError)
2276 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2278 getStreamer().getCurrentSectionOnly())) {
2280 if (ActiveMacros.empty())
2284 ActiveMacros.front()->ExitBuffer);
2289 if (!CppHashInfo.Filename.empty()) {
2290 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2291 0, StringRef(), CppHashInfo.Filename);
2292 getContext().setGenDwarfFileNumber(FileNumber);
2294 unsigned CppHashLocLineNo =
2296 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2299 getStreamer().emitDwarfLocDirective(
2300 getContext().getGenDwarfFileNumber(), Line, 0,
2306 if (!ParseHadError) {
2308 if (getTargetParser().matchAndEmitInstruction(
2309 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2310 getTargetParser().isParsingMSInlineAsm()))
2318AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2323 SMLoc StartLoc = Lexer.
getLoc();
2336bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2341 "Lexing Cpp line comment: Expected Integer");
2342 int64_t LineNumber = getTok().getIntVal();
2345 "Lexing Cpp line comment: Expected String");
2346 StringRef
Filename = getTok().getString();
2357 CppHashInfo.Loc =
L;
2359 CppHashInfo.LineNumber = LineNumber;
2360 CppHashInfo.Buf = CurBuffer;
2361 if (!HadCppHashFilename) {
2362 HadCppHashFilename =
true;
2372 std::nullopt, std::nullopt);
2380void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2381 auto *Parser =
static_cast<AsmParser *
>(
Context);
2382 raw_ostream &OS =
errs();
2385 SMLoc DiagLoc = Diag.
getLoc();
2387 unsigned CppHashBuf =
2388 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2393 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2402 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2403 if (Parser->SavedDiagHandler)
2404 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2406 Parser->getContext().diagnose(Diag);
2413 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2416 int CppHashLocLineNo =
2417 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2419 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2425 if (Parser->SavedDiagHandler)
2426 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2428 Parser->getContext().diagnose(NewDiag);
2436 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2440bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2443 bool EnableAtPseudoVariable) {
2445 auto expandArg = [&](
unsigned Index) {
2446 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2447 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2448 for (
const AsmToken &Token :
A[Index])
2456 if (AltMacroMode && Token.getString().front() ==
'%' &&
2459 OS << Token.getIntVal();
2462 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2469 OS << Token.getString();
2471 OS << Token.getStringContents();
2476 StringRef Body =
Macro.Body;
2477 size_t I = 0, End = Body.
size();
2479 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2481 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2482 OS << NumOfMacroInstantiations;
2486 if (Body[
I + 1] ==
'+') {
2491 if (Body[
I + 1] ==
'(' && Body[
I + 2] ==
')') {
2500 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2504 if (Parameters[Index].Name == Argument)
2506 if (Index == NParameters)
2515 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2517 switch (Body[
I + 1]) {
2533 unsigned Index = Body[
I + 1] -
'0';
2534 if (Index <
A.size())
2535 for (
const AsmToken &Token :
A[Index])
2536 OS << Token.getString();
2551 StringRef Token(Body.
data() + Start,
I - Start);
2555 if (Parameters[Index].Name == Token)
2557 if (Index != NParameters) {
2559 if (
I != End && Body[
I] ==
'&')
2603class AsmLexerSkipSpaceRAII {
2605 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2609 ~AsmLexerSkipSpaceRAII() {
2619bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2623 StringRef Str = parseStringToEndOfStatement();
2629 unsigned ParenLevel = 0;
2632 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2639 return TokError(
"unexpected token in macro instantiation");
2641 if (ParenLevel == 0) {
2654 MA.push_back(getTok());
2678 MA.push_back(getTok());
2682 if (ParenLevel != 0)
2683 return TokError(
"unbalanced parentheses in macro argument");
2688bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2689 MCAsmMacroArguments &
A) {
2690 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2691 bool NamedParametersFound =
false;
2692 SmallVector<SMLoc, 4> FALocs;
2694 A.resize(NParameters);
2695 FALocs.
resize(NParameters);
2700 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2701 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2703 SMLoc IDLoc = Lexer.
getLoc();
2704 MCAsmMacroParameter FA;
2707 if (parseIdentifier(FA.
Name))
2708 return Error(IDLoc,
"invalid argument identifier for formal argument");
2711 return TokError(
"expected '=' after formal parameter identifier");
2715 NamedParametersFound =
true;
2717 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2719 if (NamedParametersFound && FA.
Name.
empty())
2720 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2722 SMLoc StrLoc = Lexer.
getLoc();
2725 const MCExpr *AbsoluteExp;
2729 if (parseExpression(AbsoluteExp, EndLoc))
2731 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2732 getStreamer().getAssemblerPtr()))
2733 return Error(StrLoc,
"expected absolute expression");
2737 StringRef(StrChar, EndChar - StrChar),
Value);
2738 FA.
Value.push_back(newToken);
2743 jumpToLoc(EndLoc, CurBuffer);
2747 StringRef(StrChar, EndChar - StrChar));
2748 FA.
Value.push_back(newToken);
2749 }
else if(parseMacroArgument(FA.
Value, Vararg))
2755 for (FAI = 0; FAI < NParameters; ++FAI)
2756 if (
M->Parameters[FAI].Name == FA.
Name)
2759 if (FAI >= NParameters) {
2760 assert(M &&
"expected macro to be defined");
2761 return Error(IDLoc,
"parameter named '" + FA.
Name +
2762 "' does not exist for macro '" +
M->Name +
"'");
2767 if (!FA.
Value.empty()) {
2772 if (FALocs.
size() <= PI)
2775 FALocs[PI] = Lexer.
getLoc();
2783 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2785 if (
M->Parameters[FAI].Required) {
2787 "missing value for required parameter "
2788 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2792 if (!
M->Parameters[FAI].Value.empty())
2793 A[FAI] =
M->Parameters[FAI].Value;
2802 return TokError(
"too many positional arguments");
2805bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2809 if (ActiveMacros.size() == MaxNestingDepth) {
2810 std::ostringstream MaxNestingDepthError;
2811 MaxNestingDepthError <<
"macros cannot be nested more than "
2812 << MaxNestingDepth <<
" levels deep."
2813 <<
" Use -asm-macro-max-nesting-depth to increase "
2815 return TokError(MaxNestingDepthError.str());
2818 MCAsmMacroArguments
A;
2819 if (parseMacroArguments(M,
A))
2824 SmallString<256> Buf;
2825 raw_svector_ostream OS(Buf);
2827 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2828 return Error(getTok().getLoc(),
"Wrong number of arguments");
2829 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2834 OS <<
".endmacro\n";
2836 std::unique_ptr<MemoryBuffer> Instantiation =
2841 MacroInstantiation *
MI =
new MacroInstantiation{
2842 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2843 ActiveMacros.push_back(
MI);
2845 ++NumOfMacroInstantiations;
2855void AsmParser::handleMacroExit() {
2857 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2865 delete ActiveMacros.back();
2866 ActiveMacros.pop_back();
2869bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2871 const MCExpr *
Value;
2872 SMLoc ExprLoc = getTok().getLoc();
2874 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2886 if (discardLTOSymbol(Name))
2891 case AssignmentKind::Equal:
2894 case AssignmentKind::Set:
2895 case AssignmentKind::Equiv:
2899 case AssignmentKind::LTOSetConditional:
2901 return Error(ExprLoc,
"expected identifier");
2913bool AsmParser::parseIdentifier(StringRef &Res) {
2920 SMLoc PrefixLoc = getLexer().getLoc();
2932 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2938 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2946 Res = getTok().getIdentifier();
2958bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2960 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2961 parseAssignment(Name, Kind))
2966bool AsmParser::parseEscapedString(std::string &
Data) {
2971 StringRef Str = getTok().getStringContents();
2972 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
2973 if (Str[i] !=
'\\') {
2974 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
2976 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
2980 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
2991 return TokError(
"unexpected backslash at end of string");
2994 if (Str[i] ==
'x' || Str[i] ==
'X') {
2995 size_t length = Str.size();
2996 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
2997 return TokError(
"invalid hexadecimal escape sequence");
3002 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3010 if ((
unsigned)(Str[i] -
'0') <= 7) {
3012 unsigned Value = Str[i] -
'0';
3014 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3018 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3025 return TokError(
"invalid octal escape sequence (out of range)");
3035 return TokError(
"invalid escape sequence (unrecognized character)");
3037 case 'b':
Data +=
'\b';
break;
3038 case 'f':
Data +=
'\f';
break;
3039 case 'n':
Data +=
'\n';
break;
3040 case 'r':
Data +=
'\r';
break;
3041 case 't':
Data +=
'\t';
break;
3042 case '"':
Data +=
'"';
break;
3043 case '\\':
Data +=
'\\';
break;
3051bool AsmParser::parseAngleBracketString(std::string &
Data) {
3052 SMLoc EndLoc, StartLoc = getTok().getLoc();
3054 const char *StartChar = StartLoc.
getPointer() + 1;
3055 const char *EndChar = EndLoc.
getPointer() - 1;
3056 jumpToLoc(EndLoc, CurBuffer);
3069bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3070 auto parseOp = [&]() ->
bool {
3072 if (checkForValidSection())
3077 if (parseEscapedString(
Data))
3079 getStreamer().emitBytes(
Data);
3082 getStreamer().emitBytes(StringRef(
"\0", 1));
3086 return parseMany(parseOp);
3091bool AsmParser::parseDirectiveBase64() {
3092 auto parseOp = [&]() ->
bool {
3093 if (checkForValidSection())
3100 std::vector<char> Decoded;
3101 std::string
const str = getTok().getStringContents().str();
3102 if (check(str.empty(),
"expected nonempty string")) {
3109 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3112 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3117 return check(parseMany(parseOp),
"expected string");
3122bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3124 const MCExpr *Expr =
nullptr;
3126 if (parseExpression(
Offset))
3138 SMLoc ExprLoc = Lexer.
getLoc();
3139 if (parseExpression(Expr))
3144 return Error(ExprLoc,
"expression must be relocatable");
3150 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3156bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3157 auto parseOp = [&]() ->
bool {
3158 const MCExpr *
Value;
3159 SMLoc ExprLoc = getLexer().getLoc();
3160 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3165 uint64_t IntValue = MCE->getValue();
3167 return Error(ExprLoc,
"out of range literal value");
3168 getStreamer().emitIntValue(IntValue,
Size);
3170 getStreamer().emitValue(
Value,
Size, ExprLoc);
3174 return parseMany(parseOp);
3180 return Asm.TokError(
"unknown token in expression");
3181 SMLoc ExprLoc = Asm.getTok().getLoc();
3182 APInt IntValue = Asm.getTok().getAPIntVal();
3184 if (!IntValue.
isIntN(128))
3185 return Asm.Error(ExprLoc,
"out of range literal value");
3186 if (!IntValue.
isIntN(64)) {
3199bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3200 auto parseOp = [&]() ->
bool {
3201 if (checkForValidSection())
3207 getStreamer().emitInt64(lo);
3208 getStreamer().emitInt64(hi);
3210 getStreamer().emitInt64(hi);
3211 getStreamer().emitInt64(lo);
3216 return parseMany(parseOp);
3219bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3230 return TokError(Lexer.
getErr());
3233 return TokError(
"unexpected token in directive");
3237 StringRef IDVal = getTok().getString();
3245 return TokError(
"invalid floating point literal");
3247 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3249 return TokError(
"invalid floating point literal");
3256 Res =
Value.bitcastToAPInt();
3263bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3264 const fltSemantics &Semantics) {
3265 auto parseOp = [&]() ->
bool {
3267 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3274 return parseMany(parseOp);
3279bool AsmParser::parseDirectiveZero() {
3280 SMLoc NumBytesLoc = Lexer.
getLoc();
3281 const MCExpr *NumBytes;
3282 if (checkForValidSection() || parseExpression(NumBytes))
3288 if (parseAbsoluteExpression(Val))
3294 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3301bool AsmParser::parseDirectiveFill() {
3302 SMLoc NumValuesLoc = Lexer.
getLoc();
3303 const MCExpr *NumValues;
3304 if (checkForValidSection() || parseExpression(NumValues))
3307 int64_t FillSize = 1;
3308 int64_t FillExpr = 0;
3310 SMLoc SizeLoc, ExprLoc;
3313 SizeLoc = getTok().getLoc();
3314 if (parseAbsoluteExpression(FillSize))
3317 ExprLoc = getTok().getLoc();
3318 if (parseAbsoluteExpression(FillExpr))
3326 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3330 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3335 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3337 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3344bool AsmParser::parseDirectiveOrg() {
3346 SMLoc OffsetLoc = Lexer.
getLoc();
3347 if (checkForValidSection() || parseExpression(
Offset))
3351 int64_t FillExpr = 0;
3353 if (parseAbsoluteExpression(FillExpr))
3358 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3364bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3365 SMLoc AlignmentLoc = getLexer().getLoc();
3368 bool HasFillExpr =
false;
3369 int64_t FillExpr = 0;
3370 int64_t MaxBytesToFill = 0;
3373 auto parseAlign = [&]() ->
bool {
3374 if (parseAbsoluteExpression(Alignment))
3382 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3386 if (parseTokenLoc(MaxBytesLoc) ||
3387 parseAbsoluteExpression(MaxBytesToFill))
3393 if (checkForValidSection())
3397 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3404 bool ReturnVal =
false;
3409 if (Alignment >= 32) {
3410 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3414 Alignment = 1ULL << Alignment;
3422 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3426 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3427 Alignment = 1u << 31;
3433 if (MaxBytesToFill < 1) {
3434 ReturnVal |=
Error(MaxBytesLoc,
3435 "alignment directive can never be satisfied in this "
3436 "many bytes, ignoring maximum bytes expression");
3440 if (MaxBytesToFill >= Alignment) {
3441 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3447 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3448 assert(Section &&
"must have section to emit alignment");
3450 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3452 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3460 getStreamer().emitCodeAlignment(
3461 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3464 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3471bool AsmParser::parseDirectivePrefAlign() {
3472 SMLoc AlignmentLoc = getLexer().getLoc();
3474 if (checkForValidSection() || parseAbsoluteExpression(Log2Alignment))
3477 if (Log2Alignment < 0 || Log2Alignment > 63)
3478 return Error(AlignmentLoc,
"log2 alignment must be in the range [0, 63]");
3481 SMLoc SymLoc = getLexer().getLoc();
3485 SymLoc = getLexer().getLoc();
3486 if (parseIdentifier(Name))
3487 return Error(SymLoc,
"expected symbol name");
3491 SMLoc FillLoc = getLexer().getLoc();
3495 bool EmitNops =
false;
3497 SMLoc FillLoc2 = getLexer().getLoc();
3499 getLexer().getTok().getIdentifier() ==
"nop") {
3504 if (parseAbsoluteExpression(FillVal))
3506 if (FillVal < 0 || FillVal > 255)
3507 return Error(FillLoc2,
"fill value must be in range [0, 255]");
3508 Fill =
static_cast<uint8_t
>(FillVal);
3513 if ((EmitNops || Fill != 0) &&
3514 getStreamer().getCurrentSectionOnly()->isBssSection())
3515 return Error(FillLoc,
"non-zero fill in BSS section '" +
3516 getStreamer().getCurrentSectionOnly()->
getName() +
3519 getStreamer().emitPrefAlign(
Align(1ULL << Log2Alignment), *End, EmitNops,
3520 Fill, getTargetParser().getSTI());
3527bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3529 int64_t FileNumber = -1;
3531 FileNumber = getTok().getIntVal();
3535 return TokError(
"negative file number");
3542 if (parseEscapedString(Path))
3545 StringRef Directory;
3547 std::string FilenameData;
3549 if (check(FileNumber == -1,
3550 "explicit path specified, but no file number") ||
3551 parseEscapedString(FilenameData))
3559 uint64_t MD5Hi, MD5Lo;
3560 bool HasMD5 =
false;
3562 std::optional<StringRef>
Source;
3563 bool HasSource =
false;
3564 std::string SourceString;
3569 "unexpected token in '.file' directive") ||
3570 parseIdentifier(Keyword))
3572 if (Keyword ==
"md5") {
3574 if (check(FileNumber == -1,
3575 "MD5 checksum specified, but no file number") ||
3578 }
else if (Keyword ==
"source") {
3580 if (check(FileNumber == -1,
3581 "source specified, but no file number") ||
3583 "unexpected token in '.file' directive") ||
3584 parseEscapedString(SourceString))
3587 return TokError(
"unexpected token in '.file' directive");
3591 if (FileNumber == -1) {
3595 if (
getContext().getAsmInfo()->hasSingleParameterDotFile())
3596 getStreamer().emitFileDirective(
Filename);
3606 std::optional<MD5::MD5Result> CKMem;
3609 for (
unsigned i = 0; i != 8; ++i) {
3610 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3611 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3616 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3617 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3618 Source = StringRef(SourceBuf, SourceString.size());
3620 if (FileNumber == 0) {
3624 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3626 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3627 FileNumber, Directory,
Filename, CKMem, Source);
3634 ReportedInconsistentMD5 =
true;
3635 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3644bool AsmParser::parseDirectiveLine() {
3656bool AsmParser::parseDirectiveLoc() {
3657 int64_t FileNumber = 0, LineNumber = 0;
3658 SMLoc Loc = getTok().getLoc();
3659 if (parseIntToken(FileNumber) ||
3661 "file number less than one in '.loc' directive") ||
3662 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3663 "unassigned file number in '.loc' directive"))
3668 LineNumber = getTok().getIntVal();
3670 return TokError(
"line number less than zero in '.loc' directive");
3674 int64_t ColumnPos = 0;
3676 ColumnPos = getTok().getIntVal();
3678 return TokError(
"column position less than zero in '.loc' directive");
3682 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3687 auto parseLocOp = [&]() ->
bool {
3689 SMLoc Loc = getTok().getLoc();
3690 if (parseIdentifier(Name))
3691 return TokError(
"unexpected token in '.loc' directive");
3693 if (Name ==
"basic_block")
3695 else if (Name ==
"prologue_end")
3697 else if (Name ==
"epilogue_begin")
3699 else if (Name ==
"is_stmt") {
3700 Loc = getTok().getLoc();
3701 const MCExpr *
Value;
3702 if (parseExpression(
Value))
3706 int Value = MCE->getValue();
3708 Flags &= ~DWARF2_FLAG_IS_STMT;
3709 else if (
Value == 1)
3712 return Error(Loc,
"is_stmt value not 0 or 1");
3714 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3716 }
else if (Name ==
"isa") {
3717 Loc = getTok().getLoc();
3718 const MCExpr *
Value;
3719 if (parseExpression(
Value))
3723 int Value = MCE->getValue();
3725 return Error(Loc,
"isa number less than zero");
3728 return Error(Loc,
"isa number not a constant value");
3730 }
else if (Name ==
"discriminator") {
3731 if (parseAbsoluteExpression(Discriminator))
3734 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3739 if (parseMany(parseLocOp,
false ))
3742 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3743 Isa, Discriminator, StringRef());
3750bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3752 DirectiveLoc = Lexer.
getLoc();
3753 if (parseIdentifier(Name))
3754 return TokError(
"expected identifier");
3757 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3763bool AsmParser::parseDirectiveStabs() {
3764 return TokError(
"unsupported directive '.stabs'");
3769bool AsmParser::parseDirectiveCVFile() {
3770 SMLoc FileNumberLoc = getTok().getLoc();
3773 std::string Checksum;
3776 if (parseIntToken(FileNumber,
"expected file number") ||
3777 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3779 "unexpected token in '.cv_file' directive") ||
3784 "unexpected token in '.cv_file' directive") ||
3785 parseEscapedString(Checksum) ||
3786 parseIntToken(ChecksumKind,
3787 "expected checksum kind in '.cv_file' directive") ||
3793 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3794 memcpy(CKMem, Checksum.data(), Checksum.size());
3795 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3798 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3799 static_cast<uint8_t
>(ChecksumKind)))
3800 return Error(FileNumberLoc,
"file number already allocated");
3805bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3806 StringRef DirectiveName) {
3808 return parseTokenLoc(Loc) ||
3809 parseIntToken(FunctionId,
"expected function id") ||
3810 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3811 "expected function id within range [0, UINT_MAX)");
3814bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3816 return parseTokenLoc(Loc) ||
3817 parseIntToken(FileNumber,
"expected file number") ||
3818 check(FileNumber < 1, Loc,
3819 "file number less than one in '" + DirectiveName +
3821 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3822 "unassigned file number in '" + DirectiveName +
"' directive");
3829bool AsmParser::parseDirectiveCVFuncId() {
3830 SMLoc FunctionIdLoc = getTok().getLoc();
3833 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3836 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3837 return Error(FunctionIdLoc,
"function id already allocated");
3850bool AsmParser::parseDirectiveCVInlineSiteId() {
3851 SMLoc FunctionIdLoc = getTok().getLoc();
3859 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3864 getTok().getIdentifier() !=
"within"),
3865 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3870 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3875 getTok().getIdentifier() !=
"inlined_at"),
3876 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3882 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3883 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3888 IACol = getTok().getIntVal();
3895 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3896 IALine, IACol, FunctionIdLoc))
3897 return Error(FunctionIdLoc,
"function id already allocated");
3909bool AsmParser::parseDirectiveCVLoc() {
3910 SMLoc DirectiveLoc = getTok().getLoc();
3911 int64_t FunctionId, FileNumber;
3912 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3913 parseCVFileId(FileNumber,
".cv_loc"))
3916 int64_t LineNumber = 0;
3918 LineNumber = getTok().getIntVal();
3920 return TokError(
"line number less than zero in '.cv_loc' directive");
3924 int64_t ColumnPos = 0;
3926 ColumnPos = getTok().getIntVal();
3928 return TokError(
"column position less than zero in '.cv_loc' directive");
3932 bool PrologueEnd =
false;
3933 uint64_t IsStmt = 0;
3935 auto parseOp = [&]() ->
bool {
3937 SMLoc Loc = getTok().getLoc();
3938 if (parseIdentifier(Name))
3939 return TokError(
"unexpected token in '.cv_loc' directive");
3940 if (Name ==
"prologue_end")
3942 else if (Name ==
"is_stmt") {
3943 Loc = getTok().getLoc();
3944 const MCExpr *
Value;
3945 if (parseExpression(
Value))
3950 IsStmt = MCE->getValue();
3953 return Error(Loc,
"is_stmt value not 0 or 1");
3955 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3960 if (parseMany(parseOp,
false ))
3963 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3964 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3971bool AsmParser::parseDirectiveCVLinetable() {
3974 SMLoc Loc = getTok().getLoc();
3975 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3976 parseTokenLoc(Loc) ||
3977 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
3978 parseComma() || parseTokenLoc(Loc) ||
3979 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
3982 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3988bool AsmParser::parseDirectiveCVInlineLinetable() {
3989 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3991 SMLoc Loc = getTok().getLoc();
3992 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3993 parseTokenLoc(Loc) ||
3994 parseIntToken(SourceFileId,
"expected SourceField") ||
3995 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
3996 parseTokenLoc(Loc) ||
3997 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
3998 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
3999 parseTokenLoc(Loc) ||
4000 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
4001 parseTokenLoc(Loc) ||
4002 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
4008 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
4009 SourceLineNum, FnStartSym,
4014void AsmParser::initializeCVDefRangeTypeMap() {
4015 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
4016 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
4017 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4018 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4019 CVDefRangeTypeMap[
"reg_rel_indir"] = CVDR_DEFRANGE_REGISTER_REL_INDIR;
4024bool AsmParser::parseDirectiveCVDefRange() {
4026 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
4028 Loc = getLexer().getLoc();
4031 return Error(Loc,
"expected identifier in directive");
4033 Loc = getLexer().getLoc();
4036 return Error(Loc,
"expected identifier in directive");
4038 Ranges.push_back({GapStartSym, GapEndSym});
4041 StringRef CVDefRangeTypeStr;
4044 "expected comma before def_range type in .cv_def_range directive") ||
4045 parseIdentifier(CVDefRangeTypeStr))
4046 return Error(Loc,
"expected def_range type in directive");
4049 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4050 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4052 : CVTypeIt->getValue();
4054 case CVDR_DEFRANGE_REGISTER: {
4056 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4057 ".cv_def_range directive") ||
4058 parseAbsoluteExpression(DRRegister))
4059 return Error(Loc,
"expected register number");
4061 codeview::DefRangeRegisterHeader DRHdr;
4064 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4067 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4070 "expected comma before offset in .cv_def_range directive") ||
4071 parseAbsoluteExpression(DROffset))
4072 return Error(Loc,
"expected offset value");
4074 codeview::DefRangeFramePointerRelHeader DRHdr;
4076 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4079 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4081 int64_t DROffsetInParent;
4082 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4083 ".cv_def_range directive") ||
4084 parseAbsoluteExpression(DRRegister))
4085 return Error(Loc,
"expected register number");
4087 "expected comma before offset in .cv_def_range directive") ||
4088 parseAbsoluteExpression(DROffsetInParent))
4089 return Error(Loc,
"expected offset value");
4091 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4095 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4098 case CVDR_DEFRANGE_REGISTER_REL: {
4101 int64_t DRBasePointerOffset;
4102 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4103 ".cv_def_range directive") ||
4104 parseAbsoluteExpression(DRRegister))
4105 return Error(Loc,
"expected register value");
4108 "expected comma before flag value in .cv_def_range directive") ||
4109 parseAbsoluteExpression(DRFlags))
4110 return Error(Loc,
"expected flag value");
4111 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4112 "in .cv_def_range directive") ||
4113 parseAbsoluteExpression(DRBasePointerOffset))
4114 return Error(Loc,
"expected base pointer offset value");
4116 codeview::DefRangeRegisterRelHeader DRHdr;
4118 DRHdr.
Flags = DRFlags;
4120 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4123 case CVDR_DEFRANGE_REGISTER_REL_INDIR: {
4126 int64_t DRBasePointerOffset;
4127 int64_t DROffsetInUdt;
4128 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4129 ".cv_def_range directive") ||
4130 parseAbsoluteExpression(DRRegister))
4131 return Error(Loc,
"expected register value");
4134 "expected comma before flag value in .cv_def_range directive") ||
4135 parseAbsoluteExpression(DRFlags))
4136 return Error(Loc,
"expected flag value");
4137 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4138 "in .cv_def_range directive") ||
4139 parseAbsoluteExpression(DRBasePointerOffset))
4140 return Error(Loc,
"expected base pointer offset value");
4141 if (parseToken(
AsmToken::Comma,
"expected comma before offset in UDT "
4142 "in .cv_def_range directive") ||
4143 parseAbsoluteExpression(DROffsetInUdt))
4144 return Error(Loc,
"expected offset in UDT value");
4146 codeview::DefRangeRegisterRelIndirHeader DRHdr;
4148 DRHdr.
Flags = DRFlags;
4151 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4155 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4162bool AsmParser::parseDirectiveCVString() {
4164 if (checkForValidSection() || parseEscapedString(
Data))
4168 std::pair<StringRef, unsigned> Insertion =
4169 getCVContext().addToStringTable(
Data);
4170 getStreamer().emitInt32(Insertion.second);
4176bool AsmParser::parseDirectiveCVStringTable() {
4177 getStreamer().emitCVStringTableDirective();
4183bool AsmParser::parseDirectiveCVFileChecksums() {
4184 getStreamer().emitCVFileChecksumsDirective();
4190bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4192 if (parseIntToken(FileNo))
4196 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4202bool AsmParser::parseDirectiveCVFPOData() {
4203 SMLoc DirLoc = getLexer().getLoc();
4206 return TokError(
"expected symbol name");
4209 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4215bool AsmParser::parseDirectiveCFISections() {
4219 bool SFrame =
false;
4223 if (parseIdentifier(Name))
4224 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4225 if (Name ==
".eh_frame")
4227 else if (Name ==
".debug_frame")
4229 else if (Name ==
".sframe")
4237 getStreamer().emitCFISections(EH,
Debug, SFrame);
4243bool AsmParser::parseDirectiveCFIStartProc() {
4244 CFIStartProcLoc = StartTokLoc;
4248 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4249 "unexpected token") ||
4259 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4265bool AsmParser::parseDirectiveCFIEndProc() {
4266 CFIStartProcLoc = std::nullopt;
4271 getStreamer().emitCFIEndProc();
4276bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4277 SMLoc DirectiveLoc) {
4281 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4285 return parseAbsoluteExpression(
Register);
4292bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4294 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4295 parseAbsoluteExpression(
Offset) || parseEOL())
4304bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4306 if (parseAbsoluteExpression(
Offset) || parseEOL())
4309 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4315bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4316 int64_t Register1 = 0, Register2 = 0;
4317 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4318 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4321 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4327bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4330 getStreamer().emitCFIWindowSave(DirectiveLoc);
4336bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4337 int64_t Adjustment = 0;
4338 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4341 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4347bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4349 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4352 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4358bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4360 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4361 parseAbsoluteExpression(
Offset) || parseComma() ||
4372bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4376 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4377 parseAbsoluteExpression(
Offset) || parseEOL())
4386bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4389 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4390 parseAbsoluteExpression(
Offset) || parseEOL())
4398 if (Encoding & ~0xff)
4404 const unsigned Format = Encoding & 0xf;
4411 const unsigned Application = Encoding & 0x70;
4423bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4424 int64_t Encoding = 0;
4425 if (parseAbsoluteExpression(Encoding))
4433 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4437 getStreamer().emitCFIPersonality(Sym, Encoding);
4439 getStreamer().emitCFILsda(Sym, Encoding);
4445bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4448 getStreamer().emitCFIRememberState(DirectiveLoc);
4454bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4457 getStreamer().emitCFIRestoreState(DirectiveLoc);
4463bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4466 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4469 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4475bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4477 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4480 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4486bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4489 if (parseAbsoluteExpression(CurrValue))
4492 Values.push_back((uint8_t)CurrValue);
4497 if (parseAbsoluteExpression(CurrValue))
4500 Values.push_back((uint8_t)CurrValue);
4503 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4509bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4511 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4513 getStreamer().emitCFIReturnColumn(
Register);
4519bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4523 getStreamer().emitCFISignalFrame();
4529bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4532 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4535 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4541bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4544 if (parseIdentifier(Name))
4545 return TokError(
"expected identifier");
4548 getStreamer().emitCFILabelDirective(Loc, Name);
4554bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4558 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4559 parseAbsoluteExpression(
Offset) || parseEOL())
4569bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4572 AltMacroMode = (Directive ==
".altmacro");
4579bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4582 setMacrosEnabled(Directive ==
".macros_on");
4588bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4590 if (parseIdentifier(Name))
4591 return TokError(
"expected identifier in '.macro' directive");
4600 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4602 "' should be the last parameter");
4606 return TokError(
"expected identifier in '.macro' directive");
4609 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4611 return TokError(
"macro '" + Name +
"' has multiple parameters"
4620 QualLoc = Lexer.
getLoc();
4621 if (parseIdentifier(Qualifier))
4622 return Error(QualLoc,
"missing parameter qualifier for "
4623 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4625 if (Qualifier ==
"req")
4627 else if (Qualifier ==
"vararg")
4630 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4631 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4639 ParamLoc = Lexer.
getLoc();
4640 if (parseMacroArgument(
Parameter.Value,
false ))
4644 Warning(ParamLoc,
"pointless default value for required parameter "
4645 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4658 AsmToken EndToken, StartToken = getTok();
4659 unsigned MacroDepth = 0;
4669 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4674 if (getTok().getIdentifier() ==
".endm" ||
4675 getTok().getIdentifier() ==
".endmacro") {
4676 if (MacroDepth == 0) {
4677 EndToken = getTok();
4680 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4687 }
else if (getTok().getIdentifier() ==
".macro") {
4693 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4697 eatToEndOfStatement();
4701 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4706 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4707 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4708 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4729void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4735 if (NParameters == 0)
4738 bool NamedParametersFound =
false;
4739 bool PositionalParametersFound =
false;
4744 while (!Body.
empty()) {
4746 std::size_t End = Body.
size(), Pos = 0;
4747 for (; Pos != End; ++Pos) {
4750 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4754 if (Body[Pos] !=
'$' || Pos + 1 == End)
4756 char Next = Body[Pos + 1];
4758 isdigit(
static_cast<unsigned char>(
Next)))
4766 if (Body[Pos] ==
'$') {
4767 switch (Body[Pos + 1]) {
4774 PositionalParametersFound =
true;
4779 PositionalParametersFound =
true;
4785 unsigned I = Pos + 1;
4789 const char *Begin = Body.
data() + Pos + 1;
4790 StringRef
Argument(Begin,
I - (Pos + 1));
4793 if (Parameters[Index].Name == Argument)
4796 if (Index == NParameters) {
4797 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4803 NamedParametersFound =
true;
4811 if (!NamedParametersFound && PositionalParametersFound)
4812 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4813 "used in macro body, possible positional parameter "
4814 "found in body which will have no effect");
4819bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4823 if (!isInsideMacroInstantiation())
4824 return TokError(
"unexpected '" + Directive +
"' in file, "
4825 "no current macro definition");
4828 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4829 TheCondState = TheCondStack.back();
4830 TheCondStack.pop_back();
4840bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4842 return TokError(
"unexpected token in '" + Directive +
"' directive");
4846 if (isInsideMacroInstantiation()) {
4853 return TokError(
"unexpected '" + Directive +
"' in file, "
4854 "no current macro definition");
4859bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4862 if (parseTokenLoc(Loc) ||
4863 check(parseIdentifier(Name), Loc,
4864 "expected identifier in '.purgem' directive") ||
4869 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4873 <<
"Un-defining macro: " << Name <<
"\n");
4879bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4880 SMLoc NumBytesLoc = Lexer.
getLoc();
4881 const MCExpr *NumBytes;
4882 if (checkForValidSection() || parseExpression(NumBytes))
4885 int64_t FillExpr = 0;
4887 if (parseAbsoluteExpression(FillExpr))
4893 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4900bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
4901 SMLoc NumValuesLoc = Lexer.
getLoc();
4903 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4906 if (NumValues < 0) {
4907 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4914 const MCExpr *
Value;
4915 SMLoc ExprLoc = getLexer().getLoc();
4916 if (parseExpression(
Value))
4922 uint64_t IntValue = MCE->getValue();
4924 return Error(ExprLoc,
"literal value out of range for directive");
4925 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4926 getStreamer().emitIntValue(IntValue,
Size);
4928 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4929 getStreamer().emitValue(
Value,
Size, ExprLoc);
4937bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
4938 SMLoc NumValuesLoc = Lexer.
getLoc();
4940 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4943 if (NumValues < 0) {
4944 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4952 if (parseRealValue(Semantics, AsInt) || parseEOL())
4955 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4964bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
4965 SMLoc NumValuesLoc = Lexer.
getLoc();
4967 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4971 if (NumValues < 0) {
4972 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4976 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4977 getStreamer().emitFill(
Size, 0);
4984bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4985 if (checkForValidSection())
4988 auto parseOp = [&]() ->
bool {
4989 const MCExpr *
Value;
4990 if (parseExpression(
Value))
4993 getStreamer().emitSLEB128Value(
Value);
4995 getStreamer().emitULEB128Value(
Value);
4999 return parseMany(parseOp);
5004bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
5005 auto parseOp = [&]() ->
bool {
5007 SMLoc Loc = getTok().getLoc();
5008 if (parseIdentifier(Name))
5009 return Error(Loc,
"expected identifier");
5011 if (discardLTOSymbol(Name))
5019 return Error(Loc,
"non-local symbol required");
5021 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
5022 return Error(Loc,
"unable to emit symbol attribute");
5026 return parseMany(parseOp);
5031bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5032 if (checkForValidSection())
5035 SMLoc IDLoc = getLexer().getLoc();
5038 return TokError(
"expected identifier in directive");
5044 SMLoc SizeLoc = getLexer().getLoc();
5045 if (parseAbsoluteExpression(
Size))
5048 int64_t Pow2Alignment = 0;
5049 SMLoc Pow2AlignmentLoc;
5052 Pow2AlignmentLoc = getLexer().getLoc();
5053 if (parseAbsoluteExpression(Pow2Alignment))
5058 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5064 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5065 Pow2Alignment =
Log2_64(Pow2Alignment);
5075 return Error(SizeLoc,
"size must be non-negative");
5079 return Error(IDLoc,
"invalid symbol redefinition");
5083 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5084 Align(1ULL << Pow2Alignment));
5088 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
5094bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5095 StringRef Str = parseStringToEndOfStatement();
5100 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5103 return Error(DirectiveLoc,
5104 ".abort '" + Str +
"' detected. Assembly stopping");
5109bool AsmParser::parseDirectiveInclude() {
5112 SMLoc IncludeLoc = getTok().getLoc();
5115 "expected string in '.include' directive") ||
5118 "unexpected token in '.include' directive") ||
5121 check(enterIncludeFile(
Filename), IncludeLoc,
5122 "Could not find include file '" +
Filename +
"'"))
5130bool AsmParser::parseDirectiveIncbin() {
5133 SMLoc IncbinLoc = getTok().getLoc();
5135 "expected string in '.incbin' directive") ||
5140 const MCExpr *
Count =
nullptr;
5141 SMLoc SkipLoc, CountLoc;
5146 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5150 CountLoc = getTok().getLoc();
5151 if (parseExpression(
Count))
5159 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5164 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5170bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5171 TheCondStack.push_back(TheCondState);
5173 if (TheCondState.
Ignore) {
5174 eatToEndOfStatement();
5177 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5187 ExprValue = ExprValue == 0;
5190 ExprValue = ExprValue >= 0;
5193 ExprValue = ExprValue > 0;
5196 ExprValue = ExprValue <= 0;
5199 ExprValue = ExprValue < 0;
5203 TheCondState.
CondMet = ExprValue;
5212bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5213 TheCondStack.push_back(TheCondState);
5216 if (TheCondState.
Ignore) {
5217 eatToEndOfStatement();
5219 StringRef Str = parseStringToEndOfStatement();
5224 TheCondState.
CondMet = ExpectBlank == Str.empty();
5234bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5235 TheCondStack.push_back(TheCondState);
5238 if (TheCondState.
Ignore) {
5239 eatToEndOfStatement();
5241 StringRef Str1 = parseStringToComma();
5246 StringRef Str2 = parseStringToEndOfStatement();
5260bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5261 TheCondStack.push_back(TheCondState);
5264 if (TheCondState.
Ignore) {
5265 eatToEndOfStatement();
5269 return TokError(
"expected string parameter for '.ifeqs' directive");
5270 return TokError(
"expected string parameter for '.ifnes' directive");
5273 StringRef String1 = getTok().getStringContents();
5279 "expected comma after first string for '.ifeqs' directive");
5281 "expected comma after first string for '.ifnes' directive");
5288 return TokError(
"expected string parameter for '.ifeqs' directive");
5289 return TokError(
"expected string parameter for '.ifnes' directive");
5292 StringRef String2 = getTok().getStringContents();
5295 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5304bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5306 TheCondStack.push_back(TheCondState);
5309 if (TheCondState.
Ignore) {
5310 eatToEndOfStatement();
5312 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5330bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5333 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5334 " .if or an .elseif");
5337 bool LastIgnoreState =
false;
5338 if (!TheCondStack.empty())
5339 LastIgnoreState = TheCondStack.back().Ignore;
5340 if (LastIgnoreState || TheCondState.
CondMet) {
5341 TheCondState.
Ignore =
true;
5342 eatToEndOfStatement();
5345 if (parseAbsoluteExpression(ExprValue))
5351 TheCondState.
CondMet = ExprValue;
5360bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5366 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5367 " an .if or an .elseif");
5369 bool LastIgnoreState =
false;
5370 if (!TheCondStack.empty())
5371 LastIgnoreState = TheCondStack.back().Ignore;
5372 if (LastIgnoreState || TheCondState.
CondMet)
5373 TheCondState.
Ignore =
true;
5375 TheCondState.
Ignore =
false;
5382bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5395bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5396 if (!TheCondStack.empty()) {
5397 if (TheCondStack.back().Ignore) {
5398 eatToEndOfStatement();
5404 return Error(L,
".err encountered");
5406 StringRef Message =
".error directive invoked in source file";
5409 return TokError(
".error argument must be a string");
5411 Message = getTok().getStringContents();
5415 return Error(L, Message);
5420bool AsmParser::parseDirectiveWarning(SMLoc L) {
5421 if (!TheCondStack.empty()) {
5422 if (TheCondStack.back().Ignore) {
5423 eatToEndOfStatement();
5428 StringRef Message =
".warning directive invoked in source file";
5432 return TokError(
".warning argument must be a string");
5434 Message = getTok().getStringContents();
5445bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5450 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5452 if (!TheCondStack.empty()) {
5453 TheCondState = TheCondStack.back();
5454 TheCondStack.pop_back();
5460void AsmParser::initializeDirectiveKindMap() {
5467 DirectiveKindMap[
".set"] = DK_SET;
5468 DirectiveKindMap[
".equ"] = DK_EQU;
5469 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5470 DirectiveKindMap[
".ascii"] = DK_ASCII;
5471 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5472 DirectiveKindMap[
".string"] = DK_STRING;
5473 DirectiveKindMap[
".byte"] = DK_BYTE;
5474 DirectiveKindMap[
".base64"] = DK_BASE64;
5475 DirectiveKindMap[
".short"] = DK_SHORT;
5476 DirectiveKindMap[
".value"] = DK_VALUE;
5477 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5478 DirectiveKindMap[
".long"] = DK_LONG;
5479 DirectiveKindMap[
".int"] = DK_INT;
5480 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5481 DirectiveKindMap[
".quad"] = DK_QUAD;
5482 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5483 DirectiveKindMap[
".octa"] = DK_OCTA;
5484 DirectiveKindMap[
".single"] = DK_SINGLE;
5485 DirectiveKindMap[
".float"] = DK_FLOAT;
5486 DirectiveKindMap[
".double"] = DK_DOUBLE;
5487 DirectiveKindMap[
".align"] = DK_ALIGN;
5488 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5489 DirectiveKindMap[
".balign"] = DK_BALIGN;
5490 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5491 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5492 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5493 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5494 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5495 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5496 DirectiveKindMap[
".org"] = DK_ORG;
5497 DirectiveKindMap[
".fill"] = DK_FILL;
5498 DirectiveKindMap[
".zero"] = DK_ZERO;
5499 DirectiveKindMap[
".extern"] = DK_EXTERN;
5500 DirectiveKindMap[
".globl"] = DK_GLOBL;
5501 DirectiveKindMap[
".global"] = DK_GLOBAL;
5502 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5503 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5504 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5505 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5506 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5507 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5508 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5509 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5510 DirectiveKindMap[
".cold"] = DK_COLD;
5511 DirectiveKindMap[
".comm"] = DK_COMM;
5512 DirectiveKindMap[
".common"] = DK_COMMON;
5513 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5514 DirectiveKindMap[
".abort"] = DK_ABORT;
5515 DirectiveKindMap[
".include"] = DK_INCLUDE;
5516 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5517 DirectiveKindMap[
".code16"] = DK_CODE16;
5518 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5519 DirectiveKindMap[
".rept"] = DK_REPT;
5520 DirectiveKindMap[
".rep"] = DK_REPT;
5521 DirectiveKindMap[
".irp"] = DK_IRP;
5522 DirectiveKindMap[
".irpc"] = DK_IRPC;
5523 DirectiveKindMap[
".endr"] = DK_ENDR;
5524 DirectiveKindMap[
".if"] = DK_IF;
5525 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5526 DirectiveKindMap[
".ifge"] = DK_IFGE;
5527 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5528 DirectiveKindMap[
".ifle"] = DK_IFLE;
5529 DirectiveKindMap[
".iflt"] = DK_IFLT;
5530 DirectiveKindMap[
".ifne"] = DK_IFNE;
5531 DirectiveKindMap[
".ifb"] = DK_IFB;
5532 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5533 DirectiveKindMap[
".ifc"] = DK_IFC;
5534 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5535 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5536 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5537 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5538 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5539 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5540 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5541 DirectiveKindMap[
".else"] = DK_ELSE;
5542 DirectiveKindMap[
".end"] = DK_END;
5543 DirectiveKindMap[
".endif"] = DK_ENDIF;
5544 DirectiveKindMap[
".skip"] = DK_SKIP;
5545 DirectiveKindMap[
".space"] = DK_SPACE;
5546 DirectiveKindMap[
".file"] = DK_FILE;
5547 DirectiveKindMap[
".line"] = DK_LINE;
5548 DirectiveKindMap[
".loc"] = DK_LOC;
5549 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5550 DirectiveKindMap[
".stabs"] = DK_STABS;
5551 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5552 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5553 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5554 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5555 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5556 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5557 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5558 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5559 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5560 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5561 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5562 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5563 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5564 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5565 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5566 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5567 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5568 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5569 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5570 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5571 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5572 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5573 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5574 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5575 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5576 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5577 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5578 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5579 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5580 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5581 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5582 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5583 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5584 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5585 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5586 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5587 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5588 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5589 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5590 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5591 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5592 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5593 DirectiveKindMap[
".macro"] = DK_MACRO;
5594 DirectiveKindMap[
".exitm"] = DK_EXITM;
5595 DirectiveKindMap[
".endm"] = DK_ENDM;
5596 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5597 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5598 DirectiveKindMap[
".err"] = DK_ERR;
5599 DirectiveKindMap[
".error"] = DK_ERROR;
5600 DirectiveKindMap[
".warning"] = DK_WARNING;
5601 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5602 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5603 DirectiveKindMap[
".reloc"] = DK_RELOC;
5604 DirectiveKindMap[
".dc"] = DK_DC;
5605 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5606 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5607 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5608 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5609 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5610 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5611 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5612 DirectiveKindMap[
".dcb"] = DK_DCB;
5613 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5614 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5615 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5616 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5617 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5618 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5619 DirectiveKindMap[
".ds"] = DK_DS;
5620 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5621 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5622 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5623 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5624 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5625 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5626 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5627 DirectiveKindMap[
".print"] = DK_PRINT;
5628 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5629 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5630 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5631 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5632 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5633 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5636MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5637 AsmToken EndToken, StartToken = getTok();
5639 unsigned NestLevel = 0;
5643 printError(DirectiveLoc,
"no matching '.endr' in definition");
5648 StringRef Ident = getTok().getIdentifier();
5649 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5652 }
else if (Ident ==
".endr") {
5653 if (NestLevel == 0) {
5654 EndToken = getTok();
5658 printError(getTok().getLoc(),
"expected newline");
5666 eatToEndOfStatement();
5671 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5675 return &MacroLikeBodies.back();
5678void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5679 raw_svector_ostream &OS) {
5682 std::unique_ptr<MemoryBuffer> Instantiation =
5687 MacroInstantiation *
MI =
new MacroInstantiation{
5688 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5689 ActiveMacros.push_back(
MI);
5699bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5700 const MCExpr *CountExpr;
5701 SMLoc CountLoc = getTok().getLoc();
5702 if (parseExpression(CountExpr))
5706 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5707 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5710 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5714 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5720 SmallString<256> Buf;
5721 raw_svector_ostream OS(Buf);
5724 if (expandMacro(OS, *M, {}, {},
false))
5727 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5734bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5736 MCAsmMacroArguments
A;
5737 if (check(parseIdentifier(
Parameter.Name),
5738 "expected identifier in '.irp' directive") ||
5739 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5743 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5749 SmallString<256> Buf;
5750 raw_svector_ostream OS(Buf);
5752 for (
const MCAsmMacroArgument &Arg :
A) {
5755 if (expandMacro(OS, *M, Parameter, Arg,
true))
5759 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5766bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5768 MCAsmMacroArguments
A;
5770 if (check(parseIdentifier(
Parameter.Name),
5771 "expected identifier in '.irpc' directive") ||
5772 parseComma() || parseMacroArguments(
nullptr,
A))
5775 if (
A.size() != 1 ||
A.front().size() != 1)
5776 return TokError(
"unexpected token in '.irpc' directive");
5781 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5787 SmallString<256> Buf;
5788 raw_svector_ostream OS(Buf);
5791 :
A[0][0].getString();
5792 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5793 MCAsmMacroArgument Arg;
5798 if (expandMacro(OS, *M, Parameter, Arg,
true))
5802 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5807bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5808 if (ActiveMacros.empty())
5809 return TokError(
"unmatched '.endr' directive");
5819bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
5821 const MCExpr *
Value;
5822 SMLoc ExprLoc = getLexer().getLoc();
5823 if (parseExpression(
Value))
5827 return Error(ExprLoc,
"unexpected expression in _emit");
5828 uint64_t IntValue = MCE->
getValue();
5830 return Error(ExprLoc,
"literal value out of range for directive");
5836bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
5837 const MCExpr *
Value;
5838 SMLoc ExprLoc = getLexer().getLoc();
5839 if (parseExpression(
Value))
5843 return Error(ExprLoc,
"unexpected expression in align");
5844 uint64_t IntValue = MCE->
getValue();
5846 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5852bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5853 const AsmToken StrTok = getTok();
5856 return Error(DirectiveLoc,
"expected double quoted string after .print");
5863bool AsmParser::parseDirectiveAddrsig() {
5866 getStreamer().emitAddrsig();
5870bool AsmParser::parseDirectiveAddrsigSym() {
5872 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
5874 getStreamer().emitAddrsigSym(Sym);
5878bool AsmParser::parseDirectivePseudoProbe() {
5884 if (parseIntToken(
Guid))
5886 if (parseIntToken(Index))
5888 if (parseIntToken(
Type))
5890 if (parseIntToken(Attr))
5902 int64_t CallerGuid = 0;
5904 CallerGuid = getTok().getIntVal();
5912 int64_t CallerProbeId = 0;
5914 CallerProbeId = getTok().getIntVal();
5924 if (parseIdentifier(FnName))
5925 return Error(getLexer().getLoc(),
"expected identifier");
5931 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
5932 InlineStack, FnSym);
5941bool AsmParser::parseDirectiveLTODiscard() {
5942 auto ParseOp = [&]() ->
bool {
5944 SMLoc Loc = getTok().getLoc();
5945 if (parseIdentifier(Name))
5946 return Error(Loc,
"expected identifier");
5947 LTODiscardSymbols.
insert(Name);
5951 LTODiscardSymbols.
clear();
5952 return parseMany(ParseOp);
5978bool AsmParser::parseMSInlineAsm(
5979 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
5980 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5981 SmallVectorImpl<std::string> &Constraints,
5982 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
5983 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
5984 SmallVector<void *, 4> InputDecls;
5985 SmallVector<void *, 4> OutputDecls;
5988 SmallVector<std::string, 4> InputConstraints;
5989 SmallVector<std::string, 4> OutputConstraints;
5998 unsigned InputIdx = 0;
5999 unsigned OutputIdx = 0;
6002 if (parseCurlyBlockScope(AsmStrRewrites))
6005 ParseStatementInfo
Info(&AsmStrRewrites);
6006 bool StatementErr = parseStatement(Info, &SI);
6008 if (StatementErr ||
Info.ParseError) {
6010 printPendingErrors();
6015 assert(!hasPendingError() &&
"unexpected error from parseStatement");
6017 if (
Info.Opcode == ~0U)
6023 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
6024 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
6028 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
6029 unsigned NumDefs =
Desc.getNumDefs();
6038 if (SymName.
empty())
6046 if (Operand.
isImm()) {
6054 bool isOutput = (i == 1) &&
Desc.mayStore();
6061 OutputConstraints.
push_back((
"=" + Constraint).str());
6068 if (
Desc.operands()[i - 1].isBranchTarget())
6082 NumOutputs = OutputDecls.
size();
6083 NumInputs = InputDecls.
size();
6088 Clobbers.
assign(ClobberRegs.
size(), std::string());
6089 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6090 raw_string_ostream OS(Clobbers[
I]);
6095 if (NumOutputs || NumInputs) {
6096 unsigned NumExprs = NumOutputs + NumInputs;
6097 OpDecls.resize(NumExprs);
6098 Constraints.
resize(NumExprs);
6099 for (
unsigned i = 0; i < NumOutputs; ++i) {
6100 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6101 Constraints[i] = OutputConstraints[i];
6103 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6104 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6105 Constraints[
j] = InputConstraints[i];
6110 std::string AsmStringIR;
6111 raw_string_ostream OS(AsmStringIR);
6112 StringRef ASMString =
6114 const char *AsmStart = ASMString.
begin();
6115 const char *AsmEnd = ASMString.
end();
6117 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6118 const AsmRewrite &AR = *
I;
6125 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6128 if (
unsigned Len = Loc - AsmStart)
6129 OS << StringRef(AsmStart, Len);
6133 AsmStart = Loc + AR.
Len;
6137 unsigned AdditionalSkip = 0;
6159 size_t OffsetLen = OffsetName.
size();
6160 auto rewrite_it = std::find_if(
6161 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6162 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6163 (FusingAR.Kind == AOK_Input ||
6164 FusingAR.Kind == AOK_CallInput);
6166 if (rewrite_it == AsmStrRewrites.
end()) {
6167 OS <<
"offset " << OffsetName;
6169 OS <<
"${" << InputIdx++ <<
":P}";
6170 rewrite_it->Done =
true;
6172 OS <<
'$' << InputIdx++;
6173 rewrite_it->Done =
true;
6186 OS <<
"${" << InputIdx++ <<
":P}";
6188 OS <<
'$' << InputIdx++;
6191 OS <<
"${" << InputIdx++ <<
":P}";
6195 OS <<
"${" << OutputIdx++ <<
":P}";
6197 OS <<
'$' << OutputIdx++;
6202 case 8: OS <<
"byte ptr ";
break;
6203 case 16: OS <<
"word ptr ";
break;
6204 case 32: OS <<
"dword ptr ";
break;
6205 case 64: OS <<
"qword ptr ";
break;
6206 case 80: OS <<
"xword ptr ";
break;
6207 case 128: OS <<
"xmmword ptr ";
break;
6208 case 256: OS <<
"ymmword ptr ";
break;
6218 if (
getContext().getAsmInfo()->getAlignmentIsInBytes())
6223 unsigned Val = AR.
Val;
6225 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6226 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6238 AsmStart = Loc + AR.
Len + AdditionalSkip;
6242 if (AsmStart != AsmEnd)
6243 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6245 AsmString = std::move(AsmStringIR);
6249bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6250 MCAsmParserSemaCallback *SI) {
6251 AsmToken LabelTok = getTok();
6252 SMLoc LabelLoc = LabelTok.
getLoc();
6255 if (parseIdentifier(LabelVal))
6256 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6261 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6270 return Error(LabelLoc,
6271 "Cannot have just a label for an HLASM inline asm statement");
6281 if (enabledGenDwarfForAssembly())
6288bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6289 MCAsmParserSemaCallback *SI) {
6290 AsmToken OperationEntryTok = Lexer.
getTok();
6291 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6292 StringRef OperationEntryVal;
6295 if (parseIdentifier(OperationEntryVal))
6296 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6302 return parseAndMatchAndEmitTargetInstruction(
6303 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6306bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6307 MCAsmParserSemaCallback *SI) {
6308 assert(!hasPendingError() &&
"parseStatement started with pending error");
6311 bool ShouldParseAsHLASMLabel =
false;
6320 ShouldParseAsHLASMLabel =
true;
6326 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6327 getTok().getString().
front() ==
'\n')
6342 if (getTok().getString().
front() ==
'\n' ||
6343 getTok().getString().
front() ==
'\r') {
6352 if (ShouldParseAsHLASMLabel) {
6355 if (parseAsHLASMLabel(Info, SI)) {
6358 eatToEndOfStatement();
6363 return parseAsMachineInstruction(Info, SI);
6375 return Parser.
TokError(
"missing expression");
6381 return Parser.
Error(
6382 EqualLoc,
"relocation specifier not permitted in symbol equating");
6390 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6396 }
else if (Name ==
".") {
6411 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6412 return new HLASMAsmParser(
SM,
C, Out, MAI, CB);
6414 return new AsmParser(
SM,
C, Out, MAI, CB);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static Expected< std::vector< unsigned > > getSymbols(SymbolicFile *Obj, uint16_t Index, raw_ostream &SymNames, SymMap *SymMap)
static bool isValidEncoding(int64_t Encoding)
static bool isAngleBracketString(SMLoc &StrLoc, SMLoc &EndLoc)
This function checks if the next token is <string> type or arithmetic.
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static unsigned getGNUBinOpPrecedence(const MCAsmInfo &MAI, AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static std::string angleBracketString(StringRef AltMacroStr)
creating a string without the escape characters '!'.
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
static bool parseHexOcta(AsmParser &Asm, uint64_t &hi, uint64_t &lo)
static bool isOperator(AsmToken::TokenKind kind)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
This file contains constants used for implementing Dwarf debug support.
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_BASIC_BLOCK
#define DWARF2_LINE_DEFAULT_IS_STMT
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$....
Promote Memory to Register
static constexpr unsigned SM(unsigned Version)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
static StringRef getName(Value *V)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Class for arbitrary precision integers.
LLVM_ABI APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
unsigned getBitWidth() const
Return the number of bits in the APInt.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
ConditionalAssemblyType TheCond
SMLoc getLoc() const
Get the current source location.
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool getAllowAtInIdentifier()
void UnLex(AsmToken const &Token)
AsmToken::TokenKind getKind() const
Get the kind of current token.
const MCAsmInfo & getMAI() const
const AsmToken & getTok() const
Get the current (last) lexed token.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
SMLoc getErrLoc()
Get the current error location.
const std::string & getErr()
Get the current error string.
const AsmToken & Lex()
Consume the next token from the input stream and return it.
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
LLVM_ABI void setBuffer(StringRef Buf, const char *ptr=nullptr, bool EndStatementAtEOF=true)
Set buffer to be lexed.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
LLVM_ABI size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)
Look ahead an arbitrary number of tokens.
LLVM_ABI SMLoc getLoc() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
bool is(TokenKind K) const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Error takeError()
Take ownership of the stored error.
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
bool isLittleEndian() const
True if the target is little endian.
bool useAtForSpecifier() const
bool doesAllowAtInName() const
StringRef getPrivateLabelPrefix() const
std::optional< uint32_t > getSpecifierForName(StringRef Name) const
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
bool shouldUseLogicalShr() const
StringRef getCommentString() const
bool hasSubsectionsViaSymbols() const
bool getCOMMDirectiveAlignmentIsInBytes() const
virtual bool useCodeAlign(const MCSection &Sec) const
bool useParensForSpecifier() const
bool getDollarIsPC() const
virtual ~MCAsmParserSemaCallback()
Generic assembler parser interface, for use by target specific assembly parsers.
bool Error(SMLoc L, const Twine &Msg, SMRange Range={})
Return an error at the location L, with the message Msg.
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
bool parseAtSpecifier(const MCExpr *&Res, SMLoc &EndLoc)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
const MCExpr * applySpecifier(const MCExpr *E, uint32_t Variant)
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
bool TokError(const Twine &Msg, SMRange Range={})
Report an error at the current lexer location.
MCStreamer & getStreamer()
MCTargetAsmParser & getTargetParser() const
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
@ AShr
Arithmetic shift right.
@ LShr
Logical shift right.
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
@ Xor
Bitwise exclusive or.
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
@ NE
Inequality comparison.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
void * allocate(unsigned Size, unsigned Align=8)
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
bool getGenDwarfForAssembly()
void setGenDwarfForAssembly(bool Value)
void setDwarfVersion(uint16_t v)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_ABI MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
LLVM_ABI MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
uint16_t getDwarfVersion() const
const MCAsmInfo * getAsmInfo() const
LLVM_ABI MCSymbol * cloneSymbol(MCSymbol &Sym)
Clone a symbol for the .set directive, replacing it in the symbol table.
LLVM_ABI MCSymbol * parseSymbol(const Twine &Name)
Variant of getOrCreateSymbol that handles backslash-escaped symbols.
LLVM_ABI MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
virtual void printRegName(raw_ostream &OS, MCRegister Reg)
Print the assembler register name.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
virtual bool isMemUseUpRegs() const
isMemUseUpRegs - Is memory operand use up regs, for example, intel MS inline asm may use ARR[baseReg ...
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label?
virtual MCRegister getReg() const =0
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable,...
virtual StringRef getSymName()
virtual bool isImm() const =0
isImm - Is this an immediate operand?
unsigned getMCOperandNum()
StringRef getConstraint()
virtual void * getOpDecl()
void setBeginSymbol(MCSymbol *Sym)
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
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.
unsigned getMainFileID() const
const MemoryBuffer * getMemoryBuffer(unsigned i) const
LLVM_ABI void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
SMLoc getParentIncludeLoc(unsigned i) const
LLVM_ABI void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
LLVM_ABI unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
LLVM_ABI unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
StringMapIterBase< ValueTy, true > const_iterator
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
LLVM_ABI std::string lower() const
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
LLVM Value Representation.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
std::variant< std::monostate, DecisionParameters, BranchParameters > Parameters
The type of MC/DC-specific parameters.
@ Parameter
An inlay hint that is for a parameter.
Context & getContext() const
LLVM_ABI Instruction & front() const
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
FunctionAddr VTableAddr Value
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation. The return string is half the size of ...
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
std::tuple< uint64_t, uint32_t > InlineSite
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
auto unique(Range &&R, Predicate P)
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
cl::opt< unsigned > AsmMacroMaxNestingDepth
SmallVector< InlineSite, 8 > MCPseudoProbeInlineStack
const char AsmRewritePrecedence[]
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool hasDiscriminator(uint32_t Flags)
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
FunctionAddr VTableAddr Count
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ABI llvm::Error decodeBase64(llvm::StringRef Input, std::vector< char > &Output)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance for parsing assembly similar to gas syntax.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
@ Sub
Subtraction of integers.
FunctionAddr VTableAddr Next
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
void consumeError(Error Err)
Consume a Error without doing anything.
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
ArrayRef< int > hi(ArrayRef< int > Vuu)
ArrayRef< int > lo(ArrayRef< int > Vuu)
std::vector< AsmToken > Value
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
std::optional< StringRef > Source
The source code of the file.