74 cl::desc(
"The maximum nesting depth allowed for assembly macros."));
79 typedef std::vector<AsmToken> MCAsmMacroArgument;
80 typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
82 struct MCAsmMacroParameter {
84 MCAsmMacroArgument
Value;
91 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
96 MCAsmMacroParameters Parameters;
100 :
Name(N), Body(B), Parameters(std::move(P)) {}
105 struct MacroInstantiation {
107 SMLoc InstantiationLoc;
116 size_t CondStackDepth;
119 MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
size_t CondStackDepth);
122 struct ParseStatementInfo {
134 ParseStatementInfo() : Opcode(~0U), ParseError(
false), AsmRewrites(nullptr) {}
136 : Opcode(~0), ParseError(
false), AsmRewrites(rewrites) {}
141 AsmParser(
const AsmParser &) =
delete;
142 void operator=(
const AsmParser &) =
delete;
151 void *SavedDiagContext;
152 std::unique_ptr<MCAsmParserExtension> PlatformParser;
159 std::vector<AsmCond> TheCondStack;
170 std::vector<MacroInstantiation*> ActiveMacros;
173 std::deque<MCAsmMacro> MacroLikeBodies;
176 unsigned MacrosEnabledFlag : 1;
179 unsigned NumOfMacroInstantiations;
182 struct CppHashInfoTy {
184 int64_t LineNumber = 0;
188 CppHashInfoTy CppHashInfo;
197 SMLoc LastQueryIDLoc;
198 unsigned LastQueryBuffer;
199 unsigned LastQueryLine;
202 unsigned AssemblerDialect;
208 bool ParsingInlineAsm;
213 ~AsmParser()
override;
215 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
217 void addDirectiveHandler(
StringRef Directive,
218 ExtensionDirectiveHandler Handler)
override {
219 ExtensionDirectiveMap[Directive] = Handler;
223 DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
231 MCAsmLexer &getLexer()
override {
return Lexer; }
232 MCContext &getContext()
override {
return Ctx; }
233 MCStreamer &getStreamer()
override {
return Out; }
237 unsigned getAssemblerDialect()
override {
238 if (AssemblerDialect == ~0U)
239 return MAI.getAssemblerDialect();
241 return AssemblerDialect;
243 void setAssemblerDialect(
unsigned i)
override {
244 AssemblerDialect =
i;
253 void setParsingInlineAsm(
bool V)
override {
254 ParsingInlineAsm = V;
255 Lexer.setParsingMSInlineAsm(V);
257 bool isParsingInlineAsm()
override {
return ParsingInlineAsm; }
259 bool parseMSInlineAsm(
void *AsmLoc, std::string &AsmString,
260 unsigned &NumOutputs,
unsigned &NumInputs,
267 bool parseExpression(
const MCExpr *&Res);
268 bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
269 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
270 bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
271 bool parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
272 SMLoc &EndLoc)
override;
273 bool parseAbsoluteExpression(int64_t &Res)
override;
281 bool parseIdentifier(
StringRef &Res)
override;
282 void eatToEndOfStatement()
override;
284 bool checkForValidSection()
override;
289 bool parseStatement(ParseStatementInfo &Info,
292 bool parseCppHashLineFilenameComment(
SMLoc L);
302 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
305 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
319 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
325 bool handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc);
328 void handleMacroExit();
331 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
334 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
336 void printMacroInstantiations();
345 bool enterIncludeFile(
const std::string &Filename);
349 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
358 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
363 StringRef parseStringToEndOfStatement()
override;
370 bool NoDeadStrip =
false);
375 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
376 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
377 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
379 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
381 bool parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName);
382 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
387 DK_SET, DK_EQU, DK_EQUIV, DK_ASCII, DK_ASCIZ, DK_STRING, DK_BYTE, DK_SHORT,
389 DK_VALUE, DK_2BYTE, DK_LONG, DK_INT, DK_4BYTE, DK_QUAD, DK_8BYTE, DK_OCTA,
390 DK_DC, DK_DC_A, DK_DC_B, DK_DC_D, DK_DC_L, DK_DC_S, DK_DC_W, DK_DC_X,
391 DK_DCB, DK_DCB_B, DK_DCB_D, DK_DCB_L, DK_DCB_S, DK_DCB_W, DK_DCB_X,
392 DK_DS, DK_DS_B, DK_DS_D, DK_DS_L, DK_DS_P, DK_DS_S, DK_DS_W, DK_DS_X,
393 DK_SINGLE, DK_FLOAT, DK_DOUBLE, DK_ALIGN, DK_ALIGN32, DK_BALIGN, DK_BALIGNW,
394 DK_BALIGNL, DK_P2ALIGN, DK_P2ALIGNW, DK_P2ALIGNL, DK_ORG, DK_FILL, DK_ENDR,
395 DK_BUNDLE_ALIGN_MODE, DK_BUNDLE_LOCK, DK_BUNDLE_UNLOCK,
396 DK_ZERO, DK_EXTERN, DK_GLOBL, DK_GLOBAL,
397 DK_LAZY_REFERENCE, DK_NO_DEAD_STRIP, DK_SYMBOL_RESOLVER,
398 DK_PRIVATE_EXTERN, DK_REFERENCE, DK_WEAK_DEFINITION, DK_WEAK_REFERENCE,
399 DK_WEAK_DEF_CAN_BE_HIDDEN, DK_COMM, DK_COMMON, DK_LCOMM, DK_ABORT,
400 DK_INCLUDE, DK_INCBIN, DK_CODE16, DK_CODE16GCC, DK_REPT, DK_IRP, DK_IRPC,
401 DK_IF, DK_IFEQ, DK_IFGE, DK_IFGT, DK_IFLE, DK_IFLT, DK_IFNE, DK_IFB,
402 DK_IFNB, DK_IFC, DK_IFEQS, DK_IFNC, DK_IFNES, DK_IFDEF, DK_IFNDEF,
403 DK_IFNOTDEF, DK_ELSEIF, DK_ELSE, DK_ENDIF,
404 DK_SPACE, DK_SKIP, DK_FILE, DK_LINE, DK_LOC, DK_STABS,
405 DK_CV_FILE, DK_CV_FUNC_ID, DK_CV_INLINE_SITE_ID, DK_CV_LOC, DK_CV_LINETABLE,
406 DK_CV_INLINE_LINETABLE, DK_CV_DEF_RANGE, DK_CV_STRINGTABLE,
408 DK_CFI_SECTIONS, DK_CFI_STARTPROC, DK_CFI_ENDPROC, DK_CFI_DEF_CFA,
409 DK_CFI_DEF_CFA_OFFSET, DK_CFI_ADJUST_CFA_OFFSET, DK_CFI_DEF_CFA_REGISTER,
410 DK_CFI_OFFSET, DK_CFI_REL_OFFSET, DK_CFI_PERSONALITY, DK_CFI_LSDA,
411 DK_CFI_REMEMBER_STATE, DK_CFI_RESTORE_STATE, DK_CFI_SAME_VALUE,
412 DK_CFI_RESTORE, DK_CFI_ESCAPE, DK_CFI_SIGNAL_FRAME, DK_CFI_UNDEFINED,
413 DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE,
414 DK_MACROS_ON, DK_MACROS_OFF,
415 DK_MACRO, DK_EXITM, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
416 DK_SLEB128, DK_ULEB128,
417 DK_ERR, DK_ERROR, DK_WARNING,
426 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
427 bool parseDirectiveReloc(
SMLoc DirectiveLoc);
428 bool parseDirectiveValue(
StringRef IDVal,
430 bool parseDirectiveOctaValue(
StringRef IDVal);
431 bool parseDirectiveRealValue(
StringRef IDVal,
433 bool parseDirectiveFill();
434 bool parseDirectiveZero();
436 bool parseDirectiveSet(
StringRef IDVal,
bool allow_redef);
437 bool parseDirectiveOrg();
439 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
442 bool parseDirectiveFile(
SMLoc DirectiveLoc);
443 bool parseDirectiveLine();
444 bool parseDirectiveLoc();
445 bool parseDirectiveStabs();
449 bool parseDirectiveCVFile();
450 bool parseDirectiveCVFuncId();
451 bool parseDirectiveCVInlineSiteId();
452 bool parseDirectiveCVLoc();
453 bool parseDirectiveCVLinetable();
454 bool parseDirectiveCVInlineLinetable();
455 bool parseDirectiveCVDefRange();
456 bool parseDirectiveCVStringTable();
457 bool parseDirectiveCVFileChecksums();
460 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
461 bool parseDirectiveCFIWindowSave();
462 bool parseDirectiveCFISections();
463 bool parseDirectiveCFIStartProc();
464 bool parseDirectiveCFIEndProc();
465 bool parseDirectiveCFIDefCfaOffset();
466 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
467 bool parseDirectiveCFIAdjustCfaOffset();
468 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
469 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
470 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
471 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
472 bool parseDirectiveCFIRememberState();
473 bool parseDirectiveCFIRestoreState();
474 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
475 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
476 bool parseDirectiveCFIEscape();
477 bool parseDirectiveCFISignalFrame();
478 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
481 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
482 bool parseDirectiveExitMacro(
StringRef Directive);
483 bool parseDirectiveEndMacro(
StringRef Directive);
484 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
485 bool parseDirectiveMacrosOnOff(
StringRef Directive);
488 bool parseDirectiveBundleAlignMode();
490 bool parseDirectiveBundleLock();
492 bool parseDirectiveBundleUnlock();
495 bool parseDirectiveSpace(
StringRef IDVal);
498 bool parseDirectiveDCB(
StringRef IDVal,
unsigned Size);
501 bool parseDirectiveDS(
StringRef IDVal,
unsigned Size);
504 bool parseDirectiveLEB128(
bool Signed);
510 bool parseDirectiveComm(
bool IsLocal);
512 bool parseDirectiveAbort();
513 bool parseDirectiveInclude();
514 bool parseDirectiveIncbin();
517 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
519 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
521 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
523 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
525 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
526 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
527 bool parseDirectiveElse(
SMLoc DirectiveLoc);
528 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
529 bool parseEscapedString(std::string &Data)
override;
535 MCAsmMacro *parseMacroLikeBody(
SMLoc DirectiveLoc);
536 void instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
539 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
540 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
541 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
544 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &Info,
548 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &Info);
551 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
554 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
557 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
559 void initializeDirectiveKindMap();
576 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
577 PlatformParser(nullptr), CurBuffer(SM.getMainFileID()),
578 MacrosEnabledFlag(
true), CppHashInfo(), AssemblerDialect(~0U),
590 case MCObjectFileInfo::IsCOFF:
593 case MCObjectFileInfo::IsMachO:
597 case MCObjectFileInfo::IsELF:
602 PlatformParser->Initialize(*
this);
603 initializeDirectiveKindMap();
605 NumOfMacroInstantiations = 0;
608 AsmParser::~AsmParser() {
609 assert((HadError || ActiveMacros.empty()) &&
610 "Unexpected active macro instantiation!");
613 void AsmParser::printMacroInstantiations() {
615 for (std::vector<MacroInstantiation *>::const_reverse_iterator
616 it = ActiveMacros.rbegin(),
617 ie = ActiveMacros.rend();
619 printMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
620 "while in macro instantiation");
624 printPendingErrors();
625 printMessage(L, SourceMgr::DK_Note, Msg, Range);
626 printMacroInstantiations();
630 if(getTargetParser().getTargetOptions().MCNoWarn)
632 if (getTargetParser().getTargetOptions().MCFatalWarnings)
633 return Error(L, Msg, Range);
634 printMessage(L, SourceMgr::DK_Warning, Msg, Range);
635 printMacroInstantiations();
641 printMessage(L, SourceMgr::DK_Error, Msg, Range);
642 printMacroInstantiations();
646 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
647 std::string IncludedFile;
661 bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
663 std::string IncludedFile;
674 if (!Count->evaluateAsAbsolute(Res))
675 return Error(Loc,
"expected absolute expression");
677 return Warning(Loc,
"negative count has no effect");
680 getStreamer().EmitBytes(Bytes);
684 void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
692 Error(Lexer.getErrLoc(), Lexer.getErr());
695 if (getTok().is(AsmToken::EndOfStatement)) {
697 if (getTok().getString().front() !=
'\n' &&
705 while (tok->
is(AsmToken::Comment)) {
715 if (ParentIncludeLoc !=
SMLoc()) {
716 jumpToLoc(ParentIncludeLoc);
724 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
726 if (!NoInitialTextSection)
733 AsmCond StartingCondState = TheCondState;
737 if (getContext().getGenDwarfForAssembly()) {
738 MCSection *Sec = getStreamer().getCurrentSectionOnly();
740 MCSymbol *SectionStartSym = getContext().createTempSymbol();
741 getStreamer().EmitLabel(SectionStartSym);
744 bool InsertResult = getContext().addGenDwarfSection(Sec);
745 assert(InsertResult &&
".text section should not have debug info yet");
747 getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
748 0,
StringRef(), getContext().getMainFileName()));
753 ParseStatementInfo Info;
754 if (!parseStatement(Info,
nullptr))
765 printPendingErrors();
768 if (!getLexer().isAtStartOfStatement())
769 eatToEndOfStatement();
773 assert(!hasPendingError() &&
"unexpected error from parseStatement");
775 getTargetParser().flushPendingInstructions(getStreamer());
777 if (TheCondState.TheCond != StartingCondState.
TheCond ||
778 TheCondState.Ignore != StartingCondState.
Ignore)
779 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
781 const auto &LineTables = getContext().getMCDwarfLineTables();
782 if (!LineTables.empty()) {
784 for (
const auto &
File : LineTables.begin()->second.getMCDwarfFiles()) {
785 if (
File.Name.empty() && Index != 0)
786 printError(getTok().getLoc(),
"unassigned file number: " +
788 " for .file directives");
799 for (
const auto &TableEntry : getContext().getSymbols()) {
800 MCSymbol *Sym = TableEntry.getValue();
808 printError(getTok().getLoc(),
"assembler local symbol '" +
809 Sym->
getName() +
"' not defined");
815 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
816 if (std::get<2>(LocSym)->isUndefined()) {
819 CppHashInfo = std::get<1>(LocSym);
820 printError(std::get<0>(LocSym),
"directional label undefined");
827 if (!HadError && !NoFinalize)
830 return HadError || getContext().hadError();
833 bool AsmParser::checkForValidSection() {
834 if (!ParsingInlineAsm && !getStreamer().getCurrentSectionOnly()) {
836 return Error(getTok().getLoc(),
837 "expected section directive before assembly directive");
843 void AsmParser::eatToEndOfStatement() {
844 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
848 if (Lexer.is(AsmToken::EndOfStatement))
852 StringRef AsmParser::parseStringToEndOfStatement() {
853 const char *Start = getTok().getLoc().getPointer();
855 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
858 const char *
End = getTok().getLoc().getPointer();
862 StringRef AsmParser::parseStringToComma() {
863 const char *Start = getTok().getLoc().getPointer();
865 while (Lexer.isNot(AsmToken::EndOfStatement) &&
869 const char *End = getTok().getLoc().getPointer();
878 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
879 if (parseExpression(Res))
881 if (Lexer.isNot(AsmToken::RParen))
882 return TokError(
"expected ')' in parentheses expression");
883 EndLoc = Lexer.getTok().getEndLoc();
893 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
894 if (parseExpression(Res))
896 EndLoc = getTok().getEndLoc();
897 if (parseToken(AsmToken::RBrac,
"expected ']' in brackets expression"))
908 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
909 SMLoc FirstTokenLoc = getLexer().getLoc();
911 switch (FirstTokenKind) {
913 return TokError(
"unknown token in expression");
917 case AsmToken::Exclaim:
919 if (parsePrimaryExpr(Res, EndLoc))
921 Res = MCUnaryExpr::createLNot(Res, getContext());
923 case AsmToken::Dollar:
926 case AsmToken::Identifier: {
928 if (parseIdentifier(Identifier)) {
930 if (getTok().is(AsmToken::Dollar)) {
931 if (Lexer.getMAI().getDollarIsPC()) {
937 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None,
939 EndLoc = FirstTokenLoc;
942 return Error(FirstTokenLoc,
"invalid token in expression");
946 std::pair<StringRef, StringRef>
Split;
949 if (Lexer.is(AsmToken::At)) {
951 SMLoc AtLoc = getLexer().getLoc();
953 if (parseIdentifier(VName))
954 return Error(AtLoc,
"expected symbol variant after '@'");
956 Split = std::make_pair(Identifier, VName);
959 Split = Identifier.
split(
'@');
961 }
else if (Lexer.is(AsmToken::LParen)) {
964 parseIdentifier(VName);
966 if (parseToken(AsmToken::RParen,
967 "unexpected token in variant, expected ')'"))
969 Split = std::make_pair(Identifier, VName);
972 EndLoc = SMLoc::getFromPointer(Identifier.
end());
976 if (SymbolName.empty())
982 if (Split.second.size()) {
983 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
984 if (Variant != MCSymbolRefExpr::VK_Invalid) {
985 SymbolName = Split.first;
987 Variant = MCSymbolRefExpr::VK_None;
989 return Error(SMLoc::getFromPointer(Split.second.begin()),
990 "invalid variant '" + Split.second +
"'");
994 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
1001 return Error(EndLoc,
"unexpected modifier on variable reference");
1008 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
1011 case AsmToken::BigNum:
1012 return TokError(
"literal value out of range for directive");
1013 case AsmToken::Integer: {
1014 SMLoc Loc = getTok().getLoc();
1015 int64_t
IntVal = getTok().getIntVal();
1016 Res = MCConstantExpr::create(IntVal, getContext());
1017 EndLoc = Lexer.getTok().getEndLoc();
1020 if (Lexer.getKind() == AsmToken::Identifier) {
1023 std::pair<StringRef, StringRef> Split = IDVal.
split(
'@');
1025 if (Split.first.size() != IDVal.
size()) {
1026 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
1027 if (Variant == MCSymbolRefExpr::VK_Invalid)
1028 return TokError(
"invalid variant '" + Split.second +
"'");
1029 IDVal = Split.first;
1031 if (IDVal ==
"f" || IDVal ==
"b") {
1034 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
1036 return Error(Loc,
"directional label undefined");
1037 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1038 EndLoc = Lexer.getTok().getEndLoc();
1044 case AsmToken::Real: {
1045 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1046 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
1047 Res = MCConstantExpr::create(IntVal, getContext());
1048 EndLoc = Lexer.getTok().getEndLoc();
1052 case AsmToken::Dot: {
1057 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
1058 EndLoc = Lexer.getTok().getEndLoc();
1062 case AsmToken::LParen:
1064 return parseParenExpr(Res, EndLoc);
1065 case AsmToken::LBrac:
1066 if (!PlatformParser->HasBracketExpressions())
1067 return TokError(
"brackets expression not supported on this target");
1069 return parseBracketExpr(Res, EndLoc);
1070 case AsmToken::Minus:
1072 if (parsePrimaryExpr(Res, EndLoc))
1074 Res = MCUnaryExpr::createMinus(Res, getContext());
1076 case AsmToken::Plus:
1078 if (parsePrimaryExpr(Res, EndLoc))
1080 Res = MCUnaryExpr::createPlus(Res, getContext());
1082 case AsmToken::Tilde:
1084 if (parsePrimaryExpr(Res, EndLoc))
1086 Res = MCUnaryExpr::createNot(Res, getContext());
1090 case AsmToken::PercentCall16:
1091 case AsmToken::PercentCall_Hi:
1092 case AsmToken::PercentCall_Lo:
1093 case AsmToken::PercentDtprel_Hi:
1094 case AsmToken::PercentDtprel_Lo:
1095 case AsmToken::PercentGot:
1096 case AsmToken::PercentGot_Disp:
1097 case AsmToken::PercentGot_Hi:
1098 case AsmToken::PercentGot_Lo:
1099 case AsmToken::PercentGot_Ofst:
1100 case AsmToken::PercentGot_Page:
1101 case AsmToken::PercentGottprel:
1102 case AsmToken::PercentGp_Rel:
1103 case AsmToken::PercentHi:
1104 case AsmToken::PercentHigher:
1105 case AsmToken::PercentHighest:
1106 case AsmToken::PercentLo:
1107 case AsmToken::PercentNeg:
1108 case AsmToken::PercentPcrel_Hi:
1109 case AsmToken::PercentPcrel_Lo:
1110 case AsmToken::PercentTlsgd:
1111 case AsmToken::PercentTlsldm:
1112 case AsmToken::PercentTprel_Hi:
1113 case AsmToken::PercentTprel_Lo:
1115 if (Lexer.isNot(AsmToken::LParen))
1116 return TokError(
"expected '(' after operator");
1118 if (parseExpression(Res, EndLoc))
1120 if (Lexer.isNot(AsmToken::RParen))
1121 return TokError(
"expected ')'");
1123 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1128 bool AsmParser::parseExpression(
const MCExpr *&Res) {
1130 return parseExpression(Res, EndLoc);
1134 AsmParser::applyModifierToExpr(
const MCExpr *
E,
1137 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
1147 case MCExpr::SymbolRef: {
1150 if (SRE->
getKind() != MCSymbolRefExpr::VK_None) {
1151 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
1152 "' (already modified)");
1156 return MCSymbolRefExpr::create(&SRE->
getSymbol(), Variant, getContext());
1159 case MCExpr::Unary: {
1164 return MCUnaryExpr::create(UE->
getOpcode(), Sub, getContext());
1167 case MCExpr::Binary: {
1169 const MCExpr *LHS = applyModifierToExpr(BE->
getLHS(), Variant);
1170 const MCExpr *RHS = applyModifierToExpr(BE->
getRHS(), Variant);
1180 return MCBinaryExpr::create(BE->
getOpcode(), LHS, RHS, getContext());
1197 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1200 if (parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1206 if (Lexer.getKind() == AsmToken::At) {
1209 if (Lexer.isNot(AsmToken::Identifier))
1210 return TokError(
"unexpected symbol modifier following '@'");
1213 MCSymbolRefExpr::getVariantKindForName(getTok().getIdentifier());
1214 if (Variant == MCSymbolRefExpr::VK_Invalid)
1215 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1217 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1219 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1220 "' (no symbols present)");
1229 if (Res->evaluateAsAbsolute(Value))
1230 Res = MCConstantExpr::create(Value, getContext());
1235 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1237 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1240 bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1242 if (parseParenExpr(Res, EndLoc))
1245 for (; ParenDepth > 0; --ParenDepth) {
1246 if (parseBinOpRHS(1, Res, EndLoc))
1251 if (ParenDepth - 1 > 0) {
1252 EndLoc = getTok().getEndLoc();
1253 if (parseToken(AsmToken::RParen,
1254 "expected ')' in parentheses expression"))
1261 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1264 SMLoc StartLoc = Lexer.getLoc();
1265 if (parseExpression(Expr))
1268 if (!Expr->evaluateAsAbsolute(Res))
1269 return Error(StartLoc,
"expected absolute expression");
1276 bool ShouldUseLogicalShr) {
1282 case AsmToken::AmpAmp:
1283 Kind = MCBinaryExpr::LAnd;
1285 case AsmToken::PipePipe:
1286 Kind = MCBinaryExpr::LOr;
1295 case AsmToken::Caret:
1303 case AsmToken::EqualEqual:
1306 case AsmToken::ExclaimEqual:
1307 case AsmToken::LessGreater:
1313 case AsmToken::LessEqual:
1314 Kind = MCBinaryExpr::LTE;
1316 case AsmToken::Greater:
1319 case AsmToken::GreaterEqual:
1320 Kind = MCBinaryExpr::GTE;
1324 case AsmToken::LessLess:
1325 Kind = MCBinaryExpr::Shl;
1327 case AsmToken::GreaterGreater:
1328 Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
1332 case AsmToken::Plus:
1335 case AsmToken::Minus:
1336 Kind = MCBinaryExpr::Sub;
1340 case AsmToken::Star:
1341 Kind = MCBinaryExpr::Mul;
1343 case AsmToken::Slash:
1344 Kind = MCBinaryExpr::Div;
1346 case AsmToken::Percent:
1347 Kind = MCBinaryExpr::Mod;
1354 bool ShouldUseLogicalShr) {
1360 case AsmToken::AmpAmp:
1361 Kind = MCBinaryExpr::LAnd;
1363 case AsmToken::PipePipe:
1364 Kind = MCBinaryExpr::LOr;
1368 case AsmToken::EqualEqual:
1371 case AsmToken::ExclaimEqual:
1372 case AsmToken::LessGreater:
1378 case AsmToken::LessEqual:
1379 Kind = MCBinaryExpr::LTE;
1381 case AsmToken::Greater:
1384 case AsmToken::GreaterEqual:
1385 Kind = MCBinaryExpr::GTE;
1389 case AsmToken::Plus:
1392 case AsmToken::Minus:
1393 Kind = MCBinaryExpr::Sub;
1402 case AsmToken::Caret:
1410 case AsmToken::Star:
1411 Kind = MCBinaryExpr::Mul;
1413 case AsmToken::Slash:
1414 Kind = MCBinaryExpr::Div;
1416 case AsmToken::Percent:
1417 Kind = MCBinaryExpr::Mod;
1419 case AsmToken::LessLess:
1420 Kind = MCBinaryExpr::Shl;
1422 case AsmToken::GreaterGreater:
1423 Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
1437 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1441 unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(),
Kind);
1445 if (TokPrec < Precedence)
1452 if (parsePrimaryExpr(RHS, EndLoc))
1458 unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(),
Dummy);
1459 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1463 Res = MCBinaryExpr::create(Kind, Res, RHS, getContext());
1471 bool AsmParser::parseStatement(ParseStatementInfo &Info,
1473 assert(!hasPendingError() &&
"parseStatement started with pending error");
1475 while (Lexer.is(AsmToken::Space))
1477 if (Lexer.is(AsmToken::EndOfStatement)) {
1479 if (getTok().getString().front() ==
'\r' ||
1480 getTok().getString().front() ==
'\n')
1490 StringRef CommentStr = parseStringToEndOfStatement();
1492 Lexer.UnLex(
AsmToken(AsmToken::EndOfStatement, CommentStr));
1499 int64_t LocalLabelVal = -1;
1500 if (Lexer.is(AsmToken::HashDirective))
1501 return parseCppHashLineFilenameComment(IDLoc);
1503 if (Lexer.is(AsmToken::Integer)) {
1504 LocalLabelVal = getTok().getIntVal();
1505 if (LocalLabelVal < 0) {
1506 if (!TheCondState.Ignore) {
1508 return Error(IDLoc,
"unexpected token at start of statement");
1512 IDVal = getTok().getString();
1514 if (Lexer.getKind() != AsmToken::Colon) {
1515 if (!TheCondState.Ignore) {
1517 return Error(IDLoc,
"unexpected token at start of statement");
1521 }
else if (Lexer.is(AsmToken::Dot)) {
1525 }
else if (Lexer.is(AsmToken::LCurly)) {
1530 }
else if (Lexer.is(AsmToken::RCurly)) {
1534 }
else if (parseIdentifier(IDVal)) {
1535 if (!TheCondState.Ignore) {
1537 return Error(IDLoc,
"unexpected token at start of statement");
1546 DirectiveKindMap.find(IDVal);
1547 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1560 return parseDirectiveIf(IDLoc, DirKind);
1562 return parseDirectiveIfb(IDLoc,
true);
1564 return parseDirectiveIfb(IDLoc,
false);
1566 return parseDirectiveIfc(IDLoc,
true);
1568 return parseDirectiveIfeqs(IDLoc,
true);
1570 return parseDirectiveIfc(IDLoc,
false);
1572 return parseDirectiveIfeqs(IDLoc,
false);
1574 return parseDirectiveIfdef(IDLoc,
true);
1577 return parseDirectiveIfdef(IDLoc,
false);
1579 return parseDirectiveElseIf(IDLoc);
1581 return parseDirectiveElse(IDLoc);
1583 return parseDirectiveEndIf(IDLoc);
1588 if (TheCondState.Ignore) {
1589 eatToEndOfStatement();
1596 switch (Lexer.getKind()) {
1597 case AsmToken::Colon: {
1598 if (!getTargetParser().isLabel(ID))
1600 if (checkForValidSection())
1608 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1616 if (LocalLabelVal == -1) {
1617 if (ParsingInlineAsm && SI) {
1621 "We should have an internal name here.");
1622 Info.AsmRewrites->emplace_back(
AOK_Label, IDLoc, IDVal.
size(),
1624 IDVal = RewrittenLabel;
1626 Sym = getContext().getOrCreateSymbol(IDVal);
1633 return Error(IDLoc,
"invalid symbol redefinition");
1640 StringRef CommentStr = parseStringToEndOfStatement();
1642 Lexer.UnLex(
AsmToken(AsmToken::EndOfStatement, CommentStr));
1647 if (getTok().is(AsmToken::EndOfStatement)) {
1652 if (!ParsingInlineAsm)
1657 if (getContext().getGenDwarfForAssembly())
1658 MCGenDwarfLabelEntry::Make(Sym, &getStreamer(), getSourceManager(),
1661 getTargetParser().onLabelParsed(Sym);
1666 case AsmToken::Equal:
1667 if (!getTargetParser().equalIsAsmAssignment())
1672 return parseAssignment(IDVal,
true);
1679 if (areMacrosEnabled())
1680 if (
const MCAsmMacro *M = lookupMacro(IDVal)) {
1681 return handleMacroEntry(M, IDLoc);
1687 if (IDVal[0] ==
'.' && IDVal !=
".") {
1699 getTargetParser().flushPendingInstructions(getStreamer());
1701 SMLoc StartTokLoc = getTok().getLoc();
1702 bool TPDirectiveReturn = getTargetParser().ParseDirective(ID);
1704 if (hasPendingError())
1711 if (TPDirectiveReturn && StartTokLoc != getTok().getLoc())
1714 if (!TPDirectiveReturn || StartTokLoc != getTok().getLoc())
1719 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1720 ExtensionDirectiveMap.lookup(IDVal);
1722 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1731 return parseDirectiveSet(IDVal,
true);
1733 return parseDirectiveSet(IDVal,
false);
1735 return parseDirectiveAscii(IDVal,
false);
1738 return parseDirectiveAscii(IDVal,
true);
1741 return parseDirectiveValue(IDVal, 1);
1747 return parseDirectiveValue(IDVal, 2);
1752 return parseDirectiveValue(IDVal, 4);
1755 return parseDirectiveValue(IDVal, 8);
1757 return parseDirectiveValue(IDVal,
1760 return parseDirectiveOctaValue(IDVal);
1764 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1767 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1769 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1770 return parseDirectiveAlign(IsPow2, 1);
1773 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1774 return parseDirectiveAlign(IsPow2, 4);
1777 return parseDirectiveAlign(
false, 1);
1779 return parseDirectiveAlign(
false, 2);
1781 return parseDirectiveAlign(
false, 4);
1783 return parseDirectiveAlign(
true, 1);
1785 return parseDirectiveAlign(
true, 2);
1787 return parseDirectiveAlign(
true, 4);
1789 return parseDirectiveOrg();
1791 return parseDirectiveFill();
1793 return parseDirectiveZero();
1795 eatToEndOfStatement();
1799 return parseDirectiveSymbolAttribute(
MCSA_Global);
1800 case DK_LAZY_REFERENCE:
1802 case DK_NO_DEAD_STRIP:
1804 case DK_SYMBOL_RESOLVER:
1806 case DK_PRIVATE_EXTERN:
1810 case DK_WEAK_DEFINITION:
1812 case DK_WEAK_REFERENCE:
1814 case DK_WEAK_DEF_CAN_BE_HIDDEN:
1818 return parseDirectiveComm(
false);
1820 return parseDirectiveComm(
true);
1822 return parseDirectiveAbort();
1824 return parseDirectiveInclude();
1826 return parseDirectiveIncbin();
1829 return TokError(
Twine(IDVal) +
1830 " not currently supported for this target");
1832 return parseDirectiveRept(IDLoc, IDVal);
1834 return parseDirectiveIrp(IDLoc);
1836 return parseDirectiveIrpc(IDLoc);
1838 return parseDirectiveEndr(IDLoc);
1839 case DK_BUNDLE_ALIGN_MODE:
1840 return parseDirectiveBundleAlignMode();
1841 case DK_BUNDLE_LOCK:
1842 return parseDirectiveBundleLock();
1843 case DK_BUNDLE_UNLOCK:
1844 return parseDirectiveBundleUnlock();
1846 return parseDirectiveLEB128(
true);
1848 return parseDirectiveLEB128(
false);
1851 return parseDirectiveSpace(IDVal);
1853 return parseDirectiveFile(IDLoc);
1855 return parseDirectiveLine();
1857 return parseDirectiveLoc();
1859 return parseDirectiveStabs();
1861 return parseDirectiveCVFile();
1863 return parseDirectiveCVFuncId();
1864 case DK_CV_INLINE_SITE_ID:
1865 return parseDirectiveCVInlineSiteId();
1867 return parseDirectiveCVLoc();
1868 case DK_CV_LINETABLE:
1869 return parseDirectiveCVLinetable();
1870 case DK_CV_INLINE_LINETABLE:
1871 return parseDirectiveCVInlineLinetable();
1872 case DK_CV_DEF_RANGE:
1873 return parseDirectiveCVDefRange();
1874 case DK_CV_STRINGTABLE:
1875 return parseDirectiveCVStringTable();
1876 case DK_CV_FILECHECKSUMS:
1877 return parseDirectiveCVFileChecksums();
1878 case DK_CFI_SECTIONS:
1879 return parseDirectiveCFISections();
1880 case DK_CFI_STARTPROC:
1881 return parseDirectiveCFIStartProc();
1882 case DK_CFI_ENDPROC:
1883 return parseDirectiveCFIEndProc();
1884 case DK_CFI_DEF_CFA:
1885 return parseDirectiveCFIDefCfa(IDLoc);
1886 case DK_CFI_DEF_CFA_OFFSET:
1887 return parseDirectiveCFIDefCfaOffset();
1888 case DK_CFI_ADJUST_CFA_OFFSET:
1889 return parseDirectiveCFIAdjustCfaOffset();
1890 case DK_CFI_DEF_CFA_REGISTER:
1891 return parseDirectiveCFIDefCfaRegister(IDLoc);
1893 return parseDirectiveCFIOffset(IDLoc);
1894 case DK_CFI_REL_OFFSET:
1895 return parseDirectiveCFIRelOffset(IDLoc);
1896 case DK_CFI_PERSONALITY:
1897 return parseDirectiveCFIPersonalityOrLsda(
true);
1899 return parseDirectiveCFIPersonalityOrLsda(
false);
1900 case DK_CFI_REMEMBER_STATE:
1901 return parseDirectiveCFIRememberState();
1902 case DK_CFI_RESTORE_STATE:
1903 return parseDirectiveCFIRestoreState();
1904 case DK_CFI_SAME_VALUE:
1905 return parseDirectiveCFISameValue(IDLoc);
1906 case DK_CFI_RESTORE:
1907 return parseDirectiveCFIRestore(IDLoc);
1909 return parseDirectiveCFIEscape();
1910 case DK_CFI_SIGNAL_FRAME:
1911 return parseDirectiveCFISignalFrame();
1912 case DK_CFI_UNDEFINED:
1913 return parseDirectiveCFIUndefined(IDLoc);
1914 case DK_CFI_REGISTER:
1915 return parseDirectiveCFIRegister(IDLoc);
1916 case DK_CFI_WINDOW_SAVE:
1917 return parseDirectiveCFIWindowSave();
1920 return parseDirectiveMacrosOnOff(IDVal);
1922 return parseDirectiveMacro(IDLoc);
1924 return parseDirectiveExitMacro(IDVal);
1927 return parseDirectiveEndMacro(IDVal);
1929 return parseDirectivePurgeMacro(IDLoc);
1931 return parseDirectiveEnd(IDLoc);
1933 return parseDirectiveError(IDLoc,
false);
1935 return parseDirectiveError(IDLoc,
true);
1937 return parseDirectiveWarning(IDLoc);
1939 return parseDirectiveReloc(IDLoc);
1942 return parseDirectiveDCB(IDVal, 2);
1944 return parseDirectiveDCB(IDVal, 1);
1946 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
1948 return parseDirectiveDCB(IDVal, 4);
1950 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
1953 return TokError(
Twine(IDVal) +
1954 " not currently supported for this target");
1957 return parseDirectiveDS(IDVal, 2);
1959 return parseDirectiveDS(IDVal, 1);
1961 return parseDirectiveDS(IDVal, 8);
1964 return parseDirectiveDS(IDVal, 4);
1967 return parseDirectiveDS(IDVal, 12);
1970 return Error(IDLoc,
"unknown directive");
1974 if (ParsingInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
1975 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
1976 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
1979 if (ParsingInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
1980 return parseDirectiveMSAlign(IDLoc, Info);
1982 if (ParsingInlineAsm && (IDVal ==
"even"))
1983 Info.AsmRewrites->emplace_back(
AOK_EVEN, IDLoc, 4);
1984 if (checkForValidSection())
1988 std::string OpcodeStr = IDVal.
lower();
1990 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, ID,
1991 Info.ParsedOperands);
1992 Info.ParseError = ParseHadError;
1995 if (getShowParsedOperands()) {
1998 OS <<
"parsed instruction: [";
1999 for (
unsigned i = 0;
i != Info.ParsedOperands.size(); ++
i) {
2002 Info.ParsedOperands[
i]->print(OS);
2006 printMessage(IDLoc, SourceMgr::DK_Note, OS.str());
2010 if (hasPendingError() || ParseHadError)
2015 if (!ParseHadError && getContext().getGenDwarfForAssembly() &&
2016 getContext().getGenDwarfSectionSyms().count(
2017 getStreamer().getCurrentSectionOnly())) {
2019 if (ActiveMacros.empty())
2023 ActiveMacros.front()->ExitBuffer);
2028 if (CppHashInfo.Filename.size()) {
2029 unsigned FileNumber = getStreamer().EmitDwarfFileDirective(
2031 getContext().setGenDwarfFileNumber(FileNumber);
2036 unsigned CppHashLocLineNo;
2037 if (LastQueryIDLoc == CppHashInfo.Loc &&
2038 LastQueryBuffer == CppHashInfo.Buf)
2039 CppHashLocLineNo = LastQueryLine;
2043 LastQueryLine = CppHashLocLineNo;
2044 LastQueryIDLoc = CppHashInfo.Loc;
2045 LastQueryBuffer = CppHashInfo.Buf;
2047 Line = CppHashInfo.LineNumber - 1 + (Line - CppHashLocLineNo);
2050 getStreamer().EmitDwarfLocDirective(
2051 getContext().getGenDwarfFileNumber(), Line, 0,
2057 if (!ParseHadError) {
2059 if (getTargetParser().MatchAndEmitInstruction(IDLoc, Info.Opcode,
2060 Info.ParsedOperands, Out,
2061 ErrorInfo, ParsingInlineAsm))
2071 if (Lexer.isNot(AsmToken::LCurly) && Lexer.isNot(AsmToken::RCurly))
2074 SMLoc StartLoc = Lexer.getLoc();
2076 if (Lexer.is(AsmToken::EndOfStatement))
2087 bool AsmParser::parseCppHashLineFilenameComment(
SMLoc L) {
2091 assert(getTok().is(AsmToken::Integer) &&
2092 "Lexing Cpp line comment: Expected Integer");
2093 int64_t LineNumber = getTok().getIntVal();
2096 "Lexing Cpp line comment: Expected String");
2097 StringRef Filename = getTok().getString();
2101 Filename = Filename.
substr(1, Filename.
size() - 2);
2104 CppHashInfo.Loc =
L;
2105 CppHashInfo.Filename = Filename;
2106 CppHashInfo.LineNumber = LineNumber;
2107 CppHashInfo.Buf = CurBuffer;
2114 const AsmParser *Parser =
static_cast<const AsmParser *
>(
Context);
2120 unsigned CppHashBuf =
2121 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2126 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2135 if (!Parser->CppHashInfo.LineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
2136 DiagBuf != CppHashBuf) {
2137 if (Parser->SavedDiagHandler)
2138 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2140 Diag.
print(
nullptr, OS);
2147 const std::string &Filename = Parser->CppHashInfo.Filename;
2150 int CppHashLocLineNo =
2151 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2153 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2159 if (Parser->SavedDiagHandler)
2160 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
2162 NewDiag.print(
nullptr, OS);
2170 return isalnum(static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2177 bool EnableAtPseudoVariable,
SMLoc L) {
2178 unsigned NParameters = Parameters.
size();
2179 bool HasVararg = NParameters ? Parameters.
back().Vararg :
false;
2180 if ((!IsDarwin || NParameters != 0) && NParameters != A.
size())
2181 return Error(L,
"Wrong number of arguments");
2185 while (!Body.
empty()) {
2187 std::size_t End = Body.
size(), Pos = 0;
2188 for (; Pos !=
End; ++Pos) {
2190 if (IsDarwin && !NParameters) {
2192 if (Body[Pos] !=
'$' || Pos + 1 == End)
2195 char Next = Body[Pos + 1];
2196 if (Next ==
'$' || Next ==
'n' ||
2197 isdigit(static_cast<unsigned char>(Next)))
2201 if (Body[Pos] ==
'\\' && Pos + 1 != End)
2207 OS << Body.
slice(0, Pos);
2213 if (IsDarwin && !NParameters) {
2214 switch (Body[Pos + 1]) {
2228 unsigned Index = Body[Pos + 1] -
'0';
2229 if (Index >= A.
size())
2234 OS <<
Token.getString();
2240 unsigned I = Pos + 1;
2243 if (EnableAtPseudoVariable && Body[I] ==
'@' && I + 1 != End)
2249 const char *Begin = Body.
data() + Pos + 1;
2254 OS << NumOfMacroInstantiations;
2257 for (; Index < NParameters; ++Index)
2261 if (Index == NParameters) {
2262 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
2269 bool VarargParameter = HasVararg && Index == (NParameters - 1);
2274 OS <<
Token.getString();
2276 OS <<
Token.getStringContents();
2289 MacroInstantiation::MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
2290 size_t CondStackDepth)
2291 : InstantiationLoc(IL), ExitBuffer(EB), ExitLoc(EL),
2292 CondStackDepth(CondStackDepth) {}
2298 case AsmToken::Plus:
2299 case AsmToken::Minus:
2300 case AsmToken::Tilde:
2301 case AsmToken::Slash:
2302 case AsmToken::Star:
2304 case AsmToken::Equal:
2305 case AsmToken::EqualEqual:
2307 case AsmToken::PipePipe:
2308 case AsmToken::Caret:
2310 case AsmToken::AmpAmp:
2311 case AsmToken::Exclaim:
2312 case AsmToken::ExclaimEqual:
2314 case AsmToken::LessEqual:
2315 case AsmToken::LessLess:
2316 case AsmToken::LessGreater:
2317 case AsmToken::Greater:
2318 case AsmToken::GreaterEqual:
2319 case AsmToken::GreaterGreater:
2326 class AsmLexerSkipSpaceRAII {
2328 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2332 ~AsmLexerSkipSpaceRAII() {
2342 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2345 if (Lexer.isNot(AsmToken::EndOfStatement)) {
2346 StringRef Str = parseStringToEndOfStatement();
2352 unsigned ParenLevel = 0;
2355 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2362 return TokError(
"unexpected token in macro instantiation");
2364 if (ParenLevel == 0) {
2366 if (Lexer.is(AsmToken::Comma))
2369 if (Lexer.is(AsmToken::Space)) {
2379 MA.push_back(getTok());
2383 if (Lexer.is(AsmToken::Space))
2395 if (Lexer.is(AsmToken::EndOfStatement))
2399 if (Lexer.is(AsmToken::LParen))
2401 else if (Lexer.is(AsmToken::RParen) && ParenLevel)
2405 MA.push_back(getTok());
2409 if (ParenLevel != 0)
2410 return TokError(
"unbalanced parentheses in macro argument");
2415 bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2416 MCAsmMacroArguments &A) {
2417 const unsigned NParameters = M ? M->Parameters.size() : 0;
2418 bool NamedParametersFound =
false;
2422 FALocs.
resize(NParameters);
2427 bool HasVararg = NParameters ? M->Parameters.back().Vararg :
false;
2428 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2430 SMLoc IDLoc = Lexer.getLoc();
2431 MCAsmMacroParameter FA;
2433 if (Lexer.is(AsmToken::Identifier) && Lexer.peekTok().is(AsmToken::Equal)) {
2434 if (parseIdentifier(FA.Name))
2435 return Error(IDLoc,
"invalid argument identifier for formal argument");
2437 if (Lexer.isNot(AsmToken::Equal))
2438 return TokError(
"expected '=' after formal parameter identifier");
2442 NamedParametersFound =
true;
2445 if (NamedParametersFound && FA.Name.empty())
2446 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2448 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2449 if (parseMacroArgument(FA.Value, Vararg))
2452 unsigned PI = Parameter;
2453 if (!FA.Name.empty()) {
2455 for (FAI = 0; FAI < NParameters; ++FAI)
2456 if (M->Parameters[FAI].Name == FA.Name)
2459 if (FAI >= NParameters) {
2460 assert(M &&
"expected macro to be defined");
2461 return Error(IDLoc,
"parameter named '" + FA.Name +
2462 "' does not exist for macro '" + M->Name +
"'");
2467 if (!FA.Value.empty()) {
2472 if (FALocs.
size() <= PI)
2475 FALocs[PI] = Lexer.getLoc();
2481 if (Lexer.is(AsmToken::EndOfStatement)) {
2482 bool Failure =
false;
2483 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2484 if (A[FAI].empty()) {
2485 if (M->Parameters[FAI].Required) {
2486 Error(FALocs[FAI].
isValid() ? FALocs[FAI] : Lexer.getLoc(),
2487 "missing value for required parameter "
2488 "'" + M->Parameters[FAI].Name +
"' in macro '" + M->Name +
"'");
2492 if (!M->Parameters[FAI].Value.empty())
2493 A[FAI] = M->Parameters[FAI].Value;
2499 if (Lexer.is(AsmToken::Comma))
2503 return TokError(
"too many positional arguments");
2508 return (I == MacroMap.end()) ?
nullptr : &I->getValue();
2512 MacroMap.insert(std::make_pair(Name, std::move(Macro)));
2515 void AsmParser::undefineMacro(
StringRef Name) { MacroMap.erase(Name); }
2517 bool AsmParser::handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc) {
2521 if (ActiveMacros.size() == MaxNestingDepth) {
2522 std::ostringstream MaxNestingDepthError;
2523 MaxNestingDepthError <<
"macros cannot be nested more than "
2524 << MaxNestingDepth <<
" levels deep."
2525 <<
" Use -asm-macro-max-nesting-depth to increase "
2527 return TokError(MaxNestingDepthError.str());
2530 MCAsmMacroArguments
A;
2531 if (parseMacroArguments(M, A))
2540 if (expandMacro(OS, Body, M->Parameters, A,
true, getTok().getLoc()))
2545 OS <<
".endmacro\n";
2547 std::unique_ptr<MemoryBuffer> Instantiation =
2548 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
2552 MacroInstantiation *
MI =
new MacroInstantiation(
2553 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
2554 ActiveMacros.push_back(MI);
2556 ++NumOfMacroInstantiations;
2566 void AsmParser::handleMacroExit() {
2568 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2572 delete ActiveMacros.back();
2573 ActiveMacros.pop_back();
2576 bool AsmParser::parseAssignment(
StringRef Name,
bool allow_redef,
2602 bool AsmParser::parseIdentifier(
StringRef &Res) {
2608 if (Lexer.is(AsmToken::Dollar) || Lexer.is(AsmToken::At)) {
2609 SMLoc PrefixLoc = getLexer().getLoc();
2614 Lexer.peekTokens(Buf,
false);
2616 if (Buf[0].isNot(AsmToken::Identifier))
2635 Res = getTok().getIdentifier();
2646 bool AsmParser::parseDirectiveSet(
StringRef IDVal,
bool allow_redef) {
2648 if (check(parseIdentifier(Name),
"expected identifier") ||
2649 parseToken(AsmToken::Comma) || parseAssignment(Name, allow_redef,
true))
2650 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2654 bool AsmParser::parseEscapedString(std::string &Data) {
2659 StringRef Str = getTok().getStringContents();
2660 for (
unsigned i = 0, e = Str.
size();
i != e; ++
i) {
2661 if (Str[
i] !=
'\\') {
2670 return TokError(
"unexpected backslash at end of string");
2673 if ((
unsigned)(Str[
i] -
'0') <= 7) {
2675 unsigned Value = Str[
i] -
'0';
2677 if (
i + 1 != e && ((
unsigned)(Str[
i + 1] -
'0')) <= 7) {
2679 Value = Value * 8 + (Str[
i] -
'0');
2681 if (
i + 1 != e && ((
unsigned)(Str[
i + 1] -
'0')) <= 7) {
2683 Value = Value * 8 + (Str[
i] -
'0');
2688 return TokError(
"invalid octal escape sequence (out of range)");
2690 Data += (
unsigned char)Value;
2698 return TokError(
"invalid escape sequence (unrecognized character)");
2700 case 'b': Data +=
'\b';
break;
2701 case 'f': Data +=
'\f';
break;
2702 case 'n': Data +=
'\n';
break;
2703 case 'r': Data +=
'\r';
break;
2704 case 't': Data +=
'\t';
break;
2705 case '"': Data +=
'"';
break;
2706 case '\\': Data +=
'\\';
break;
2716 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
2717 auto parseOp = [&]() ->
bool {
2719 if (checkForValidSection() || parseEscapedString(Data))
2721 getStreamer().EmitBytes(Data);
2723 getStreamer().EmitBytes(
StringRef(
"\0", 1));
2727 if (parseMany(parseOp))
2728 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2734 bool AsmParser::parseDirectiveReloc(
SMLoc DirectiveLoc) {
2736 const MCExpr *Expr =
nullptr;
2738 SMLoc OffsetLoc = Lexer.getTok().getLoc();
2739 int64_t OffsetValue;
2742 if (parseExpression(Offset))
2745 if (check(!Offset->evaluateAsAbsolute(OffsetValue), OffsetLoc,
2746 "expression is not a constant value") ||
2747 check(OffsetValue < 0, OffsetLoc,
"expression is negative") ||
2748 parseToken(AsmToken::Comma,
"expected comma") ||
2749 check(getTok().isNot(AsmToken::Identifier),
"expected relocation name"))
2752 SMLoc NameLoc = Lexer.getTok().getLoc();
2753 StringRef Name = Lexer.getTok().getIdentifier();
2756 if (Lexer.is(AsmToken::Comma)) {
2758 SMLoc ExprLoc = Lexer.getLoc();
2759 if (parseExpression(Expr))
2764 return Error(ExprLoc,
"expression must be relocatable");
2767 if (parseToken(AsmToken::EndOfStatement,
2768 "unexpected token in .reloc directive"))
2771 if (getStreamer().EmitRelocDirective(*Offset, Name, Expr, DirectiveLoc))
2772 return Error(NameLoc,
"unknown relocation name");
2779 bool AsmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
2780 auto parseOp = [&]() ->
bool {
2782 SMLoc ExprLoc = getLexer().getLoc();
2783 if (checkForValidSection() || parseExpression(Value))
2786 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2787 assert(Size <= 8 &&
"Invalid size");
2788 uint64_t IntValue = MCE->getValue();
2789 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
2790 return Error(ExprLoc,
"out of range literal value");
2791 getStreamer().EmitIntValue(IntValue, Size);
2793 getStreamer().EmitValue(Value, Size, ExprLoc);
2797 if (parseMany(parseOp))
2798 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2805 bool AsmParser::parseDirectiveOctaValue(
StringRef IDVal) {
2806 auto parseOp = [&]() ->
bool {
2807 if (checkForValidSection())
2809 if (getTok().isNot(AsmToken::Integer) && getTok().isNot(AsmToken::BigNum))
2810 return TokError(
"unknown token in expression");
2811 SMLoc ExprLoc = getTok().getLoc();
2812 APInt IntValue = getTok().getAPIntVal();
2815 if (!IntValue.
isIntN(128))
2816 return Error(ExprLoc,
"out of range literal value");
2817 if (!IntValue.
isIntN(64)) {
2825 getStreamer().EmitIntValue(lo, 8);
2826 getStreamer().EmitIntValue(hi, 8);
2828 getStreamer().EmitIntValue(hi, 8);
2829 getStreamer().EmitIntValue(lo, 8);
2834 if (parseMany(parseOp))
2835 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2843 if (getLexer().is(AsmToken::Minus)) {
2846 }
else if (getLexer().is(AsmToken::Plus))
2850 return TokError(Lexer.getErr());
2851 if (Lexer.isNot(AsmToken::Integer) && Lexer.isNot(AsmToken::Real) &&
2852 Lexer.isNot(AsmToken::Identifier))
2853 return TokError(
"unexpected token in directive");
2858 if (getLexer().is(AsmToken::Identifier)) {
2860 Value = APFloat::getInf(Semantics);
2862 Value = APFloat::getNaN(Semantics,
false, ~0);
2864 return TokError(
"invalid floating point literal");
2865 }
else if (Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven) ==
2866 APFloat::opInvalidOp)
2867 return TokError(
"invalid floating point literal");
2874 Res = Value.bitcastToAPInt();
2881 bool AsmParser::parseDirectiveRealValue(
StringRef IDVal,
2883 auto parseOp = [&]() ->
bool {
2885 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
2892 if (parseMany(parseOp))
2893 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2899 bool AsmParser::parseDirectiveZero() {
2900 SMLoc NumBytesLoc = Lexer.getLoc();
2902 if (checkForValidSection() || parseExpression(NumBytes))
2906 if (getLexer().is(AsmToken::Comma)) {
2908 if (parseAbsoluteExpression(Val))
2912 if (parseToken(AsmToken::EndOfStatement,
2913 "unexpected token in '.zero' directive"))
2915 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
2922 bool AsmParser::parseDirectiveFill() {
2923 SMLoc NumValuesLoc = Lexer.getLoc();
2925 if (checkForValidSection() || parseExpression(NumValues))
2928 int64_t FillSize = 1;
2929 int64_t FillExpr = 0;
2931 SMLoc SizeLoc, ExprLoc;
2933 if (parseOptionalToken(AsmToken::Comma)) {
2934 SizeLoc = getTok().getLoc();
2935 if (parseAbsoluteExpression(FillSize))
2937 if (parseOptionalToken(AsmToken::Comma)) {
2938 ExprLoc = getTok().getLoc();
2939 if (parseAbsoluteExpression(FillExpr))
2943 if (parseToken(AsmToken::EndOfStatement,
2944 "unexpected token in '.fill' directive"))
2948 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
2952 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
2957 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
2959 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
2966 bool AsmParser::parseDirectiveOrg() {
2968 SMLoc OffsetLoc = Lexer.getLoc();
2969 if (checkForValidSection() || parseExpression(Offset))
2973 int64_t FillExpr = 0;
2974 if (parseOptionalToken(AsmToken::Comma))
2975 if (parseAbsoluteExpression(FillExpr))
2976 return addErrorSuffix(
" in '.org' directive");
2977 if (parseToken(AsmToken::EndOfStatement))
2978 return addErrorSuffix(
" in '.org' directive");
2980 getStreamer().emitValueToOffset(Offset, FillExpr, OffsetLoc);
2986 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
2987 SMLoc AlignmentLoc = getLexer().getLoc();
2990 bool HasFillExpr =
false;
2991 int64_t FillExpr = 0;
2992 int64_t MaxBytesToFill = 0;
2994 auto parseAlign = [&]() ->
bool {
2995 if (checkForValidSection() || parseAbsoluteExpression(Alignment))
2997 if (parseOptionalToken(AsmToken::Comma)) {
3001 if (getTok().isNot(AsmToken::Comma)) {
3003 if (parseAbsoluteExpression(FillExpr))
3006 if (parseOptionalToken(AsmToken::Comma))
3007 if (parseTokenLoc(MaxBytesLoc) ||
3008 parseAbsoluteExpression(MaxBytesToFill))
3011 return parseToken(AsmToken::EndOfStatement);
3015 return addErrorSuffix(
" in directive");
3018 bool ReturnVal =
false;
3023 if (Alignment >= 32) {
3024 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3028 Alignment = 1ULL << Alignment;
3036 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3041 if (MaxBytesToFill < 1) {
3042 ReturnVal |=
Error(MaxBytesLoc,
3043 "alignment directive can never be satisfied in this "
3044 "many bytes, ignoring maximum bytes expression");
3048 if (MaxBytesToFill >= Alignment) {
3049 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3058 assert(Section &&
"must have section to emit alignment");
3060 if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) &&
3061 ValueSize == 1 && UseCodeAlign) {
3062 getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
3065 getStreamer().EmitValueToAlignment(Alignment, FillExpr, ValueSize,
3075 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
3077 int64_t FileNumber = -1;
3078 SMLoc FileNumberLoc = getLexer().getLoc();
3079 if (getLexer().is(AsmToken::Integer)) {
3080 FileNumber = getTok().getIntVal();
3084 return TokError(
"file number less than one");
3087 std::string Path = getTok().getString();
3092 "unexpected token in '.file' directive") ||
3093 parseEscapedString(Path))
3098 std::string FilenameData;
3100 if (check(FileNumber == -1,
3101 "explicit path specified, but no file number") ||
3102 parseEscapedString(FilenameData))
3104 Filename = FilenameData;
3110 if (parseToken(AsmToken::EndOfStatement,
3111 "unexpected token in '.file' directive"))
3114 if (FileNumber == -1)
3115 getStreamer().EmitFileDirective(Filename);
3119 if (getContext().getGenDwarfForAssembly())
3120 getContext().setGenDwarfForAssembly(
false);
3121 else if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename) ==
3123 return Error(FileNumberLoc,
"file number already allocated");
3131 bool AsmParser::parseDirectiveLine() {
3133 if (getLexer().is(AsmToken::Integer)) {
3134 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
3139 if (parseToken(AsmToken::EndOfStatement,
3140 "unexpected token in '.line' directive"))
3153 bool AsmParser::parseDirectiveLoc() {
3154 int64_t FileNumber = 0, LineNumber = 0;
3155 SMLoc Loc = getTok().getLoc();
3156 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
3157 check(FileNumber < 1, Loc,
3158 "file number less than one in '.loc' directive") ||
3159 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
3160 "unassigned file number in '.loc' directive"))
3164 if (getLexer().is(AsmToken::Integer)) {
3165 LineNumber = getTok().getIntVal();
3167 return TokError(
"line number less than zero in '.loc' directive");
3171 int64_t ColumnPos = 0;
3172 if (getLexer().is(AsmToken::Integer)) {
3173 ColumnPos = getTok().getIntVal();
3175 return TokError(
"column position less than zero in '.loc' directive");
3181 int64_t Discriminator = 0;
3183 auto parseLocOp = [&]() ->
bool {
3185 SMLoc Loc = getTok().getLoc();
3186 if (parseIdentifier(Name))
3187 return TokError(
"unexpected token in '.loc' directive");
3189 if (Name ==
"basic_block")
3191 else if (Name ==
"prologue_end")
3193 else if (Name ==
"epilogue_begin")
3195 else if (Name ==
"is_stmt") {
3196 Loc = getTok().getLoc();
3198 if (parseExpression(Value))
3201 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3202 int Value = MCE->getValue();
3204 Flags &= ~DWARF2_FLAG_IS_STMT;
3205 else if (Value == 1)
3208 return Error(Loc,
"is_stmt value not 0 or 1");
3210 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3212 }
else if (Name ==
"isa") {
3213 Loc = getTok().getLoc();
3215 if (parseExpression(Value))
3218 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3219 int Value = MCE->getValue();
3221 return Error(Loc,
"isa number less than zero");
3224 return Error(Loc,
"isa number not a constant value");
3226 }
else if (Name ==
"discriminator") {
3227 if (parseAbsoluteExpression(Discriminator))
3230 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3235 if (parseMany(parseLocOp,
false ))
3238 getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3246 bool AsmParser::parseDirectiveStabs() {
3247 return TokError(
"unsupported directive '.stabs'");
3252 bool AsmParser::parseDirectiveCVFile() {
3253 SMLoc FileNumberLoc = getTok().getLoc();
3255 std::string Filename;
3257 if (parseIntToken(FileNumber,
3258 "expected file number in '.cv_file' directive") ||
3259 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3261 "unexpected token in '.cv_file' directive") ||
3264 parseEscapedString(Filename) ||
3265 parseToken(AsmToken::EndOfStatement,
3266 "unexpected token in '.cv_file' directive"))
3269 if (!getStreamer().EmitCVFileDirective(FileNumber, Filename))
3270 return Error(FileNumberLoc,
"file number already allocated");
3275 bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3278 return parseTokenLoc(Loc) ||
3279 parseIntToken(FunctionId,
"expected function id in '" + DirectiveName +
3281 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3282 "expected function id within range [0, UINT_MAX)");
3285 bool AsmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
3287 return parseTokenLoc(Loc) ||
3288 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
3290 check(FileNumber < 1, Loc,
"file number less than one in '" +
3291 DirectiveName +
"' directive") ||
3292 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3293 "unassigned file number in '" + DirectiveName +
"' directive");
3300 bool AsmParser::parseDirectiveCVFuncId() {
3301 SMLoc FunctionIdLoc = getTok().getLoc();
3304 if (parseCVFunctionId(FunctionId,
".cv_func_id") ||
3305 parseToken(AsmToken::EndOfStatement,
3306 "unexpected token in '.cv_func_id' directive"))
3309 if (!getStreamer().EmitCVFuncIdDirective(FunctionId))
3310 return Error(FunctionIdLoc,
"function id already allocated");
3323 bool AsmParser::parseDirectiveCVInlineSiteId() {
3324 SMLoc FunctionIdLoc = getTok().getLoc();
3332 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3336 if (check((getLexer().isNot(AsmToken::Identifier) ||
3337 getTok().getIdentifier() !=
"within"),
3338 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3343 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3347 if (check((getLexer().isNot(AsmToken::Identifier) ||
3348 getTok().getIdentifier() !=
"inlined_at"),
3349 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3355 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3356 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3360 if (getLexer().is(AsmToken::Integer)) {
3361 IACol = getTok().getIntVal();
3365 if (parseToken(AsmToken::EndOfStatement,
3366 "unexpected token in '.cv_inline_site_id' directive"))
3369 if (!getStreamer().EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3370 IALine, IACol, FunctionIdLoc))
3371 return Error(FunctionIdLoc,
"function id already allocated");
3383 bool AsmParser::parseDirectiveCVLoc() {
3384 SMLoc DirectiveLoc = getTok().getLoc();
3386 int64_t FunctionId, FileNumber;
3387 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3388 parseCVFileId(FileNumber,
".cv_loc"))
3391 int64_t LineNumber = 0;
3392 if (getLexer().is(AsmToken::Integer)) {
3393 LineNumber = getTok().getIntVal();
3395 return TokError(
"line number less than zero in '.cv_loc' directive");
3399 int64_t ColumnPos = 0;
3400 if (getLexer().is(AsmToken::Integer)) {
3401 ColumnPos = getTok().getIntVal();
3403 return TokError(
"column position less than zero in '.cv_loc' directive");
3407 bool PrologueEnd =
false;
3408 uint64_t IsStmt = 0;
3410 auto parseOp = [&]() ->
bool {
3412 SMLoc Loc = getTok().getLoc();
3413 if (parseIdentifier(Name))
3414 return TokError(
"unexpected token in '.cv_loc' directive");
3415 if (Name ==
"prologue_end")
3417 else if (Name ==
"is_stmt") {
3418 Loc = getTok().getLoc();
3420 if (parseExpression(Value))
3424 if (
const auto *MCE = dyn_cast<MCConstantExpr>(Value))
3425 IsStmt = MCE->getValue();
3428 return Error(Loc,
"is_stmt value not 0 or 1");
3430 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3435 if (parseMany(parseOp,
false ))
3438 getStreamer().EmitCVLocDirective(FunctionId, FileNumber, LineNumber,
3439 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
3446 bool AsmParser::parseDirectiveCVLinetable() {
3449 SMLoc Loc = getTok().getLoc();
3450 if (parseCVFunctionId(FunctionId,
".cv_linetable") ||
3451 parseToken(AsmToken::Comma,
3452 "unexpected token in '.cv_linetable' directive") ||
3453 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3454 "expected identifier in directive") ||
3455 parseToken(AsmToken::Comma,
3456 "unexpected token in '.cv_linetable' directive") ||
3457 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3458 "expected identifier in directive"))
3461 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3462 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3464 getStreamer().EmitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3470 bool AsmParser::parseDirectiveCVInlineLinetable() {
3471 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3473 SMLoc Loc = getTok().getLoc();
3474 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3475 parseTokenLoc(Loc) ||
3478 "expected SourceField in '.cv_inline_linetable' directive") ||
3479 check(SourceFileId <= 0, Loc,
3480 "File id less than zero in '.cv_inline_linetable' directive") ||
3481 parseTokenLoc(Loc) ||
3484 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
3485 check(SourceLineNum < 0, Loc,
3486 "Line number less than zero in '.cv_inline_linetable' directive") ||
3487 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3488 "expected identifier in directive") ||
3489 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3490 "expected identifier in directive"))
3493 if (parseToken(AsmToken::EndOfStatement,
"Expected End of Statement"))
3496 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3497 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3498 getStreamer().EmitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3499 SourceLineNum, FnStartSym,
3506 bool AsmParser::parseDirectiveCVDefRange() {
3508 std::vector<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
3509 while (getLexer().is(AsmToken::Identifier)) {
3510 Loc = getLexer().getLoc();
3512 if (parseIdentifier(GapStartName))
3513 return Error(Loc,
"expected identifier in directive");
3514 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
3516 Loc = getLexer().getLoc();
3518 if (parseIdentifier(GapEndName))
3519 return Error(Loc,
"expected identifier in directive");
3520 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
3522 Ranges.push_back({GapStartSym, GapEndSym});
3525 std::string FixedSizePortion;
3526 if (parseToken(AsmToken::Comma,
"unexpected token in directive") ||
3527 parseEscapedString(FixedSizePortion))
3530 getStreamer().EmitCVDefRangeDirective(Ranges, FixedSizePortion);
3536 bool AsmParser::parseDirectiveCVStringTable() {
3537 getStreamer().EmitCVStringTableDirective();
3543 bool AsmParser::parseDirectiveCVFileChecksums() {
3544 getStreamer().EmitCVFileChecksumsDirective();
3550 bool AsmParser::parseDirectiveCFISections() {
3555 if (parseIdentifier(Name))
3556 return TokError(
"Expected an identifier");
3558 if (Name ==
".eh_frame")
3560 else if (Name ==
".debug_frame")
3563 if (getLexer().is(AsmToken::Comma)) {
3566 if (parseIdentifier(Name))
3567 return TokError(
"Expected an identifier");
3569 if (Name ==
".eh_frame")
3571 else if (Name ==
".debug_frame")
3575 getStreamer().EmitCFISections(EH, Debug);
3581 bool AsmParser::parseDirectiveCFIStartProc() {
3583 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
3584 if (check(parseIdentifier(Simple) || Simple !=
"simple",
3585 "unexpected token") ||
3586 parseToken(AsmToken::EndOfStatement))
3587 return addErrorSuffix(
" in '.cfi_startproc' directive");
3590 getStreamer().EmitCFIStartProc(!Simple.
empty());
3596 bool AsmParser::parseDirectiveCFIEndProc() {
3597 getStreamer().EmitCFIEndProc();
3602 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
3603 SMLoc DirectiveLoc) {
3606 if (getLexer().isNot(AsmToken::Integer)) {
3607 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
3609 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
3611 return parseAbsoluteExpression(Register);
3618 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
3619 int64_t Register = 0, Offset = 0;
3620 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3621 parseToken(AsmToken::Comma,
"unexpected token in directive") ||
3622 parseAbsoluteExpression(Offset))
3625 getStreamer().EmitCFIDefCfa(Register, Offset);
3631 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
3633 if (parseAbsoluteExpression(Offset))
3636 getStreamer().EmitCFIDefCfaOffset(Offset);
3642 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
3643 int64_t Register1 = 0, Register2 = 0;
3644 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) ||
3645 parseToken(AsmToken::Comma,
"unexpected token in directive") ||
3646 parseRegisterOrRegisterNumber(Register2, DirectiveLoc))
3649 getStreamer().EmitCFIRegister(Register1, Register2);
3655 bool AsmParser::parseDirectiveCFIWindowSave() {
3656 getStreamer().EmitCFIWindowSave();
3662 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
3663 int64_t Adjustment = 0;
3664 if (parseAbsoluteExpression(Adjustment))
3667 getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
3673 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
3674 int64_t Register = 0;
3675 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3678 getStreamer().EmitCFIDefCfaRegister(Register);
3684 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
3685 int64_t Register = 0;
3688 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3689 parseToken(AsmToken::Comma,
"unexpected token in directive") ||
3690 parseAbsoluteExpression(Offset))
3693 getStreamer().EmitCFIOffset(Register, Offset);
3699 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
3700 int64_t Register = 0, Offset = 0;
3702 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3703 parseToken(AsmToken::Comma,
"unexpected token in directive") ||
3704 parseAbsoluteExpression(Offset))
3707 getStreamer().EmitCFIRelOffset(Register, Offset);
3712 if (Encoding & ~0xff)
3718 const unsigned Format = Encoding & 0xf;
3725 const unsigned Application = Encoding & 0x70;
3737 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
3738 int64_t Encoding = 0;
3739 if (parseAbsoluteExpression(Encoding))
3746 parseToken(AsmToken::Comma,
"unexpected token in directive") ||
3747 check(parseIdentifier(Name),
"expected identifier in directive"))
3750 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
3753 getStreamer().EmitCFIPersonality(Sym, Encoding);
3755 getStreamer().EmitCFILsda(Sym, Encoding);
3761 bool AsmParser::parseDirectiveCFIRememberState() {
3762 getStreamer().EmitCFIRememberState();
3768 bool AsmParser::parseDirectiveCFIRestoreState() {
3769 getStreamer().EmitCFIRestoreState();
3775 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
3776 int64_t Register = 0;
3778 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3781 getStreamer().EmitCFISameValue(Register);
3787 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
3788 int64_t Register = 0;
3789 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3792 getStreamer().EmitCFIRestore(Register);
3798 bool AsmParser::parseDirectiveCFIEscape() {
3801 if (parseAbsoluteExpression(CurrValue))
3804 Values.push_back((uint8_t)CurrValue);
3806 while (getLexer().is(AsmToken::Comma)) {
3809 if (parseAbsoluteExpression(CurrValue))
3812 Values.push_back((uint8_t)CurrValue);
3815 getStreamer().EmitCFIEscape(Values);
3821 bool AsmParser::parseDirectiveCFISignalFrame() {
3822 if (parseToken(AsmToken::EndOfStatement,
3823 "unexpected token in '.cfi_signal_frame'"))
3826 getStreamer().EmitCFISignalFrame();
3832 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
3833 int64_t Register = 0;
3835 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3838 getStreamer().EmitCFIUndefined(Register);
3845 bool AsmParser::parseDirectiveMacrosOnOff(
StringRef Directive) {
3846 if (parseToken(AsmToken::EndOfStatement,
3847 "unexpected token in '" + Directive +
"' directive"))
3850 setMacrosEnabled(Directive ==
".macros_on");
3856 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
3858 if (parseIdentifier(Name))
3859 return TokError(
"expected identifier in '.macro' directive");
3861 if (getLexer().is(AsmToken::Comma))
3864 MCAsmMacroParameters Parameters;
3865 while (getLexer().isNot(AsmToken::EndOfStatement)) {
3867 if (!Parameters.empty() && Parameters.back().Vararg)
3868 return Error(Lexer.getLoc(),
3869 "Vararg parameter '" + Parameters.back().Name +
3870 "' should be last one in the list of parameters.");
3872 MCAsmMacroParameter Parameter;
3873 if (parseIdentifier(Parameter.Name))
3874 return TokError(
"expected identifier in '.macro' directive");
3876 if (Lexer.is(AsmToken::Colon)) {
3882 QualLoc = Lexer.getLoc();
3883 if (parseIdentifier(Qualifier))
3884 return Error(QualLoc,
"missing parameter qualifier for "
3885 "'" + Parameter.Name +
"' in macro '" + Name +
"'");
3887 if (Qualifier ==
"req")
3888 Parameter.Required =
true;
3889 else if (Qualifier ==
"vararg")
3890 Parameter.Vararg =
true;
3892 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
3893 "for '" + Parameter.Name +
"' in macro '" + Name +
"'");
3896 if (getLexer().is(AsmToken::Equal)) {
3901 ParamLoc = Lexer.getLoc();
3902 if (parseMacroArgument(Parameter.Value,
false ))
3905 if (Parameter.Required)
3906 Warning(ParamLoc,
"pointless default value for required parameter "
3907 "'" + Parameter.Name +
"' in macro '" + Name +
"'");
3910 Parameters.push_back(std::move(Parameter));
3912 if (getLexer().is(AsmToken::Comma))
3920 AsmToken EndToken, StartToken = getTok();
3921 unsigned MacroDepth = 0;
3931 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
3934 if (getLexer().is(AsmToken::Identifier)) {
3935 if (getTok().getIdentifier() ==
".endm" ||
3936 getTok().getIdentifier() ==
".endmacro") {
3937 if (MacroDepth == 0) {
3938 EndToken = getTok();
3940 if (getLexer().isNot(AsmToken::EndOfStatement))
3941 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
3948 }
else if (getTok().getIdentifier() ==
".macro") {
3956 eatToEndOfStatement();
3959 if (lookupMacro(Name)) {
3960 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
3966 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
3967 defineMacro(Name, MCAsmMacro(Name, Body, std::move(Parameters)));
3985 void AsmParser::checkForBadMacro(
SMLoc DirectiveLoc,
StringRef Name,
3990 unsigned NParameters = Parameters.
size();
3991 if (NParameters == 0)
3994 bool NamedParametersFound =
false;
3995 bool PositionalParametersFound =
false;
4000 while (!Body.
empty()) {
4002 std::size_t End = Body.
size(), Pos = 0;
4003 for (; Pos !=
End; ++Pos) {
4006 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4010 if (Body[Pos] !=
'$' || Pos + 1 == End)
4012 char Next = Body[Pos + 1];
4013 if (Next ==
'$' || Next ==
'n' ||
4014 isdigit(static_cast<unsigned char>(Next)))
4022 if (Body[Pos] ==
'$') {
4023 switch (Body[Pos + 1]) {
4030 PositionalParametersFound =
true;
4035 PositionalParametersFound =
true;
4041 unsigned I = Pos + 1;
4045 const char *Begin = Body.
data() + Pos + 1;
4048 for (; Index < NParameters; ++Index)
4049 if (Parameters[Index].Name ==
Argument)
4052 if (Index == NParameters) {
4053 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4059 NamedParametersFound =
true;
4067 if (!NamedParametersFound && PositionalParametersFound)
4068 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4069 "used in macro body, possible positional parameter "
4070 "found in body which will have no effect");
4075 bool AsmParser::parseDirectiveExitMacro(
StringRef Directive) {
4076 if (parseToken(AsmToken::EndOfStatement,
4077 "unexpected token in '" + Directive +
"' directive"))
4080 if (!isInsideMacroInstantiation())
4081 return TokError(
"unexpected '" + Directive +
"' in file, "
4082 "no current macro definition");
4085 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4086 TheCondState = TheCondStack.back();
4087 TheCondStack.pop_back();
4097 bool AsmParser::parseDirectiveEndMacro(
StringRef Directive) {
4098 if (getLexer().isNot(AsmToken::EndOfStatement))
4099 return TokError(
"unexpected token in '" + Directive +
"' directive");
4103 if (isInsideMacroInstantiation()) {
4110 return TokError(
"unexpected '" + Directive +
"' in file, "
4111 "no current macro definition");
4116 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
4119 if (parseTokenLoc(Loc) ||
4120 check(parseIdentifier(Name), Loc,
4121 "expected identifier in '.purgem' directive") ||
4122 parseToken(AsmToken::EndOfStatement,
4123 "unexpected token in '.purgem' directive"))
4126 if (!lookupMacro(Name))
4127 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4129 undefineMacro(Name);
4135 bool AsmParser::parseDirectiveBundleAlignMode() {
4138 SMLoc ExprLoc = getLexer().getLoc();
4139 int64_t AlignSizePow2;
4140 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4141 parseToken(AsmToken::EndOfStatement,
"unexpected token after expression "
4142 "in '.bundle_align_mode' "
4144 check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
4145 "invalid bundle alignment size (expected between 0 and 30)"))
4150 getStreamer().EmitBundleAlignMode(static_cast<unsigned>(AlignSizePow2));
4156 bool AsmParser::parseDirectiveBundleLock() {
4157 if (checkForValidSection())
4159 bool AlignToEnd =
false;
4162 SMLoc Loc = getTok().getLoc();
4163 const char *kInvalidOptionError =
4164 "invalid option for '.bundle_lock' directive";
4166 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
4167 if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
4168 check(Option !=
"align_to_end", Loc, kInvalidOptionError) ||
4169 parseToken(AsmToken::EndOfStatement,
4170 "unexpected token after '.bundle_lock' directive option"))
4175 getStreamer().EmitBundleLock(AlignToEnd);
4181 bool AsmParser::parseDirectiveBundleUnlock() {
4182 if (checkForValidSection() ||
4183 parseToken(AsmToken::EndOfStatement,
4184 "unexpected token in '.bundle_unlock' directive"))
4187 getStreamer().EmitBundleUnlock();
4193 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
4195 SMLoc NumBytesLoc = Lexer.getLoc();
4197 if (checkForValidSection() || parseExpression(NumBytes))
4200 int64_t FillExpr = 0;
4201 if (parseOptionalToken(AsmToken::Comma))
4202 if (parseAbsoluteExpression(FillExpr))
4203 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4204 if (parseToken(AsmToken::EndOfStatement))
4205 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4208 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4215 bool AsmParser::parseDirectiveDCB(
StringRef IDVal,
unsigned Size) {
4216 SMLoc NumValuesLoc = Lexer.getLoc();
4218 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4221 if (NumValues < 0) {
4222 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4226 if (parseToken(AsmToken::Comma,
4227 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4231 SMLoc ExprLoc = getLexer().getLoc();
4232 if (parseExpression(Value))
4236 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
4237 assert(Size <= 8 &&
"Invalid size");
4238 uint64_t IntValue = MCE->getValue();
4239 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
4240 return Error(ExprLoc,
"literal value out of range for directive");
4241 for (uint64_t
i = 0, e = NumValues;
i != e; ++
i)
4242 getStreamer().EmitIntValue(IntValue, Size);
4244 for (uint64_t
i = 0, e = NumValues;
i != e; ++
i)
4245 getStreamer().EmitValue(Value, Size, ExprLoc);
4248 if (parseToken(AsmToken::EndOfStatement,
4249 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4258 SMLoc NumValuesLoc = Lexer.getLoc();
4260 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4263 if (NumValues < 0) {
4264 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4268 if (parseToken(AsmToken::Comma,
4269 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4273 if (parseRealValue(Semantics, AsInt))
4276 if (parseToken(AsmToken::EndOfStatement,
4277 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4280 for (uint64_t
i = 0, e = NumValues;
i != e; ++
i)
4289 bool AsmParser::parseDirectiveDS(
StringRef IDVal,
unsigned Size) {
4291 SMLoc NumValuesLoc = Lexer.getLoc();
4293 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4296 if (NumValues < 0) {
4297 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4301 if (parseToken(AsmToken::EndOfStatement,
4302 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4305 for (uint64_t
i = 0, e = NumValues;
i != e; ++
i)
4306 getStreamer().emitFill(Size, 0);
4313 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4314 if (checkForValidSection())
4317 auto parseOp = [&]() ->
bool {
4319 if (parseExpression(Value))
4322 getStreamer().EmitSLEB128Value(Value);
4324 getStreamer().EmitULEB128Value(Value);
4328 if (parseMany(parseOp))
4329 return addErrorSuffix(
" in directive");
4336 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4337 auto parseOp = [&]() ->
bool {
4339 SMLoc Loc = getTok().getLoc();
4340 if (parseIdentifier(Name))
4341 return Error(Loc,
"expected identifier");
4342 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4346 return Error(Loc,
"non-local symbol required");
4348 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
4349 return Error(Loc,
"unable to emit symbol attribute");
4353 if (parseMany(parseOp))
4354 return addErrorSuffix(
" in directive");
4360 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4361 if (checkForValidSection())
4364 SMLoc IDLoc = getLexer().getLoc();
4366 if (parseIdentifier(Name))
4367 return TokError(
"expected identifier in directive");
4370 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4372 if (getLexer().isNot(AsmToken::Comma))
4373 return TokError(
"unexpected token in directive");
4377 SMLoc SizeLoc = getLexer().getLoc();
4378 if (parseAbsoluteExpression(Size))
4381 int64_t Pow2Alignment = 0;
4382 SMLoc Pow2AlignmentLoc;
4383 if (getLexer().is(AsmToken::Comma)) {
4385 Pow2AlignmentLoc = getLexer().getLoc();
4386 if (parseAbsoluteExpression(Pow2Alignment))
4391 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4394 if ((!IsLocal && Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) ||
4397 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4398 Pow2Alignment =
Log2_64(Pow2Alignment);
4402 if (parseToken(AsmToken::EndOfStatement,
4403 "unexpected token in '.comm' or '.lcomm' directive"))
4409 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't "
4410 "be less than zero");
4415 if (Pow2Alignment < 0)
4416 return Error(Pow2AlignmentLoc,
"invalid '.comm' or '.lcomm' directive "
4417 "alignment, can't be less than zero");
4420 return Error(IDLoc,
"invalid symbol redefinition");
4424 getStreamer().EmitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4428 getStreamer().EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4434 bool AsmParser::parseDirectiveAbort() {
4436 SMLoc Loc = getLexer().getLoc();
4438 StringRef Str = parseStringToEndOfStatement();
4439 if (parseToken(AsmToken::EndOfStatement,
4440 "unexpected token in '.abort' directive"))
4444 return Error(Loc,
".abort detected. Assembly stopping.");
4446 return Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
4454 bool AsmParser::parseDirectiveInclude() {
4456 std::string Filename;
4457 SMLoc IncludeLoc = getTok().getLoc();
4460 "expected string in '.include' directive") ||
4461 parseEscapedString(Filename) ||
4462 check(getTok().isNot(AsmToken::EndOfStatement),
4463 "unexpected token in '.include' directive") ||
4466 check(enterIncludeFile(Filename), IncludeLoc,
4467 "Could not find include file '" + Filename +
"'"))
4475 bool AsmParser::parseDirectiveIncbin() {
4477 std::string Filename;
4478 SMLoc IncbinLoc = getTok().getLoc();
4480 "expected string in '.incbin' directive") ||
4481 parseEscapedString(Filename))
4485 const MCExpr *Count =
nullptr;
4486 SMLoc SkipLoc, CountLoc;
4487 if (parseOptionalToken(AsmToken::Comma)) {
4490 if (getTok().isNot(AsmToken::Comma)) {
4491 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
4494 if (parseOptionalToken(AsmToken::Comma)) {
4495 CountLoc = getTok().getLoc();
4496 if (parseExpression(Count))
4501 if (parseToken(AsmToken::EndOfStatement,
4502 "unexpected token in '.incbin' directive"))
4505 if (check(Skip < 0, SkipLoc,
"skip is negative"))
4509 if (processIncbinFile(Filename, Skip, Count, CountLoc))
4510 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
4516 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
4517 TheCondStack.push_back(TheCondState);
4518 TheCondState.TheCond = AsmCond::IfCond;
4519 if (TheCondState.Ignore) {
4520 eatToEndOfStatement();
4523 if (parseAbsoluteExpression(ExprValue) ||
4524 parseToken(AsmToken::EndOfStatement,
4525 "unexpected token in '.if' directive"))
4535 ExprValue = ExprValue == 0;
4538 ExprValue = ExprValue >= 0;
4541 ExprValue = ExprValue > 0;
4544 ExprValue = ExprValue <= 0;
4547 ExprValue = ExprValue < 0;
4551 TheCondState.CondMet = ExprValue;
4552 TheCondState.Ignore = !TheCondState.CondMet;
4560 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
4561 TheCondStack.push_back(TheCondState);
4562 TheCondState.TheCond = AsmCond::IfCond;
4564 if (TheCondState.Ignore) {
4565 eatToEndOfStatement();
4567 StringRef Str = parseStringToEndOfStatement();
4569 if (parseToken(AsmToken::EndOfStatement,
4570 "unexpected token in '.ifb' directive"))
4573 TheCondState.CondMet = ExpectBlank == Str.
empty();
4574 TheCondState.Ignore = !TheCondState.CondMet;
4583 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4584 TheCondStack.push_back(TheCondState);
4585 TheCondState.TheCond = AsmCond::IfCond;
4587 if (TheCondState.Ignore) {
4588 eatToEndOfStatement();
4592 if (parseToken(AsmToken::Comma,
"unexpected token in '.ifc' directive"))
4595 StringRef Str2 = parseStringToEndOfStatement();
4597 if (parseToken(AsmToken::EndOfStatement,
4598 "unexpected token in '.ifc' directive"))
4601 TheCondState.CondMet = ExpectEqual == (Str1.
trim() == Str2.
trim());
4602 TheCondState.Ignore = !TheCondState.CondMet;
4610 bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4613 return TokError(
"expected string parameter for '.ifeqs' directive");
4614 return TokError(
"expected string parameter for '.ifnes' directive");
4617 StringRef String1 = getTok().getStringContents();
4620 if (Lexer.isNot(AsmToken::Comma)) {
4623 "expected comma after first string for '.ifeqs' directive");
4624 return TokError(
"expected comma after first string for '.ifnes' directive");
4631 return TokError(
"expected string parameter for '.ifeqs' directive");
4632 return TokError(
"expected string parameter for '.ifnes' directive");
4635 StringRef String2 = getTok().getStringContents();
4638 TheCondStack.push_back(TheCondState);
4639 TheCondState.TheCond = AsmCond::IfCond;
4640 TheCondState.CondMet = ExpectEqual == (String1 == String2);
4641 TheCondState.Ignore = !TheCondState.CondMet;
4648 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
4650 TheCondStack.push_back(TheCondState);
4651 TheCondState.TheCond = AsmCond::IfCond;
4653 if (TheCondState.Ignore) {
4654 eatToEndOfStatement();
4656 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
4657 parseToken(AsmToken::EndOfStatement,
"unexpected token in '.ifdef'"))
4660 MCSymbol *Sym = getContext().lookupSymbol(Name);
4663 TheCondState.CondMet = (Sym && !Sym->
isUndefined());
4665 TheCondState.CondMet = (!Sym || Sym->
isUndefined());
4666 TheCondState.Ignore = !TheCondState.CondMet;
4674 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
4675 if (TheCondState.TheCond != AsmCond::IfCond &&
4676 TheCondState.TheCond != AsmCond::ElseIfCond)
4677 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
4678 " .if or an .elseif");
4679 TheCondState.TheCond = AsmCond::ElseIfCond;
4681 bool LastIgnoreState =
false;
4682 if (!TheCondStack.empty())
4683 LastIgnoreState = TheCondStack.back().Ignore;
4684 if (LastIgnoreState || TheCondState.CondMet) {
4685 TheCondState.Ignore =
true;
4686 eatToEndOfStatement();
4689 if (parseAbsoluteExpression(ExprValue))
4692 if (parseToken(AsmToken::EndOfStatement,
4693 "unexpected token in '.elseif' directive"))
4696 TheCondState.CondMet = ExprValue;
4697 TheCondState.Ignore = !TheCondState.CondMet;
4705 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
4706 if (parseToken(AsmToken::EndOfStatement,
4707 "unexpected token in '.else' directive"))
4710 if (TheCondState.TheCond != AsmCond::IfCond &&
4711 TheCondState.TheCond != AsmCond::ElseIfCond)
4712 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
4713 " an .if or an .elseif");
4714 TheCondState.TheCond = AsmCond::ElseCond;
4715 bool LastIgnoreState =
false;
4716 if (!TheCondStack.empty())
4717 LastIgnoreState = TheCondStack.back().Ignore;
4718 if (LastIgnoreState || TheCondState.CondMet)
4719 TheCondState.Ignore =
true;
4721 TheCondState.Ignore =
false;
4728 bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
4729 if (parseToken(AsmToken::EndOfStatement,
4730 "unexpected token in '.end' directive"))
4742 bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
4743 if (!TheCondStack.empty()) {
4744 if (TheCondStack.back().Ignore) {
4745 eatToEndOfStatement();
4751 return Error(L,
".err encountered");
4753 StringRef Message =
".error directive invoked in source file";
4754 if (Lexer.isNot(AsmToken::EndOfStatement)) {
4756 return TokError(
".error argument must be a string");
4758 Message = getTok().getStringContents();
4762 return Error(L, Message);
4767 bool AsmParser::parseDirectiveWarning(
SMLoc L) {
4768 if (!TheCondStack.empty()) {
4769 if (TheCondStack.back().Ignore) {
4770 eatToEndOfStatement();
4775 StringRef Message =
".warning directive invoked in source file";
4777 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
4779 return TokError(
".warning argument must be a string");
4781 Message = getTok().getStringContents();
4783 if (parseToken(AsmToken::EndOfStatement,
4784 "expected end of statement in '.warning' directive"))
4788 return Warning(L, Message);
4793 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
4794 if (parseToken(AsmToken::EndOfStatement,
4795 "unexpected token in '.endif' directive"))
4798 if ((TheCondState.TheCond == AsmCond::NoCond) || TheCondStack.empty())
4799 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
4801 if (!TheCondStack.empty()) {
4802 TheCondState = TheCondStack.back();
4803 TheCondStack.pop_back();
4809 void AsmParser::initializeDirectiveKindMap() {
4810 DirectiveKindMap[
".set"] = DK_SET;
4811 DirectiveKindMap[
".equ"] = DK_EQU;
4812 DirectiveKindMap[
".equiv"] = DK_EQUIV;
4813 DirectiveKindMap[
".ascii"] = DK_ASCII;
4814 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
4815 DirectiveKindMap[
".string"] = DK_STRING;
4816 DirectiveKindMap[
".byte"] = DK_BYTE;
4817 DirectiveKindMap[
".short"] = DK_SHORT;
4818 DirectiveKindMap[
".value"] = DK_VALUE;
4819 DirectiveKindMap[
".2byte"] = DK_2BYTE;
4820 DirectiveKindMap[
".long"] = DK_LONG;
4821 DirectiveKindMap[
".int"] = DK_INT;
4822 DirectiveKindMap[
".4byte"] = DK_4BYTE;
4823 DirectiveKindMap[
".quad"] = DK_QUAD;
4824 DirectiveKindMap[
".8byte"] = DK_8BYTE;
4825 DirectiveKindMap[
".octa"] = DK_OCTA;
4826 DirectiveKindMap[
".single"] = DK_SINGLE;
4827 DirectiveKindMap[
".float"] = DK_FLOAT;
4828 DirectiveKindMap[
".double"] = DK_DOUBLE;
4829 DirectiveKindMap[
".align"] = DK_ALIGN;
4830 DirectiveKindMap[
".align32"] = DK_ALIGN32;
4831 DirectiveKindMap[
".balign"] = DK_BALIGN;
4832 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
4833 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
4834 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
4835 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
4836 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
4837 DirectiveKindMap[
".org"] = DK_ORG;
4838 DirectiveKindMap[
".fill"] = DK_FILL;
4839 DirectiveKindMap[
".zero"] = DK_ZERO;
4840 DirectiveKindMap[
".extern"] = DK_EXTERN;
4841 DirectiveKindMap[
".globl"] = DK_GLOBL;
4842 DirectiveKindMap[
".global"] = DK_GLOBAL;
4843 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
4844 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
4845 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
4846 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
4847 DirectiveKindMap[
".reference"] = DK_REFERENCE;
4848 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
4849 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
4850 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
4851 DirectiveKindMap[
".comm"] = DK_COMM;
4852 DirectiveKindMap[
".common"] = DK_COMMON;
4853 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
4854 DirectiveKindMap[
".abort"] = DK_ABORT;
4855 DirectiveKindMap[
".include"] = DK_INCLUDE;
4856 DirectiveKindMap[
".incbin"] = DK_INCBIN;
4857 DirectiveKindMap[
".code16"] = DK_CODE16;
4858 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
4859 DirectiveKindMap[
".rept"] = DK_REPT;
4860 DirectiveKindMap[
".rep"] = DK_REPT;
4861 DirectiveKindMap[
".irp"] = DK_IRP;
4862 DirectiveKindMap[
".irpc"] = DK_IRPC;
4863 DirectiveKindMap[
".endr"] = DK_ENDR;
4864 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
4865 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
4866 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
4867 DirectiveKindMap[
".if"] = DK_IF;
4868 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
4869 DirectiveKindMap[
".ifge"] = DK_IFGE;
4870 DirectiveKindMap[
".ifgt"] = DK_IFGT;
4871 DirectiveKindMap[
".ifle"] = DK_IFLE;
4872 DirectiveKindMap[
".iflt"] = DK_IFLT;
4873 DirectiveKindMap[
".ifne"] = DK_IFNE;
4874 DirectiveKindMap[
".ifb"] = DK_IFB;
4875 DirectiveKindMap[
".ifnb"] = DK_IFNB;
4876 DirectiveKindMap[
".ifc"] = DK_IFC;
4877 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
4878 DirectiveKindMap[
".ifnc"] = DK_IFNC;
4879 DirectiveKindMap[
".ifnes"] = DK_IFNES;
4880 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
4881 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
4882 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
4883 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
4884 DirectiveKindMap[
".else"] = DK_ELSE;
4885 DirectiveKindMap[
".end"] = DK_END;
4886 DirectiveKindMap[
".endif"] = DK_ENDIF;
4887 DirectiveKindMap[
".skip"] = DK_SKIP;
4888 DirectiveKindMap[
".space"] = DK_SPACE;
4889 DirectiveKindMap[
".file"] = DK_FILE;
4890 DirectiveKindMap[
".line"] = DK_LINE;
4891 DirectiveKindMap[
".loc"] = DK_LOC;
4892 DirectiveKindMap[
".stabs"] = DK_STABS;
4893 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
4894 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
4895 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
4896 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
4897 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
4898 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
4899 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
4900 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
4901 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
4902 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
4903 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
4904 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
4905 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
4906 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
4907 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
4908 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
4909 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
4910 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
4911 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
4912 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
4913 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
4914 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
4915 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
4916 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
4917 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
4918 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
4919 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
4920 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
4921 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
4922 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
4923 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
4924 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
4925 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
4926 DirectiveKindMap[
".macro"] = DK_MACRO;
4927 DirectiveKindMap[
".exitm"] = DK_EXITM;
4928 DirectiveKindMap[
".endm"] = DK_ENDM;
4929 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
4930 DirectiveKindMap[
".purgem"] = DK_PURGEM;
4931 DirectiveKindMap[
".err"] = DK_ERR;
4932 DirectiveKindMap[
".error"] = DK_ERROR;
4933 DirectiveKindMap[
".warning"] = DK_WARNING;
4934 DirectiveKindMap[
".reloc"] = DK_RELOC;
4935 DirectiveKindMap[
".dc"] = DK_DC;
4936 DirectiveKindMap[
".dc.a"] = DK_DC_A;
4937 DirectiveKindMap[
".dc.b"] = DK_DC_B;
4938 DirectiveKindMap[
".dc.d"] = DK_DC_D;
4939 DirectiveKindMap[
".dc.l"] = DK_DC_L;
4940 DirectiveKindMap[
".dc.s"] = DK_DC_S;
4941 DirectiveKindMap[
".dc.w"] = DK_DC_W;
4942 DirectiveKindMap[
".dc.x"] = DK_DC_X;
4943 DirectiveKindMap[
".dcb"] = DK_DCB;
4944 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
4945 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
4946 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
4947 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
4948 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
4949 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
4950 DirectiveKindMap[
".ds"] = DK_DS;
4951 DirectiveKindMap[
".ds.b"] = DK_DS_B;
4952 DirectiveKindMap[
".ds.d"] = DK_DS_D;
4953 DirectiveKindMap[
".ds.l"] = DK_DS_L;
4954 DirectiveKindMap[
".ds.p"] = DK_DS_P;
4955 DirectiveKindMap[
".ds.s"] = DK_DS_S;
4956 DirectiveKindMap[
".ds.w"] = DK_DS_W;
4957 DirectiveKindMap[
".ds.x"] = DK_DS_X;
4960 MCAsmMacro *AsmParser::parseMacroLikeBody(
SMLoc DirectiveLoc) {
4961 AsmToken EndToken, StartToken = getTok();
4963 unsigned NestLevel = 0;
4967 printError(DirectiveLoc,
"no matching '.endr' in definition");
4971 if (Lexer.is(AsmToken::Identifier) &&
4972 (getTok().getIdentifier() ==
".rept" ||
4973 getTok().getIdentifier() ==
".irp" ||
4974 getTok().getIdentifier() ==
".irpc")) {
4979 if (Lexer.is(AsmToken::Identifier) && getTok().getIdentifier() ==
".endr") {
4980 if (NestLevel == 0) {
4981 EndToken = getTok();
4983 if (Lexer.isNot(AsmToken::EndOfStatement)) {
4984 printError(getTok().getLoc(),
4985 "unexpected token in '.endr' directive");
4994 eatToEndOfStatement();
5002 MacroLikeBodies.emplace_back(
StringRef(), Body, MCAsmMacroParameters());
5003 return &MacroLikeBodies.back();
5006 void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
5010 std::unique_ptr<MemoryBuffer> Instantiation =
5011 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
5015 MacroInstantiation *MI =
new MacroInstantiation(
5016 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
5017 ActiveMacros.push_back(MI);
5027 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
5029 SMLoc CountLoc = getTok().getLoc();
5030 if (parseExpression(CountExpr))
5034 if (!CountExpr->evaluateAsAbsolute(Count)) {
5035 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5038 if (check(Count < 0, CountLoc,
"Count is negative") ||
5039 parseToken(AsmToken::EndOfStatement,
5040 "unexpected token in '" + Dir +
"' directive"))
5044 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5054 if (expandMacro(OS, M->Body,
None,
None,
false, getTok().getLoc()))
5057 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5064 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
5065 MCAsmMacroParameter Parameter;
5066 MCAsmMacroArguments
A;
5067 if (check(parseIdentifier(Parameter.Name),
5068 "expected identifier in '.irp' directive") ||
5069 parseToken(AsmToken::Comma,
"expected comma in '.irp' directive") ||
5070 parseMacroArguments(
nullptr, A) ||
5071 parseToken(AsmToken::EndOfStatement,
"expected End of Statement"))
5075 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5084 for (
const MCAsmMacroArgument &Arg : A) {
5087 if (expandMacro(OS, M->Body, Parameter, Arg,
true, getTok().getLoc()))
5091 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5098 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
5099 MCAsmMacroParameter Parameter;
5100 MCAsmMacroArguments
A;
5102 if (check(parseIdentifier(Parameter.Name),
5103 "expected identifier in '.irpc' directive") ||
5104 parseToken(AsmToken::Comma,
"expected comma in '.irpc' directive") ||
5105 parseMacroArguments(
nullptr, A))
5108 if (A.size() != 1 || A.front().size() != 1)
5109 return TokError(
"unexpected token in '.irpc' directive");
5112 if (parseToken(AsmToken::EndOfStatement,
"expected end of statement"))
5116 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5126 for (std::size_t I = 0, End = Values.
size(); I !=
End; ++
I) {
5127 MCAsmMacroArgument Arg;
5128 Arg.emplace_back(AsmToken::Identifier, Values.
slice(I, I + 1));
5132 if (expandMacro(OS, M->Body, Parameter, Arg,
true, getTok().getLoc()))
5136 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5141 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
5142 if (ActiveMacros.empty())
5143 return TokError(
"unmatched '.endr' directive");
5147 assert(getLexer().is(AsmToken::EndOfStatement));
5153 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
5156 SMLoc ExprLoc = getLexer().getLoc();
5157 if (parseExpression(Value))
5161 return Error(ExprLoc,
"unexpected expression in _emit");
5162 uint64_t IntValue = MCE->
getValue();
5164 return Error(ExprLoc,
"literal value out of range for directive");
5166 Info.AsmRewrites->emplace_back(
AOK_Emit, IDLoc, Len);
5170 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
5172 SMLoc ExprLoc = getLexer().getLoc();
5173 if (parseExpression(Value))
5177 return Error(ExprLoc,
"unexpected expression in align");
5178 uint64_t IntValue = MCE->
getValue();
5180 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5209 bool AsmParser::parseMSInlineAsm(
5210 void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs,
5211 unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool> > &OpDecls,
5229 unsigned InputIdx = 0;
5230 unsigned OutputIdx = 0;
5233 if (parseCurlyBlockScope(AsmStrRewrites))
5236 ParseStatementInfo Info(&AsmStrRewrites);
5237 bool StatementErr = parseStatement(Info, &SI);
5239 if (StatementErr || Info.ParseError) {
5241 printPendingErrors();
5246 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5248 if (Info.Opcode == ~0U)
5254 for (
unsigned i = 1, e = Info.ParsedOperands.size();
i != e; ++
i) {
5258 if (Operand.
isImm())
5263 !getTargetParser().OmitRegisterFromClobberLists(Operand.
getReg())) {
5273 if (SymName.
empty())
5280 bool isOutput = (
i == 1) && Desc.
mayStore();
5281 SMLoc Start = SMLoc::getFromPointer(SymName.
data());
5299 ClobberRegs.
insert(ClobberRegs.
end(), ImpDefs.begin(), ImpDefs.end());
5303 NumOutputs = OutputDecls.
size();
5304 NumInputs = InputDecls.
size();
5308 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
5310 Clobbers.
assign(ClobberRegs.
size(), std::string());
5311 for (
unsigned I = 0, E = ClobberRegs.
size(); I !=
E; ++
I) {
5317 if (NumOutputs || NumInputs) {
5318 unsigned NumExprs = NumOutputs + NumInputs;
5319 OpDecls.resize(NumExprs);
5320 Constraints.
resize(NumExprs);
5321 for (
unsigned i = 0;
i < NumOutputs; ++
i) {
5322 OpDecls[
i] = std::make_pair(OutputDecls[
i], OutputDeclsAddressOf[i]);
5323 Constraints[
i] = OutputConstraints[
i];
5325 for (
unsigned i = 0, j = NumOutputs;
i < NumInputs; ++
i, ++j) {
5326 OpDecls[j] = std::make_pair(InputDecls[
i], InputDeclsAddressOf[i]);
5327 Constraints[j] = InputConstraints[
i];
5332 std::string AsmStringIR;
5336 const char *AsmStart = ASMString.
begin();
5337 const char *AsmEnd = ASMString.
end();
5339 for (
const AsmRewrite &AR : AsmStrRewrites) {
5345 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
5348 if (
unsigned Len = Loc - AsmStart)
5353 AsmStart = Loc + AR.Len;
5357 unsigned AdditionalSkip = 0;
5363 OS <<
"$$" << AR.Val;
5372 OS <<
'$' << InputIdx++;
5375 OS <<
'$' << OutputIdx++;
5380 case 8: OS <<
"byte ptr ";
break;
5381 case 16: OS <<
"word ptr ";
break;
5382 case 32: OS <<
"dword ptr ";
break;
5383 case 64: OS <<
"qword ptr ";
break;
5384 case 80: OS <<
"xword ptr ";
break;
5385 case 128: OS <<
"xmmword ptr ";
break;
5386 case 256: OS <<
"ymmword ptr ";
break;
5396 if (getContext().getAsmInfo()->getAlignmentIsInBytes())
5401 unsigned Val = AR.Val;
5403 assert(Val < 10 &&
"Expected alignment less then 2^10.");
5404 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
5413 if (AsmStringIR.back() !=
'.')
5423 AsmStart = Loc + AR.Len + AdditionalSkip;
5427 if (AsmStart != AsmEnd)
5428 OS <<
StringRef(AsmStart, AsmEnd - AsmStart);
5430 AsmString = OS.
str();
5435 namespace MCParserUtils {
5458 Sym, static_cast<const MCUnaryExpr *>(Value)->getSubExpr());
5472 return Parser.
TokError(
"missing expression");
5491 return Parser.
Error(EqualLoc,
"Recursive use of '" + Name +
"'");
5498 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
5500 return Parser.
Error(EqualLoc,
"invalid assignment to '" + Name +
"'");
5502 return Parser.
Error(EqualLoc,
5503 "invalid reassignment of non-absolute variable '" +
5505 }
else if (Name ==
".") {
5522 return new AsmParser(SM, C, Out, MAI);
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
constexpr bool isUInt< 32 >(uint64_t x)
Represents a range in source code.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void push_back(const T &Elt)
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
const MCAsmInfo * getAsmInfo() const
LLVM_NODISCARD int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
const ValueTy & getValue() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual ~MCAsmParserSemaCallback()
LLVM Argument representation.
uint64_t getZExtValue() const
Get zero extended value.
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
bool doesAllowAtInName() const
const MCSymbol & getSymbol() const
#define DWARF2_FLAG_PROLOGUE_END
const char * getPointer() const
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.
This represents an "assembler immediate".
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void redefineIfPossible()
Prepare this symbol to be redefined.
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
unsigned getNumImplicitDefs() const
Return the number of implicit defs this instruct has.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
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...
bool mayStore() const
Return true if this instruction could possibly modify memory.
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
void * getDiagContext() const
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
MCAsmParserExtension * createDarwinAsmParser()
constexpr bool isInt< 8 >(int64_t x)
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
StringRef getBuffer() const
A raw_ostream that writes to an SmallVector or SmallString.
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
MCAsmParserExtension * createELFAsmParser()
unsigned getMainFileID() const
static bool isIdentifierChar(char c)
AsmLexer - Lexer class for assembly files.
#define DWARF2_FLAG_IS_STMT
struct fuzzer::@269 Flags
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Generic assembler lexer interface, for use by target specific assembly lexers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
StringRef getLineContents() const
Target independent representation for an assembler token.
Represent a reference to a symbol from inside an expression.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
AsmCond - Class to support conditional assembly.
virtual StringRef getSymName()
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
This file implements a class to represent arbitrary precision integral constant values and operations...
bool isLittleEndian() const
True if the target is little endian.
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
void assign(size_type NumElts, const T &Elt)
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Context object for machine code objects.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
bool isIntN(unsigned N, const APInt &APIVal)
Check if the specified APInt has a N-bits unsigned integer value.
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *Value)
Returns whether the given symbol is used anywhere in the given expression, or subexpressions.
Environment getObjectFileType() const
static unsigned getGNUBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
Unary assembler expressions.
static bool isOperator(AsmToken::TokenKind kind)
StringRef getMessage() const
Function Alias Analysis false
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
const MCPhysReg * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
virtual void * getOpDecl()
LLVM_NODISCARD char front() const
front - Get the first character in the string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
StringRef getConstraint()
const AsmToken & getTok() const
Get the current AsmToken from the stream.
size_t size() const
size - Get the array size.
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
virtual void printRegName(raw_ostream &OS, unsigned RegNo) const
Print the assembler register name.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Flag
These should be considered private to the implementation of the MCInstrDesc class.
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
bool isUsed() const
isUsed - Check if this is used.
virtual MCContext & getContext()=0
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
initializer< Ty > init(const Ty &Val)
Streaming machine code generation interface.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
constexpr bool isUInt< 8 >(uint64_t x)
.weak_def_can_be_hidden (MachO)
void setRedefinable(bool Value)
Mark this symbol as redefinable.
#define DWARF2_FLAG_EPILOGUE_BEGIN
static cl::opt< unsigned > AsmMacroMaxNestingDepth("asm-macro-max-nesting-depth", cl::init(20), cl::Hidden, cl::desc("The maximum nesting depth allowed for assembly macros."))
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
bool shouldUseLogicalShr() const
void(* DiagHandlerTy)(const SMDiagnostic &, void *Context)
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Interface to description of machine instruction set.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
constexpr bool isPowerOf2_64(uint64_t Value)
isPowerOf2_64 - This function returns true if the argument is a power of two 0 (64 bit edition...
This file declares a class to represent arbitrary precision floating point values and provide a varie...
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &)
Create an MCAsmParser instance.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static const unsigned End
Generic Sema callback for assembly parser.
#define DWARF2_FLAG_BASIC_BLOCK
bool Error(SMLoc L, const Twine &Msg, SMRange Range=None)
Return an error at the location L, with the message Msg.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
void Finish()
Finish emission of machine code.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
virtual unsigned getReg() const =0
virtual bool UseCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
iterator erase(const_iterator CI)
MCAsmParserExtension * createCOFFAsmParser()
Binary assembler expressions.
static bool isValidEncoding(int64_t Encoding)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
const T & back() const
back - Get the last element.
StringRef getPrivateLabelPrefix() const
virtual void InitSections(bool NoExecStack)
Create the default sections and set the initial one.
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
SourceMgr::DiagKind getKind() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static const char * Target
Promote Memory to Register
INITIALIZE_PASS(HexagonGenMux,"hexagon-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
MCSymbol * getBeginSymbol()
SMLoc getParentIncludeLoc(unsigned i) const
StringRef str()
Return a StringRef for the vector contents.
bool is(TokenKind K) const
bool isDefined(bool SetUsed=true) const
isDefined - Check if this symbol is defined (i.e., it has an address).
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Class for arbitrary precision integers.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Base class for user error types.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
iterator insert(iterator I, T &&Elt)
#define DWARF2_LINE_DEFAULT_IS_STMT
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
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...
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
const MCExpr * getSubExpr() const
Get the child of this unary expression.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
void emplace_back(ArgTypes &&...Args)
StringRef getName() const
getName - Get the symbol name.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
virtual bool isImm() const =0
isImm - Is this an immediate operand?
virtual StringRef LookupInlineAsmLabel(StringRef Identifier, SourceMgr &SM, SMLoc Location, bool Create)=0
Opcode getOpcode() const
Get the kind of this binary expression.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
References to labels and assigned expressions.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isVariable() const
isVariable - Check if this is a variable symbol.
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
VariantKind getKind() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool TokError(const Twine &Msg, SMRange Range=None)
Report an error at the current lexer location.
A raw_ostream that writes to an std::string.
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
const char AsmRewritePrecedence[]
LLVM Value Representation.
bool useParensForSymbolVariant() const
const MCObjectFileInfo * getObjectFileInfo() const
bool hasSubsectionsViaSymbols() const
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
std::string Hash(const Unit &U)
unsigned getMCOperandNum()
StringRef - Represent a constant reference to a string, i.e.
const SourceMgr * getSourceMgr() const
Target specific expression.
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label? Only valid when par...
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind, bool ShouldUseLogicalShr)
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Represents a location in source code.
static void Split(std::vector< std::string > &V, StringRef S)
Split - Splits a string of comma separated items in to a vector of strings.
bool isUIntN(unsigned N, uint64_t x)
isUIntN - Checks if an unsigned integer fits into the given (dynamic) bit width.
static uint64_t getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI)
DiagHandlerTy getDiagHandler() const
ConditionalAssemblyType TheCond
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
unsigned Log2_64(uint64_t Value)
Log2_64 - This function returns the floor log base 2 of the specified value, -1 if the value is zero...
LLVM_NODISCARD std::string lower() const
virtual bool isReg() const =0
isReg - Is this a register operand?
Opcode getOpcode() const
Get the kind of this unary expression.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
void setBeginSymbol(MCSymbol *Sym)
Holds state from .cv_file and .cv_loc directives for later emission.