81typedef std::vector<AsmToken> MCAsmMacroArgument;
82typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
86struct MacroInstantiation {
88 SMLoc InstantiationLoc;
97 size_t CondStackDepth;
100struct ParseStatementInfo {
105 unsigned Opcode = ~0
U;
108 bool ParseError =
false;
110 SmallVectorImpl<AsmRewrite> *AsmRewrites =
nullptr;
112 ParseStatementInfo() =
delete;
113 ParseStatementInfo(SmallVectorImpl<AsmRewrite> *rewrites)
114 : AsmRewrites(rewrites) {}
121 void *SavedDiagContext;
122 std::unique_ptr<MCAsmParserExtension> PlatformParser;
123 std::unique_ptr<MCAsmParserExtension> LFIParser;
125 std::optional<SMLoc> CFIStartProcLoc;
131 AsmCond TheCondState;
132 std::vector<AsmCond> TheCondStack;
137 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
140 std::vector<MacroInstantiation*> ActiveMacros;
143 std::deque<MCAsmMacro> MacroLikeBodies;
146 unsigned MacrosEnabledFlag : 1;
149 unsigned NumOfMacroInstantiations = 0;
152 struct CppHashInfoTy {
157 CppHashInfoTy() : LineNumber(0), Buf(0) {}
159 CppHashInfoTy CppHashInfo;
162 bool HadCppHashFilename =
false;
167 SmallSet<StringRef, 2> LTODiscardSymbols;
170 unsigned AssemblerDialect = ~0
U;
173 bool IsDarwin =
false;
176 bool ParsingMSInlineAsm =
false;
179 bool ReportedInconsistentMD5 =
false;
182 bool AltMacroMode =
false;
185 virtual bool parseStatement(ParseStatementInfo &Info,
186 MCAsmParserSemaCallback *SI);
191 bool parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
192 StringRef IDVal, AsmToken
ID,
198 bool enabledGenDwarfForAssembly();
201 AsmParser(SourceMgr &
SM, MCContext &Ctx, MCStreamer &Out,
202 const MCAsmInfo &MAI,
unsigned CB);
203 AsmParser(
const AsmParser &) =
delete;
204 AsmParser &operator=(
const AsmParser &) =
delete;
205 ~AsmParser()
override;
207 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
209 void addDirectiveHandler(StringRef Directive,
210 ExtensionDirectiveHandler Handler)
override {
211 ExtensionDirectiveMap[Directive] = std::move(Handler);
214 void addAliasForDirective(StringRef Directive, StringRef Alias)
override {
215 DirectiveKindMap[Directive.
lower()] = DirectiveKindMap[Alias.
lower()];
221 CodeViewContext &getCVContext() {
return Ctx.getCVContext(); }
223 unsigned getAssemblerDialect()
override {
224 if (AssemblerDialect == ~0U)
225 return MAI.getAssemblerDialect();
227 return AssemblerDialect;
229 void setAssemblerDialect(
unsigned i)
override {
230 AssemblerDialect = i;
233 void Note(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
234 bool Warning(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
235 bool printError(SMLoc L,
const Twine &Msg, SMRange
Range = {})
override;
237 const AsmToken &Lex()
override;
239 void setParsingMSInlineAsm(
bool V)
override {
240 ParsingMSInlineAsm =
V;
243 Lexer.setLexMasmIntegers(V);
245 bool isParsingMSInlineAsm()
override {
return ParsingMSInlineAsm; }
247 bool discardLTOSymbol(StringRef Name)
const override {
248 return LTODiscardSymbols.contains(Name);
251 bool parseMSInlineAsm(std::string &AsmString,
unsigned &NumOutputs,
253 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
254 SmallVectorImpl<std::string> &Constraints,
255 SmallVectorImpl<std::string> &Clobbers,
256 const MCInstrInfo *MII, MCInstPrinter *IP,
257 MCAsmParserSemaCallback &SI)
override;
259 bool parseExpression(
const MCExpr *&Res);
260 bool parseExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
261 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
262 AsmTypeInfo *TypeInfo)
override;
263 bool parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc)
override;
264 bool parseAbsoluteExpression(int64_t &Res)
override;
268 bool parseRealValue(
const fltSemantics &Semantics, APInt &Res);
272 bool parseIdentifier(StringRef &Res)
override;
273 void eatToEndOfStatement()
override;
275 bool checkForValidSection()
override;
280 bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
281 bool parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo =
true);
283 void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
285 bool expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
290 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
293 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
296 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
302 bool handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc);
305 void handleMacroExit();
308 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
311 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
313 void printMacroInstantiations();
315 SMRange
Range = {})
const {
322 bool enterIncludeFile(
const std::string &
Filename);
326 bool processIncbinFile(
const std::string &
Filename, int64_t Skip = 0,
327 const MCExpr *
Count =
nullptr, SMLoc Loc = SMLoc());
335 void jumpToLoc(SMLoc Loc,
unsigned InBuffer = 0);
340 StringRef parseStringToEndOfStatement()
override;
344 StringRef parseStringToComma();
346 enum class AssignmentKind {
353 bool parseAssignment(StringRef Name, AssignmentKind Kind);
358 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res, SMLoc &EndLoc);
359 bool parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc);
360 bool parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc);
362 bool parseRegisterOrRegisterNumber(int64_t &
Register, SMLoc DirectiveLoc);
364 bool parseCVFunctionId(int64_t &FunctionId, StringRef DirectiveName);
365 bool parseCVFileId(int64_t &FileId, StringRef DirectiveName);
436 DK_WEAK_DEF_CAN_BE_HIDDEN,
477 DK_CV_INLINE_SITE_ID,
480 DK_CV_INLINE_LINETABLE,
485 DK_CV_FILECHECKSUM_OFFSET,
491 DK_CFI_DEF_CFA_OFFSET,
492 DK_CFI_ADJUST_CFA_OFFSET,
493 DK_CFI_DEF_CFA_REGISTER,
494 DK_CFI_LLVM_DEF_ASPACE_CFA,
499 DK_CFI_REMEMBER_STATE,
500 DK_CFI_RESTORE_STATE,
504 DK_CFI_RETURN_COLUMN,
531 DK_LTO_SET_CONDITIONAL,
532 DK_CFI_MTE_TAGGED_FRAME,
540 StringMap<DirectiveKind> DirectiveKindMap;
543 enum CVDefRangeType {
545 CVDR_DEFRANGE_REGISTER,
546 CVDR_DEFRANGE_FRAMEPOINTER_REL,
547 CVDR_DEFRANGE_SUBFIELD_REGISTER,
548 CVDR_DEFRANGE_REGISTER_REL,
549 CVDR_DEFRANGE_REGISTER_REL_INDIR
554 StringMap<CVDefRangeType> CVDefRangeTypeMap;
557 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
558 bool parseDirectiveBase64();
559 bool parseDirectiveReloc(SMLoc DirectiveLoc);
560 bool parseDirectiveValue(StringRef IDVal,
562 bool parseDirectiveOctaValue(StringRef IDVal);
563 bool parseDirectiveRealValue(StringRef IDVal,
564 const fltSemantics &);
565 bool parseDirectiveFill();
566 bool parseDirectiveZero();
568 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
569 bool parseDirectiveOrg();
571 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
572 bool parseDirectivePrefAlign();
575 bool parseDirectiveFile(SMLoc DirectiveLoc);
576 bool parseDirectiveLine();
577 bool parseDirectiveLoc();
578 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
579 bool parseDirectiveStabs();
583 bool parseDirectiveCVFile();
584 bool parseDirectiveCVFuncId();
585 bool parseDirectiveCVInlineSiteId();
586 bool parseDirectiveCVLoc();
587 bool parseDirectiveCVLinetable();
588 bool parseDirectiveCVInlineLinetable();
589 bool parseDirectiveCVDefRange();
590 bool parseDirectiveCVString();
591 bool parseDirectiveCVStringTable();
592 bool parseDirectiveCVFileChecksums();
593 bool parseDirectiveCVFileChecksumOffset();
594 bool parseDirectiveCVFPOData();
597 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
598 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
599 bool parseDirectiveCFISections();
600 bool parseDirectiveCFIStartProc();
601 bool parseDirectiveCFIEndProc();
602 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
603 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
604 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
605 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
606 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
607 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
608 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
609 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
610 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
611 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
612 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
613 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
614 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
615 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
616 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
617 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
618 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
619 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
622 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
623 bool parseDirectiveExitMacro(StringRef Directive);
624 bool parseDirectiveEndMacro(StringRef Directive);
625 bool parseDirectiveMacro(SMLoc DirectiveLoc);
626 bool parseDirectiveMacrosOnOff(StringRef Directive);
628 bool parseDirectiveAltmacro(StringRef Directive);
631 bool parseDirectiveSpace(StringRef IDVal);
634 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
635 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
637 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
640 bool parseDirectiveLEB128(
bool Signed);
646 bool parseDirectiveComm(
bool IsLocal);
648 bool parseDirectiveAbort(SMLoc DirectiveLoc);
649 bool parseDirectiveInclude();
650 bool parseDirectiveIncbin();
653 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
655 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
657 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
659 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
661 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
662 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
663 bool parseDirectiveElse(SMLoc DirectiveLoc);
664 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
665 bool parseEscapedString(std::string &
Data)
override;
666 bool parseAngleBracketString(std::string &
Data)
override;
669 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
670 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
671 raw_svector_ostream &OS);
672 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
673 bool parseDirectiveIrp(SMLoc DirectiveLoc);
674 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
675 bool parseDirectiveEndr(SMLoc DirectiveLoc);
678 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,
682 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
685 bool parseDirectiveEnd(SMLoc DirectiveLoc);
688 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
691 bool parseDirectiveWarning(SMLoc DirectiveLoc);
694 bool parseDirectivePrint(SMLoc DirectiveLoc);
697 bool parseDirectivePseudoProbe();
700 bool parseDirectiveLTODiscard();
703 bool parseDirectiveAddrsig();
704 bool parseDirectiveAddrsigSym();
706 void initializeDirectiveKindMap();
707 void initializeCVDefRangeTypeMap();
710class HLASMAsmParser final :
public AsmParser {
715 void lexLeadingSpaces() {
720 bool parseAsHLASMLabel(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI);
721 bool parseAsMachineInstruction(ParseStatementInfo &Info,
722 MCAsmParserSemaCallback *SI);
725 HLASMAsmParser(SourceMgr &
SM, MCContext &Ctx, MCStreamer &Out,
726 const MCAsmInfo &MAI,
unsigned CB = 0)
727 : AsmParser(
SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
728 Lexer.setSkipSpace(
false);
729 Lexer.setAllowHashInIdentifier(
true);
730 Lexer.setLexHLASMIntegers(
true);
731 Lexer.setLexHLASMStrings(
true);
734 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
736 bool parseStatement(ParseStatementInfo &Info,
737 MCAsmParserSemaCallback *SI)
override;
750 :
MCAsmParser(Ctx, Out,
SM, MAI), CurBuffer(CB ? CB :
SM.getMainFileID()),
751 MacrosEnabledFlag(
true) {
754 SavedDiagHandler =
SrcMgr.getDiagHandler();
755 SavedDiagContext =
SrcMgr.getDiagContext();
763 switch (Ctx.getObjectFileType()) {
764 case MCContext::IsCOFF:
765 PlatformParser.reset(createCOFFAsmParser());
767 case MCContext::IsMachO:
768 PlatformParser.reset(createDarwinAsmParser());
771 case MCContext::IsELF:
772 PlatformParser.reset(createELFAsmParser());
774 case MCContext::IsGOFF:
775 PlatformParser.reset(createGOFFAsmParser());
777 case MCContext::IsSPIRV:
779 "Need to implement createSPIRVAsmParser for SPIRV format.");
781 case MCContext::IsWasm:
782 PlatformParser.reset(createWasmAsmParser());
784 case MCContext::IsXCOFF:
785 PlatformParser.reset(createXCOFFAsmParser());
787 case MCContext::IsDXContainer:
788 report_fatal_error(
"DXContainer is not supported yet");
792 PlatformParser->Initialize(*
this);
794 LFIParser.reset(createLFIAsmParser(Out.getLFIRewriter()));
795 LFIParser->Initialize(*this);
797 initializeDirectiveKindMap();
798 initializeCVDefRangeTypeMap();
801AsmParser::~AsmParser() {
802 assert((HadError || ActiveMacros.empty()) &&
803 "Unexpected active macro instantiation!");
812void AsmParser::printMacroInstantiations() {
814 for (MacroInstantiation *M :
reverse(ActiveMacros))
816 "while in macro instantiation");
819void AsmParser::Note(SMLoc L,
const Twine &Msg, SMRange
Range) {
820 printPendingErrors();
822 printMacroInstantiations();
825bool AsmParser::Warning(SMLoc L,
const Twine &Msg, SMRange
Range) {
826 if(getTargetParser().getTargetOptions().MCNoWarn)
828 if (getTargetParser().getTargetOptions().MCFatalWarnings)
831 printMacroInstantiations();
835bool AsmParser::printError(SMLoc L,
const Twine &Msg, SMRange
Range) {
838 printMacroInstantiations();
842bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
843 std::string IncludedFile;
857bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
858 const MCExpr *
Count, SMLoc Loc) {
860 if (SymbolScanningMode)
866 std::string IncludedFile;
873 StringRef Bytes = (*BufOrErr)->getBuffer();
877 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
878 return Error(Loc,
"expected absolute expression");
880 return Warning(Loc,
"negative count has no effect");
883 getStreamer().emitBytes(Bytes);
887void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
893const AsmToken &AsmParser::Lex() {
900 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
905 const AsmToken *tok = &Lexer.
Lex();
918 if (ParentIncludeLoc != SMLoc()) {
919 jumpToLoc(ParentIncludeLoc);
927bool AsmParser::enabledGenDwarfForAssembly() {
934 if (
getContext().getGenDwarfFileNumber() == 0) {
935 const MCDwarfFile &RootFile =
936 getContext().getMCDwarfLineTable(0).getRootFile();
937 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
944bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
945 LTODiscardSymbols.
clear();
948 if (!NoInitialTextSection)
955 AsmCond StartingCondState = TheCondState;
963 MCSection *Sec = getStreamer().getCurrentSectionOnly();
966 getStreamer().emitLabel(SectionStartSym);
969 bool InsertResult =
getContext().addGenDwarfSection(Sec);
970 assert(InsertResult &&
".text section should not have debug info yet");
974 getTargetParser().onBeginOfFile();
978 ParseStatementInfo
Info(&AsmStrRewrites);
979 bool HasError = parseStatement(Info,
nullptr);
988 printPendingErrors();
991 if (HasError && !getLexer().justConsumedEOL())
992 eatToEndOfStatement();
995 getTargetParser().onEndOfFile();
996 printPendingErrors();
999 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1003 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1005 const auto &LineTables =
getContext().getMCDwarfLineTables();
1006 if (!LineTables.empty()) {
1008 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1009 if (
File.Name.empty() && Index != 0)
1010 printError(getTok().getLoc(),
"unassigned file number: " +
1012 " for .file directives");
1024 MCSymbol *Sym = TableEntry.getValue().Symbol;
1033 printError(getTok().getLoc(),
"assembler local symbol '" +
1034 Sym->
getName() +
"' not defined");
1040 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1041 if (std::get<2>(LocSym)->isUndefined()) {
1044 CppHashInfo = std::get<1>(LocSym);
1045 printError(std::get<0>(LocSym),
"directional label undefined");
1051 if (!HadError && !NoFinalize) {
1053 TS->emitConstantPools();
1061bool AsmParser::checkForValidSection() {
1062 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1064 return Error(getTok().getLoc(),
1065 "expected section directive before assembly directive");
1071void AsmParser::eatToEndOfStatement() {
1080StringRef AsmParser::parseStringToEndOfStatement() {
1081 const char *
Start = getTok().getLoc().getPointer();
1087 return StringRef(Start, End - Start);
1090StringRef AsmParser::parseStringToComma() {
1091 const char *
Start = getTok().getLoc().getPointer();
1097 const char *End = getTok().getLoc().getPointer();
1098 return StringRef(Start, End - Start);
1106bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1107 if (parseExpression(Res))
1110 return parseRParen();
1118bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1119 if (parseExpression(Res))
1121 EndLoc = getTok().getEndLoc();
1122 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1133bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1134 AsmTypeInfo *TypeInfo) {
1135 SMLoc FirstTokenLoc = getLexer().getLoc();
1137 switch (FirstTokenKind) {
1139 return TokError(
"unknown token in expression");
1145 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1155 if (parseIdentifier(Identifier)) {
1159 bool ShouldGenerateTempSymbol =
false;
1162 ShouldGenerateTempSymbol =
true;
1164 if (!ShouldGenerateTempSymbol)
1165 return Error(FirstTokenLoc,
"invalid token in expression");
1174 EndLoc = FirstTokenLoc;
1179 std::pair<StringRef, StringRef>
Split;
1184 SMLoc AtLoc = getLexer().getLoc();
1186 if (parseIdentifier(VName))
1187 return Error(AtLoc,
"expected symbol variant after '@'");
1189 Split = std::make_pair(Identifier, VName);
1197 parseIdentifier(VName);
1200 Split = std::make_pair(Identifier, VName);
1208 return Error(getLexer().getLoc(),
"expected a symbol reference");
1212 if (!
Split.second.empty()) {
1214 if (MaybeSpecifier) {
1216 Spec = *MaybeSpecifier;
1219 "invalid variant '" +
Split.second +
"'");
1234 DoInline = TV->inlineAssignedExpr();
1237 return Error(EndLoc,
"unexpected modifier on variable reference");
1248 return TokError(
"literal value out of range for directive");
1250 SMLoc Loc = getTok().getLoc();
1251 int64_t
IntVal = getTok().getIntVal();
1257 StringRef IDVal = getTok().getString();
1259 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1261 if (
Split.first.size() != IDVal.
size()) {
1264 return TokError(
"invalid variant '" +
Split.second +
"'");
1265 IDVal =
Split.first;
1268 if (IDVal ==
"f" || IDVal ==
"b") {
1273 return Error(Loc,
"directional label undefined");
1274 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1282 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1283 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
1291 return TokError(
"cannot use . as current PC");
1304 return parseParenExpr(Res, EndLoc);
1306 if (!PlatformParser->HasBracketExpressions())
1307 return TokError(
"brackets expression not supported on this target");
1309 return parseBracketExpr(Res, EndLoc);
1312 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1318 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1324 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1331bool AsmParser::parseExpression(
const MCExpr *&Res) {
1333 return parseExpression(Res, EndLoc);
1343 switch (E->getKind()) {
1354 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1355 "' (already modified)");
1406 "Argument to the function cannot be a NULL value");
1408 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1409 (*CharPtr !=
'\0')) {
1410 if (*CharPtr ==
'!')
1414 if (*CharPtr ==
'>') {
1424 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1425 if (AltMacroStr[Pos] ==
'!')
1427 Res += AltMacroStr[Pos];
1435 return TokError(
"expected specifier following '@'");
1437 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1439 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1459bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1462 auto &TS = getTargetParser();
1463 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1471 return TokError(
"unexpected symbol modifier following '@'");
1475 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1477 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1479 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1480 "' (no symbols present)");
1490 if (Res->evaluateAsAbsolute(
Value))
1496bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1498 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1501bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1504 SMLoc StartLoc = Lexer.
getLoc();
1505 if (parseExpression(Expr))
1508 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1509 return Error(StartLoc,
"expected absolute expression");
1516 bool ShouldUseLogicalShr) {
1593 bool ShouldUseLogicalShr) {
1682bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1684 SMLoc StartLoc = Lexer.
getLoc();
1687 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1691 if (TokPrec < Precedence)
1698 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1704 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1705 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1717bool AsmParser::parseStatement(ParseStatementInfo &Info,
1718 MCAsmParserSemaCallback *SI) {
1719 assert(!hasPendingError() &&
"parseStatement started with pending error");
1725 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1726 getTok().getString().
front() ==
'\n')
1732 AsmToken
ID = getTok();
1733 SMLoc IDLoc =
ID.getLoc();
1735 int64_t LocalLabelVal = -1;
1736 StartTokLoc =
ID.getLoc();
1738 return parseCppHashLineFilenameComment(IDLoc,
1739 !isInsideMacroInstantiation());
1743 LocalLabelVal = getTok().getIntVal();
1744 if (LocalLabelVal < 0) {
1745 if (!TheCondState.
Ignore) {
1747 return Error(IDLoc,
"unexpected token at start of statement");
1751 IDVal = getTok().getString();
1754 if (!TheCondState.
Ignore) {
1756 return Error(IDLoc,
"unexpected token at start of statement");
1764 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1766 IDVal =
ID.getString();
1767 }
else if (parseIdentifier(IDVal)) {
1768 if (!TheCondState.
Ignore) {
1770 return Error(IDLoc,
"unexpected token at start of statement");
1779 DirectiveKindMap.find(IDVal.
lower());
1780 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1782 : DirKindIt->getValue();
1793 return parseDirectiveIf(IDLoc, DirKind);
1795 return parseDirectiveIfb(IDLoc,
true);
1797 return parseDirectiveIfb(IDLoc,
false);
1799 return parseDirectiveIfc(IDLoc,
true);
1801 return parseDirectiveIfeqs(IDLoc,
true);
1803 return parseDirectiveIfc(IDLoc,
false);
1805 return parseDirectiveIfeqs(IDLoc,
false);
1807 return parseDirectiveIfdef(IDLoc,
true);
1810 return parseDirectiveIfdef(IDLoc,
false);
1812 return parseDirectiveElseIf(IDLoc);
1814 return parseDirectiveElse(IDLoc);
1816 return parseDirectiveEndIf(IDLoc);
1821 if (TheCondState.
Ignore) {
1822 eatToEndOfStatement();
1832 if (checkForValidSection())
1839 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1847 if (LocalLabelVal == -1) {
1848 if (ParsingMSInlineAsm && SI) {
1849 StringRef RewrittenLabel =
1850 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1852 "We should have an internal name here.");
1855 IDVal = RewrittenLabel;
1865 StringRef CommentStr = parseStringToEndOfStatement();
1876 if (MAI.
isMachO() && CFIStartProcLoc) {
1877 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1878 if (SymM->isExternal() && !SymM->isAltEntry())
1879 return Error(StartTokLoc,
"non-private labels cannot appear between "
1880 ".cfi_startproc / .cfi_endproc pairs") &&
1881 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1884 if (discardLTOSymbol(IDVal))
1887 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1890 if (!getTargetParser().isParsingMSInlineAsm())
1895 if (enabledGenDwarfForAssembly())
1899 getTargetParser().onLabelParsed(Sym);
1908 return parseAssignment(IDVal, AssignmentKind::Equal);
1912 if (areMacrosEnabled())
1913 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1914 return handleMacroEntry(M, IDLoc);
1931 getTargetParser().flushPendingInstructions(getStreamer());
1933 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
1935 "Should only return Failure iff there was an error");
1943 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1944 ExtensionDirectiveMap.
lookup(IDVal);
1946 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1955 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1957 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1958 case DK_LTO_SET_CONDITIONAL:
1959 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1961 return parseDirectiveAscii(IDVal,
false);
1964 return parseDirectiveAscii(IDVal,
true);
1966 return parseDirectiveBase64();
1969 return parseDirectiveValue(IDVal, 1);
1975 return parseDirectiveValue(IDVal, 2);
1980 return parseDirectiveValue(IDVal, 4);
1983 return parseDirectiveValue(IDVal, 8);
1985 return parseDirectiveValue(
1986 IDVal,
getContext().getAsmInfo().getCodePointerSize());
1988 return parseDirectiveOctaValue(IDVal);
1992 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1995 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1997 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
1998 return parseDirectiveAlign(IsPow2, 1);
2001 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2002 return parseDirectiveAlign(IsPow2, 4);
2005 return parseDirectiveAlign(
false, 1);
2007 return parseDirectiveAlign(
false, 2);
2009 return parseDirectiveAlign(
false, 4);
2011 return parseDirectiveAlign(
true, 1);
2013 return parseDirectiveAlign(
true, 2);
2015 return parseDirectiveAlign(
true, 4);
2017 return parseDirectivePrefAlign();
2019 return parseDirectiveOrg();
2021 return parseDirectiveFill();
2023 return parseDirectiveZero();
2025 eatToEndOfStatement();
2029 return parseDirectiveSymbolAttribute(
MCSA_Global);
2030 case DK_LAZY_REFERENCE:
2032 case DK_NO_DEAD_STRIP:
2034 case DK_SYMBOL_RESOLVER:
2036 case DK_PRIVATE_EXTERN:
2040 case DK_WEAK_DEFINITION:
2042 case DK_WEAK_REFERENCE:
2044 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2047 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2050 return parseDirectiveComm(
false);
2052 return parseDirectiveComm(
true);
2054 return parseDirectiveAbort(IDLoc);
2056 return parseDirectiveInclude();
2058 return parseDirectiveIncbin();
2061 return TokError(Twine(IDVal) +
2062 " not currently supported for this target");
2064 return parseDirectiveRept(IDLoc, IDVal);
2066 return parseDirectiveIrp(IDLoc);
2068 return parseDirectiveIrpc(IDLoc);
2070 return parseDirectiveEndr(IDLoc);
2072 return parseDirectiveLEB128(
true);
2074 return parseDirectiveLEB128(
false);
2077 return parseDirectiveSpace(IDVal);
2079 return parseDirectiveFile(IDLoc);
2081 return parseDirectiveLine();
2083 return parseDirectiveLoc();
2085 return parseDirectiveLocLabel(IDLoc);
2087 return parseDirectiveStabs();
2089 return parseDirectiveCVFile();
2091 return parseDirectiveCVFuncId();
2092 case DK_CV_INLINE_SITE_ID:
2093 return parseDirectiveCVInlineSiteId();
2095 return parseDirectiveCVLoc();
2096 case DK_CV_LINETABLE:
2097 return parseDirectiveCVLinetable();
2098 case DK_CV_INLINE_LINETABLE:
2099 return parseDirectiveCVInlineLinetable();
2100 case DK_CV_DEF_RANGE:
2101 return parseDirectiveCVDefRange();
2103 return parseDirectiveCVString();
2104 case DK_CV_STRINGTABLE:
2105 return parseDirectiveCVStringTable();
2106 case DK_CV_FILECHECKSUMS:
2107 return parseDirectiveCVFileChecksums();
2108 case DK_CV_FILECHECKSUM_OFFSET:
2109 return parseDirectiveCVFileChecksumOffset();
2110 case DK_CV_FPO_DATA:
2111 return parseDirectiveCVFPOData();
2112 case DK_CFI_SECTIONS:
2113 return parseDirectiveCFISections();
2114 case DK_CFI_STARTPROC:
2115 return parseDirectiveCFIStartProc();
2116 case DK_CFI_ENDPROC:
2117 return parseDirectiveCFIEndProc();
2118 case DK_CFI_DEF_CFA:
2119 return parseDirectiveCFIDefCfa(IDLoc);
2120 case DK_CFI_DEF_CFA_OFFSET:
2121 return parseDirectiveCFIDefCfaOffset(IDLoc);
2122 case DK_CFI_ADJUST_CFA_OFFSET:
2123 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2124 case DK_CFI_DEF_CFA_REGISTER:
2125 return parseDirectiveCFIDefCfaRegister(IDLoc);
2126 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2127 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2129 return parseDirectiveCFIOffset(IDLoc);
2130 case DK_CFI_REL_OFFSET:
2131 return parseDirectiveCFIRelOffset(IDLoc);
2132 case DK_CFI_PERSONALITY:
2133 return parseDirectiveCFIPersonalityOrLsda(
true);
2135 return parseDirectiveCFIPersonalityOrLsda(
false);
2136 case DK_CFI_REMEMBER_STATE:
2137 return parseDirectiveCFIRememberState(IDLoc);
2138 case DK_CFI_RESTORE_STATE:
2139 return parseDirectiveCFIRestoreState(IDLoc);
2140 case DK_CFI_SAME_VALUE:
2141 return parseDirectiveCFISameValue(IDLoc);
2142 case DK_CFI_RESTORE:
2143 return parseDirectiveCFIRestore(IDLoc);
2145 return parseDirectiveCFIEscape(IDLoc);
2146 case DK_CFI_RETURN_COLUMN:
2147 return parseDirectiveCFIReturnColumn(IDLoc);
2148 case DK_CFI_SIGNAL_FRAME:
2149 return parseDirectiveCFISignalFrame(IDLoc);
2150 case DK_CFI_UNDEFINED:
2151 return parseDirectiveCFIUndefined(IDLoc);
2152 case DK_CFI_REGISTER:
2153 return parseDirectiveCFIRegister(IDLoc);
2154 case DK_CFI_WINDOW_SAVE:
2155 return parseDirectiveCFIWindowSave(IDLoc);
2157 return parseDirectiveCFILabel(IDLoc);
2158 case DK_CFI_VAL_OFFSET:
2159 return parseDirectiveCFIValOffset(IDLoc);
2162 return parseDirectiveMacrosOnOff(IDVal);
2164 return parseDirectiveMacro(IDLoc);
2167 return parseDirectiveAltmacro(IDVal);
2169 return parseDirectiveExitMacro(IDVal);
2172 return parseDirectiveEndMacro(IDVal);
2174 return parseDirectivePurgeMacro(IDLoc);
2176 return parseDirectiveEnd(IDLoc);
2178 return parseDirectiveError(IDLoc,
false);
2180 return parseDirectiveError(IDLoc,
true);
2182 return parseDirectiveWarning(IDLoc);
2184 return parseDirectiveReloc(IDLoc);
2187 return parseDirectiveDCB(IDVal, 2);
2189 return parseDirectiveDCB(IDVal, 1);
2191 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2193 return parseDirectiveDCB(IDVal, 4);
2195 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2198 return TokError(Twine(IDVal) +
2199 " not currently supported for this target");
2202 return parseDirectiveDS(IDVal, 2);
2204 return parseDirectiveDS(IDVal, 1);
2206 return parseDirectiveDS(IDVal, 8);
2209 return parseDirectiveDS(IDVal, 4);
2212 return parseDirectiveDS(IDVal, 12);
2214 return parseDirectivePrint(IDLoc);
2216 return parseDirectiveAddrsig();
2217 case DK_ADDRSIG_SYM:
2218 return parseDirectiveAddrsigSym();
2219 case DK_PSEUDO_PROBE:
2220 return parseDirectivePseudoProbe();
2221 case DK_LTO_DISCARD:
2222 return parseDirectiveLTODiscard();
2224 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2227 return Error(IDLoc,
"unknown directive");
2231 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2232 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2233 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2236 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2237 return parseDirectiveMSAlign(IDLoc, Info);
2239 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2241 if (checkForValidSection())
2244 return parseAndMatchAndEmitTargetInstruction(Info, IDVal,
ID, IDLoc);
2247bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2252 std::string OpcodeStr = IDVal.
lower();
2253 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2254 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr,
ID,
2255 Info.ParsedOperands);
2256 Info.ParseError = ParseHadError;
2259 if (getShowParsedOperands()) {
2260 SmallString<256> Str;
2261 raw_svector_ostream OS(Str);
2262 OS <<
"parsed instruction: [";
2263 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2266 Info.ParsedOperands[i]->print(OS, MAI);
2274 if (hasPendingError() || ParseHadError)
2279 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2281 getStreamer().getCurrentSectionOnly())) {
2283 if (ActiveMacros.empty())
2287 ActiveMacros.front()->ExitBuffer);
2292 if (!CppHashInfo.Filename.empty()) {
2293 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2294 0, StringRef(), CppHashInfo.Filename);
2295 getContext().setGenDwarfFileNumber(FileNumber);
2297 unsigned CppHashLocLineNo =
2299 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2302 getStreamer().emitDwarfLocDirective(
2303 getContext().getGenDwarfFileNumber(), Line, 0,
2309 if (!ParseHadError) {
2311 if (getTargetParser().matchAndEmitInstruction(
2312 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2313 getTargetParser().isParsingMSInlineAsm()))
2321AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2326 SMLoc StartLoc = Lexer.
getLoc();
2339bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2344 "Lexing Cpp line comment: Expected Integer");
2345 int64_t LineNumber = getTok().getIntVal();
2348 "Lexing Cpp line comment: Expected String");
2349 StringRef
Filename = getTok().getString();
2360 CppHashInfo.Loc =
L;
2362 CppHashInfo.LineNumber = LineNumber;
2363 CppHashInfo.Buf = CurBuffer;
2364 if (!HadCppHashFilename) {
2365 HadCppHashFilename =
true;
2375 std::nullopt, std::nullopt);
2383void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2384 auto *Parser =
static_cast<AsmParser *
>(
Context);
2385 raw_ostream &OS =
errs();
2388 SMLoc DiagLoc = Diag.
getLoc();
2390 unsigned CppHashBuf =
2391 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2396 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2405 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2406 if (Parser->SavedDiagHandler)
2407 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2409 Parser->getContext().diagnose(Diag);
2416 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2419 int CppHashLocLineNo =
2420 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2422 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2428 if (Parser->SavedDiagHandler)
2429 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2431 Parser->getContext().diagnose(NewDiag);
2439 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2443bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2446 bool EnableAtPseudoVariable) {
2448 auto expandArg = [&](
unsigned Index) {
2449 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2450 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2451 for (
const AsmToken &Token :
A[Index])
2459 if (AltMacroMode && Token.getString().front() ==
'%' &&
2462 OS << Token.getIntVal();
2465 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2472 OS << Token.getString();
2474 OS << Token.getStringContents();
2479 StringRef Body =
Macro.Body;
2480 size_t I = 0, End = Body.
size();
2482 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2484 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2485 OS << NumOfMacroInstantiations;
2489 if (Body[
I + 1] ==
'+') {
2494 if (Body[
I + 1] ==
'(' && Body[
I + 2] ==
')') {
2503 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2507 if (Parameters[Index].Name == Argument)
2509 if (Index == NParameters)
2518 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2520 switch (Body[
I + 1]) {
2536 unsigned Index = Body[
I + 1] -
'0';
2537 if (Index <
A.size())
2538 for (
const AsmToken &Token :
A[Index])
2539 OS << Token.getString();
2554 StringRef Token(Body.
data() + Start,
I - Start);
2558 if (Parameters[Index].Name == Token)
2560 if (Index != NParameters) {
2562 if (
I != End && Body[
I] ==
'&')
2606class AsmLexerSkipSpaceRAII {
2608 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2612 ~AsmLexerSkipSpaceRAII() {
2622bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2626 StringRef Str = parseStringToEndOfStatement();
2632 unsigned ParenLevel = 0;
2635 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2642 return TokError(
"unexpected token in macro instantiation");
2644 if (ParenLevel == 0) {
2657 MA.push_back(getTok());
2681 MA.push_back(getTok());
2685 if (ParenLevel != 0)
2686 return TokError(
"unbalanced parentheses in macro argument");
2691bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2692 MCAsmMacroArguments &
A) {
2693 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2694 bool NamedParametersFound =
false;
2695 SmallVector<SMLoc, 4> FALocs;
2697 A.resize(NParameters);
2698 FALocs.
resize(NParameters);
2703 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2704 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2706 SMLoc IDLoc = Lexer.
getLoc();
2707 MCAsmMacroParameter FA;
2710 if (parseIdentifier(FA.
Name))
2711 return Error(IDLoc,
"invalid argument identifier for formal argument");
2714 return TokError(
"expected '=' after formal parameter identifier");
2718 NamedParametersFound =
true;
2720 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2722 if (NamedParametersFound && FA.
Name.
empty())
2723 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2725 SMLoc StrLoc = Lexer.
getLoc();
2728 const MCExpr *AbsoluteExp;
2732 if (parseExpression(AbsoluteExp, EndLoc))
2734 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2735 getStreamer().getAssemblerPtr()))
2736 return Error(StrLoc,
"expected absolute expression");
2740 StringRef(StrChar, EndChar - StrChar),
Value);
2741 FA.
Value.push_back(newToken);
2746 jumpToLoc(EndLoc, CurBuffer);
2750 StringRef(StrChar, EndChar - StrChar));
2751 FA.
Value.push_back(newToken);
2752 }
else if(parseMacroArgument(FA.
Value, Vararg))
2758 for (FAI = 0; FAI < NParameters; ++FAI)
2759 if (
M->Parameters[FAI].Name == FA.
Name)
2762 if (FAI >= NParameters) {
2763 assert(M &&
"expected macro to be defined");
2764 return Error(IDLoc,
"parameter named '" + FA.
Name +
2765 "' does not exist for macro '" +
M->Name +
"'");
2770 if (!FA.
Value.empty()) {
2775 if (FALocs.
size() <= PI)
2778 FALocs[PI] = Lexer.
getLoc();
2786 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2788 if (
M->Parameters[FAI].Required) {
2790 "missing value for required parameter "
2791 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2795 if (!
M->Parameters[FAI].Value.empty())
2796 A[FAI] =
M->Parameters[FAI].Value;
2805 return TokError(
"too many positional arguments");
2808bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2812 if (ActiveMacros.size() == MaxNestingDepth) {
2813 std::ostringstream MaxNestingDepthError;
2814 MaxNestingDepthError <<
"macros cannot be nested more than "
2815 << MaxNestingDepth <<
" levels deep."
2816 <<
" Use -asm-macro-max-nesting-depth to increase "
2818 return TokError(MaxNestingDepthError.str());
2821 MCAsmMacroArguments
A;
2822 if (parseMacroArguments(M,
A))
2827 SmallString<256> Buf;
2828 raw_svector_ostream OS(Buf);
2830 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2831 return Error(getTok().getLoc(),
"Wrong number of arguments");
2832 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2837 OS <<
".endmacro\n";
2839 std::unique_ptr<MemoryBuffer> Instantiation =
2844 MacroInstantiation *
MI =
new MacroInstantiation{
2845 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2846 ActiveMacros.push_back(
MI);
2848 ++NumOfMacroInstantiations;
2858void AsmParser::handleMacroExit() {
2860 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2868 delete ActiveMacros.back();
2869 ActiveMacros.pop_back();
2872bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2874 const MCExpr *
Value;
2875 SMLoc ExprLoc = getTok().getLoc();
2877 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2889 if (discardLTOSymbol(Name))
2894 case AssignmentKind::Equal:
2897 case AssignmentKind::Set:
2898 case AssignmentKind::Equiv:
2902 case AssignmentKind::LTOSetConditional:
2904 return Error(ExprLoc,
"expected identifier");
2916bool AsmParser::parseIdentifier(StringRef &Res) {
2923 SMLoc PrefixLoc = getLexer().getLoc();
2935 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2941 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2949 Res = getTok().getIdentifier();
2961bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2963 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2964 parseAssignment(Name, Kind))
2969bool AsmParser::parseEscapedString(std::string &
Data) {
2974 StringRef Str = getTok().getStringContents();
2975 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
2976 if (Str[i] !=
'\\') {
2977 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
2979 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
2983 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
2994 return TokError(
"unexpected backslash at end of string");
2997 if (Str[i] ==
'x' || Str[i] ==
'X') {
2998 size_t length = Str.size();
2999 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
3000 return TokError(
"invalid hexadecimal escape sequence");
3005 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3013 if ((
unsigned)(Str[i] -
'0') <= 7) {
3015 unsigned Value = Str[i] -
'0';
3017 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3021 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3028 return TokError(
"invalid octal escape sequence (out of range)");
3038 return TokError(
"invalid escape sequence (unrecognized character)");
3040 case 'b':
Data +=
'\b';
break;
3041 case 'f':
Data +=
'\f';
break;
3042 case 'n':
Data +=
'\n';
break;
3043 case 'r':
Data +=
'\r';
break;
3044 case 't':
Data +=
'\t';
break;
3045 case '"':
Data +=
'"';
break;
3046 case '\\':
Data +=
'\\';
break;
3054bool AsmParser::parseAngleBracketString(std::string &
Data) {
3055 SMLoc EndLoc, StartLoc = getTok().getLoc();
3057 const char *StartChar = StartLoc.
getPointer() + 1;
3058 const char *EndChar = EndLoc.
getPointer() - 1;
3059 jumpToLoc(EndLoc, CurBuffer);
3072bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3073 auto parseOp = [&]() ->
bool {
3075 if (checkForValidSection())
3080 if (parseEscapedString(
Data))
3082 getStreamer().emitBytes(
Data);
3085 getStreamer().emitBytes(StringRef(
"\0", 1));
3089 return parseMany(parseOp);
3094bool AsmParser::parseDirectiveBase64() {
3095 auto parseOp = [&]() ->
bool {
3096 if (checkForValidSection())
3103 std::vector<char> Decoded;
3104 std::string
const str = getTok().getStringContents().str();
3105 if (check(str.empty(),
"expected nonempty string")) {
3112 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3115 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3120 return check(parseMany(parseOp),
"expected string");
3125bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3127 const MCExpr *Expr =
nullptr;
3129 if (parseExpression(
Offset))
3141 SMLoc ExprLoc = Lexer.
getLoc();
3142 if (parseExpression(Expr))
3147 return Error(ExprLoc,
"expression must be relocatable");
3153 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3159bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3160 auto parseOp = [&]() ->
bool {
3161 const MCExpr *
Value;
3162 SMLoc ExprLoc = getLexer().getLoc();
3163 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3168 uint64_t IntValue = MCE->getValue();
3170 return Error(ExprLoc,
"out of range literal value");
3171 getStreamer().emitIntValue(IntValue,
Size);
3173 getStreamer().emitValue(
Value,
Size, ExprLoc);
3177 return parseMany(parseOp);
3183 return Asm.TokError(
"unknown token in expression");
3184 SMLoc ExprLoc = Asm.getTok().getLoc();
3185 APInt IntValue = Asm.getTok().getAPIntVal();
3187 if (!IntValue.
isIntN(128))
3188 return Asm.Error(ExprLoc,
"out of range literal value");
3189 if (!IntValue.
isIntN(64)) {
3202bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3203 auto parseOp = [&]() ->
bool {
3204 if (checkForValidSection())
3210 getStreamer().emitInt64(lo);
3211 getStreamer().emitInt64(hi);
3213 getStreamer().emitInt64(hi);
3214 getStreamer().emitInt64(lo);
3219 return parseMany(parseOp);
3222bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3233 return TokError(Lexer.
getErr());
3236 return TokError(
"unexpected token in directive");
3240 StringRef IDVal = getTok().getString();
3248 return TokError(
"invalid floating point literal");
3250 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3252 return TokError(
"invalid floating point literal");
3259 Res =
Value.bitcastToAPInt();
3266bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3267 const fltSemantics &Semantics) {
3268 auto parseOp = [&]() ->
bool {
3270 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3277 return parseMany(parseOp);
3282bool AsmParser::parseDirectiveZero() {
3283 SMLoc NumBytesLoc = Lexer.
getLoc();
3284 const MCExpr *NumBytes;
3285 if (checkForValidSection() || parseExpression(NumBytes))
3291 if (parseAbsoluteExpression(Val))
3297 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3304bool AsmParser::parseDirectiveFill() {
3305 SMLoc NumValuesLoc = Lexer.
getLoc();
3306 const MCExpr *NumValues;
3307 if (checkForValidSection() || parseExpression(NumValues))
3310 int64_t FillSize = 1;
3311 int64_t FillExpr = 0;
3313 SMLoc SizeLoc, ExprLoc;
3316 SizeLoc = getTok().getLoc();
3317 if (parseAbsoluteExpression(FillSize))
3320 ExprLoc = getTok().getLoc();
3321 if (parseAbsoluteExpression(FillExpr))
3329 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3333 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3338 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3340 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3347bool AsmParser::parseDirectiveOrg() {
3349 SMLoc OffsetLoc = Lexer.
getLoc();
3350 if (checkForValidSection() || parseExpression(
Offset))
3354 int64_t FillExpr = 0;
3356 if (parseAbsoluteExpression(FillExpr))
3361 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3367bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3368 SMLoc AlignmentLoc = getLexer().getLoc();
3371 bool HasFillExpr =
false;
3372 int64_t FillExpr = 0;
3373 int64_t MaxBytesToFill = 0;
3376 auto parseAlign = [&]() ->
bool {
3377 if (parseAbsoluteExpression(Alignment))
3385 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3389 if (parseTokenLoc(MaxBytesLoc) ||
3390 parseAbsoluteExpression(MaxBytesToFill))
3396 if (checkForValidSection())
3400 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3407 bool ReturnVal =
false;
3412 if (Alignment >= 32) {
3413 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3417 Alignment = 1ULL << Alignment;
3425 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3429 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3430 Alignment = 1u << 31;
3436 if (MaxBytesToFill < 1) {
3437 ReturnVal |=
Error(MaxBytesLoc,
3438 "alignment directive can never be satisfied in this "
3439 "many bytes, ignoring maximum bytes expression");
3443 if (MaxBytesToFill >= Alignment) {
3444 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3450 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3451 assert(Section &&
"must have section to emit alignment");
3453 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3455 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3463 getStreamer().emitCodeAlignment(
3464 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3467 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3474bool AsmParser::parseDirectivePrefAlign() {
3475 SMLoc AlignmentLoc = getLexer().getLoc();
3477 if (checkForValidSection() || parseAbsoluteExpression(Log2Alignment))
3480 if (Log2Alignment < 0 || Log2Alignment > 63)
3481 return Error(AlignmentLoc,
"log2 alignment must be in the range [0, 63]");
3484 SMLoc SymLoc = getLexer().getLoc();
3488 SymLoc = getLexer().getLoc();
3489 if (parseIdentifier(Name))
3490 return Error(SymLoc,
"expected symbol name");
3494 SMLoc FillLoc = getLexer().getLoc();
3498 bool EmitNops =
false;
3500 SMLoc FillLoc2 = getLexer().getLoc();
3502 getLexer().getTok().getIdentifier() ==
"nop") {
3507 if (parseAbsoluteExpression(FillVal))
3509 if (FillVal < 0 || FillVal > 255)
3510 return Error(FillLoc2,
"fill value must be in range [0, 255]");
3511 Fill =
static_cast<uint8_t
>(FillVal);
3516 if ((EmitNops || Fill != 0) &&
3517 getStreamer().getCurrentSectionOnly()->isBssSection())
3518 return Error(FillLoc,
"non-zero fill in BSS section '" +
3519 getStreamer().getCurrentSectionOnly()->
getName() +
3522 getStreamer().emitPrefAlign(
Align(1ULL << Log2Alignment), *End, EmitNops,
3523 Fill, getTargetParser().getSTI());
3530bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3532 int64_t FileNumber = -1;
3534 FileNumber = getTok().getIntVal();
3538 return TokError(
"negative file number");
3545 if (parseEscapedString(Path))
3548 StringRef Directory;
3550 std::string FilenameData;
3552 if (check(FileNumber == -1,
3553 "explicit path specified, but no file number") ||
3554 parseEscapedString(FilenameData))
3562 uint64_t MD5Hi, MD5Lo;
3563 bool HasMD5 =
false;
3565 std::optional<StringRef>
Source;
3566 bool HasSource =
false;
3567 std::string SourceString;
3572 "unexpected token in '.file' directive") ||
3573 parseIdentifier(Keyword))
3575 if (Keyword ==
"md5") {
3577 if (check(FileNumber == -1,
3578 "MD5 checksum specified, but no file number") ||
3581 }
else if (Keyword ==
"source") {
3583 if (check(FileNumber == -1,
3584 "source specified, but no file number") ||
3586 "unexpected token in '.file' directive") ||
3587 parseEscapedString(SourceString))
3590 return TokError(
"unexpected token in '.file' directive");
3594 if (FileNumber == -1) {
3598 if (
getContext().getAsmInfo().hasSingleParameterDotFile())
3599 getStreamer().emitFileDirective(
Filename);
3609 std::optional<MD5::MD5Result> CKMem;
3612 for (
unsigned i = 0; i != 8; ++i) {
3613 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3614 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3619 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3620 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3621 Source = StringRef(SourceBuf, SourceString.size());
3623 if (FileNumber == 0) {
3627 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3629 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3630 FileNumber, Directory,
Filename, CKMem, Source);
3637 ReportedInconsistentMD5 =
true;
3638 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3647bool AsmParser::parseDirectiveLine() {
3659bool AsmParser::parseDirectiveLoc() {
3660 int64_t FileNumber = 0, LineNumber = 0;
3661 SMLoc Loc = getTok().getLoc();
3662 if (parseIntToken(FileNumber) ||
3664 "file number less than one in '.loc' directive") ||
3665 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3666 "unassigned file number in '.loc' directive"))
3671 LineNumber = getTok().getIntVal();
3673 return TokError(
"line number less than zero in '.loc' directive");
3677 int64_t ColumnPos = 0;
3679 ColumnPos = getTok().getIntVal();
3681 return TokError(
"column position less than zero in '.loc' directive");
3685 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3690 auto parseLocOp = [&]() ->
bool {
3692 SMLoc Loc = getTok().getLoc();
3693 if (parseIdentifier(Name))
3694 return TokError(
"unexpected token in '.loc' directive");
3696 if (Name ==
"basic_block")
3698 else if (Name ==
"prologue_end")
3700 else if (Name ==
"epilogue_begin")
3702 else if (Name ==
"is_stmt") {
3703 Loc = getTok().getLoc();
3704 const MCExpr *
Value;
3705 if (parseExpression(
Value))
3709 int Value = MCE->getValue();
3711 Flags &= ~DWARF2_FLAG_IS_STMT;
3712 else if (
Value == 1)
3715 return Error(Loc,
"is_stmt value not 0 or 1");
3717 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3719 }
else if (Name ==
"isa") {
3720 Loc = getTok().getLoc();
3721 const MCExpr *
Value;
3722 if (parseExpression(
Value))
3726 int Value = MCE->getValue();
3728 return Error(Loc,
"isa number less than zero");
3731 return Error(Loc,
"isa number not a constant value");
3733 }
else if (Name ==
"discriminator") {
3734 if (parseAbsoluteExpression(Discriminator))
3737 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3742 if (parseMany(parseLocOp,
false ))
3745 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3746 Isa, Discriminator, StringRef());
3753bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3755 DirectiveLoc = Lexer.
getLoc();
3756 if (parseIdentifier(Name))
3757 return TokError(
"expected identifier");
3760 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3766bool AsmParser::parseDirectiveStabs() {
3767 return TokError(
"unsupported directive '.stabs'");
3772bool AsmParser::parseDirectiveCVFile() {
3773 SMLoc FileNumberLoc = getTok().getLoc();
3776 std::string Checksum;
3779 if (parseIntToken(FileNumber,
"expected file number") ||
3780 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3782 "unexpected token in '.cv_file' directive") ||
3787 "unexpected token in '.cv_file' directive") ||
3788 parseEscapedString(Checksum) ||
3789 parseIntToken(ChecksumKind,
3790 "expected checksum kind in '.cv_file' directive") ||
3796 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3797 memcpy(CKMem, Checksum.data(), Checksum.size());
3798 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3801 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3802 static_cast<uint8_t
>(ChecksumKind)))
3803 return Error(FileNumberLoc,
"file number already allocated");
3808bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3809 StringRef DirectiveName) {
3811 return parseTokenLoc(Loc) ||
3812 parseIntToken(FunctionId,
"expected function id") ||
3813 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3814 "expected function id within range [0, UINT_MAX)");
3817bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3819 return parseTokenLoc(Loc) ||
3820 parseIntToken(FileNumber,
"expected file number") ||
3821 check(FileNumber < 1, Loc,
3822 "file number less than one in '" + DirectiveName +
3824 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3825 "unassigned file number in '" + DirectiveName +
"' directive");
3832bool AsmParser::parseDirectiveCVFuncId() {
3833 SMLoc FunctionIdLoc = getTok().getLoc();
3836 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3839 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3840 return Error(FunctionIdLoc,
"function id already allocated");
3853bool AsmParser::parseDirectiveCVInlineSiteId() {
3854 SMLoc FunctionIdLoc = getTok().getLoc();
3862 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3867 getTok().getIdentifier() !=
"within"),
3868 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3873 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3878 getTok().getIdentifier() !=
"inlined_at"),
3879 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3885 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3886 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3891 IACol = getTok().getIntVal();
3898 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3899 IALine, IACol, FunctionIdLoc))
3900 return Error(FunctionIdLoc,
"function id already allocated");
3912bool AsmParser::parseDirectiveCVLoc() {
3913 SMLoc DirectiveLoc = getTok().getLoc();
3914 int64_t FunctionId, FileNumber;
3915 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3916 parseCVFileId(FileNumber,
".cv_loc"))
3919 int64_t LineNumber = 0;
3921 LineNumber = getTok().getIntVal();
3923 return TokError(
"line number less than zero in '.cv_loc' directive");
3927 int64_t ColumnPos = 0;
3929 ColumnPos = getTok().getIntVal();
3931 return TokError(
"column position less than zero in '.cv_loc' directive");
3935 bool PrologueEnd =
false;
3936 uint64_t IsStmt = 0;
3938 auto parseOp = [&]() ->
bool {
3940 SMLoc Loc = getTok().getLoc();
3941 if (parseIdentifier(Name))
3942 return TokError(
"unexpected token in '.cv_loc' directive");
3943 if (Name ==
"prologue_end")
3945 else if (Name ==
"is_stmt") {
3946 Loc = getTok().getLoc();
3947 const MCExpr *
Value;
3948 if (parseExpression(
Value))
3953 IsStmt = MCE->getValue();
3956 return Error(Loc,
"is_stmt value not 0 or 1");
3958 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3963 if (parseMany(parseOp,
false ))
3966 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3967 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3974bool AsmParser::parseDirectiveCVLinetable() {
3977 SMLoc Loc = getTok().getLoc();
3978 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3979 parseTokenLoc(Loc) ||
3980 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
3981 parseComma() || parseTokenLoc(Loc) ||
3982 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
3985 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3991bool AsmParser::parseDirectiveCVInlineLinetable() {
3992 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3994 SMLoc Loc = getTok().getLoc();
3995 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3996 parseTokenLoc(Loc) ||
3997 parseIntToken(SourceFileId,
"expected SourceField") ||
3998 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
3999 parseTokenLoc(Loc) ||
4000 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
4001 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
4002 parseTokenLoc(Loc) ||
4003 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
4004 parseTokenLoc(Loc) ||
4005 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
4011 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
4012 SourceLineNum, FnStartSym,
4017void AsmParser::initializeCVDefRangeTypeMap() {
4018 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
4019 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
4020 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4021 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4022 CVDefRangeTypeMap[
"reg_rel_indir"] = CVDR_DEFRANGE_REGISTER_REL_INDIR;
4027bool AsmParser::parseDirectiveCVDefRange() {
4029 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
4031 Loc = getLexer().getLoc();
4034 return Error(Loc,
"expected identifier in directive");
4036 Loc = getLexer().getLoc();
4039 return Error(Loc,
"expected identifier in directive");
4041 Ranges.push_back({GapStartSym, GapEndSym});
4044 StringRef CVDefRangeTypeStr;
4047 "expected comma before def_range type in .cv_def_range directive") ||
4048 parseIdentifier(CVDefRangeTypeStr))
4049 return Error(Loc,
"expected def_range type in directive");
4052 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4053 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4055 : CVTypeIt->getValue();
4057 case CVDR_DEFRANGE_REGISTER: {
4059 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4060 ".cv_def_range directive") ||
4061 parseAbsoluteExpression(DRRegister))
4062 return Error(Loc,
"expected register number");
4064 codeview::DefRangeRegisterHeader DRHdr;
4067 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4070 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4073 "expected comma before offset in .cv_def_range directive") ||
4074 parseAbsoluteExpression(DROffset))
4075 return Error(Loc,
"expected offset value");
4077 codeview::DefRangeFramePointerRelHeader DRHdr;
4079 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4082 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4084 int64_t DROffsetInParent;
4085 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4086 ".cv_def_range directive") ||
4087 parseAbsoluteExpression(DRRegister))
4088 return Error(Loc,
"expected register number");
4090 "expected comma before offset in .cv_def_range directive") ||
4091 parseAbsoluteExpression(DROffsetInParent))
4092 return Error(Loc,
"expected offset value");
4094 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4098 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4101 case CVDR_DEFRANGE_REGISTER_REL: {
4104 int64_t DRBasePointerOffset;
4105 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4106 ".cv_def_range directive") ||
4107 parseAbsoluteExpression(DRRegister))
4108 return Error(Loc,
"expected register value");
4111 "expected comma before flag value in .cv_def_range directive") ||
4112 parseAbsoluteExpression(DRFlags))
4113 return Error(Loc,
"expected flag value");
4114 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4115 "in .cv_def_range directive") ||
4116 parseAbsoluteExpression(DRBasePointerOffset))
4117 return Error(Loc,
"expected base pointer offset value");
4119 codeview::DefRangeRegisterRelHeader DRHdr;
4121 DRHdr.
Flags = DRFlags;
4123 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4126 case CVDR_DEFRANGE_REGISTER_REL_INDIR: {
4129 int64_t DRBasePointerOffset;
4130 int64_t DROffsetInUdt;
4131 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4132 ".cv_def_range directive") ||
4133 parseAbsoluteExpression(DRRegister))
4134 return Error(Loc,
"expected register value");
4137 "expected comma before flag value in .cv_def_range directive") ||
4138 parseAbsoluteExpression(DRFlags))
4139 return Error(Loc,
"expected flag value");
4140 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4141 "in .cv_def_range directive") ||
4142 parseAbsoluteExpression(DRBasePointerOffset))
4143 return Error(Loc,
"expected base pointer offset value");
4144 if (parseToken(
AsmToken::Comma,
"expected comma before offset in UDT "
4145 "in .cv_def_range directive") ||
4146 parseAbsoluteExpression(DROffsetInUdt))
4147 return Error(Loc,
"expected offset in UDT value");
4149 codeview::DefRangeRegisterRelIndirHeader DRHdr;
4151 DRHdr.
Flags = DRFlags;
4154 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4158 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4165bool AsmParser::parseDirectiveCVString() {
4167 if (checkForValidSection() || parseEscapedString(
Data))
4171 std::pair<StringRef, unsigned> Insertion =
4172 getCVContext().addToStringTable(
Data);
4173 getStreamer().emitInt32(Insertion.second);
4179bool AsmParser::parseDirectiveCVStringTable() {
4180 getStreamer().emitCVStringTableDirective();
4186bool AsmParser::parseDirectiveCVFileChecksums() {
4187 getStreamer().emitCVFileChecksumsDirective();
4193bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4195 if (parseIntToken(FileNo))
4199 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4205bool AsmParser::parseDirectiveCVFPOData() {
4206 SMLoc DirLoc = getLexer().getLoc();
4209 return TokError(
"expected symbol name");
4212 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4218bool AsmParser::parseDirectiveCFISections() {
4222 bool SFrame =
false;
4226 if (parseIdentifier(Name))
4227 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4228 if (Name ==
".eh_frame")
4230 else if (Name ==
".debug_frame")
4232 else if (Name ==
".sframe")
4240 getStreamer().emitCFISections(EH,
Debug, SFrame);
4246bool AsmParser::parseDirectiveCFIStartProc() {
4247 CFIStartProcLoc = StartTokLoc;
4251 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4252 "unexpected token") ||
4262 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4268bool AsmParser::parseDirectiveCFIEndProc() {
4269 CFIStartProcLoc = std::nullopt;
4274 getStreamer().emitCFIEndProc();
4279bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4280 SMLoc DirectiveLoc) {
4284 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4288 return parseAbsoluteExpression(
Register);
4295bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4297 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4298 parseAbsoluteExpression(
Offset) || parseEOL())
4307bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4309 if (parseAbsoluteExpression(
Offset) || parseEOL())
4312 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4318bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4319 int64_t Register1 = 0, Register2 = 0;
4320 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4321 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4324 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4330bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4333 getStreamer().emitCFIWindowSave(DirectiveLoc);
4339bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4340 int64_t Adjustment = 0;
4341 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4344 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4350bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4352 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4355 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4361bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4363 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4364 parseAbsoluteExpression(
Offset) || parseComma() ||
4375bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4379 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4380 parseAbsoluteExpression(
Offset) || parseEOL())
4389bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4392 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4393 parseAbsoluteExpression(
Offset) || parseEOL())
4401 if (Encoding & ~0xff)
4407 const unsigned Format = Encoding & 0xf;
4414 const unsigned Application = Encoding & 0x70;
4426bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4427 int64_t Encoding = 0;
4428 if (parseAbsoluteExpression(Encoding))
4436 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4440 getStreamer().emitCFIPersonality(Sym, Encoding);
4442 getStreamer().emitCFILsda(Sym, Encoding);
4448bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4451 getStreamer().emitCFIRememberState(DirectiveLoc);
4457bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4460 getStreamer().emitCFIRestoreState(DirectiveLoc);
4466bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4469 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4472 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4478bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4480 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4483 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4489bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4492 if (parseAbsoluteExpression(CurrValue))
4495 Values.push_back((uint8_t)CurrValue);
4500 if (parseAbsoluteExpression(CurrValue))
4503 Values.push_back((uint8_t)CurrValue);
4506 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4512bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4514 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4516 getStreamer().emitCFIReturnColumn(
Register);
4522bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4526 getStreamer().emitCFISignalFrame();
4532bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4535 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4538 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4544bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4547 if (parseIdentifier(Name))
4548 return TokError(
"expected identifier");
4551 getStreamer().emitCFILabelDirective(Loc, Name);
4557bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4561 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4562 parseAbsoluteExpression(
Offset) || parseEOL())
4572bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4575 AltMacroMode = (Directive ==
".altmacro");
4582bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4585 setMacrosEnabled(Directive ==
".macros_on");
4591bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4593 if (parseIdentifier(Name))
4594 return TokError(
"expected identifier in '.macro' directive");
4603 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4605 "' should be the last parameter");
4609 return TokError(
"expected identifier in '.macro' directive");
4612 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4614 return TokError(
"macro '" + Name +
"' has multiple parameters"
4623 QualLoc = Lexer.
getLoc();
4624 if (parseIdentifier(Qualifier))
4625 return Error(QualLoc,
"missing parameter qualifier for "
4626 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4628 if (Qualifier ==
"req")
4630 else if (Qualifier ==
"vararg")
4633 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4634 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4642 ParamLoc = Lexer.
getLoc();
4643 if (parseMacroArgument(
Parameter.Value,
false ))
4647 Warning(ParamLoc,
"pointless default value for required parameter "
4648 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4661 AsmToken EndToken, StartToken = getTok();
4662 unsigned MacroDepth = 0;
4672 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4677 if (getTok().getIdentifier() ==
".endm" ||
4678 getTok().getIdentifier() ==
".endmacro") {
4679 if (MacroDepth == 0) {
4680 EndToken = getTok();
4683 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4690 }
else if (getTok().getIdentifier() ==
".macro") {
4696 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4700 eatToEndOfStatement();
4704 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4709 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4710 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4711 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4732void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4738 if (NParameters == 0)
4741 bool NamedParametersFound =
false;
4742 bool PositionalParametersFound =
false;
4747 while (!Body.
empty()) {
4749 std::size_t End = Body.
size(), Pos = 0;
4750 for (; Pos != End; ++Pos) {
4753 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4757 if (Body[Pos] !=
'$' || Pos + 1 == End)
4759 char Next = Body[Pos + 1];
4761 isdigit(
static_cast<unsigned char>(
Next)))
4769 if (Body[Pos] ==
'$') {
4770 switch (Body[Pos + 1]) {
4777 PositionalParametersFound =
true;
4782 PositionalParametersFound =
true;
4788 unsigned I = Pos + 1;
4792 const char *Begin = Body.
data() + Pos + 1;
4793 StringRef
Argument(Begin,
I - (Pos + 1));
4796 if (Parameters[Index].Name == Argument)
4799 if (Index == NParameters) {
4800 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4806 NamedParametersFound =
true;
4814 if (!NamedParametersFound && PositionalParametersFound)
4815 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4816 "used in macro body, possible positional parameter "
4817 "found in body which will have no effect");
4822bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4826 if (!isInsideMacroInstantiation())
4827 return TokError(
"unexpected '" + Directive +
"' in file, "
4828 "no current macro definition");
4831 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4832 TheCondState = TheCondStack.back();
4833 TheCondStack.pop_back();
4843bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4845 return TokError(
"unexpected token in '" + Directive +
"' directive");
4849 if (isInsideMacroInstantiation()) {
4856 return TokError(
"unexpected '" + Directive +
"' in file, "
4857 "no current macro definition");
4862bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4865 if (parseTokenLoc(Loc) ||
4866 check(parseIdentifier(Name), Loc,
4867 "expected identifier in '.purgem' directive") ||
4872 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4876 <<
"Un-defining macro: " << Name <<
"\n");
4882bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4883 SMLoc NumBytesLoc = Lexer.
getLoc();
4884 const MCExpr *NumBytes;
4885 if (checkForValidSection() || parseExpression(NumBytes))
4888 int64_t FillExpr = 0;
4890 if (parseAbsoluteExpression(FillExpr))
4896 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4903bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
4904 SMLoc NumValuesLoc = Lexer.
getLoc();
4906 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4909 if (NumValues < 0) {
4910 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4917 const MCExpr *
Value;
4918 SMLoc ExprLoc = getLexer().getLoc();
4919 if (parseExpression(
Value))
4925 uint64_t IntValue = MCE->getValue();
4927 return Error(ExprLoc,
"literal value out of range for directive");
4928 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4929 getStreamer().emitIntValue(IntValue,
Size);
4931 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4932 getStreamer().emitValue(
Value,
Size, ExprLoc);
4940bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
4941 SMLoc NumValuesLoc = Lexer.
getLoc();
4943 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4946 if (NumValues < 0) {
4947 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4955 if (parseRealValue(Semantics, AsInt) || parseEOL())
4958 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4967bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
4968 SMLoc NumValuesLoc = Lexer.
getLoc();
4970 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4974 if (NumValues < 0) {
4975 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
4979 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
4980 getStreamer().emitFill(
Size, 0);
4987bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4988 if (checkForValidSection())
4991 auto parseOp = [&]() ->
bool {
4992 const MCExpr *
Value;
4993 if (parseExpression(
Value))
4996 getStreamer().emitSLEB128Value(
Value);
4998 getStreamer().emitULEB128Value(
Value);
5002 return parseMany(parseOp);
5007bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
5008 auto parseOp = [&]() ->
bool {
5010 SMLoc Loc = getTok().getLoc();
5011 if (parseIdentifier(Name))
5012 return Error(Loc,
"expected identifier");
5014 if (discardLTOSymbol(Name))
5022 return Error(Loc,
"non-local symbol required");
5024 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
5025 return Error(Loc,
"unable to emit symbol attribute");
5029 return parseMany(parseOp);
5034bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5035 if (checkForValidSection())
5038 SMLoc IDLoc = getLexer().getLoc();
5041 return TokError(
"expected identifier in directive");
5047 SMLoc SizeLoc = getLexer().getLoc();
5048 if (parseAbsoluteExpression(
Size))
5051 int64_t Pow2Alignment = 0;
5052 SMLoc Pow2AlignmentLoc;
5055 Pow2AlignmentLoc = getLexer().getLoc();
5056 if (parseAbsoluteExpression(Pow2Alignment))
5061 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5067 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5068 Pow2Alignment =
Log2_64(Pow2Alignment);
5078 return Error(SizeLoc,
"size must be non-negative");
5082 return Error(IDLoc,
"invalid symbol redefinition");
5086 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5087 Align(1ULL << Pow2Alignment));
5091 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
5097bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5098 StringRef Str = parseStringToEndOfStatement();
5103 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5106 return Error(DirectiveLoc,
5107 ".abort '" + Str +
"' detected. Assembly stopping");
5112bool AsmParser::parseDirectiveInclude() {
5115 SMLoc IncludeLoc = getTok().getLoc();
5118 "expected string in '.include' directive") ||
5121 "unexpected token in '.include' directive") ||
5124 check(enterIncludeFile(
Filename), IncludeLoc,
5125 "Could not find include file '" +
Filename +
"'"))
5133bool AsmParser::parseDirectiveIncbin() {
5136 SMLoc IncbinLoc = getTok().getLoc();
5138 "expected string in '.incbin' directive") ||
5143 const MCExpr *
Count =
nullptr;
5144 SMLoc SkipLoc, CountLoc;
5149 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5153 CountLoc = getTok().getLoc();
5154 if (parseExpression(
Count))
5162 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5167 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5173bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5174 TheCondStack.push_back(TheCondState);
5176 if (TheCondState.
Ignore) {
5177 eatToEndOfStatement();
5180 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5190 ExprValue = ExprValue == 0;
5193 ExprValue = ExprValue >= 0;
5196 ExprValue = ExprValue > 0;
5199 ExprValue = ExprValue <= 0;
5202 ExprValue = ExprValue < 0;
5206 TheCondState.
CondMet = ExprValue;
5215bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5216 TheCondStack.push_back(TheCondState);
5219 if (TheCondState.
Ignore) {
5220 eatToEndOfStatement();
5222 StringRef Str = parseStringToEndOfStatement();
5227 TheCondState.
CondMet = ExpectBlank == Str.empty();
5237bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5238 TheCondStack.push_back(TheCondState);
5241 if (TheCondState.
Ignore) {
5242 eatToEndOfStatement();
5244 StringRef Str1 = parseStringToComma();
5249 StringRef Str2 = parseStringToEndOfStatement();
5263bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5264 TheCondStack.push_back(TheCondState);
5267 if (TheCondState.
Ignore) {
5268 eatToEndOfStatement();
5272 return TokError(
"expected string parameter for '.ifeqs' directive");
5273 return TokError(
"expected string parameter for '.ifnes' directive");
5276 StringRef String1 = getTok().getStringContents();
5282 "expected comma after first string for '.ifeqs' directive");
5284 "expected comma after first string for '.ifnes' directive");
5291 return TokError(
"expected string parameter for '.ifeqs' directive");
5292 return TokError(
"expected string parameter for '.ifnes' directive");
5295 StringRef String2 = getTok().getStringContents();
5298 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5307bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5309 TheCondStack.push_back(TheCondState);
5312 if (TheCondState.
Ignore) {
5313 eatToEndOfStatement();
5315 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5333bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5336 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5337 " .if or an .elseif");
5340 bool LastIgnoreState =
false;
5341 if (!TheCondStack.empty())
5342 LastIgnoreState = TheCondStack.back().Ignore;
5343 if (LastIgnoreState || TheCondState.
CondMet) {
5344 TheCondState.
Ignore =
true;
5345 eatToEndOfStatement();
5348 if (parseAbsoluteExpression(ExprValue))
5354 TheCondState.
CondMet = ExprValue;
5363bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5369 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5370 " an .if or an .elseif");
5372 bool LastIgnoreState =
false;
5373 if (!TheCondStack.empty())
5374 LastIgnoreState = TheCondStack.back().Ignore;
5375 if (LastIgnoreState || TheCondState.
CondMet)
5376 TheCondState.
Ignore =
true;
5378 TheCondState.
Ignore =
false;
5385bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5398bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5399 if (!TheCondStack.empty()) {
5400 if (TheCondStack.back().Ignore) {
5401 eatToEndOfStatement();
5407 return Error(L,
".err encountered");
5409 StringRef Message =
".error directive invoked in source file";
5412 return TokError(
".error argument must be a string");
5414 Message = getTok().getStringContents();
5418 return Error(L, Message);
5423bool AsmParser::parseDirectiveWarning(SMLoc L) {
5424 if (!TheCondStack.empty()) {
5425 if (TheCondStack.back().Ignore) {
5426 eatToEndOfStatement();
5431 StringRef Message =
".warning directive invoked in source file";
5435 return TokError(
".warning argument must be a string");
5437 Message = getTok().getStringContents();
5448bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5453 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5455 if (!TheCondStack.empty()) {
5456 TheCondState = TheCondStack.back();
5457 TheCondStack.pop_back();
5463void AsmParser::initializeDirectiveKindMap() {
5470 DirectiveKindMap[
".set"] = DK_SET;
5471 DirectiveKindMap[
".equ"] = DK_EQU;
5472 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5473 DirectiveKindMap[
".ascii"] = DK_ASCII;
5474 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5475 DirectiveKindMap[
".string"] = DK_STRING;
5476 DirectiveKindMap[
".byte"] = DK_BYTE;
5477 DirectiveKindMap[
".base64"] = DK_BASE64;
5478 DirectiveKindMap[
".short"] = DK_SHORT;
5479 DirectiveKindMap[
".value"] = DK_VALUE;
5480 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5481 DirectiveKindMap[
".long"] = DK_LONG;
5482 DirectiveKindMap[
".int"] = DK_INT;
5483 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5484 DirectiveKindMap[
".quad"] = DK_QUAD;
5485 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5486 DirectiveKindMap[
".octa"] = DK_OCTA;
5487 DirectiveKindMap[
".single"] = DK_SINGLE;
5488 DirectiveKindMap[
".float"] = DK_FLOAT;
5489 DirectiveKindMap[
".double"] = DK_DOUBLE;
5490 DirectiveKindMap[
".align"] = DK_ALIGN;
5491 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5492 DirectiveKindMap[
".balign"] = DK_BALIGN;
5493 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5494 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5495 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5496 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5497 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5498 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5499 DirectiveKindMap[
".org"] = DK_ORG;
5500 DirectiveKindMap[
".fill"] = DK_FILL;
5501 DirectiveKindMap[
".zero"] = DK_ZERO;
5502 DirectiveKindMap[
".extern"] = DK_EXTERN;
5503 DirectiveKindMap[
".globl"] = DK_GLOBL;
5504 DirectiveKindMap[
".global"] = DK_GLOBAL;
5505 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5506 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5507 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5508 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5509 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5510 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5511 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5512 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5513 DirectiveKindMap[
".cold"] = DK_COLD;
5514 DirectiveKindMap[
".comm"] = DK_COMM;
5515 DirectiveKindMap[
".common"] = DK_COMMON;
5516 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5517 DirectiveKindMap[
".abort"] = DK_ABORT;
5518 DirectiveKindMap[
".include"] = DK_INCLUDE;
5519 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5520 DirectiveKindMap[
".code16"] = DK_CODE16;
5521 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5522 DirectiveKindMap[
".rept"] = DK_REPT;
5523 DirectiveKindMap[
".rep"] = DK_REPT;
5524 DirectiveKindMap[
".irp"] = DK_IRP;
5525 DirectiveKindMap[
".irpc"] = DK_IRPC;
5526 DirectiveKindMap[
".endr"] = DK_ENDR;
5527 DirectiveKindMap[
".if"] = DK_IF;
5528 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5529 DirectiveKindMap[
".ifge"] = DK_IFGE;
5530 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5531 DirectiveKindMap[
".ifle"] = DK_IFLE;
5532 DirectiveKindMap[
".iflt"] = DK_IFLT;
5533 DirectiveKindMap[
".ifne"] = DK_IFNE;
5534 DirectiveKindMap[
".ifb"] = DK_IFB;
5535 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5536 DirectiveKindMap[
".ifc"] = DK_IFC;
5537 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5538 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5539 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5540 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5541 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5542 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5543 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5544 DirectiveKindMap[
".else"] = DK_ELSE;
5545 DirectiveKindMap[
".end"] = DK_END;
5546 DirectiveKindMap[
".endif"] = DK_ENDIF;
5547 DirectiveKindMap[
".skip"] = DK_SKIP;
5548 DirectiveKindMap[
".space"] = DK_SPACE;
5549 DirectiveKindMap[
".file"] = DK_FILE;
5550 DirectiveKindMap[
".line"] = DK_LINE;
5551 DirectiveKindMap[
".loc"] = DK_LOC;
5552 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5553 DirectiveKindMap[
".stabs"] = DK_STABS;
5554 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5555 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5556 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5557 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5558 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5559 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5560 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5561 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5562 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5563 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5564 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5565 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5566 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5567 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5568 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5569 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5570 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5571 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5572 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5573 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5574 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5575 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5576 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5577 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5578 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5579 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5580 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5581 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5582 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5583 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5584 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5585 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5586 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5587 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5588 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5589 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5590 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5591 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5592 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5593 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5594 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5595 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5596 DirectiveKindMap[
".macro"] = DK_MACRO;
5597 DirectiveKindMap[
".exitm"] = DK_EXITM;
5598 DirectiveKindMap[
".endm"] = DK_ENDM;
5599 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5600 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5601 DirectiveKindMap[
".err"] = DK_ERR;
5602 DirectiveKindMap[
".error"] = DK_ERROR;
5603 DirectiveKindMap[
".warning"] = DK_WARNING;
5604 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5605 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5606 DirectiveKindMap[
".reloc"] = DK_RELOC;
5607 DirectiveKindMap[
".dc"] = DK_DC;
5608 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5609 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5610 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5611 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5612 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5613 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5614 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5615 DirectiveKindMap[
".dcb"] = DK_DCB;
5616 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5617 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5618 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5619 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5620 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5621 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5622 DirectiveKindMap[
".ds"] = DK_DS;
5623 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5624 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5625 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5626 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5627 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5628 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5629 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5630 DirectiveKindMap[
".print"] = DK_PRINT;
5631 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5632 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5633 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5634 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5635 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5636 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5639MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5640 AsmToken EndToken, StartToken = getTok();
5642 unsigned NestLevel = 0;
5646 printError(DirectiveLoc,
"no matching '.endr' in definition");
5651 StringRef Ident = getTok().getIdentifier();
5652 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5655 }
else if (Ident ==
".endr") {
5656 if (NestLevel == 0) {
5657 EndToken = getTok();
5661 printError(getTok().getLoc(),
"expected newline");
5669 eatToEndOfStatement();
5674 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5678 return &MacroLikeBodies.back();
5681void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5682 raw_svector_ostream &OS) {
5685 std::unique_ptr<MemoryBuffer> Instantiation =
5690 MacroInstantiation *
MI =
new MacroInstantiation{
5691 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5692 ActiveMacros.push_back(
MI);
5702bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5703 const MCExpr *CountExpr;
5704 SMLoc CountLoc = getTok().getLoc();
5705 if (parseExpression(CountExpr))
5709 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5710 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5713 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5717 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5723 SmallString<256> Buf;
5724 raw_svector_ostream OS(Buf);
5727 if (expandMacro(OS, *M, {}, {},
false))
5730 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5737bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5739 MCAsmMacroArguments
A;
5740 if (check(parseIdentifier(
Parameter.Name),
5741 "expected identifier in '.irp' directive") ||
5742 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5746 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5752 SmallString<256> Buf;
5753 raw_svector_ostream OS(Buf);
5755 for (
const MCAsmMacroArgument &Arg :
A) {
5758 if (expandMacro(OS, *M, Parameter, Arg,
true))
5762 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5769bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5771 MCAsmMacroArguments
A;
5773 if (check(parseIdentifier(
Parameter.Name),
5774 "expected identifier in '.irpc' directive") ||
5775 parseComma() || parseMacroArguments(
nullptr,
A))
5778 if (
A.size() != 1 ||
A.front().size() != 1)
5779 return TokError(
"unexpected token in '.irpc' directive");
5784 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5790 SmallString<256> Buf;
5791 raw_svector_ostream OS(Buf);
5794 :
A[0][0].getString();
5795 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5796 MCAsmMacroArgument Arg;
5801 if (expandMacro(OS, *M, Parameter, Arg,
true))
5805 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5810bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5811 if (ActiveMacros.empty())
5812 return TokError(
"unmatched '.endr' directive");
5822bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
5824 const MCExpr *
Value;
5825 SMLoc ExprLoc = getLexer().getLoc();
5826 if (parseExpression(
Value))
5830 return Error(ExprLoc,
"unexpected expression in _emit");
5831 uint64_t IntValue = MCE->
getValue();
5833 return Error(ExprLoc,
"literal value out of range for directive");
5839bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
5840 const MCExpr *
Value;
5841 SMLoc ExprLoc = getLexer().getLoc();
5842 if (parseExpression(
Value))
5846 return Error(ExprLoc,
"unexpected expression in align");
5847 uint64_t IntValue = MCE->
getValue();
5849 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5855bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5856 const AsmToken StrTok = getTok();
5859 return Error(DirectiveLoc,
"expected double quoted string after .print");
5866bool AsmParser::parseDirectiveAddrsig() {
5869 getStreamer().emitAddrsig();
5873bool AsmParser::parseDirectiveAddrsigSym() {
5875 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
5877 getStreamer().emitAddrsigSym(Sym);
5881bool AsmParser::parseDirectivePseudoProbe() {
5887 if (parseIntToken(
Guid))
5889 if (parseIntToken(Index))
5891 if (parseIntToken(
Type))
5893 if (parseIntToken(Attr))
5905 int64_t CallerGuid = 0;
5907 CallerGuid = getTok().getIntVal();
5915 int64_t CallerProbeId = 0;
5917 CallerProbeId = getTok().getIntVal();
5927 if (parseIdentifier(FnName))
5928 return Error(getLexer().getLoc(),
"expected identifier");
5934 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
5935 InlineStack, FnSym);
5944bool AsmParser::parseDirectiveLTODiscard() {
5945 auto ParseOp = [&]() ->
bool {
5947 SMLoc Loc = getTok().getLoc();
5948 if (parseIdentifier(Name))
5949 return Error(Loc,
"expected identifier");
5950 LTODiscardSymbols.
insert(Name);
5954 LTODiscardSymbols.
clear();
5955 return parseMany(ParseOp);
5981bool AsmParser::parseMSInlineAsm(
5982 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
5983 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5984 SmallVectorImpl<std::string> &Constraints,
5985 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
5986 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
5987 SmallVector<void *, 4> InputDecls;
5988 SmallVector<void *, 4> OutputDecls;
5991 SmallVector<std::string, 4> InputConstraints;
5992 SmallVector<std::string, 4> OutputConstraints;
6001 unsigned InputIdx = 0;
6002 unsigned OutputIdx = 0;
6005 if (parseCurlyBlockScope(AsmStrRewrites))
6008 ParseStatementInfo
Info(&AsmStrRewrites);
6009 bool StatementErr = parseStatement(Info, &SI);
6011 if (StatementErr ||
Info.ParseError) {
6013 printPendingErrors();
6018 assert(!hasPendingError() &&
"unexpected error from parseStatement");
6020 if (
Info.Opcode == ~0U)
6026 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
6027 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
6031 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
6032 unsigned NumDefs =
Desc.getNumDefs();
6041 if (SymName.
empty())
6049 if (Operand.
isImm()) {
6057 bool isOutput = (i == 1) &&
Desc.mayStore();
6064 OutputConstraints.
push_back((
"=" + Constraint).str());
6071 if (
Desc.operands()[i - 1].isBranchTarget())
6085 NumOutputs = OutputDecls.
size();
6086 NumInputs = InputDecls.
size();
6091 Clobbers.
assign(ClobberRegs.
size(), std::string());
6092 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6093 raw_string_ostream OS(Clobbers[
I]);
6098 if (NumOutputs || NumInputs) {
6099 unsigned NumExprs = NumOutputs + NumInputs;
6100 OpDecls.resize(NumExprs);
6101 Constraints.
resize(NumExprs);
6102 for (
unsigned i = 0; i < NumOutputs; ++i) {
6103 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6104 Constraints[i] = OutputConstraints[i];
6106 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6107 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6108 Constraints[
j] = InputConstraints[i];
6113 std::string AsmStringIR;
6114 raw_string_ostream OS(AsmStringIR);
6115 StringRef ASMString =
6117 const char *AsmStart = ASMString.
begin();
6118 const char *AsmEnd = ASMString.
end();
6120 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6121 const AsmRewrite &AR = *
I;
6128 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6131 if (
unsigned Len = Loc - AsmStart)
6132 OS << StringRef(AsmStart, Len);
6136 AsmStart = Loc + AR.
Len;
6140 unsigned AdditionalSkip = 0;
6162 size_t OffsetLen = OffsetName.
size();
6163 auto rewrite_it = std::find_if(
6164 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6165 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6166 (FusingAR.Kind == AOK_Input ||
6167 FusingAR.Kind == AOK_CallInput);
6169 if (rewrite_it == AsmStrRewrites.
end()) {
6170 OS <<
"offset " << OffsetName;
6172 OS <<
"${" << InputIdx++ <<
":P}";
6173 rewrite_it->Done =
true;
6175 OS <<
'$' << InputIdx++;
6176 rewrite_it->Done =
true;
6189 OS <<
"${" << InputIdx++ <<
":P}";
6191 OS <<
'$' << InputIdx++;
6194 OS <<
"${" << InputIdx++ <<
":P}";
6198 OS <<
"${" << OutputIdx++ <<
":P}";
6200 OS <<
'$' << OutputIdx++;
6205 case 8: OS <<
"byte ptr ";
break;
6206 case 16: OS <<
"word ptr ";
break;
6207 case 32: OS <<
"dword ptr ";
break;
6208 case 64: OS <<
"qword ptr ";
break;
6209 case 80: OS <<
"xword ptr ";
break;
6210 case 128: OS <<
"xmmword ptr ";
break;
6211 case 256: OS <<
"ymmword ptr ";
break;
6221 if (
getContext().getAsmInfo().getAlignmentIsInBytes())
6226 unsigned Val = AR.
Val;
6228 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6229 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6241 AsmStart = Loc + AR.
Len + AdditionalSkip;
6245 if (AsmStart != AsmEnd)
6246 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6248 AsmString = std::move(AsmStringIR);
6252bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6253 MCAsmParserSemaCallback *SI) {
6254 AsmToken LabelTok = getTok();
6255 SMLoc LabelLoc = LabelTok.
getLoc();
6258 if (parseIdentifier(LabelVal))
6259 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6264 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6273 return Error(LabelLoc,
6274 "Cannot have just a label for an HLASM inline asm statement");
6284 if (enabledGenDwarfForAssembly())
6291bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6292 MCAsmParserSemaCallback *SI) {
6293 AsmToken OperationEntryTok = Lexer.
getTok();
6294 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6295 StringRef OperationEntryVal;
6298 if (parseIdentifier(OperationEntryVal))
6299 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6305 return parseAndMatchAndEmitTargetInstruction(
6306 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6309bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6310 MCAsmParserSemaCallback *SI) {
6311 assert(!hasPendingError() &&
"parseStatement started with pending error");
6314 bool ShouldParseAsHLASMLabel =
false;
6323 ShouldParseAsHLASMLabel =
true;
6329 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6330 getTok().getString().
front() ==
'\n')
6345 if (getTok().getString().
front() ==
'\n' ||
6346 getTok().getString().
front() ==
'\r') {
6355 if (ShouldParseAsHLASMLabel) {
6358 if (parseAsHLASMLabel(Info, SI)) {
6361 eatToEndOfStatement();
6366 return parseAsMachineInstruction(Info, SI);
6378 return Parser.
TokError(
"missing expression");
6384 return Parser.
Error(
6385 EqualLoc,
"relocation specifier not permitted in symbol equating");
6393 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6399 }
else if (Name ==
".") {
6414 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6415 return new HLASMAsmParser(
SM,
C, Out, MAI, CB);
6417 return new AsmParser(
SM,
C, Out, MAI, CB);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static Expected< std::vector< unsigned > > getSymbols(SymbolicFile *Obj, uint16_t Index, raw_ostream &SymNames, SymMap *SymMap)
static bool isValidEncoding(int64_t Encoding)
static bool isAngleBracketString(SMLoc &StrLoc, SMLoc &EndLoc)
This function checks if the next token is <string> type or arithmetic.
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static unsigned getGNUBinOpPrecedence(const MCAsmInfo &MAI, AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
static std::string angleBracketString(StringRef AltMacroStr)
creating a string without the escape characters '!'.
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
static bool parseHexOcta(AsmParser &Asm, uint64_t &hi, uint64_t &lo)
static bool isOperator(AsmToken::TokenKind kind)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
This file contains constants used for implementing Dwarf debug support.
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_BASIC_BLOCK
#define DWARF2_LINE_DEFAULT_IS_STMT
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$....
Promote Memory to Register
static constexpr unsigned SM(unsigned Version)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
static StringRef getName(Value *V)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Class for arbitrary precision integers.
LLVM_ABI APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
unsigned getBitWidth() const
Return the number of bits in the APInt.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
ConditionalAssemblyType TheCond
SMLoc getLoc() const
Get the current source location.
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool getAllowAtInIdentifier()
void UnLex(AsmToken const &Token)
AsmToken::TokenKind getKind() const
Get the kind of current token.
const MCAsmInfo & getMAI() const
const AsmToken & getTok() const
Get the current (last) lexed token.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
SMLoc getErrLoc()
Get the current error location.
const std::string & getErr()
Get the current error string.
const AsmToken & Lex()
Consume the next token from the input stream and return it.
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
LLVM_ABI void setBuffer(StringRef Buf, const char *ptr=nullptr, bool EndStatementAtEOF=true)
Set buffer to be lexed.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
LLVM_ABI size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)
Look ahead an arbitrary number of tokens.
LLVM_ABI SMLoc getLoc() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
bool is(TokenKind K) const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Error takeError()
Take ownership of the stored error.
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
bool isLittleEndian() const
True if the target is little endian.
bool useAtForSpecifier() const
bool doesAllowAtInName() const
StringRef getPrivateLabelPrefix() const
std::optional< uint32_t > getSpecifierForName(StringRef Name) const
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
bool shouldUseLogicalShr() const
StringRef getCommentString() const
bool hasSubsectionsViaSymbols() const
bool getCOMMDirectiveAlignmentIsInBytes() const
virtual bool useCodeAlign(const MCSection &Sec) const
bool useParensForSpecifier() const
bool getDollarIsPC() const
virtual ~MCAsmParserSemaCallback()
Generic assembler parser interface, for use by target specific assembly parsers.
bool Error(SMLoc L, const Twine &Msg, SMRange Range={})
Return an error at the location L, with the message Msg.
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
bool parseAtSpecifier(const MCExpr *&Res, SMLoc &EndLoc)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
const MCExpr * applySpecifier(const MCExpr *E, uint32_t Variant)
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
bool TokError(const Twine &Msg, SMRange Range={})
Report an error at the current lexer location.
MCStreamer & getStreamer()
MCTargetAsmParser & getTargetParser() const
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
@ AShr
Arithmetic shift right.
@ LShr
Logical shift right.
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
@ Xor
Bitwise exclusive or.
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
@ NE
Inequality comparison.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
void * allocate(unsigned Size, unsigned Align=8)
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
bool getGenDwarfForAssembly()
void setGenDwarfForAssembly(bool Value)
void setDwarfVersion(uint16_t v)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_ABI MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
LLVM_ABI MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
uint16_t getDwarfVersion() const
LLVM_ABI MCSymbol * cloneSymbol(MCSymbol &Sym)
Clone a symbol for the .set directive, replacing it in the symbol table.
LLVM_ABI MCSymbol * parseSymbol(const Twine &Name)
Variant of getOrCreateSymbol that handles backslash-escaped symbols.
const MCAsmInfo & getAsmInfo() const
LLVM_ABI MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
virtual void printRegName(raw_ostream &OS, MCRegister Reg)
Print the assembler register name.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
virtual bool isMemUseUpRegs() const
isMemUseUpRegs - Is memory operand use up regs, for example, intel MS inline asm may use ARR[baseReg ...
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label?
virtual MCRegister getReg() const =0
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable,...
virtual StringRef getSymName()
virtual bool isImm() const =0
isImm - Is this an immediate operand?
unsigned getMCOperandNum()
StringRef getConstraint()
virtual void * getOpDecl()
void setBeginSymbol(MCSymbol *Sym)
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
void setStartTokLocPtr(const SMLoc *Loc)
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
virtual void initSections(const MCSubtargetInfo &STI)
Create the default sections and set the initial one.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
MCTargetStreamer * getTargetStreamer()
MCLFIRewriter * getLFIRewriter()
virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc)
Emit some number of copies of Value until the byte offset Offset is reached.
virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol, but only if Value is also emitted.
void finish(SMLoc EndLoc=SMLoc())
Finish emission of machine code.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
uint16_t getSpecifier() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
bool isRedefinable() const
Check if this symbol is redefinable.
void setRedefinable(bool Value)
Mark this symbol as redefinable.
void redefineIfPossible()
Prepare this symbol to be redefined.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Unary assembler expressions.
Opcode getOpcode() const
Get the kind of this unary expression.
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getSubExpr() const
Get the child of this unary expression.
static const MCUnaryExpr * createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
StringRef getBuffer() const
constexpr bool isFailure() const
constexpr bool isSuccess() const
SourceMgr::DiagKind getKind() const
StringRef getLineContents() const
StringRef getMessage() const
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
const SourceMgr * getSourceMgr() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
constexpr bool isValid() const
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
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.
LLVM_ABI ErrorOr< std::unique_ptr< MemoryBuffer > > OpenIncludeFile(const std::string &Filename, std::string &IncludedFile, bool RequiresNullTerminator=true)
Search for a file with the specified name in the current directory or in one of the IncludeDirs,...
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
LLVM_ABI unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
StringMapIterBase< ValueTy, true > const_iterator
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
constexpr size_t size() const
Get the string size.
char front() const
Get the first character in the string.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
LLVM_ABI std::string lower() const
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
LLVM Value Representation.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
std::variant< std::monostate, DecisionParameters, BranchParameters > Parameters
The type of MC/DC-specific parameters.
@ Parameter
An inlay hint that is for a parameter.
Context & getContext() const
LLVM_ABI Instruction & front() const
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
FunctionAddr VTableAddr Value
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation. The return string is half the size of ...
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
std::tuple< uint64_t, uint32_t > InlineSite
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
auto unique(Range &&R, Predicate P)
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
cl::opt< unsigned > AsmMacroMaxNestingDepth
SmallVector< InlineSite, 8 > MCPseudoProbeInlineStack
const char AsmRewritePrecedence[]
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool hasDiscriminator(uint32_t Flags)
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
FunctionAddr VTableAddr Count
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ABI llvm::Error decodeBase64(llvm::StringRef Input, std::vector< char > &Output)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance for parsing assembly similar to gas syntax.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
@ Sub
Subtraction of integers.
FunctionAddr VTableAddr Next
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
void consumeError(Error Err)
Consume a Error without doing anything.
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
ArrayRef< int > hi(ArrayRef< int > Vuu)
ArrayRef< int > lo(ArrayRef< int > Vuu)
std::vector< AsmToken > Value
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
std::optional< StringRef > Source
The source code of the file.