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 = std::nullopt)
override;
232 bool Warning(SMLoc L,
const Twine &Msg,
233 SMRange
Range = std::nullopt)
override;
234 bool printError(SMLoc L,
const Twine &Msg,
235 SMRange
Range = std::nullopt)
override;
237 const AsmToken &Lex()
override;
239 void setParsingMSInlineAsm(
bool V)
override {
240 ParsingMSInlineAsm =
V;
243 Lexer.setLexMasmIntegers(V);
245 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
247 bool discardLTOSymbol(StringRef Name)
const override {
248 return LTODiscardSymbols.contains(Name);
251 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
253 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
254 SmallVectorImpl<std::string> &Constraints,
255 SmallVectorImpl<std::string> &Clobbers,
256 const MCInstrInfo *MII, MCInstPrinter *IP,
257 MCAsmParserSemaCallback &SI)
override;
259 bool parseExpression(
const MCExpr *&Res);
260 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
261 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
262 AsmTypeInfo *TypeInfo)
override;
263 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
264 bool parseAbsoluteExpression(int64_t &Res)
override;
268 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
272 bool parseIdentifier(StringRef &Res)
override;
273 void eatToEndOfStatement()
override;
275 bool checkForValidSection()
override;
280 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
281 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
283 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
285 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
290 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
293 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
296 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
302 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
305 void handleMacroExit();
308 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
311 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
313 void printMacroInstantiations();
315 SMRange
Range = std::nullopt)
const {
322 bool enterIncludeFile(
const std::string &Filename);
326 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
327 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
335 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
340 StringRef parseStringToEndOfStatement()
override;
344 StringRef parseStringToComma();
346 enum class AssignmentKind {
353 bool parseAssignment(StringRef Name, AssignmentKind Kind);
358 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
359 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
360 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
362 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
364 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
365 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
435 DK_WEAK_DEF_CAN_BE_HIDDEN,
476 DK_CV_INLINE_SITE_ID,
479 DK_CV_INLINE_LINETABLE,
484 DK_CV_FILECHECKSUM_OFFSET,
490 DK_CFI_DEF_CFA_OFFSET,
491 DK_CFI_ADJUST_CFA_OFFSET,
492 DK_CFI_DEF_CFA_REGISTER,
493 DK_CFI_LLVM_DEF_ASPACE_CFA,
498 DK_CFI_REMEMBER_STATE,
499 DK_CFI_RESTORE_STATE,
503 DK_CFI_RETURN_COLUMN,
530 DK_LTO_SET_CONDITIONAL,
531 DK_CFI_MTE_TAGGED_FRAME,
538 StringMap<DirectiveKind> DirectiveKindMap;
541 enum CVDefRangeType {
543 CVDR_DEFRANGE_REGISTER,
544 CVDR_DEFRANGE_FRAMEPOINTER_REL,
545 CVDR_DEFRANGE_SUBFIELD_REGISTER,
546 CVDR_DEFRANGE_REGISTER_REL
551 StringMap<CVDefRangeType> CVDefRangeTypeMap;
554 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
555 bool parseDirectiveReloc(SMLoc DirectiveLoc);
556 bool parseDirectiveValue(StringRef IDVal,
558 bool parseDirectiveOctaValue(StringRef IDVal);
559 bool parseDirectiveRealValue(StringRef IDVal,
560 const fltSemantics &);
561 bool parseDirectiveFill();
562 bool parseDirectiveZero();
564 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
565 bool parseDirectiveOrg();
567 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
570 bool parseDirectiveFile(SMLoc DirectiveLoc);
571 bool parseDirectiveLine();
572 bool parseDirectiveLoc();
573 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
574 bool parseDirectiveStabs();
578 bool parseDirectiveCVFile();
579 bool parseDirectiveCVFuncId();
580 bool parseDirectiveCVInlineSiteId();
581 bool parseDirectiveCVLoc();
582 bool parseDirectiveCVLinetable();
583 bool parseDirectiveCVInlineLinetable();
584 bool parseDirectiveCVDefRange();
585 bool parseDirectiveCVString();
586 bool parseDirectiveCVStringTable();
587 bool parseDirectiveCVFileChecksums();
588 bool parseDirectiveCVFileChecksumOffset();
589 bool parseDirectiveCVFPOData();
592 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
593 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
594 bool parseDirectiveCFISections();
595 bool parseDirectiveCFIStartProc();
596 bool parseDirectiveCFIEndProc();
597 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
598 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
599 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
600 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
601 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
602 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
603 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
604 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
605 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
606 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
607 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
608 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
609 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
610 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
611 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
612 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
613 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
614 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
617 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
618 bool parseDirectiveExitMacro(StringRef Directive);
619 bool parseDirectiveEndMacro(StringRef Directive);
620 bool parseDirectiveMacro(SMLoc DirectiveLoc);
621 bool parseDirectiveMacrosOnOff(StringRef Directive);
623 bool parseDirectiveAltmacro(StringRef Directive);
626 bool parseDirectiveSpace(StringRef IDVal);
629 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
630 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
632 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
635 bool parseDirectiveLEB128(
bool Signed);
641 bool parseDirectiveComm(
bool IsLocal);
643 bool parseDirectiveAbort(SMLoc DirectiveLoc);
644 bool parseDirectiveInclude();
645 bool parseDirectiveIncbin();
648 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
650 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
652 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
654 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
656 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
657 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
658 bool parseDirectiveElse(SMLoc DirectiveLoc);
659 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
660 bool parseEscapedString(std::string &
Data)
override;
661 bool parseAngleBracketString(std::string &
Data)
override;
664 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
665 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
666 raw_svector_ostream &OS);
667 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
668 bool parseDirectiveIrp(SMLoc DirectiveLoc);
669 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
670 bool parseDirectiveEndr(SMLoc DirectiveLoc);
673 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &
Info,
677 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &
Info);
680 bool parseDirectiveEnd(SMLoc DirectiveLoc);
683 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
686 bool parseDirectiveWarning(SMLoc DirectiveLoc);
689 bool parseDirectivePrint(SMLoc DirectiveLoc);
692 bool parseDirectivePseudoProbe();
695 bool parseDirectiveLTODiscard();
698 bool parseDirectiveAddrsig();
699 bool parseDirectiveAddrsigSym();
701 void initializeDirectiveKindMap();
702 void initializeCVDefRangeTypeMap();
705class HLASMAsmParser final :
public AsmParser {
710 void lexLeadingSpaces() {
715 bool parseAsHLASMLabel(ParseStatementInfo &
Info, MCAsmParserSemaCallback *SI);
716 bool parseAsMachineInstruction(ParseStatementInfo &
Info,
717 MCAsmParserSemaCallback *SI);
720 HLASMAsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
721 const MCAsmInfo &MAI,
unsigned CB = 0)
722 : AsmParser(SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
723 Lexer.setSkipSpace(
false);
724 Lexer.setAllowHashInIdentifier(
true);
725 Lexer.setLexHLASMIntegers(
true);
726 Lexer.setLexHLASMStrings(
true);
729 ~HLASMAsmParser() { Lexer.setSkipSpace(
true); }
731 bool parseStatement(ParseStatementInfo &
Info,
732 MCAsmParserSemaCallback *SI)
override;
752 :
MCAsmParser(Ctx, Out, SM, MAI), CurBuffer(CB ? CB : SM.getMainFileID()),
753 MacrosEnabledFlag(
true) {
756 SavedDiagHandler =
SrcMgr.getDiagHandler();
757 SavedDiagContext =
SrcMgr.getDiagContext();
765 switch (Ctx.getObjectFileType()) {
766 case MCContext::IsCOFF:
767 PlatformParser.reset(createCOFFAsmParser());
769 case MCContext::IsMachO:
770 PlatformParser.reset(createDarwinAsmParser());
773 case MCContext::IsELF:
774 PlatformParser.reset(createELFAsmParser());
776 case MCContext::IsGOFF:
777 PlatformParser.reset(createGOFFAsmParser());
779 case MCContext::IsSPIRV:
781 "Need to implement createSPIRVAsmParser for SPIRV format.");
783 case MCContext::IsWasm:
784 PlatformParser.reset(createWasmAsmParser());
786 case MCContext::IsXCOFF:
787 PlatformParser.reset(createXCOFFAsmParser());
789 case MCContext::IsDXContainer:
790 report_fatal_error(
"DXContainer is not supported yet");
794 PlatformParser->Initialize(*
this);
795 initializeDirectiveKindMap();
796 initializeCVDefRangeTypeMap();
799AsmParser::~AsmParser() {
800 assert((HadError || ActiveMacros.empty()) &&
801 "Unexpected active macro instantiation!");
810void AsmParser::printMacroInstantiations() {
812 for (MacroInstantiation *M :
reverse(ActiveMacros))
814 "while in macro instantiation");
817void AsmParser::Note(SMLoc L,
const Twine &Msg, SMRange
Range) {
818 printPendingErrors();
820 printMacroInstantiations();
823bool AsmParser::Warning(SMLoc L,
const Twine &Msg, SMRange
Range) {
824 if(getTargetParser().getTargetOptions().MCNoWarn)
826 if (getTargetParser().getTargetOptions().MCFatalWarnings)
829 printMacroInstantiations();
833bool AsmParser::printError(SMLoc L,
const Twine &Msg, SMRange
Range) {
836 printMacroInstantiations();
840bool AsmParser::enterIncludeFile(
const std::string &Filename) {
841 std::string IncludedFile;
855bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
856 const MCExpr *
Count, SMLoc Loc) {
857 std::string IncludedFile;
868 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
869 return Error(Loc,
"expected absolute expression");
871 return Warning(Loc,
"negative count has no effect");
874 getStreamer().emitBytes(Bytes);
878void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
884const AsmToken &AsmParser::Lex() {
891 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
896 const AsmToken *tok = &Lexer.
Lex();
909 if (ParentIncludeLoc != SMLoc()) {
910 jumpToLoc(ParentIncludeLoc);
918bool AsmParser::enabledGenDwarfForAssembly() {
925 if (
getContext().getGenDwarfFileNumber() == 0) {
926 const MCDwarfFile &RootFile =
927 getContext().getMCDwarfLineTable(0).getRootFile();
928 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
935bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
936 LTODiscardSymbols.
clear();
939 if (!NoInitialTextSection)
946 AsmCond StartingCondState = TheCondState;
954 MCSection *Sec = getStreamer().getCurrentSectionOnly();
957 getStreamer().emitLabel(SectionStartSym);
960 bool InsertResult =
getContext().addGenDwarfSection(Sec);
961 assert(InsertResult &&
".text section should not have debug info yet");
965 getTargetParser().onBeginOfFile();
969 ParseStatementInfo
Info(&AsmStrRewrites);
970 bool HasError = parseStatement(
Info,
nullptr);
979 printPendingErrors();
982 if (HasError && !getLexer().justConsumedEOL())
983 eatToEndOfStatement();
986 getTargetParser().onEndOfFile();
987 printPendingErrors();
990 assert(!hasPendingError() &&
"unexpected error from parseStatement");
994 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
996 const auto &LineTables =
getContext().getMCDwarfLineTables();
997 if (!LineTables.empty()) {
999 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1000 if (
File.Name.empty() && Index != 0)
1001 printError(getTok().getLoc(),
"unassigned file number: " +
1003 " for .file directives");
1015 MCSymbol *Sym = TableEntry.getValue().Symbol;
1024 printError(getTok().getLoc(),
"assembler local symbol '" +
1025 Sym->
getName() +
"' not defined");
1031 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1032 if (std::get<2>(LocSym)->isUndefined()) {
1035 CppHashInfo = std::get<1>(LocSym);
1036 printError(std::get<0>(LocSym),
"directional label undefined");
1042 if (!HadError && !NoFinalize) {
1044 TS->emitConstantPools();
1052bool AsmParser::checkForValidSection() {
1053 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1055 return Error(getTok().getLoc(),
1056 "expected section directive before assembly directive");
1062void AsmParser::eatToEndOfStatement() {
1071StringRef AsmParser::parseStringToEndOfStatement() {
1072 const char *
Start = getTok().getLoc().getPointer();
1078 return StringRef(Start, End - Start);
1081StringRef AsmParser::parseStringToComma() {
1082 const char *
Start = getTok().getLoc().getPointer();
1088 const char *End = getTok().getLoc().getPointer();
1089 return StringRef(Start, End - Start);
1097bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1098 if (parseExpression(Res))
1101 return parseRParen();
1109bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1110 if (parseExpression(Res))
1112 EndLoc = getTok().getEndLoc();
1113 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1124bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1125 AsmTypeInfo *TypeInfo) {
1126 SMLoc FirstTokenLoc = getLexer().getLoc();
1128 switch (FirstTokenKind) {
1130 return TokError(
"unknown token in expression");
1136 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1146 if (parseIdentifier(Identifier)) {
1150 bool ShouldGenerateTempSymbol =
false;
1153 ShouldGenerateTempSymbol =
true;
1155 if (!ShouldGenerateTempSymbol)
1156 return Error(FirstTokenLoc,
"invalid token in expression");
1165 EndLoc = FirstTokenLoc;
1170 std::pair<StringRef, StringRef>
Split;
1175 SMLoc AtLoc = getLexer().getLoc();
1177 if (parseIdentifier(VName))
1178 return Error(AtLoc,
"expected symbol variant after '@'");
1180 Split = std::make_pair(Identifier, VName);
1188 parseIdentifier(VName);
1191 Split = std::make_pair(Identifier, VName);
1199 return Error(getLexer().getLoc(),
"expected a symbol reference");
1203 if (!
Split.second.empty()) {
1205 if (MaybeSpecifier) {
1207 Spec = *MaybeSpecifier;
1210 "invalid variant '" +
Split.second +
"'");
1225 DoInline = TV->inlineAssignedExpr();
1228 return Error(EndLoc,
"unexpected modifier on variable reference");
1239 return TokError(
"literal value out of range for directive");
1241 SMLoc Loc = getTok().getLoc();
1242 int64_t
IntVal = getTok().getIntVal();
1248 StringRef IDVal = getTok().getString();
1250 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1252 if (
Split.first.size() != IDVal.
size()) {
1255 return TokError(
"invalid variant '" +
Split.second +
"'");
1256 IDVal =
Split.first;
1259 if (IDVal ==
"f" || IDVal ==
"b") {
1264 return Error(Loc,
"directional label undefined");
1265 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1273 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1274 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
1282 return TokError(
"cannot use . as current PC");
1295 return parseParenExpr(Res, EndLoc);
1297 if (!PlatformParser->HasBracketExpressions())
1298 return TokError(
"brackets expression not supported on this target");
1300 return parseBracketExpr(Res, EndLoc);
1303 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1309 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1315 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1322bool AsmParser::parseExpression(
const MCExpr *&Res) {
1324 return parseExpression(Res, EndLoc);
1334 switch (E->getKind()) {
1345 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1346 "' (already modified)");
1397 "Argument to the function cannot be a NULL value");
1399 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1400 (*CharPtr !=
'\0')) {
1401 if (*CharPtr ==
'!')
1405 if (*CharPtr ==
'>') {
1415 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1416 if (AltMacroStr[Pos] ==
'!')
1418 Res += AltMacroStr[Pos];
1426 return TokError(
"expected specifier following '@'");
1428 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1430 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1450bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1453 auto &TS = getTargetParser();
1454 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1462 return TokError(
"unexpected symbol modifier following '@'");
1466 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1468 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1470 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1471 "' (no symbols present)");
1481 if (Res->evaluateAsAbsolute(
Value))
1487bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1489 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1492bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1495 SMLoc StartLoc = Lexer.
getLoc();
1496 if (parseExpression(Expr))
1499 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1500 return Error(StartLoc,
"expected absolute expression");
1507 bool ShouldUseLogicalShr) {
1584 bool ShouldUseLogicalShr) {
1673bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1675 SMLoc StartLoc = Lexer.
getLoc();
1678 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1682 if (TokPrec < Precedence)
1689 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1695 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1696 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1708bool AsmParser::parseStatement(ParseStatementInfo &
Info,
1709 MCAsmParserSemaCallback *SI) {
1710 assert(!hasPendingError() &&
"parseStatement started with pending error");
1716 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1717 getTok().getString().
front() ==
'\n')
1723 AsmToken
ID = getTok();
1724 SMLoc IDLoc =
ID.getLoc();
1726 int64_t LocalLabelVal = -1;
1727 StartTokLoc =
ID.getLoc();
1729 return parseCppHashLineFilenameComment(IDLoc,
1730 !isInsideMacroInstantiation());
1734 LocalLabelVal = getTok().getIntVal();
1735 if (LocalLabelVal < 0) {
1736 if (!TheCondState.
Ignore) {
1738 return Error(IDLoc,
"unexpected token at start of statement");
1742 IDVal = getTok().getString();
1745 if (!TheCondState.
Ignore) {
1747 return Error(IDLoc,
"unexpected token at start of statement");
1755 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1757 IDVal =
ID.getString();
1758 }
else if (parseIdentifier(IDVal)) {
1759 if (!TheCondState.
Ignore) {
1761 return Error(IDLoc,
"unexpected token at start of statement");
1770 DirectiveKindMap.find(IDVal.
lower());
1771 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1773 : DirKindIt->getValue();
1784 return parseDirectiveIf(IDLoc, DirKind);
1786 return parseDirectiveIfb(IDLoc,
true);
1788 return parseDirectiveIfb(IDLoc,
false);
1790 return parseDirectiveIfc(IDLoc,
true);
1792 return parseDirectiveIfeqs(IDLoc,
true);
1794 return parseDirectiveIfc(IDLoc,
false);
1796 return parseDirectiveIfeqs(IDLoc,
false);
1798 return parseDirectiveIfdef(IDLoc,
true);
1801 return parseDirectiveIfdef(IDLoc,
false);
1803 return parseDirectiveElseIf(IDLoc);
1805 return parseDirectiveElse(IDLoc);
1807 return parseDirectiveEndIf(IDLoc);
1812 if (TheCondState.
Ignore) {
1813 eatToEndOfStatement();
1823 if (checkForValidSection())
1830 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1838 if (LocalLabelVal == -1) {
1839 if (ParsingMSInlineAsm && SI) {
1840 StringRef RewrittenLabel =
1841 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1843 "We should have an internal name here.");
1846 IDVal = RewrittenLabel;
1856 StringRef CommentStr = parseStringToEndOfStatement();
1867 if (MAI.
isMachO() && CFIStartProcLoc) {
1868 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1869 if (SymM->isExternal() && !SymM->isAltEntry())
1870 return Error(StartTokLoc,
"non-private labels cannot appear between "
1871 ".cfi_startproc / .cfi_endproc pairs") &&
1872 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1875 if (discardLTOSymbol(IDVal))
1878 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1881 if (!getTargetParser().isParsingMSInlineAsm())
1886 if (enabledGenDwarfForAssembly())
1890 getTargetParser().onLabelParsed(Sym);
1899 return parseAssignment(IDVal, AssignmentKind::Equal);
1903 if (areMacrosEnabled())
1904 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1905 return handleMacroEntry(M, IDLoc);
1922 getTargetParser().flushPendingInstructions(getStreamer());
1924 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
1926 "Should only return Failure iff there was an error");
1934 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1935 ExtensionDirectiveMap.
lookup(IDVal);
1937 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1946 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1948 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1949 case DK_LTO_SET_CONDITIONAL:
1950 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1952 return parseDirectiveAscii(IDVal,
false);
1955 return parseDirectiveAscii(IDVal,
true);
1958 return parseDirectiveValue(IDVal, 1);
1964 return parseDirectiveValue(IDVal, 2);
1969 return parseDirectiveValue(IDVal, 4);
1972 return parseDirectiveValue(IDVal, 8);
1974 return parseDirectiveValue(
1975 IDVal,
getContext().getAsmInfo()->getCodePointerSize());
1977 return parseDirectiveOctaValue(IDVal);
1981 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1984 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1986 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1987 return parseDirectiveAlign(IsPow2, 1);
1990 bool IsPow2 = !
getContext().getAsmInfo()->getAlignmentIsInBytes();
1991 return parseDirectiveAlign(IsPow2, 4);
1994 return parseDirectiveAlign(
false, 1);
1996 return parseDirectiveAlign(
false, 2);
1998 return parseDirectiveAlign(
false, 4);
2000 return parseDirectiveAlign(
true, 1);
2002 return parseDirectiveAlign(
true, 2);
2004 return parseDirectiveAlign(
true, 4);
2006 return parseDirectiveOrg();
2008 return parseDirectiveFill();
2010 return parseDirectiveZero();
2012 eatToEndOfStatement();
2016 return parseDirectiveSymbolAttribute(
MCSA_Global);
2017 case DK_LAZY_REFERENCE:
2019 case DK_NO_DEAD_STRIP:
2021 case DK_SYMBOL_RESOLVER:
2023 case DK_PRIVATE_EXTERN:
2027 case DK_WEAK_DEFINITION:
2029 case DK_WEAK_REFERENCE:
2031 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2034 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2037 return parseDirectiveComm(
false);
2039 return parseDirectiveComm(
true);
2041 return parseDirectiveAbort(IDLoc);
2043 return parseDirectiveInclude();
2045 return parseDirectiveIncbin();
2048 return TokError(Twine(IDVal) +
2049 " not currently supported for this target");
2051 return parseDirectiveRept(IDLoc, IDVal);
2053 return parseDirectiveIrp(IDLoc);
2055 return parseDirectiveIrpc(IDLoc);
2057 return parseDirectiveEndr(IDLoc);
2059 return parseDirectiveLEB128(
true);
2061 return parseDirectiveLEB128(
false);
2064 return parseDirectiveSpace(IDVal);
2066 return parseDirectiveFile(IDLoc);
2068 return parseDirectiveLine();
2070 return parseDirectiveLoc();
2072 return parseDirectiveLocLabel(IDLoc);
2074 return parseDirectiveStabs();
2076 return parseDirectiveCVFile();
2078 return parseDirectiveCVFuncId();
2079 case DK_CV_INLINE_SITE_ID:
2080 return parseDirectiveCVInlineSiteId();
2082 return parseDirectiveCVLoc();
2083 case DK_CV_LINETABLE:
2084 return parseDirectiveCVLinetable();
2085 case DK_CV_INLINE_LINETABLE:
2086 return parseDirectiveCVInlineLinetable();
2087 case DK_CV_DEF_RANGE:
2088 return parseDirectiveCVDefRange();
2090 return parseDirectiveCVString();
2091 case DK_CV_STRINGTABLE:
2092 return parseDirectiveCVStringTable();
2093 case DK_CV_FILECHECKSUMS:
2094 return parseDirectiveCVFileChecksums();
2095 case DK_CV_FILECHECKSUM_OFFSET:
2096 return parseDirectiveCVFileChecksumOffset();
2097 case DK_CV_FPO_DATA:
2098 return parseDirectiveCVFPOData();
2099 case DK_CFI_SECTIONS:
2100 return parseDirectiveCFISections();
2101 case DK_CFI_STARTPROC:
2102 return parseDirectiveCFIStartProc();
2103 case DK_CFI_ENDPROC:
2104 return parseDirectiveCFIEndProc();
2105 case DK_CFI_DEF_CFA:
2106 return parseDirectiveCFIDefCfa(IDLoc);
2107 case DK_CFI_DEF_CFA_OFFSET:
2108 return parseDirectiveCFIDefCfaOffset(IDLoc);
2109 case DK_CFI_ADJUST_CFA_OFFSET:
2110 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2111 case DK_CFI_DEF_CFA_REGISTER:
2112 return parseDirectiveCFIDefCfaRegister(IDLoc);
2113 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2114 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2116 return parseDirectiveCFIOffset(IDLoc);
2117 case DK_CFI_REL_OFFSET:
2118 return parseDirectiveCFIRelOffset(IDLoc);
2119 case DK_CFI_PERSONALITY:
2120 return parseDirectiveCFIPersonalityOrLsda(
true);
2122 return parseDirectiveCFIPersonalityOrLsda(
false);
2123 case DK_CFI_REMEMBER_STATE:
2124 return parseDirectiveCFIRememberState(IDLoc);
2125 case DK_CFI_RESTORE_STATE:
2126 return parseDirectiveCFIRestoreState(IDLoc);
2127 case DK_CFI_SAME_VALUE:
2128 return parseDirectiveCFISameValue(IDLoc);
2129 case DK_CFI_RESTORE:
2130 return parseDirectiveCFIRestore(IDLoc);
2132 return parseDirectiveCFIEscape(IDLoc);
2133 case DK_CFI_RETURN_COLUMN:
2134 return parseDirectiveCFIReturnColumn(IDLoc);
2135 case DK_CFI_SIGNAL_FRAME:
2136 return parseDirectiveCFISignalFrame(IDLoc);
2137 case DK_CFI_UNDEFINED:
2138 return parseDirectiveCFIUndefined(IDLoc);
2139 case DK_CFI_REGISTER:
2140 return parseDirectiveCFIRegister(IDLoc);
2141 case DK_CFI_WINDOW_SAVE:
2142 return parseDirectiveCFIWindowSave(IDLoc);
2144 return parseDirectiveCFILabel(IDLoc);
2145 case DK_CFI_VAL_OFFSET:
2146 return parseDirectiveCFIValOffset(IDLoc);
2149 return parseDirectiveMacrosOnOff(IDVal);
2151 return parseDirectiveMacro(IDLoc);
2154 return parseDirectiveAltmacro(IDVal);
2156 return parseDirectiveExitMacro(IDVal);
2159 return parseDirectiveEndMacro(IDVal);
2161 return parseDirectivePurgeMacro(IDLoc);
2163 return parseDirectiveEnd(IDLoc);
2165 return parseDirectiveError(IDLoc,
false);
2167 return parseDirectiveError(IDLoc,
true);
2169 return parseDirectiveWarning(IDLoc);
2171 return parseDirectiveReloc(IDLoc);
2174 return parseDirectiveDCB(IDVal, 2);
2176 return parseDirectiveDCB(IDVal, 1);
2178 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2180 return parseDirectiveDCB(IDVal, 4);
2182 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2185 return TokError(Twine(IDVal) +
2186 " not currently supported for this target");
2189 return parseDirectiveDS(IDVal, 2);
2191 return parseDirectiveDS(IDVal, 1);
2193 return parseDirectiveDS(IDVal, 8);
2196 return parseDirectiveDS(IDVal, 4);
2199 return parseDirectiveDS(IDVal, 12);
2201 return parseDirectivePrint(IDLoc);
2203 return parseDirectiveAddrsig();
2204 case DK_ADDRSIG_SYM:
2205 return parseDirectiveAddrsigSym();
2206 case DK_PSEUDO_PROBE:
2207 return parseDirectivePseudoProbe();
2208 case DK_LTO_DISCARD:
2209 return parseDirectiveLTODiscard();
2211 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2214 return Error(IDLoc,
"unknown directive");
2218 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2219 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2220 return parseDirectiveMSEmit(IDLoc,
Info, IDVal.
size());
2223 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2224 return parseDirectiveMSAlign(IDLoc,
Info);
2226 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2228 if (checkForValidSection())
2231 return parseAndMatchAndEmitTargetInstruction(
Info, IDVal,
ID, IDLoc);
2234bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &
Info,
2239 std::string OpcodeStr = IDVal.
lower();
2240 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2241 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr,
ID,
2242 Info.ParsedOperands);
2243 Info.ParseError = ParseHadError;
2246 if (getShowParsedOperands()) {
2247 SmallString<256> Str;
2248 raw_svector_ostream OS(Str);
2249 OS <<
"parsed instruction: [";
2250 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2253 Info.ParsedOperands[i]->print(OS, MAI);
2261 if (hasPendingError() || ParseHadError)
2266 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2268 getStreamer().getCurrentSectionOnly())) {
2270 if (ActiveMacros.empty())
2274 ActiveMacros.front()->ExitBuffer);
2279 if (!CppHashInfo.Filename.empty()) {
2280 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2281 0, StringRef(), CppHashInfo.Filename);
2282 getContext().setGenDwarfFileNumber(FileNumber);
2284 unsigned CppHashLocLineNo =
2286 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2289 getStreamer().emitDwarfLocDirective(
2290 getContext().getGenDwarfFileNumber(), Line, 0,
2296 if (!ParseHadError) {
2298 if (getTargetParser().matchAndEmitInstruction(
2299 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2300 getTargetParser().isParsingMSInlineAsm()))
2308AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2313 SMLoc StartLoc = Lexer.
getLoc();
2326bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2331 "Lexing Cpp line comment: Expected Integer");
2332 int64_t LineNumber = getTok().getIntVal();
2335 "Lexing Cpp line comment: Expected String");
2336 StringRef
Filename = getTok().getString();
2347 CppHashInfo.Loc =
L;
2349 CppHashInfo.LineNumber = LineNumber;
2350 CppHashInfo.Buf = CurBuffer;
2351 if (!HadCppHashFilename) {
2352 HadCppHashFilename =
true;
2361 0,
getContext().getCompilationDir(), Filename,
2362 std::nullopt, std::nullopt);
2370void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2371 auto *Parser =
static_cast<AsmParser *
>(
Context);
2372 raw_ostream &OS =
errs();
2375 SMLoc DiagLoc = Diag.
getLoc();
2377 unsigned CppHashBuf =
2378 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2383 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2392 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2393 if (Parser->SavedDiagHandler)
2394 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2396 Parser->getContext().diagnose(Diag);
2403 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2406 int CppHashLocLineNo =
2407 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2409 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2415 if (Parser->SavedDiagHandler)
2416 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2418 Parser->getContext().diagnose(NewDiag);
2426 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2430bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2433 bool EnableAtPseudoVariable) {
2435 auto expandArg = [&](
unsigned Index) {
2436 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2437 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2438 for (
const AsmToken &Token :
A[Index])
2446 if (AltMacroMode && Token.getString().front() ==
'%' &&
2449 OS << Token.getIntVal();
2452 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2459 OS << Token.getString();
2461 OS << Token.getStringContents();
2466 StringRef Body =
Macro.Body;
2467 size_t I = 0, End = Body.
size();
2469 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2471 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2472 OS << NumOfMacroInstantiations;
2476 if (Body[
I + 1] ==
'+') {
2481 if (Body[
I + 1] ==
'(' && Body[
I + 2] ==
')') {
2490 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2494 if (Parameters[Index].Name == Argument)
2496 if (Index == NParameters)
2505 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2507 switch (Body[
I + 1]) {
2523 unsigned Index = Body[
I + 1] -
'0';
2524 if (Index <
A.size())
2525 for (
const AsmToken &Token :
A[Index])
2526 OS << Token.getString();
2541 StringRef Token(Body.
data() + Start,
I - Start);
2545 if (Parameters[Index].Name == Token)
2547 if (Index != NParameters) {
2549 if (
I != End && Body[
I] ==
'&')
2593class AsmLexerSkipSpaceRAII {
2595 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2599 ~AsmLexerSkipSpaceRAII() {
2609bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2613 StringRef Str = parseStringToEndOfStatement();
2619 unsigned ParenLevel = 0;
2622 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2629 return TokError(
"unexpected token in macro instantiation");
2631 if (ParenLevel == 0) {
2644 MA.push_back(getTok());
2668 MA.push_back(getTok());
2672 if (ParenLevel != 0)
2673 return TokError(
"unbalanced parentheses in macro argument");
2678bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2679 MCAsmMacroArguments &
A) {
2680 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2681 bool NamedParametersFound =
false;
2682 SmallVector<SMLoc, 4> FALocs;
2684 A.resize(NParameters);
2685 FALocs.
resize(NParameters);
2690 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2691 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2693 SMLoc IDLoc = Lexer.
getLoc();
2694 MCAsmMacroParameter FA;
2697 if (parseIdentifier(FA.
Name))
2698 return Error(IDLoc,
"invalid argument identifier for formal argument");
2701 return TokError(
"expected '=' after formal parameter identifier");
2705 NamedParametersFound =
true;
2707 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2709 if (NamedParametersFound && FA.
Name.
empty())
2710 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2712 SMLoc StrLoc = Lexer.
getLoc();
2715 const MCExpr *AbsoluteExp;
2719 if (parseExpression(AbsoluteExp, EndLoc))
2721 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2722 getStreamer().getAssemblerPtr()))
2723 return Error(StrLoc,
"expected absolute expression");
2727 StringRef(StrChar, EndChar - StrChar),
Value);
2728 FA.
Value.push_back(newToken);
2733 jumpToLoc(EndLoc, CurBuffer);
2737 StringRef(StrChar, EndChar - StrChar));
2738 FA.
Value.push_back(newToken);
2739 }
else if(parseMacroArgument(FA.
Value, Vararg))
2742 unsigned PI = Parameter;
2745 for (FAI = 0; FAI < NParameters; ++FAI)
2746 if (
M->Parameters[FAI].Name == FA.
Name)
2749 if (FAI >= NParameters) {
2750 assert(M &&
"expected macro to be defined");
2751 return Error(IDLoc,
"parameter named '" + FA.
Name +
2752 "' does not exist for macro '" +
M->Name +
"'");
2757 if (!FA.
Value.empty()) {
2762 if (FALocs.
size() <= PI)
2765 FALocs[PI] = Lexer.
getLoc();
2773 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2775 if (
M->Parameters[FAI].Required) {
2777 "missing value for required parameter "
2778 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2782 if (!
M->Parameters[FAI].Value.empty())
2783 A[FAI] =
M->Parameters[FAI].Value;
2792 return TokError(
"too many positional arguments");
2795bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2799 if (ActiveMacros.size() == MaxNestingDepth) {
2800 std::ostringstream MaxNestingDepthError;
2801 MaxNestingDepthError <<
"macros cannot be nested more than "
2802 << MaxNestingDepth <<
" levels deep."
2803 <<
" Use -asm-macro-max-nesting-depth to increase "
2805 return TokError(MaxNestingDepthError.str());
2808 MCAsmMacroArguments
A;
2809 if (parseMacroArguments(M,
A))
2814 SmallString<256> Buf;
2815 raw_svector_ostream OS(Buf);
2817 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2818 return Error(getTok().getLoc(),
"Wrong number of arguments");
2819 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2824 OS <<
".endmacro\n";
2826 std::unique_ptr<MemoryBuffer> Instantiation =
2831 MacroInstantiation *
MI =
new MacroInstantiation{
2832 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2833 ActiveMacros.push_back(
MI);
2835 ++NumOfMacroInstantiations;
2845void AsmParser::handleMacroExit() {
2847 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2855 delete ActiveMacros.back();
2856 ActiveMacros.pop_back();
2859bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2861 const MCExpr *
Value;
2862 SMLoc ExprLoc = getTok().getLoc();
2864 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2876 if (discardLTOSymbol(Name))
2881 case AssignmentKind::Equal:
2884 case AssignmentKind::Set:
2885 case AssignmentKind::Equiv:
2889 case AssignmentKind::LTOSetConditional:
2891 return Error(ExprLoc,
"expected identifier");
2903bool AsmParser::parseIdentifier(StringRef &Res) {
2910 SMLoc PrefixLoc = getLexer().getLoc();
2922 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2928 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2936 Res = getTok().getIdentifier();
2948bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2950 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2951 parseAssignment(Name, Kind))
2956bool AsmParser::parseEscapedString(std::string &
Data) {
2961 StringRef Str = getTok().getStringContents();
2962 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
2963 if (Str[i] !=
'\\') {
2964 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
2966 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
2970 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
2981 return TokError(
"unexpected backslash at end of string");
2984 if (Str[i] ==
'x' || Str[i] ==
'X') {
2985 size_t length = Str.size();
2986 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
2987 return TokError(
"invalid hexadecimal escape sequence");
2992 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3000 if ((
unsigned)(Str[i] -
'0') <= 7) {
3002 unsigned Value = Str[i] -
'0';
3004 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3008 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3015 return TokError(
"invalid octal escape sequence (out of range)");
3025 return TokError(
"invalid escape sequence (unrecognized character)");
3027 case 'b':
Data +=
'\b';
break;
3028 case 'f':
Data +=
'\f';
break;
3029 case 'n':
Data +=
'\n';
break;
3030 case 'r':
Data +=
'\r';
break;
3031 case 't':
Data +=
'\t';
break;
3032 case '"':
Data +=
'"';
break;
3033 case '\\':
Data +=
'\\';
break;
3041bool AsmParser::parseAngleBracketString(std::string &
Data) {
3042 SMLoc EndLoc, StartLoc = getTok().getLoc();
3044 const char *StartChar = StartLoc.
getPointer() + 1;
3045 const char *EndChar = EndLoc.
getPointer() - 1;
3046 jumpToLoc(EndLoc, CurBuffer);
3059bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3060 auto parseOp = [&]() ->
bool {
3062 if (checkForValidSection())
3067 if (parseEscapedString(
Data))
3069 getStreamer().emitBytes(
Data);
3072 getStreamer().emitBytes(StringRef(
"\0", 1));
3076 return parseMany(parseOp);
3081bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3083 const MCExpr *Expr =
nullptr;
3085 if (parseExpression(
Offset))
3097 SMLoc ExprLoc = Lexer.
getLoc();
3098 if (parseExpression(Expr))
3103 return Error(ExprLoc,
"expression must be relocatable");
3109 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3115bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3116 auto parseOp = [&]() ->
bool {
3117 const MCExpr *
Value;
3118 SMLoc ExprLoc = getLexer().getLoc();
3119 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3124 uint64_t IntValue = MCE->getValue();
3126 return Error(ExprLoc,
"out of range literal value");
3127 getStreamer().emitIntValue(IntValue,
Size);
3129 getStreamer().emitValue(
Value,
Size, ExprLoc);
3133 return parseMany(parseOp);
3139 return Asm.TokError(
"unknown token in expression");
3140 SMLoc ExprLoc = Asm.getTok().getLoc();
3141 APInt IntValue = Asm.getTok().getAPIntVal();
3143 if (!IntValue.
isIntN(128))
3144 return Asm.Error(ExprLoc,
"out of range literal value");
3145 if (!IntValue.
isIntN(64)) {
3158bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3159 auto parseOp = [&]() ->
bool {
3160 if (checkForValidSection())
3166 getStreamer().emitInt64(lo);
3167 getStreamer().emitInt64(hi);
3169 getStreamer().emitInt64(hi);
3170 getStreamer().emitInt64(lo);
3175 return parseMany(parseOp);
3178bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3189 return TokError(Lexer.
getErr());
3192 return TokError(
"unexpected token in directive");
3196 StringRef IDVal = getTok().getString();
3204 return TokError(
"invalid floating point literal");
3206 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3208 return TokError(
"invalid floating point literal");
3215 Res =
Value.bitcastToAPInt();
3222bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3223 const fltSemantics &Semantics) {
3224 auto parseOp = [&]() ->
bool {
3226 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3233 return parseMany(parseOp);
3238bool AsmParser::parseDirectiveZero() {
3239 SMLoc NumBytesLoc = Lexer.
getLoc();
3240 const MCExpr *NumBytes;
3241 if (checkForValidSection() || parseExpression(NumBytes))
3247 if (parseAbsoluteExpression(Val))
3253 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3260bool AsmParser::parseDirectiveFill() {
3261 SMLoc NumValuesLoc = Lexer.
getLoc();
3262 const MCExpr *NumValues;
3263 if (checkForValidSection() || parseExpression(NumValues))
3266 int64_t FillSize = 1;
3267 int64_t FillExpr = 0;
3269 SMLoc SizeLoc, ExprLoc;
3272 SizeLoc = getTok().getLoc();
3273 if (parseAbsoluteExpression(FillSize))
3276 ExprLoc = getTok().getLoc();
3277 if (parseAbsoluteExpression(FillExpr))
3285 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3289 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3294 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3296 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3303bool AsmParser::parseDirectiveOrg() {
3305 SMLoc OffsetLoc = Lexer.
getLoc();
3306 if (checkForValidSection() || parseExpression(
Offset))
3310 int64_t FillExpr = 0;
3312 if (parseAbsoluteExpression(FillExpr))
3317 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3323bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3324 SMLoc AlignmentLoc = getLexer().getLoc();
3327 bool HasFillExpr =
false;
3328 int64_t FillExpr = 0;
3329 int64_t MaxBytesToFill = 0;
3332 auto parseAlign = [&]() ->
bool {
3333 if (parseAbsoluteExpression(Alignment))
3341 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3345 if (parseTokenLoc(MaxBytesLoc) ||
3346 parseAbsoluteExpression(MaxBytesToFill))
3352 if (checkForValidSection())
3356 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3363 bool ReturnVal =
false;
3368 if (Alignment >= 32) {
3369 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3373 Alignment = 1ULL << Alignment;
3381 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3385 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3386 Alignment = 1u << 31;
3392 if (MaxBytesToFill < 1) {
3393 ReturnVal |=
Error(MaxBytesLoc,
3394 "alignment directive can never be satisfied in this "
3395 "many bytes, ignoring maximum bytes expression");
3399 if (MaxBytesToFill >= Alignment) {
3400 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3406 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3407 assert(Section &&
"must have section to emit alignment");
3409 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3411 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3419 getStreamer().emitCodeAlignment(
3420 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3423 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3433bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3435 int64_t FileNumber = -1;
3437 FileNumber = getTok().getIntVal();
3441 return TokError(
"negative file number");
3448 if (parseEscapedString(Path))
3451 StringRef Directory;
3453 std::string FilenameData;
3455 if (check(FileNumber == -1,
3456 "explicit path specified, but no file number") ||
3457 parseEscapedString(FilenameData))
3465 uint64_t MD5Hi, MD5Lo;
3466 bool HasMD5 =
false;
3468 std::optional<StringRef>
Source;
3469 bool HasSource =
false;
3470 std::string SourceString;
3475 "unexpected token in '.file' directive") ||
3476 parseIdentifier(Keyword))
3478 if (Keyword ==
"md5") {
3480 if (check(FileNumber == -1,
3481 "MD5 checksum specified, but no file number") ||
3484 }
else if (Keyword ==
"source") {
3486 if (check(FileNumber == -1,
3487 "source specified, but no file number") ||
3489 "unexpected token in '.file' directive") ||
3490 parseEscapedString(SourceString))
3493 return TokError(
"unexpected token in '.file' directive");
3497 if (FileNumber == -1) {
3501 if (
getContext().getAsmInfo()->hasSingleParameterDotFile())
3502 getStreamer().emitFileDirective(Filename);
3512 std::optional<MD5::MD5Result> CKMem;
3515 for (
unsigned i = 0; i != 8; ++i) {
3516 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3517 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3522 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3523 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3524 Source = StringRef(SourceBuf, SourceString.size());
3526 if (FileNumber == 0) {
3530 getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
3532 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3533 FileNumber, Directory, Filename, CKMem, Source);
3540 ReportedInconsistentMD5 =
true;
3541 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3550bool AsmParser::parseDirectiveLine() {
3562bool AsmParser::parseDirectiveLoc() {
3563 int64_t FileNumber = 0, LineNumber = 0;
3564 SMLoc Loc = getTok().getLoc();
3565 if (parseIntToken(FileNumber) ||
3567 "file number less than one in '.loc' directive") ||
3568 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3569 "unassigned file number in '.loc' directive"))
3574 LineNumber = getTok().getIntVal();
3576 return TokError(
"line number less than zero in '.loc' directive");
3580 int64_t ColumnPos = 0;
3582 ColumnPos = getTok().getIntVal();
3584 return TokError(
"column position less than zero in '.loc' directive");
3588 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3593 auto parseLocOp = [&]() ->
bool {
3595 SMLoc Loc = getTok().getLoc();
3596 if (parseIdentifier(Name))
3597 return TokError(
"unexpected token in '.loc' directive");
3599 if (Name ==
"basic_block")
3601 else if (Name ==
"prologue_end")
3603 else if (Name ==
"epilogue_begin")
3605 else if (Name ==
"is_stmt") {
3606 Loc = getTok().getLoc();
3607 const MCExpr *
Value;
3608 if (parseExpression(
Value))
3612 int Value = MCE->getValue();
3614 Flags &= ~DWARF2_FLAG_IS_STMT;
3615 else if (
Value == 1)
3618 return Error(Loc,
"is_stmt value not 0 or 1");
3620 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3622 }
else if (Name ==
"isa") {
3623 Loc = getTok().getLoc();
3624 const MCExpr *
Value;
3625 if (parseExpression(
Value))
3629 int Value = MCE->getValue();
3631 return Error(Loc,
"isa number less than zero");
3634 return Error(Loc,
"isa number not a constant value");
3636 }
else if (Name ==
"discriminator") {
3637 if (parseAbsoluteExpression(Discriminator))
3640 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3645 if (parseMany(parseLocOp,
false ))
3648 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3649 Isa, Discriminator, StringRef());
3656bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3658 DirectiveLoc = Lexer.
getLoc();
3659 if (parseIdentifier(Name))
3660 return TokError(
"expected identifier");
3663 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3669bool AsmParser::parseDirectiveStabs() {
3670 return TokError(
"unsupported directive '.stabs'");
3675bool AsmParser::parseDirectiveCVFile() {
3676 SMLoc FileNumberLoc = getTok().getLoc();
3679 std::string Checksum;
3682 if (parseIntToken(FileNumber,
"expected file number") ||
3683 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3685 "unexpected token in '.cv_file' directive") ||
3686 parseEscapedString(Filename))
3690 "unexpected token in '.cv_file' directive") ||
3691 parseEscapedString(Checksum) ||
3692 parseIntToken(ChecksumKind,
3693 "expected checksum kind in '.cv_file' directive") ||
3699 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3700 memcpy(CKMem, Checksum.data(), Checksum.size());
3701 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3704 if (!getStreamer().emitCVFileDirective(FileNumber, Filename, ChecksumAsBytes,
3705 static_cast<uint8_t
>(ChecksumKind)))
3706 return Error(FileNumberLoc,
"file number already allocated");
3711bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3712 StringRef DirectiveName) {
3714 return parseTokenLoc(Loc) ||
3715 parseIntToken(FunctionId,
"expected function id") ||
3716 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3717 "expected function id within range [0, UINT_MAX)");
3720bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3722 return parseTokenLoc(Loc) ||
3723 parseIntToken(FileNumber,
"expected file number") ||
3724 check(FileNumber < 1, Loc,
3725 "file number less than one in '" + DirectiveName +
3727 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3728 "unassigned file number in '" + DirectiveName +
"' directive");
3735bool AsmParser::parseDirectiveCVFuncId() {
3736 SMLoc FunctionIdLoc = getTok().getLoc();
3739 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3742 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3743 return Error(FunctionIdLoc,
"function id already allocated");
3756bool AsmParser::parseDirectiveCVInlineSiteId() {
3757 SMLoc FunctionIdLoc = getTok().getLoc();
3765 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3770 getTok().getIdentifier() !=
"within"),
3771 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3776 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3781 getTok().getIdentifier() !=
"inlined_at"),
3782 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3788 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3789 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3794 IACol = getTok().getIntVal();
3801 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3802 IALine, IACol, FunctionIdLoc))
3803 return Error(FunctionIdLoc,
"function id already allocated");
3815bool AsmParser::parseDirectiveCVLoc() {
3816 SMLoc DirectiveLoc = getTok().getLoc();
3817 int64_t FunctionId, FileNumber;
3818 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3819 parseCVFileId(FileNumber,
".cv_loc"))
3822 int64_t LineNumber = 0;
3824 LineNumber = getTok().getIntVal();
3826 return TokError(
"line number less than zero in '.cv_loc' directive");
3830 int64_t ColumnPos = 0;
3832 ColumnPos = getTok().getIntVal();
3834 return TokError(
"column position less than zero in '.cv_loc' directive");
3838 bool PrologueEnd =
false;
3839 uint64_t IsStmt = 0;
3841 auto parseOp = [&]() ->
bool {
3843 SMLoc Loc = getTok().getLoc();
3844 if (parseIdentifier(Name))
3845 return TokError(
"unexpected token in '.cv_loc' directive");
3846 if (Name ==
"prologue_end")
3848 else if (Name ==
"is_stmt") {
3849 Loc = getTok().getLoc();
3850 const MCExpr *
Value;
3851 if (parseExpression(
Value))
3856 IsStmt = MCE->getValue();
3859 return Error(Loc,
"is_stmt value not 0 or 1");
3861 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3866 if (parseMany(parseOp,
false ))
3869 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3870 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3877bool AsmParser::parseDirectiveCVLinetable() {
3879 StringRef FnStartName, FnEndName;
3880 SMLoc Loc = getTok().getLoc();
3881 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3882 parseTokenLoc(Loc) ||
3883 check(parseIdentifier(FnStartName), Loc,
3884 "expected identifier in directive") ||
3885 parseComma() || parseTokenLoc(Loc) ||
3886 check(parseIdentifier(FnEndName), Loc,
3887 "expected identifier in directive"))
3893 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3899bool AsmParser::parseDirectiveCVInlineLinetable() {
3900 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3901 StringRef FnStartName, FnEndName;
3902 SMLoc Loc = getTok().getLoc();
3903 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3904 parseTokenLoc(Loc) ||
3905 parseIntToken(SourceFileId,
"expected SourceField") ||
3906 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
3907 parseTokenLoc(Loc) ||
3908 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
3909 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
3910 parseTokenLoc(Loc) ||
3911 check(parseIdentifier(FnStartName), Loc,
"expected identifier") ||
3912 parseTokenLoc(Loc) ||
3913 check(parseIdentifier(FnEndName), Loc,
"expected identifier"))
3921 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3922 SourceLineNum, FnStartSym,
3927void AsmParser::initializeCVDefRangeTypeMap() {
3928 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
3929 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
3930 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
3931 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
3936bool AsmParser::parseDirectiveCVDefRange() {
3938 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
3940 Loc = getLexer().getLoc();
3941 StringRef GapStartName;
3942 if (parseIdentifier(GapStartName))
3943 return Error(Loc,
"expected identifier in directive");
3946 Loc = getLexer().getLoc();
3947 StringRef GapEndName;
3948 if (parseIdentifier(GapEndName))
3949 return Error(Loc,
"expected identifier in directive");
3952 Ranges.push_back({GapStartSym, GapEndSym});
3955 StringRef CVDefRangeTypeStr;
3958 "expected comma before def_range type in .cv_def_range directive") ||
3959 parseIdentifier(CVDefRangeTypeStr))
3960 return Error(Loc,
"expected def_range type in directive");
3963 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
3964 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
3966 : CVTypeIt->getValue();
3968 case CVDR_DEFRANGE_REGISTER: {
3970 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
3971 ".cv_def_range directive") ||
3972 parseAbsoluteExpression(DRRegister))
3973 return Error(Loc,
"expected register number");
3975 codeview::DefRangeRegisterHeader DRHdr;
3978 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
3981 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
3984 "expected comma before offset in .cv_def_range directive") ||
3985 parseAbsoluteExpression(DROffset))
3986 return Error(Loc,
"expected offset value");
3988 codeview::DefRangeFramePointerRelHeader DRHdr;
3990 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
3993 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
3995 int64_t DROffsetInParent;
3996 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
3997 ".cv_def_range directive") ||
3998 parseAbsoluteExpression(DRRegister))
3999 return Error(Loc,
"expected register number");
4001 "expected comma before offset in .cv_def_range directive") ||
4002 parseAbsoluteExpression(DROffsetInParent))
4003 return Error(Loc,
"expected offset value");
4005 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4009 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4012 case CVDR_DEFRANGE_REGISTER_REL: {
4015 int64_t DRBasePointerOffset;
4016 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4017 ".cv_def_range directive") ||
4018 parseAbsoluteExpression(DRRegister))
4019 return Error(Loc,
"expected register value");
4022 "expected comma before flag value in .cv_def_range directive") ||
4023 parseAbsoluteExpression(DRFlags))
4024 return Error(Loc,
"expected flag value");
4025 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4026 "in .cv_def_range directive") ||
4027 parseAbsoluteExpression(DRBasePointerOffset))
4028 return Error(Loc,
"expected base pointer offset value");
4030 codeview::DefRangeRegisterRelHeader DRHdr;
4032 DRHdr.
Flags = DRFlags;
4034 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4038 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4045bool AsmParser::parseDirectiveCVString() {
4047 if (checkForValidSection() || parseEscapedString(
Data))
4051 std::pair<StringRef, unsigned> Insertion =
4052 getCVContext().addToStringTable(
Data);
4053 getStreamer().emitInt32(Insertion.second);
4059bool AsmParser::parseDirectiveCVStringTable() {
4060 getStreamer().emitCVStringTableDirective();
4066bool AsmParser::parseDirectiveCVFileChecksums() {
4067 getStreamer().emitCVFileChecksumsDirective();
4073bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4075 if (parseIntToken(FileNo))
4079 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4085bool AsmParser::parseDirectiveCVFPOData() {
4086 SMLoc DirLoc = getLexer().getLoc();
4088 if (parseIdentifier(ProcName))
4089 return TokError(
"expected symbol name");
4093 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4099bool AsmParser::parseDirectiveCFISections() {
4103 bool SFrame =
false;
4107 if (parseIdentifier(Name))
4108 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4109 if (Name ==
".eh_frame")
4111 else if (Name ==
".debug_frame")
4113 else if (Name ==
".sframe")
4121 getStreamer().emitCFISections(EH,
Debug, SFrame);
4127bool AsmParser::parseDirectiveCFIStartProc() {
4128 CFIStartProcLoc = StartTokLoc;
4132 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4133 "unexpected token") ||
4143 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4149bool AsmParser::parseDirectiveCFIEndProc() {
4150 CFIStartProcLoc = std::nullopt;
4155 getStreamer().emitCFIEndProc();
4160bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4161 SMLoc DirectiveLoc) {
4165 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4169 return parseAbsoluteExpression(
Register);
4176bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4178 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4179 parseAbsoluteExpression(
Offset) || parseEOL())
4188bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4190 if (parseAbsoluteExpression(
Offset) || parseEOL())
4193 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4199bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4200 int64_t Register1 = 0, Register2 = 0;
4201 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4202 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4205 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4211bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4214 getStreamer().emitCFIWindowSave(DirectiveLoc);
4220bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4221 int64_t Adjustment = 0;
4222 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4225 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4231bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4233 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4236 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4242bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4244 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4245 parseAbsoluteExpression(
Offset) || parseComma() ||
4256bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4260 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4261 parseAbsoluteExpression(
Offset) || parseEOL())
4270bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4273 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4274 parseAbsoluteExpression(
Offset) || parseEOL())
4282 if (Encoding & ~0xff)
4288 const unsigned Format = Encoding & 0xf;
4295 const unsigned Application = Encoding & 0x70;
4307bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4308 int64_t Encoding = 0;
4309 if (parseAbsoluteExpression(Encoding))
4317 check(parseIdentifier(Name),
"expected identifier in directive") ||
4324 getStreamer().emitCFIPersonality(Sym, Encoding);
4326 getStreamer().emitCFILsda(Sym, Encoding);
4332bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4335 getStreamer().emitCFIRememberState(DirectiveLoc);
4341bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4344 getStreamer().emitCFIRestoreState(DirectiveLoc);
4350bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4353 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4356 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4362bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4364 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4367 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4373bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4376 if (parseAbsoluteExpression(CurrValue))
4379 Values.push_back((uint8_t)CurrValue);
4384 if (parseAbsoluteExpression(CurrValue))
4387 Values.push_back((uint8_t)CurrValue);
4390 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4396bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4398 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4400 getStreamer().emitCFIReturnColumn(
Register);
4406bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4410 getStreamer().emitCFISignalFrame();
4416bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4419 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4422 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4428bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4431 if (parseIdentifier(Name))
4432 return TokError(
"expected identifier");
4435 getStreamer().emitCFILabelDirective(Loc, Name);
4441bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4445 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4446 parseAbsoluteExpression(
Offset) || parseEOL())
4456bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4459 AltMacroMode = (Directive ==
".altmacro");
4466bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4469 setMacrosEnabled(Directive ==
".macros_on");
4475bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4477 if (parseIdentifier(Name))
4478 return TokError(
"expected identifier in '.macro' directive");
4487 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4489 "' should be the last parameter");
4491 MCAsmMacroParameter Parameter;
4492 if (parseIdentifier(Parameter.
Name))
4493 return TokError(
"expected identifier in '.macro' directive");
4496 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4497 if (CurrParam.Name == Parameter.
Name)
4498 return TokError(
"macro '" + Name +
"' has multiple parameters"
4499 " named '" + Parameter.
Name +
"'");
4507 QualLoc = Lexer.
getLoc();
4508 if (parseIdentifier(Qualifier))
4509 return Error(QualLoc,
"missing parameter qualifier for "
4510 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4512 if (Qualifier ==
"req")
4514 else if (Qualifier ==
"vararg")
4517 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4518 "for '" + Parameter.
Name +
"' in macro '" + Name +
"'");
4526 ParamLoc = Lexer.
getLoc();
4527 if (parseMacroArgument(Parameter.
Value,
false ))
4531 Warning(ParamLoc,
"pointless default value for required parameter "
4532 "'" + Parameter.
Name +
"' in macro '" + Name +
"'");
4545 AsmToken EndToken, StartToken = getTok();
4546 unsigned MacroDepth = 0;
4556 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4561 if (getTok().getIdentifier() ==
".endm" ||
4562 getTok().getIdentifier() ==
".endmacro") {
4563 if (MacroDepth == 0) {
4564 EndToken = getTok();
4567 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4574 }
else if (getTok().getIdentifier() ==
".macro") {
4580 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4584 eatToEndOfStatement();
4588 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4593 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4594 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4595 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4616void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4622 if (NParameters == 0)
4625 bool NamedParametersFound =
false;
4626 bool PositionalParametersFound =
false;
4631 while (!Body.
empty()) {
4633 std::size_t End = Body.
size(), Pos = 0;
4634 for (; Pos != End; ++Pos) {
4637 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4641 if (Body[Pos] !=
'$' || Pos + 1 == End)
4643 char Next = Body[Pos + 1];
4645 isdigit(
static_cast<unsigned char>(
Next)))
4653 if (Body[Pos] ==
'$') {
4654 switch (Body[Pos + 1]) {
4661 PositionalParametersFound =
true;
4666 PositionalParametersFound =
true;
4672 unsigned I = Pos + 1;
4676 const char *Begin = Body.
data() + Pos + 1;
4677 StringRef
Argument(Begin,
I - (Pos + 1));
4680 if (Parameters[Index].Name == Argument)
4683 if (Index == NParameters) {
4684 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4690 NamedParametersFound =
true;
4698 if (!NamedParametersFound && PositionalParametersFound)
4699 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4700 "used in macro body, possible positional parameter "
4701 "found in body which will have no effect");
4706bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4710 if (!isInsideMacroInstantiation())
4711 return TokError(
"unexpected '" + Directive +
"' in file, "
4712 "no current macro definition");
4715 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4716 TheCondState = TheCondStack.back();
4717 TheCondStack.pop_back();
4727bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4729 return TokError(
"unexpected token in '" + Directive +
"' directive");
4733 if (isInsideMacroInstantiation()) {
4740 return TokError(
"unexpected '" + Directive +
"' in file, "
4741 "no current macro definition");
4746bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4749 if (parseTokenLoc(Loc) ||
4750 check(parseIdentifier(Name), Loc,
4751 "expected identifier in '.purgem' directive") ||
4756 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4760 <<
"Un-defining macro: " << Name <<
"\n");
4766bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4767 SMLoc NumBytesLoc = Lexer.
getLoc();
4768 const MCExpr *NumBytes;
4769 if (checkForValidSection() || parseExpression(NumBytes))
4772 int64_t FillExpr = 0;
4774 if (parseAbsoluteExpression(FillExpr))
4780 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4787bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
4788 SMLoc NumValuesLoc = Lexer.
getLoc();
4790 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4793 if (NumValues < 0) {
4794 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4801 const MCExpr *
Value;
4802 SMLoc ExprLoc = getLexer().getLoc();
4803 if (parseExpression(
Value))
4809 uint64_t IntValue = MCE->getValue();
4811 return Error(ExprLoc,
"literal value out of range for directive");
4812 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4813 getStreamer().emitIntValue(IntValue,
Size);
4815 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4816 getStreamer().emitValue(
Value,
Size, ExprLoc);
4824bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
4825 SMLoc NumValuesLoc = Lexer.
getLoc();
4827 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4830 if (NumValues < 0) {
4831 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4839 if (parseRealValue(Semantics, AsInt) || parseEOL())
4842 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4851bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
4852 SMLoc NumValuesLoc = Lexer.
getLoc();
4854 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4858 if (NumValues < 0) {
4859 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4863 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4864 getStreamer().emitFill(
Size, 0);
4871bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4872 if (checkForValidSection())
4875 auto parseOp = [&]() ->
bool {
4876 const MCExpr *
Value;
4877 if (parseExpression(
Value))
4880 getStreamer().emitSLEB128Value(
Value);
4882 getStreamer().emitULEB128Value(
Value);
4886 return parseMany(parseOp);
4891bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4892 auto parseOp = [&]() ->
bool {
4894 SMLoc Loc = getTok().getLoc();
4895 if (parseIdentifier(Name))
4896 return Error(Loc,
"expected identifier");
4898 if (discardLTOSymbol(Name))
4906 return Error(Loc,
"non-local symbol required");
4908 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
4909 return Error(Loc,
"unable to emit symbol attribute");
4913 return parseMany(parseOp);
4918bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4919 if (checkForValidSection())
4922 SMLoc IDLoc = getLexer().getLoc();
4924 if (parseIdentifier(Name))
4925 return TokError(
"expected identifier in directive");
4934 SMLoc SizeLoc = getLexer().getLoc();
4935 if (parseAbsoluteExpression(
Size))
4938 int64_t Pow2Alignment = 0;
4939 SMLoc Pow2AlignmentLoc;
4942 Pow2AlignmentLoc = getLexer().getLoc();
4943 if (parseAbsoluteExpression(Pow2Alignment))
4948 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4954 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4955 Pow2Alignment =
Log2_64(Pow2Alignment);
4965 return Error(SizeLoc,
"size must be non-negative");
4969 return Error(IDLoc,
"invalid symbol redefinition");
4973 getStreamer().emitLocalCommonSymbol(Sym,
Size,
4974 Align(1ULL << Pow2Alignment));
4978 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
4984bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
4985 StringRef Str = parseStringToEndOfStatement();
4990 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
4993 return Error(DirectiveLoc,
4994 ".abort '" + Str +
"' detected. Assembly stopping");
4999bool AsmParser::parseDirectiveInclude() {
5002 SMLoc IncludeLoc = getTok().getLoc();
5005 "expected string in '.include' directive") ||
5006 parseEscapedString(Filename) ||
5008 "unexpected token in '.include' directive") ||
5011 check(enterIncludeFile(Filename), IncludeLoc,
5012 "Could not find include file '" + Filename +
"'"))
5020bool AsmParser::parseDirectiveIncbin() {
5023 SMLoc IncbinLoc = getTok().getLoc();
5025 "expected string in '.incbin' directive") ||
5026 parseEscapedString(Filename))
5030 const MCExpr *
Count =
nullptr;
5031 SMLoc SkipLoc, CountLoc;
5036 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5040 CountLoc = getTok().getLoc();
5041 if (parseExpression(
Count))
5049 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5053 if (processIncbinFile(Filename, Skip,
Count, CountLoc))
5054 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
5060bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5061 TheCondStack.push_back(TheCondState);
5063 if (TheCondState.
Ignore) {
5064 eatToEndOfStatement();
5067 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5077 ExprValue = ExprValue == 0;
5080 ExprValue = ExprValue >= 0;
5083 ExprValue = ExprValue > 0;
5086 ExprValue = ExprValue <= 0;
5089 ExprValue = ExprValue < 0;
5093 TheCondState.
CondMet = ExprValue;
5102bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5103 TheCondStack.push_back(TheCondState);
5106 if (TheCondState.
Ignore) {
5107 eatToEndOfStatement();
5109 StringRef Str = parseStringToEndOfStatement();
5114 TheCondState.
CondMet = ExpectBlank == Str.empty();
5124bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5125 TheCondStack.push_back(TheCondState);
5128 if (TheCondState.
Ignore) {
5129 eatToEndOfStatement();
5131 StringRef Str1 = parseStringToComma();
5136 StringRef Str2 = parseStringToEndOfStatement();
5150bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5151 TheCondStack.push_back(TheCondState);
5154 if (TheCondState.
Ignore) {
5155 eatToEndOfStatement();
5159 return TokError(
"expected string parameter for '.ifeqs' directive");
5160 return TokError(
"expected string parameter for '.ifnes' directive");
5163 StringRef String1 = getTok().getStringContents();
5169 "expected comma after first string for '.ifeqs' directive");
5171 "expected comma after first string for '.ifnes' directive");
5178 return TokError(
"expected string parameter for '.ifeqs' directive");
5179 return TokError(
"expected string parameter for '.ifnes' directive");
5182 StringRef String2 = getTok().getStringContents();
5185 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5194bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5196 TheCondStack.push_back(TheCondState);
5199 if (TheCondState.
Ignore) {
5200 eatToEndOfStatement();
5202 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5220bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5223 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5224 " .if or an .elseif");
5227 bool LastIgnoreState =
false;
5228 if (!TheCondStack.empty())
5229 LastIgnoreState = TheCondStack.back().Ignore;
5230 if (LastIgnoreState || TheCondState.
CondMet) {
5231 TheCondState.
Ignore =
true;
5232 eatToEndOfStatement();
5235 if (parseAbsoluteExpression(ExprValue))
5241 TheCondState.
CondMet = ExprValue;
5250bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5256 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5257 " an .if or an .elseif");
5259 bool LastIgnoreState =
false;
5260 if (!TheCondStack.empty())
5261 LastIgnoreState = TheCondStack.back().Ignore;
5262 if (LastIgnoreState || TheCondState.
CondMet)
5263 TheCondState.
Ignore =
true;
5265 TheCondState.
Ignore =
false;
5272bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5285bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5286 if (!TheCondStack.empty()) {
5287 if (TheCondStack.back().Ignore) {
5288 eatToEndOfStatement();
5294 return Error(L,
".err encountered");
5296 StringRef Message =
".error directive invoked in source file";
5299 return TokError(
".error argument must be a string");
5301 Message = getTok().getStringContents();
5305 return Error(L, Message);
5310bool AsmParser::parseDirectiveWarning(SMLoc L) {
5311 if (!TheCondStack.empty()) {
5312 if (TheCondStack.back().Ignore) {
5313 eatToEndOfStatement();
5318 StringRef Message =
".warning directive invoked in source file";
5322 return TokError(
".warning argument must be a string");
5324 Message = getTok().getStringContents();
5335bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5340 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5342 if (!TheCondStack.empty()) {
5343 TheCondState = TheCondStack.back();
5344 TheCondStack.pop_back();
5350void AsmParser::initializeDirectiveKindMap() {
5357 DirectiveKindMap[
".set"] = DK_SET;
5358 DirectiveKindMap[
".equ"] = DK_EQU;
5359 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5360 DirectiveKindMap[
".ascii"] = DK_ASCII;
5361 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5362 DirectiveKindMap[
".string"] = DK_STRING;
5363 DirectiveKindMap[
".byte"] = DK_BYTE;
5364 DirectiveKindMap[
".short"] = DK_SHORT;
5365 DirectiveKindMap[
".value"] = DK_VALUE;
5366 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5367 DirectiveKindMap[
".long"] = DK_LONG;
5368 DirectiveKindMap[
".int"] = DK_INT;
5369 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5370 DirectiveKindMap[
".quad"] = DK_QUAD;
5371 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5372 DirectiveKindMap[
".octa"] = DK_OCTA;
5373 DirectiveKindMap[
".single"] = DK_SINGLE;
5374 DirectiveKindMap[
".float"] = DK_FLOAT;
5375 DirectiveKindMap[
".double"] = DK_DOUBLE;
5376 DirectiveKindMap[
".align"] = DK_ALIGN;
5377 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5378 DirectiveKindMap[
".balign"] = DK_BALIGN;
5379 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5380 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5381 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5382 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5383 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5384 DirectiveKindMap[
".org"] = DK_ORG;
5385 DirectiveKindMap[
".fill"] = DK_FILL;
5386 DirectiveKindMap[
".zero"] = DK_ZERO;
5387 DirectiveKindMap[
".extern"] = DK_EXTERN;
5388 DirectiveKindMap[
".globl"] = DK_GLOBL;
5389 DirectiveKindMap[
".global"] = DK_GLOBAL;
5390 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5391 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5392 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5393 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5394 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5395 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5396 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5397 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5398 DirectiveKindMap[
".cold"] = DK_COLD;
5399 DirectiveKindMap[
".comm"] = DK_COMM;
5400 DirectiveKindMap[
".common"] = DK_COMMON;
5401 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5402 DirectiveKindMap[
".abort"] = DK_ABORT;
5403 DirectiveKindMap[
".include"] = DK_INCLUDE;
5404 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5405 DirectiveKindMap[
".code16"] = DK_CODE16;
5406 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5407 DirectiveKindMap[
".rept"] = DK_REPT;
5408 DirectiveKindMap[
".rep"] = DK_REPT;
5409 DirectiveKindMap[
".irp"] = DK_IRP;
5410 DirectiveKindMap[
".irpc"] = DK_IRPC;
5411 DirectiveKindMap[
".endr"] = DK_ENDR;
5412 DirectiveKindMap[
".if"] = DK_IF;
5413 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5414 DirectiveKindMap[
".ifge"] = DK_IFGE;
5415 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5416 DirectiveKindMap[
".ifle"] = DK_IFLE;
5417 DirectiveKindMap[
".iflt"] = DK_IFLT;
5418 DirectiveKindMap[
".ifne"] = DK_IFNE;
5419 DirectiveKindMap[
".ifb"] = DK_IFB;
5420 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5421 DirectiveKindMap[
".ifc"] = DK_IFC;
5422 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5423 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5424 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5425 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5426 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5427 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5428 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5429 DirectiveKindMap[
".else"] = DK_ELSE;
5430 DirectiveKindMap[
".end"] = DK_END;
5431 DirectiveKindMap[
".endif"] = DK_ENDIF;
5432 DirectiveKindMap[
".skip"] = DK_SKIP;
5433 DirectiveKindMap[
".space"] = DK_SPACE;
5434 DirectiveKindMap[
".file"] = DK_FILE;
5435 DirectiveKindMap[
".line"] = DK_LINE;
5436 DirectiveKindMap[
".loc"] = DK_LOC;
5437 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5438 DirectiveKindMap[
".stabs"] = DK_STABS;
5439 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5440 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5441 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5442 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5443 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5444 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5445 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5446 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5447 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5448 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5449 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5450 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5451 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5452 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5453 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5454 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5455 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5456 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5457 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5458 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5459 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5460 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5461 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5462 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5463 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5464 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5465 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5466 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5467 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5468 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5469 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5470 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5471 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5472 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5473 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5474 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5475 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5476 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5477 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5478 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5479 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5480 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5481 DirectiveKindMap[
".macro"] = DK_MACRO;
5482 DirectiveKindMap[
".exitm"] = DK_EXITM;
5483 DirectiveKindMap[
".endm"] = DK_ENDM;
5484 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5485 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5486 DirectiveKindMap[
".err"] = DK_ERR;
5487 DirectiveKindMap[
".error"] = DK_ERROR;
5488 DirectiveKindMap[
".warning"] = DK_WARNING;
5489 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5490 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5491 DirectiveKindMap[
".reloc"] = DK_RELOC;
5492 DirectiveKindMap[
".dc"] = DK_DC;
5493 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5494 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5495 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5496 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5497 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5498 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5499 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5500 DirectiveKindMap[
".dcb"] = DK_DCB;
5501 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5502 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5503 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5504 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5505 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5506 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5507 DirectiveKindMap[
".ds"] = DK_DS;
5508 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5509 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5510 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5511 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5512 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5513 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5514 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5515 DirectiveKindMap[
".print"] = DK_PRINT;
5516 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5517 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5518 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5519 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5520 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5521 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5524MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5525 AsmToken EndToken, StartToken = getTok();
5527 unsigned NestLevel = 0;
5531 printError(DirectiveLoc,
"no matching '.endr' in definition");
5536 StringRef Ident = getTok().getIdentifier();
5537 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5540 }
else if (Ident ==
".endr") {
5541 if (NestLevel == 0) {
5542 EndToken = getTok();
5546 printError(getTok().getLoc(),
"expected newline");
5554 eatToEndOfStatement();
5559 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5563 return &MacroLikeBodies.back();
5566void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5567 raw_svector_ostream &OS) {
5570 std::unique_ptr<MemoryBuffer> Instantiation =
5575 MacroInstantiation *
MI =
new MacroInstantiation{
5576 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5577 ActiveMacros.push_back(
MI);
5587bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5588 const MCExpr *CountExpr;
5589 SMLoc CountLoc = getTok().getLoc();
5590 if (parseExpression(CountExpr))
5594 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5595 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5598 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5602 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5608 SmallString<256> Buf;
5609 raw_svector_ostream OS(Buf);
5612 if (expandMacro(OS, *M, {}, {},
false))
5615 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5622bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5623 MCAsmMacroParameter Parameter;
5624 MCAsmMacroArguments
A;
5625 if (check(parseIdentifier(Parameter.
Name),
5626 "expected identifier in '.irp' directive") ||
5627 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5631 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5637 SmallString<256> Buf;
5638 raw_svector_ostream OS(Buf);
5640 for (
const MCAsmMacroArgument &Arg :
A) {
5643 if (expandMacro(OS, *M, Parameter, Arg,
true))
5647 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5654bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5655 MCAsmMacroParameter Parameter;
5656 MCAsmMacroArguments
A;
5658 if (check(parseIdentifier(Parameter.
Name),
5659 "expected identifier in '.irpc' directive") ||
5660 parseComma() || parseMacroArguments(
nullptr,
A))
5663 if (
A.size() != 1 ||
A.front().size() != 1)
5664 return TokError(
"unexpected token in '.irpc' directive");
5669 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5675 SmallString<256> Buf;
5676 raw_svector_ostream OS(Buf);
5679 :
A[0][0].getString();
5680 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5681 MCAsmMacroArgument Arg;
5686 if (expandMacro(OS, *M, Parameter, Arg,
true))
5690 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5695bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5696 if (ActiveMacros.empty())
5697 return TokError(
"unmatched '.endr' directive");
5707bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &
Info,
5709 const MCExpr *
Value;
5710 SMLoc ExprLoc = getLexer().getLoc();
5711 if (parseExpression(
Value))
5715 return Error(ExprLoc,
"unexpected expression in _emit");
5716 uint64_t IntValue = MCE->
getValue();
5718 return Error(ExprLoc,
"literal value out of range for directive");
5724bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &
Info) {
5725 const MCExpr *
Value;
5726 SMLoc ExprLoc = getLexer().getLoc();
5727 if (parseExpression(
Value))
5731 return Error(ExprLoc,
"unexpected expression in align");
5732 uint64_t IntValue = MCE->
getValue();
5734 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5740bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5741 const AsmToken StrTok = getTok();
5744 return Error(DirectiveLoc,
"expected double quoted string after .print");
5751bool AsmParser::parseDirectiveAddrsig() {
5754 getStreamer().emitAddrsig();
5758bool AsmParser::parseDirectiveAddrsigSym() {
5760 if (check(parseIdentifier(Name),
"expected identifier") || parseEOL())
5763 getStreamer().emitAddrsigSym(Sym);
5767bool AsmParser::parseDirectivePseudoProbe() {
5773 if (parseIntToken(
Guid))
5775 if (parseIntToken(Index))
5777 if (parseIntToken(
Type))
5779 if (parseIntToken(Attr))
5791 int64_t CallerGuid = 0;
5793 CallerGuid = getTok().getIntVal();
5801 int64_t CallerProbeId = 0;
5803 CallerProbeId = getTok().getIntVal();
5813 if (parseIdentifier(FnName))
5814 return Error(getLexer().getLoc(),
"expected identifier");
5820 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
5821 InlineStack, FnSym);
5830bool AsmParser::parseDirectiveLTODiscard() {
5831 auto ParseOp = [&]() ->
bool {
5833 SMLoc Loc = getTok().getLoc();
5834 if (parseIdentifier(Name))
5835 return Error(Loc,
"expected identifier");
5836 LTODiscardSymbols.
insert(Name);
5840 LTODiscardSymbols.
clear();
5841 return parseMany(ParseOp);
5867bool AsmParser::parseMSInlineAsm(
5868 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
5869 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5870 SmallVectorImpl<std::string> &Constraints,
5871 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
5872 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
5873 SmallVector<void *, 4> InputDecls;
5874 SmallVector<void *, 4> OutputDecls;
5877 SmallVector<std::string, 4> InputConstraints;
5878 SmallVector<std::string, 4> OutputConstraints;
5887 unsigned InputIdx = 0;
5888 unsigned OutputIdx = 0;
5891 if (parseCurlyBlockScope(AsmStrRewrites))
5894 ParseStatementInfo
Info(&AsmStrRewrites);
5895 bool StatementErr = parseStatement(
Info, &SI);
5897 if (StatementErr ||
Info.ParseError) {
5899 printPendingErrors();
5904 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5906 if (
Info.Opcode == ~0U)
5912 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
5913 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
5917 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
5918 unsigned NumDefs =
Desc.getNumDefs();
5927 if (SymName.
empty())
5935 if (Operand.
isImm()) {
5943 bool isOutput = (i == 1) &&
Desc.mayStore();
5950 OutputConstraints.
push_back((
"=" + Constraint).str());
5957 if (
Desc.operands()[i - 1].isBranchTarget())
5971 NumOutputs = OutputDecls.
size();
5972 NumInputs = InputDecls.
size();
5977 Clobbers.
assign(ClobberRegs.
size(), std::string());
5978 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
5979 raw_string_ostream OS(Clobbers[
I]);
5984 if (NumOutputs || NumInputs) {
5985 unsigned NumExprs = NumOutputs + NumInputs;
5986 OpDecls.resize(NumExprs);
5987 Constraints.
resize(NumExprs);
5988 for (
unsigned i = 0; i < NumOutputs; ++i) {
5989 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
5990 Constraints[i] = OutputConstraints[i];
5992 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
5993 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
5994 Constraints[
j] = InputConstraints[i];
5999 std::string AsmStringIR;
6000 raw_string_ostream OS(AsmStringIR);
6001 StringRef ASMString =
6003 const char *AsmStart = ASMString.
begin();
6004 const char *AsmEnd = ASMString.
end();
6006 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6007 const AsmRewrite &AR = *
I;
6014 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6017 if (
unsigned Len = Loc - AsmStart)
6018 OS << StringRef(AsmStart, Len);
6022 AsmStart = Loc + AR.
Len;
6026 unsigned AdditionalSkip = 0;
6048 size_t OffsetLen = OffsetName.
size();
6049 auto rewrite_it = std::find_if(
6050 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6051 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6052 (FusingAR.Kind == AOK_Input ||
6053 FusingAR.Kind == AOK_CallInput);
6055 if (rewrite_it == AsmStrRewrites.
end()) {
6056 OS <<
"offset " << OffsetName;
6058 OS <<
"${" << InputIdx++ <<
":P}";
6059 rewrite_it->Done =
true;
6061 OS <<
'$' << InputIdx++;
6062 rewrite_it->Done =
true;
6075 OS <<
"${" << InputIdx++ <<
":P}";
6077 OS <<
'$' << InputIdx++;
6080 OS <<
"${" << InputIdx++ <<
":P}";
6084 OS <<
"${" << OutputIdx++ <<
":P}";
6086 OS <<
'$' << OutputIdx++;
6091 case 8: OS <<
"byte ptr ";
break;
6092 case 16: OS <<
"word ptr ";
break;
6093 case 32: OS <<
"dword ptr ";
break;
6094 case 64: OS <<
"qword ptr ";
break;
6095 case 80: OS <<
"xword ptr ";
break;
6096 case 128: OS <<
"xmmword ptr ";
break;
6097 case 256: OS <<
"ymmword ptr ";
break;
6107 if (
getContext().getAsmInfo()->getAlignmentIsInBytes())
6112 unsigned Val = AR.
Val;
6114 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6115 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6127 AsmStart = Loc + AR.
Len + AdditionalSkip;
6131 if (AsmStart != AsmEnd)
6132 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6134 AsmString = std::move(AsmStringIR);
6138bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &
Info,
6139 MCAsmParserSemaCallback *SI) {
6140 AsmToken LabelTok = getTok();
6141 SMLoc LabelLoc = LabelTok.
getLoc();
6144 if (parseIdentifier(LabelVal))
6145 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6150 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6159 return Error(LabelLoc,
6160 "Cannot have just a label for an HLASM inline asm statement");
6170 if (enabledGenDwarfForAssembly())
6177bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &
Info,
6178 MCAsmParserSemaCallback *SI) {
6179 AsmToken OperationEntryTok = Lexer.
getTok();
6180 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6181 StringRef OperationEntryVal;
6184 if (parseIdentifier(OperationEntryVal))
6185 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6191 return parseAndMatchAndEmitTargetInstruction(
6192 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6195bool HLASMAsmParser::parseStatement(ParseStatementInfo &
Info,
6196 MCAsmParserSemaCallback *SI) {
6197 assert(!hasPendingError() &&
"parseStatement started with pending error");
6200 bool ShouldParseAsHLASMLabel =
false;
6209 ShouldParseAsHLASMLabel =
true;
6215 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6216 getTok().getString().
front() ==
'\n')
6231 if (getTok().getString().
front() ==
'\n' ||
6232 getTok().getString().
front() ==
'\r') {
6241 if (ShouldParseAsHLASMLabel) {
6244 if (parseAsHLASMLabel(
Info, SI)) {
6247 eatToEndOfStatement();
6252 return parseAsMachineInstruction(
Info, SI);
6256namespace MCParserUtils {
6265 return Parser.
TokError(
"missing expression");
6271 return Parser.
Error(
6272 EqualLoc,
"relocation specifier not permitted in symbol equating");
6280 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6286 }
else if (Name ==
".") {
6304 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6305 return new HLASMAsmParser(SM,
C, Out, MAI, CB);
6307 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.
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=std::nullopt)
Report an error at the current lexer location.
MCStreamer & getStreamer()
MCTargetAsmParser & getTargetParser() const
bool Error(SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)
Return an error at the location L, with the message Msg.
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 * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
LLVM_ABI MCSymbol * cloneSymbol(MCSymbol &Sym)
Clone a symbol for the .set directive, replacing it in the symbol table.
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.
std::variant< std::monostate, DecisionParameters, BranchParameters > Parameters
The type of MC/DC-specific parameters.
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.