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,
497 DK_CFI_LLVM_REGISTER_PAIR,
498 DK_CFI_LLVM_VECTOR_REGISTERS,
499 DK_CFI_LLVM_VECTOR_OFFSET,
500 DK_CFI_LLVM_VECTOR_REGISTER_MASK,
503 DK_CFI_REMEMBER_STATE,
504 DK_CFI_RESTORE_STATE,
508 DK_CFI_RETURN_COLUMN,
535 DK_LTO_SET_CONDITIONAL,
536 DK_CFI_MTE_TAGGED_FRAME,
544 StringMap<DirectiveKind> DirectiveKindMap;
547 enum CVDefRangeType {
549 CVDR_DEFRANGE_REGISTER,
550 CVDR_DEFRANGE_FRAMEPOINTER_REL,
551 CVDR_DEFRANGE_SUBFIELD_REGISTER,
552 CVDR_DEFRANGE_REGISTER_REL,
553 CVDR_DEFRANGE_REGISTER_REL_INDIR
558 StringMap<CVDefRangeType> CVDefRangeTypeMap;
561 bool parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated);
562 bool parseDirectiveBase64();
563 bool parseDirectiveReloc(SMLoc DirectiveLoc);
564 bool parseDirectiveValue(StringRef IDVal,
566 bool parseDirectiveOctaValue(StringRef IDVal);
567 bool parseDirectiveRealValue(StringRef IDVal,
568 const fltSemantics &);
569 bool parseDirectiveFill();
570 bool parseDirectiveZero();
572 bool parseDirectiveSet(StringRef IDVal, AssignmentKind Kind);
573 bool parseDirectiveOrg();
575 bool parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize);
576 bool parseDirectivePrefAlign();
579 bool parseDirectiveFile(SMLoc DirectiveLoc);
580 bool parseDirectiveLine();
581 bool parseDirectiveLoc();
582 bool parseDirectiveLocLabel(SMLoc DirectiveLoc);
583 bool parseDirectiveStabs();
587 bool parseDirectiveCVFile();
588 bool parseDirectiveCVFuncId();
589 bool parseDirectiveCVInlineSiteId();
590 bool parseDirectiveCVLoc();
591 bool parseDirectiveCVLinetable();
592 bool parseDirectiveCVInlineLinetable();
593 bool parseDirectiveCVDefRange();
594 bool parseDirectiveCVString();
595 bool parseDirectiveCVStringTable();
596 bool parseDirectiveCVFileChecksums();
597 bool parseDirectiveCVFileChecksumOffset();
598 bool parseDirectiveCVFPOData();
601 bool parseDirectiveCFIRegister(SMLoc DirectiveLoc);
602 bool parseDirectiveCFIWindowSave(SMLoc DirectiveLoc);
603 bool parseDirectiveCFISections();
604 bool parseDirectiveCFIStartProc();
605 bool parseDirectiveCFIEndProc();
606 bool parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc);
607 bool parseDirectiveCFIDefCfa(SMLoc DirectiveLoc);
608 bool parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc);
609 bool parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc);
610 bool parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc);
611 bool parseDirectiveCFIOffset(SMLoc DirectiveLoc);
612 bool parseDirectiveCFIRelOffset(SMLoc DirectiveLoc);
613 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
614 bool parseDirectiveCFIRememberState(SMLoc DirectiveLoc);
615 bool parseDirectiveCFIRestoreState(SMLoc DirectiveLoc);
616 bool parseDirectiveCFISameValue(SMLoc DirectiveLoc);
617 bool parseDirectiveCFIRestore(SMLoc DirectiveLoc);
618 bool parseDirectiveCFIEscape(SMLoc DirectiveLoc);
619 bool parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc);
620 bool parseDirectiveCFISignalFrame(SMLoc DirectiveLoc);
621 bool parseDirectiveCFIUndefined(SMLoc DirectiveLoc);
622 bool parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc);
623 bool parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc);
624 bool parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc);
625 bool parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc);
626 bool parseDirectiveCFILabel(SMLoc DirectiveLoc);
627 bool parseDirectiveCFIValOffset(SMLoc DirectiveLoc);
630 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
631 bool parseDirectiveExitMacro(StringRef Directive);
632 bool parseDirectiveEndMacro(StringRef Directive);
633 bool parseDirectiveMacro(SMLoc DirectiveLoc);
634 bool parseDirectiveMacrosOnOff(StringRef Directive);
636 bool parseDirectiveAltmacro(StringRef Directive);
639 bool parseDirectiveSpace(StringRef IDVal);
642 bool parseDirectiveDCB(StringRef IDVal,
unsigned Size);
643 bool parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &);
645 bool parseDirectiveDS(StringRef IDVal,
unsigned Size);
648 bool parseDirectiveLEB128(
bool Signed);
654 bool parseDirectiveComm(
bool IsLocal);
656 bool parseDirectiveAbort(SMLoc DirectiveLoc);
657 bool parseDirectiveInclude();
658 bool parseDirectiveIncbin();
661 bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);
663 bool parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank);
665 bool parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual);
667 bool parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual);
669 bool parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined);
670 bool parseDirectiveElseIf(SMLoc DirectiveLoc);
671 bool parseDirectiveElse(SMLoc DirectiveLoc);
672 bool parseDirectiveEndIf(SMLoc DirectiveLoc);
673 bool parseEscapedString(std::string &
Data)
override;
674 bool parseAngleBracketString(std::string &
Data)
override;
677 MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
678 void instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
679 raw_svector_ostream &OS);
680 bool parseDirectiveRept(SMLoc DirectiveLoc, StringRef Directive);
681 bool parseDirectiveIrp(SMLoc DirectiveLoc);
682 bool parseDirectiveIrpc(SMLoc DirectiveLoc);
683 bool parseDirectiveEndr(SMLoc DirectiveLoc);
686 bool parseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,
690 bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
693 bool parseDirectiveEnd(SMLoc DirectiveLoc);
696 bool parseDirectiveError(SMLoc DirectiveLoc,
bool WithMessage);
699 bool parseDirectiveWarning(SMLoc DirectiveLoc);
702 bool parseDirectivePrint(SMLoc DirectiveLoc);
705 bool parseDirectivePseudoProbe();
708 bool parseDirectiveLTODiscard();
711 bool parseDirectiveAddrsig();
712 bool parseDirectiveAddrsigSym();
714 void initializeDirectiveKindMap();
715 void initializeCVDefRangeTypeMap();
718class HLASMAsmParser final :
public AsmParser {
723 void lexLeadingSpaces() {
728 bool parseAsHLASMLabel(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI);
729 bool parseAsMachineInstruction(ParseStatementInfo &Info,
730 MCAsmParserSemaCallback *SI);
733 HLASMAsmParser(SourceMgr &
SM, MCContext &Ctx, MCStreamer &Out,
734 const MCAsmInfo &MAI,
unsigned CB = 0)
735 : AsmParser(
SM, Ctx, Out, MAI, CB), Lexer(getLexer()), Out(Out) {
736 Lexer.setSkipSpace(
false);
737 Lexer.setAllowHashInIdentifier(
true);
738 Lexer.setLexHLASMIntegers(
true);
739 Lexer.setLexHLASMStrings(
true);
742 ~HLASMAsmParser()
override { Lexer.setSkipSpace(
true); }
744 bool parseStatement(ParseStatementInfo &Info,
745 MCAsmParserSemaCallback *SI)
override;
758 :
MCAsmParser(Ctx, Out,
SM, MAI), CurBuffer(CB ? CB :
SM.getMainFileID()),
759 MacrosEnabledFlag(
true) {
762 SavedDiagHandler =
SrcMgr.getDiagHandler();
763 SavedDiagContext =
SrcMgr.getDiagContext();
771 switch (Ctx.getObjectFileType()) {
772 case MCContext::IsCOFF:
773 PlatformParser.reset(createCOFFAsmParser());
775 case MCContext::IsMachO:
776 PlatformParser.reset(createDarwinAsmParser());
779 case MCContext::IsELF:
780 PlatformParser.reset(createELFAsmParser());
782 case MCContext::IsGOFF:
783 PlatformParser.reset(createGOFFAsmParser());
785 case MCContext::IsSPIRV:
787 "Need to implement createSPIRVAsmParser for SPIRV format.");
789 case MCContext::IsWasm:
790 PlatformParser.reset(createWasmAsmParser());
792 case MCContext::IsXCOFF:
793 PlatformParser.reset(createXCOFFAsmParser());
795 case MCContext::IsDXContainer:
796 report_fatal_error(
"DXContainer is not supported yet");
800 PlatformParser->Initialize(*
this);
802 LFIParser.reset(createLFIAsmParser(Out.getLFIRewriter()));
803 LFIParser->Initialize(*this);
805 initializeDirectiveKindMap();
806 initializeCVDefRangeTypeMap();
809AsmParser::~AsmParser() {
810 assert((HadError || ActiveMacros.empty()) &&
811 "Unexpected active macro instantiation!");
820void AsmParser::printMacroInstantiations() {
822 for (MacroInstantiation *M :
reverse(ActiveMacros))
824 "while in macro instantiation");
827void AsmParser::Note(SMLoc L,
const Twine &Msg, SMRange
Range) {
828 printPendingErrors();
830 printMacroInstantiations();
833bool AsmParser::Warning(SMLoc L,
const Twine &Msg, SMRange
Range) {
834 if(getTargetParser().getTargetOptions().MCNoWarn)
836 if (getTargetParser().getTargetOptions().MCFatalWarnings)
839 printMacroInstantiations();
843bool AsmParser::printError(SMLoc L,
const Twine &Msg, SMRange
Range) {
846 printMacroInstantiations();
850bool AsmParser::enterIncludeFile(
const std::string &
Filename) {
851 std::string IncludedFile;
865bool AsmParser::processIncbinFile(
const std::string &
Filename, int64_t Skip,
866 const MCExpr *
Count, SMLoc Loc) {
868 if (SymbolScanningMode)
874 std::string IncludedFile;
881 StringRef Bytes = (*BufOrErr)->getBuffer();
885 if (!
Count->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
886 return Error(Loc,
"expected absolute expression");
888 return Warning(Loc,
"negative count has no effect");
891 getStreamer().emitBytes(Bytes);
895void AsmParser::jumpToLoc(SMLoc Loc,
unsigned InBuffer) {
901const AsmToken &AsmParser::Lex() {
908 if (!getTok().getString().
empty() && getTok().getString().
front() !=
'\n' &&
913 const AsmToken *tok = &Lexer.
Lex();
926 if (ParentIncludeLoc != SMLoc()) {
927 jumpToLoc(ParentIncludeLoc);
935bool AsmParser::enabledGenDwarfForAssembly() {
942 if (
getContext().getGenDwarfFileNumber() == 0) {
943 const MCDwarfFile &RootFile =
944 getContext().getMCDwarfLineTable(0).getRootFile();
945 getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
952bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
953 LTODiscardSymbols.
clear();
956 if (!NoInitialTextSection)
963 AsmCond StartingCondState = TheCondState;
971 MCSection *Sec = getStreamer().getCurrentSectionOnly();
974 getStreamer().emitLabel(SectionStartSym);
977 bool InsertResult =
getContext().addGenDwarfSection(Sec);
978 assert(InsertResult &&
".text section should not have debug info yet");
982 getTargetParser().onBeginOfFile();
986 ParseStatementInfo
Info(&AsmStrRewrites);
987 bool HasError = parseStatement(Info,
nullptr);
996 printPendingErrors();
999 if (HasError && !getLexer().justConsumedEOL())
1000 eatToEndOfStatement();
1003 getTargetParser().onEndOfFile();
1004 printPendingErrors();
1007 assert(!hasPendingError() &&
"unexpected error from parseStatement");
1011 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
1013 const auto &LineTables =
getContext().getMCDwarfLineTables();
1014 if (!LineTables.empty()) {
1016 for (
const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
1017 if (
File.Name.empty() && Index != 0)
1018 printError(getTok().getLoc(),
"unassigned file number: " +
1020 " for .file directives");
1032 MCSymbol *Sym = TableEntry.getValue().Symbol;
1041 printError(getTok().getLoc(),
"assembler local symbol '" +
1042 Sym->
getName() +
"' not defined");
1048 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
1049 if (std::get<2>(LocSym)->isUndefined()) {
1052 CppHashInfo = std::get<1>(LocSym);
1053 printError(std::get<0>(LocSym),
"directional label undefined");
1059 if (!HadError && !NoFinalize) {
1061 TS->emitConstantPools();
1069bool AsmParser::checkForValidSection() {
1070 if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
1072 return Error(getTok().getLoc(),
1073 "expected section directive before assembly directive");
1079void AsmParser::eatToEndOfStatement() {
1088StringRef AsmParser::parseStringToEndOfStatement() {
1089 const char *
Start = getTok().getLoc().getPointer();
1095 return StringRef(Start, End - Start);
1098StringRef AsmParser::parseStringToComma() {
1099 const char *
Start = getTok().getLoc().getPointer();
1105 const char *End = getTok().getLoc().getPointer();
1106 return StringRef(Start, End - Start);
1114bool AsmParser::parseParenExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1115 if (parseExpression(Res))
1118 return parseRParen();
1126bool AsmParser::parseBracketExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
1127 if (parseExpression(Res))
1129 EndLoc = getTok().getEndLoc();
1130 if (parseToken(
AsmToken::RBrac,
"expected ']' in brackets expression"))
1141bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc,
1142 AsmTypeInfo *TypeInfo) {
1143 SMLoc FirstTokenLoc = getLexer().getLoc();
1145 switch (FirstTokenKind) {
1147 return TokError(
"unknown token in expression");
1153 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1163 if (parseIdentifier(Identifier)) {
1167 bool ShouldGenerateTempSymbol =
false;
1170 ShouldGenerateTempSymbol =
true;
1172 if (!ShouldGenerateTempSymbol)
1173 return Error(FirstTokenLoc,
"invalid token in expression");
1182 EndLoc = FirstTokenLoc;
1187 std::pair<StringRef, StringRef>
Split;
1192 SMLoc AtLoc = getLexer().getLoc();
1194 if (parseIdentifier(VName))
1195 return Error(AtLoc,
"expected symbol variant after '@'");
1197 Split = std::make_pair(Identifier, VName);
1205 parseIdentifier(VName);
1208 Split = std::make_pair(Identifier, VName);
1216 return Error(getLexer().getLoc(),
"expected a symbol reference");
1220 if (!
Split.second.empty()) {
1222 if (MaybeSpecifier) {
1224 Spec = *MaybeSpecifier;
1227 "invalid variant '" +
Split.second +
"'");
1242 DoInline = TV->inlineAssignedExpr();
1245 return Error(EndLoc,
"unexpected modifier on variable reference");
1256 return TokError(
"literal value out of range for directive");
1258 SMLoc Loc = getTok().getLoc();
1259 int64_t
IntVal = getTok().getIntVal();
1265 StringRef IDVal = getTok().getString();
1267 std::pair<StringRef, StringRef>
Split = IDVal.
split(
'@');
1269 if (
Split.first.size() != IDVal.
size()) {
1272 return TokError(
"invalid variant '" +
Split.second +
"'");
1273 IDVal =
Split.first;
1276 if (IDVal ==
"f" || IDVal ==
"b") {
1281 return Error(Loc,
"directional label undefined");
1282 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1290 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1291 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
1299 return TokError(
"cannot use . as current PC");
1312 return parseParenExpr(Res, EndLoc);
1314 if (!PlatformParser->HasBracketExpressions())
1315 return TokError(
"brackets expression not supported on this target");
1317 return parseBracketExpr(Res, EndLoc);
1320 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1326 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1332 if (parsePrimaryExpr(Res, EndLoc, TypeInfo))
1339bool AsmParser::parseExpression(
const MCExpr *&Res) {
1341 return parseExpression(Res, EndLoc);
1351 switch (E->getKind()) {
1362 TokError(
"invalid variant on expression '" +
getTok().getIdentifier() +
1363 "' (already modified)");
1414 "Argument to the function cannot be a NULL value");
1416 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') && (*CharPtr !=
'\r') &&
1417 (*CharPtr !=
'\0')) {
1418 if (*CharPtr ==
'!')
1422 if (*CharPtr ==
'>') {
1432 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1433 if (AltMacroStr[Pos] ==
'!')
1435 Res += AltMacroStr[Pos];
1443 return TokError(
"expected specifier following '@'");
1445 auto Spec =
MAI.getSpecifierForName(
getTok().getIdentifier());
1447 return TokError(
"invalid specifier '@" +
getTok().getIdentifier() +
"'");
1467bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1470 auto &TS = getTargetParser();
1471 if (TS.parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1479 return TokError(
"unexpected symbol modifier following '@'");
1483 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1485 const MCExpr *ModifiedRes = applySpecifier(Res, *
Spec);
1487 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1488 "' (no symbols present)");
1498 if (Res->evaluateAsAbsolute(
Value))
1504bool AsmParser::parseParenExpression(
const MCExpr *&Res, SMLoc &EndLoc) {
1506 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1509bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1512 SMLoc StartLoc = Lexer.
getLoc();
1513 if (parseExpression(Expr))
1516 if (!Expr->evaluateAsAbsolute(Res, getStreamer().getAssemblerPtr()))
1517 return Error(StartLoc,
"expected absolute expression");
1524 bool ShouldUseLogicalShr) {
1601 bool ShouldUseLogicalShr) {
1690bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1692 SMLoc StartLoc = Lexer.
getLoc();
1695 unsigned TokPrec = getBinOpPrecedence(Lexer.
getKind(), Kind);
1699 if (TokPrec < Precedence)
1706 if (getTargetParser().parsePrimaryExpr(
RHS, EndLoc))
1712 unsigned NextTokPrec = getBinOpPrecedence(Lexer.
getKind(), Dummy);
1713 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1,
RHS, EndLoc))
1725bool AsmParser::parseStatement(ParseStatementInfo &Info,
1726 MCAsmParserSemaCallback *SI) {
1727 assert(!hasPendingError() &&
"parseStatement started with pending error");
1733 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
1734 getTok().getString().
front() ==
'\n')
1740 AsmToken
ID = getTok();
1741 SMLoc IDLoc =
ID.getLoc();
1743 int64_t LocalLabelVal = -1;
1744 StartTokLoc =
ID.getLoc();
1746 return parseCppHashLineFilenameComment(IDLoc,
1747 !isInsideMacroInstantiation());
1751 LocalLabelVal = getTok().getIntVal();
1752 if (LocalLabelVal < 0) {
1753 if (!TheCondState.
Ignore) {
1755 return Error(IDLoc,
"unexpected token at start of statement");
1759 IDVal = getTok().getString();
1762 if (!TheCondState.
Ignore) {
1764 return Error(IDLoc,
"unexpected token at start of statement");
1772 }
else if (getTargetParser().tokenIsStartOfStatement(
ID.getKind())) {
1774 IDVal =
ID.getString();
1775 }
else if (parseIdentifier(IDVal)) {
1776 if (!TheCondState.
Ignore) {
1778 return Error(IDLoc,
"unexpected token at start of statement");
1787 DirectiveKindMap.find(IDVal.
lower());
1788 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1790 : DirKindIt->getValue();
1801 return parseDirectiveIf(IDLoc, DirKind);
1803 return parseDirectiveIfb(IDLoc,
true);
1805 return parseDirectiveIfb(IDLoc,
false);
1807 return parseDirectiveIfc(IDLoc,
true);
1809 return parseDirectiveIfeqs(IDLoc,
true);
1811 return parseDirectiveIfc(IDLoc,
false);
1813 return parseDirectiveIfeqs(IDLoc,
false);
1815 return parseDirectiveIfdef(IDLoc,
true);
1818 return parseDirectiveIfdef(IDLoc,
false);
1820 return parseDirectiveElseIf(IDLoc);
1822 return parseDirectiveElse(IDLoc);
1824 return parseDirectiveEndIf(IDLoc);
1829 if (TheCondState.
Ignore) {
1830 eatToEndOfStatement();
1840 if (checkForValidSection())
1847 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1855 if (LocalLabelVal == -1) {
1856 if (ParsingMSInlineAsm && SI) {
1857 StringRef RewrittenLabel =
1858 SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
true);
1860 "We should have an internal name here.");
1863 IDVal = RewrittenLabel;
1873 StringRef CommentStr = parseStringToEndOfStatement();
1884 if (MAI.
isMachO() && CFIStartProcLoc) {
1885 auto *SymM =
static_cast<MCSymbolMachO *
>(Sym);
1886 if (SymM->isExternal() && !SymM->isAltEntry())
1887 return Error(StartTokLoc,
"non-private labels cannot appear between "
1888 ".cfi_startproc / .cfi_endproc pairs") &&
1889 Error(*CFIStartProcLoc,
"previous .cfi_startproc was here");
1892 if (discardLTOSymbol(IDVal))
1895 getTargetParser().doBeforeLabelEmit(Sym, IDLoc);
1898 if (!getTargetParser().isParsingMSInlineAsm())
1903 if (enabledGenDwarfForAssembly())
1907 getTargetParser().onLabelParsed(Sym);
1916 return parseAssignment(IDVal, AssignmentKind::Equal);
1920 if (areMacrosEnabled())
1921 if (MCAsmMacro *M =
getContext().lookupMacro(IDVal))
1922 return handleMacroEntry(M, IDLoc);
1939 getTargetParser().flushPendingInstructions(getStreamer());
1941 ParseStatus TPDirectiveReturn = getTargetParser().parseDirective(
ID);
1943 "Should only return Failure iff there was an error");
1951 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1952 ExtensionDirectiveMap.
lookup(IDVal);
1954 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1963 return parseDirectiveSet(IDVal, AssignmentKind::Set);
1965 return parseDirectiveSet(IDVal, AssignmentKind::Equiv);
1966 case DK_LTO_SET_CONDITIONAL:
1967 return parseDirectiveSet(IDVal, AssignmentKind::LTOSetConditional);
1969 return parseDirectiveAscii(IDVal,
false);
1972 return parseDirectiveAscii(IDVal,
true);
1974 return parseDirectiveBase64();
1977 return parseDirectiveValue(IDVal, 1);
1983 return parseDirectiveValue(IDVal, 2);
1988 return parseDirectiveValue(IDVal, 4);
1991 return parseDirectiveValue(IDVal, 8);
1993 return parseDirectiveValue(
1994 IDVal,
getContext().getAsmInfo().getCodePointerSize());
1996 return parseDirectiveOctaValue(IDVal);
2000 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
2003 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
2005 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2006 return parseDirectiveAlign(IsPow2, 1);
2009 bool IsPow2 = !
getContext().getAsmInfo().getAlignmentIsInBytes();
2010 return parseDirectiveAlign(IsPow2, 4);
2013 return parseDirectiveAlign(
false, 1);
2015 return parseDirectiveAlign(
false, 2);
2017 return parseDirectiveAlign(
false, 4);
2019 return parseDirectiveAlign(
true, 1);
2021 return parseDirectiveAlign(
true, 2);
2023 return parseDirectiveAlign(
true, 4);
2025 return parseDirectivePrefAlign();
2027 return parseDirectiveOrg();
2029 return parseDirectiveFill();
2031 return parseDirectiveZero();
2033 eatToEndOfStatement();
2037 return parseDirectiveSymbolAttribute(
MCSA_Global);
2038 case DK_LAZY_REFERENCE:
2040 case DK_NO_DEAD_STRIP:
2042 case DK_SYMBOL_RESOLVER:
2044 case DK_PRIVATE_EXTERN:
2048 case DK_WEAK_DEFINITION:
2050 case DK_WEAK_REFERENCE:
2052 case DK_WEAK_DEF_CAN_BE_HIDDEN:
2055 return parseDirectiveSymbolAttribute(
MCSA_Cold);
2058 return parseDirectiveComm(
false);
2060 return parseDirectiveComm(
true);
2062 return parseDirectiveAbort(IDLoc);
2064 return parseDirectiveInclude();
2066 return parseDirectiveIncbin();
2069 return TokError(Twine(IDVal) +
2070 " not currently supported for this target");
2072 return parseDirectiveRept(IDLoc, IDVal);
2074 return parseDirectiveIrp(IDLoc);
2076 return parseDirectiveIrpc(IDLoc);
2078 return parseDirectiveEndr(IDLoc);
2080 return parseDirectiveLEB128(
true);
2082 return parseDirectiveLEB128(
false);
2085 return parseDirectiveSpace(IDVal);
2087 return parseDirectiveFile(IDLoc);
2089 return parseDirectiveLine();
2091 return parseDirectiveLoc();
2093 return parseDirectiveLocLabel(IDLoc);
2095 return parseDirectiveStabs();
2097 return parseDirectiveCVFile();
2099 return parseDirectiveCVFuncId();
2100 case DK_CV_INLINE_SITE_ID:
2101 return parseDirectiveCVInlineSiteId();
2103 return parseDirectiveCVLoc();
2104 case DK_CV_LINETABLE:
2105 return parseDirectiveCVLinetable();
2106 case DK_CV_INLINE_LINETABLE:
2107 return parseDirectiveCVInlineLinetable();
2108 case DK_CV_DEF_RANGE:
2109 return parseDirectiveCVDefRange();
2111 return parseDirectiveCVString();
2112 case DK_CV_STRINGTABLE:
2113 return parseDirectiveCVStringTable();
2114 case DK_CV_FILECHECKSUMS:
2115 return parseDirectiveCVFileChecksums();
2116 case DK_CV_FILECHECKSUM_OFFSET:
2117 return parseDirectiveCVFileChecksumOffset();
2118 case DK_CV_FPO_DATA:
2119 return parseDirectiveCVFPOData();
2120 case DK_CFI_SECTIONS:
2121 return parseDirectiveCFISections();
2122 case DK_CFI_STARTPROC:
2123 return parseDirectiveCFIStartProc();
2124 case DK_CFI_ENDPROC:
2125 return parseDirectiveCFIEndProc();
2126 case DK_CFI_DEF_CFA:
2127 return parseDirectiveCFIDefCfa(IDLoc);
2128 case DK_CFI_DEF_CFA_OFFSET:
2129 return parseDirectiveCFIDefCfaOffset(IDLoc);
2130 case DK_CFI_ADJUST_CFA_OFFSET:
2131 return parseDirectiveCFIAdjustCfaOffset(IDLoc);
2132 case DK_CFI_DEF_CFA_REGISTER:
2133 return parseDirectiveCFIDefCfaRegister(IDLoc);
2134 case DK_CFI_LLVM_DEF_ASPACE_CFA:
2135 return parseDirectiveCFILLVMDefAspaceCfa(IDLoc);
2137 return parseDirectiveCFIOffset(IDLoc);
2138 case DK_CFI_REL_OFFSET:
2139 return parseDirectiveCFIRelOffset(IDLoc);
2140 case DK_CFI_LLVM_REGISTER_PAIR:
2141 return parseDirectiveCFILLVMRegisterPair(IDLoc);
2142 case DK_CFI_LLVM_VECTOR_REGISTERS:
2143 return parseDirectiveCFILLVMVectorRegisters(IDLoc);
2144 case DK_CFI_LLVM_VECTOR_OFFSET:
2145 return parseDirectiveCFILLVMVectorOffset(IDLoc);
2146 case DK_CFI_LLVM_VECTOR_REGISTER_MASK:
2147 return parseDirectiveCFILLVMVectorRegisterMask(IDLoc);
2148 case DK_CFI_PERSONALITY:
2149 return parseDirectiveCFIPersonalityOrLsda(
true);
2151 return parseDirectiveCFIPersonalityOrLsda(
false);
2152 case DK_CFI_REMEMBER_STATE:
2153 return parseDirectiveCFIRememberState(IDLoc);
2154 case DK_CFI_RESTORE_STATE:
2155 return parseDirectiveCFIRestoreState(IDLoc);
2156 case DK_CFI_SAME_VALUE:
2157 return parseDirectiveCFISameValue(IDLoc);
2158 case DK_CFI_RESTORE:
2159 return parseDirectiveCFIRestore(IDLoc);
2161 return parseDirectiveCFIEscape(IDLoc);
2162 case DK_CFI_RETURN_COLUMN:
2163 return parseDirectiveCFIReturnColumn(IDLoc);
2164 case DK_CFI_SIGNAL_FRAME:
2165 return parseDirectiveCFISignalFrame(IDLoc);
2166 case DK_CFI_UNDEFINED:
2167 return parseDirectiveCFIUndefined(IDLoc);
2168 case DK_CFI_REGISTER:
2169 return parseDirectiveCFIRegister(IDLoc);
2170 case DK_CFI_WINDOW_SAVE:
2171 return parseDirectiveCFIWindowSave(IDLoc);
2173 return parseDirectiveCFILabel(IDLoc);
2174 case DK_CFI_VAL_OFFSET:
2175 return parseDirectiveCFIValOffset(IDLoc);
2178 return parseDirectiveMacrosOnOff(IDVal);
2180 return parseDirectiveMacro(IDLoc);
2183 return parseDirectiveAltmacro(IDVal);
2185 return parseDirectiveExitMacro(IDVal);
2188 return parseDirectiveEndMacro(IDVal);
2190 return parseDirectivePurgeMacro(IDLoc);
2192 return parseDirectiveEnd(IDLoc);
2194 return parseDirectiveError(IDLoc,
false);
2196 return parseDirectiveError(IDLoc,
true);
2198 return parseDirectiveWarning(IDLoc);
2200 return parseDirectiveReloc(IDLoc);
2203 return parseDirectiveDCB(IDVal, 2);
2205 return parseDirectiveDCB(IDVal, 1);
2207 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
2209 return parseDirectiveDCB(IDVal, 4);
2211 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
2214 return TokError(Twine(IDVal) +
2215 " not currently supported for this target");
2218 return parseDirectiveDS(IDVal, 2);
2220 return parseDirectiveDS(IDVal, 1);
2222 return parseDirectiveDS(IDVal, 8);
2225 return parseDirectiveDS(IDVal, 4);
2228 return parseDirectiveDS(IDVal, 12);
2230 return parseDirectivePrint(IDLoc);
2232 return parseDirectiveAddrsig();
2233 case DK_ADDRSIG_SYM:
2234 return parseDirectiveAddrsigSym();
2235 case DK_PSEUDO_PROBE:
2236 return parseDirectivePseudoProbe();
2237 case DK_LTO_DISCARD:
2238 return parseDirectiveLTODiscard();
2240 return parseDirectiveSymbolAttribute(
MCSA_Memtag);
2243 return Error(IDLoc,
"unknown directive");
2247 if (ParsingMSInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2248 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2249 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2252 if (ParsingMSInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2253 return parseDirectiveMSAlign(IDLoc, Info);
2255 if (ParsingMSInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2257 if (checkForValidSection())
2260 return parseAndMatchAndEmitTargetInstruction(Info, IDVal,
ID, IDLoc);
2263bool AsmParser::parseAndMatchAndEmitTargetInstruction(ParseStatementInfo &Info,
2268 std::string OpcodeStr = IDVal.
lower();
2269 ParseInstructionInfo IInfo(
Info.AsmRewrites);
2270 bool ParseHadError = getTargetParser().parseInstruction(IInfo, OpcodeStr,
ID,
2271 Info.ParsedOperands);
2272 Info.ParseError = ParseHadError;
2275 if (getShowParsedOperands()) {
2276 SmallString<256> Str;
2277 raw_svector_ostream OS(Str);
2278 OS <<
"parsed instruction: [";
2279 for (
unsigned i = 0; i !=
Info.ParsedOperands.size(); ++i) {
2282 Info.ParsedOperands[i]->print(OS, MAI);
2290 if (hasPendingError() || ParseHadError)
2295 if (!ParseHadError && enabledGenDwarfForAssembly() &&
2297 getStreamer().getCurrentSectionOnly())) {
2299 if (ActiveMacros.empty())
2303 ActiveMacros.front()->ExitBuffer);
2308 if (!CppHashInfo.Filename.empty()) {
2309 unsigned FileNumber = getStreamer().emitDwarfFileDirective(
2310 0, StringRef(), CppHashInfo.Filename);
2311 getContext().setGenDwarfFileNumber(FileNumber);
2313 unsigned CppHashLocLineNo =
2315 Line = CppHashInfo.LineNumber - 1 + (
Line - CppHashLocLineNo);
2318 getStreamer().emitDwarfLocDirective(
2319 getContext().getGenDwarfFileNumber(), Line, 0,
2325 if (!ParseHadError) {
2327 if (getTargetParser().matchAndEmitInstruction(
2328 IDLoc,
Info.Opcode,
Info.ParsedOperands, Out, ErrorInfo,
2329 getTargetParser().isParsingMSInlineAsm()))
2337AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
2342 SMLoc StartLoc = Lexer.
getLoc();
2355bool AsmParser::parseCppHashLineFilenameComment(SMLoc L,
bool SaveLocInfo) {
2360 "Lexing Cpp line comment: Expected Integer");
2361 int64_t LineNumber = getTok().getIntVal();
2364 "Lexing Cpp line comment: Expected String");
2365 StringRef
Filename = getTok().getString();
2376 CppHashInfo.Loc =
L;
2378 CppHashInfo.LineNumber = LineNumber;
2379 CppHashInfo.Buf = CurBuffer;
2380 if (!HadCppHashFilename) {
2381 HadCppHashFilename =
true;
2391 std::nullopt, std::nullopt);
2399void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *
Context) {
2400 auto *Parser =
static_cast<AsmParser *
>(
Context);
2401 raw_ostream &OS =
errs();
2404 SMLoc DiagLoc = Diag.
getLoc();
2406 unsigned CppHashBuf =
2407 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2412 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2421 if (!Parser->CppHashInfo.LineNumber || DiagBuf != CppHashBuf) {
2422 if (Parser->SavedDiagHandler)
2423 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2425 Parser->getContext().diagnose(Diag);
2432 const std::string &
Filename = std::string(Parser->CppHashInfo.Filename);
2435 int CppHashLocLineNo =
2436 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2438 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2444 if (Parser->SavedDiagHandler)
2445 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2447 Parser->getContext().diagnose(NewDiag);
2455 return isalnum(
static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2459bool AsmParser::expandMacro(raw_svector_ostream &OS, MCAsmMacro &
Macro,
2462 bool EnableAtPseudoVariable) {
2464 auto expandArg = [&](
unsigned Index) {
2465 bool HasVararg = NParameters ?
Parameters.back().Vararg :
false;
2466 bool VarargParameter = HasVararg &&
Index == (NParameters - 1);
2467 for (
const AsmToken &Token :
A[Index])
2475 if (AltMacroMode && Token.getString().front() ==
'%' &&
2478 OS << Token.getIntVal();
2481 else if (AltMacroMode && Token.getString().front() ==
'<' &&
2488 OS << Token.getString();
2490 OS << Token.getStringContents();
2495 StringRef Body =
Macro.Body;
2496 size_t I = 0, End = Body.
size();
2498 if (Body[
I] ==
'\\' &&
I + 1 != End) {
2500 if (EnableAtPseudoVariable && Body[
I + 1] ==
'@') {
2501 OS << NumOfMacroInstantiations;
2505 if (Body[
I + 1] ==
'+') {
2510 if (Body[
I + 1] ==
'(' && Body[
I + 2] ==
')') {
2519 if (AltMacroMode &&
I != End && Body[
I] ==
'&')
2523 if (Parameters[Index].Name == Argument)
2525 if (Index == NParameters)
2534 if (Body[
I] ==
'$' &&
I + 1 != End && IsDarwin && !NParameters) {
2536 switch (Body[
I + 1]) {
2552 unsigned Index = Body[
I + 1] -
'0';
2553 if (Index <
A.size())
2554 for (
const AsmToken &Token :
A[Index])
2555 OS << Token.getString();
2570 StringRef Token(Body.
data() + Start,
I - Start);
2574 if (Parameters[Index].Name == Token)
2576 if (Index != NParameters) {
2578 if (
I != End && Body[
I] ==
'&')
2622class AsmLexerSkipSpaceRAII {
2624 AsmLexerSkipSpaceRAII(AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2628 ~AsmLexerSkipSpaceRAII() {
2638bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2642 StringRef Str = parseStringToEndOfStatement();
2648 unsigned ParenLevel = 0;
2651 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2658 return TokError(
"unexpected token in macro instantiation");
2660 if (ParenLevel == 0) {
2673 MA.push_back(getTok());
2697 MA.push_back(getTok());
2701 if (ParenLevel != 0)
2702 return TokError(
"unbalanced parentheses in macro argument");
2707bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2708 MCAsmMacroArguments &
A) {
2709 const unsigned NParameters =
M ?
M->Parameters.size() : 0;
2710 bool NamedParametersFound =
false;
2711 SmallVector<SMLoc, 4> FALocs;
2713 A.resize(NParameters);
2714 FALocs.
resize(NParameters);
2719 bool HasVararg = NParameters ?
M->Parameters.back().Vararg :
false;
2720 for (
unsigned Parameter = 0; !NParameters ||
Parameter < NParameters;
2722 SMLoc IDLoc = Lexer.
getLoc();
2723 MCAsmMacroParameter FA;
2726 if (parseIdentifier(FA.
Name))
2727 return Error(IDLoc,
"invalid argument identifier for formal argument");
2730 return TokError(
"expected '=' after formal parameter identifier");
2734 NamedParametersFound =
true;
2736 bool Vararg = HasVararg &&
Parameter == (NParameters - 1);
2738 if (NamedParametersFound && FA.
Name.
empty())
2739 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2741 SMLoc StrLoc = Lexer.
getLoc();
2744 const MCExpr *AbsoluteExp;
2748 if (parseExpression(AbsoluteExp, EndLoc))
2750 if (!AbsoluteExp->evaluateAsAbsolute(
Value,
2751 getStreamer().getAssemblerPtr()))
2752 return Error(StrLoc,
"expected absolute expression");
2756 StringRef(StrChar, EndChar - StrChar),
Value);
2757 FA.
Value.push_back(newToken);
2762 jumpToLoc(EndLoc, CurBuffer);
2766 StringRef(StrChar, EndChar - StrChar));
2767 FA.
Value.push_back(newToken);
2768 }
else if(parseMacroArgument(FA.
Value, Vararg))
2774 for (FAI = 0; FAI < NParameters; ++FAI)
2775 if (
M->Parameters[FAI].Name == FA.
Name)
2778 if (FAI >= NParameters) {
2779 assert(M &&
"expected macro to be defined");
2780 return Error(IDLoc,
"parameter named '" + FA.
Name +
2781 "' does not exist for macro '" +
M->Name +
"'");
2786 if (!FA.
Value.empty()) {
2791 if (FALocs.
size() <= PI)
2794 FALocs[PI] = Lexer.
getLoc();
2802 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2804 if (
M->Parameters[FAI].Required) {
2806 "missing value for required parameter "
2807 "'" +
M->Parameters[FAI].Name +
"' in macro '" +
M->Name +
"'");
2811 if (!
M->Parameters[FAI].Value.empty())
2812 A[FAI] =
M->Parameters[FAI].Value;
2821 return TokError(
"too many positional arguments");
2824bool AsmParser::handleMacroEntry(MCAsmMacro *M, SMLoc NameLoc) {
2828 if (ActiveMacros.size() == MaxNestingDepth) {
2829 std::ostringstream MaxNestingDepthError;
2830 MaxNestingDepthError <<
"macros cannot be nested more than "
2831 << MaxNestingDepth <<
" levels deep."
2832 <<
" Use -asm-macro-max-nesting-depth to increase "
2834 return TokError(MaxNestingDepthError.str());
2837 MCAsmMacroArguments
A;
2838 if (parseMacroArguments(M,
A))
2843 SmallString<256> Buf;
2844 raw_svector_ostream OS(Buf);
2846 if ((!IsDarwin ||
M->Parameters.size()) &&
M->Parameters.size() !=
A.size())
2847 return Error(getTok().getLoc(),
"Wrong number of arguments");
2848 if (expandMacro(OS, *M,
M->Parameters,
A,
true))
2853 OS <<
".endmacro\n";
2855 std::unique_ptr<MemoryBuffer> Instantiation =
2860 MacroInstantiation *
MI =
new MacroInstantiation{
2861 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
2862 ActiveMacros.push_back(
MI);
2864 ++NumOfMacroInstantiations;
2874void AsmParser::handleMacroExit() {
2876 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2884 delete ActiveMacros.back();
2885 ActiveMacros.pop_back();
2888bool AsmParser::parseAssignment(StringRef Name, AssignmentKind Kind) {
2890 const MCExpr *
Value;
2891 SMLoc ExprLoc = getTok().getLoc();
2893 Kind == AssignmentKind::Set ||
Kind == AssignmentKind::Equal;
2905 if (discardLTOSymbol(Name))
2910 case AssignmentKind::Equal:
2913 case AssignmentKind::Set:
2914 case AssignmentKind::Equiv:
2918 case AssignmentKind::LTOSetConditional:
2920 return Error(ExprLoc,
"expected identifier");
2932bool AsmParser::parseIdentifier(StringRef &Res) {
2939 SMLoc PrefixLoc = getLexer().getLoc();
2951 if (PrefixLoc.
getPointer() + 1 != Buf[0].getLoc().getPointer())
2957 Res = StringRef(PrefixLoc.
getPointer(), getTok().getString().
size() + 1);
2965 Res = getTok().getIdentifier();
2977bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
2979 if (check(parseIdentifier(Name),
"expected identifier") || parseComma() ||
2980 parseAssignment(Name, Kind))
2985bool AsmParser::parseEscapedString(std::string &
Data) {
2990 StringRef Str = getTok().getStringContents();
2991 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
2992 if (Str[i] !=
'\\') {
2993 if ((Str[i] ==
'\n') || (Str[i] ==
'\r')) {
2995 if ((Str[i] ==
'\n') && (i > 0) && (Str[i - 1] ==
'\r'))
2999 if (
Warning(NewlineLoc,
"unterminated string; newline inserted"))
3010 return TokError(
"unexpected backslash at end of string");
3013 if (Str[i] ==
'x' || Str[i] ==
'X') {
3014 size_t length = Str.size();
3015 if (i + 1 >= length || !
isHexDigit(Str[i + 1]))
3016 return TokError(
"invalid hexadecimal escape sequence");
3021 while (i + 1 < length &&
isHexDigit(Str[i + 1]))
3029 if ((
unsigned)(Str[i] -
'0') <= 7) {
3031 unsigned Value = Str[i] -
'0';
3033 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3037 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
3044 return TokError(
"invalid octal escape sequence (out of range)");
3054 return TokError(
"invalid escape sequence (unrecognized character)");
3056 case 'b':
Data +=
'\b';
break;
3057 case 'f':
Data +=
'\f';
break;
3058 case 'n':
Data +=
'\n';
break;
3059 case 'r':
Data +=
'\r';
break;
3060 case 't':
Data +=
'\t';
break;
3061 case '"':
Data +=
'"';
break;
3062 case '\\':
Data +=
'\\';
break;
3070bool AsmParser::parseAngleBracketString(std::string &
Data) {
3071 SMLoc EndLoc, StartLoc = getTok().getLoc();
3073 const char *StartChar = StartLoc.
getPointer() + 1;
3074 const char *EndChar = EndLoc.
getPointer() - 1;
3075 jumpToLoc(EndLoc, CurBuffer);
3088bool AsmParser::parseDirectiveAscii(StringRef IDVal,
bool ZeroTerminated) {
3089 auto parseOp = [&]() ->
bool {
3091 if (checkForValidSection())
3096 if (parseEscapedString(
Data))
3098 getStreamer().emitBytes(
Data);
3101 getStreamer().emitBytes(StringRef(
"\0", 1));
3105 return parseMany(parseOp);
3110bool AsmParser::parseDirectiveBase64() {
3111 auto parseOp = [&]() ->
bool {
3112 if (checkForValidSection())
3119 std::vector<char> Decoded;
3120 std::string
const str = getTok().getStringContents().str();
3121 if (check(str.empty(),
"expected nonempty string")) {
3128 return Error(Lexer.
getLoc(),
"failed to base64 decode string data");
3131 getStreamer().emitBytes(std::string(Decoded.begin(), Decoded.end()));
3136 return check(parseMany(parseOp),
"expected string");
3141bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
3143 const MCExpr *Expr =
nullptr;
3145 if (parseExpression(
Offset))
3157 SMLoc ExprLoc = Lexer.
getLoc();
3158 if (parseExpression(Expr))
3163 return Error(ExprLoc,
"expression must be relocatable");
3169 getStreamer().emitRelocDirective(*
Offset, Name, Expr, NameLoc);
3175bool AsmParser::parseDirectiveValue(StringRef IDVal,
unsigned Size) {
3176 auto parseOp = [&]() ->
bool {
3177 const MCExpr *
Value;
3178 SMLoc ExprLoc = getLexer().getLoc();
3179 if (checkForValidSection() || getTargetParser().parseDataExpr(
Value))
3184 uint64_t IntValue = MCE->getValue();
3186 return Error(ExprLoc,
"out of range literal value");
3187 getStreamer().emitIntValue(IntValue,
Size);
3189 getStreamer().emitValue(
Value,
Size, ExprLoc);
3193 return parseMany(parseOp);
3199 return Asm.TokError(
"unknown token in expression");
3200 SMLoc ExprLoc = Asm.getTok().getLoc();
3201 APInt IntValue = Asm.getTok().getAPIntVal();
3203 if (!IntValue.
isIntN(128))
3204 return Asm.Error(ExprLoc,
"out of range literal value");
3205 if (!IntValue.
isIntN(64)) {
3218bool AsmParser::parseDirectiveOctaValue(StringRef IDVal) {
3219 auto parseOp = [&]() ->
bool {
3220 if (checkForValidSection())
3226 getStreamer().emitInt64(lo);
3227 getStreamer().emitInt64(hi);
3229 getStreamer().emitInt64(hi);
3230 getStreamer().emitInt64(lo);
3235 return parseMany(parseOp);
3238bool AsmParser::parseRealValue(
const fltSemantics &Semantics, APInt &Res) {
3249 return TokError(Lexer.
getErr());
3252 return TokError(
"unexpected token in directive");
3256 StringRef IDVal = getTok().getString();
3264 return TokError(
"invalid floating point literal");
3266 Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven)
3268 return TokError(
"invalid floating point literal");
3275 Res =
Value.bitcastToAPInt();
3282bool AsmParser::parseDirectiveRealValue(StringRef IDVal,
3283 const fltSemantics &Semantics) {
3284 auto parseOp = [&]() ->
bool {
3286 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
3293 return parseMany(parseOp);
3298bool AsmParser::parseDirectiveZero() {
3299 SMLoc NumBytesLoc = Lexer.
getLoc();
3300 const MCExpr *NumBytes;
3301 if (checkForValidSection() || parseExpression(NumBytes))
3307 if (parseAbsoluteExpression(Val))
3313 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3320bool AsmParser::parseDirectiveFill() {
3321 SMLoc NumValuesLoc = Lexer.
getLoc();
3322 const MCExpr *NumValues;
3323 if (checkForValidSection() || parseExpression(NumValues))
3326 int64_t FillSize = 1;
3327 int64_t FillExpr = 0;
3329 SMLoc SizeLoc, ExprLoc;
3332 SizeLoc = getTok().getLoc();
3333 if (parseAbsoluteExpression(FillSize))
3336 ExprLoc = getTok().getLoc();
3337 if (parseAbsoluteExpression(FillExpr))
3345 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3349 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3354 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3356 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3363bool AsmParser::parseDirectiveOrg() {
3365 SMLoc OffsetLoc = Lexer.
getLoc();
3366 if (checkForValidSection() || parseExpression(
Offset))
3370 int64_t FillExpr = 0;
3372 if (parseAbsoluteExpression(FillExpr))
3377 getStreamer().emitValueToOffset(
Offset, FillExpr, OffsetLoc);
3383bool AsmParser::parseDirectiveAlign(
bool IsPow2, uint8_t ValueSize) {
3384 SMLoc AlignmentLoc = getLexer().getLoc();
3387 bool HasFillExpr =
false;
3388 int64_t FillExpr = 0;
3389 int64_t MaxBytesToFill = 0;
3392 auto parseAlign = [&]() ->
bool {
3393 if (parseAbsoluteExpression(Alignment))
3401 if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
3405 if (parseTokenLoc(MaxBytesLoc) ||
3406 parseAbsoluteExpression(MaxBytesToFill))
3412 if (checkForValidSection())
3416 Warning(AlignmentLoc,
"p2align directive with no operand(s) is ignored");
3423 bool ReturnVal =
false;
3428 if (Alignment >= 32) {
3429 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3433 Alignment = 1ULL << Alignment;
3441 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3445 ReturnVal |=
Error(AlignmentLoc,
"alignment must be smaller than 2**32");
3446 Alignment = 1u << 31;
3452 if (MaxBytesToFill < 1) {
3453 ReturnVal |=
Error(MaxBytesLoc,
3454 "alignment directive can never be satisfied in this "
3455 "many bytes, ignoring maximum bytes expression");
3459 if (MaxBytesToFill >= Alignment) {
3460 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3466 const MCSection *
Section = getStreamer().getCurrentSectionOnly();
3467 assert(Section &&
"must have section to emit alignment");
3469 if (HasFillExpr && FillExpr != 0 &&
Section->isBssSection()) {
3471 Warning(FillExprLoc,
"ignoring non-zero fill value in BSS section '" +
3479 getStreamer().emitCodeAlignment(
3480 Align(Alignment), &getTargetParser().getSTI(), MaxBytesToFill);
3483 getStreamer().emitValueToAlignment(
Align(Alignment), FillExpr, ValueSize,
3490bool AsmParser::parseDirectivePrefAlign() {
3491 SMLoc AlignmentLoc = getLexer().getLoc();
3493 if (checkForValidSection() || parseAbsoluteExpression(Log2Alignment))
3496 if (Log2Alignment < 0 || Log2Alignment > 63)
3497 return Error(AlignmentLoc,
"log2 alignment must be in the range [0, 63]");
3500 SMLoc SymLoc = getLexer().getLoc();
3504 SymLoc = getLexer().getLoc();
3505 if (parseIdentifier(Name))
3506 return Error(SymLoc,
"expected symbol name");
3510 SMLoc FillLoc = getLexer().getLoc();
3514 bool EmitNops =
false;
3516 SMLoc FillLoc2 = getLexer().getLoc();
3518 getLexer().getTok().getIdentifier() ==
"nop") {
3523 if (parseAbsoluteExpression(FillVal))
3525 if (FillVal < 0 || FillVal > 255)
3526 return Error(FillLoc2,
"fill value must be in range [0, 255]");
3527 Fill =
static_cast<uint8_t
>(FillVal);
3532 if ((EmitNops || Fill != 0) &&
3533 getStreamer().getCurrentSectionOnly()->isBssSection())
3534 return Error(FillLoc,
"non-zero fill in BSS section '" +
3535 getStreamer().getCurrentSectionOnly()->
getName() +
3538 getStreamer().emitPrefAlign(
Align(1ULL << Log2Alignment), *End, EmitNops,
3539 Fill, getTargetParser().getSTI());
3546bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
3548 int64_t FileNumber = -1;
3550 FileNumber = getTok().getIntVal();
3554 return TokError(
"negative file number");
3561 if (parseEscapedString(Path))
3564 StringRef Directory;
3566 std::string FilenameData;
3568 if (check(FileNumber == -1,
3569 "explicit path specified, but no file number") ||
3570 parseEscapedString(FilenameData))
3578 uint64_t MD5Hi, MD5Lo;
3579 bool HasMD5 =
false;
3581 std::optional<StringRef>
Source;
3582 bool HasSource =
false;
3583 std::string SourceString;
3588 "unexpected token in '.file' directive") ||
3589 parseIdentifier(Keyword))
3591 if (Keyword ==
"md5") {
3593 if (check(FileNumber == -1,
3594 "MD5 checksum specified, but no file number") ||
3597 }
else if (Keyword ==
"source") {
3599 if (check(FileNumber == -1,
3600 "source specified, but no file number") ||
3602 "unexpected token in '.file' directive") ||
3603 parseEscapedString(SourceString))
3606 return TokError(
"unexpected token in '.file' directive");
3610 if (FileNumber == -1) {
3614 if (
getContext().getAsmInfo().hasSingleParameterDotFile())
3615 getStreamer().emitFileDirective(
Filename);
3625 std::optional<MD5::MD5Result> CKMem;
3628 for (
unsigned i = 0; i != 8; ++i) {
3629 Sum[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
3630 Sum[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
3635 char *SourceBuf =
static_cast<char *
>(Ctx.
allocate(SourceString.size()));
3636 memcpy(SourceBuf, SourceString.data(), SourceString.size());
3637 Source = StringRef(SourceBuf, SourceString.size());
3639 if (FileNumber == 0) {
3643 getStreamer().emitDwarfFile0Directive(Directory,
Filename, CKMem, Source);
3645 Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
3646 FileNumber, Directory,
Filename, CKMem, Source);
3653 ReportedInconsistentMD5 =
true;
3654 return Warning(DirectiveLoc,
"inconsistent use of MD5 checksums");
3663bool AsmParser::parseDirectiveLine() {
3675bool AsmParser::parseDirectiveLoc() {
3676 int64_t FileNumber = 0, LineNumber = 0;
3677 SMLoc Loc = getTok().getLoc();
3678 if (parseIntToken(FileNumber) ||
3680 "file number less than one in '.loc' directive") ||
3681 check(!
getContext().isValidDwarfFileNumber(FileNumber), Loc,
3682 "unassigned file number in '.loc' directive"))
3687 LineNumber = getTok().getIntVal();
3689 return TokError(
"line number less than zero in '.loc' directive");
3693 int64_t ColumnPos = 0;
3695 ColumnPos = getTok().getIntVal();
3697 return TokError(
"column position less than zero in '.loc' directive");
3701 auto PrevFlags =
getContext().getCurrentDwarfLoc().getFlags();
3706 auto parseLocOp = [&]() ->
bool {
3708 SMLoc Loc = getTok().getLoc();
3709 if (parseIdentifier(Name))
3710 return TokError(
"unexpected token in '.loc' directive");
3712 if (Name ==
"basic_block")
3714 else if (Name ==
"prologue_end")
3716 else if (Name ==
"epilogue_begin")
3718 else if (Name ==
"is_stmt") {
3719 Loc = getTok().getLoc();
3720 const MCExpr *
Value;
3721 if (parseExpression(
Value))
3725 int Value = MCE->getValue();
3727 Flags &= ~DWARF2_FLAG_IS_STMT;
3728 else if (
Value == 1)
3731 return Error(Loc,
"is_stmt value not 0 or 1");
3733 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3735 }
else if (Name ==
"isa") {
3736 Loc = getTok().getLoc();
3737 const MCExpr *
Value;
3738 if (parseExpression(
Value))
3742 int Value = MCE->getValue();
3744 return Error(Loc,
"isa number less than zero");
3747 return Error(Loc,
"isa number not a constant value");
3749 }
else if (Name ==
"discriminator") {
3750 if (parseAbsoluteExpression(Discriminator))
3753 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3758 if (parseMany(parseLocOp,
false ))
3761 getStreamer().emitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3762 Isa, Discriminator, StringRef());
3769bool AsmParser::parseDirectiveLocLabel(SMLoc DirectiveLoc) {
3771 DirectiveLoc = Lexer.
getLoc();
3772 if (parseIdentifier(Name))
3773 return TokError(
"expected identifier");
3776 getStreamer().emitDwarfLocLabelDirective(DirectiveLoc, Name);
3782bool AsmParser::parseDirectiveStabs() {
3783 return TokError(
"unsupported directive '.stabs'");
3788bool AsmParser::parseDirectiveCVFile() {
3789 SMLoc FileNumberLoc = getTok().getLoc();
3792 std::string Checksum;
3795 if (parseIntToken(FileNumber,
"expected file number") ||
3796 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3798 "unexpected token in '.cv_file' directive") ||
3803 "unexpected token in '.cv_file' directive") ||
3804 parseEscapedString(Checksum) ||
3805 parseIntToken(ChecksumKind,
3806 "expected checksum kind in '.cv_file' directive") ||
3812 void *CKMem = Ctx.
allocate(Checksum.size(), 1);
3813 memcpy(CKMem, Checksum.data(), Checksum.size());
3814 ArrayRef<uint8_t> ChecksumAsBytes(
reinterpret_cast<const uint8_t *
>(CKMem),
3817 if (!getStreamer().emitCVFileDirective(FileNumber,
Filename, ChecksumAsBytes,
3818 static_cast<uint8_t
>(ChecksumKind)))
3819 return Error(FileNumberLoc,
"file number already allocated");
3824bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3825 StringRef DirectiveName) {
3827 return parseTokenLoc(Loc) ||
3828 parseIntToken(FunctionId,
"expected function id") ||
3829 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3830 "expected function id within range [0, UINT_MAX)");
3833bool AsmParser::parseCVFileId(int64_t &FileNumber, StringRef DirectiveName) {
3835 return parseTokenLoc(Loc) ||
3836 parseIntToken(FileNumber,
"expected file number") ||
3837 check(FileNumber < 1, Loc,
3838 "file number less than one in '" + DirectiveName +
3840 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3841 "unassigned file number in '" + DirectiveName +
"' directive");
3848bool AsmParser::parseDirectiveCVFuncId() {
3849 SMLoc FunctionIdLoc = getTok().getLoc();
3852 if (parseCVFunctionId(FunctionId,
".cv_func_id") || parseEOL())
3855 if (!getStreamer().emitCVFuncIdDirective(FunctionId))
3856 return Error(FunctionIdLoc,
"function id already allocated");
3869bool AsmParser::parseDirectiveCVInlineSiteId() {
3870 SMLoc FunctionIdLoc = getTok().getLoc();
3878 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3883 getTok().getIdentifier() !=
"within"),
3884 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3889 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3894 getTok().getIdentifier() !=
"inlined_at"),
3895 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3901 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3902 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3907 IACol = getTok().getIntVal();
3914 if (!getStreamer().emitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3915 IALine, IACol, FunctionIdLoc))
3916 return Error(FunctionIdLoc,
"function id already allocated");
3928bool AsmParser::parseDirectiveCVLoc() {
3929 SMLoc DirectiveLoc = getTok().getLoc();
3930 int64_t FunctionId, FileNumber;
3931 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3932 parseCVFileId(FileNumber,
".cv_loc"))
3935 int64_t LineNumber = 0;
3937 LineNumber = getTok().getIntVal();
3939 return TokError(
"line number less than zero in '.cv_loc' directive");
3943 int64_t ColumnPos = 0;
3945 ColumnPos = getTok().getIntVal();
3947 return TokError(
"column position less than zero in '.cv_loc' directive");
3951 bool PrologueEnd =
false;
3952 uint64_t IsStmt = 0;
3954 auto parseOp = [&]() ->
bool {
3956 SMLoc Loc = getTok().getLoc();
3957 if (parseIdentifier(Name))
3958 return TokError(
"unexpected token in '.cv_loc' directive");
3959 if (Name ==
"prologue_end")
3961 else if (Name ==
"is_stmt") {
3962 Loc = getTok().getLoc();
3963 const MCExpr *
Value;
3964 if (parseExpression(
Value))
3969 IsStmt = MCE->getValue();
3972 return Error(Loc,
"is_stmt value not 0 or 1");
3974 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3979 if (parseMany(parseOp,
false ))
3982 getStreamer().emitCVLocDirective(FunctionId, FileNumber, LineNumber,
3983 ColumnPos, PrologueEnd, IsStmt, StringRef(),
3990bool AsmParser::parseDirectiveCVLinetable() {
3993 SMLoc Loc = getTok().getLoc();
3994 if (parseCVFunctionId(FunctionId,
".cv_linetable") || parseComma() ||
3995 parseTokenLoc(Loc) ||
3996 check(
parseSymbol(FnStartSym), Loc,
"expected identifier in directive") ||
3997 parseComma() || parseTokenLoc(Loc) ||
3998 check(
parseSymbol(FnEndSym), Loc,
"expected identifier in directive"))
4001 getStreamer().emitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
4007bool AsmParser::parseDirectiveCVInlineLinetable() {
4008 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
4010 SMLoc Loc = getTok().getLoc();
4011 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
4012 parseTokenLoc(Loc) ||
4013 parseIntToken(SourceFileId,
"expected SourceField") ||
4014 check(SourceFileId <= 0, Loc,
"File id less than zero") ||
4015 parseTokenLoc(Loc) ||
4016 parseIntToken(SourceLineNum,
"expected SourceLineNum") ||
4017 check(SourceLineNum < 0, Loc,
"Line number less than zero") ||
4018 parseTokenLoc(Loc) ||
4019 check(
parseSymbol(FnStartSym), Loc,
"expected identifier") ||
4020 parseTokenLoc(Loc) ||
4021 check(
parseSymbol(FnEndSym), Loc,
"expected identifier"))
4027 getStreamer().emitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
4028 SourceLineNum, FnStartSym,
4033void AsmParser::initializeCVDefRangeTypeMap() {
4034 CVDefRangeTypeMap[
"reg"] = CVDR_DEFRANGE_REGISTER;
4035 CVDefRangeTypeMap[
"frame_ptr_rel"] = CVDR_DEFRANGE_FRAMEPOINTER_REL;
4036 CVDefRangeTypeMap[
"subfield_reg"] = CVDR_DEFRANGE_SUBFIELD_REGISTER;
4037 CVDefRangeTypeMap[
"reg_rel"] = CVDR_DEFRANGE_REGISTER_REL;
4038 CVDefRangeTypeMap[
"reg_rel_indir"] = CVDR_DEFRANGE_REGISTER_REL_INDIR;
4043bool AsmParser::parseDirectiveCVDefRange() {
4045 std::vector<std::pair<const MCSymbol *, const MCSymbol *>>
Ranges;
4047 Loc = getLexer().getLoc();
4050 return Error(Loc,
"expected identifier in directive");
4052 Loc = getLexer().getLoc();
4055 return Error(Loc,
"expected identifier in directive");
4057 Ranges.push_back({GapStartSym, GapEndSym});
4060 StringRef CVDefRangeTypeStr;
4063 "expected comma before def_range type in .cv_def_range directive") ||
4064 parseIdentifier(CVDefRangeTypeStr))
4065 return Error(Loc,
"expected def_range type in directive");
4068 CVDefRangeTypeMap.find(CVDefRangeTypeStr);
4069 CVDefRangeType CVDRType = (CVTypeIt == CVDefRangeTypeMap.end())
4071 : CVTypeIt->getValue();
4073 case CVDR_DEFRANGE_REGISTER: {
4075 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4076 ".cv_def_range directive") ||
4077 parseAbsoluteExpression(DRRegister))
4078 return Error(Loc,
"expected register number");
4080 codeview::DefRangeRegisterHeader DRHdr;
4083 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4086 case CVDR_DEFRANGE_FRAMEPOINTER_REL: {
4089 "expected comma before offset in .cv_def_range directive") ||
4090 parseAbsoluteExpression(DROffset))
4091 return Error(Loc,
"expected offset value");
4093 codeview::DefRangeFramePointerRelHeader DRHdr;
4095 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4098 case CVDR_DEFRANGE_SUBFIELD_REGISTER: {
4100 int64_t DROffsetInParent;
4101 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4102 ".cv_def_range directive") ||
4103 parseAbsoluteExpression(DRRegister))
4104 return Error(Loc,
"expected register number");
4106 "expected comma before offset in .cv_def_range directive") ||
4107 parseAbsoluteExpression(DROffsetInParent))
4108 return Error(Loc,
"expected offset value");
4110 codeview::DefRangeSubfieldRegisterHeader DRHdr;
4114 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4117 case CVDR_DEFRANGE_REGISTER_REL: {
4120 int64_t DRBasePointerOffset;
4121 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4122 ".cv_def_range directive") ||
4123 parseAbsoluteExpression(DRRegister))
4124 return Error(Loc,
"expected register value");
4127 "expected comma before flag value in .cv_def_range directive") ||
4128 parseAbsoluteExpression(DRFlags))
4129 return Error(Loc,
"expected flag value");
4130 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4131 "in .cv_def_range directive") ||
4132 parseAbsoluteExpression(DRBasePointerOffset))
4133 return Error(Loc,
"expected base pointer offset value");
4135 codeview::DefRangeRegisterRelHeader DRHdr;
4137 DRHdr.
Flags = DRFlags;
4139 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4142 case CVDR_DEFRANGE_REGISTER_REL_INDIR: {
4145 int64_t DRBasePointerOffset;
4146 int64_t DROffsetInUdt;
4147 if (parseToken(
AsmToken::Comma,
"expected comma before register number in "
4148 ".cv_def_range directive") ||
4149 parseAbsoluteExpression(DRRegister))
4150 return Error(Loc,
"expected register value");
4153 "expected comma before flag value in .cv_def_range directive") ||
4154 parseAbsoluteExpression(DRFlags))
4155 return Error(Loc,
"expected flag value");
4156 if (parseToken(
AsmToken::Comma,
"expected comma before base pointer offset "
4157 "in .cv_def_range directive") ||
4158 parseAbsoluteExpression(DRBasePointerOffset))
4159 return Error(Loc,
"expected base pointer offset value");
4160 if (parseToken(
AsmToken::Comma,
"expected comma before offset in UDT "
4161 "in .cv_def_range directive") ||
4162 parseAbsoluteExpression(DROffsetInUdt))
4163 return Error(Loc,
"expected offset in UDT value");
4165 codeview::DefRangeRegisterRelIndirHeader DRHdr;
4167 DRHdr.
Flags = DRFlags;
4170 getStreamer().emitCVDefRangeDirective(Ranges, DRHdr);
4174 return Error(Loc,
"unexpected def_range type in .cv_def_range directive");
4181bool AsmParser::parseDirectiveCVString() {
4183 if (checkForValidSection() || parseEscapedString(
Data))
4187 std::pair<StringRef, unsigned> Insertion =
4188 getCVContext().addToStringTable(
Data);
4189 getStreamer().emitInt32(Insertion.second);
4195bool AsmParser::parseDirectiveCVStringTable() {
4196 getStreamer().emitCVStringTableDirective();
4202bool AsmParser::parseDirectiveCVFileChecksums() {
4203 getStreamer().emitCVFileChecksumsDirective();
4209bool AsmParser::parseDirectiveCVFileChecksumOffset() {
4211 if (parseIntToken(FileNo))
4215 getStreamer().emitCVFileChecksumOffsetDirective(FileNo);
4221bool AsmParser::parseDirectiveCVFPOData() {
4222 SMLoc DirLoc = getLexer().getLoc();
4225 return TokError(
"expected symbol name");
4228 getStreamer().emitCVFPOData(ProcSym, DirLoc);
4234bool AsmParser::parseDirectiveCFISections() {
4238 bool SFrame =
false;
4242 if (parseIdentifier(Name))
4243 return TokError(
"expected .eh_frame, .debug_frame, or .sframe");
4244 if (Name ==
".eh_frame")
4246 else if (Name ==
".debug_frame")
4248 else if (Name ==
".sframe")
4256 getStreamer().emitCFISections(EH,
Debug, SFrame);
4262bool AsmParser::parseDirectiveCFIStartProc() {
4263 CFIStartProcLoc = StartTokLoc;
4267 if (check(parseIdentifier(
Simple) ||
Simple !=
"simple",
4268 "unexpected token") ||
4278 getStreamer().emitCFIStartProc(!
Simple.empty(), Lexer.
getLoc());
4284bool AsmParser::parseDirectiveCFIEndProc() {
4285 CFIStartProcLoc = std::nullopt;
4290 getStreamer().emitCFIEndProc();
4295bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
4296 SMLoc DirectiveLoc) {
4300 if (getTargetParser().parseRegister(RegNo, DirectiveLoc, DirectiveLoc))
4304 return parseAbsoluteExpression(
Register);
4311bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
4313 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4314 parseAbsoluteExpression(
Offset) || parseEOL())
4323bool AsmParser::parseDirectiveCFIDefCfaOffset(SMLoc DirectiveLoc) {
4325 if (parseAbsoluteExpression(
Offset) || parseEOL())
4328 getStreamer().emitCFIDefCfaOffset(
Offset, DirectiveLoc);
4334bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
4335 int64_t Register1 = 0, Register2 = 0;
4336 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
4337 parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
4340 getStreamer().emitCFIRegister(Register1, Register2, DirectiveLoc);
4346bool AsmParser::parseDirectiveCFIWindowSave(SMLoc DirectiveLoc) {
4349 getStreamer().emitCFIWindowSave(DirectiveLoc);
4355bool AsmParser::parseDirectiveCFIAdjustCfaOffset(SMLoc DirectiveLoc) {
4356 int64_t Adjustment = 0;
4357 if (parseAbsoluteExpression(Adjustment) || parseEOL())
4360 getStreamer().emitCFIAdjustCfaOffset(Adjustment, DirectiveLoc);
4366bool AsmParser::parseDirectiveCFIDefCfaRegister(SMLoc DirectiveLoc) {
4368 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4371 getStreamer().emitCFIDefCfaRegister(
Register, DirectiveLoc);
4377bool AsmParser::parseDirectiveCFILLVMDefAspaceCfa(SMLoc DirectiveLoc) {
4379 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4380 parseAbsoluteExpression(
Offset) || parseComma() ||
4391bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
4395 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4396 parseAbsoluteExpression(
Offset) || parseEOL())
4405bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
4408 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4409 parseAbsoluteExpression(
Offset) || parseEOL())
4417 if (Encoding & ~0xff)
4423 const unsigned Format = Encoding & 0xf;
4430 const unsigned Application = Encoding & 0x70;
4442bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
4443 int64_t Encoding = 0;
4444 if (parseAbsoluteExpression(Encoding))
4452 check(
parseSymbol(Sym),
"expected identifier in directive") || parseEOL())
4456 getStreamer().emitCFIPersonality(Sym, Encoding);
4458 getStreamer().emitCFILsda(Sym, Encoding);
4464bool AsmParser::parseDirectiveCFIRememberState(SMLoc DirectiveLoc) {
4467 getStreamer().emitCFIRememberState(DirectiveLoc);
4473bool AsmParser::parseDirectiveCFIRestoreState(SMLoc DirectiveLoc) {
4476 getStreamer().emitCFIRestoreState(DirectiveLoc);
4482bool AsmParser::parseDirectiveCFISameValue(SMLoc DirectiveLoc) {
4485 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4488 getStreamer().emitCFISameValue(
Register, DirectiveLoc);
4494bool AsmParser::parseDirectiveCFIRestore(SMLoc DirectiveLoc) {
4496 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4499 getStreamer().emitCFIRestore(
Register, DirectiveLoc);
4505bool AsmParser::parseDirectiveCFIEscape(SMLoc DirectiveLoc) {
4508 if (parseAbsoluteExpression(CurrValue))
4511 Values.push_back((uint8_t)CurrValue);
4516 if (parseAbsoluteExpression(CurrValue))
4519 Values.push_back((uint8_t)CurrValue);
4522 getStreamer().emitCFIEscape(Values, DirectiveLoc);
4528bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
4530 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4532 getStreamer().emitCFIReturnColumn(
Register);
4538bool AsmParser::parseDirectiveCFISignalFrame(SMLoc DirectiveLoc) {
4542 getStreamer().emitCFISignalFrame();
4548bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
4551 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseEOL())
4554 getStreamer().emitCFIUndefined(
Register, DirectiveLoc);
4560bool AsmParser::parseDirectiveCFILLVMRegisterPair(SMLoc DirectiveLoc) {
4562 int64_t R1 = 0,
R2 = 0;
4563 int64_t R1Size = 0, R2Size = 0;
4565 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4566 parseRegisterOrRegisterNumber(R1, DirectiveLoc) || parseComma() ||
4567 parseAbsoluteExpression(R1Size) || parseComma() ||
4568 parseRegisterOrRegisterNumber(
R2, DirectiveLoc) || parseComma() ||
4569 parseAbsoluteExpression(R2Size) || parseEOL())
4572 getStreamer().emitCFILLVMRegisterPair(
Register, R1, R1Size,
R2, R2Size,
4579bool AsmParser::parseDirectiveCFILLVMVectorRegisters(SMLoc DirectiveLoc) {
4581 std::vector<MCCFIInstruction::VectorRegisterWithLane> VRs;
4583 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma())
4587 int64_t VectorRegister = 0;
4590 if (parseRegisterOrRegisterNumber(VectorRegister, DirectiveLoc) ||
4591 parseComma() || parseIntToken(Lane,
"expected a lane number") ||
4592 parseComma() || parseAbsoluteExpression(
Size))
4594 VRs.push_back({unsigned(VectorRegister), unsigned(Lane), unsigned(
Size)});
4600 getStreamer().emitCFILLVMVectorRegisters(
Register, std::move(VRs),
4607bool AsmParser::parseDirectiveCFILLVMVectorOffset(SMLoc DirectiveLoc) {
4608 int64_t
Register = 0, MaskRegister = 0;
4609 int64_t RegisterSize = 0, MaskRegisterSize = 0;
4612 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4613 parseAbsoluteExpression(RegisterSize) || parseComma() ||
4614 parseRegisterOrRegisterNumber(MaskRegister, DirectiveLoc) ||
4615 parseComma() || parseAbsoluteExpression(MaskRegisterSize) ||
4616 parseComma() || parseAbsoluteExpression(
Offset) || parseEOL())
4619 getStreamer().emitCFILLVMVectorOffset(
Register, RegisterSize, MaskRegister,
4620 MaskRegisterSize,
Offset, DirectiveLoc);
4627bool AsmParser::parseDirectiveCFILLVMVectorRegisterMask(SMLoc DirectiveLoc) {
4628 int64_t
Register = 0, SpillReg = 0, MaskReg = 0;
4629 int64_t SpillRegLaneSize = 0, MaskRegSize = 0;
4631 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4632 parseRegisterOrRegisterNumber(SpillReg, DirectiveLoc) || parseComma() ||
4633 parseAbsoluteExpression(SpillRegLaneSize) || parseComma() ||
4634 parseRegisterOrRegisterNumber(MaskReg, DirectiveLoc) || parseComma() ||
4635 parseAbsoluteExpression(MaskRegSize) || parseEOL())
4638 getStreamer().emitCFILLVMVectorRegisterMask(
4639 Register, SpillReg, SpillRegLaneSize, MaskReg, MaskRegSize, DirectiveLoc);
4645bool AsmParser::parseDirectiveCFILabel(SMLoc Loc) {
4648 if (parseIdentifier(Name))
4649 return TokError(
"expected identifier");
4652 getStreamer().emitCFILabelDirective(Loc, Name);
4658bool AsmParser::parseDirectiveCFIValOffset(SMLoc DirectiveLoc) {
4662 if (parseRegisterOrRegisterNumber(
Register, DirectiveLoc) || parseComma() ||
4663 parseAbsoluteExpression(
Offset) || parseEOL())
4673bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
4676 AltMacroMode = (Directive ==
".altmacro");
4683bool AsmParser::parseDirectiveMacrosOnOff(StringRef Directive) {
4686 setMacrosEnabled(Directive ==
".macros_on");
4692bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
4694 if (parseIdentifier(Name))
4695 return TokError(
"expected identifier in '.macro' directive");
4704 return Error(Lexer.
getLoc(),
"vararg parameter '" +
4706 "' should be the last parameter");
4710 return TokError(
"expected identifier in '.macro' directive");
4713 for (
const MCAsmMacroParameter& CurrParam : Parameters)
4715 return TokError(
"macro '" + Name +
"' has multiple parameters"
4724 QualLoc = Lexer.
getLoc();
4725 if (parseIdentifier(Qualifier))
4726 return Error(QualLoc,
"missing parameter qualifier for "
4727 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4729 if (Qualifier ==
"req")
4731 else if (Qualifier ==
"vararg")
4734 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
4735 "for '" +
Parameter.Name +
"' in macro '" + Name +
"'");
4743 ParamLoc = Lexer.
getLoc();
4744 if (parseMacroArgument(
Parameter.Value,
false ))
4748 Warning(ParamLoc,
"pointless default value for required parameter "
4749 "'" +
Parameter.Name +
"' in macro '" + Name +
"'");
4762 AsmToken EndToken, StartToken = getTok();
4763 unsigned MacroDepth = 0;
4773 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4778 if (getTok().getIdentifier() ==
".endm" ||
4779 getTok().getIdentifier() ==
".endmacro") {
4780 if (MacroDepth == 0) {
4781 EndToken = getTok();
4784 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4791 }
else if (getTok().getIdentifier() ==
".macro") {
4797 (void)parseCppHashLineFilenameComment(getLexer().getLoc());
4801 eatToEndOfStatement();
4805 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4810 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
4811 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4812 MCAsmMacro
Macro(Name, Body, std::move(Parameters));
4833void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
4839 if (NParameters == 0)
4842 bool NamedParametersFound =
false;
4843 bool PositionalParametersFound =
false;
4848 while (!Body.
empty()) {
4850 std::size_t End = Body.
size(), Pos = 0;
4851 for (; Pos != End; ++Pos) {
4854 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4858 if (Body[Pos] !=
'$' || Pos + 1 == End)
4860 char Next = Body[Pos + 1];
4862 isdigit(
static_cast<unsigned char>(
Next)))
4870 if (Body[Pos] ==
'$') {
4871 switch (Body[Pos + 1]) {
4878 PositionalParametersFound =
true;
4883 PositionalParametersFound =
true;
4889 unsigned I = Pos + 1;
4893 const char *Begin = Body.
data() + Pos + 1;
4894 StringRef
Argument(Begin,
I - (Pos + 1));
4897 if (Parameters[Index].Name == Argument)
4900 if (Index == NParameters) {
4901 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4907 NamedParametersFound =
true;
4915 if (!NamedParametersFound && PositionalParametersFound)
4916 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4917 "used in macro body, possible positional parameter "
4918 "found in body which will have no effect");
4923bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
4927 if (!isInsideMacroInstantiation())
4928 return TokError(
"unexpected '" + Directive +
"' in file, "
4929 "no current macro definition");
4932 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4933 TheCondState = TheCondStack.back();
4934 TheCondStack.pop_back();
4944bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
4946 return TokError(
"unexpected token in '" + Directive +
"' directive");
4950 if (isInsideMacroInstantiation()) {
4957 return TokError(
"unexpected '" + Directive +
"' in file, "
4958 "no current macro definition");
4963bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
4966 if (parseTokenLoc(Loc) ||
4967 check(parseIdentifier(Name), Loc,
4968 "expected identifier in '.purgem' directive") ||
4973 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4977 <<
"Un-defining macro: " << Name <<
"\n");
4983bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
4984 SMLoc NumBytesLoc = Lexer.
getLoc();
4985 const MCExpr *NumBytes;
4986 if (checkForValidSection() || parseExpression(NumBytes))
4989 int64_t FillExpr = 0;
4991 if (parseAbsoluteExpression(FillExpr))
4997 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
5004bool AsmParser::parseDirectiveDCB(StringRef IDVal,
unsigned Size) {
5005 SMLoc NumValuesLoc = Lexer.
getLoc();
5007 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5010 if (NumValues < 0) {
5011 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5018 const MCExpr *
Value;
5019 SMLoc ExprLoc = getLexer().getLoc();
5020 if (parseExpression(
Value))
5026 uint64_t IntValue = MCE->getValue();
5028 return Error(ExprLoc,
"literal value out of range for directive");
5029 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
5030 getStreamer().emitIntValue(IntValue,
Size);
5032 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
5033 getStreamer().emitValue(
Value,
Size, ExprLoc);
5041bool AsmParser::parseDirectiveRealDCB(StringRef IDVal,
const fltSemantics &Semantics) {
5042 SMLoc NumValuesLoc = Lexer.
getLoc();
5044 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
5047 if (NumValues < 0) {
5048 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5056 if (parseRealValue(Semantics, AsInt) || parseEOL())
5059 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
5068bool AsmParser::parseDirectiveDS(StringRef IDVal,
unsigned Size) {
5069 SMLoc NumValuesLoc = Lexer.
getLoc();
5071 if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
5075 if (NumValues < 0) {
5076 Warning(NumValuesLoc,
"'" + Twine(IDVal) +
"' directive with negative repeat count has no effect");
5080 for (uint64_t i = 0, e = NumValues; i !=
e; ++i)
5081 getStreamer().emitFill(
Size, 0);
5088bool AsmParser::parseDirectiveLEB128(
bool Signed) {
5089 if (checkForValidSection())
5092 auto parseOp = [&]() ->
bool {
5093 const MCExpr *
Value;
5094 if (parseExpression(
Value))
5097 getStreamer().emitSLEB128Value(
Value);
5099 getStreamer().emitULEB128Value(
Value);
5103 return parseMany(parseOp);
5108bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
5109 auto parseOp = [&]() ->
bool {
5111 SMLoc Loc = getTok().getLoc();
5112 if (parseIdentifier(Name))
5113 return Error(Loc,
"expected identifier");
5115 if (discardLTOSymbol(Name))
5123 return Error(Loc,
"non-local symbol required");
5125 if (!getStreamer().emitSymbolAttribute(Sym, Attr))
5126 return Error(Loc,
"unable to emit symbol attribute");
5130 return parseMany(parseOp);
5135bool AsmParser::parseDirectiveComm(
bool IsLocal) {
5136 if (checkForValidSection())
5139 SMLoc IDLoc = getLexer().getLoc();
5142 return TokError(
"expected identifier in directive");
5148 SMLoc SizeLoc = getLexer().getLoc();
5149 if (parseAbsoluteExpression(
Size))
5152 int64_t Pow2Alignment = 0;
5153 SMLoc Pow2AlignmentLoc;
5156 Pow2AlignmentLoc = getLexer().getLoc();
5157 if (parseAbsoluteExpression(Pow2Alignment))
5162 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
5168 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
5169 Pow2Alignment =
Log2_64(Pow2Alignment);
5179 return Error(SizeLoc,
"size must be non-negative");
5183 return Error(IDLoc,
"invalid symbol redefinition");
5187 getStreamer().emitLocalCommonSymbol(Sym,
Size,
5188 Align(1ULL << Pow2Alignment));
5192 getStreamer().emitCommonSymbol(Sym,
Size,
Align(1ULL << Pow2Alignment));
5198bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
5199 StringRef Str = parseStringToEndOfStatement();
5204 return Error(DirectiveLoc,
".abort detected. Assembly stopping");
5207 return Error(DirectiveLoc,
5208 ".abort '" + Str +
"' detected. Assembly stopping");
5213bool AsmParser::parseDirectiveInclude() {
5216 SMLoc IncludeLoc = getTok().getLoc();
5219 "expected string in '.include' directive") ||
5222 "unexpected token in '.include' directive") ||
5225 check(enterIncludeFile(
Filename), IncludeLoc,
5226 "Could not find include file '" +
Filename +
"'"))
5234bool AsmParser::parseDirectiveIncbin() {
5237 SMLoc IncbinLoc = getTok().getLoc();
5239 "expected string in '.incbin' directive") ||
5244 const MCExpr *
Count =
nullptr;
5245 SMLoc SkipLoc, CountLoc;
5250 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
5254 CountLoc = getTok().getLoc();
5255 if (parseExpression(
Count))
5263 if (check(Skip < 0, SkipLoc,
"skip is negative"))
5268 return Error(IncbinLoc,
"Could not find incbin file '" +
Filename +
"'");
5274bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {
5275 TheCondStack.push_back(TheCondState);
5277 if (TheCondState.
Ignore) {
5278 eatToEndOfStatement();
5281 if (parseAbsoluteExpression(ExprValue) || parseEOL())
5291 ExprValue = ExprValue == 0;
5294 ExprValue = ExprValue >= 0;
5297 ExprValue = ExprValue > 0;
5300 ExprValue = ExprValue <= 0;
5303 ExprValue = ExprValue < 0;
5307 TheCondState.
CondMet = ExprValue;
5316bool AsmParser::parseDirectiveIfb(SMLoc DirectiveLoc,
bool ExpectBlank) {
5317 TheCondStack.push_back(TheCondState);
5320 if (TheCondState.
Ignore) {
5321 eatToEndOfStatement();
5323 StringRef Str = parseStringToEndOfStatement();
5328 TheCondState.
CondMet = ExpectBlank == Str.empty();
5338bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc,
bool ExpectEqual) {
5339 TheCondStack.push_back(TheCondState);
5342 if (TheCondState.
Ignore) {
5343 eatToEndOfStatement();
5345 StringRef Str1 = parseStringToComma();
5350 StringRef Str2 = parseStringToEndOfStatement();
5364bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc,
bool ExpectEqual) {
5365 TheCondStack.push_back(TheCondState);
5368 if (TheCondState.
Ignore) {
5369 eatToEndOfStatement();
5373 return TokError(
"expected string parameter for '.ifeqs' directive");
5374 return TokError(
"expected string parameter for '.ifnes' directive");
5377 StringRef String1 = getTok().getStringContents();
5383 "expected comma after first string for '.ifeqs' directive");
5385 "expected comma after first string for '.ifnes' directive");
5392 return TokError(
"expected string parameter for '.ifeqs' directive");
5393 return TokError(
"expected string parameter for '.ifnes' directive");
5396 StringRef String2 = getTok().getStringContents();
5399 TheCondState.
CondMet = ExpectEqual == (String1 == String2);
5408bool AsmParser::parseDirectiveIfdef(SMLoc DirectiveLoc,
bool expect_defined) {
5410 TheCondStack.push_back(TheCondState);
5413 if (TheCondState.
Ignore) {
5414 eatToEndOfStatement();
5416 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
5434bool AsmParser::parseDirectiveElseIf(SMLoc DirectiveLoc) {
5437 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
5438 " .if or an .elseif");
5441 bool LastIgnoreState =
false;
5442 if (!TheCondStack.empty())
5443 LastIgnoreState = TheCondStack.back().Ignore;
5444 if (LastIgnoreState || TheCondState.
CondMet) {
5445 TheCondState.
Ignore =
true;
5446 eatToEndOfStatement();
5449 if (parseAbsoluteExpression(ExprValue))
5455 TheCondState.
CondMet = ExprValue;
5464bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
5470 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
5471 " an .if or an .elseif");
5473 bool LastIgnoreState =
false;
5474 if (!TheCondStack.empty())
5475 LastIgnoreState = TheCondStack.back().Ignore;
5476 if (LastIgnoreState || TheCondState.
CondMet)
5477 TheCondState.
Ignore =
true;
5479 TheCondState.
Ignore =
false;
5486bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5499bool AsmParser::parseDirectiveError(SMLoc L,
bool WithMessage) {
5500 if (!TheCondStack.empty()) {
5501 if (TheCondStack.back().Ignore) {
5502 eatToEndOfStatement();
5508 return Error(L,
".err encountered");
5510 StringRef Message =
".error directive invoked in source file";
5513 return TokError(
".error argument must be a string");
5515 Message = getTok().getStringContents();
5519 return Error(L, Message);
5524bool AsmParser::parseDirectiveWarning(SMLoc L) {
5525 if (!TheCondStack.empty()) {
5526 if (TheCondStack.back().Ignore) {
5527 eatToEndOfStatement();
5532 StringRef Message =
".warning directive invoked in source file";
5536 return TokError(
".warning argument must be a string");
5538 Message = getTok().getStringContents();
5549bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
5554 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
5556 if (!TheCondStack.empty()) {
5557 TheCondState = TheCondStack.back();
5558 TheCondStack.pop_back();
5564void AsmParser::initializeDirectiveKindMap() {
5571 DirectiveKindMap[
".set"] = DK_SET;
5572 DirectiveKindMap[
".equ"] = DK_EQU;
5573 DirectiveKindMap[
".equiv"] = DK_EQUIV;
5574 DirectiveKindMap[
".ascii"] = DK_ASCII;
5575 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
5576 DirectiveKindMap[
".string"] = DK_STRING;
5577 DirectiveKindMap[
".byte"] = DK_BYTE;
5578 DirectiveKindMap[
".base64"] = DK_BASE64;
5579 DirectiveKindMap[
".short"] = DK_SHORT;
5580 DirectiveKindMap[
".value"] = DK_VALUE;
5581 DirectiveKindMap[
".2byte"] = DK_2BYTE;
5582 DirectiveKindMap[
".long"] = DK_LONG;
5583 DirectiveKindMap[
".int"] = DK_INT;
5584 DirectiveKindMap[
".4byte"] = DK_4BYTE;
5585 DirectiveKindMap[
".quad"] = DK_QUAD;
5586 DirectiveKindMap[
".8byte"] = DK_8BYTE;
5587 DirectiveKindMap[
".octa"] = DK_OCTA;
5588 DirectiveKindMap[
".single"] = DK_SINGLE;
5589 DirectiveKindMap[
".float"] = DK_FLOAT;
5590 DirectiveKindMap[
".double"] = DK_DOUBLE;
5591 DirectiveKindMap[
".align"] = DK_ALIGN;
5592 DirectiveKindMap[
".align32"] = DK_ALIGN32;
5593 DirectiveKindMap[
".balign"] = DK_BALIGN;
5594 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
5595 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
5596 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
5597 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
5598 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
5599 DirectiveKindMap[
".prefalign"] = DK_PREFALIGN;
5600 DirectiveKindMap[
".org"] = DK_ORG;
5601 DirectiveKindMap[
".fill"] = DK_FILL;
5602 DirectiveKindMap[
".zero"] = DK_ZERO;
5603 DirectiveKindMap[
".extern"] = DK_EXTERN;
5604 DirectiveKindMap[
".globl"] = DK_GLOBL;
5605 DirectiveKindMap[
".global"] = DK_GLOBAL;
5606 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
5607 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
5608 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
5609 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
5610 DirectiveKindMap[
".reference"] = DK_REFERENCE;
5611 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
5612 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
5613 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
5614 DirectiveKindMap[
".cold"] = DK_COLD;
5615 DirectiveKindMap[
".comm"] = DK_COMM;
5616 DirectiveKindMap[
".common"] = DK_COMMON;
5617 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
5618 DirectiveKindMap[
".abort"] = DK_ABORT;
5619 DirectiveKindMap[
".include"] = DK_INCLUDE;
5620 DirectiveKindMap[
".incbin"] = DK_INCBIN;
5621 DirectiveKindMap[
".code16"] = DK_CODE16;
5622 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
5623 DirectiveKindMap[
".rept"] = DK_REPT;
5624 DirectiveKindMap[
".rep"] = DK_REPT;
5625 DirectiveKindMap[
".irp"] = DK_IRP;
5626 DirectiveKindMap[
".irpc"] = DK_IRPC;
5627 DirectiveKindMap[
".endr"] = DK_ENDR;
5628 DirectiveKindMap[
".if"] = DK_IF;
5629 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
5630 DirectiveKindMap[
".ifge"] = DK_IFGE;
5631 DirectiveKindMap[
".ifgt"] = DK_IFGT;
5632 DirectiveKindMap[
".ifle"] = DK_IFLE;
5633 DirectiveKindMap[
".iflt"] = DK_IFLT;
5634 DirectiveKindMap[
".ifne"] = DK_IFNE;
5635 DirectiveKindMap[
".ifb"] = DK_IFB;
5636 DirectiveKindMap[
".ifnb"] = DK_IFNB;
5637 DirectiveKindMap[
".ifc"] = DK_IFC;
5638 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
5639 DirectiveKindMap[
".ifnc"] = DK_IFNC;
5640 DirectiveKindMap[
".ifnes"] = DK_IFNES;
5641 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
5642 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
5643 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
5644 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
5645 DirectiveKindMap[
".else"] = DK_ELSE;
5646 DirectiveKindMap[
".end"] = DK_END;
5647 DirectiveKindMap[
".endif"] = DK_ENDIF;
5648 DirectiveKindMap[
".skip"] = DK_SKIP;
5649 DirectiveKindMap[
".space"] = DK_SPACE;
5650 DirectiveKindMap[
".file"] = DK_FILE;
5651 DirectiveKindMap[
".line"] = DK_LINE;
5652 DirectiveKindMap[
".loc"] = DK_LOC;
5653 DirectiveKindMap[
".loc_label"] = DK_LOC_LABEL;
5654 DirectiveKindMap[
".stabs"] = DK_STABS;
5655 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
5656 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
5657 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5658 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5659 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5660 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5661 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5662 DirectiveKindMap[
".cv_string"] = DK_CV_STRING;
5663 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5664 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5665 DirectiveKindMap[
".cv_filechecksumoffset"] = DK_CV_FILECHECKSUM_OFFSET;
5666 DirectiveKindMap[
".cv_fpo_data"] = DK_CV_FPO_DATA;
5667 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5668 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5669 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5670 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5671 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5672 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5673 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5674 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5675 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5676 DirectiveKindMap[
".cfi_llvm_def_aspace_cfa"] = DK_CFI_LLVM_DEF_ASPACE_CFA;
5677 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5678 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5679 DirectiveKindMap[
".cfi_llvm_register_pair"] = DK_CFI_LLVM_REGISTER_PAIR;
5680 DirectiveKindMap[
".cfi_llvm_vector_registers"] = DK_CFI_LLVM_VECTOR_REGISTERS;
5681 DirectiveKindMap[
".cfi_llvm_vector_offset"] = DK_CFI_LLVM_VECTOR_OFFSET;
5682 DirectiveKindMap[
".cfi_llvm_vector_register_mask"] =
5683 DK_CFI_LLVM_VECTOR_REGISTER_MASK;
5684 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5685 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5686 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5687 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5688 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5689 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5690 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5691 DirectiveKindMap[
".cfi_return_column"] = DK_CFI_RETURN_COLUMN;
5692 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5693 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5694 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5695 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5696 DirectiveKindMap[
".cfi_label"] = DK_CFI_LABEL;
5697 DirectiveKindMap[
".cfi_b_key_frame"] = DK_CFI_B_KEY_FRAME;
5698 DirectiveKindMap[
".cfi_mte_tagged_frame"] = DK_CFI_MTE_TAGGED_FRAME;
5699 DirectiveKindMap[
".cfi_val_offset"] = DK_CFI_VAL_OFFSET;
5700 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5701 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5702 DirectiveKindMap[
".macro"] = DK_MACRO;
5703 DirectiveKindMap[
".exitm"] = DK_EXITM;
5704 DirectiveKindMap[
".endm"] = DK_ENDM;
5705 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5706 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5707 DirectiveKindMap[
".err"] = DK_ERR;
5708 DirectiveKindMap[
".error"] = DK_ERROR;
5709 DirectiveKindMap[
".warning"] = DK_WARNING;
5710 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5711 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5712 DirectiveKindMap[
".reloc"] = DK_RELOC;
5713 DirectiveKindMap[
".dc"] = DK_DC;
5714 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5715 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5716 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5717 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5718 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5719 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5720 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5721 DirectiveKindMap[
".dcb"] = DK_DCB;
5722 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5723 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5724 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5725 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5726 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5727 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5728 DirectiveKindMap[
".ds"] = DK_DS;
5729 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5730 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5731 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5732 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5733 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5734 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5735 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5736 DirectiveKindMap[
".print"] = DK_PRINT;
5737 DirectiveKindMap[
".addrsig"] = DK_ADDRSIG;
5738 DirectiveKindMap[
".addrsig_sym"] = DK_ADDRSIG_SYM;
5739 DirectiveKindMap[
".pseudoprobe"] = DK_PSEUDO_PROBE;
5740 DirectiveKindMap[
".lto_discard"] = DK_LTO_DISCARD;
5741 DirectiveKindMap[
".lto_set_conditional"] = DK_LTO_SET_CONDITIONAL;
5742 DirectiveKindMap[
".memtag"] = DK_MEMTAG;
5745MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {
5746 AsmToken EndToken, StartToken = getTok();
5748 unsigned NestLevel = 0;
5752 printError(DirectiveLoc,
"no matching '.endr' in definition");
5757 StringRef Ident = getTok().getIdentifier();
5758 if (Ident ==
".rep" || Ident ==
".rept" || Ident ==
".irp" ||
5761 }
else if (Ident ==
".endr") {
5762 if (NestLevel == 0) {
5763 EndToken = getTok();
5767 printError(getTok().getLoc(),
"expected newline");
5775 eatToEndOfStatement();
5780 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
5784 return &MacroLikeBodies.back();
5787void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
5788 raw_svector_ostream &OS) {
5791 std::unique_ptr<MemoryBuffer> Instantiation =
5796 MacroInstantiation *
MI =
new MacroInstantiation{
5797 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size()};
5798 ActiveMacros.push_back(
MI);
5808bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5809 const MCExpr *CountExpr;
5810 SMLoc CountLoc = getTok().getLoc();
5811 if (parseExpression(CountExpr))
5815 if (!CountExpr->evaluateAsAbsolute(
Count, getStreamer().getAssemblerPtr())) {
5816 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5819 if (check(
Count < 0, CountLoc,
"Count is negative") || parseEOL())
5823 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5829 SmallString<256> Buf;
5830 raw_svector_ostream OS(Buf);
5833 if (expandMacro(OS, *M, {}, {},
false))
5836 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5843bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5845 MCAsmMacroArguments
A;
5846 if (check(parseIdentifier(
Parameter.Name),
5847 "expected identifier in '.irp' directive") ||
5848 parseComma() || parseMacroArguments(
nullptr,
A) || parseEOL())
5852 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5858 SmallString<256> Buf;
5859 raw_svector_ostream OS(Buf);
5861 for (
const MCAsmMacroArgument &Arg :
A) {
5864 if (expandMacro(OS, *M, Parameter, Arg,
true))
5868 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5875bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5877 MCAsmMacroArguments
A;
5879 if (check(parseIdentifier(
Parameter.Name),
5880 "expected identifier in '.irpc' directive") ||
5881 parseComma() || parseMacroArguments(
nullptr,
A))
5884 if (
A.size() != 1 ||
A.front().size() != 1)
5885 return TokError(
"unexpected token in '.irpc' directive");
5890 MCAsmMacro *
M = parseMacroLikeBody(DirectiveLoc);
5896 SmallString<256> Buf;
5897 raw_svector_ostream OS(Buf);
5900 :
A[0][0].getString();
5901 for (std::size_t
I = 0, End = Values.
size();
I != End; ++
I) {
5902 MCAsmMacroArgument Arg;
5907 if (expandMacro(OS, *M, Parameter, Arg,
true))
5911 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5916bool AsmParser::parseDirectiveEndr(SMLoc DirectiveLoc) {
5917 if (ActiveMacros.empty())
5918 return TokError(
"unmatched '.endr' directive");
5928bool AsmParser::parseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info,
5930 const MCExpr *
Value;
5931 SMLoc ExprLoc = getLexer().getLoc();
5932 if (parseExpression(
Value))
5936 return Error(ExprLoc,
"unexpected expression in _emit");
5937 uint64_t IntValue = MCE->
getValue();
5939 return Error(ExprLoc,
"literal value out of range for directive");
5945bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
5946 const MCExpr *
Value;
5947 SMLoc ExprLoc = getLexer().getLoc();
5948 if (parseExpression(
Value))
5952 return Error(ExprLoc,
"unexpected expression in align");
5953 uint64_t IntValue = MCE->
getValue();
5955 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5961bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
5962 const AsmToken StrTok = getTok();
5965 return Error(DirectiveLoc,
"expected double quoted string after .print");
5972bool AsmParser::parseDirectiveAddrsig() {
5975 getStreamer().emitAddrsig();
5979bool AsmParser::parseDirectiveAddrsigSym() {
5981 if (check(
parseSymbol(Sym),
"expected identifier") || parseEOL())
5983 getStreamer().emitAddrsigSym(Sym);
5987bool AsmParser::parseDirectivePseudoProbe() {
5993 if (parseIntToken(
Guid))
5995 if (parseIntToken(Index))
5997 if (parseIntToken(
Type))
5999 if (parseIntToken(Attr))
6011 int64_t CallerGuid = 0;
6013 CallerGuid = getTok().getIntVal();
6021 int64_t CallerProbeId = 0;
6023 CallerProbeId = getTok().getIntVal();
6033 if (parseIdentifier(FnName))
6034 return Error(getLexer().getLoc(),
"expected identifier");
6040 getStreamer().emitPseudoProbe(
Guid, Index,
Type, Attr, Discriminator,
6041 InlineStack, FnSym);
6050bool AsmParser::parseDirectiveLTODiscard() {
6051 auto ParseOp = [&]() ->
bool {
6053 SMLoc Loc = getTok().getLoc();
6054 if (parseIdentifier(Name))
6055 return Error(Loc,
"expected identifier");
6056 LTODiscardSymbols.
insert(Name);
6060 LTODiscardSymbols.
clear();
6061 return parseMany(ParseOp);
6087bool AsmParser::parseMSInlineAsm(
6088 std::string &AsmString,
unsigned &NumOutputs,
unsigned &NumInputs,
6089 SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
6090 SmallVectorImpl<std::string> &Constraints,
6091 SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII,
6092 MCInstPrinter *IP, MCAsmParserSemaCallback &SI) {
6093 SmallVector<void *, 4> InputDecls;
6094 SmallVector<void *, 4> OutputDecls;
6097 SmallVector<std::string, 4> InputConstraints;
6098 SmallVector<std::string, 4> OutputConstraints;
6107 unsigned InputIdx = 0;
6108 unsigned OutputIdx = 0;
6111 if (parseCurlyBlockScope(AsmStrRewrites))
6114 ParseStatementInfo
Info(&AsmStrRewrites);
6115 bool StatementErr = parseStatement(Info, &SI);
6117 if (StatementErr ||
Info.ParseError) {
6119 printPendingErrors();
6124 assert(!hasPendingError() &&
"unexpected error from parseStatement");
6126 if (
Info.Opcode == ~0U)
6132 for (
unsigned i = 1, e =
Info.ParsedOperands.size(); i != e; ++i) {
6133 MCParsedAsmOperand &Operand = *
Info.ParsedOperands[i];
6137 !getTargetParser().omitRegisterFromClobberLists(Operand.
getReg())) {
6138 unsigned NumDefs =
Desc.getNumDefs();
6147 if (SymName.
empty())
6155 if (Operand.
isImm()) {
6163 bool isOutput = (i == 1) &&
Desc.mayStore();
6170 OutputConstraints.
push_back((
"=" + Constraint).str());
6177 if (
Desc.operands()[i - 1].isBranchTarget())
6191 NumOutputs = OutputDecls.
size();
6192 NumInputs = InputDecls.
size();
6197 Clobbers.
assign(ClobberRegs.
size(), std::string());
6198 for (
unsigned I = 0,
E = ClobberRegs.
size();
I !=
E; ++
I) {
6199 raw_string_ostream OS(Clobbers[
I]);
6204 if (NumOutputs || NumInputs) {
6205 unsigned NumExprs = NumOutputs + NumInputs;
6206 OpDecls.resize(NumExprs);
6207 Constraints.
resize(NumExprs);
6208 for (
unsigned i = 0; i < NumOutputs; ++i) {
6209 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
6210 Constraints[i] = OutputConstraints[i];
6212 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++
j) {
6213 OpDecls[
j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
6214 Constraints[
j] = InputConstraints[i];
6219 std::string AsmStringIR;
6220 raw_string_ostream OS(AsmStringIR);
6221 StringRef ASMString =
6223 const char *AsmStart = ASMString.
begin();
6224 const char *AsmEnd = ASMString.
end();
6226 for (
auto I = AsmStrRewrites.
begin(),
E = AsmStrRewrites.
end();
I !=
E; ++
I) {
6227 const AsmRewrite &AR = *
I;
6234 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
6237 if (
unsigned Len = Loc - AsmStart)
6238 OS << StringRef(AsmStart, Len);
6242 AsmStart = Loc + AR.
Len;
6246 unsigned AdditionalSkip = 0;
6268 size_t OffsetLen = OffsetName.
size();
6269 auto rewrite_it = std::find_if(
6270 I, AsmStrRewrites.
end(), [&](
const AsmRewrite &FusingAR) {
6271 return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
6272 (FusingAR.Kind == AOK_Input ||
6273 FusingAR.Kind == AOK_CallInput);
6275 if (rewrite_it == AsmStrRewrites.
end()) {
6276 OS <<
"offset " << OffsetName;
6278 OS <<
"${" << InputIdx++ <<
":P}";
6279 rewrite_it->Done =
true;
6281 OS <<
'$' << InputIdx++;
6282 rewrite_it->Done =
true;
6295 OS <<
"${" << InputIdx++ <<
":P}";
6297 OS <<
'$' << InputIdx++;
6300 OS <<
"${" << InputIdx++ <<
":P}";
6304 OS <<
"${" << OutputIdx++ <<
":P}";
6306 OS <<
'$' << OutputIdx++;
6311 case 8: OS <<
"byte ptr ";
break;
6312 case 16: OS <<
"word ptr ";
break;
6313 case 32: OS <<
"dword ptr ";
break;
6314 case 64: OS <<
"qword ptr ";
break;
6315 case 80: OS <<
"xword ptr ";
break;
6316 case 128: OS <<
"xmmword ptr ";
break;
6317 case 256: OS <<
"ymmword ptr ";
break;
6327 if (
getContext().getAsmInfo().getAlignmentIsInBytes())
6332 unsigned Val = AR.
Val;
6334 assert(Val < 10 &&
"Expected alignment less then 2^10.");
6335 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
6347 AsmStart = Loc + AR.
Len + AdditionalSkip;
6351 if (AsmStart != AsmEnd)
6352 OS << StringRef(AsmStart, AsmEnd - AsmStart);
6354 AsmString = std::move(AsmStringIR);
6358bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
6359 MCAsmParserSemaCallback *SI) {
6360 AsmToken LabelTok = getTok();
6361 SMLoc LabelLoc = LabelTok.
getLoc();
6364 if (parseIdentifier(LabelVal))
6365 return Error(LabelLoc,
"The HLASM Label has to be an Identifier");
6370 if (!getTargetParser().isLabel(LabelTok) || checkForValidSection())
6379 return Error(LabelLoc,
6380 "Cannot have just a label for an HLASM inline asm statement");
6390 if (enabledGenDwarfForAssembly())
6397bool HLASMAsmParser::parseAsMachineInstruction(ParseStatementInfo &Info,
6398 MCAsmParserSemaCallback *SI) {
6399 AsmToken OperationEntryTok = Lexer.
getTok();
6400 SMLoc OperationEntryLoc = OperationEntryTok.
getLoc();
6401 StringRef OperationEntryVal;
6404 if (parseIdentifier(OperationEntryVal))
6405 return Error(OperationEntryLoc,
"unexpected token at start of statement");
6411 return parseAndMatchAndEmitTargetInstruction(
6412 Info, OperationEntryVal, OperationEntryTok, OperationEntryLoc);
6415bool HLASMAsmParser::parseStatement(ParseStatementInfo &Info,
6416 MCAsmParserSemaCallback *SI) {
6417 assert(!hasPendingError() &&
"parseStatement started with pending error");
6420 bool ShouldParseAsHLASMLabel =
false;
6429 ShouldParseAsHLASMLabel =
true;
6435 if (getTok().getString().
empty() || getTok().getString().
front() ==
'\r' ||
6436 getTok().getString().
front() ==
'\n')
6451 if (getTok().getString().
front() ==
'\n' ||
6452 getTok().getString().
front() ==
'\r') {
6461 if (ShouldParseAsHLASMLabel) {
6464 if (parseAsHLASMLabel(Info, SI)) {
6467 eatToEndOfStatement();
6472 return parseAsMachineInstruction(Info, SI);
6484 return Parser.
TokError(
"missing expression");
6490 return Parser.
Error(
6491 EqualLoc,
"relocation specifier not permitted in symbol equating");
6499 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
6505 }
else if (Name ==
".") {
6520 if (
C.getTargetTriple().isSystemZ() &&
C.getTargetTriple().isOSzOS())
6521 return new HLASMAsmParser(
SM,
C, Out, MAI, CB);
6523 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.