77 cl::desc(
"The maximum nesting depth allowed for assembly macros."));
82 typedef std::vector<AsmToken> MCAsmMacroArgument;
83 typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
85 struct MCAsmMacroParameter {
87 MCAsmMacroArgument
Value;
91 MCAsmMacroParameter() =
default;
94 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
99 MCAsmMacroParameters Parameters;
103 :
Name(N), Body(B), Parameters(std::move(P)) {}
108 struct MacroInstantiation {
110 SMLoc InstantiationLoc;
119 size_t CondStackDepth;
122 MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
size_t CondStackDepth);
125 struct ParseStatementInfo {
130 unsigned Opcode = ~0U;
133 bool ParseError =
false;
137 ParseStatementInfo() =
delete;
139 : AsmRewrites(rewrites) {}
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 = ~0U;
205 bool IsDarwin =
false;
208 bool ParsingInlineAsm =
false;
213 AsmParser(
const AsmParser &) =
delete;
214 AsmParser &operator=(
const AsmParser &) =
delete;
215 ~AsmParser()
override;
217 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
219 void addDirectiveHandler(
StringRef Directive,
220 ExtensionDirectiveHandler Handler)
override {
221 ExtensionDirectiveMap[Directive] = Handler;
225 DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
232 MCAsmLexer &getLexer()
override {
return Lexer; }
233 MCContext &getContext()
override {
return Ctx; }
234 MCStreamer &getStreamer()
override {
return Out; }
238 unsigned getAssemblerDialect()
override {
239 if (AssemblerDialect == ~0U)
240 return MAI.getAssemblerDialect();
242 return AssemblerDialect;
244 void setAssemblerDialect(
unsigned i)
override {
245 AssemblerDialect = i;
254 void setParsingInlineAsm(
bool V)
override {
255 ParsingInlineAsm = V;
256 Lexer.setParsingMSInlineAsm(V);
258 bool isParsingInlineAsm()
override {
return ParsingInlineAsm; }
260 bool parseMSInlineAsm(
void *AsmLoc, std::string &AsmString,
261 unsigned &NumOutputs,
unsigned &NumInputs,
268 bool parseExpression(
const MCExpr *&Res);
269 bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
270 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
271 bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
272 bool parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
273 SMLoc &EndLoc)
override;
274 bool parseAbsoluteExpression(int64_t &Res)
override;
282 bool parseIdentifier(
StringRef &Res)
override;
283 void eatToEndOfStatement()
override;
285 bool checkForValidSection()
override;
290 bool isAltmacroString(
SMLoc &StrLoc,
SMLoc &EndLoc);
291 void altMacroString(
StringRef AltMacroStr, std::string &Res);
292 bool parseStatement(ParseStatementInfo &Info,
295 bool parseCppHashLineFilenameComment(
SMLoc L);
305 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
308 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
322 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
328 bool handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc);
331 void handleMacroExit();
334 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
337 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
339 void printMacroInstantiations();
348 bool enterIncludeFile(
const std::string &Filename);
352 bool processIncbinFile(
const std::string &Filename, int64_t Skip = 0,
361 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
366 StringRef parseStringToEndOfStatement()
override;
373 bool NoDeadStrip =
false);
378 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
379 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
380 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
382 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
384 bool parseCVFunctionId(int64_t &FunctionId,
StringRef DirectiveName);
385 bool parseCVFileId(int64_t &FileId,
StringRef DirectiveName);
390 DK_SET, DK_EQU, DK_EQUIV, DK_ASCII, DK_ASCIZ, DK_STRING, DK_BYTE, DK_SHORT,
392 DK_VALUE, DK_2BYTE, DK_LONG, DK_INT, DK_4BYTE, DK_QUAD, DK_8BYTE, DK_OCTA,
393 DK_DC, DK_DC_A, DK_DC_B, DK_DC_D, DK_DC_L, DK_DC_S, DK_DC_W, DK_DC_X,
394 DK_DCB, DK_DCB_B, DK_DCB_D, DK_DCB_L, DK_DCB_S, DK_DCB_W, DK_DCB_X,
395 DK_DS, DK_DS_B, DK_DS_D, DK_DS_L, DK_DS_P, DK_DS_S, DK_DS_W, DK_DS_X,
396 DK_SINGLE, DK_FLOAT, DK_DOUBLE, DK_ALIGN, DK_ALIGN32, DK_BALIGN, DK_BALIGNW,
397 DK_BALIGNL, DK_P2ALIGN, DK_P2ALIGNW, DK_P2ALIGNL, DK_ORG, DK_FILL, DK_ENDR,
398 DK_BUNDLE_ALIGN_MODE, DK_BUNDLE_LOCK, DK_BUNDLE_UNLOCK,
399 DK_ZERO, DK_EXTERN, DK_GLOBL, DK_GLOBAL,
400 DK_LAZY_REFERENCE, DK_NO_DEAD_STRIP, DK_SYMBOL_RESOLVER,
401 DK_PRIVATE_EXTERN, DK_REFERENCE, DK_WEAK_DEFINITION, DK_WEAK_REFERENCE,
402 DK_WEAK_DEF_CAN_BE_HIDDEN, DK_COMM, DK_COMMON, DK_LCOMM, DK_ABORT,
403 DK_INCLUDE, DK_INCBIN, DK_CODE16, DK_CODE16GCC, DK_REPT, DK_IRP, DK_IRPC,
404 DK_IF, DK_IFEQ, DK_IFGE, DK_IFGT, DK_IFLE, DK_IFLT, DK_IFNE, DK_IFB,
405 DK_IFNB, DK_IFC, DK_IFEQS, DK_IFNC, DK_IFNES, DK_IFDEF, DK_IFNDEF,
406 DK_IFNOTDEF, DK_ELSEIF, DK_ELSE, DK_ENDIF,
407 DK_SPACE, DK_SKIP, DK_FILE, DK_LINE, DK_LOC, DK_STABS,
408 DK_CV_FILE, DK_CV_FUNC_ID, DK_CV_INLINE_SITE_ID, DK_CV_LOC, DK_CV_LINETABLE,
409 DK_CV_INLINE_LINETABLE, DK_CV_DEF_RANGE, DK_CV_STRINGTABLE,
411 DK_CFI_SECTIONS, DK_CFI_STARTPROC, DK_CFI_ENDPROC, DK_CFI_DEF_CFA,
412 DK_CFI_DEF_CFA_OFFSET, DK_CFI_ADJUST_CFA_OFFSET, DK_CFI_DEF_CFA_REGISTER,
413 DK_CFI_OFFSET, DK_CFI_REL_OFFSET, DK_CFI_PERSONALITY, DK_CFI_LSDA,
414 DK_CFI_REMEMBER_STATE, DK_CFI_RESTORE_STATE, DK_CFI_SAME_VALUE,
415 DK_CFI_RESTORE, DK_CFI_ESCAPE, DK_CFI_SIGNAL_FRAME, DK_CFI_UNDEFINED,
416 DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE,
417 DK_MACROS_ON, DK_MACROS_OFF, DK_ALTMACRO, DK_NOALTMACRO,
418 DK_MACRO, DK_EXITM, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
419 DK_SLEB128, DK_ULEB128,
420 DK_ERR, DK_ERROR, DK_WARNING,
429 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
430 bool parseDirectiveReloc(
SMLoc DirectiveLoc);
431 bool parseDirectiveValue(
StringRef IDVal,
433 bool parseDirectiveOctaValue(
StringRef IDVal);
434 bool parseDirectiveRealValue(
StringRef IDVal,
436 bool parseDirectiveFill();
437 bool parseDirectiveZero();
439 bool parseDirectiveSet(
StringRef IDVal,
bool allow_redef);
440 bool parseDirectiveOrg();
442 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
445 bool parseDirectiveFile(
SMLoc DirectiveLoc);
446 bool parseDirectiveLine();
447 bool parseDirectiveLoc();
448 bool parseDirectiveStabs();
452 bool parseDirectiveCVFile();
453 bool parseDirectiveCVFuncId();
454 bool parseDirectiveCVInlineSiteId();
455 bool parseDirectiveCVLoc();
456 bool parseDirectiveCVLinetable();
457 bool parseDirectiveCVInlineLinetable();
458 bool parseDirectiveCVDefRange();
459 bool parseDirectiveCVStringTable();
460 bool parseDirectiveCVFileChecksums();
463 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
464 bool parseDirectiveCFIWindowSave();
465 bool parseDirectiveCFISections();
466 bool parseDirectiveCFIStartProc();
467 bool parseDirectiveCFIEndProc();
468 bool parseDirectiveCFIDefCfaOffset();
469 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
470 bool parseDirectiveCFIAdjustCfaOffset();
471 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
472 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
473 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
474 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
475 bool parseDirectiveCFIRememberState();
476 bool parseDirectiveCFIRestoreState();
477 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
478 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
479 bool parseDirectiveCFIEscape();
480 bool parseDirectiveCFISignalFrame();
481 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
484 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
485 bool parseDirectiveExitMacro(
StringRef Directive);
486 bool parseDirectiveEndMacro(
StringRef Directive);
487 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
488 bool parseDirectiveMacrosOnOff(
StringRef Directive);
490 bool parseDirectiveAltmacro(
StringRef Directive);
492 bool parseDirectiveBundleAlignMode();
494 bool parseDirectiveBundleLock();
496 bool parseDirectiveBundleUnlock();
499 bool parseDirectiveSpace(
StringRef IDVal);
508 bool parseDirectiveLEB128(
bool Signed);
514 bool parseDirectiveComm(
bool IsLocal);
516 bool parseDirectiveAbort();
517 bool parseDirectiveInclude();
518 bool parseDirectiveIncbin();
521 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
523 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
525 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
527 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
529 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
530 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
531 bool parseDirectiveElse(
SMLoc DirectiveLoc);
532 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
533 bool parseEscapedString(std::string &
Data)
override;
539 MCAsmMacro *parseMacroLikeBody(
SMLoc DirectiveLoc);
540 void instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
543 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
544 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
545 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
548 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &Info,
552 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &Info);
555 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
558 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
561 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
563 void initializeDirectiveKindMap();
580 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
581 CurBuffer(CB ? CB : SM.getMainFileID()), MacrosEnabledFlag(
true) {
592 case MCObjectFileInfo::IsCOFF:
595 case MCObjectFileInfo::IsMachO:
599 case MCObjectFileInfo::IsELF:
602 case MCObjectFileInfo::IsWasm:
607 PlatformParser->Initialize(*
this);
608 initializeDirectiveKindMap();
610 NumOfMacroInstantiations = 0;
613 AsmParser::~AsmParser() {
614 assert((HadError || ActiveMacros.empty()) &&
615 "Unexpected active macro instantiation!");
622 void AsmParser::printMacroInstantiations() {
624 for (std::vector<MacroInstantiation *>::const_reverse_iterator
625 it = ActiveMacros.rbegin(),
626 ie = ActiveMacros.rend();
628 printMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
629 "while in macro instantiation");
633 printPendingErrors();
634 printMessage(L, SourceMgr::DK_Note, Msg, Range);
635 printMacroInstantiations();
639 if(getTargetParser().getTargetOptions().MCNoWarn)
641 if (getTargetParser().getTargetOptions().MCFatalWarnings)
642 return Error(L, Msg, Range);
643 printMessage(L, SourceMgr::DK_Warning, Msg, Range);
644 printMacroInstantiations();
650 printMessage(L, SourceMgr::DK_Error, Msg, Range);
651 printMacroInstantiations();
655 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
656 std::string IncludedFile;
670 bool AsmParser::processIncbinFile(
const std::string &Filename, int64_t Skip,
672 std::string IncludedFile;
683 if (!Count->evaluateAsAbsolute(Res))
684 return Error(Loc,
"expected absolute expression");
686 return Warning(Loc,
"negative count has no effect");
689 getStreamer().EmitBytes(Bytes);
693 void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
701 Error(Lexer.getErrLoc(), Lexer.getErr());
704 if (getTok().is(AsmToken::EndOfStatement)) {
706 if (!getTok().getString().empty() && getTok().getString().front() !=
'\n' &&
714 while (tok->
is(AsmToken::Comment)) {
724 if (ParentIncludeLoc !=
SMLoc()) {
725 jumpToLoc(ParentIncludeLoc);
733 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
735 if (!NoInitialTextSection)
742 AsmCond StartingCondState = TheCondState;
747 if (getContext().getGenDwarfForAssembly()) {
748 MCSection *Sec = getStreamer().getCurrentSectionOnly();
750 MCSymbol *SectionStartSym = getContext().createTempSymbol();
751 getStreamer().EmitLabel(SectionStartSym);
754 bool InsertResult = getContext().addGenDwarfSection(Sec);
755 assert(InsertResult &&
".text section should not have debug info yet");
757 getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
758 0,
StringRef(), getContext().getMainFileName()));
763 ParseStatementInfo Info(&AsmStrRewrites);
764 if (!parseStatement(Info,
nullptr))
775 printPendingErrors();
778 if (!getLexer().isAtStartOfStatement())
779 eatToEndOfStatement();
783 assert(!hasPendingError() &&
"unexpected error from parseStatement");
785 getTargetParser().flushPendingInstructions(getStreamer());
787 if (TheCondState.TheCond != StartingCondState.
TheCond ||
788 TheCondState.Ignore != StartingCondState.
Ignore)
789 printError(getTok().getLoc(),
"unmatched .ifs or .elses");
791 const auto &LineTables = getContext().getMCDwarfLineTables();
792 if (!LineTables.empty()) {
794 for (
const auto &
File : LineTables.begin()->second.getMCDwarfFiles()) {
795 if (
File.Name.empty() && Index != 0)
796 printError(getTok().getLoc(),
"unassigned file number: " +
798 " for .file directives");
809 for (
const auto &TableEntry : getContext().getSymbols()) {
810 MCSymbol *Sym = TableEntry.getValue();
818 printError(getTok().getLoc(),
"assembler local symbol '" +
819 Sym->
getName() +
"' not defined");
825 for (std::tuple<SMLoc, CppHashInfoTy, MCSymbol *> &LocSym : DirLabels) {
826 if (std::get<2>(LocSym)->isUndefined()) {
829 CppHashInfo = std::get<1>(LocSym);
830 printError(std::get<0>(LocSym),
"directional label undefined");
837 if (!HadError && !NoFinalize)
840 return HadError || getContext().hadError();
843 bool AsmParser::checkForValidSection() {
844 if (!ParsingInlineAsm && !getStreamer().getCurrentSectionOnly()) {
846 return Error(getTok().getLoc(),
847 "expected section directive before assembly directive");
853 void AsmParser::eatToEndOfStatement() {
854 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
858 if (Lexer.is(AsmToken::EndOfStatement))
862 StringRef AsmParser::parseStringToEndOfStatement() {
863 const char *Start = getTok().getLoc().getPointer();
865 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
868 const char *
End = getTok().getLoc().getPointer();
872 StringRef AsmParser::parseStringToComma() {
873 const char *Start = getTok().getLoc().getPointer();
875 while (Lexer.isNot(AsmToken::EndOfStatement) &&
879 const char *End = getTok().getLoc().getPointer();
888 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
889 if (parseExpression(Res))
891 if (Lexer.isNot(AsmToken::RParen))
892 return TokError(
"expected ')' in parentheses expression");
893 EndLoc = Lexer.getTok().getEndLoc();
903 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
904 if (parseExpression(Res))
906 EndLoc = getTok().getEndLoc();
907 if (parseToken(AsmToken::RBrac,
"expected ']' in brackets expression"))
918 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
919 SMLoc FirstTokenLoc = getLexer().getLoc();
921 switch (FirstTokenKind) {
923 return TokError(
"unknown token in expression");
927 case AsmToken::Exclaim:
929 if (parsePrimaryExpr(Res, EndLoc))
931 Res = MCUnaryExpr::createLNot(Res, getContext(), FirstTokenLoc);
933 case AsmToken::Dollar:
938 if (parseIdentifier(Identifier)) {
940 if (getTok().is(AsmToken::Dollar)) {
941 if (Lexer.getMAI().getDollarIsPC()) {
947 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None,
949 EndLoc = FirstTokenLoc;
952 return Error(FirstTokenLoc,
"invalid token in expression");
956 std::pair<StringRef, StringRef>
Split;
959 if (Lexer.is(AsmToken::At)) {
961 SMLoc AtLoc = getLexer().getLoc();
963 if (parseIdentifier(VName))
964 return Error(AtLoc,
"expected symbol variant after '@'");
966 Split = std::make_pair(Identifier, VName);
969 Split = Identifier.
split(
'@');
971 }
else if (Lexer.is(AsmToken::LParen)) {
974 parseIdentifier(VName);
976 if (parseToken(AsmToken::RParen,
977 "unexpected token in variant, expected ')'"))
979 Split = std::make_pair(Identifier, VName);
982 EndLoc = SMLoc::getFromPointer(Identifier.
end());
986 if (SymbolName.empty())
992 if (!Split.second.empty()) {
993 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
994 if (Variant != MCSymbolRefExpr::VK_Invalid) {
995 SymbolName = Split.first;
997 Variant = MCSymbolRefExpr::VK_None;
999 return Error(SMLoc::getFromPointer(Split.second.begin()),
1000 "invalid variant '" + Split.second +
"'");
1004 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
1011 return Error(EndLoc,
"unexpected modifier on variable reference");
1018 Res = MCSymbolRefExpr::create(Sym, Variant, getContext(), FirstTokenLoc);
1021 case AsmToken::BigNum:
1022 return TokError(
"literal value out of range for directive");
1023 case AsmToken::Integer: {
1024 SMLoc Loc = getTok().getLoc();
1025 int64_t
IntVal = getTok().getIntVal();
1026 Res = MCConstantExpr::create(IntVal, getContext());
1027 EndLoc = Lexer.getTok().getEndLoc();
1033 std::pair<StringRef, StringRef> Split = IDVal.
split(
'@');
1035 if (Split.first.size() != IDVal.
size()) {
1036 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
1037 if (Variant == MCSymbolRefExpr::VK_Invalid)
1038 return TokError(
"invalid variant '" + Split.second +
"'");
1039 IDVal = Split.first;
1041 if (IDVal ==
"f" || IDVal ==
"b") {
1044 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
1046 return Error(Loc,
"directional label undefined");
1047 DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
1048 EndLoc = Lexer.getTok().getEndLoc();
1054 case AsmToken::Real: {
1055 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
1056 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
1057 Res = MCConstantExpr::create(IntVal, getContext());
1058 EndLoc = Lexer.getTok().getEndLoc();
1062 case AsmToken::Dot: {
1067 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
1068 EndLoc = Lexer.getTok().getEndLoc();
1072 case AsmToken::LParen:
1074 return parseParenExpr(Res, EndLoc);
1075 case AsmToken::LBrac:
1076 if (!PlatformParser->HasBracketExpressions())
1077 return TokError(
"brackets expression not supported on this target");
1079 return parseBracketExpr(Res, EndLoc);
1080 case AsmToken::Minus:
1082 if (parsePrimaryExpr(Res, EndLoc))
1084 Res = MCUnaryExpr::createMinus(Res, getContext(), FirstTokenLoc);
1086 case AsmToken::Plus:
1088 if (parsePrimaryExpr(Res, EndLoc))
1090 Res = MCUnaryExpr::createPlus(Res, getContext(), FirstTokenLoc);
1092 case AsmToken::Tilde:
1094 if (parsePrimaryExpr(Res, EndLoc))
1096 Res = MCUnaryExpr::createNot(Res, getContext(), FirstTokenLoc);
1100 case AsmToken::PercentCall16:
1101 case AsmToken::PercentCall_Hi:
1102 case AsmToken::PercentCall_Lo:
1103 case AsmToken::PercentDtprel_Hi:
1104 case AsmToken::PercentDtprel_Lo:
1105 case AsmToken::PercentGot:
1106 case AsmToken::PercentGot_Disp:
1107 case AsmToken::PercentGot_Hi:
1108 case AsmToken::PercentGot_Lo:
1109 case AsmToken::PercentGot_Ofst:
1110 case AsmToken::PercentGot_Page:
1111 case AsmToken::PercentGottprel:
1112 case AsmToken::PercentGp_Rel:
1113 case AsmToken::PercentHi:
1114 case AsmToken::PercentHigher:
1115 case AsmToken::PercentHighest:
1116 case AsmToken::PercentLo:
1117 case AsmToken::PercentNeg:
1118 case AsmToken::PercentPcrel_Hi:
1119 case AsmToken::PercentPcrel_Lo:
1120 case AsmToken::PercentTlsgd:
1121 case AsmToken::PercentTlsldm:
1122 case AsmToken::PercentTprel_Hi:
1123 case AsmToken::PercentTprel_Lo:
1125 if (Lexer.isNot(AsmToken::LParen))
1126 return TokError(
"expected '(' after operator");
1128 if (parseExpression(Res, EndLoc))
1130 if (Lexer.isNot(AsmToken::RParen))
1131 return TokError(
"expected ')'");
1133 Res = getTargetParser().createTargetUnaryExpr(Res, FirstTokenKind, Ctx);
1138 bool AsmParser::parseExpression(
const MCExpr *&Res) {
1140 return parseExpression(Res, EndLoc);
1144 AsmParser::applyModifierToExpr(
const MCExpr *
E,
1147 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
1157 case MCExpr::SymbolRef: {
1160 if (SRE->
getKind() != MCSymbolRefExpr::VK_None) {
1161 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
1162 "' (already modified)");
1166 return MCSymbolRefExpr::create(&SRE->
getSymbol(), Variant, getContext());
1169 case MCExpr::Unary: {
1174 return MCUnaryExpr::create(UE->
getOpcode(), Sub, getContext());
1177 case MCExpr::Binary: {
1179 const MCExpr *LHS = applyModifierToExpr(BE->
getLHS(), Variant);
1180 const MCExpr *RHS = applyModifierToExpr(BE->
getRHS(), Variant);
1190 return MCBinaryExpr::create(BE->
getOpcode(), LHS, RHS, getContext());
1207 bool AsmParser::isAltmacroString(
SMLoc &StrLoc,
SMLoc &EndLoc) {
1209 "Argument to the function cannot be a NULL value");
1211 while ((*CharPtr !=
'>') && (*CharPtr !=
'\n') &&
1212 (*CharPtr !=
'\r') && (*CharPtr !=
'\0')){
1217 if (*CharPtr ==
'>') {
1225 void AsmParser::altMacroString(
StringRef AltMacroStr,std::string &Res) {
1226 for (
size_t Pos = 0; Pos < AltMacroStr.
size(); Pos++) {
1227 if (AltMacroStr[Pos] ==
'!')
1229 Res += AltMacroStr[Pos];
1243 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1246 if (parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1252 if (Lexer.getKind() == AsmToken::At) {
1256 return TokError(
"unexpected symbol modifier following '@'");
1259 MCSymbolRefExpr::getVariantKindForName(getTok().getIdentifier());
1260 if (Variant == MCSymbolRefExpr::VK_Invalid)
1261 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1263 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1265 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1266 "' (no symbols present)");
1275 if (Res->evaluateAsAbsolute(Value))
1276 Res = MCConstantExpr::create(Value, getContext());
1281 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1283 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1286 bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1288 if (parseParenExpr(Res, EndLoc))
1291 for (; ParenDepth > 0; --ParenDepth) {
1292 if (parseBinOpRHS(1, Res, EndLoc))
1297 if (ParenDepth - 1 > 0) {
1298 EndLoc = getTok().getEndLoc();
1299 if (parseToken(AsmToken::RParen,
1300 "expected ')' in parentheses expression"))
1307 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1310 SMLoc StartLoc = Lexer.getLoc();
1311 if (parseExpression(Expr))
1314 if (!Expr->evaluateAsAbsolute(Res))
1315 return Error(StartLoc,
"expected absolute expression");
1322 bool ShouldUseLogicalShr) {
1328 case AsmToken::AmpAmp:
1329 Kind = MCBinaryExpr::LAnd;
1331 case AsmToken::PipePipe:
1332 Kind = MCBinaryExpr::LOr;
1338 case AsmToken::Pipe:
1339 Kind = MCBinaryExpr::Or;
1341 case AsmToken::Caret:
1342 Kind = MCBinaryExpr::Xor;
1345 Kind = MCBinaryExpr::And;
1349 case AsmToken::EqualEqual:
1352 case AsmToken::ExclaimEqual:
1353 case AsmToken::LessGreater:
1359 case AsmToken::LessEqual:
1360 Kind = MCBinaryExpr::LTE;
1362 case AsmToken::Greater:
1365 case AsmToken::GreaterEqual:
1366 Kind = MCBinaryExpr::GTE;
1370 case AsmToken::LessLess:
1371 Kind = MCBinaryExpr::Shl;
1373 case AsmToken::GreaterGreater:
1374 Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
1378 case AsmToken::Plus:
1381 case AsmToken::Minus:
1382 Kind = MCBinaryExpr::Sub;
1386 case AsmToken::Star:
1387 Kind = MCBinaryExpr::Mul;
1389 case AsmToken::Slash:
1390 Kind = MCBinaryExpr::Div;
1392 case AsmToken::Percent:
1393 Kind = MCBinaryExpr::Mod;
1400 bool ShouldUseLogicalShr) {
1406 case AsmToken::AmpAmp:
1407 Kind = MCBinaryExpr::LAnd;
1409 case AsmToken::PipePipe:
1410 Kind = MCBinaryExpr::LOr;
1414 case AsmToken::EqualEqual:
1417 case AsmToken::ExclaimEqual:
1418 case AsmToken::LessGreater:
1424 case AsmToken::LessEqual:
1425 Kind = MCBinaryExpr::LTE;
1427 case AsmToken::Greater:
1430 case AsmToken::GreaterEqual:
1431 Kind = MCBinaryExpr::GTE;
1435 case AsmToken::Plus:
1438 case AsmToken::Minus:
1439 Kind = MCBinaryExpr::Sub;
1445 case AsmToken::Pipe:
1446 Kind = MCBinaryExpr::Or;
1448 case AsmToken::Caret:
1449 Kind = MCBinaryExpr::Xor;
1452 Kind = MCBinaryExpr::And;
1456 case AsmToken::Star:
1457 Kind = MCBinaryExpr::Mul;
1459 case AsmToken::Slash:
1460 Kind = MCBinaryExpr::Div;
1462 case AsmToken::Percent:
1463 Kind = MCBinaryExpr::Mod;
1465 case AsmToken::LessLess:
1466 Kind = MCBinaryExpr::Shl;
1468 case AsmToken::GreaterGreater:
1469 Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
1483 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1485 SMLoc StartLoc = Lexer.getLoc();
1488 unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(),
Kind);
1492 if (TokPrec < Precedence)
1499 if (parsePrimaryExpr(RHS, EndLoc))
1505 unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(),
Dummy);
1506 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1510 Res = MCBinaryExpr::create(Kind, Res, RHS, getContext(), StartLoc);
1518 bool AsmParser::parseStatement(ParseStatementInfo &Info,
1520 assert(!hasPendingError() &&
"parseStatement started with pending error");
1522 while (Lexer.is(AsmToken::Space))
1524 if (Lexer.is(AsmToken::EndOfStatement)) {
1526 if (getTok().getString().empty() || getTok().getString().front() ==
'\r' ||
1527 getTok().getString().front() ==
'\n')
1537 StringRef CommentStr = parseStringToEndOfStatement();
1539 Lexer.UnLex(
AsmToken(AsmToken::EndOfStatement, CommentStr));
1546 int64_t LocalLabelVal = -1;
1547 if (Lexer.is(AsmToken::HashDirective))
1548 return parseCppHashLineFilenameComment(IDLoc);
1550 if (Lexer.is(AsmToken::Integer)) {
1551 LocalLabelVal = getTok().getIntVal();
1552 if (LocalLabelVal < 0) {
1553 if (!TheCondState.Ignore) {
1555 return Error(IDLoc,
"unexpected token at start of statement");
1559 IDVal = getTok().getString();
1561 if (Lexer.getKind() != AsmToken::Colon) {
1562 if (!TheCondState.Ignore) {
1564 return Error(IDLoc,
"unexpected token at start of statement");
1568 }
else if (Lexer.is(AsmToken::Dot)) {
1572 }
else if (Lexer.is(AsmToken::LCurly)) {
1577 }
else if (Lexer.is(AsmToken::RCurly)) {
1581 }
else if (parseIdentifier(IDVal)) {
1582 if (!TheCondState.Ignore) {
1584 return Error(IDLoc,
"unexpected token at start of statement");
1593 DirectiveKindMap.find(IDVal);
1594 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1596 : DirKindIt->getValue();
1607 return parseDirectiveIf(IDLoc, DirKind);
1609 return parseDirectiveIfb(IDLoc,
true);
1611 return parseDirectiveIfb(IDLoc,
false);
1613 return parseDirectiveIfc(IDLoc,
true);
1615 return parseDirectiveIfeqs(IDLoc,
true);
1617 return parseDirectiveIfc(IDLoc,
false);
1619 return parseDirectiveIfeqs(IDLoc,
false);
1621 return parseDirectiveIfdef(IDLoc,
true);
1624 return parseDirectiveIfdef(IDLoc,
false);
1626 return parseDirectiveElseIf(IDLoc);
1628 return parseDirectiveElse(IDLoc);
1630 return parseDirectiveEndIf(IDLoc);
1635 if (TheCondState.Ignore) {
1636 eatToEndOfStatement();
1643 switch (Lexer.getKind()) {
1644 case AsmToken::Colon: {
1645 if (!getTargetParser().isLabel(ID))
1647 if (checkForValidSection())
1655 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1663 if (LocalLabelVal == -1) {
1664 if (ParsingInlineAsm && SI) {
1668 "We should have an internal name here.");
1669 Info.AsmRewrites->emplace_back(
AOK_Label, IDLoc, IDVal.
size(),
1671 IDVal = RewrittenLabel;
1673 Sym = getContext().getOrCreateSymbol(IDVal);
1681 StringRef CommentStr = parseStringToEndOfStatement();
1683 Lexer.UnLex(
AsmToken(AsmToken::EndOfStatement, CommentStr));
1688 if (getTok().is(AsmToken::EndOfStatement)) {
1693 if (!getTargetParser().isParsingInlineAsm())
1698 if (getContext().getGenDwarfForAssembly())
1699 MCGenDwarfLabelEntry::Make(Sym, &getStreamer(), getSourceManager(),
1702 getTargetParser().onLabelParsed(Sym);
1708 if (!getTargetParser().equalIsAsmAssignment())
1713 return parseAssignment(IDVal,
true);
1720 if (areMacrosEnabled())
1721 if (
const MCAsmMacro *M = lookupMacro(IDVal)) {
1722 return handleMacroEntry(M, IDLoc);
1728 if (IDVal[0] ==
'.' && IDVal !=
".") {
1740 getTargetParser().flushPendingInstructions(getStreamer());
1742 SMLoc StartTokLoc = getTok().getLoc();
1743 bool TPDirectiveReturn = getTargetParser().ParseDirective(ID);
1745 if (hasPendingError())
1752 if (TPDirectiveReturn && StartTokLoc != getTok().getLoc())
1755 if (!TPDirectiveReturn || StartTokLoc != getTok().getLoc())
1760 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1761 ExtensionDirectiveMap.lookup(IDVal);
1763 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1772 return parseDirectiveSet(IDVal,
true);
1774 return parseDirectiveSet(IDVal,
false);
1776 return parseDirectiveAscii(IDVal,
false);
1779 return parseDirectiveAscii(IDVal,
true);
1782 return parseDirectiveValue(IDVal, 1);
1788 return parseDirectiveValue(IDVal, 2);
1793 return parseDirectiveValue(IDVal, 4);
1796 return parseDirectiveValue(IDVal, 8);
1798 return parseDirectiveValue(
1799 IDVal, getContext().getAsmInfo()->getCodePointerSize());
1801 return parseDirectiveOctaValue(IDVal);
1805 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
1808 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
1810 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1811 return parseDirectiveAlign(IsPow2, 1);
1814 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1815 return parseDirectiveAlign(IsPow2, 4);
1818 return parseDirectiveAlign(
false, 1);
1820 return parseDirectiveAlign(
false, 2);
1822 return parseDirectiveAlign(
false, 4);
1824 return parseDirectiveAlign(
true, 1);
1826 return parseDirectiveAlign(
true, 2);
1828 return parseDirectiveAlign(
true, 4);
1830 return parseDirectiveOrg();
1832 return parseDirectiveFill();
1834 return parseDirectiveZero();
1836 eatToEndOfStatement();
1840 return parseDirectiveSymbolAttribute(
MCSA_Global);
1841 case DK_LAZY_REFERENCE:
1843 case DK_NO_DEAD_STRIP:
1845 case DK_SYMBOL_RESOLVER:
1847 case DK_PRIVATE_EXTERN:
1851 case DK_WEAK_DEFINITION:
1853 case DK_WEAK_REFERENCE:
1855 case DK_WEAK_DEF_CAN_BE_HIDDEN:
1859 return parseDirectiveComm(
false);
1861 return parseDirectiveComm(
true);
1863 return parseDirectiveAbort();
1865 return parseDirectiveInclude();
1867 return parseDirectiveIncbin();
1870 return TokError(
Twine(IDVal) +
1871 " not currently supported for this target");
1873 return parseDirectiveRept(IDLoc, IDVal);
1875 return parseDirectiveIrp(IDLoc);
1877 return parseDirectiveIrpc(IDLoc);
1879 return parseDirectiveEndr(IDLoc);
1880 case DK_BUNDLE_ALIGN_MODE:
1881 return parseDirectiveBundleAlignMode();
1882 case DK_BUNDLE_LOCK:
1883 return parseDirectiveBundleLock();
1884 case DK_BUNDLE_UNLOCK:
1885 return parseDirectiveBundleUnlock();
1887 return parseDirectiveLEB128(
true);
1889 return parseDirectiveLEB128(
false);
1892 return parseDirectiveSpace(IDVal);
1894 return parseDirectiveFile(IDLoc);
1896 return parseDirectiveLine();
1898 return parseDirectiveLoc();
1900 return parseDirectiveStabs();
1902 return parseDirectiveCVFile();
1904 return parseDirectiveCVFuncId();
1905 case DK_CV_INLINE_SITE_ID:
1906 return parseDirectiveCVInlineSiteId();
1908 return parseDirectiveCVLoc();
1909 case DK_CV_LINETABLE:
1910 return parseDirectiveCVLinetable();
1911 case DK_CV_INLINE_LINETABLE:
1912 return parseDirectiveCVInlineLinetable();
1913 case DK_CV_DEF_RANGE:
1914 return parseDirectiveCVDefRange();
1915 case DK_CV_STRINGTABLE:
1916 return parseDirectiveCVStringTable();
1917 case DK_CV_FILECHECKSUMS:
1918 return parseDirectiveCVFileChecksums();
1919 case DK_CFI_SECTIONS:
1920 return parseDirectiveCFISections();
1921 case DK_CFI_STARTPROC:
1922 return parseDirectiveCFIStartProc();
1923 case DK_CFI_ENDPROC:
1924 return parseDirectiveCFIEndProc();
1925 case DK_CFI_DEF_CFA:
1926 return parseDirectiveCFIDefCfa(IDLoc);
1927 case DK_CFI_DEF_CFA_OFFSET:
1928 return parseDirectiveCFIDefCfaOffset();
1929 case DK_CFI_ADJUST_CFA_OFFSET:
1930 return parseDirectiveCFIAdjustCfaOffset();
1931 case DK_CFI_DEF_CFA_REGISTER:
1932 return parseDirectiveCFIDefCfaRegister(IDLoc);
1934 return parseDirectiveCFIOffset(IDLoc);
1935 case DK_CFI_REL_OFFSET:
1936 return parseDirectiveCFIRelOffset(IDLoc);
1937 case DK_CFI_PERSONALITY:
1938 return parseDirectiveCFIPersonalityOrLsda(
true);
1940 return parseDirectiveCFIPersonalityOrLsda(
false);
1941 case DK_CFI_REMEMBER_STATE:
1942 return parseDirectiveCFIRememberState();
1943 case DK_CFI_RESTORE_STATE:
1944 return parseDirectiveCFIRestoreState();
1945 case DK_CFI_SAME_VALUE:
1946 return parseDirectiveCFISameValue(IDLoc);
1947 case DK_CFI_RESTORE:
1948 return parseDirectiveCFIRestore(IDLoc);
1950 return parseDirectiveCFIEscape();
1951 case DK_CFI_SIGNAL_FRAME:
1952 return parseDirectiveCFISignalFrame();
1953 case DK_CFI_UNDEFINED:
1954 return parseDirectiveCFIUndefined(IDLoc);
1955 case DK_CFI_REGISTER:
1956 return parseDirectiveCFIRegister(IDLoc);
1957 case DK_CFI_WINDOW_SAVE:
1958 return parseDirectiveCFIWindowSave();
1961 return parseDirectiveMacrosOnOff(IDVal);
1963 return parseDirectiveMacro(IDLoc);
1966 return parseDirectiveAltmacro(IDVal);
1968 return parseDirectiveExitMacro(IDVal);
1971 return parseDirectiveEndMacro(IDVal);
1973 return parseDirectivePurgeMacro(IDLoc);
1975 return parseDirectiveEnd(IDLoc);
1977 return parseDirectiveError(IDLoc,
false);
1979 return parseDirectiveError(IDLoc,
true);
1981 return parseDirectiveWarning(IDLoc);
1983 return parseDirectiveReloc(IDLoc);
1986 return parseDirectiveDCB(IDVal, 2);
1988 return parseDirectiveDCB(IDVal, 1);
1990 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
1992 return parseDirectiveDCB(IDVal, 4);
1994 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
1997 return TokError(
Twine(IDVal) +
1998 " not currently supported for this target");
2001 return parseDirectiveDS(IDVal, 2);
2003 return parseDirectiveDS(IDVal, 1);
2005 return parseDirectiveDS(IDVal, 8);
2008 return parseDirectiveDS(IDVal, 4);
2011 return parseDirectiveDS(IDVal, 12);
2014 return Error(IDLoc,
"unknown directive");
2018 if (ParsingInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
2019 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
2020 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
2023 if (ParsingInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
2024 return parseDirectiveMSAlign(IDLoc, Info);
2026 if (ParsingInlineAsm && (IDVal ==
"even" || IDVal ==
"EVEN"))
2027 Info.AsmRewrites->emplace_back(
AOK_EVEN, IDLoc, 4);
2028 if (checkForValidSection())
2032 std::string OpcodeStr = IDVal.
lower();
2034 bool ParseHadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, ID,
2035 Info.ParsedOperands);
2036 Info.ParseError = ParseHadError;
2039 if (getShowParsedOperands()) {
2042 OS <<
"parsed instruction: [";
2043 for (
unsigned i = 0; i != Info.ParsedOperands.size(); ++i) {
2046 Info.ParsedOperands[i]->print(OS);
2050 printMessage(IDLoc, SourceMgr::DK_Note, OS.str());
2054 if (hasPendingError() || ParseHadError)
2059 if (!ParseHadError && getContext().getGenDwarfForAssembly() &&
2060 getContext().getGenDwarfSectionSyms().count(
2061 getStreamer().getCurrentSectionOnly())) {
2063 if (ActiveMacros.empty())
2067 ActiveMacros.front()->ExitBuffer);
2072 if (!CppHashInfo.Filename.empty()) {
2073 unsigned FileNumber = getStreamer().EmitDwarfFileDirective(
2075 getContext().setGenDwarfFileNumber(FileNumber);
2080 unsigned CppHashLocLineNo;
2081 if (LastQueryIDLoc == CppHashInfo.Loc &&
2082 LastQueryBuffer == CppHashInfo.Buf)
2083 CppHashLocLineNo = LastQueryLine;
2087 LastQueryLine = CppHashLocLineNo;
2088 LastQueryIDLoc = CppHashInfo.Loc;
2089 LastQueryBuffer = CppHashInfo.Buf;
2091 Line = CppHashInfo.LineNumber - 1 + (Line - CppHashLocLineNo);
2094 getStreamer().EmitDwarfLocDirective(
2095 getContext().getGenDwarfFileNumber(), Line, 0,
2101 if (!ParseHadError) {
2103 if (getTargetParser().MatchAndEmitInstruction(
2104 IDLoc, Info.Opcode, Info.ParsedOperands, Out, ErrorInfo,
2105 getTargetParser().isParsingInlineAsm()))
2115 if (Lexer.isNot(AsmToken::LCurly) && Lexer.isNot(AsmToken::RCurly))
2118 SMLoc StartLoc = Lexer.getLoc();
2120 if (Lexer.is(AsmToken::EndOfStatement))
2131 bool AsmParser::parseCppHashLineFilenameComment(
SMLoc L) {
2135 assert(getTok().is(AsmToken::Integer) &&
2136 "Lexing Cpp line comment: Expected Integer");
2137 int64_t LineNumber = getTok().getIntVal();
2140 "Lexing Cpp line comment: Expected String");
2141 StringRef Filename = getTok().getString();
2145 Filename = Filename.
substr(1, Filename.
size() - 2);
2148 CppHashInfo.Loc =
L;
2149 CppHashInfo.Filename = Filename;
2150 CppHashInfo.LineNumber = LineNumber;
2151 CppHashInfo.Buf = CurBuffer;
2158 const AsmParser *Parser =
static_cast<const AsmParser *
>(
Context);
2164 unsigned CppHashBuf =
2165 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashInfo.Loc);
2170 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
2179 if (!Parser->CppHashInfo.LineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
2180 DiagBuf != CppHashBuf) {
2181 if (Parser->SavedDiagHandler)
2182 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
2184 Diag.
print(
nullptr, OS);
2191 const std::string &Filename = Parser->CppHashInfo.Filename;
2194 int CppHashLocLineNo =
2195 Parser->SrcMgr.FindLineNumber(Parser->CppHashInfo.Loc, CppHashBuf);
2197 Parser->CppHashInfo.LineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
2203 if (Parser->SavedDiagHandler)
2204 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
2206 NewDiag.print(
nullptr, OS);
2214 return isalnum(static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
2221 bool EnableAtPseudoVariable,
SMLoc L) {
2222 unsigned NParameters = Parameters.
size();
2223 bool HasVararg = NParameters ? Parameters.
back().Vararg :
false;
2224 if ((!IsDarwin || NParameters != 0) && NParameters != A.
size())
2225 return Error(L,
"Wrong number of arguments");
2229 while (!Body.
empty()) {
2231 std::size_t End = Body.
size(), Pos = 0;
2232 for (; Pos !=
End; ++Pos) {
2234 if (IsDarwin && !NParameters) {
2236 if (Body[Pos] !=
'$' || Pos + 1 == End)
2239 char Next = Body[Pos + 1];
2240 if (Next ==
'$' || Next ==
'n' ||
2241 isdigit(static_cast<unsigned char>(Next)))
2245 if (Body[Pos] ==
'\\' && Pos + 1 != End)
2251 OS << Body.
slice(0, Pos);
2257 if (IsDarwin && !NParameters) {
2258 switch (Body[Pos + 1]) {
2272 unsigned Index = Body[Pos + 1] -
'0';
2273 if (Index >= A.
size())
2277 for (
const AsmToken &Token : A[Index])
2278 OS << Token.getString();
2284 unsigned I = Pos + 1;
2287 if (EnableAtPseudoVariable && Body[I] ==
'@' && I + 1 != End)
2293 const char *Begin = Body.
data() + Pos + 1;
2298 OS << NumOfMacroInstantiations;
2301 for (; Index < NParameters; ++Index)
2305 if (Index == NParameters) {
2306 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
2313 bool VarargParameter = HasVararg && Index == (NParameters - 1);
2314 for (
const AsmToken &Token : A[Index])
2320 if ((Lexer.IsaAltMacroMode()) &&
2321 (*(Token.getString().begin()) ==
'%') && Token.is(AsmToken::Integer))
2323 OS << Token.getIntVal();
2326 else if ((Lexer.IsaAltMacroMode()) &&
2327 (*(Token.getString().begin()) ==
'<') &&
2330 altMacroString(Token.getStringContents(), Res);
2336 OS << Token.getString();
2338 OS << Token.getStringContents();
2351 MacroInstantiation::MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
2352 size_t CondStackDepth)
2353 : InstantiationLoc(IL), ExitBuffer(EB), ExitLoc(EL),
2354 CondStackDepth(CondStackDepth) {}
2360 case AsmToken::Plus:
2361 case AsmToken::Minus:
2362 case AsmToken::Tilde:
2363 case AsmToken::Slash:
2364 case AsmToken::Star:
2367 case AsmToken::EqualEqual:
2368 case AsmToken::Pipe:
2369 case AsmToken::PipePipe:
2370 case AsmToken::Caret:
2372 case AsmToken::AmpAmp:
2373 case AsmToken::Exclaim:
2374 case AsmToken::ExclaimEqual:
2376 case AsmToken::LessEqual:
2377 case AsmToken::LessLess:
2378 case AsmToken::LessGreater:
2379 case AsmToken::Greater:
2380 case AsmToken::GreaterEqual:
2381 case AsmToken::GreaterGreater:
2388 class AsmLexerSkipSpaceRAII {
2390 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
2394 ~AsmLexerSkipSpaceRAII() {
2404 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
2407 if (Lexer.isNot(AsmToken::EndOfStatement)) {
2408 StringRef Str = parseStringToEndOfStatement();
2414 unsigned ParenLevel = 0;
2417 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
2424 return TokError(
"unexpected token in macro instantiation");
2426 if (ParenLevel == 0) {
2431 if (Lexer.is(AsmToken::Space)) {
2441 MA.push_back(getTok());
2445 if (Lexer.is(AsmToken::Space))
2457 if (Lexer.is(AsmToken::EndOfStatement))
2461 if (Lexer.is(AsmToken::LParen))
2463 else if (Lexer.is(AsmToken::RParen) && ParenLevel)
2467 MA.push_back(getTok());
2471 if (ParenLevel != 0)
2472 return TokError(
"unbalanced parentheses in macro argument");
2477 bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2478 MCAsmMacroArguments &A) {
2479 const unsigned NParameters = M ? M->Parameters.size() : 0;
2480 bool NamedParametersFound =
false;
2484 FALocs.
resize(NParameters);
2489 bool HasVararg = NParameters ? M->Parameters.back().Vararg :
false;
2490 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2492 SMLoc IDLoc = Lexer.getLoc();
2493 MCAsmMacroParameter FA;
2496 if (parseIdentifier(FA.Name))
2497 return Error(IDLoc,
"invalid argument identifier for formal argument");
2500 return TokError(
"expected '=' after formal parameter identifier");
2504 NamedParametersFound =
true;
2506 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2508 if (NamedParametersFound && FA.Name.empty())
2509 return Error(IDLoc,
"cannot mix positional and keyword arguments");
2511 SMLoc StrLoc = Lexer.getLoc();
2513 if (Lexer.IsaAltMacroMode() && Lexer.is(AsmToken::Percent)) {
2514 const MCExpr *AbsoluteExp;
2518 if (parseExpression(AbsoluteExp, EndLoc))
2520 if (!AbsoluteExp->evaluateAsAbsolute(Value))
2521 return Error(StrLoc,
"expected absolute expression");
2524 AsmToken newToken(AsmToken::Integer,
StringRef(StrChar , EndChar - StrChar), Value);
2525 FA.Value.push_back(newToken);
2526 }
else if (Lexer.IsaAltMacroMode() && Lexer.is(
AsmToken::Less) &&
2527 isAltmacroString(StrLoc, EndLoc)) {
2530 jumpToLoc(EndLoc, CurBuffer);
2534 FA.Value.push_back(newToken);
2535 }
else if(parseMacroArgument(FA.Value, Vararg))
2538 unsigned PI = Parameter;
2539 if (!FA.Name.empty()) {
2541 for (FAI = 0; FAI < NParameters; ++FAI)
2542 if (M->Parameters[FAI].Name == FA.Name)
2545 if (FAI >= NParameters) {
2546 assert(M &&
"expected macro to be defined");
2547 return Error(IDLoc,
"parameter named '" + FA.Name +
2548 "' does not exist for macro '" + M->Name +
"'");
2553 if (!FA.Value.empty()) {
2558 if (FALocs.
size() <= PI)
2561 FALocs[PI] = Lexer.getLoc();
2567 if (Lexer.is(AsmToken::EndOfStatement)) {
2568 bool Failure =
false;
2569 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2570 if (A[FAI].empty()) {
2571 if (M->Parameters[FAI].Required) {
2572 Error(FALocs[FAI].
isValid() ? FALocs[FAI] : Lexer.getLoc(),
2573 "missing value for required parameter "
2574 "'" + M->Parameters[FAI].Name +
"' in macro '" + M->Name +
"'");
2578 if (!M->Parameters[FAI].Value.empty())
2579 A[FAI] = M->Parameters[FAI].Value;
2589 return TokError(
"too many positional arguments");
2594 return (I == MacroMap.end()) ?
nullptr : &I->getValue();
2598 MacroMap.insert(std::make_pair(Name, std::move(Macro)));
2601 void AsmParser::undefineMacro(
StringRef Name) { MacroMap.erase(Name); }
2603 bool AsmParser::handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc) {
2607 if (ActiveMacros.size() == MaxNestingDepth) {
2608 std::ostringstream MaxNestingDepthError;
2609 MaxNestingDepthError <<
"macros cannot be nested more than "
2610 << MaxNestingDepth <<
" levels deep."
2611 <<
" Use -asm-macro-max-nesting-depth to increase "
2613 return TokError(MaxNestingDepthError.str());
2616 MCAsmMacroArguments
A;
2617 if (parseMacroArguments(M, A))
2626 if (expandMacro(OS, Body, M->Parameters, A,
true, getTok().getLoc()))
2631 OS <<
".endmacro\n";
2633 std::unique_ptr<MemoryBuffer> Instantiation =
2634 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
2638 MacroInstantiation *
MI =
new MacroInstantiation(
2639 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
2640 ActiveMacros.push_back(MI);
2642 ++NumOfMacroInstantiations;
2652 void AsmParser::handleMacroExit() {
2654 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2658 delete ActiveMacros.back();
2659 ActiveMacros.pop_back();
2662 bool AsmParser::parseAssignment(
StringRef Name,
bool allow_redef,
2688 bool AsmParser::parseIdentifier(
StringRef &Res) {
2694 if (Lexer.is(AsmToken::Dollar) || Lexer.is(AsmToken::At)) {
2695 SMLoc PrefixLoc = getLexer().getLoc();
2700 Lexer.peekTokens(Buf,
false);
2721 Res = getTok().getIdentifier();
2732 bool AsmParser::parseDirectiveSet(
StringRef IDVal,
bool allow_redef) {
2734 if (check(parseIdentifier(Name),
"expected identifier") ||
2735 parseToken(
AsmToken::Comma) || parseAssignment(Name, allow_redef,
true))
2736 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2740 bool AsmParser::parseEscapedString(std::string &
Data) {
2745 StringRef Str = getTok().getStringContents();
2746 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
2747 if (Str[i] !=
'\\') {
2756 return TokError(
"unexpected backslash at end of string");
2759 if ((
unsigned)(Str[i] -
'0') <= 7) {
2761 unsigned Value = Str[i] -
'0';
2763 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2765 Value = Value * 8 + (Str[i] -
'0');
2767 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2769 Value = Value * 8 + (Str[i] -
'0');
2774 return TokError(
"invalid octal escape sequence (out of range)");
2776 Data += (
unsigned char)Value;
2784 return TokError(
"invalid escape sequence (unrecognized character)");
2786 case 'b': Data +=
'\b';
break;
2787 case 'f': Data +=
'\f';
break;
2788 case 'n': Data +=
'\n';
break;
2789 case 'r': Data +=
'\r';
break;
2790 case 't': Data +=
'\t';
break;
2791 case '"': Data +=
'"';
break;
2792 case '\\': Data +=
'\\';
break;
2802 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
2803 auto parseOp = [&]() ->
bool {
2805 if (checkForValidSection() || parseEscapedString(Data))
2807 getStreamer().EmitBytes(Data);
2809 getStreamer().EmitBytes(
StringRef(
"\0", 1));
2813 if (parseMany(parseOp))
2814 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2820 bool AsmParser::parseDirectiveReloc(
SMLoc DirectiveLoc) {
2822 const MCExpr *Expr =
nullptr;
2824 SMLoc OffsetLoc = Lexer.getTok().getLoc();
2825 int64_t OffsetValue;
2828 if (parseExpression(Offset))
2831 if (check(!Offset->evaluateAsAbsolute(OffsetValue), OffsetLoc,
2832 "expression is not a constant value") ||
2833 check(OffsetValue < 0, OffsetLoc,
"expression is negative") ||
2838 SMLoc NameLoc = Lexer.getTok().getLoc();
2839 StringRef Name = Lexer.getTok().getIdentifier();
2844 SMLoc ExprLoc = Lexer.getLoc();
2845 if (parseExpression(Expr))
2850 return Error(ExprLoc,
"expression must be relocatable");
2853 if (parseToken(AsmToken::EndOfStatement,
2854 "unexpected token in .reloc directive"))
2857 if (getStreamer().EmitRelocDirective(*Offset, Name, Expr, DirectiveLoc))
2858 return Error(NameLoc,
"unknown relocation name");
2865 bool AsmParser::parseDirectiveValue(
StringRef IDVal,
unsigned Size) {
2866 auto parseOp = [&]() ->
bool {
2868 SMLoc ExprLoc = getLexer().getLoc();
2869 if (checkForValidSection() || parseExpression(Value))
2872 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2873 assert(Size <= 8 &&
"Invalid size");
2874 uint64_t IntValue = MCE->getValue();
2875 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
2876 return Error(ExprLoc,
"out of range literal value");
2877 getStreamer().EmitIntValue(IntValue, Size);
2879 getStreamer().EmitValue(Value, Size, ExprLoc);
2883 if (parseMany(parseOp))
2884 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2891 bool AsmParser::parseDirectiveOctaValue(
StringRef IDVal) {
2892 auto parseOp = [&]() ->
bool {
2893 if (checkForValidSection())
2895 if (getTok().isNot(AsmToken::Integer) && getTok().isNot(AsmToken::BigNum))
2896 return TokError(
"unknown token in expression");
2897 SMLoc ExprLoc = getTok().getLoc();
2898 APInt IntValue = getTok().getAPIntVal();
2901 if (!IntValue.
isIntN(128))
2902 return Error(ExprLoc,
"out of range literal value");
2903 if (!IntValue.
isIntN(64)) {
2911 getStreamer().EmitIntValue(lo, 8);
2912 getStreamer().EmitIntValue(hi, 8);
2914 getStreamer().EmitIntValue(hi, 8);
2915 getStreamer().EmitIntValue(lo, 8);
2920 if (parseMany(parseOp))
2921 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2929 if (getLexer().is(AsmToken::Minus)) {
2932 }
else if (getLexer().is(AsmToken::Plus))
2936 return TokError(Lexer.getErr());
2937 if (Lexer.isNot(AsmToken::Integer) && Lexer.isNot(AsmToken::Real) &&
2939 return TokError(
"unexpected token in directive");
2946 Value = APFloat::getInf(Semantics);
2948 Value = APFloat::getNaN(Semantics,
false, ~0);
2950 return TokError(
"invalid floating point literal");
2951 }
else if (Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven) ==
2952 APFloat::opInvalidOp)
2953 return TokError(
"invalid floating point literal");
2960 Res = Value.bitcastToAPInt();
2967 bool AsmParser::parseDirectiveRealValue(
StringRef IDVal,
2969 auto parseOp = [&]() ->
bool {
2971 if (checkForValidSection() || parseRealValue(Semantics, AsInt))
2978 if (parseMany(parseOp))
2979 return addErrorSuffix(
" in '" +
Twine(IDVal) +
"' directive");
2985 bool AsmParser::parseDirectiveZero() {
2986 SMLoc NumBytesLoc = Lexer.getLoc();
2988 if (checkForValidSection() || parseExpression(NumBytes))
2994 if (parseAbsoluteExpression(Val))
2998 if (parseToken(AsmToken::EndOfStatement,
2999 "unexpected token in '.zero' directive"))
3001 getStreamer().emitFill(*NumBytes, Val, NumBytesLoc);
3008 bool AsmParser::parseDirectiveFill() {
3009 SMLoc NumValuesLoc = Lexer.getLoc();
3011 if (checkForValidSection() || parseExpression(NumValues))
3014 int64_t FillSize = 1;
3015 int64_t FillExpr = 0;
3017 SMLoc SizeLoc, ExprLoc;
3020 SizeLoc = getTok().getLoc();
3021 if (parseAbsoluteExpression(FillSize))
3024 ExprLoc = getTok().getLoc();
3025 if (parseAbsoluteExpression(FillExpr))
3029 if (parseToken(AsmToken::EndOfStatement,
3030 "unexpected token in '.fill' directive"))
3034 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
3038 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
3043 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
3045 getStreamer().emitFill(*NumValues, FillSize, FillExpr, NumValuesLoc);
3052 bool AsmParser::parseDirectiveOrg() {
3054 SMLoc OffsetLoc = Lexer.getLoc();
3055 if (checkForValidSection() || parseExpression(Offset))
3059 int64_t FillExpr = 0;
3061 if (parseAbsoluteExpression(FillExpr))
3062 return addErrorSuffix(
" in '.org' directive");
3063 if (parseToken(AsmToken::EndOfStatement))
3064 return addErrorSuffix(
" in '.org' directive");
3066 getStreamer().emitValueToOffset(Offset, FillExpr, OffsetLoc);
3072 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
3073 SMLoc AlignmentLoc = getLexer().getLoc();
3076 bool HasFillExpr =
false;
3077 int64_t FillExpr = 0;
3078 int64_t MaxBytesToFill = 0;
3080 auto parseAlign = [&]() ->
bool {
3081 if (checkForValidSection() || parseAbsoluteExpression(Alignment))
3089 if (parseAbsoluteExpression(FillExpr))
3093 if (parseTokenLoc(MaxBytesLoc) ||
3094 parseAbsoluteExpression(MaxBytesToFill))
3097 return parseToken(AsmToken::EndOfStatement);
3101 return addErrorSuffix(
" in directive");
3104 bool ReturnVal =
false;
3109 if (Alignment >= 32) {
3110 ReturnVal |=
Error(AlignmentLoc,
"invalid alignment value");
3114 Alignment = 1ULL << Alignment;
3122 ReturnVal |=
Error(AlignmentLoc,
"alignment must be a power of 2");
3127 if (MaxBytesToFill < 1) {
3128 ReturnVal |=
Error(MaxBytesLoc,
3129 "alignment directive can never be satisfied in this "
3130 "many bytes, ignoring maximum bytes expression");
3134 if (MaxBytesToFill >= Alignment) {
3135 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
3144 assert(Section &&
"must have section to emit alignment");
3146 if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) &&
3147 ValueSize == 1 && UseCodeAlign) {
3148 getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
3151 getStreamer().EmitValueToAlignment(Alignment, FillExpr, ValueSize,
3161 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
3163 int64_t FileNumber = -1;
3164 SMLoc FileNumberLoc = getLexer().getLoc();
3165 if (getLexer().is(AsmToken::Integer)) {
3166 FileNumber = getTok().getIntVal();
3170 return TokError(
"file number less than one");
3173 std::string Path = getTok().getString();
3178 "unexpected token in '.file' directive") ||
3179 parseEscapedString(Path))
3184 std::string FilenameData;
3186 if (check(FileNumber == -1,
3187 "explicit path specified, but no file number") ||
3188 parseEscapedString(FilenameData))
3190 Filename = FilenameData;
3196 if (parseToken(AsmToken::EndOfStatement,
3197 "unexpected token in '.file' directive"))
3200 if (FileNumber == -1)
3201 getStreamer().EmitFileDirective(Filename);
3205 if (getContext().getGenDwarfForAssembly())
3206 getContext().setGenDwarfForAssembly(
false);
3207 else if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename) ==
3209 return Error(FileNumberLoc,
"file number already allocated");
3217 bool AsmParser::parseDirectiveLine() {
3219 if (getLexer().is(AsmToken::Integer)) {
3220 if (parseIntToken(LineNumber,
"unexpected token in '.line' directive"))
3225 if (parseToken(AsmToken::EndOfStatement,
3226 "unexpected token in '.line' directive"))
3239 bool AsmParser::parseDirectiveLoc() {
3240 int64_t FileNumber = 0, LineNumber = 0;
3241 SMLoc Loc = getTok().getLoc();
3242 if (parseIntToken(FileNumber,
"unexpected token in '.loc' directive") ||
3243 check(FileNumber < 1, Loc,
3244 "file number less than one in '.loc' directive") ||
3245 check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
3246 "unassigned file number in '.loc' directive"))
3250 if (getLexer().is(AsmToken::Integer)) {
3251 LineNumber = getTok().getIntVal();
3253 return TokError(
"line number less than zero in '.loc' directive");
3257 int64_t ColumnPos = 0;
3258 if (getLexer().is(AsmToken::Integer)) {
3259 ColumnPos = getTok().getIntVal();
3261 return TokError(
"column position less than zero in '.loc' directive");
3267 int64_t Discriminator = 0;
3269 auto parseLocOp = [&]() ->
bool {
3271 SMLoc Loc = getTok().getLoc();
3272 if (parseIdentifier(Name))
3273 return TokError(
"unexpected token in '.loc' directive");
3275 if (Name ==
"basic_block")
3277 else if (Name ==
"prologue_end")
3279 else if (Name ==
"epilogue_begin")
3281 else if (Name ==
"is_stmt") {
3282 Loc = getTok().getLoc();
3284 if (parseExpression(Value))
3287 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3288 int Value = MCE->getValue();
3290 Flags &= ~DWARF2_FLAG_IS_STMT;
3291 else if (Value == 1)
3294 return Error(Loc,
"is_stmt value not 0 or 1");
3296 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
3298 }
else if (Name ==
"isa") {
3299 Loc = getTok().getLoc();
3301 if (parseExpression(Value))
3304 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
3305 int Value = MCE->getValue();
3307 return Error(Loc,
"isa number less than zero");
3310 return Error(Loc,
"isa number not a constant value");
3312 }
else if (Name ==
"discriminator") {
3313 if (parseAbsoluteExpression(Discriminator))
3316 return Error(Loc,
"unknown sub-directive in '.loc' directive");
3321 if (parseMany(parseLocOp,
false ))
3324 getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
3332 bool AsmParser::parseDirectiveStabs() {
3333 return TokError(
"unsupported directive '.stabs'");
3338 bool AsmParser::parseDirectiveCVFile() {
3339 SMLoc FileNumberLoc = getTok().getLoc();
3341 std::string Filename;
3343 if (parseIntToken(FileNumber,
3344 "expected file number in '.cv_file' directive") ||
3345 check(FileNumber < 1, FileNumberLoc,
"file number less than one") ||
3347 "unexpected token in '.cv_file' directive") ||
3350 parseEscapedString(Filename) ||
3351 parseToken(AsmToken::EndOfStatement,
3352 "unexpected token in '.cv_file' directive"))
3355 if (!getStreamer().EmitCVFileDirective(FileNumber, Filename))
3356 return Error(FileNumberLoc,
"file number already allocated");
3361 bool AsmParser::parseCVFunctionId(int64_t &FunctionId,
3364 return parseTokenLoc(Loc) ||
3365 parseIntToken(FunctionId,
"expected function id in '" + DirectiveName +
3367 check(FunctionId < 0 || FunctionId >= UINT_MAX, Loc,
3368 "expected function id within range [0, UINT_MAX)");
3371 bool AsmParser::parseCVFileId(int64_t &FileNumber,
StringRef DirectiveName) {
3373 return parseTokenLoc(Loc) ||
3374 parseIntToken(FileNumber,
"expected integer in '" + DirectiveName +
3376 check(FileNumber < 1, Loc,
"file number less than one in '" +
3377 DirectiveName +
"' directive") ||
3378 check(!getCVContext().isValidFileNumber(FileNumber), Loc,
3379 "unassigned file number in '" + DirectiveName +
"' directive");
3386 bool AsmParser::parseDirectiveCVFuncId() {
3387 SMLoc FunctionIdLoc = getTok().getLoc();
3390 if (parseCVFunctionId(FunctionId,
".cv_func_id") ||
3391 parseToken(AsmToken::EndOfStatement,
3392 "unexpected token in '.cv_func_id' directive"))
3395 if (!getStreamer().EmitCVFuncIdDirective(FunctionId))
3396 return Error(FunctionIdLoc,
"function id already allocated");
3409 bool AsmParser::parseDirectiveCVInlineSiteId() {
3410 SMLoc FunctionIdLoc = getTok().getLoc();
3418 if (parseCVFunctionId(FunctionId,
".cv_inline_site_id"))
3423 getTok().getIdentifier() !=
"within"),
3424 "expected 'within' identifier in '.cv_inline_site_id' directive"))
3429 if (parseCVFunctionId(IAFunc,
".cv_inline_site_id"))
3434 getTok().getIdentifier() !=
"inlined_at"),
3435 "expected 'inlined_at' identifier in '.cv_inline_site_id' "
3441 if (parseCVFileId(IAFile,
".cv_inline_site_id") ||
3442 parseIntToken(IALine,
"expected line number after 'inlined_at'"))
3446 if (getLexer().is(AsmToken::Integer)) {
3447 IACol = getTok().getIntVal();
3451 if (parseToken(AsmToken::EndOfStatement,
3452 "unexpected token in '.cv_inline_site_id' directive"))
3455 if (!getStreamer().EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
3456 IALine, IACol, FunctionIdLoc))
3457 return Error(FunctionIdLoc,
"function id already allocated");
3469 bool AsmParser::parseDirectiveCVLoc() {
3470 SMLoc DirectiveLoc = getTok().getLoc();
3472 int64_t FunctionId, FileNumber;
3473 if (parseCVFunctionId(FunctionId,
".cv_loc") ||
3474 parseCVFileId(FileNumber,
".cv_loc"))
3477 int64_t LineNumber = 0;
3478 if (getLexer().is(AsmToken::Integer)) {
3479 LineNumber = getTok().getIntVal();
3481 return TokError(
"line number less than zero in '.cv_loc' directive");
3485 int64_t ColumnPos = 0;
3486 if (getLexer().is(AsmToken::Integer)) {
3487 ColumnPos = getTok().getIntVal();
3489 return TokError(
"column position less than zero in '.cv_loc' directive");
3493 bool PrologueEnd =
false;
3494 uint64_t IsStmt = 0;
3496 auto parseOp = [&]() ->
bool {
3498 SMLoc Loc = getTok().getLoc();
3499 if (parseIdentifier(Name))
3500 return TokError(
"unexpected token in '.cv_loc' directive");
3501 if (Name ==
"prologue_end")
3503 else if (Name ==
"is_stmt") {
3504 Loc = getTok().getLoc();
3506 if (parseExpression(Value))
3510 if (
const auto *MCE = dyn_cast<MCConstantExpr>(Value))
3511 IsStmt = MCE->getValue();
3514 return Error(Loc,
"is_stmt value not 0 or 1");
3516 return Error(Loc,
"unknown sub-directive in '.cv_loc' directive");
3521 if (parseMany(parseOp,
false ))
3524 getStreamer().EmitCVLocDirective(FunctionId, FileNumber, LineNumber,
3525 ColumnPos, PrologueEnd, IsStmt,
StringRef(),
3532 bool AsmParser::parseDirectiveCVLinetable() {
3535 SMLoc Loc = getTok().getLoc();
3536 if (parseCVFunctionId(FunctionId,
".cv_linetable") ||
3538 "unexpected token in '.cv_linetable' directive") ||
3539 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3540 "expected identifier in directive") ||
3542 "unexpected token in '.cv_linetable' directive") ||
3543 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3544 "expected identifier in directive"))
3547 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3548 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3550 getStreamer().EmitCVLinetableDirective(FunctionId, FnStartSym, FnEndSym);
3556 bool AsmParser::parseDirectiveCVInlineLinetable() {
3557 int64_t PrimaryFunctionId, SourceFileId, SourceLineNum;
3559 SMLoc Loc = getTok().getLoc();
3560 if (parseCVFunctionId(PrimaryFunctionId,
".cv_inline_linetable") ||
3561 parseTokenLoc(Loc) ||
3564 "expected SourceField in '.cv_inline_linetable' directive") ||
3565 check(SourceFileId <= 0, Loc,
3566 "File id less than zero in '.cv_inline_linetable' directive") ||
3567 parseTokenLoc(Loc) ||
3570 "expected SourceLineNum in '.cv_inline_linetable' directive") ||
3571 check(SourceLineNum < 0, Loc,
3572 "Line number less than zero in '.cv_inline_linetable' directive") ||
3573 parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
3574 "expected identifier in directive") ||
3575 parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
3576 "expected identifier in directive"))
3579 if (parseToken(AsmToken::EndOfStatement,
"Expected End of Statement"))
3582 MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
3583 MCSymbol *FnEndSym = getContext().getOrCreateSymbol(FnEndName);
3584 getStreamer().EmitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId,
3585 SourceLineNum, FnStartSym,
3592 bool AsmParser::parseDirectiveCVDefRange() {
3594 std::vector<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
3596 Loc = getLexer().getLoc();
3598 if (parseIdentifier(GapStartName))
3599 return Error(Loc,
"expected identifier in directive");
3600 MCSymbol *GapStartSym = getContext().getOrCreateSymbol(GapStartName);
3602 Loc = getLexer().getLoc();
3604 if (parseIdentifier(GapEndName))
3605 return Error(Loc,
"expected identifier in directive");
3606 MCSymbol *GapEndSym = getContext().getOrCreateSymbol(GapEndName);
3608 Ranges.push_back({GapStartSym, GapEndSym});
3611 std::string FixedSizePortion;
3613 parseEscapedString(FixedSizePortion))
3616 getStreamer().EmitCVDefRangeDirective(Ranges, FixedSizePortion);
3622 bool AsmParser::parseDirectiveCVStringTable() {
3623 getStreamer().EmitCVStringTableDirective();
3629 bool AsmParser::parseDirectiveCVFileChecksums() {
3630 getStreamer().EmitCVFileChecksumsDirective();
3636 bool AsmParser::parseDirectiveCFISections() {
3641 if (parseIdentifier(Name))
3642 return TokError(
"Expected an identifier");
3644 if (Name ==
".eh_frame")
3646 else if (Name ==
".debug_frame")
3652 if (parseIdentifier(Name))
3653 return TokError(
"Expected an identifier");
3655 if (Name ==
".eh_frame")
3657 else if (Name ==
".debug_frame")
3661 getStreamer().EmitCFISections(EH, Debug);
3667 bool AsmParser::parseDirectiveCFIStartProc() {
3669 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
3670 if (check(parseIdentifier(Simple) || Simple !=
"simple",
3671 "unexpected token") ||
3672 parseToken(AsmToken::EndOfStatement))
3673 return addErrorSuffix(
" in '.cfi_startproc' directive");
3676 getStreamer().EmitCFIStartProc(!Simple.
empty());
3682 bool AsmParser::parseDirectiveCFIEndProc() {
3683 getStreamer().EmitCFIEndProc();
3688 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
3689 SMLoc DirectiveLoc) {
3692 if (getLexer().isNot(AsmToken::Integer)) {
3693 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
3695 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
3697 return parseAbsoluteExpression(Register);
3704 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
3705 int64_t Register = 0, Offset = 0;
3706 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3708 parseAbsoluteExpression(Offset))
3711 getStreamer().EmitCFIDefCfa(Register, Offset);
3717 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
3719 if (parseAbsoluteExpression(Offset))
3722 getStreamer().EmitCFIDefCfaOffset(Offset);
3728 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
3729 int64_t Register1 = 0, Register2 = 0;
3730 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) ||
3732 parseRegisterOrRegisterNumber(Register2, DirectiveLoc))
3735 getStreamer().EmitCFIRegister(Register1, Register2);
3741 bool AsmParser::parseDirectiveCFIWindowSave() {
3742 getStreamer().EmitCFIWindowSave();
3748 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
3749 int64_t Adjustment = 0;
3750 if (parseAbsoluteExpression(Adjustment))
3753 getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
3759 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
3760 int64_t Register = 0;
3761 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3764 getStreamer().EmitCFIDefCfaRegister(Register);
3770 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
3771 int64_t Register = 0;
3774 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3776 parseAbsoluteExpression(Offset))
3779 getStreamer().EmitCFIOffset(Register, Offset);
3785 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
3786 int64_t Register = 0, Offset = 0;
3788 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
3790 parseAbsoluteExpression(Offset))
3793 getStreamer().EmitCFIRelOffset(Register, Offset);
3798 if (Encoding & ~0xff)
3804 const unsigned Format = Encoding & 0xf;
3811 const unsigned Application = Encoding & 0x70;
3823 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
3824 int64_t Encoding = 0;
3825 if (parseAbsoluteExpression(Encoding))
3833 check(parseIdentifier(Name),
"expected identifier in directive"))
3836 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
3839 getStreamer().EmitCFIPersonality(Sym, Encoding);
3841 getStreamer().EmitCFILsda(Sym, Encoding);
3847 bool AsmParser::parseDirectiveCFIRememberState() {
3848 getStreamer().EmitCFIRememberState();
3854 bool AsmParser::parseDirectiveCFIRestoreState() {
3855 getStreamer().EmitCFIRestoreState();
3861 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
3862 int64_t Register = 0;
3864 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3867 getStreamer().EmitCFISameValue(Register);
3873 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
3874 int64_t Register = 0;
3875 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3878 getStreamer().EmitCFIRestore(Register);
3884 bool AsmParser::parseDirectiveCFIEscape() {
3887 if (parseAbsoluteExpression(CurrValue))
3890 Values.push_back((uint8_t)CurrValue);
3895 if (parseAbsoluteExpression(CurrValue))
3898 Values.push_back((uint8_t)CurrValue);
3901 getStreamer().EmitCFIEscape(Values);
3907 bool AsmParser::parseDirectiveCFISignalFrame() {
3908 if (parseToken(AsmToken::EndOfStatement,
3909 "unexpected token in '.cfi_signal_frame'"))
3912 getStreamer().EmitCFISignalFrame();
3918 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
3919 int64_t Register = 0;
3921 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3924 getStreamer().EmitCFIUndefined(Register);
3931 bool AsmParser::parseDirectiveAltmacro(
StringRef Directive) {
3932 if (getLexer().isNot(AsmToken::EndOfStatement))
3933 return TokError(
"unexpected token in '" + Directive +
"' directive");
3934 if (Directive ==
".altmacro")
3935 getLexer().SetAltMacroMode(
true);
3937 getLexer().SetAltMacroMode(
false);
3944 bool AsmParser::parseDirectiveMacrosOnOff(
StringRef Directive) {
3945 if (parseToken(AsmToken::EndOfStatement,
3946 "unexpected token in '" + Directive +
"' directive"))
3949 setMacrosEnabled(Directive ==
".macros_on");
3955 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
3957 if (parseIdentifier(Name))
3958 return TokError(
"expected identifier in '.macro' directive");
3963 MCAsmMacroParameters Parameters;
3964 while (getLexer().isNot(AsmToken::EndOfStatement)) {
3966 if (!Parameters.empty() && Parameters.back().Vararg)
3967 return Error(Lexer.getLoc(),
3968 "Vararg parameter '" + Parameters.back().Name +
3969 "' should be last one in the list of parameters.");
3971 MCAsmMacroParameter Parameter;
3972 if (parseIdentifier(Parameter.Name))
3973 return TokError(
"expected identifier in '.macro' directive");
3976 for (
const MCAsmMacroParameter& CurrParam : Parameters)
3977 if (CurrParam.Name.equals(Parameter.Name))
3978 return TokError(
"macro '" + Name +
"' has multiple parameters"
3979 " named '" + Parameter.Name +
"'");
3981 if (Lexer.is(AsmToken::Colon)) {
3987 QualLoc = Lexer.getLoc();
3988 if (parseIdentifier(Qualifier))
3989 return Error(QualLoc,
"missing parameter qualifier for "
3990 "'" + Parameter.Name +
"' in macro '" + Name +
"'");
3992 if (Qualifier ==
"req")
3993 Parameter.Required =
true;
3994 else if (Qualifier ==
"vararg")
3995 Parameter.Vararg =
true;
3997 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
3998 "for '" + Parameter.Name +
"' in macro '" + Name +
"'");
4006 ParamLoc = Lexer.getLoc();
4007 if (parseMacroArgument(Parameter.Value,
false ))
4010 if (Parameter.Required)
4011 Warning(ParamLoc,
"pointless default value for required parameter "
4012 "'" + Parameter.Name +
"' in macro '" + Name +
"'");
4015 Parameters.push_back(std::move(Parameter));
4025 AsmToken EndToken, StartToken = getTok();
4026 unsigned MacroDepth = 0;
4036 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
4040 if (getTok().getIdentifier() ==
".endm" ||
4041 getTok().getIdentifier() ==
".endmacro") {
4042 if (MacroDepth == 0) {
4043 EndToken = getTok();
4045 if (getLexer().isNot(AsmToken::EndOfStatement))
4046 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
4053 }
else if (getTok().getIdentifier() ==
".macro") {
4061 eatToEndOfStatement();
4064 if (lookupMacro(Name)) {
4065 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
4071 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
4072 defineMacro(Name, MCAsmMacro(Name, Body, std::move(Parameters)));
4090 void AsmParser::checkForBadMacro(
SMLoc DirectiveLoc,
StringRef Name,
4095 unsigned NParameters = Parameters.
size();
4096 if (NParameters == 0)
4099 bool NamedParametersFound =
false;
4100 bool PositionalParametersFound =
false;
4105 while (!Body.
empty()) {
4107 std::size_t End = Body.
size(), Pos = 0;
4108 for (; Pos !=
End; ++Pos) {
4111 if (Body[Pos] ==
'\\' && Pos + 1 != End)
4115 if (Body[Pos] !=
'$' || Pos + 1 == End)
4117 char Next = Body[Pos + 1];
4118 if (Next ==
'$' || Next ==
'n' ||
4119 isdigit(static_cast<unsigned char>(Next)))
4127 if (Body[Pos] ==
'$') {
4128 switch (Body[Pos + 1]) {
4135 PositionalParametersFound =
true;
4140 PositionalParametersFound =
true;
4146 unsigned I = Pos + 1;
4150 const char *Begin = Body.
data() + Pos + 1;
4153 for (; Index < NParameters; ++Index)
4154 if (Parameters[Index].Name ==
Argument)
4157 if (Index == NParameters) {
4158 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
4164 NamedParametersFound =
true;
4172 if (!NamedParametersFound && PositionalParametersFound)
4173 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
4174 "used in macro body, possible positional parameter "
4175 "found in body which will have no effect");
4180 bool AsmParser::parseDirectiveExitMacro(
StringRef Directive) {
4181 if (parseToken(AsmToken::EndOfStatement,
4182 "unexpected token in '" + Directive +
"' directive"))
4185 if (!isInsideMacroInstantiation())
4186 return TokError(
"unexpected '" + Directive +
"' in file, "
4187 "no current macro definition");
4190 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
4191 TheCondState = TheCondStack.back();
4192 TheCondStack.pop_back();
4202 bool AsmParser::parseDirectiveEndMacro(
StringRef Directive) {
4203 if (getLexer().isNot(AsmToken::EndOfStatement))
4204 return TokError(
"unexpected token in '" + Directive +
"' directive");
4208 if (isInsideMacroInstantiation()) {
4215 return TokError(
"unexpected '" + Directive +
"' in file, "
4216 "no current macro definition");
4221 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
4224 if (parseTokenLoc(Loc) ||
4225 check(parseIdentifier(Name), Loc,
4226 "expected identifier in '.purgem' directive") ||
4227 parseToken(AsmToken::EndOfStatement,
4228 "unexpected token in '.purgem' directive"))
4231 if (!lookupMacro(Name))
4232 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
4234 undefineMacro(Name);
4240 bool AsmParser::parseDirectiveBundleAlignMode() {
4243 SMLoc ExprLoc = getLexer().getLoc();
4244 int64_t AlignSizePow2;
4245 if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4246 parseToken(AsmToken::EndOfStatement,
"unexpected token after expression "
4247 "in '.bundle_align_mode' "
4249 check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
4250 "invalid bundle alignment size (expected between 0 and 30)"))
4255 getStreamer().EmitBundleAlignMode(static_cast<unsigned>(AlignSizePow2));
4261 bool AsmParser::parseDirectiveBundleLock() {
4262 if (checkForValidSection())
4264 bool AlignToEnd =
false;
4267 SMLoc Loc = getTok().getLoc();
4268 const char *kInvalidOptionError =
4269 "invalid option for '.bundle_lock' directive";
4271 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
4272 if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
4273 check(Option !=
"align_to_end", Loc, kInvalidOptionError) ||
4274 parseToken(AsmToken::EndOfStatement,
4275 "unexpected token after '.bundle_lock' directive option"))
4280 getStreamer().EmitBundleLock(AlignToEnd);
4286 bool AsmParser::parseDirectiveBundleUnlock() {
4287 if (checkForValidSection() ||
4288 parseToken(AsmToken::EndOfStatement,
4289 "unexpected token in '.bundle_unlock' directive"))
4292 getStreamer().EmitBundleUnlock();
4298 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
4299 SMLoc NumBytesLoc = Lexer.getLoc();
4301 if (checkForValidSection() || parseExpression(NumBytes))
4304 int64_t FillExpr = 0;
4306 if (parseAbsoluteExpression(FillExpr))
4307 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4308 if (parseToken(AsmToken::EndOfStatement))
4309 return addErrorSuffix(
"in '" +
Twine(IDVal) +
"' directive");
4312 getStreamer().emitFill(*NumBytes, FillExpr, NumBytesLoc);
4319 bool AsmParser::parseDirectiveDCB(
StringRef IDVal,
unsigned Size) {
4320 SMLoc NumValuesLoc = Lexer.getLoc();
4322 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4325 if (NumValues < 0) {
4326 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4331 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4335 SMLoc ExprLoc = getLexer().getLoc();
4336 if (parseExpression(Value))
4340 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
4341 assert(Size <= 8 &&
"Invalid size");
4342 uint64_t IntValue = MCE->getValue();
4343 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
4344 return Error(ExprLoc,
"literal value out of range for directive");
4345 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4346 getStreamer().EmitIntValue(IntValue, Size);
4348 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4349 getStreamer().EmitValue(Value, Size, ExprLoc);
4352 if (parseToken(AsmToken::EndOfStatement,
4353 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4362 SMLoc NumValuesLoc = Lexer.getLoc();
4364 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4367 if (NumValues < 0) {
4368 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4373 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4377 if (parseRealValue(Semantics, AsInt))
4380 if (parseToken(AsmToken::EndOfStatement,
4381 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4384 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4393 bool AsmParser::parseDirectiveDS(
StringRef IDVal,
unsigned Size) {
4394 SMLoc NumValuesLoc = Lexer.getLoc();
4396 if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4399 if (NumValues < 0) {
4400 Warning(NumValuesLoc,
"'" +
Twine(IDVal) +
"' directive with negative repeat count has no effect");
4404 if (parseToken(AsmToken::EndOfStatement,
4405 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
4408 for (uint64_t i = 0, e = NumValues; i != e; ++i)
4409 getStreamer().emitFill(Size, 0);
4416 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
4417 if (checkForValidSection())
4420 auto parseOp = [&]() ->
bool {
4422 if (parseExpression(Value))
4425 getStreamer().EmitSLEB128Value(Value);
4427 getStreamer().EmitULEB128Value(Value);
4431 if (parseMany(parseOp))
4432 return addErrorSuffix(
" in directive");
4439 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
4440 auto parseOp = [&]() ->
bool {
4442 SMLoc Loc = getTok().getLoc();
4443 if (parseIdentifier(Name))
4444 return Error(Loc,
"expected identifier");
4445 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4449 return Error(Loc,
"non-local symbol required");
4451 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
4452 return Error(Loc,
"unable to emit symbol attribute");
4456 if (parseMany(parseOp))
4457 return addErrorSuffix(
" in directive");
4463 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
4464 if (checkForValidSection())
4467 SMLoc IDLoc = getLexer().getLoc();
4469 if (parseIdentifier(Name))
4470 return TokError(
"expected identifier in directive");
4473 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
4476 return TokError(
"unexpected token in directive");
4480 SMLoc SizeLoc = getLexer().getLoc();
4481 if (parseAbsoluteExpression(Size))
4484 int64_t Pow2Alignment = 0;
4485 SMLoc Pow2AlignmentLoc;
4488 Pow2AlignmentLoc = getLexer().getLoc();
4489 if (parseAbsoluteExpression(Pow2Alignment))
4494 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
4497 if ((!IsLocal && Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) ||
4500 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
4501 Pow2Alignment =
Log2_64(Pow2Alignment);
4505 if (parseToken(AsmToken::EndOfStatement,
4506 "unexpected token in '.comm' or '.lcomm' directive"))
4512 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't "
4513 "be less than zero");
4518 if (Pow2Alignment < 0)
4519 return Error(Pow2AlignmentLoc,
"invalid '.comm' or '.lcomm' directive "
4520 "alignment, can't be less than zero");
4524 return Error(IDLoc,
"invalid symbol redefinition");
4528 getStreamer().EmitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4532 getStreamer().EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
4538 bool AsmParser::parseDirectiveAbort() {
4540 SMLoc Loc = getLexer().getLoc();
4542 StringRef Str = parseStringToEndOfStatement();
4543 if (parseToken(AsmToken::EndOfStatement,
4544 "unexpected token in '.abort' directive"))
4548 return Error(Loc,
".abort detected. Assembly stopping.");
4550 return Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
4558 bool AsmParser::parseDirectiveInclude() {
4560 std::string Filename;
4561 SMLoc IncludeLoc = getTok().getLoc();
4564 "expected string in '.include' directive") ||
4565 parseEscapedString(Filename) ||
4566 check(getTok().isNot(AsmToken::EndOfStatement),
4567 "unexpected token in '.include' directive") ||
4570 check(enterIncludeFile(Filename), IncludeLoc,
4571 "Could not find include file '" + Filename +
"'"))
4579 bool AsmParser::parseDirectiveIncbin() {
4581 std::string Filename;
4582 SMLoc IncbinLoc = getTok().getLoc();
4584 "expected string in '.incbin' directive") ||
4585 parseEscapedString(Filename))
4589 const MCExpr *Count =
nullptr;
4590 SMLoc SkipLoc, CountLoc;
4595 if (parseTokenLoc(SkipLoc) || parseAbsoluteExpression(Skip))
4599 CountLoc = getTok().getLoc();
4600 if (parseExpression(Count))
4605 if (parseToken(AsmToken::EndOfStatement,
4606 "unexpected token in '.incbin' directive"))
4609 if (check(Skip < 0, SkipLoc,
"skip is negative"))
4613 if (processIncbinFile(Filename, Skip, Count, CountLoc))
4614 return Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
4620 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
4621 TheCondStack.push_back(TheCondState);
4622 TheCondState.TheCond = AsmCond::IfCond;
4623 if (TheCondState.Ignore) {
4624 eatToEndOfStatement();
4627 if (parseAbsoluteExpression(ExprValue) ||
4628 parseToken(AsmToken::EndOfStatement,
4629 "unexpected token in '.if' directive"))
4639 ExprValue = ExprValue == 0;
4642 ExprValue = ExprValue >= 0;
4645 ExprValue = ExprValue > 0;
4648 ExprValue = ExprValue <= 0;
4651 ExprValue = ExprValue < 0;
4655 TheCondState.CondMet = ExprValue;
4656 TheCondState.Ignore = !TheCondState.CondMet;
4664 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
4665 TheCondStack.push_back(TheCondState);
4666 TheCondState.TheCond = AsmCond::IfCond;
4668 if (TheCondState.Ignore) {
4669 eatToEndOfStatement();
4671 StringRef Str = parseStringToEndOfStatement();
4673 if (parseToken(AsmToken::EndOfStatement,
4674 "unexpected token in '.ifb' directive"))
4677 TheCondState.CondMet = ExpectBlank == Str.
empty();
4678 TheCondState.Ignore = !TheCondState.CondMet;
4687 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4688 TheCondStack.push_back(TheCondState);
4689 TheCondState.TheCond = AsmCond::IfCond;
4691 if (TheCondState.Ignore) {
4692 eatToEndOfStatement();
4696 if (parseToken(
AsmToken::Comma,
"unexpected token in '.ifc' directive"))
4699 StringRef Str2 = parseStringToEndOfStatement();
4701 if (parseToken(AsmToken::EndOfStatement,
4702 "unexpected token in '.ifc' directive"))
4705 TheCondState.CondMet = ExpectEqual == (Str1.
trim() == Str2.
trim());
4706 TheCondState.Ignore = !TheCondState.CondMet;
4714 bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
4717 return TokError(
"expected string parameter for '.ifeqs' directive");
4718 return TokError(
"expected string parameter for '.ifnes' directive");
4721 StringRef String1 = getTok().getStringContents();
4727 "expected comma after first string for '.ifeqs' directive");
4728 return TokError(
"expected comma after first string for '.ifnes' directive");
4735 return TokError(
"expected string parameter for '.ifeqs' directive");
4736 return TokError(
"expected string parameter for '.ifnes' directive");
4739 StringRef String2 = getTok().getStringContents();
4742 TheCondStack.push_back(TheCondState);
4743 TheCondState.TheCond = AsmCond::IfCond;
4744 TheCondState.CondMet = ExpectEqual == (String1 == String2);
4745 TheCondState.Ignore = !TheCondState.CondMet;
4752 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
4754 TheCondStack.push_back(TheCondState);
4755 TheCondState.TheCond = AsmCond::IfCond;
4757 if (TheCondState.Ignore) {
4758 eatToEndOfStatement();
4760 if (check(parseIdentifier(Name),
"expected identifier after '.ifdef'") ||
4761 parseToken(AsmToken::EndOfStatement,
"unexpected token in '.ifdef'"))
4764 MCSymbol *Sym = getContext().lookupSymbol(Name);
4767 TheCondState.CondMet = (Sym && !Sym->
isUndefined());
4769 TheCondState.CondMet = (!Sym || Sym->
isUndefined());
4770 TheCondState.Ignore = !TheCondState.CondMet;
4778 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
4779 if (TheCondState.TheCond != AsmCond::IfCond &&
4780 TheCondState.TheCond != AsmCond::ElseIfCond)
4781 return Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow an"
4782 " .if or an .elseif");
4783 TheCondState.TheCond = AsmCond::ElseIfCond;
4785 bool LastIgnoreState =
false;
4786 if (!TheCondStack.empty())
4787 LastIgnoreState = TheCondStack.back().Ignore;
4788 if (LastIgnoreState || TheCondState.CondMet) {
4789 TheCondState.Ignore =
true;
4790 eatToEndOfStatement();
4793 if (parseAbsoluteExpression(ExprValue))
4796 if (parseToken(AsmToken::EndOfStatement,
4797 "unexpected token in '.elseif' directive"))
4800 TheCondState.CondMet = ExprValue;
4801 TheCondState.Ignore = !TheCondState.CondMet;
4809 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
4810 if (parseToken(AsmToken::EndOfStatement,
4811 "unexpected token in '.else' directive"))
4814 if (TheCondState.TheCond != AsmCond::IfCond &&
4815 TheCondState.TheCond != AsmCond::ElseIfCond)
4816 return Error(DirectiveLoc,
"Encountered a .else that doesn't follow "
4817 " an .if or an .elseif");
4818 TheCondState.TheCond = AsmCond::ElseCond;
4819 bool LastIgnoreState =
false;
4820 if (!TheCondStack.empty())
4821 LastIgnoreState = TheCondStack.back().Ignore;
4822 if (LastIgnoreState || TheCondState.CondMet)
4823 TheCondState.Ignore =
true;
4825 TheCondState.Ignore =
false;
4832 bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
4833 if (parseToken(AsmToken::EndOfStatement,
4834 "unexpected token in '.end' directive"))
4846 bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
4847 if (!TheCondStack.empty()) {
4848 if (TheCondStack.back().Ignore) {
4849 eatToEndOfStatement();
4855 return Error(L,
".err encountered");
4857 StringRef Message =
".error directive invoked in source file";
4858 if (Lexer.isNot(AsmToken::EndOfStatement)) {
4860 return TokError(
".error argument must be a string");
4862 Message = getTok().getStringContents();
4866 return Error(L, Message);
4871 bool AsmParser::parseDirectiveWarning(
SMLoc L) {
4872 if (!TheCondStack.empty()) {
4873 if (TheCondStack.back().Ignore) {
4874 eatToEndOfStatement();
4879 StringRef Message =
".warning directive invoked in source file";
4881 if (!parseOptionalToken(AsmToken::EndOfStatement)) {
4883 return TokError(
".warning argument must be a string");
4885 Message = getTok().getStringContents();
4887 if (parseToken(AsmToken::EndOfStatement,
4888 "expected end of statement in '.warning' directive"))
4892 return Warning(L, Message);
4897 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
4898 if (parseToken(AsmToken::EndOfStatement,
4899 "unexpected token in '.endif' directive"))
4902 if ((TheCondState.TheCond == AsmCond::NoCond) || TheCondStack.empty())
4903 return Error(DirectiveLoc,
"Encountered a .endif that doesn't follow "
4905 if (!TheCondStack.empty()) {
4906 TheCondState = TheCondStack.back();
4907 TheCondStack.pop_back();
4913 void AsmParser::initializeDirectiveKindMap() {
4914 DirectiveKindMap[
".set"] = DK_SET;
4915 DirectiveKindMap[
".equ"] = DK_EQU;
4916 DirectiveKindMap[
".equiv"] = DK_EQUIV;
4917 DirectiveKindMap[
".ascii"] = DK_ASCII;
4918 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
4919 DirectiveKindMap[
".string"] = DK_STRING;
4920 DirectiveKindMap[
".byte"] = DK_BYTE;
4921 DirectiveKindMap[
".short"] = DK_SHORT;
4922 DirectiveKindMap[
".value"] = DK_VALUE;
4923 DirectiveKindMap[
".2byte"] = DK_2BYTE;
4924 DirectiveKindMap[
".long"] = DK_LONG;
4925 DirectiveKindMap[
".int"] = DK_INT;
4926 DirectiveKindMap[
".4byte"] = DK_4BYTE;
4927 DirectiveKindMap[
".quad"] = DK_QUAD;
4928 DirectiveKindMap[
".8byte"] = DK_8BYTE;
4929 DirectiveKindMap[
".octa"] = DK_OCTA;
4930 DirectiveKindMap[
".single"] = DK_SINGLE;
4931 DirectiveKindMap[
".float"] = DK_FLOAT;
4932 DirectiveKindMap[
".double"] = DK_DOUBLE;
4933 DirectiveKindMap[
".align"] = DK_ALIGN;
4934 DirectiveKindMap[
".align32"] = DK_ALIGN32;
4935 DirectiveKindMap[
".balign"] = DK_BALIGN;
4936 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
4937 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
4938 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
4939 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
4940 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
4941 DirectiveKindMap[
".org"] = DK_ORG;
4942 DirectiveKindMap[
".fill"] = DK_FILL;
4943 DirectiveKindMap[
".zero"] = DK_ZERO;
4944 DirectiveKindMap[
".extern"] = DK_EXTERN;
4945 DirectiveKindMap[
".globl"] = DK_GLOBL;
4946 DirectiveKindMap[
".global"] = DK_GLOBAL;
4947 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
4948 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
4949 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
4950 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
4951 DirectiveKindMap[
".reference"] = DK_REFERENCE;
4952 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
4953 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
4954 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
4955 DirectiveKindMap[
".comm"] = DK_COMM;
4956 DirectiveKindMap[
".common"] = DK_COMMON;
4957 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
4958 DirectiveKindMap[
".abort"] = DK_ABORT;
4959 DirectiveKindMap[
".include"] = DK_INCLUDE;
4960 DirectiveKindMap[
".incbin"] = DK_INCBIN;
4961 DirectiveKindMap[
".code16"] = DK_CODE16;
4962 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
4963 DirectiveKindMap[
".rept"] = DK_REPT;
4964 DirectiveKindMap[
".rep"] = DK_REPT;
4965 DirectiveKindMap[
".irp"] = DK_IRP;
4966 DirectiveKindMap[
".irpc"] = DK_IRPC;
4967 DirectiveKindMap[
".endr"] = DK_ENDR;
4968 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
4969 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
4970 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
4971 DirectiveKindMap[
".if"] = DK_IF;
4972 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
4973 DirectiveKindMap[
".ifge"] = DK_IFGE;
4974 DirectiveKindMap[
".ifgt"] = DK_IFGT;
4975 DirectiveKindMap[
".ifle"] = DK_IFLE;
4976 DirectiveKindMap[
".iflt"] = DK_IFLT;
4977 DirectiveKindMap[
".ifne"] = DK_IFNE;
4978 DirectiveKindMap[
".ifb"] = DK_IFB;
4979 DirectiveKindMap[
".ifnb"] = DK_IFNB;
4980 DirectiveKindMap[
".ifc"] = DK_IFC;
4981 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
4982 DirectiveKindMap[
".ifnc"] = DK_IFNC;
4983 DirectiveKindMap[
".ifnes"] = DK_IFNES;
4984 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
4985 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
4986 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
4987 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
4988 DirectiveKindMap[
".else"] = DK_ELSE;
4989 DirectiveKindMap[
".end"] = DK_END;
4990 DirectiveKindMap[
".endif"] = DK_ENDIF;
4991 DirectiveKindMap[
".skip"] = DK_SKIP;
4992 DirectiveKindMap[
".space"] = DK_SPACE;
4993 DirectiveKindMap[
".file"] = DK_FILE;
4994 DirectiveKindMap[
".line"] = DK_LINE;
4995 DirectiveKindMap[
".loc"] = DK_LOC;
4996 DirectiveKindMap[
".stabs"] = DK_STABS;
4997 DirectiveKindMap[
".cv_file"] = DK_CV_FILE;
4998 DirectiveKindMap[
".cv_func_id"] = DK_CV_FUNC_ID;
4999 DirectiveKindMap[
".cv_loc"] = DK_CV_LOC;
5000 DirectiveKindMap[
".cv_linetable"] = DK_CV_LINETABLE;
5001 DirectiveKindMap[
".cv_inline_linetable"] = DK_CV_INLINE_LINETABLE;
5002 DirectiveKindMap[
".cv_inline_site_id"] = DK_CV_INLINE_SITE_ID;
5003 DirectiveKindMap[
".cv_def_range"] = DK_CV_DEF_RANGE;
5004 DirectiveKindMap[
".cv_stringtable"] = DK_CV_STRINGTABLE;
5005 DirectiveKindMap[
".cv_filechecksums"] = DK_CV_FILECHECKSUMS;
5006 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
5007 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
5008 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
5009 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
5010 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
5011 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
5012 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
5013 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
5014 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
5015 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
5016 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
5017 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
5018 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
5019 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
5020 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
5021 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
5022 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
5023 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
5024 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
5025 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
5026 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
5027 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
5028 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
5029 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
5030 DirectiveKindMap[
".macro"] = DK_MACRO;
5031 DirectiveKindMap[
".exitm"] = DK_EXITM;
5032 DirectiveKindMap[
".endm"] = DK_ENDM;
5033 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
5034 DirectiveKindMap[
".purgem"] = DK_PURGEM;
5035 DirectiveKindMap[
".err"] = DK_ERR;
5036 DirectiveKindMap[
".error"] = DK_ERROR;
5037 DirectiveKindMap[
".warning"] = DK_WARNING;
5038 DirectiveKindMap[
".altmacro"] = DK_ALTMACRO;
5039 DirectiveKindMap[
".noaltmacro"] = DK_NOALTMACRO;
5040 DirectiveKindMap[
".reloc"] = DK_RELOC;
5041 DirectiveKindMap[
".dc"] = DK_DC;
5042 DirectiveKindMap[
".dc.a"] = DK_DC_A;
5043 DirectiveKindMap[
".dc.b"] = DK_DC_B;
5044 DirectiveKindMap[
".dc.d"] = DK_DC_D;
5045 DirectiveKindMap[
".dc.l"] = DK_DC_L;
5046 DirectiveKindMap[
".dc.s"] = DK_DC_S;
5047 DirectiveKindMap[
".dc.w"] = DK_DC_W;
5048 DirectiveKindMap[
".dc.x"] = DK_DC_X;
5049 DirectiveKindMap[
".dcb"] = DK_DCB;
5050 DirectiveKindMap[
".dcb.b"] = DK_DCB_B;
5051 DirectiveKindMap[
".dcb.d"] = DK_DCB_D;
5052 DirectiveKindMap[
".dcb.l"] = DK_DCB_L;
5053 DirectiveKindMap[
".dcb.s"] = DK_DCB_S;
5054 DirectiveKindMap[
".dcb.w"] = DK_DCB_W;
5055 DirectiveKindMap[
".dcb.x"] = DK_DCB_X;
5056 DirectiveKindMap[
".ds"] = DK_DS;
5057 DirectiveKindMap[
".ds.b"] = DK_DS_B;
5058 DirectiveKindMap[
".ds.d"] = DK_DS_D;
5059 DirectiveKindMap[
".ds.l"] = DK_DS_L;
5060 DirectiveKindMap[
".ds.p"] = DK_DS_P;
5061 DirectiveKindMap[
".ds.s"] = DK_DS_S;
5062 DirectiveKindMap[
".ds.w"] = DK_DS_W;
5063 DirectiveKindMap[
".ds.x"] = DK_DS_X;
5066 MCAsmMacro *AsmParser::parseMacroLikeBody(
SMLoc DirectiveLoc) {
5067 AsmToken EndToken, StartToken = getTok();
5069 unsigned NestLevel = 0;
5073 printError(DirectiveLoc,
"no matching '.endr' in definition");
5078 (getTok().getIdentifier() ==
".rept" ||
5079 getTok().getIdentifier() ==
".irp" ||
5080 getTok().getIdentifier() ==
".irpc")) {
5086 if (NestLevel == 0) {
5087 EndToken = getTok();
5089 if (Lexer.isNot(AsmToken::EndOfStatement)) {
5090 printError(getTok().getLoc(),
5091 "unexpected token in '.endr' directive");
5100 eatToEndOfStatement();
5108 MacroLikeBodies.emplace_back(
StringRef(), Body, MCAsmMacroParameters());
5109 return &MacroLikeBodies.back();
5112 void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
5116 std::unique_ptr<MemoryBuffer> Instantiation =
5117 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
5121 MacroInstantiation *MI =
new MacroInstantiation(
5122 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
5123 ActiveMacros.push_back(MI);
5133 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
5135 SMLoc CountLoc = getTok().getLoc();
5136 if (parseExpression(CountExpr))
5140 if (!CountExpr->evaluateAsAbsolute(Count)) {
5141 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
5144 if (check(Count < 0, CountLoc,
"Count is negative") ||
5145 parseToken(AsmToken::EndOfStatement,
5146 "unexpected token in '" + Dir +
"' directive"))
5150 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5160 if (expandMacro(OS, M->Body,
None,
None,
false, getTok().getLoc()))
5163 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5170 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
5171 MCAsmMacroParameter Parameter;
5172 MCAsmMacroArguments
A;
5173 if (check(parseIdentifier(Parameter.Name),
5174 "expected identifier in '.irp' directive") ||
5176 parseMacroArguments(
nullptr, A) ||
5177 parseToken(AsmToken::EndOfStatement,
"expected End of Statement"))
5181 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5190 for (
const MCAsmMacroArgument &Arg : A) {
5193 if (expandMacro(OS, M->Body, Parameter, Arg,
true, getTok().getLoc()))
5197 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5204 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
5205 MCAsmMacroParameter Parameter;
5206 MCAsmMacroArguments
A;
5208 if (check(parseIdentifier(Parameter.Name),
5209 "expected identifier in '.irpc' directive") ||
5211 parseMacroArguments(
nullptr, A))
5214 if (A.size() != 1 || A.front().size() != 1)
5215 return TokError(
"unexpected token in '.irpc' directive");
5218 if (parseToken(AsmToken::EndOfStatement,
"expected end of statement"))
5222 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
5232 for (std::size_t I = 0, End = Values.
size(); I !=
End; ++
I) {
5233 MCAsmMacroArgument Arg;
5238 if (expandMacro(OS, M->Body, Parameter, Arg,
true, getTok().getLoc()))
5242 instantiateMacroLikeBody(M, DirectiveLoc, OS);
5247 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
5248 if (ActiveMacros.empty())
5249 return TokError(
"unmatched '.endr' directive");
5253 assert(getLexer().is(AsmToken::EndOfStatement));
5259 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
5262 SMLoc ExprLoc = getLexer().getLoc();
5263 if (parseExpression(Value))
5267 return Error(ExprLoc,
"unexpected expression in _emit");
5268 uint64_t IntValue = MCE->
getValue();
5270 return Error(ExprLoc,
"literal value out of range for directive");
5272 Info.AsmRewrites->emplace_back(
AOK_Emit, IDLoc, Len);
5276 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
5278 SMLoc ExprLoc = getLexer().getLoc();
5279 if (parseExpression(Value))
5283 return Error(ExprLoc,
"unexpected expression in align");
5284 uint64_t IntValue = MCE->
getValue();
5286 return Error(ExprLoc,
"literal value not a power of two greater then zero");
5315 bool AsmParser::parseMSInlineAsm(
5316 void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs,
5317 unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
5335 unsigned InputIdx = 0;
5336 unsigned OutputIdx = 0;
5339 if (parseCurlyBlockScope(AsmStrRewrites))
5342 ParseStatementInfo Info(&AsmStrRewrites);
5343 bool StatementErr = parseStatement(Info, &SI);
5345 if (StatementErr || Info.ParseError) {
5347 printPendingErrors();
5352 assert(!hasPendingError() &&
"unexpected error from parseStatement");
5354 if (Info.Opcode == ~0U)
5360 for (
unsigned i = 1, e = Info.ParsedOperands.size(); i != e; ++i) {
5364 if (Operand.
isImm())
5369 !getTargetParser().OmitRegisterFromClobberLists(Operand.
getReg())) {
5379 if (SymName.
empty())
5386 bool isOutput = (i == 1) && Desc.
mayStore();
5387 SMLoc Start = SMLoc::getFromPointer(SymName.
data());
5405 ClobberRegs.
insert(ClobberRegs.
end(), ImpDefs.begin(), ImpDefs.end());
5409 NumOutputs = OutputDecls.
size();
5410 NumInputs = InputDecls.
size();
5414 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
5416 Clobbers.
assign(ClobberRegs.
size(), std::string());
5417 for (
unsigned I = 0, E = ClobberRegs.
size(); I !=
E; ++
I) {
5423 if (NumOutputs || NumInputs) {
5424 unsigned NumExprs = NumOutputs + NumInputs;
5425 OpDecls.resize(NumExprs);
5426 Constraints.
resize(NumExprs);
5427 for (
unsigned i = 0; i < NumOutputs; ++i) {
5428 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
5429 Constraints[i] = OutputConstraints[i];
5431 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) {
5432 OpDecls[j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
5433 Constraints[j] = InputConstraints[i];
5438 std::string AsmStringIR;
5442 const char *AsmStart = ASMString.
begin();
5443 const char *AsmEnd = ASMString.
end();
5445 for (
const AsmRewrite &AR : AsmStrRewrites) {
5451 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
5454 if (
unsigned Len = Loc - AsmStart)
5459 AsmStart = Loc + AR.Len;
5463 unsigned AdditionalSkip = 0;
5469 OS <<
"$$" << AR.Val;
5478 OS <<
'$' << InputIdx++;
5481 OS <<
'$' << OutputIdx++;
5486 case 8: OS <<
"byte ptr ";
break;
5487 case 16: OS <<
"word ptr ";
break;
5488 case 32: OS <<
"dword ptr ";
break;
5489 case 64: OS <<
"qword ptr ";
break;
5490 case 80: OS <<
"xword ptr ";
break;
5491 case 128: OS <<
"xmmword ptr ";
break;
5492 case 256: OS <<
"ymmword ptr ";
break;
5502 if (getContext().getAsmInfo()->getAlignmentIsInBytes())
5507 unsigned Val = AR.Val;
5509 assert(Val < 10 &&
"Expected alignment less then 2^10.");
5510 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
5519 if (AsmStringIR.back() !=
'.')
5529 AsmStart = Loc + AR.Len + AdditionalSkip;
5533 if (AsmStart != AsmEnd)
5534 OS <<
StringRef(AsmStart, AsmEnd - AsmStart);
5536 AsmString = OS.
str();
5541 namespace MCParserUtils {
5564 Sym, static_cast<const MCUnaryExpr *>(Value)->getSubExpr());
5578 return Parser.
TokError(
"missing expression");
5597 return Parser.
Error(EqualLoc,
"Recursive use of '" + Name +
"'");
5604 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
5606 return Parser.
Error(EqualLoc,
"invalid assignment to '" + Name +
"'");
5608 return Parser.
Error(EqualLoc,
5609 "invalid reassignment of non-absolute variable '" +
5611 }
else if (Name ==
".") {
5629 return new AsmParser(SM, C, Out, MAI, CB);
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.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual ~MCAsmParserSemaCallback()
This class represents an incoming formal argument to a Function.
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)
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()
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance.
unsigned getMainFileID() const
static bool isIdentifierChar(char c)
AsmLexer - Lexer class for assembly files.
#define DWARF2_FLAG_IS_STMT
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Generic assembler lexer interface, for use by target specific assembly lexers.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
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.
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
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)
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.
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
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)
Return 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.
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.
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
iterator erase(const_iterator CI)
MCAsmParserExtension * createCOFFAsmParser()
Binary assembler expressions.
static bool isValidEncoding(int64_t Encoding)
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.
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
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).
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
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static SMLoc getFromPointer(const char *Ptr)
llvm_unreachable("Unknown RegBank!")
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...
static std::vector< std::string > Flags
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)
INITIALIZE_PASS(HexagonGenMux,"hexagon-gen-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
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))
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
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)
Splits a string of comma separated items in to a vector of strings.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
DiagHandlerTy getDiagHandler() const
ConditionalAssemblyType TheCond
unsigned Log2_64(uint64_t Value)
Return 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.