80typedef std::vector<AsmToken> MCAsmMacroArgument;
81typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
85struct MacroInstantiation {
87 SMLoc InstantiationLoc;
96 size_t CondStackDepth;
99struct ParseStatementInfo {
104 unsigned Opcode = ~0
U;
107 bool ParseError =
false;
109 SmallVectorImpl<AsmRewrite> *AsmRewrites =
nullptr;
111 ParseStatementInfo() =
delete;
112 ParseStatementInfo(SmallVectorImpl<AsmRewrite> *rewrites)
113 : AsmRewrites(rewrites) {}
120 void *SavedDiagContext;
121 std::unique_ptr<MCAsmParserExtension> PlatformParser;
123 std::optional<SMLoc> CFIStartProcLoc;
129 AsmCond TheCondState;
130 std::vector<AsmCond> TheCondStack;
135 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
138 std::vector<MacroInstantiation*> ActiveMacros;
141 std::deque<MCAsmMacro> MacroLikeBodies;
144 unsigned MacrosEnabledFlag : 1;
147 unsigned NumOfMacroInstantiations = 0;
150 struct CppHashInfoTy {
155 CppHashInfoTy() : LineNumber(0), Buf(0) {}
157 CppHashInfoTy CppHashInfo;
160 bool HadCppHashFilename =
false;
165 SmallSet<StringRef, 2> LTODiscardSymbols;
168 unsigned AssemblerDialect = ~0
U;
171 bool IsDarwin =
false;
174 bool ParsingMSInlineAsm =
false;
177 bool ReportedInconsistentMD5 =
false;
180 bool AltMacroMode =
false;
183 virtual bool parseStatement(ParseStatementInfo &
Info,
184 MCAsmParserSemaCallback *SI);
189 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &
Info,
190 StringRef IDVal, AsmToken
ID,
196 bool enabledGenDwarfForAssembly();
199 AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
200 const MCAsmInfo &MAI,
unsigned CB);
201 AsmParser(
const AsmParser &) =
delete;
202 AsmParser &operator=(
const AsmParser &) =
delete;
203 ~AsmParser()
override;
205 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
207 void addDirectiveHandler(StringRef Directive,
208 ExtensionDirectiveHandler Handler)
override {
209 ExtensionDirectiveMap[Directive] = Handler;
212 void addAliasForDirective(StringRef Directive, StringRef Alias)
override {
213 DirectiveKindMap[Directive.
lower()] = DirectiveKindMap[Alias.
lower()];
219 CodeViewContext &getCVContext() {
return Ctx.getCVContext(); }
221 unsigned getAssemblerDialect()
override {
222 if (AssemblerDialect == ~0U)
223 return MAI.getAssemblerDialect();
225 return AssemblerDialect;
227 void setAssemblerDialect(
unsigned i)
override {
228 AssemblerDialect = i;
231 void Note(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
232 bool Warning(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
233 bool printError(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
235 const AsmToken &Lex()
override;
237 void setParsingMSInlineAsm(
bool V)
override {
238 ParsingMSInlineAsm =
V;
241 Lexer.setLexMasmIntegers(V);
243 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
245 bool discardLTOSymbol(StringRef Name)
const override {
246 return LTODiscardSymbols.contains(Name);
249 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
251 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
252 SmallVectorImpl<std::string> &Constraints,
253 SmallVectorImpl<std::string> &Clobbers,
254 const MCInstrInfo *MII, MCInstPrinter *IP,
255 MCAsmParserSemaCallback &SI)
override;
257 bool parseExpression(
const MCExpr *&Res);
258 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
259 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
260 AsmTypeInfo *TypeInfo)
override;
261 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
262 bool parseAbsoluteExpression(int64_t &Res)
override;
266 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
270 bool parseIdentifier(StringRef &Res)
override;
271 void eatToEndOfStatement()
override;
273 bool checkForValidSection()
override;
278 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
279 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
281 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
283 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
288 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
291 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
294 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
300 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
303 void handleMacroExit();
306 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
309 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
311 void printMacroInstantiations();
313 SMRange
Range = {})
const {
320 bool enterIncludeFile(
const std::string &Filename);
324 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
325 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
333 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
338 StringRef parseStringToEndOfStatement()
override;
342 StringRef parseStringToComma();
344 enum class AssignmentKind {
351 bool parseAssignment(StringRef Name, AssignmentKind Kind);
356 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
357 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
358 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
360 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
362 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
363 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
433 DK_WEAK_DEF_CAN_BE_HIDDEN,
474 DK_CV_INLINE_SITE_ID,
477 DK_CV_INLINE_LINETABLE,
482 DK_CV_FILECHECKSUM_OFFSET,
488 DK_CFI_DEF_CFA_OFFSET,
489 DK_CFI_ADJUST_CFA_OFFSET,
490 DK_CFI_DEF_CFA_REGISTER,
491 DK_CFI_LLVM_DEF_ASPACE_CFA,
496 DK_CFI_REMEMBER_STATE,
497 DK_CFI_RESTORE_STATE,
501 DK_CFI_RETURN_COLUMN,
528 DK_LTO_SET_CONDITIONAL,
529 DK_CFI_MTE_TAGGED_FRAME,
536 StringMap<DirectiveKind> DirectiveKindMap;
539 enum CVDefRangeType {
541 CVDR_DEFRANGE_REGISTER,
542 CVDR_DEFRANGE_FRAMEPOINTER_REL,
543 CVDR_DEFRANGE_SUBFIELD_REGISTER,
544 CVDR_DEFRANGE_REGISTER_REL
549 StringMap<CVDefRangeType> CVDefRangeTypeMap;
552 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
553 bool parseDirectiveReloc(SMLoc DirectiveLoc);
554 bool parseDirectiveValue(StringRef IDVal,
556 bool parseDirectiveOctaValue(StringRef IDVal);
557 bool parseDirectiveRealValue(StringRef IDVal,
558 const fltSemantics &);
559 bool parseDirectiveFill();
560 bool parseDirectiveZero();
562 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
563 bool parseDirectiveOrg();
565 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
568 bool parseDirectiveFile(SMLoc DirectiveLoc);
569 bool parseDirectiveLine();
570 bool parseDirectiveLoc();
571 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
572 bool parseDirectiveStabs();
576 bool parseDirectiveCVFile();
577 bool parseDirectiveCVFuncId();
578 bool parseDirectiveCVInlineSiteId();
579 bool parseDirectiveCVLoc();
580 bool parseDirectiveCVLinetable();
581 bool parseDirectiveCVInlineLinetable();
582 bool parseDirectiveCVDefRange();
583 bool parseDirectiveCVString();
584 bool parseDirectiveCVStringTable();
585 bool parseDirectiveCVFileChecksums();
586 bool parseDirectiveCVFileChecksumOffset();
587 bool parseDirectiveCVFPOData();
590 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
591 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
592 bool parseDirectiveCFISections();
593 bool parseDirectiveCFIStartProc();
594 bool parseDirectiveCFIEndProc();
595 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
596 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
597 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
598 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
599 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
600 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
601 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
602 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
603 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
604 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
605 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
606 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
607 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
608 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
609 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
610 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
611 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
612 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
615 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
616 bool parseDirectiveExitMacro(StringRef Directive);
617 bool parseDirectiveEndMacro(StringRef Directive);
618 bool parseDirectiveMacro(SMLoc DirectiveLoc);
619 bool parseDirectiveMacrosOnOff(StringRef Directive);
621 bool parseDirectiveAltmacro(StringRef Directive);
624 bool parseDirectiveSpace(StringRef IDVal);
627 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
628 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
630 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
633 bool parseDirectiveLEB128(
bool Signed);
639 bool parseDirectiveComm(
bool IsLocal);
641 bool parseDirectiveAbort(SMLoc DirectiveLoc);
642 bool parseDirectiveInclude();
643 bool parseDirectiveIncbin();
646 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
648 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
650 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
652 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
654 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
655 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
656 bool parseDirectiveElse(SMLoc DirectiveLoc);
657 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
658 bool parseEscapedString(std::string &
Data)
override;
659 bool parseAngleBracketString(std::string &
Data)
override;
662 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
663 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
664 raw_svector_ostream &OS);
665 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
666 bool parseDirectiveIrp(SMLoc DirectiveLoc);
667 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
668 bool parseDirectiveEndr(SMLoc DirectiveLoc);
671 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &
Info,
675 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &
Info);
678 bool parseDirectiveEnd(SMLoc DirectiveLoc);
681 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
684 bool parseDirectiveWarning(SMLoc DirectiveLoc);
687 bool parseDirectivePrint(SMLoc DirectiveLoc);
690 bool parseDirectivePseudoProbe();
693 bool parseDirectiveLTODiscard();
696 bool parseDirectiveAddrsig();
697 bool parseDirectiveAddrsigSym();
699 void initializeDirectiveKindMap();
700 void initializeCVDefRangeTypeMap();
703class HLASMAsmParser final :
public AsmParser {
708 void lexLeadingSpaces() {
713 bool parseAsHLASMLabel(ParseStatementInfo &
Info, MCAsmParserSemaCallback *SI);
714 bool parseAsMachineInstruction(ParseStatementInfo &
Info,
715 MCAsmParserSemaCallback *SI);
718 HLASMAsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
719 const MCAsmInfo &MAI,
unsigned CB = 0)
720 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
721 Lexer.setSkipSpace(
false);
722 Lexer.setAllowHashInIdentifier(
true);
723 Lexer.setLexHLASMIntegers(
true);
724 Lexer.setLexHLASMStrings(
true);
727 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
729 bool parseStatement(ParseStatementInfo &
Info,
730 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);
793 initializeDirectiveKindMap();
794 initializeCVDefRangeTypeMap();
797AsmParser::~AsmParser() {
798 assert((HadError || ActiveMacros.empty()) &&
799 "Unexpected active macro instantiation!");
808void AsmParser::printMacroInstantiations() {
810 for (MacroInstantiation *M :
reverse(ActiveMacros))
812 "while in macro instantiation");
815void AsmParser::Note(SMLoc L,
const Twine &Msg, SMRange
Range) {
816 printPendingErrors();
818 printMacroInstantiations();
821bool AsmParser::Warning(SMLoc L,
const Twine &Msg, SMRange
Range) {
822 if(getTargetParser().getTargetOptions().MCNoWarn)
824 if (getTargetParser().getTargetOptions().MCFatalWarnings)
827 printMacroInstantiations();
831bool AsmParser::printError(SMLoc L,
const Twine &Msg, SMRange
Range) {
834 printMacroInstantiations();
838bool AsmParser::enterIncludeFile(
const std::string &Filename) {
839 std::string IncludedFile;
853bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
854 const MCExpr *
Count, SMLoc Loc) {
855 std::string IncludedFile;
866 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
867 return Error(Loc,
"expected absolute expression");
869 return Warning(Loc,
"negative count has no effect");
872 getStreamer().emitBytes(Bytes);
876void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
882const AsmToken &AsmParser::Lex() {
889 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
894 const AsmToken *tok = &Lexer.
Lex();
907 if (ParentIncludeLoc != SMLoc()) {
908 jumpToLoc(ParentIncludeLoc);
916bool AsmParser::enabledGenDwarfForAssembly() {
923 if (
getContext().getGenDwarfFileNumber() == 0) {
924 const MCDwarfFile &RootFile =
925 getContext().getMCDwarfLineTable(0).getRootFile();
926 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
933bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
934 LTODiscardSymbols.
clear();
937 if (!NoInitialTextSection)
944 AsmCond StartingCondState = TheCondState;
952 MCSection *Sec = getStreamer().getCurrentSectionOnly();
955 getStreamer().emitLabel(SectionStartSym);
958 bool InsertResult =
getContext().addGenDwarfSection(Sec);
959 assert(InsertResult &&
".text section should not have debug info yet");
963 getTargetParser().onBeginOfFile();
967 ParseStatementInfo
Info(&AsmStrRewrites);
968 bool HasError = parseStatement(
Info,
nullptr);
977 printPendingErrors();
980 if (HasError && !getLexer().justConsumedEOL())
981 eatToEndOfStatement();
984 getTargetParser().onEndOfFile();
985 printPendingErrors();
988 assert(!hasPendingError() &&
"unexpected error from parseStatement");
992 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
994 const auto &LineTables =
getContext().getMCDwarfLineTables();
995 if (!LineTables.empty()) {
997 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
998 if (
File.Name.empty() && Index != 0)
999 printError(getTok().getLoc(),
"unassigned file number: " +
1001 " for .file directives");
1013 MCSymbol *Sym = TableEntry.getValue().Symbol;
1022 printError(getTok().getLoc(),
"assembler local symbol '" +
1023 Sym->
getName() +
"' not defined");
1029 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1030 if (std::get<2>(LocSym)->isUndefined()) {
1033 CppHashInfo = std::get<1>(LocSym);
1034 printError(std::get<0>(LocSym),
"directional label undefined");
1040 if (!HadError && !NoFinalize) {
1042 TS->emitConstantPools();
1050bool AsmParser::checkForValidSection() {
1051 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1053 return Error(getTok().getLoc(),
1054 "expected section directive before assembly directive");
1060void AsmParser::eatToEndOfStatement() {
1069StringRef AsmParser::parseStringToEndOfStatement() {
1070 const char *
Start = getTok().getLoc().getPointer();
1076 return StringRef(Start, End - Start);
1079StringRef AsmParser::parseStringToComma() {
1080 const char *
Start = getTok().getLoc().getPointer();
1086 const char *End = getTok().getLoc().getPointer();
1087 return StringRef(Start, End - Start);
1095bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1096 if (parseExpression(Res))
1099 return parseRParen();
1107bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1108 if (parseExpression(Res))
1110 EndLoc = getTok().getEndLoc();
1111 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1122bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1123 AsmTypeInfo *TypeInfo) {
1124 SMLoc FirstTokenLoc = getLexer().getLoc();
1126 switch (FirstTokenKind) {
1128 return TokError(
"unknown token in expression");
1134 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1144 if (parseIdentifier(Identifier)) {
1148 bool ShouldGenerateTempSymbol =
false;
1151 ShouldGenerateTempSymbol =
true;
1153 if (!ShouldGenerateTempSymbol)
1154 return Error(FirstTokenLoc,
"invalid token in expression");
1163 EndLoc = FirstTokenLoc;
1168 std::pair<StringRef, StringRef>
Split;
1173 SMLoc AtLoc = getLexer().getLoc();
1175 if (parseIdentifier(VName))
1176 return Error(AtLoc,
"expected symbol variant after '@'");
1178 Split = std::make_pair(Identifier, VName);
1186 parseIdentifier(VName);
1189 Split = std::make_pair(Identifier, VName);
1197 return Error(getLexer().getLoc(),
"expected a symbol reference");
1201 if (!
Split.second.empty()) {
1203 if (MaybeSpecifier) {
1205 Spec = *MaybeSpecifier;
1208 "invalid variant '" +
Split.second +
"'");
1223 DoInline = TV->inlineAssignedExpr();
1226 return Error(EndLoc,
"unexpected modifier on variable reference");
1237 return TokError(
"literal value out of range for directive");
1239 SMLoc Loc = getTok().getLoc();
1240 int64_t
IntVal = getTok().getIntVal();
1246 StringRef IDVal = getTok().getString();
1248 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1250 if (
Split.first.size() != IDVal.
size()) {
1253 return TokError(
"invalid variant '" +
Split.second +
"'");
1254 IDVal =
Split.first;
1257 if (IDVal ==
"f" || IDVal ==
"b") {
1262 return Error(Loc,
"directional label undefined");
1263 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1271 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1272 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
1280 return TokError(
"cannot use . as current PC");
1293 return parseParenExpr(Res, EndLoc);
1295 if (!PlatformParser->HasBracketExpressions())
1296 return TokError(
"brackets expression not supported on this target");
1298 return parseBracketExpr(Res, EndLoc);
1301 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1307 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1313 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1320bool AsmParser::parseExpression(
const MCExpr *&Res) {
1322 return parseExpression(Res, EndLoc);
1332 switch (E->getKind()) {
1343 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1344 "' (already modified)");
1395 "Argument to the function cannot be a NULL value");
1397 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1398 (*CharPtr !=
'\0')) {
1399 if (*CharPtr ==
'!')
1403 if (*CharPtr ==
'>') {
1413 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1414 if (AltMacroStr[Pos] ==
'!')
1416 Res += AltMacroStr[Pos];
1424 return TokError(
"expected specifier following '@'");
1426 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1428 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1448bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1451 auto &TS = getTargetParser();
1452 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1460 return TokError(
"unexpected symbol modifier following '@'");
1464 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1466 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1468 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1469 "' (no symbols present)");
1479 if (Res->evaluateAsAbsolute(
Value))
1485bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1487 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1490bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1493 SMLoc StartLoc = Lexer.
getLoc();
1494 if (parseExpression(Expr))
1497 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1498 return Error(StartLoc,
"expected absolute expression");
1505 bool ShouldUseLogicalShr) {
1582 bool ShouldUseLogicalShr) {
1671bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1673 SMLoc StartLoc = Lexer.
getLoc();
1676 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1680 if (TokPrec < Precedence)
1687 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1693 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1694 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1706bool AsmParser::parseStatement(ParseStatementInfo &
Info,
1707 MCAsmParserSemaCallback *SI) {
1708 assert(!hasPendingError() &&
"parseStatement started with pending error");
1714 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1715 getTok().getString().
front() ==
'\n')
1721 AsmToken
ID = getTok();
1722 SMLoc IDLoc =
ID.getLoc();
1724 int64_t LocalLabelVal = -1;
1725 StartTokLoc =
ID.getLoc();
1727 return parseCppHashLineFilenameComment(IDLoc,
1728 !isInsideMacroInstantiation());
1732 LocalLabelVal = getTok().getIntVal();
1733 if (LocalLabelVal < 0) {
1734 if (!TheCondState.
Ignore) {
1736 return Error(IDLoc,
"unexpected token at start of statement");
1740 IDVal = getTok().getString();
1743 if (!TheCondState.
Ignore) {
1745 return Error(IDLoc,
"unexpected token at start of statement");
1753 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1755 IDVal =
ID.getString();
1756 }
else if (parseIdentifier(IDVal)) {
1757 if (!TheCondState.
Ignore) {
1759 return Error(IDLoc,
"unexpected token at start of statement");
1768 DirectiveKindMap.find(IDVal.
lower());
1769 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1771 : DirKindIt->getValue();
1782 return parseDirectiveIf(IDLoc, DirKind);
1784 return parseDirectiveIfb(IDLoc,
true);
1786 return parseDirectiveIfb(IDLoc,
false);
1788 return parseDirectiveIfc(IDLoc,
true);
1790 return parseDirectiveIfeqs(IDLoc,
true);
1792 return parseDirectiveIfc(IDLoc,
false);
1794 return parseDirectiveIfeqs(IDLoc,
false);
1796 return parseDirectiveIfdef(IDLoc,
true);
1799 return parseDirectiveIfdef(IDLoc,
false);
1801 return parseDirectiveElseIf(IDLoc);
1803 return parseDirectiveElse(IDLoc);
1805 return parseDirectiveEndIf(IDLoc);
1810 if (TheCondState.
Ignore) {
1811 eatToEndOfStatement();
1821 if (checkForValidSection())
1828 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1836 if (LocalLabelVal == -1) {
1837 if (ParsingMSInlineAsm && SI) {
1838 StringRef RewrittenLabel =
1839 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1841 "We should have an internal name here.");
1844 IDVal = RewrittenLabel;
1854 StringRef CommentStr = parseStringToEndOfStatement();
1865 if (MAI.
isMachO() && CFIStartProcLoc) {
1866 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1867 if (SymM->isExternal() && !SymM->isAltEntry())
1868 return Error(StartTokLoc,
"non-private labels cannot appear between "
1869 ".cfi_startproc / .cfi_endproc pairs") &&
1870 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1873 if (discardLTOSymbol(IDVal))
1876 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1879 if (!getTargetParser().isParsingMSInlineAsm())
1884 if (enabledGenDwarfForAssembly())
1888 getTargetParser().onLabelParsed(Sym);
1897 return parseAssignment(IDVal, AssignmentKind::Equal);
1901 if (areMacrosEnabled())
1902 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1903 return handleMacroEntry(M, IDLoc);
1920 getTargetParser().flushPendingInstructions(getStreamer());
1922 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
1924 "Should only return Failure iff there was an error");
1932 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1933 ExtensionDirectiveMap.
lookup(IDVal);
1935 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1944 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1946 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1947 case DK_LTO_SET_CONDITIONAL:
1948 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1950 return parseDirectiveAscii(IDVal,
false);
1953 return parseDirectiveAscii(IDVal,
true);
1956 return parseDirectiveValue(IDVal, 1);
1962 return parseDirectiveValue(IDVal, 2);
1967 return parseDirectiveValue(IDVal, 4);
1970 return parseDirectiveValue(IDVal, 8);
1972 return parseDirectiveValue(
1973 IDVal,
getContext().getAsmInfo()->getCodePointerSize());
1975 return parseDirectiveOctaValue(IDVal);
1979 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1982 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1984 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1985 return parseDirectiveAlign(IsPow2, 1);
1988 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1989 return parseDirectiveAlign(IsPow2, 4);
1992 return parseDirectiveAlign(
false, 1);
1994 return parseDirectiveAlign(
false, 2);
1996 return parseDirectiveAlign(
false, 4);
1998 return parseDirectiveAlign(
true, 1);
2000 return parseDirectiveAlign(
true, 2);
2002 return parseDirectiveAlign(
true, 4);
2004 return parseDirectiveOrg();
2006 return parseDirectiveFill();
2008 return parseDirectiveZero();
2010 eatToEndOfStatement();
2014 return parseDirectiveSymbolAttribute(
MCSA_Global);
2015 case DK_LAZY_REFERENCE:
2017 case DK_NO_DEAD_STRIP:
2019 case DK_SYMBOL_RESOLVER:
2021 case DK_PRIVATE_EXTERN:
2025 case DK_WEAK_DEFINITION:
2027 case DK_WEAK_REFERENCE:
2029 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2032 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2035 return parseDirectiveComm(
false);
2037 return parseDirectiveComm(
true);
2039 return parseDirectiveAbort(IDLoc);
2041 return parseDirectiveInclude();
2043 return parseDirectiveIncbin();
2046 return TokError(Twine(IDVal) +
2047 " not currently supported for this target");
2049 return parseDirectiveRept(IDLoc, IDVal);
2051 return parseDirectiveIrp(IDLoc);
2053 return parseDirectiveIrpc(IDLoc);
2055 return parseDirectiveEndr(IDLoc);
2057 return parseDirectiveLEB128(
true);
2059 return parseDirectiveLEB128(
false);
2062 return parseDirectiveSpace(IDVal);
2064 return parseDirectiveFile(IDLoc);
2066 return parseDirectiveLine();
2068 return parseDirectiveLoc();
2070 return parseDirectiveLocLabel(IDLoc);
2072 return parseDirectiveStabs();
2074 return parseDirectiveCVFile();
2076 return parseDirectiveCVFuncId();
2077 case DK_CV_INLINE_SITE_ID:
2078 return parseDirectiveCVInlineSiteId();
2080 return parseDirectiveCVLoc();
2081 case DK_CV_LINETABLE:
2082 return parseDirectiveCVLinetable();
2083 case DK_CV_INLINE_LINETABLE:
2084 return parseDirectiveCVInlineLinetable();
2085 case DK_CV_DEF_RANGE:
2086 return parseDirectiveCVDefRange();
2088 return parseDirectiveCVString();
2089 case DK_CV_STRINGTABLE:
2090 return parseDirectiveCVStringTable();
2091 case DK_CV_FILECHECKSUMS:
2092 return parseDirectiveCVFileChecksums();
2093 case DK_CV_FILECHECKSUM_OFFSET:
2094 return parseDirectiveCVFileChecksumOffset();
2095 case DK_CV_FPO_DATA:
2096 return parseDirectiveCVFPOData();
2097 case DK_CFI_SECTIONS:
2098 return parseDirectiveCFISections();
2099 case DK_CFI_STARTPROC:
2100 return parseDirectiveCFIStartProc();
2101 case DK_CFI_ENDPROC:
2102 return parseDirectiveCFIEndProc();
2103 case DK_CFI_DEF_CFA:
2104 return parseDirectiveCFIDefCfa(IDLoc);
2105 case DK_CFI_DEF_CFA_OFFSET:
2106 return parseDirectiveCFIDefCfaOffset(IDLoc);
2107 case DK_CFI_ADJUST_CFA_OFFSET:
2108 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2109 case DK_CFI_DEF_CFA_REGISTER:
2110 return parseDirectiveCFIDefCfaRegister(IDLoc);
2111 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2112 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2114 return parseDirectiveCFIOffset(IDLoc);
2115 case DK_CFI_REL_OFFSET:
2116 return parseDirectiveCFIRelOffset(IDLoc);
2117 case DK_CFI_PERSONALITY:
2118 return parseDirectiveCFIPersonalityOrLsda(
true);
2120 return parseDirectiveCFIPersonalityOrLsda(
false);
2121 case DK_CFI_REMEMBER_STATE:
2122 return parseDirectiveCFIRememberState(IDLoc);
2123 case DK_CFI_RESTORE_STATE:
2124 return parseDirectiveCFIRestoreState(IDLoc);
2125 case DK_CFI_SAME_VALUE:
2126 return parseDirectiveCFISameValue(IDLoc);
2127 case DK_CFI_RESTORE:
2128 return parseDirectiveCFIRestore(IDLoc);
2130 return parseDirectiveCFIEscape(IDLoc);
2131 case DK_CFI_RETURN_COLUMN:
2132 return parseDirectiveCFIReturnColumn(IDLoc);
2133 case DK_CFI_SIGNAL_FRAME:
2134 return parseDirectiveCFISignalFrame(IDLoc);
2135 case DK_CFI_UNDEFINED:
2136 return parseDirectiveCFIUndefined(IDLoc);
2137 case DK_CFI_REGISTER:
2138 return parseDirectiveCFIRegister(IDLoc);
2139 case DK_CFI_WINDOW_SAVE:
2140 return parseDirectiveCFIWindowSave(IDLoc);
2142 return parseDirectiveCFILabel(IDLoc);
2143 case DK_CFI_VAL_OFFSET:
2144 return parseDirectiveCFIValOffset(IDLoc);
2147 return parseDirectiveMacrosOnOff(IDVal);
2149 return parseDirectiveMacro(IDLoc);
2152 return parseDirectiveAltmacro(IDVal);
2154 return parseDirectiveExitMacro(IDVal);
2157 return parseDirectiveEndMacro(IDVal);
2159 return parseDirectivePurgeMacro(IDLoc);
2161 return parseDirectiveEnd(IDLoc);
2163 return parseDirectiveError(IDLoc,
false);
2165 return parseDirectiveError(IDLoc,
true);
2167 return parseDirectiveWarning(IDLoc);
2169 return parseDirectiveReloc(IDLoc);
2172 return parseDirectiveDCB(IDVal, 2);
2174 return parseDirectiveDCB(IDVal, 1);
2176 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2178 return parseDirectiveDCB(IDVal, 4);
2180 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2183 return TokError(Twine(IDVal) +
2184 " not currently supported for this target");
2187 return parseDirectiveDS(IDVal, 2);
2189 return parseDirectiveDS(IDVal, 1);
2191 return parseDirectiveDS(IDVal, 8);
2194 return parseDirectiveDS(IDVal, 4);
2197 return parseDirectiveDS(IDVal, 12);
2199 return parseDirectivePrint(IDLoc);
2201 return parseDirectiveAddrsig();
2202 case DK_ADDRSIG_SYM:
2203 return parseDirectiveAddrsigSym();
2204 case DK_PSEUDO_PROBE:
2205 return parseDirectivePseudoProbe();
2206 case DK_LTO_DISCARD:
2207 return parseDirectiveLTODiscard();
2209 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2212 return Error(IDLoc,
"unknown directive");
2216 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2217 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2218 return parseDirectiveMSEmit(IDLoc,
Info, IDVal.
size());
2221 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2222 return parseDirectiveMSAlign(IDLoc,
Info);
2224 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2226 if (checkForValidSection())
2229 return parseAndMatchAndEmitTargetInstruction(
Info, IDVal,
ID, IDLoc);
2232bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &
Info,
2237 std::string OpcodeStr = IDVal.
lower();
2238 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2239 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr,
ID,
2240 Info.ParsedOperands);
2241 Info.ParseError = ParseHadError;
2244 if (getShowParsedOperands()) {
2245 SmallString<256> Str;
2246 raw_svector_ostream OS(Str);
2247 OS <<
"parsed instruction: [";
2248 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2251 Info.ParsedOperands[i]->print(OS, MAI);
2259 if (hasPendingError() || ParseHadError)
2264 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2266 getStreamer().getCurrentSectionOnly())) {
2268 if (ActiveMacros.empty())
2272 ActiveMacros.front()->ExitBuffer);
2277 if (!CppHashInfo.Filename.empty()) {
2278 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2279 0, StringRef(), CppHashInfo.Filename);
2280 getContext().setGenDwarfFileNumber(FileNumber);
2282 unsigned CppHashLocLineNo =
2284 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2287 getStreamer().emitDwarfLocDirective(
2288 getContext().getGenDwarfFileNumber(), Line, 0,
2294 if (!ParseHadError) {
2296 if (getTargetParser().matchAndEmitInstruction(
2297 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2298 getTargetParser().isParsingMSInlineAsm()))
2306AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2311 SMLoc StartLoc = Lexer.
getLoc();
2324bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2329 "Lexing Cpp line comment: Expected Integer");
2330 int64_t LineNumber = getTok().getIntVal();
2333 "Lexing Cpp line comment: Expected String");
2334 StringRef
Filename = getTok().getString();
2345 CppHashInfo.Loc =
L;
2347 CppHashInfo.LineNumber = LineNumber;
2348 CppHashInfo.Buf = CurBuffer;
2349 if (!HadCppHashFilename) {
2350 HadCppHashFilename =
true;
2359 0,
getContext().getCompilationDir(), Filename,
2360 std::nullopt, std::nullopt);
2368void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2369 auto *Parser =
static_cast<AsmParser *
>(
Context);
2370 raw_ostream &OS =
errs();
2373 SMLoc DiagLoc = Diag.
getLoc();
2375 unsigned CppHashBuf =
2376 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2381 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2390 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2391 if (Parser->SavedDiagHandler)
2392 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2394 Parser->getContext().diagnose(Diag);
2401 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2404 int CppHashLocLineNo =
2405 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2407 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2413 if (Parser->SavedDiagHandler)
2414 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2416 Parser->getContext().diagnose(NewDiag);
2424 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2428bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2431 bool EnableAtPseudoVariable) {
2433 auto expandArg = [&](
unsigned Index) {
2434 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2435 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2436 for (
const AsmToken &Token :
A[Index])
2444 if (AltMacroMode && Token.getString().front() ==
'%' &&
2447 OS << Token.getIntVal();
2450 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2457 OS << Token.getString();
2459 OS << Token.getStringContents();
2464 StringRef Body =
Macro.Body;
2465 size_t I = 0, End = Body.
size();
2467 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2469 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2470 OS << NumOfMacroInstantiations;
2474 if (Body[
I + 1] ==
'+') {
2479 if (Body[
I + 1] ==
'(' && Body[
I + 2] ==
')') {
2488 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2492 if (Parameters[Index].Name == Argument)
2494 if (Index == NParameters)
2503 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2505 switch (Body[
I + 1]) {
2521 unsigned Index = Body[
I + 1] -
'0';
2522 if (Index <
A.size())
2523 for (
const AsmToken &Token :
A[Index])
2524 OS << Token.getString();
2539 StringRef Token(Body.
data() + Start,
I - Start);
2543 if (Parameters[Index].Name == Token)
2545 if (Index != NParameters) {
2547 if (
I != End && Body[
I] ==
'&')
2591class AsmLexerSkipSpaceRAII {
2593 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2597 ~AsmLexerSkipSpaceRAII() {
2607bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2611 StringRef Str = parseStringToEndOfStatement();
2617 unsigned ParenLevel = 0;
2620 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2627 return TokError(
"unexpected token in macro instantiation");
2629 if (ParenLevel == 0) {
2642 MA.push_back(getTok());
2666 MA.push_back(getTok());
2670 if (ParenLevel != 0)
2671 return TokError(
"unbalanced parentheses in macro argument");
2676bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2677 MCAsmMacroArguments &
A) {
2678 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2679 bool NamedParametersFound =
false;
2680 SmallVector<SMLoc, 4> FALocs;
2682 A.resize(NParameters);
2683 FALocs.
resize(NParameters);
2688 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2689 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2691 SMLoc IDLoc = Lexer.
getLoc();
2692 MCAsmMacroParameter FA;
2695 if (parseIdentifier(FA.
Name))
2696 return Error(IDLoc,
"invalid argument identifier for formal argument");
2699 return TokError(
"expected '=' after formal parameter identifier");
2703 NamedParametersFound =
true;
2705 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2707 if (NamedParametersFound && FA.
Name.
empty())
2708 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2710 SMLoc StrLoc = Lexer.
getLoc();
2713 const MCExpr *AbsoluteExp;
2717 if (parseExpression(AbsoluteExp, EndLoc))
2719 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2720 getStreamer().getAssemblerPtr()))
2721 return Error(StrLoc,
"expected absolute expression");
2725 StringRef(StrChar, EndChar - StrChar),
Value);
2726 FA.
Value.push_back(newToken);
2731 jumpToLoc(EndLoc, CurBuffer);
2735 StringRef(StrChar, EndChar - StrChar));
2736 FA.
Value.push_back(newToken);
2737 }
else if(parseMacroArgument(FA.
Value, Vararg))
2743 for (FAI = 0; FAI < NParameters; ++FAI)
2744 if (
M->Parameters[FAI].Name == FA.
Name)
2747 if (FAI >= NParameters) {
2748 assert(M &&
"expected macro to be defined");
2749 return Error(IDLoc,
"parameter named '" + FA.
Name +
2750 "' does not exist for macro '" +
M->Name +
"'");
2755 if (!FA.
Value.empty()) {
2760 if (FALocs.
size() <= PI)
2763 FALocs[PI] = Lexer.
getLoc();
2771 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2773 if (
M->Parameters[FAI].Required) {
2775 "missing value for required parameter "
2776 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2780 if (!
M->Parameters[FAI].Value.empty())
2781 A[FAI] =
M->Parameters[FAI].Value;
2790 return TokError(
"too many positional arguments");
2793bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2797 if (ActiveMacros.size() == MaxNestingDepth) {
2798 std::ostringstream MaxNestingDepthError;
2799 MaxNestingDepthError <<
"macros cannot be nested more than "
2800 << MaxNestingDepth <<
" levels deep."
2801 <<
" Use -asm-macro-max-nesting-depth to increase "
2803 return TokError(MaxNestingDepthError.str());
2806 MCAsmMacroArguments
A;
2807 if (parseMacroArguments(M,
A))
2812 SmallString<256> Buf;
2813 raw_svector_ostream OS(Buf);
2815 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2816 return Error(getTok().getLoc(),
"Wrong number of arguments");
2817 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2822 OS <<
".endmacro\n";
2824 std::unique_ptr<MemoryBuffer> Instantiation =
2829 MacroInstantiation *
MI =
new MacroInstantiation{
2830 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2831 ActiveMacros.push_back(
MI);
2833 ++NumOfMacroInstantiations;
2843void AsmParser::handleMacroExit() {
2845 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2853 delete ActiveMacros.back();
2854 ActiveMacros.pop_back();
2857bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2859 const MCExpr *
Value;
2860 SMLoc ExprLoc = getTok().getLoc();
2862 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2874 if (discardLTOSymbol(Name))
2879 case AssignmentKind::Equal:
2882 case AssignmentKind::Set:
2883 case AssignmentKind::Equiv:
2887 case AssignmentKind::LTOSetConditional:
2889 return Error(ExprLoc,
"expected identifier");
2901bool AsmParser::parseIdentifier(StringRef &Res) {
2908 SMLoc PrefixLoc = getLexer().getLoc();
2920 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2926 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2934 Res = getTok().getIdentifier();
2946bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2948 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2949 parseAssignment(Name, Kind))
2954bool AsmParser::parseEscapedString(std::string &
Data) {
2959 StringRef Str = getTok().getStringContents();
2960 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
2961 if (Str[i] !=
'\\') {
2962 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
2964 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
2968 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
2979 return TokError(
"unexpected backslash at end of string");
2982 if (Str[i] ==
'x' || Str[i] ==
'X') {
2983 size_t length = Str.size();
2984 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
2985 return TokError(
"invalid hexadecimal escape sequence");
2990 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
2998 if ((
unsigned)(Str[i] -
'0') <= 7) {
3000 unsigned Value = Str[i] -
'0';
3002 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3006 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3013 return TokError(
"invalid octal escape sequence (out of range)");
3023 return TokError(
"invalid escape sequence (unrecognized character)");
3025 case 'b':
Data +=
'\b';
break;
3026 case 'f':
Data +=
'\f';
break;
3027 case 'n':
Data +=
'\n';
break;
3028 case 'r':
Data +=
'\r';
break;
3029 case 't':
Data +=
'\t';
break;
3030 case '"':
Data +=
'"';
break;
3031 case '\\':
Data +=
'\\';
break;
3039bool AsmParser::parseAngleBracketString(std::string &
Data) {
3040 SMLoc EndLoc, StartLoc = getTok().getLoc();
3042 const char *StartChar = StartLoc.
getPointer() + 1;
3043 const char *EndChar = EndLoc.
getPointer() - 1;
3044 jumpToLoc(EndLoc, CurBuffer);
3057bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3058 auto parseOp = [&]() ->
bool {
3060 if (checkForValidSection())
3065 if (parseEscapedString(
Data))
3067 getStreamer().emitBytes(
Data);
3070 getStreamer().emitBytes(StringRef(
"\0", 1));
3074 return parseMany(parseOp);
3079bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3081 const MCExpr *Expr =
nullptr;
3083 if (parseExpression(
Offset))
3095 SMLoc ExprLoc = Lexer.
getLoc();
3096 if (parseExpression(Expr))
3101 return Error(ExprLoc,
"expression must be relocatable");
3107 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3113bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3114 auto parseOp = [&]() ->
bool {
3115 const MCExpr *
Value;
3116 SMLoc ExprLoc = getLexer().getLoc();
3117 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3122 uint64_t IntValue = MCE->getValue();
3124 return Error(ExprLoc,
"out of range literal value");
3125 getStreamer().emitIntValue(IntValue,
Size);
3127 getStreamer().emitValue(
Value,
Size, ExprLoc);
3131 return parseMany(parseOp);
3137 return Asm.TokError(
"unknown token in expression");
3138 SMLoc ExprLoc = Asm.getTok().getLoc();
3139 APInt IntValue = Asm.getTok().getAPIntVal();
3141 if (!IntValue.
isIntN(128))
3142 return Asm.Error(ExprLoc,
"out of range literal value");
3143 if (!IntValue.
isIntN(64)) {
3156bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3157 auto parseOp = [&]() ->
bool {
3158 if (checkForValidSection())
3164 getStreamer().emitInt64(lo);
3165 getStreamer().emitInt64(hi);
3167 getStreamer().emitInt64(hi);
3168 getStreamer().emitInt64(lo);
3173 return parseMany(parseOp);
3176bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3187 return TokError(Lexer.
getErr());
3190 return TokError(
"unexpected token in directive");
3194 StringRef IDVal = getTok().getString();
3202 return TokError(
"invalid floating point literal");
3204 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3206 return TokError(
"invalid floating point literal");
3213 Res =
Value.bitcastToAPInt();
3220bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3221 const fltSemantics &Semantics) {
3222 auto parseOp = [&]() ->
bool {
3224 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3231 return parseMany(parseOp);
3236bool AsmParser::parseDirectiveZero() {
3237 SMLoc NumBytesLoc = Lexer.
getLoc();
3238 const MCExpr *NumBytes;
3239 if (checkForValidSection() || parseExpression(NumBytes))
3245 if (parseAbsoluteExpression(Val))
3251 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3258bool AsmParser::parseDirectiveFill() {
3259 SMLoc NumValuesLoc = Lexer.
getLoc();
3260 const MCExpr *NumValues;
3261 if (checkForValidSection() || parseExpression(NumValues))
3264 int64_t FillSize = 1;
3265 int64_t FillExpr = 0;
3267 SMLoc SizeLoc, ExprLoc;
3270 SizeLoc = getTok().getLoc();
3271 if (parseAbsoluteExpression(FillSize))
3274 ExprLoc = getTok().getLoc();
3275 if (parseAbsoluteExpression(FillExpr))
3283 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3287 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3292 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3294 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3301bool AsmParser::parseDirectiveOrg() {
3303 SMLoc OffsetLoc = Lexer.
getLoc();
3304 if (checkForValidSection() || parseExpression(
Offset))
3308 int64_t FillExpr = 0;
3310 if (parseAbsoluteExpression(FillExpr))
3315 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3321bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3322 SMLoc AlignmentLoc = getLexer().getLoc();
3325 bool HasFillExpr =
false;
3326 int64_t FillExpr = 0;
3327 int64_t MaxBytesToFill = 0;
3330 auto parseAlign = [&]() ->
bool {
3331 if (parseAbsoluteExpression(Alignment))
3339 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3343 if (parseTokenLoc(MaxBytesLoc) ||
3344 parseAbsoluteExpression(MaxBytesToFill))
3350 if (checkForValidSection())
3354 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3361 bool ReturnVal =
false;
3366 if (Alignment >= 32) {
3367 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3371 Alignment = 1ULL << Alignment;
3379 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3383 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3384 Alignment = 1u << 31;
3390 if (MaxBytesToFill < 1) {
3391 ReturnVal |=
Error(MaxBytesLoc,
3392 "alignment directive can never be satisfied in this "
3393 "many bytes, ignoring maximum bytes expression");
3397 if (MaxBytesToFill >= Alignment) {
3398 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3404 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3405 assert(Section &&
"must have section to emit alignment");
3407 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3409 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3417 getStreamer().emitCodeAlignment(
3418 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3421 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3431bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3433 int64_t FileNumber = -1;
3435 FileNumber = getTok().getIntVal();
3439 return TokError(
"negative file number");
3446 if (parseEscapedString(Path))
3449 StringRef Directory;
3451 std::string FilenameData;
3453 if (check(FileNumber == -1,
3454 "explicit path specified, but no file number") ||
3455 parseEscapedString(FilenameData))
3463 uint64_t MD5Hi, MD5Lo;
3464 bool HasMD5 =
false;
3466 std::optional<StringRef>
Source;
3467 bool HasSource =
false;
3468 std::string SourceString;
3473 "unexpected token in '.file' directive") ||
3474 parseIdentifier(Keyword))
3476 if (Keyword ==
"md5") {
3478 if (check(FileNumber == -1,
3479 "MD5 checksum specified, but no file number") ||
3482 }
else if (Keyword ==
"source") {
3484 if (check(FileNumber == -1,
3485 "source specified, but no file number") ||
3487 "unexpected token in '.file' directive") ||
3488 parseEscapedString(SourceString))
3491 return TokError(
"unexpected token in '.file' directive");
3495 if (FileNumber == -1) {
3499 if (
getContext().getAsmInfo()->hasSingleParameterDotFile())
3500 getStreamer().emitFileDirective(Filename);
3510 std::optional<MD5::MD5Result> CKMem;
3513 for (
unsigned i = 0; i != 8; ++i) {
3514 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3515 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3520 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3521 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3522 Source = StringRef(SourceBuf, SourceString.size());
3524 if (FileNumber == 0) {
3528 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
3530 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3531 FileNumber, Directory, Filename, CKMem, Source);
3538 ReportedInconsistentMD5 =
true;
3539 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3548bool AsmParser::parseDirectiveLine() {
3560bool AsmParser::parseDirectiveLoc() {
3561 int64_t FileNumber = 0, LineNumber = 0;
3562 SMLoc Loc = getTok().getLoc();
3563 if (parseIntToken(FileNumber) ||
3565 "file number less than one in '.loc' directive") ||
3566 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3567 "unassigned file number in '.loc' directive"))
3572 LineNumber = getTok().getIntVal();
3574 return TokError(
"line number less than zero in '.loc' directive");
3578 int64_t ColumnPos = 0;
3580 ColumnPos = getTok().getIntVal();
3582 return TokError(
"column position less than zero in '.loc' directive");
3586 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3591 auto parseLocOp = [&]() ->
bool {
3593 SMLoc Loc = getTok().getLoc();
3594 if (parseIdentifier(Name))
3595 return TokError(
"unexpected token in '.loc' directive");
3597 if (Name ==
"basic_block")
3599 else if (Name ==
"prologue_end")
3601 else if (Name ==
"epilogue_begin")
3603 else if (Name ==
"is_stmt") {
3604 Loc = getTok().getLoc();
3605 const MCExpr *
Value;
3606 if (parseExpression(
Value))
3610 int Value = MCE->getValue();
3612 Flags &= ~DWARF2_FLAG_IS_STMT;
3613 else if (
Value == 1)
3616 return Error(Loc,
"is_stmt value not 0 or 1");
3618 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3620 }
else if (Name ==
"isa") {
3621 Loc = getTok().getLoc();
3622 const MCExpr *
Value;
3623 if (parseExpression(
Value))
3627 int Value = MCE->getValue();
3629 return Error(Loc,
"isa number less than zero");
3632 return Error(Loc,
"isa number not a constant value");
3634 }
else if (Name ==
"discriminator") {
3635 if (parseAbsoluteExpression(Discriminator))
3638 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3643 if (parseMany(parseLocOp,
false ))
3646 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3647 Isa, Discriminator, StringRef());
3654bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3656 DirectiveLoc = Lexer.
getLoc();
3657 if (parseIdentifier(Name))
3658 return TokError(
"expected identifier");
3661 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3667bool AsmParser::parseDirectiveStabs() {
3668 return TokError(
"unsupported directive '.stabs'");
3673bool AsmParser::parseDirectiveCVFile() {
3674 SMLoc FileNumberLoc = getTok().getLoc();
3677 std::string Checksum;
3680 if (parseIntToken(FileNumber,
"expected file number") ||
3681 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3683 "unexpected token in '.cv_file' directive") ||
3684 parseEscapedString(Filename))
3688 "unexpected token in '.cv_file' directive") ||
3689 parseEscapedString(Checksum) ||
3690 parseIntToken(ChecksumKind,
3691 "expected checksum kind in '.cv_file' directive") ||
3697 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3698 memcpy(CKMem, Checksum.data(), Checksum.size());
3699 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3702 if (!getStreamer().emitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
3703 static_cast<uint8_t
>(ChecksumKind)))
3704 return Error(FileNumberLoc,
"file number already allocated");
3709bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3710 StringRef DirectiveName) {
3712 return parseTokenLoc(Loc) ||
3713 parseIntToken(FunctionId,
"expected function id") ||
3714 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3715 "expected function id within range [0, UINT_MAX)");
3718bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3720 return parseTokenLoc(Loc) ||
3721 parseIntToken(FileNumber,
"expected file number") ||
3722 check(FileNumber < 1, Loc,
3723 "file number less than one in '" + DirectiveName +
3725 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3726 "unassigned file number in '" + DirectiveName +
"' directive");
3733bool AsmParser::parseDirectiveCVFuncId() {
3734 SMLoc FunctionIdLoc = getTok().getLoc();
3737 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3740 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3741 return Error(FunctionIdLoc,
"function id already allocated");
3754bool AsmParser::parseDirectiveCVInlineSiteId() {
3755 SMLoc FunctionIdLoc = getTok().getLoc();
3763 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3768 getTok().getIdentifier() !=
"within"),
3769 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3774 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3779 getTok().getIdentifier() !=
"inlined_at"),
3780 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3786 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3787 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3792 IACol = getTok().getIntVal();
3799 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3800 IALine, IACol, FunctionIdLoc))
3801 return Error(FunctionIdLoc,
"function id already allocated");
3813bool AsmParser::parseDirectiveCVLoc() {
3814 SMLoc DirectiveLoc = getTok().getLoc();
3815 int64_t FunctionId, FileNumber;
3816 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3817 parseCVFileId(FileNumber,
".cv_loc"))
3820 int64_t LineNumber = 0;
3822 LineNumber = getTok().getIntVal();
3824 return TokError(
"line number less than zero in '.cv_loc' directive");
3828 int64_t ColumnPos = 0;
3830 ColumnPos = getTok().getIntVal();
3832 return TokError(
"column position less than zero in '.cv_loc' directive");
3836 bool PrologueEnd =
false;
3837 uint64_t IsStmt = 0;
3839 auto parseOp = [&]() ->
bool {
3841 SMLoc Loc = getTok().getLoc();
3842 if (parseIdentifier(Name))
3843 return TokError(
"unexpected token in '.cv_loc' directive");
3844 if (Name ==
"prologue_end")
3846 else if (Name ==
"is_stmt") {
3847 Loc = getTok().getLoc();
3848 const MCExpr *
Value;
3849 if (parseExpression(
Value))
3854 IsStmt = MCE->getValue();
3857 return Error(Loc,
"is_stmt value not 0 or 1");
3859 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3864 if (parseMany(parseOp,
false ))
3867 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3868 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3875bool AsmParser::parseDirectiveCVLinetable() {
3878 SMLoc Loc = getTok().getLoc();
3879 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3880 parseTokenLoc(Loc) ||
3881 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
3882 parseComma() || parseTokenLoc(Loc) ||
3883 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
3886 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3892bool AsmParser::parseDirectiveCVInlineLinetable() {
3893 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3895 SMLoc Loc = getTok().getLoc();
3896 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3897 parseTokenLoc(Loc) ||
3898 parseIntToken(SourceFileId,
"expected SourceField") ||
3899 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
3900 parseTokenLoc(Loc) ||
3901 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
3902 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
3903 parseTokenLoc(Loc) ||
3904 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
3905 parseTokenLoc(Loc) ||
3906 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
3912 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3913 SourceLineNum, FnStartSym,
3918void AsmParser::initializeCVDefRangeTypeMap() {
3919 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
3920 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
3921 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
3922 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
3927bool AsmParser::parseDirectiveCVDefRange() {
3929 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
3931 Loc = getLexer().getLoc();
3934 return Error(Loc,
"expected identifier in directive");
3936 Loc = getLexer().getLoc();
3939 return Error(Loc,
"expected identifier in directive");
3941 Ranges.push_back({GapStartSym, GapEndSym});
3944 StringRef CVDefRangeTypeStr;
3947 "expected comma before def_range type in .cv_def_range directive") ||
3948 parseIdentifier(CVDefRangeTypeStr))
3949 return Error(Loc,
"expected def_range type in directive");
3952 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
3953 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
3955 : CVTypeIt->getValue();
3957 case CVDR_DEFRANGE_REGISTER: {
3959 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
3960 ".cv_def_range directive") ||
3961 parseAbsoluteExpression(DRRegister))
3962 return Error(Loc,
"expected register number");
3964 codeview::DefRangeRegisterHeader DRHdr;
3967 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
3970 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
3973 "expected comma before offset in .cv_def_range directive") ||
3974 parseAbsoluteExpression(DROffset))
3975 return Error(Loc,
"expected offset value");
3977 codeview::DefRangeFramePointerRelHeader DRHdr;
3979 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
3982 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
3984 int64_t DROffsetInParent;
3985 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
3986 ".cv_def_range directive") ||
3987 parseAbsoluteExpression(DRRegister))
3988 return Error(Loc,
"expected register number");
3990 "expected comma before offset in .cv_def_range directive") ||
3991 parseAbsoluteExpression(DROffsetInParent))
3992 return Error(Loc,
"expected offset value");
3994 codeview::DefRangeSubfieldRegisterHeader DRHdr;
3998 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4001 case CVDR_DEFRANGE_REGISTER_REL: {
4004 int64_t DRBasePointerOffset;
4005 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4006 ".cv_def_range directive") ||
4007 parseAbsoluteExpression(DRRegister))
4008 return Error(Loc,
"expected register value");
4011 "expected comma before flag value in .cv_def_range directive") ||
4012 parseAbsoluteExpression(DRFlags))
4013 return Error(Loc,
"expected flag value");
4014 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4015 "in .cv_def_range directive") ||
4016 parseAbsoluteExpression(DRBasePointerOffset))
4017 return Error(Loc,
"expected base pointer offset value");
4019 codeview::DefRangeRegisterRelHeader DRHdr;
4021 DRHdr.
Flags = DRFlags;
4023 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4027 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4034bool AsmParser::parseDirectiveCVString() {
4036 if (checkForValidSection() || parseEscapedString(
Data))
4040 std::pair<StringRef, unsigned> Insertion =
4041 getCVContext().addToStringTable(
Data);
4042 getStreamer().emitInt32(Insertion.second);
4048bool AsmParser::parseDirectiveCVStringTable() {
4049 getStreamer().emitCVStringTableDirective();
4055bool AsmParser::parseDirectiveCVFileChecksums() {
4056 getStreamer().emitCVFileChecksumsDirective();
4062bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4064 if (parseIntToken(FileNo))
4068 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4074bool AsmParser::parseDirectiveCVFPOData() {
4075 SMLoc DirLoc = getLexer().getLoc();
4078 return TokError(
"expected symbol name");
4081 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4087bool AsmParser::parseDirectiveCFISections() {
4091 bool SFrame =
false;
4095 if (parseIdentifier(Name))
4096 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4097 if (Name ==
".eh_frame")
4099 else if (Name ==
".debug_frame")
4101 else if (Name ==
".sframe")
4109 getStreamer().emitCFISections(EH,
Debug, SFrame);
4115bool AsmParser::parseDirectiveCFIStartProc() {
4116 CFIStartProcLoc = StartTokLoc;
4120 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4121 "unexpected token") ||
4131 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4137bool AsmParser::parseDirectiveCFIEndProc() {
4138 CFIStartProcLoc = std::nullopt;
4143 getStreamer().emitCFIEndProc();
4148bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4149 SMLoc DirectiveLoc) {
4153 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4157 return parseAbsoluteExpression(
Register);
4164bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4166 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4167 parseAbsoluteExpression(
Offset) || parseEOL())
4176bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4178 if (parseAbsoluteExpression(
Offset) || parseEOL())
4181 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4187bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4188 int64_t Register1 = 0, Register2 = 0;
4189 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4190 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4193 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4199bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4202 getStreamer().emitCFIWindowSave(DirectiveLoc);
4208bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4209 int64_t Adjustment = 0;
4210 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4213 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4219bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4221 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4224 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4230bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4232 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4233 parseAbsoluteExpression(
Offset) || parseComma() ||
4244bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4248 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4249 parseAbsoluteExpression(
Offset) || parseEOL())
4258bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4261 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4262 parseAbsoluteExpression(
Offset) || parseEOL())
4270 if (Encoding & ~0xff)
4276 const unsigned Format = Encoding & 0xf;
4283 const unsigned Application = Encoding & 0x70;
4295bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4296 int64_t Encoding = 0;
4297 if (parseAbsoluteExpression(Encoding))
4305 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4309 getStreamer().emitCFIPersonality(Sym, Encoding);
4311 getStreamer().emitCFILsda(Sym, Encoding);
4317bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4320 getStreamer().emitCFIRememberState(DirectiveLoc);
4326bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4329 getStreamer().emitCFIRestoreState(DirectiveLoc);
4335bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4338 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4341 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4347bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4349 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4352 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4358bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4361 if (parseAbsoluteExpression(CurrValue))
4364 Values.push_back((uint8_t)CurrValue);
4369 if (parseAbsoluteExpression(CurrValue))
4372 Values.push_back((uint8_t)CurrValue);
4375 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4381bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4383 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4385 getStreamer().emitCFIReturnColumn(
Register);
4391bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4395 getStreamer().emitCFISignalFrame();
4401bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4404 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4407 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4413bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4416 if (parseIdentifier(Name))
4417 return TokError(
"expected identifier");
4420 getStreamer().emitCFILabelDirective(Loc, Name);
4426bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4430 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4431 parseAbsoluteExpression(
Offset) || parseEOL())
4441bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4444 AltMacroMode = (Directive ==
".altmacro");
4451bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4454 setMacrosEnabled(Directive ==
".macros_on");
4460bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4462 if (parseIdentifier(Name))
4463 return TokError(
"expected identifier in '.macro' directive");
4472 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4474 "' should be the last parameter");
4478 return TokError(
"expected identifier in '.macro' directive");
4481 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4483 return TokError(
"macro '" + Name +
"' has multiple parameters"
4492 QualLoc = Lexer.
getLoc();
4493 if (parseIdentifier(Qualifier))
4494 return Error(QualLoc,
"missing parameter qualifier for "
4495 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4497 if (Qualifier ==
"req")
4499 else if (Qualifier ==
"vararg")
4502 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4503 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4511 ParamLoc = Lexer.
getLoc();
4512 if (parseMacroArgument(
Parameter.Value,
false ))
4516 Warning(ParamLoc,
"pointless default value for required parameter "
4517 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4530 AsmToken EndToken, StartToken = getTok();
4531 unsigned MacroDepth = 0;
4541 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4546 if (getTok().getIdentifier() ==
".endm" ||
4547 getTok().getIdentifier() ==
".endmacro") {
4548 if (MacroDepth == 0) {
4549 EndToken = getTok();
4552 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4559 }
else if (getTok().getIdentifier() ==
".macro") {
4565 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4569 eatToEndOfStatement();
4573 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4578 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4579 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4580 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4601void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4607 if (NParameters == 0)
4610 bool NamedParametersFound =
false;
4611 bool PositionalParametersFound =
false;
4616 while (!Body.
empty()) {
4618 std::size_t End = Body.
size(), Pos = 0;
4619 for (; Pos != End; ++Pos) {
4622 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4626 if (Body[Pos] !=
'$' || Pos + 1 == End)
4628 char Next = Body[Pos + 1];
4630 isdigit(
static_cast<unsigned char>(
Next)))
4638 if (Body[Pos] ==
'$') {
4639 switch (Body[Pos + 1]) {
4646 PositionalParametersFound =
true;
4651 PositionalParametersFound =
true;
4657 unsigned I = Pos + 1;
4661 const char *Begin = Body.
data() + Pos + 1;
4662 StringRef
Argument(Begin,
I - (Pos + 1));
4665 if (Parameters[Index].Name == Argument)
4668 if (Index == NParameters) {
4669 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4675 NamedParametersFound =
true;
4683 if (!NamedParametersFound && PositionalParametersFound)
4684 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4685 "used in macro body, possible positional parameter "
4686 "found in body which will have no effect");
4691bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4695 if (!isInsideMacroInstantiation())
4696 return TokError(
"unexpected '" + Directive +
"' in file, "
4697 "no current macro definition");
4700 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4701 TheCondState = TheCondStack.back();
4702 TheCondStack.pop_back();
4712bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4714 return TokError(
"unexpected token in '" + Directive +
"' directive");
4718 if (isInsideMacroInstantiation()) {
4725 return TokError(
"unexpected '" + Directive +
"' in file, "
4726 "no current macro definition");
4731bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4734 if (parseTokenLoc(Loc) ||
4735 check(parseIdentifier(Name), Loc,
4736 "expected identifier in '.purgem' directive") ||
4741 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4745 <<
"Un-defining macro: " << Name <<
"\n");
4751bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4752 SMLoc NumBytesLoc = Lexer.
getLoc();
4753 const MCExpr *NumBytes;
4754 if (checkForValidSection() || parseExpression(NumBytes))
4757 int64_t FillExpr = 0;
4759 if (parseAbsoluteExpression(FillExpr))
4765 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4772bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
4773 SMLoc NumValuesLoc = Lexer.
getLoc();
4775 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4778 if (NumValues < 0) {
4779 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4786 const MCExpr *
Value;
4787 SMLoc ExprLoc = getLexer().getLoc();
4788 if (parseExpression(
Value))
4794 uint64_t IntValue = MCE->getValue();
4796 return Error(ExprLoc,
"literal value out of range for directive");
4797 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4798 getStreamer().emitIntValue(IntValue,
Size);
4800 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4801 getStreamer().emitValue(
Value,
Size, ExprLoc);
4809bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
4810 SMLoc NumValuesLoc = Lexer.
getLoc();
4812 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4815 if (NumValues < 0) {
4816 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4824 if (parseRealValue(Semantics, AsInt) || parseEOL())
4827 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4836bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
4837 SMLoc NumValuesLoc = Lexer.
getLoc();
4839 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4843 if (NumValues < 0) {
4844 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4848 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4849 getStreamer().emitFill(
Size, 0);
4856bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4857 if (checkForValidSection())
4860 auto parseOp = [&]() ->
bool {
4861 const MCExpr *
Value;
4862 if (parseExpression(
Value))
4865 getStreamer().emitSLEB128Value(
Value);
4867 getStreamer().emitULEB128Value(
Value);
4871 return parseMany(parseOp);
4876bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4877 auto parseOp = [&]() ->
bool {
4879 SMLoc Loc = getTok().getLoc();
4880 if (parseIdentifier(Name))
4881 return Error(Loc,
"expected identifier");
4883 if (discardLTOSymbol(Name))
4891 return Error(Loc,
"non-local symbol required");
4893 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
4894 return Error(Loc,
"unable to emit symbol attribute");
4898 return parseMany(parseOp);
4903bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4904 if (checkForValidSection())
4907 SMLoc IDLoc = getLexer().getLoc();
4910 return TokError(
"expected identifier in directive");
4916 SMLoc SizeLoc = getLexer().getLoc();
4917 if (parseAbsoluteExpression(
Size))
4920 int64_t Pow2Alignment = 0;
4921 SMLoc Pow2AlignmentLoc;
4924 Pow2AlignmentLoc = getLexer().getLoc();
4925 if (parseAbsoluteExpression(Pow2Alignment))
4930 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4936 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4937 Pow2Alignment =
Log2_64(Pow2Alignment);
4947 return Error(SizeLoc,
"size must be non-negative");
4951 return Error(IDLoc,
"invalid symbol redefinition");
4955 getStreamer().emitLocalCommonSymbol(Sym,
Size,
4956 Align(1ULL << Pow2Alignment));
4960 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
4966bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
4967 StringRef Str = parseStringToEndOfStatement();
4972 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
4975 return Error(DirectiveLoc,
4976 ".abort '" + Str +
"' detected. Assembly stopping");
4981bool AsmParser::parseDirectiveInclude() {
4984 SMLoc IncludeLoc = getTok().getLoc();
4987 "expected string in '.include' directive") ||
4988 parseEscapedString(Filename) ||
4990 "unexpected token in '.include' directive") ||
4993 check(enterIncludeFile(Filename), IncludeLoc,
4994 "Could not find include file '" + Filename +
"'"))
5002bool AsmParser::parseDirectiveIncbin() {
5005 SMLoc IncbinLoc = getTok().getLoc();
5007 "expected string in '.incbin' directive") ||
5008 parseEscapedString(Filename))
5012 const MCExpr *
Count =
nullptr;
5013 SMLoc SkipLoc, CountLoc;
5018 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5022 CountLoc = getTok().getLoc();
5023 if (parseExpression(
Count))
5031 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5035 if (processIncbinFile(Filename, Skip,
Count, CountLoc))
5036 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
5042bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5043 TheCondStack.push_back(TheCondState);
5045 if (TheCondState.
Ignore) {
5046 eatToEndOfStatement();
5049 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5059 ExprValue = ExprValue == 0;
5062 ExprValue = ExprValue >= 0;
5065 ExprValue = ExprValue > 0;
5068 ExprValue = ExprValue <= 0;
5071 ExprValue = ExprValue < 0;
5075 TheCondState.
CondMet = ExprValue;
5084bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5085 TheCondStack.push_back(TheCondState);
5088 if (TheCondState.
Ignore) {
5089 eatToEndOfStatement();
5091 StringRef Str = parseStringToEndOfStatement();
5096 TheCondState.
CondMet = ExpectBlank == Str.empty();
5106bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5107 TheCondStack.push_back(TheCondState);
5110 if (TheCondState.
Ignore) {
5111 eatToEndOfStatement();
5113 StringRef Str1 = parseStringToComma();
5118 StringRef Str2 = parseStringToEndOfStatement();
5132bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5133 TheCondStack.push_back(TheCondState);
5136 if (TheCondState.
Ignore) {
5137 eatToEndOfStatement();
5141 return TokError(
"expected string parameter for '.ifeqs' directive");
5142 return TokError(
"expected string parameter for '.ifnes' directive");
5145 StringRef String1 = getTok().getStringContents();
5151 "expected comma after first string for '.ifeqs' directive");
5153 "expected comma after first string for '.ifnes' directive");
5160 return TokError(
"expected string parameter for '.ifeqs' directive");
5161 return TokError(
"expected string parameter for '.ifnes' directive");
5164 StringRef String2 = getTok().getStringContents();
5167 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5176bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5178 TheCondStack.push_back(TheCondState);
5181 if (TheCondState.
Ignore) {
5182 eatToEndOfStatement();
5184 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5202bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5205 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5206 " .if or an .elseif");
5209 bool LastIgnoreState =
false;
5210 if (!TheCondStack.empty())
5211 LastIgnoreState = TheCondStack.back().Ignore;
5212 if (LastIgnoreState || TheCondState.
CondMet) {
5213 TheCondState.
Ignore =
true;
5214 eatToEndOfStatement();
5217 if (parseAbsoluteExpression(ExprValue))
5223 TheCondState.
CondMet = ExprValue;
5232bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5238 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5239 " an .if or an .elseif");
5241 bool LastIgnoreState =
false;
5242 if (!TheCondStack.empty())
5243 LastIgnoreState = TheCondStack.back().Ignore;
5244 if (LastIgnoreState || TheCondState.
CondMet)
5245 TheCondState.
Ignore =
true;
5247 TheCondState.
Ignore =
false;
5254bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5267bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5268 if (!TheCondStack.empty()) {
5269 if (TheCondStack.back().Ignore) {
5270 eatToEndOfStatement();
5276 return Error(L,
".err encountered");
5278 StringRef Message =
".error directive invoked in source file";
5281 return TokError(
".error argument must be a string");
5283 Message = getTok().getStringContents();
5287 return Error(L, Message);
5292bool AsmParser::parseDirectiveWarning(SMLoc L) {
5293 if (!TheCondStack.empty()) {
5294 if (TheCondStack.back().Ignore) {
5295 eatToEndOfStatement();
5300 StringRef Message =
".warning directive invoked in source file";
5304 return TokError(
".warning argument must be a string");
5306 Message = getTok().getStringContents();
5317bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5322 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5324 if (!TheCondStack.empty()) {
5325 TheCondState = TheCondStack.back();
5326 TheCondStack.pop_back();
5332void AsmParser::initializeDirectiveKindMap() {
5339 DirectiveKindMap[
".set"] = DK_SET;
5340 DirectiveKindMap[
".equ"] = DK_EQU;
5341 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5342 DirectiveKindMap[
".ascii"] = DK_ASCII;
5343 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5344 DirectiveKindMap[
".string"] = DK_STRING;
5345 DirectiveKindMap[
".byte"] = DK_BYTE;
5346 DirectiveKindMap[
".short"] = DK_SHORT;
5347 DirectiveKindMap[
".value"] = DK_VALUE;
5348 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5349 DirectiveKindMap[
".long"] = DK_LONG;
5350 DirectiveKindMap[
".int"] = DK_INT;
5351 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5352 DirectiveKindMap[
".quad"] = DK_QUAD;
5353 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5354 DirectiveKindMap[
".octa"] = DK_OCTA;
5355 DirectiveKindMap[
".single"] = DK_SINGLE;
5356 DirectiveKindMap[
".float"] = DK_FLOAT;
5357 DirectiveKindMap[
".double"] = DK_DOUBLE;
5358 DirectiveKindMap[
".align"] = DK_ALIGN;
5359 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5360 DirectiveKindMap[
".balign"] = DK_BALIGN;
5361 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5362 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5363 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5364 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5365 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5366 DirectiveKindMap[
".org"] = DK_ORG;
5367 DirectiveKindMap[
".fill"] = DK_FILL;
5368 DirectiveKindMap[
".zero"] = DK_ZERO;
5369 DirectiveKindMap[
".extern"] = DK_EXTERN;
5370 DirectiveKindMap[
".globl"] = DK_GLOBL;
5371 DirectiveKindMap[
".global"] = DK_GLOBAL;
5372 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5373 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5374 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5375 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5376 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5377 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5378 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5379 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5380 DirectiveKindMap[
".cold"] = DK_COLD;
5381 DirectiveKindMap[
".comm"] = DK_COMM;
5382 DirectiveKindMap[
".common"] = DK_COMMON;
5383 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5384 DirectiveKindMap[
".abort"] = DK_ABORT;
5385 DirectiveKindMap[
".include"] = DK_INCLUDE;
5386 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5387 DirectiveKindMap[
".code16"] = DK_CODE16;
5388 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5389 DirectiveKindMap[
".rept"] = DK_REPT;
5390 DirectiveKindMap[
".rep"] = DK_REPT;
5391 DirectiveKindMap[
".irp"] = DK_IRP;
5392 DirectiveKindMap[
".irpc"] = DK_IRPC;
5393 DirectiveKindMap[
".endr"] = DK_ENDR;
5394 DirectiveKindMap[
".if"] = DK_IF;
5395 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5396 DirectiveKindMap[
".ifge"] = DK_IFGE;
5397 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5398 DirectiveKindMap[
".ifle"] = DK_IFLE;
5399 DirectiveKindMap[
".iflt"] = DK_IFLT;
5400 DirectiveKindMap[
".ifne"] = DK_IFNE;
5401 DirectiveKindMap[
".ifb"] = DK_IFB;
5402 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5403 DirectiveKindMap[
".ifc"] = DK_IFC;
5404 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5405 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5406 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5407 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5408 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5409 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5410 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5411 DirectiveKindMap[
".else"] = DK_ELSE;
5412 DirectiveKindMap[
".end"] = DK_END;
5413 DirectiveKindMap[
".endif"] = DK_ENDIF;
5414 DirectiveKindMap[
".skip"] = DK_SKIP;
5415 DirectiveKindMap[
".space"] = DK_SPACE;
5416 DirectiveKindMap[
".file"] = DK_FILE;
5417 DirectiveKindMap[
".line"] = DK_LINE;
5418 DirectiveKindMap[
".loc"] = DK_LOC;
5419 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5420 DirectiveKindMap[
".stabs"] = DK_STABS;
5421 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5422 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5423 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5424 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5425 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5426 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5427 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5428 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5429 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5430 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5431 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5432 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5433 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5434 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5435 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5436 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5437 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5438 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5439 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5440 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5441 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5442 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5443 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5444 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5445 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5446 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5447 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5448 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5449 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5450 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5451 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5452 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5453 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5454 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5455 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5456 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5457 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5458 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5459 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5460 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5461 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5462 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5463 DirectiveKindMap[
".macro"] = DK_MACRO;
5464 DirectiveKindMap[
".exitm"] = DK_EXITM;
5465 DirectiveKindMap[
".endm"] = DK_ENDM;
5466 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5467 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5468 DirectiveKindMap[
".err"] = DK_ERR;
5469 DirectiveKindMap[
".error"] = DK_ERROR;
5470 DirectiveKindMap[
".warning"] = DK_WARNING;
5471 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5472 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5473 DirectiveKindMap[
".reloc"] = DK_RELOC;
5474 DirectiveKindMap[
".dc"] = DK_DC;
5475 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5476 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5477 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5478 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5479 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5480 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5481 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5482 DirectiveKindMap[
".dcb"] = DK_DCB;
5483 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5484 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5485 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5486 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5487 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5488 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5489 DirectiveKindMap[
".ds"] = DK_DS;
5490 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5491 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5492 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5493 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5494 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5495 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5496 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5497 DirectiveKindMap[
".print"] = DK_PRINT;
5498 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5499 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5500 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5501 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5502 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5503 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5506MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5507 AsmToken EndToken, StartToken = getTok();
5509 unsigned NestLevel = 0;
5513 printError(DirectiveLoc,
"no matching '.endr' in definition");
5518 StringRef Ident = getTok().getIdentifier();
5519 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5522 }
else if (Ident ==
".endr") {
5523 if (NestLevel == 0) {
5524 EndToken = getTok();
5528 printError(getTok().getLoc(),
"expected newline");
5536 eatToEndOfStatement();
5541 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5545 return &MacroLikeBodies.back();
5548void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5549 raw_svector_ostream &OS) {
5552 std::unique_ptr<MemoryBuffer> Instantiation =
5557 MacroInstantiation *
MI =
new MacroInstantiation{
5558 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5559 ActiveMacros.push_back(
MI);
5569bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5570 const MCExpr *CountExpr;
5571 SMLoc CountLoc = getTok().getLoc();
5572 if (parseExpression(CountExpr))
5576 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5577 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5580 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5584 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5590 SmallString<256> Buf;
5591 raw_svector_ostream OS(Buf);
5594 if (expandMacro(OS, *M, {}, {},
false))
5597 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5604bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5606 MCAsmMacroArguments
A;
5607 if (check(parseIdentifier(
Parameter.Name),
5608 "expected identifier in '.irp' directive") ||
5609 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5613 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5619 SmallString<256> Buf;
5620 raw_svector_ostream OS(Buf);
5622 for (
const MCAsmMacroArgument &Arg :
A) {
5625 if (expandMacro(OS, *M, Parameter, Arg,
true))
5629 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5636bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5638 MCAsmMacroArguments
A;
5640 if (check(parseIdentifier(
Parameter.Name),
5641 "expected identifier in '.irpc' directive") ||
5642 parseComma() || parseMacroArguments(
nullptr,
A))
5645 if (
A.size() != 1 ||
A.front().size() != 1)
5646 return TokError(
"unexpected token in '.irpc' directive");
5651 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5657 SmallString<256> Buf;
5658 raw_svector_ostream OS(Buf);
5661 :
A[0][0].getString();
5662 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5663 MCAsmMacroArgument Arg;
5668 if (expandMacro(OS, *M, Parameter, Arg,
true))
5672 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5677bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5678 if (ActiveMacros.empty())
5679 return TokError(
"unmatched '.endr' directive");
5689bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &
Info,
5691 const MCExpr *
Value;
5692 SMLoc ExprLoc = getLexer().getLoc();
5693 if (parseExpression(
Value))
5697 return Error(ExprLoc,
"unexpected expression in _emit");
5698 uint64_t IntValue = MCE->
getValue();
5700 return Error(ExprLoc,
"literal value out of range for directive");
5706bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &
Info) {
5707 const MCExpr *
Value;
5708 SMLoc ExprLoc = getLexer().getLoc();
5709 if (parseExpression(
Value))
5713 return Error(ExprLoc,
"unexpected expression in align");
5714 uint64_t IntValue = MCE->
getValue();
5716 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5722bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5723 const AsmToken StrTok = getTok();
5726 return Error(DirectiveLoc,
"expected double quoted string after .print");
5733bool AsmParser::parseDirectiveAddrsig() {
5736 getStreamer().emitAddrsig();
5740bool AsmParser::parseDirectiveAddrsigSym() {
5742 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
5744 getStreamer().emitAddrsigSym(Sym);
5748bool AsmParser::parseDirectivePseudoProbe() {
5754 if (parseIntToken(
Guid))
5756 if (parseIntToken(Index))
5758 if (parseIntToken(
Type))
5760 if (parseIntToken(Attr))
5772 int64_t CallerGuid = 0;
5774 CallerGuid = getTok().getIntVal();
5782 int64_t CallerProbeId = 0;
5784 CallerProbeId = getTok().getIntVal();
5794 if (parseIdentifier(FnName))
5795 return Error(getLexer().getLoc(),
"expected identifier");
5801 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
5802 InlineStack, FnSym);
5811bool AsmParser::parseDirectiveLTODiscard() {
5812 auto ParseOp = [&]() ->
bool {
5814 SMLoc Loc = getTok().getLoc();
5815 if (parseIdentifier(Name))
5816 return Error(Loc,
"expected identifier");
5817 LTODiscardSymbols.
insert(Name);
5821 LTODiscardSymbols.
clear();
5822 return parseMany(ParseOp);
5848bool AsmParser::parseMSInlineAsm(
5849 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
5850 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5851 SmallVectorImpl<std::string> &Constraints,
5852 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
5853 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
5854 SmallVector<void *, 4> InputDecls;
5855 SmallVector<void *, 4> OutputDecls;
5858 SmallVector<std::string, 4> InputConstraints;
5859 SmallVector<std::string, 4> OutputConstraints;
5868 unsigned InputIdx = 0;
5869 unsigned OutputIdx = 0;
5872 if (parseCurlyBlockScope(AsmStrRewrites))
5875 ParseStatementInfo
Info(&AsmStrRewrites);
5876 bool StatementErr = parseStatement(
Info, &SI);
5878 if (StatementErr ||
Info.ParseError) {
5880 printPendingErrors();
5885 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5887 if (
Info.Opcode == ~0U)
5893 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
5894 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
5898 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
5899 unsigned NumDefs =
Desc.getNumDefs();
5908 if (SymName.
empty())
5916 if (Operand.
isImm()) {
5924 bool isOutput = (i == 1) &&
Desc.mayStore();
5931 OutputConstraints.
push_back((
"=" + Constraint).str());
5938 if (
Desc.operands()[i - 1].isBranchTarget())
5952 NumOutputs = OutputDecls.
size();
5953 NumInputs = InputDecls.
size();
5958 Clobbers.
assign(ClobberRegs.
size(), std::string());
5959 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
5960 raw_string_ostream OS(Clobbers[
I]);
5965 if (NumOutputs || NumInputs) {
5966 unsigned NumExprs = NumOutputs + NumInputs;
5967 OpDecls.resize(NumExprs);
5968 Constraints.
resize(NumExprs);
5969 for (
unsigned i = 0; i < NumOutputs; ++i) {
5970 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
5971 Constraints[i] = OutputConstraints[i];
5973 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
5974 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
5975 Constraints[
j] = InputConstraints[i];
5980 std::string AsmStringIR;
5981 raw_string_ostream OS(AsmStringIR);
5982 StringRef ASMString =
5984 const char *AsmStart = ASMString.
begin();
5985 const char *AsmEnd = ASMString.
end();
5987 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
5988 const AsmRewrite &AR = *
I;
5995 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
5998 if (
unsigned Len = Loc - AsmStart)
5999 OS << StringRef(AsmStart, Len);
6003 AsmStart = Loc + AR.
Len;
6007 unsigned AdditionalSkip = 0;
6029 size_t OffsetLen = OffsetName.
size();
6030 auto rewrite_it = std::find_if(
6031 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6032 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6033 (FusingAR.Kind == AOK_Input ||
6034 FusingAR.Kind == AOK_CallInput);
6036 if (rewrite_it == AsmStrRewrites.
end()) {
6037 OS <<
"offset " << OffsetName;
6039 OS <<
"${" << InputIdx++ <<
":P}";
6040 rewrite_it->Done =
true;
6042 OS <<
'$' << InputIdx++;
6043 rewrite_it->Done =
true;
6056 OS <<
"${" << InputIdx++ <<
":P}";
6058 OS <<
'$' << InputIdx++;
6061 OS <<
"${" << InputIdx++ <<
":P}";
6065 OS <<
"${" << OutputIdx++ <<
":P}";
6067 OS <<
'$' << OutputIdx++;
6072 case 8: OS <<
"byte ptr ";
break;
6073 case 16: OS <<
"word ptr ";
break;
6074 case 32: OS <<
"dword ptr ";
break;
6075 case 64: OS <<
"qword ptr ";
break;
6076 case 80: OS <<
"xword ptr ";
break;
6077 case 128: OS <<
"xmmword ptr ";
break;
6078 case 256: OS <<
"ymmword ptr ";
break;
6088 if (
getContext().getAsmInfo()->getAlignmentIsInBytes())
6093 unsigned Val = AR.
Val;
6095 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6096 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6108 AsmStart = Loc + AR.
Len + AdditionalSkip;
6112 if (AsmStart != AsmEnd)
6113 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6115 AsmString = std::move(AsmStringIR);
6119bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &
Info,
6120 MCAsmParserSemaCallback *SI) {
6121 AsmToken LabelTok = getTok();
6122 SMLoc LabelLoc = LabelTok.
getLoc();
6125 if (parseIdentifier(LabelVal))
6126 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6131 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6140 return Error(LabelLoc,
6141 "Cannot have just a label for an HLASM inline asm statement");
6151 if (enabledGenDwarfForAssembly())
6158bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &
Info,
6159 MCAsmParserSemaCallback *SI) {
6160 AsmToken OperationEntryTok = Lexer.
getTok();
6161 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6162 StringRef OperationEntryVal;
6165 if (parseIdentifier(OperationEntryVal))
6166 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6172 return parseAndMatchAndEmitTargetInstruction(
6173 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6176bool HLASMAsmParser::parseStatement(ParseStatementInfo &
Info,
6177 MCAsmParserSemaCallback *SI) {
6178 assert(!hasPendingError() &&
"parseStatement started with pending error");
6181 bool ShouldParseAsHLASMLabel =
false;
6190 ShouldParseAsHLASMLabel =
true;
6196 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6197 getTok().getString().
front() ==
'\n')
6212 if (getTok().getString().
front() ==
'\n' ||
6213 getTok().getString().
front() ==
'\r') {
6222 if (ShouldParseAsHLASMLabel) {
6225 if (parseAsHLASMLabel(
Info, SI)) {
6228 eatToEndOfStatement();
6233 return parseAsMachineInstruction(
Info, SI);
6237namespace MCParserUtils {
6246 return Parser.
TokError(
"missing expression");
6252 return Parser.
Error(
6253 EqualLoc,
"relocation specifier not permitted in symbol equating");
6261 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6267 }
else if (Name ==
".") {
6285 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6286 return new HLASMAsmParser(SM,
C, Out, MAI, CB);
6288 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")
Analysis containing CSE Info
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
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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)
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
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
virtual ~MCAsmParserSemaCallback()
Generic assembler parser interface, for use by target specific assembly parsers.
bool Error(SMLoc L, const Twine &Msg, SMRange Range={})
Return an error at the location L, with the message Msg.
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
bool parseAtSpecifier(const MCExpr *&Res, SMLoc &EndLoc)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
const MCExpr * applySpecifier(const MCExpr *E, uint32_t Variant)
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
bool TokError(const Twine &Msg, SMRange Range={})
Report an error at the current lexer location.
MCStreamer & getStreamer()
MCTargetAsmParser & getTargetParser() const
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
@ AShr
Arithmetic shift right.
@ LShr
Logical shift right.
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
@ Xor
Bitwise exclusive or.
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
@ NE
Inequality comparison.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
void * allocate(unsigned Size, unsigned Align=8)
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
bool getGenDwarfForAssembly()
void setGenDwarfForAssembly(bool Value)
void setDwarfVersion(uint16_t v)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_ABI MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
LLVM_ABI MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
uint16_t getDwarfVersion() const
const MCAsmInfo * getAsmInfo() const
LLVM_ABI MCSymbol * cloneSymbol(MCSymbol &Sym)
Clone a symbol for the .set directive, replacing it in the symbol table.
LLVM_ABI MCSymbol * parseSymbol(const Twine &Name)
Variant of getOrCreateSymbol that handles backslash-escaped symbols.
LLVM_ABI MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
virtual void printRegName(raw_ostream &OS, MCRegister Reg)
Print the assembler register name.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
virtual bool isMemUseUpRegs() const
isMemUseUpRegs - Is memory operand use up regs, for example, intel MS inline asm may use ARR[baseReg ...
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label?
virtual MCRegister getReg() const =0
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable,...
virtual StringRef getSymName()
virtual bool isImm() const =0
isImm - Is this an immediate operand?
unsigned getMCOperandNum()
StringRef getConstraint()
virtual void * getOpDecl()
void setBeginSymbol(MCSymbol *Sym)
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI)
Create the default sections and set the initial one.
void setStartTokLocPtr(const SMLoc *Loc)
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
MCTargetStreamer * getTargetStreamer()
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
MCAsmParserExtension * createCOFFAsmParser()
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.
MCAsmParserExtension * createXCOFFAsmParser()
MCAsmParserExtension * createGOFFAsmParser()
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)
MCAsmParserExtension * createWasmAsmParser()
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.
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.
MCAsmParserExtension * createELFAsmParser()
MCAsmParserExtension * createDarwinAsmParser()
@ 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.