53 typedef std::vector<AsmToken> MCAsmMacroArgument;
54 typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
56 struct MCAsmMacroParameter {
58 MCAsmMacroArgument
Value;
65 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
70 MCAsmMacroParameters Parameters;
74 :
Name(N), Body(B), Parameters(std::move(P)) {}
79 struct MacroInstantiation {
81 SMLoc InstantiationLoc;
90 size_t CondStackDepth;
93 MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
size_t CondStackDepth);
96 struct ParseStatementInfo {
108 ParseStatementInfo() : Opcode(~0U), ParseError(
false), AsmRewrites(nullptr) {}
110 : Opcode(~0), ParseError(
false), AsmRewrites(rewrites) {}
115 AsmParser(
const AsmParser &) =
delete;
116 void operator=(
const AsmParser &) =
delete;
124 void *SavedDiagContext;
125 std::unique_ptr<MCAsmParserExtension> PlatformParser;
132 std::vector<AsmCond> TheCondStack;
143 std::vector<MacroInstantiation*> ActiveMacros;
146 std::deque<MCAsmMacro> MacroLikeBodies;
149 unsigned MacrosEnabledFlag : 1;
152 unsigned NumOfMacroInstantiations;
155 unsigned HadError : 1;
159 int64_t CppHashLineNumber;
166 SMLoc LastQueryIDLoc;
167 unsigned LastQueryBuffer;
168 unsigned LastQueryLine;
171 unsigned AssemblerDialect;
177 bool ParsingInlineAsm;
182 ~AsmParser()
override;
184 bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false)
override;
186 void addDirectiveHandler(
StringRef Directive,
187 ExtensionDirectiveHandler Handler)
override {
188 ExtensionDirectiveMap[Directive] = Handler;
192 DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
200 MCAsmLexer &getLexer()
override {
return Lexer; }
201 MCContext &getContext()
override {
return Ctx; }
202 MCStreamer &getStreamer()
override {
return Out; }
203 unsigned getAssemblerDialect()
override {
204 if (AssemblerDialect == ~0U)
205 return MAI.getAssemblerDialect();
207 return AssemblerDialect;
209 void setAssemblerDialect(
unsigned i)
override {
210 AssemblerDialect = i;
222 void setParsingInlineAsm(
bool V)
override { ParsingInlineAsm = V; }
223 bool isParsingInlineAsm()
override {
return ParsingInlineAsm; }
225 bool parseMSInlineAsm(
void *AsmLoc, std::string &AsmString,
226 unsigned &NumOutputs,
unsigned &NumInputs,
233 bool parseExpression(
const MCExpr *&Res);
234 bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
235 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
236 bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
237 bool parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
238 SMLoc &EndLoc)
override;
239 bool parseAbsoluteExpression(int64_t &Res)
override;
243 bool parseIdentifier(
StringRef &Res)
override;
244 void eatToEndOfStatement()
override;
246 void checkForValidSection()
override;
251 bool parseStatement(ParseStatementInfo &Info,
253 void eatToEndOfLine();
254 bool parseCppHashLineFilenameComment(
const SMLoc &L);
264 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
267 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag =
Flag;}
281 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
287 bool handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc);
290 void handleMacroExit();
293 bool parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg);
296 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
298 void printMacroInstantiations();
303 static void DiagHandler(
const SMDiagnostic &Diag,
void *Context);
306 bool enterIncludeFile(
const std::string &Filename);
310 bool processIncbinFile(
const std::string &Filename);
318 void jumpToLoc(
SMLoc Loc,
unsigned InBuffer = 0);
323 StringRef parseStringToEndOfStatement()
override;
330 bool NoDeadStrip =
false);
335 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
336 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
337 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
339 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
344 DK_SET, DK_EQU, DK_EQUIV, DK_ASCII, DK_ASCIZ, DK_STRING, DK_BYTE, DK_SHORT,
345 DK_VALUE, DK_2BYTE, DK_LONG, DK_INT, DK_4BYTE, DK_QUAD, DK_8BYTE, DK_OCTA,
346 DK_SINGLE, DK_FLOAT, DK_DOUBLE, DK_ALIGN, DK_ALIGN32, DK_BALIGN, DK_BALIGNW,
347 DK_BALIGNL, DK_P2ALIGN, DK_P2ALIGNW, DK_P2ALIGNL, DK_ORG, DK_FILL, DK_ENDR,
348 DK_BUNDLE_ALIGN_MODE, DK_BUNDLE_LOCK, DK_BUNDLE_UNLOCK,
349 DK_ZERO, DK_EXTERN, DK_GLOBL, DK_GLOBAL,
350 DK_LAZY_REFERENCE, DK_NO_DEAD_STRIP, DK_SYMBOL_RESOLVER, DK_PRIVATE_EXTERN,
351 DK_REFERENCE, DK_WEAK_DEFINITION, DK_WEAK_REFERENCE,
352 DK_WEAK_DEF_CAN_BE_HIDDEN, DK_COMM, DK_COMMON, DK_LCOMM, DK_ABORT,
353 DK_INCLUDE, DK_INCBIN, DK_CODE16, DK_CODE16GCC, DK_REPT, DK_IRP, DK_IRPC,
354 DK_IF, DK_IFEQ, DK_IFGE, DK_IFGT, DK_IFLE, DK_IFLT, DK_IFNE, DK_IFB,
355 DK_IFNB, DK_IFC, DK_IFEQS, DK_IFNC, DK_IFNES, DK_IFDEF, DK_IFNDEF,
356 DK_IFNOTDEF, DK_ELSEIF, DK_ELSE, DK_ENDIF,
357 DK_SPACE, DK_SKIP, DK_FILE, DK_LINE, DK_LOC, DK_STABS,
358 DK_CFI_SECTIONS, DK_CFI_STARTPROC, DK_CFI_ENDPROC, DK_CFI_DEF_CFA,
359 DK_CFI_DEF_CFA_OFFSET, DK_CFI_ADJUST_CFA_OFFSET, DK_CFI_DEF_CFA_REGISTER,
360 DK_CFI_OFFSET, DK_CFI_REL_OFFSET, DK_CFI_PERSONALITY, DK_CFI_LSDA,
361 DK_CFI_REMEMBER_STATE, DK_CFI_RESTORE_STATE, DK_CFI_SAME_VALUE,
362 DK_CFI_RESTORE, DK_CFI_ESCAPE, DK_CFI_SIGNAL_FRAME, DK_CFI_UNDEFINED,
363 DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE,
364 DK_MACROS_ON, DK_MACROS_OFF,
365 DK_MACRO, DK_EXITM, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
366 DK_SLEB128, DK_ULEB128,
367 DK_ERR, DK_ERROR, DK_WARNING,
376 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
377 bool parseDirectiveValue(
unsigned Size);
378 bool parseDirectiveOctaValue();
380 bool parseDirectiveFill();
381 bool parseDirectiveZero();
383 bool parseDirectiveSet(
StringRef IDVal,
bool allow_redef);
384 bool parseDirectiveOrg();
386 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
389 bool parseDirectiveFile(
SMLoc DirectiveLoc);
390 bool parseDirectiveLine();
391 bool parseDirectiveLoc();
392 bool parseDirectiveStabs();
395 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
396 bool parseDirectiveCFIWindowSave();
397 bool parseDirectiveCFISections();
398 bool parseDirectiveCFIStartProc();
399 bool parseDirectiveCFIEndProc();
400 bool parseDirectiveCFIDefCfaOffset();
401 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
402 bool parseDirectiveCFIAdjustCfaOffset();
403 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
404 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
405 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
406 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
407 bool parseDirectiveCFIRememberState();
408 bool parseDirectiveCFIRestoreState();
409 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
410 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
411 bool parseDirectiveCFIEscape();
412 bool parseDirectiveCFISignalFrame();
413 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
416 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
417 bool parseDirectiveExitMacro(
StringRef Directive);
418 bool parseDirectiveEndMacro(
StringRef Directive);
419 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
420 bool parseDirectiveMacrosOnOff(
StringRef Directive);
423 bool parseDirectiveBundleAlignMode();
425 bool parseDirectiveBundleLock();
427 bool parseDirectiveBundleUnlock();
430 bool parseDirectiveSpace(
StringRef IDVal);
433 bool parseDirectiveLEB128(
bool Signed);
439 bool parseDirectiveComm(
bool IsLocal);
441 bool parseDirectiveAbort();
442 bool parseDirectiveInclude();
443 bool parseDirectiveIncbin();
446 bool parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind);
448 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
450 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
452 bool parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual);
454 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
455 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
456 bool parseDirectiveElse(
SMLoc DirectiveLoc);
457 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
458 bool parseEscapedString(std::string &
Data)
override;
464 MCAsmMacro *parseMacroLikeBody(
SMLoc DirectiveLoc);
465 void instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
468 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
469 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
470 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
473 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &Info,
477 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &Info);
480 bool parseDirectiveEnd(
SMLoc DirectiveLoc);
483 bool parseDirectiveError(
SMLoc DirectiveLoc,
bool WithMessage);
486 bool parseDirectiveWarning(
SMLoc DirectiveLoc);
488 void initializeDirectiveKindMap();
504 : Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI),
SrcMgr(SM),
505 PlatformParser(nullptr), CurBuffer(SM.getMainFileID()),
506 MacrosEnabledFlag(
true), HadError(
false), CppHashLineNumber(0),
507 AssemblerDialect(~0U), IsDarwin(
false), ParsingInlineAsm(
false) {
517 case MCObjectFileInfo::IsCOFF:
520 case MCObjectFileInfo::IsMachO:
524 case MCObjectFileInfo::IsELF:
529 PlatformParser->Initialize(*
this);
530 initializeDirectiveKindMap();
532 NumOfMacroInstantiations = 0;
535 AsmParser::~AsmParser() {
536 assert((HadError || ActiveMacros.empty()) &&
537 "Unexpected active macro instantiation!");
540 void AsmParser::printMacroInstantiations() {
542 for (std::vector<MacroInstantiation *>::const_reverse_iterator
543 it = ActiveMacros.rbegin(),
544 ie = ActiveMacros.rend();
546 printMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
547 "while in macro instantiation");
551 printMessage(L, SourceMgr::DK_Note, Msg, Ranges);
552 printMacroInstantiations();
556 if (getTargetParser().getTargetOptions().MCFatalWarnings)
557 return Error(L, Msg, Ranges);
558 printMessage(L, SourceMgr::DK_Warning, Msg, Ranges);
559 printMacroInstantiations();
565 printMessage(L, SourceMgr::DK_Error, Msg, Ranges);
566 printMacroInstantiations();
570 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
571 std::string IncludedFile;
585 bool AsmParser::processIncbinFile(
const std::string &Filename) {
586 std::string IncludedFile;
597 void AsmParser::jumpToLoc(
SMLoc Loc,
unsigned InBuffer) {
610 if (ParentIncludeLoc !=
SMLoc()) {
611 jumpToLoc(ParentIncludeLoc);
617 Error(Lexer.getErrLoc(), Lexer.getErr());
622 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
624 if (!NoInitialTextSection)
631 AsmCond StartingCondState = TheCondState;
635 if (getContext().getGenDwarfForAssembly()) {
636 MCSection *Sec = getStreamer().getCurrentSection().first;
638 MCSymbol *SectionStartSym = getContext().createTempSymbol();
639 getStreamer().EmitLabel(SectionStartSym);
642 bool InsertResult = getContext().addGenDwarfSection(Sec);
643 assert(InsertResult &&
".text section should not have debug info yet");
645 getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
646 0,
StringRef(), getContext().getMainFileName()));
651 ParseStatementInfo Info;
652 if (!parseStatement(Info,
nullptr))
657 assert(HadError &&
"Parse statement returned an error, but none emitted!");
658 eatToEndOfStatement();
661 if (TheCondState.TheCond != StartingCondState.
TheCond ||
662 TheCondState.Ignore != StartingCondState.
Ignore)
663 return TokError(
"unmatched .ifs or .elses");
666 const auto &LineTables = getContext().getMCDwarfLineTables();
667 if (!LineTables.empty()) {
669 for (
const auto &
File : LineTables.begin()->second.getMCDwarfFiles()) {
670 if (
File.Name.empty() && Index != 0)
671 TokError(
"unassigned file number: " +
Twine(Index) +
672 " for .file directives");
695 getLexer().getLoc(), SourceMgr::DK_Error,
696 "assembler local symbol '" + Sym->
getName() +
"' not defined");
702 if (!HadError && !NoFinalize)
708 void AsmParser::checkForValidSection() {
709 if (!ParsingInlineAsm && !getStreamer().getCurrentSection().first) {
710 TokError(
"expected section directive before assembly directive");
716 void AsmParser::eatToEndOfStatement() {
717 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
721 if (Lexer.is(AsmToken::EndOfStatement))
725 StringRef AsmParser::parseStringToEndOfStatement() {
726 const char *Start = getTok().getLoc().getPointer();
728 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
731 const char *End = getTok().getLoc().getPointer();
735 StringRef AsmParser::parseStringToComma() {
736 const char *Start = getTok().getLoc().getPointer();
738 while (Lexer.isNot(AsmToken::EndOfStatement) &&
742 const char *End = getTok().getLoc().getPointer();
751 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
752 if (parseExpression(Res))
754 if (Lexer.isNot(AsmToken::RParen))
755 return TokError(
"expected ')' in parentheses expression");
756 EndLoc = Lexer.getTok().getEndLoc();
766 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
767 if (parseExpression(Res))
769 if (Lexer.isNot(AsmToken::RBrac))
770 return TokError(
"expected ']' in brackets expression");
771 EndLoc = Lexer.getTok().getEndLoc();
782 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
783 SMLoc FirstTokenLoc = getLexer().getLoc();
785 switch (FirstTokenKind) {
787 return TokError(
"unknown token in expression");
791 case AsmToken::Exclaim:
793 if (parsePrimaryExpr(Res, EndLoc))
795 Res = MCUnaryExpr::createLNot(Res, getContext());
797 case AsmToken::Dollar:
800 case AsmToken::Identifier: {
802 if (parseIdentifier(Identifier)) {
803 if (FirstTokenKind == AsmToken::Dollar) {
804 if (Lexer.getMAI().getDollarIsPC()) {
809 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None,
811 EndLoc = FirstTokenLoc;
814 return Error(FirstTokenLoc,
"invalid token in expression");
818 std::pair<StringRef, StringRef>
Split;
821 if (Lexer.is(AsmToken::At)) {
823 SMLoc AtLoc = getLexer().getLoc();
825 if (parseIdentifier(VName))
826 return Error(AtLoc,
"expected symbol variant after '@'");
828 Split = std::make_pair(Identifier, VName);
831 Split = Identifier.
split(
'@');
833 }
else if (Lexer.is(AsmToken::LParen)) {
836 parseIdentifier(VName);
837 if (Lexer.isNot(AsmToken::RParen)) {
838 return Error(Lexer.getTok().getLoc(),
839 "unexpected token in variant, expected ')'");
842 Split = std::make_pair(Identifier, VName);
845 EndLoc = SMLoc::getFromPointer(Identifier.
end());
852 if (Split.second.size()) {
853 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
854 if (Variant != MCSymbolRefExpr::VK_Invalid) {
855 SymbolName = Split.first;
857 Variant = MCSymbolRefExpr::VK_None;
859 return Error(SMLoc::getFromPointer(Split.second.begin()),
860 "invalid variant '" + Split.second +
"'");
864 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
870 return Error(EndLoc,
"unexpected modifier on variable reference");
877 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
880 case AsmToken::BigNum:
881 return TokError(
"literal value out of range for directive");
882 case AsmToken::Integer: {
883 SMLoc Loc = getTok().getLoc();
884 int64_t
IntVal = getTok().getIntVal();
885 Res = MCConstantExpr::create(IntVal, getContext());
886 EndLoc = Lexer.getTok().getEndLoc();
889 if (Lexer.getKind() == AsmToken::Identifier) {
892 std::pair<StringRef, StringRef> Split = IDVal.
split(
'@');
894 if (Split.first.size() != IDVal.
size()) {
895 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
896 if (Variant == MCSymbolRefExpr::VK_Invalid)
897 return TokError(
"invalid variant '" + Split.second +
"'");
900 if (IDVal ==
"f" || IDVal ==
"b") {
903 Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
905 return Error(Loc,
"invalid reference to undefined symbol");
906 EndLoc = Lexer.getTok().getEndLoc();
912 case AsmToken::Real: {
914 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
915 Res = MCConstantExpr::create(IntVal, getContext());
916 EndLoc = Lexer.getTok().getEndLoc();
920 case AsmToken::Dot: {
925 Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
926 EndLoc = Lexer.getTok().getEndLoc();
930 case AsmToken::LParen:
932 return parseParenExpr(Res, EndLoc);
933 case AsmToken::LBrac:
934 if (!PlatformParser->HasBracketExpressions())
935 return TokError(
"brackets expression not supported on this target");
937 return parseBracketExpr(Res, EndLoc);
938 case AsmToken::Minus:
940 if (parsePrimaryExpr(Res, EndLoc))
942 Res = MCUnaryExpr::createMinus(Res, getContext());
946 if (parsePrimaryExpr(Res, EndLoc))
948 Res = MCUnaryExpr::createPlus(Res, getContext());
950 case AsmToken::Tilde:
952 if (parsePrimaryExpr(Res, EndLoc))
954 Res = MCUnaryExpr::createNot(Res, getContext());
959 bool AsmParser::parseExpression(
const MCExpr *&Res) {
961 return parseExpression(Res, EndLoc);
965 AsmParser::applyModifierToExpr(
const MCExpr *E,
968 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
978 case MCExpr::SymbolRef: {
981 if (SRE->
getKind() != MCSymbolRefExpr::VK_None) {
982 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
983 "' (already modified)");
987 return MCSymbolRefExpr::create(&SRE->
getSymbol(), Variant, getContext());
990 case MCExpr::Unary: {
995 return MCUnaryExpr::create(UE->
getOpcode(), Sub, getContext());
998 case MCExpr::Binary: {
1000 const MCExpr *LHS = applyModifierToExpr(BE->
getLHS(), Variant);
1001 const MCExpr *RHS = applyModifierToExpr(BE->
getRHS(), Variant);
1011 return MCBinaryExpr::create(BE->
getOpcode(), LHS, RHS, getContext());
1028 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1031 if (parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
1037 if (Lexer.getKind() == AsmToken::At) {
1040 if (Lexer.isNot(AsmToken::Identifier))
1041 return TokError(
"unexpected symbol modifier following '@'");
1044 MCSymbolRefExpr::getVariantKindForName(getTok().getIdentifier());
1045 if (Variant == MCSymbolRefExpr::VK_Invalid)
1046 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
1048 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
1050 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1051 "' (no symbols present)");
1060 if (Res->evaluateAsAbsolute(Value))
1061 Res = MCConstantExpr::create(Value, getContext());
1066 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1068 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1071 bool AsmParser::parseParenExprOfDepth(
unsigned ParenDepth,
const MCExpr *&Res,
1073 if (parseParenExpr(Res, EndLoc))
1076 for (; ParenDepth > 0; --ParenDepth) {
1077 if (parseBinOpRHS(1, Res, EndLoc))
1082 if (ParenDepth - 1 > 0) {
1083 if (Lexer.isNot(AsmToken::RParen))
1084 return TokError(
"expected ')' in parentheses expression");
1085 EndLoc = Lexer.getTok().getEndLoc();
1092 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1095 SMLoc StartLoc = Lexer.getLoc();
1096 if (parseExpression(Expr))
1099 if (!Expr->evaluateAsAbsolute(Res))
1100 return Error(StartLoc,
"expected absolute expression");
1112 case AsmToken::AmpAmp:
1113 Kind = MCBinaryExpr::LAnd;
1115 case AsmToken::PipePipe:
1116 Kind = MCBinaryExpr::LOr;
1122 case AsmToken::Pipe:
1125 case AsmToken::Caret:
1133 case AsmToken::EqualEqual:
1136 case AsmToken::ExclaimEqual:
1137 case AsmToken::LessGreater:
1143 case AsmToken::LessEqual:
1144 Kind = MCBinaryExpr::LTE;
1146 case AsmToken::Greater:
1149 case AsmToken::GreaterEqual:
1150 Kind = MCBinaryExpr::GTE;
1154 case AsmToken::LessLess:
1155 Kind = MCBinaryExpr::Shl;
1157 case AsmToken::GreaterGreater:
1162 case AsmToken::Plus:
1163 Kind = MCBinaryExpr::Add;
1165 case AsmToken::Minus:
1166 Kind = MCBinaryExpr::Sub;
1170 case AsmToken::Star:
1171 Kind = MCBinaryExpr::Mul;
1173 case AsmToken::Slash:
1174 Kind = MCBinaryExpr::Div;
1176 case AsmToken::Percent:
1177 Kind = MCBinaryExpr::Mod;
1184 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1188 unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(),
Kind);
1192 if (TokPrec < Precedence)
1199 if (parsePrimaryExpr(RHS, EndLoc))
1205 unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(),
Dummy);
1206 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1210 Res = MCBinaryExpr::create(Kind, Res, RHS, getContext());
1218 bool AsmParser::parseStatement(ParseStatementInfo &Info,
1220 if (Lexer.is(AsmToken::EndOfStatement)) {
1230 int64_t LocalLabelVal = -1;
1233 return parseCppHashLineFilenameComment(IDLoc);
1236 if (Lexer.is(AsmToken::Integer)) {
1237 LocalLabelVal = getTok().getIntVal();
1238 if (LocalLabelVal < 0) {
1239 if (!TheCondState.Ignore)
1240 return TokError(
"unexpected token at start of statement");
1243 IDVal = getTok().getString();
1245 if (Lexer.getKind() != AsmToken::Colon) {
1246 if (!TheCondState.Ignore)
1247 return TokError(
"unexpected token at start of statement");
1250 }
else if (Lexer.is(AsmToken::Dot)) {
1254 }
else if (parseIdentifier(IDVal)) {
1255 if (!TheCondState.Ignore)
1256 return TokError(
"unexpected token at start of statement");
1264 DirectiveKindMap.find(IDVal);
1265 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1278 return parseDirectiveIf(IDLoc, DirKind);
1280 return parseDirectiveIfb(IDLoc,
true);
1282 return parseDirectiveIfb(IDLoc,
false);
1284 return parseDirectiveIfc(IDLoc,
true);
1286 return parseDirectiveIfeqs(IDLoc,
true);
1288 return parseDirectiveIfc(IDLoc,
false);
1290 return parseDirectiveIfeqs(IDLoc,
false);
1292 return parseDirectiveIfdef(IDLoc,
true);
1295 return parseDirectiveIfdef(IDLoc,
false);
1297 return parseDirectiveElseIf(IDLoc);
1299 return parseDirectiveElse(IDLoc);
1301 return parseDirectiveEndIf(IDLoc);
1306 if (TheCondState.Ignore) {
1307 eatToEndOfStatement();
1314 switch (Lexer.getKind()) {
1315 case AsmToken::Colon: {
1316 checkForValidSection();
1323 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1331 if (LocalLabelVal == -1) {
1332 if (ParsingInlineAsm && SI) {
1335 assert(RewrittenLabel.
size() &&
1336 "We should have an internal name here.");
1338 IDVal.
size(), RewrittenLabel));
1339 IDVal = RewrittenLabel;
1341 Sym = getContext().getOrCreateSymbol(IDVal);
1348 return Error(IDLoc,
"invalid symbol redefinition");
1351 if (!ParsingInlineAsm)
1356 if (getContext().getGenDwarfForAssembly())
1357 MCGenDwarfLabelEntry::Make(Sym, &getStreamer(), getSourceManager(),
1360 getTargetParser().onLabelParsed(Sym);
1364 if (Lexer.is(AsmToken::EndOfStatement)) {
1373 case AsmToken::Equal:
1377 return parseAssignment(IDVal,
true);
1384 if (areMacrosEnabled())
1385 if (
const MCAsmMacro *M = lookupMacro(IDVal)) {
1386 return handleMacroEntry(M, IDLoc);
1392 if (IDVal[0] ==
'.' && IDVal !=
".") {
1406 if (!getTargetParser().ParseDirective(ID))
1411 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1412 ExtensionDirectiveMap.lookup(IDVal);
1414 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1423 return parseDirectiveSet(IDVal,
true);
1425 return parseDirectiveSet(IDVal,
false);
1427 return parseDirectiveAscii(IDVal,
false);
1430 return parseDirectiveAscii(IDVal,
true);
1432 return parseDirectiveValue(1);
1436 return parseDirectiveValue(2);
1440 return parseDirectiveValue(4);
1443 return parseDirectiveValue(8);
1445 return parseDirectiveOctaValue();
1448 return parseDirectiveRealValue(APFloat::IEEEsingle);
1450 return parseDirectiveRealValue(APFloat::IEEEdouble);
1452 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1453 return parseDirectiveAlign(IsPow2, 1);
1456 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1457 return parseDirectiveAlign(IsPow2, 4);
1460 return parseDirectiveAlign(
false, 1);
1462 return parseDirectiveAlign(
false, 2);
1464 return parseDirectiveAlign(
false, 4);
1466 return parseDirectiveAlign(
true, 1);
1468 return parseDirectiveAlign(
true, 2);
1470 return parseDirectiveAlign(
true, 4);
1472 return parseDirectiveOrg();
1474 return parseDirectiveFill();
1476 return parseDirectiveZero();
1478 eatToEndOfStatement();
1482 return parseDirectiveSymbolAttribute(
MCSA_Global);
1483 case DK_LAZY_REFERENCE:
1485 case DK_NO_DEAD_STRIP:
1487 case DK_SYMBOL_RESOLVER:
1489 case DK_PRIVATE_EXTERN:
1493 case DK_WEAK_DEFINITION:
1495 case DK_WEAK_REFERENCE:
1497 case DK_WEAK_DEF_CAN_BE_HIDDEN:
1501 return parseDirectiveComm(
false);
1503 return parseDirectiveComm(
true);
1505 return parseDirectiveAbort();
1507 return parseDirectiveInclude();
1509 return parseDirectiveIncbin();
1512 return TokError(
Twine(IDVal) +
" not supported yet");
1514 return parseDirectiveRept(IDLoc, IDVal);
1516 return parseDirectiveIrp(IDLoc);
1518 return parseDirectiveIrpc(IDLoc);
1520 return parseDirectiveEndr(IDLoc);
1521 case DK_BUNDLE_ALIGN_MODE:
1522 return parseDirectiveBundleAlignMode();
1523 case DK_BUNDLE_LOCK:
1524 return parseDirectiveBundleLock();
1525 case DK_BUNDLE_UNLOCK:
1526 return parseDirectiveBundleUnlock();
1528 return parseDirectiveLEB128(
true);
1530 return parseDirectiveLEB128(
false);
1533 return parseDirectiveSpace(IDVal);
1535 return parseDirectiveFile(IDLoc);
1537 return parseDirectiveLine();
1539 return parseDirectiveLoc();
1541 return parseDirectiveStabs();
1542 case DK_CFI_SECTIONS:
1543 return parseDirectiveCFISections();
1544 case DK_CFI_STARTPROC:
1545 return parseDirectiveCFIStartProc();
1546 case DK_CFI_ENDPROC:
1547 return parseDirectiveCFIEndProc();
1548 case DK_CFI_DEF_CFA:
1549 return parseDirectiveCFIDefCfa(IDLoc);
1550 case DK_CFI_DEF_CFA_OFFSET:
1551 return parseDirectiveCFIDefCfaOffset();
1552 case DK_CFI_ADJUST_CFA_OFFSET:
1553 return parseDirectiveCFIAdjustCfaOffset();
1554 case DK_CFI_DEF_CFA_REGISTER:
1555 return parseDirectiveCFIDefCfaRegister(IDLoc);
1557 return parseDirectiveCFIOffset(IDLoc);
1558 case DK_CFI_REL_OFFSET:
1559 return parseDirectiveCFIRelOffset(IDLoc);
1560 case DK_CFI_PERSONALITY:
1561 return parseDirectiveCFIPersonalityOrLsda(
true);
1563 return parseDirectiveCFIPersonalityOrLsda(
false);
1564 case DK_CFI_REMEMBER_STATE:
1565 return parseDirectiveCFIRememberState();
1566 case DK_CFI_RESTORE_STATE:
1567 return parseDirectiveCFIRestoreState();
1568 case DK_CFI_SAME_VALUE:
1569 return parseDirectiveCFISameValue(IDLoc);
1570 case DK_CFI_RESTORE:
1571 return parseDirectiveCFIRestore(IDLoc);
1573 return parseDirectiveCFIEscape();
1574 case DK_CFI_SIGNAL_FRAME:
1575 return parseDirectiveCFISignalFrame();
1576 case DK_CFI_UNDEFINED:
1577 return parseDirectiveCFIUndefined(IDLoc);
1578 case DK_CFI_REGISTER:
1579 return parseDirectiveCFIRegister(IDLoc);
1580 case DK_CFI_WINDOW_SAVE:
1581 return parseDirectiveCFIWindowSave();
1584 return parseDirectiveMacrosOnOff(IDVal);
1586 return parseDirectiveMacro(IDLoc);
1588 return parseDirectiveExitMacro(IDVal);
1591 return parseDirectiveEndMacro(IDVal);
1593 return parseDirectivePurgeMacro(IDLoc);
1595 return parseDirectiveEnd(IDLoc);
1597 return parseDirectiveError(IDLoc,
false);
1599 return parseDirectiveError(IDLoc,
true);
1601 return parseDirectiveWarning(IDLoc);
1604 return Error(IDLoc,
"unknown directive");
1608 if (ParsingInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
1609 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
1610 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
1613 if (ParsingInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
1614 return parseDirectiveMSAlign(IDLoc, Info);
1616 checkForValidSection();
1619 std::string OpcodeStr = IDVal.
lower();
1621 bool HadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, IDLoc,
1622 Info.ParsedOperands);
1623 Info.ParseError = HadError;
1626 if (getShowParsedOperands()) {
1629 OS <<
"parsed instruction: [";
1630 for (
unsigned i = 0; i != Info.ParsedOperands.size(); ++i) {
1633 Info.ParsedOperands[i]->print(OS);
1637 printMessage(IDLoc, SourceMgr::DK_Note, OS.str());
1642 if (!HadError && getContext().getGenDwarfForAssembly() &&
1643 getContext().getGenDwarfSectionSyms().count(
1644 getStreamer().getCurrentSection().first)) {
1646 if (ActiveMacros.empty())
1650 ActiveMacros.front()->ExitBuffer);
1655 if (CppHashFilename.size()) {
1656 unsigned FileNumber = getStreamer().EmitDwarfFileDirective(
1658 getContext().setGenDwarfFileNumber(FileNumber);
1663 unsigned CppHashLocLineNo;
1664 if (LastQueryIDLoc == CppHashLoc && LastQueryBuffer == CppHashBuf)
1665 CppHashLocLineNo = LastQueryLine;
1668 LastQueryLine = CppHashLocLineNo;
1669 LastQueryIDLoc = CppHashLoc;
1670 LastQueryBuffer = CppHashBuf;
1672 Line = CppHashLineNumber - 1 + (Line - CppHashLocLineNo);
1675 getStreamer().EmitDwarfLocDirective(
1676 getContext().getGenDwarfFileNumber(), Line, 0,
1684 getTargetParser().MatchAndEmitInstruction(IDLoc, Info.Opcode,
1685 Info.ParsedOperands, Out,
1686 ErrorInfo, ParsingInlineAsm);
1696 void AsmParser::eatToEndOfLine() {
1697 if (!Lexer.is(AsmToken::EndOfStatement))
1698 Lexer.LexUntilEndOfLine();
1706 bool AsmParser::parseCppHashLineFilenameComment(
const SMLoc &L) {
1709 if (getLexer().isNot(AsmToken::Integer)) {
1716 int64_t LineNumber = getTok().getIntVal();
1724 StringRef Filename = getTok().getString();
1726 Filename = Filename.
substr(1, Filename.
size() - 2);
1730 CppHashFilename = Filename;
1731 CppHashLineNumber = LineNumber;
1732 CppHashBuf = CurBuffer;
1741 void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *Context) {
1742 const AsmParser *Parser =
static_cast<const AsmParser *
>(Context);
1748 unsigned CppHashBuf =
1749 Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashLoc);
1754 if (!Parser->SavedDiagHandler && DiagCurBuffer &&
1763 if (!Parser->CppHashLineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
1764 DiagBuf != CppHashBuf) {
1765 if (Parser->SavedDiagHandler)
1766 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
1768 Diag.
print(
nullptr, OS);
1775 const std::string &Filename = Parser->CppHashFilename;
1778 int CppHashLocLineNo =
1779 Parser->SrcMgr.FindLineNumber(Parser->CppHashLoc, CppHashBuf);
1781 Parser->CppHashLineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
1787 if (Parser->SavedDiagHandler)
1788 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
1790 NewDiag.print(
nullptr, OS);
1798 return isalnum(static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
1805 bool EnableAtPseudoVariable,
const SMLoc &L) {
1806 unsigned NParameters = Parameters.
size();
1807 bool HasVararg = NParameters ? Parameters.
back().Vararg :
false;
1808 if ((!IsDarwin || NParameters != 0) && NParameters != A.
size())
1809 return Error(L,
"Wrong number of arguments");
1813 while (!Body.
empty()) {
1815 std::size_t End = Body.
size(), Pos = 0;
1816 for (; Pos != End; ++Pos) {
1818 if (IsDarwin && !NParameters) {
1820 if (Body[Pos] !=
'$' || Pos + 1 == End)
1823 char Next = Body[Pos + 1];
1824 if (Next ==
'$' || Next ==
'n' ||
1825 isdigit(static_cast<unsigned char>(Next)))
1829 if (Body[Pos] ==
'\\' && Pos + 1 != End)
1835 OS << Body.
slice(0, Pos);
1841 if (IsDarwin && !NParameters) {
1842 switch (Body[Pos + 1]) {
1856 unsigned Index = Body[Pos + 1] -
'0';
1857 if (Index >= A.
size())
1861 for (MCAsmMacroArgument::const_iterator it = A[Index].
begin(),
1862 ie = A[Index].
end();
1864 OS << it->getString();
1870 unsigned I = Pos + 1;
1873 if (EnableAtPseudoVariable && Body[I] ==
'@' && I + 1 != End)
1879 const char *Begin = Body.
data() + Pos + 1;
1884 OS << NumOfMacroInstantiations;
1887 for (; Index < NParameters; ++Index)
1891 if (Index == NParameters) {
1892 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
1899 bool VarargParameter = HasVararg && Index == (NParameters - 1);
1900 for (MCAsmMacroArgument::const_iterator it = A[Index].
begin(),
1901 ie = A[Index].
end();
1906 OS << it->getString();
1908 OS << it->getStringContents();
1921 MacroInstantiation::MacroInstantiation(
SMLoc IL,
int EB,
SMLoc EL,
1922 size_t CondStackDepth)
1923 : InstantiationLoc(IL), ExitBuffer(EB), ExitLoc(EL),
1924 CondStackDepth(CondStackDepth) {}
1930 case AsmToken::Plus:
1931 case AsmToken::Minus:
1932 case AsmToken::Tilde:
1933 case AsmToken::Slash:
1934 case AsmToken::Star:
1936 case AsmToken::Equal:
1937 case AsmToken::EqualEqual:
1938 case AsmToken::Pipe:
1939 case AsmToken::PipePipe:
1940 case AsmToken::Caret:
1942 case AsmToken::AmpAmp:
1943 case AsmToken::Exclaim:
1944 case AsmToken::ExclaimEqual:
1945 case AsmToken::Percent:
1947 case AsmToken::LessEqual:
1948 case AsmToken::LessLess:
1949 case AsmToken::LessGreater:
1950 case AsmToken::Greater:
1951 case AsmToken::GreaterEqual:
1952 case AsmToken::GreaterGreater:
1958 class AsmLexerSkipSpaceRAII {
1960 AsmLexerSkipSpaceRAII(
AsmLexer &Lexer,
bool SkipSpace) : Lexer(Lexer) {
1964 ~AsmLexerSkipSpaceRAII() {
1973 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
bool Vararg) {
1976 if (Lexer.isNot(AsmToken::EndOfStatement)) {
1977 StringRef Str = parseStringToEndOfStatement();
1983 unsigned ParenLevel = 0;
1984 unsigned AddTokens = 0;
1987 AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
1991 return TokError(
"unexpected token in macro instantiation");
1993 if (ParenLevel == 0 && Lexer.is(AsmToken::Comma))
1996 if (Lexer.is(AsmToken::Space)) {
2006 const char *NextChar = getTok().getEndLoc().getPointer();
2007 if (*NextChar ==
' ')
2011 if (!AddTokens && ParenLevel == 0) {
2019 if (Lexer.is(AsmToken::EndOfStatement))
2023 if (Lexer.is(AsmToken::LParen))
2025 else if (Lexer.is(AsmToken::RParen) && ParenLevel)
2029 MA.push_back(getTok());
2035 if (ParenLevel != 0)
2036 return TokError(
"unbalanced parentheses in macro argument");
2041 bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
2042 MCAsmMacroArguments &A) {
2043 const unsigned NParameters = M ? M->Parameters.size() : 0;
2044 bool NamedParametersFound =
false;
2048 FALocs.
resize(NParameters);
2053 bool HasVararg = NParameters ? M->Parameters.back().Vararg :
false;
2054 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
2056 SMLoc IDLoc = Lexer.getLoc();
2057 MCAsmMacroParameter FA;
2059 if (Lexer.is(AsmToken::Identifier) && Lexer.peekTok().is(AsmToken::Equal)) {
2060 if (parseIdentifier(FA.Name)) {
2061 Error(IDLoc,
"invalid argument identifier for formal argument");
2062 eatToEndOfStatement();
2066 if (!Lexer.is(AsmToken::Equal)) {
2067 TokError(
"expected '=' after formal parameter identifier");
2068 eatToEndOfStatement();
2073 NamedParametersFound =
true;
2076 if (NamedParametersFound && FA.Name.empty()) {
2077 Error(IDLoc,
"cannot mix positional and keyword arguments");
2078 eatToEndOfStatement();
2082 bool Vararg = HasVararg && Parameter == (NParameters - 1);
2083 if (parseMacroArgument(FA.Value, Vararg))
2086 unsigned PI = Parameter;
2087 if (!FA.Name.empty()) {
2089 for (FAI = 0; FAI < NParameters; ++FAI)
2090 if (M->Parameters[FAI].Name == FA.Name)
2093 if (FAI >= NParameters) {
2094 assert(M &&
"expected macro to be defined");
2096 "parameter named '" + FA.Name +
"' does not exist for macro '" +
2103 if (!FA.Value.empty()) {
2108 if (FALocs.
size() <= PI)
2111 FALocs[PI] = Lexer.getLoc();
2117 if (Lexer.is(AsmToken::EndOfStatement)) {
2118 bool Failure =
false;
2119 for (
unsigned FAI = 0; FAI < NParameters; ++FAI) {
2120 if (A[FAI].empty()) {
2121 if (M->Parameters[FAI].Required) {
2122 Error(FALocs[FAI].isValid() ? FALocs[FAI] : Lexer.getLoc(),
2123 "missing value for required parameter "
2124 "'" + M->Parameters[FAI].Name +
"' in macro '" + M->Name +
"'");
2128 if (!M->Parameters[FAI].Value.empty())
2129 A[FAI] = M->Parameters[FAI].Value;
2135 if (Lexer.is(AsmToken::Comma))
2139 return TokError(
"too many positional arguments");
2144 return (I == MacroMap.end()) ?
nullptr : &I->getValue();
2147 void AsmParser::defineMacro(
StringRef Name, MCAsmMacro Macro) {
2148 MacroMap.insert(std::make_pair(Name, std::move(Macro)));
2151 void AsmParser::undefineMacro(
StringRef Name) { MacroMap.erase(Name); }
2153 bool AsmParser::handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc) {
2156 if (ActiveMacros.size() == 20)
2157 return TokError(
"macros cannot be nested more than 20 levels deep");
2159 MCAsmMacroArguments
A;
2160 if (parseMacroArguments(M, A))
2169 if (expandMacro(OS, Body, M->Parameters, A,
true, getTok().getLoc()))
2174 OS <<
".endmacro\n";
2176 std::unique_ptr<MemoryBuffer> Instantiation =
2177 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
2181 MacroInstantiation *
MI =
new MacroInstantiation(
2182 NameLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
2183 ActiveMacros.push_back(MI);
2185 ++NumOfMacroInstantiations;
2195 void AsmParser::handleMacroExit() {
2197 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2201 delete ActiveMacros.back();
2202 ActiveMacros.pop_back();
2205 bool AsmParser::parseAssignment(
StringRef Name,
bool allow_redef,
2231 bool AsmParser::parseIdentifier(
StringRef &Res) {
2237 if (Lexer.is(AsmToken::Dollar) || Lexer.is(AsmToken::At)) {
2238 SMLoc PrefixLoc = getLexer().getLoc();
2242 if (Lexer.isNot(AsmToken::Identifier))
2246 if (PrefixLoc.
getPointer() + 1 != getTok().getLoc().getPointer())
2259 Res = getTok().getIdentifier();
2270 bool AsmParser::parseDirectiveSet(
StringRef IDVal,
bool allow_redef) {
2273 if (parseIdentifier(Name))
2274 return TokError(
"expected identifier after '" +
Twine(IDVal) +
"'");
2276 if (getLexer().isNot(AsmToken::Comma))
2277 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"'");
2280 return parseAssignment(Name, allow_redef,
true);
2283 bool AsmParser::parseEscapedString(std::string &Data) {
2287 StringRef Str = getTok().getStringContents();
2288 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
2289 if (Str[i] !=
'\\') {
2298 return TokError(
"unexpected backslash at end of string");
2301 if ((
unsigned)(Str[i] -
'0') <= 7) {
2303 unsigned Value = Str[i] -
'0';
2305 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2307 Value = Value * 8 + (Str[i] -
'0');
2309 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2311 Value = Value * 8 + (Str[i] -
'0');
2316 return TokError(
"invalid octal escape sequence (out of range)");
2318 Data += (
unsigned char)Value;
2326 return TokError(
"invalid escape sequence (unrecognized character)");
2328 case 'b': Data +=
'\b';
break;
2329 case 'f': Data +=
'\f';
break;
2330 case 'n': Data +=
'\n';
break;
2331 case 'r': Data +=
'\r';
break;
2332 case 't': Data +=
'\t';
break;
2333 case '"': Data +=
'"';
break;
2334 case '\\': Data +=
'\\';
break;
2343 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
2344 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2345 checkForValidSection();
2349 return TokError(
"expected string in '" +
Twine(IDVal) +
"' directive");
2352 if (parseEscapedString(Data))
2355 getStreamer().EmitBytes(Data);
2357 getStreamer().EmitBytes(
StringRef(
"\0", 1));
2361 if (getLexer().is(AsmToken::EndOfStatement))
2364 if (getLexer().isNot(AsmToken::Comma))
2365 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
2376 bool AsmParser::parseDirectiveValue(
unsigned Size) {
2377 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2378 checkForValidSection();
2382 SMLoc ExprLoc = getLexer().getLoc();
2383 if (parseExpression(Value))
2387 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2388 assert(Size <= 8 &&
"Invalid size");
2389 uint64_t IntValue = MCE->getValue();
2390 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
2391 return Error(ExprLoc,
"literal value out of range for directive");
2392 getStreamer().EmitIntValue(IntValue, Size);
2394 getStreamer().EmitValue(Value, Size, ExprLoc);
2396 if (getLexer().is(AsmToken::EndOfStatement))
2400 if (getLexer().isNot(AsmToken::Comma))
2401 return TokError(
"unexpected token in directive");
2412 bool AsmParser::parseDirectiveOctaValue() {
2413 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2414 checkForValidSection();
2419 if (Lexer.getKind() != AsmToken::Integer &&
2420 Lexer.getKind() != AsmToken::BigNum)
2421 return TokError(
"unknown token in expression");
2423 SMLoc ExprLoc = getLexer().getLoc();
2424 APInt IntValue = getTok().getAPIntVal();
2428 if (IntValue.
isIntN(64)) {
2431 }
else if (IntValue.
isIntN(128)) {
2436 return Error(ExprLoc,
"literal value out of range for directive");
2439 getStreamer().EmitIntValue(lo, 8);
2440 getStreamer().EmitIntValue(hi, 8);
2442 getStreamer().EmitIntValue(hi, 8);
2443 getStreamer().EmitIntValue(lo, 8);
2446 if (getLexer().is(AsmToken::EndOfStatement))
2450 if (getLexer().isNot(AsmToken::Comma))
2451 return TokError(
"unexpected token in directive");
2462 bool AsmParser::parseDirectiveRealValue(
const fltSemantics &Semantics) {
2463 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2464 checkForValidSection();
2470 if (getLexer().is(AsmToken::Minus)) {
2473 }
else if (getLexer().is(AsmToken::Plus))
2476 if (getLexer().isNot(AsmToken::Integer) &&
2477 getLexer().isNot(AsmToken::Real) &&
2478 getLexer().isNot(AsmToken::Identifier))
2479 return TokError(
"unexpected token in directive");
2484 if (getLexer().is(AsmToken::Identifier)) {
2486 Value = APFloat::getInf(Semantics);
2488 Value = APFloat::getNaN(Semantics,
false, ~0);
2490 return TokError(
"invalid floating point literal");
2491 }
else if (Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven) ==
2492 APFloat::opInvalidOp)
2493 return TokError(
"invalid floating point literal");
2501 APInt AsInt = Value.bitcastToAPInt();
2505 if (getLexer().is(AsmToken::EndOfStatement))
2508 if (getLexer().isNot(AsmToken::Comma))
2509 return TokError(
"unexpected token in directive");
2520 bool AsmParser::parseDirectiveZero() {
2521 checkForValidSection();
2524 if (parseAbsoluteExpression(NumBytes))
2528 if (getLexer().is(AsmToken::Comma)) {
2530 if (parseAbsoluteExpression(Val))
2534 if (getLexer().isNot(AsmToken::EndOfStatement))
2535 return TokError(
"unexpected token in '.zero' directive");
2539 getStreamer().EmitFill(NumBytes, Val);
2546 bool AsmParser::parseDirectiveFill() {
2547 checkForValidSection();
2549 SMLoc RepeatLoc = getLexer().getLoc();
2551 if (parseAbsoluteExpression(NumValues))
2554 if (NumValues < 0) {
2556 "'.fill' directive with negative repeat count has no effect");
2560 int64_t FillSize = 1;
2561 int64_t FillExpr = 0;
2563 SMLoc SizeLoc, ExprLoc;
2564 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2565 if (getLexer().isNot(AsmToken::Comma))
2566 return TokError(
"unexpected token in '.fill' directive");
2569 SizeLoc = getLexer().getLoc();
2570 if (parseAbsoluteExpression(FillSize))
2573 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2574 if (getLexer().isNot(AsmToken::Comma))
2575 return TokError(
"unexpected token in '.fill' directive");
2578 ExprLoc = getLexer().getLoc();
2579 if (parseAbsoluteExpression(FillExpr))
2582 if (getLexer().isNot(AsmToken::EndOfStatement))
2583 return TokError(
"unexpected token in '.fill' directive");
2590 Warning(SizeLoc,
"'.fill' directive with negative size has no effect");
2594 Warning(SizeLoc,
"'.fill' directive with size greater than 8 has been truncated to 8");
2599 Warning(ExprLoc,
"'.fill' directive pattern has been truncated to 32-bits");
2601 if (NumValues > 0) {
2602 int64_t NonZeroFillSize = FillSize > 4 ? 4 : FillSize;
2603 FillExpr &= ~0ULL >> (64 - NonZeroFillSize * 8);
2604 for (uint64_t i = 0, e = NumValues; i != e; ++i) {
2605 getStreamer().EmitIntValue(FillExpr, NonZeroFillSize);
2606 if (NonZeroFillSize < FillSize)
2607 getStreamer().EmitIntValue(0, FillSize - NonZeroFillSize);
2616 bool AsmParser::parseDirectiveOrg() {
2617 checkForValidSection();
2620 SMLoc Loc = getTok().getLoc();
2621 if (parseExpression(Offset))
2625 int64_t FillExpr = 0;
2626 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2627 if (getLexer().isNot(AsmToken::Comma))
2628 return TokError(
"unexpected token in '.org' directive");
2631 if (parseAbsoluteExpression(FillExpr))
2634 if (getLexer().isNot(AsmToken::EndOfStatement))
2635 return TokError(
"unexpected token in '.org' directive");
2643 if (getStreamer().EmitValueToOffset(Offset, FillExpr))
2644 return Error(Loc,
"expected assembly-time absolute expression");
2651 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
2652 checkForValidSection();
2654 SMLoc AlignmentLoc = getLexer().getLoc();
2656 if (parseAbsoluteExpression(Alignment))
2660 bool HasFillExpr =
false;
2661 int64_t FillExpr = 0;
2662 int64_t MaxBytesToFill = 0;
2663 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2664 if (getLexer().isNot(AsmToken::Comma))
2665 return TokError(
"unexpected token in directive");
2671 if (getLexer().isNot(AsmToken::Comma)) {
2673 if (parseAbsoluteExpression(FillExpr))
2677 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2678 if (getLexer().isNot(AsmToken::Comma))
2679 return TokError(
"unexpected token in directive");
2682 MaxBytesLoc = getLexer().getLoc();
2683 if (parseAbsoluteExpression(MaxBytesToFill))
2686 if (getLexer().isNot(AsmToken::EndOfStatement))
2687 return TokError(
"unexpected token in directive");
2699 if (Alignment >= 32) {
2700 Error(AlignmentLoc,
"invalid alignment value");
2704 Alignment = 1ULL << Alignment;
2708 Error(AlignmentLoc,
"alignment must be a power of 2");
2713 if (MaxBytesToFill < 1) {
2714 Error(MaxBytesLoc,
"alignment directive can never be satisfied in this "
2715 "many bytes, ignoring maximum bytes expression");
2719 if (MaxBytesToFill >= Alignment) {
2720 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
2729 assert(Section &&
"must have section to emit alignment");
2731 if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) &&
2732 ValueSize == 1 && UseCodeAlign) {
2733 getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
2736 getStreamer().EmitValueToAlignment(Alignment, FillExpr, ValueSize,
2746 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
2748 int64_t FileNumber = -1;
2749 SMLoc FileNumberLoc = getLexer().getLoc();
2750 if (getLexer().is(AsmToken::Integer)) {
2751 FileNumber = getTok().getIntVal();
2755 return TokError(
"file number less than one");
2759 return TokError(
"unexpected token in '.file' directive");
2763 std::string Path = getTok().getString();
2764 if (parseEscapedString(Path))
2770 std::string FilenameData;
2772 if (FileNumber == -1)
2773 return TokError(
"explicit path specified, but no file number");
2774 if (parseEscapedString(FilenameData))
2776 Filename = FilenameData;
2783 if (getLexer().isNot(AsmToken::EndOfStatement))
2784 return TokError(
"unexpected token in '.file' directive");
2786 if (FileNumber == -1)
2787 getStreamer().EmitFileDirective(Filename);
2789 if (getContext().getGenDwarfForAssembly())
2791 "input can't have .file dwarf directives when -g is "
2792 "used to generate dwarf debug info for assembly code");
2794 if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename) ==
2796 Error(FileNumberLoc,
"file number already allocated");
2804 bool AsmParser::parseDirectiveLine() {
2805 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2806 if (getLexer().isNot(AsmToken::Integer))
2807 return TokError(
"unexpected token in '.line' directive");
2809 int64_t LineNumber = getTok().getIntVal();
2816 if (getLexer().isNot(AsmToken::EndOfStatement))
2817 return TokError(
"unexpected token in '.line' directive");
2829 bool AsmParser::parseDirectiveLoc() {
2830 if (getLexer().isNot(AsmToken::Integer))
2831 return TokError(
"unexpected token in '.loc' directive");
2832 int64_t FileNumber = getTok().getIntVal();
2834 return TokError(
"file number less than one in '.loc' directive");
2835 if (!getContext().isValidDwarfFileNumber(FileNumber))
2836 return TokError(
"unassigned file number in '.loc' directive");
2839 int64_t LineNumber = 0;
2840 if (getLexer().is(AsmToken::Integer)) {
2841 LineNumber = getTok().getIntVal();
2843 return TokError(
"line number less than zero in '.loc' directive");
2847 int64_t ColumnPos = 0;
2848 if (getLexer().is(AsmToken::Integer)) {
2849 ColumnPos = getTok().getIntVal();
2851 return TokError(
"column position less than zero in '.loc' directive");
2857 int64_t Discriminator = 0;
2858 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2860 if (getLexer().is(AsmToken::EndOfStatement))
2864 SMLoc Loc = getTok().getLoc();
2865 if (parseIdentifier(Name))
2866 return TokError(
"unexpected token in '.loc' directive");
2868 if (Name ==
"basic_block")
2870 else if (Name ==
"prologue_end")
2872 else if (Name ==
"epilogue_begin")
2874 else if (Name ==
"is_stmt") {
2875 Loc = getTok().getLoc();
2877 if (parseExpression(Value))
2880 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2881 int Value = MCE->getValue();
2883 Flags &= ~DWARF2_FLAG_IS_STMT;
2884 else if (Value == 1)
2887 return Error(Loc,
"is_stmt value not 0 or 1");
2889 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
2891 }
else if (Name ==
"isa") {
2892 Loc = getTok().getLoc();
2894 if (parseExpression(Value))
2897 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2898 int Value = MCE->getValue();
2900 return Error(Loc,
"isa number less than zero");
2903 return Error(Loc,
"isa number not a constant value");
2905 }
else if (Name ==
"discriminator") {
2906 if (parseAbsoluteExpression(Discriminator))
2909 return Error(Loc,
"unknown sub-directive in '.loc' directive");
2912 if (getLexer().is(AsmToken::EndOfStatement))
2917 getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
2925 bool AsmParser::parseDirectiveStabs() {
2926 return TokError(
"unsupported directive '.stabs'");
2931 bool AsmParser::parseDirectiveCFISections() {
2936 if (parseIdentifier(Name))
2937 return TokError(
"Expected an identifier");
2939 if (Name ==
".eh_frame")
2941 else if (Name ==
".debug_frame")
2944 if (getLexer().is(AsmToken::Comma)) {
2947 if (parseIdentifier(Name))
2948 return TokError(
"Expected an identifier");
2950 if (Name ==
".eh_frame")
2952 else if (Name ==
".debug_frame")
2956 getStreamer().EmitCFISections(EH, Debug);
2962 bool AsmParser::parseDirectiveCFIStartProc() {
2964 if (getLexer().isNot(AsmToken::EndOfStatement))
2965 if (parseIdentifier(Simple) || Simple !=
"simple")
2966 return TokError(
"unexpected token in .cfi_startproc directive");
2968 getStreamer().EmitCFIStartProc(!Simple.
empty());
2974 bool AsmParser::parseDirectiveCFIEndProc() {
2975 getStreamer().EmitCFIEndProc();
2980 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
2981 SMLoc DirectiveLoc) {
2984 if (getLexer().isNot(AsmToken::Integer)) {
2985 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
2987 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
2989 return parseAbsoluteExpression(Register);
2996 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
2997 int64_t Register = 0;
2998 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3001 if (getLexer().isNot(AsmToken::Comma))
3002 return TokError(
"unexpected token in directive");
3006 if (parseAbsoluteExpression(Offset))
3009 getStreamer().EmitCFIDefCfa(Register, Offset);
3015 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
3017 if (parseAbsoluteExpression(Offset))
3020 getStreamer().EmitCFIDefCfaOffset(Offset);
3026 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
3027 int64_t Register1 = 0;
3028 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc))
3031 if (getLexer().isNot(AsmToken::Comma))
3032 return TokError(
"unexpected token in directive");
3035 int64_t Register2 = 0;
3036 if (parseRegisterOrRegisterNumber(Register2, DirectiveLoc))
3039 getStreamer().EmitCFIRegister(Register1, Register2);
3045 bool AsmParser::parseDirectiveCFIWindowSave() {
3046 getStreamer().EmitCFIWindowSave();
3052 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
3053 int64_t Adjustment = 0;
3054 if (parseAbsoluteExpression(Adjustment))
3057 getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
3063 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
3064 int64_t Register = 0;
3065 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3068 getStreamer().EmitCFIDefCfaRegister(Register);
3074 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
3075 int64_t Register = 0;
3078 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3081 if (getLexer().isNot(AsmToken::Comma))
3082 return TokError(
"unexpected token in directive");
3085 if (parseAbsoluteExpression(Offset))
3088 getStreamer().EmitCFIOffset(Register, Offset);
3094 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
3095 int64_t Register = 0;
3097 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3100 if (getLexer().isNot(AsmToken::Comma))
3101 return TokError(
"unexpected token in directive");
3105 if (parseAbsoluteExpression(Offset))
3108 getStreamer().EmitCFIRelOffset(Register, Offset);
3113 if (Encoding & ~0xff)
3119 const unsigned Format = Encoding & 0xf;
3126 const unsigned Application = Encoding & 0x70;
3138 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
3139 int64_t Encoding = 0;
3140 if (parseAbsoluteExpression(Encoding))
3146 return TokError(
"unsupported encoding.");
3148 if (getLexer().isNot(AsmToken::Comma))
3149 return TokError(
"unexpected token in directive");
3153 if (parseIdentifier(Name))
3154 return TokError(
"expected identifier in directive");
3156 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
3159 getStreamer().EmitCFIPersonality(Sym, Encoding);
3161 getStreamer().EmitCFILsda(Sym, Encoding);
3167 bool AsmParser::parseDirectiveCFIRememberState() {
3168 getStreamer().EmitCFIRememberState();
3174 bool AsmParser::parseDirectiveCFIRestoreState() {
3175 getStreamer().EmitCFIRestoreState();
3181 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
3182 int64_t Register = 0;
3184 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3187 getStreamer().EmitCFISameValue(Register);
3193 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
3194 int64_t Register = 0;
3195 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3198 getStreamer().EmitCFIRestore(Register);
3204 bool AsmParser::parseDirectiveCFIEscape() {
3207 if (parseAbsoluteExpression(CurrValue))
3210 Values.push_back((uint8_t)CurrValue);
3212 while (getLexer().is(AsmToken::Comma)) {
3215 if (parseAbsoluteExpression(CurrValue))
3218 Values.push_back((uint8_t)CurrValue);
3221 getStreamer().EmitCFIEscape(Values);
3227 bool AsmParser::parseDirectiveCFISignalFrame() {
3228 if (getLexer().isNot(AsmToken::EndOfStatement))
3229 return Error(getLexer().getLoc(),
3230 "unexpected token in '.cfi_signal_frame'");
3232 getStreamer().EmitCFISignalFrame();
3238 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
3239 int64_t Register = 0;
3241 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3244 getStreamer().EmitCFIUndefined(Register);
3251 bool AsmParser::parseDirectiveMacrosOnOff(
StringRef Directive) {
3252 if (getLexer().isNot(AsmToken::EndOfStatement))
3253 return Error(getLexer().getLoc(),
3254 "unexpected token in '" + Directive +
"' directive");
3256 setMacrosEnabled(Directive ==
".macros_on");
3262 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
3264 if (parseIdentifier(Name))
3265 return TokError(
"expected identifier in '.macro' directive");
3267 if (getLexer().is(AsmToken::Comma))
3270 MCAsmMacroParameters Parameters;
3271 while (getLexer().isNot(AsmToken::EndOfStatement)) {
3273 if (!Parameters.empty() && Parameters.back().Vararg)
3274 return Error(Lexer.getLoc(),
3275 "Vararg parameter '" + Parameters.back().Name +
3276 "' should be last one in the list of parameters.");
3278 MCAsmMacroParameter Parameter;
3279 if (parseIdentifier(Parameter.Name))
3280 return TokError(
"expected identifier in '.macro' directive");
3282 if (Lexer.is(AsmToken::Colon)) {
3288 QualLoc = Lexer.getLoc();
3289 if (parseIdentifier(Qualifier))
3290 return Error(QualLoc,
"missing parameter qualifier for "
3291 "'" + Parameter.Name +
"' in macro '" + Name +
"'");
3293 if (Qualifier ==
"req")
3294 Parameter.Required =
true;
3295 else if (Qualifier ==
"vararg")
3296 Parameter.Vararg =
true;
3298 return Error(QualLoc, Qualifier +
" is not a valid parameter qualifier "
3299 "for '" + Parameter.Name +
"' in macro '" + Name +
"'");
3302 if (getLexer().is(AsmToken::Equal)) {
3307 ParamLoc = Lexer.getLoc();
3308 if (parseMacroArgument(Parameter.Value,
false ))
3311 if (Parameter.Required)
3312 Warning(ParamLoc,
"pointless default value for required parameter "
3313 "'" + Parameter.Name +
"' in macro '" + Name +
"'");
3316 Parameters.push_back(std::move(Parameter));
3318 if (getLexer().is(AsmToken::Comma))
3325 AsmToken EndToken, StartToken = getTok();
3326 unsigned MacroDepth = 0;
3332 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
3335 if (getLexer().is(AsmToken::Identifier)) {
3336 if (getTok().getIdentifier() ==
".endm" ||
3337 getTok().getIdentifier() ==
".endmacro") {
3338 if (MacroDepth == 0) {
3339 EndToken = getTok();
3341 if (getLexer().isNot(AsmToken::EndOfStatement))
3342 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
3349 }
else if (getTok().getIdentifier() ==
".macro") {
3357 eatToEndOfStatement();
3360 if (lookupMacro(Name)) {
3361 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
3367 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
3368 defineMacro(Name, MCAsmMacro(Name, Body, std::move(Parameters)));
3386 void AsmParser::checkForBadMacro(
SMLoc DirectiveLoc,
StringRef Name,
3391 unsigned NParameters = Parameters.
size();
3392 if (NParameters == 0)
3395 bool NamedParametersFound =
false;
3396 bool PositionalParametersFound =
false;
3401 while (!Body.
empty()) {
3403 std::size_t End = Body.
size(), Pos = 0;
3404 for (; Pos != End; ++Pos) {
3407 if (Body[Pos] ==
'\\' && Pos + 1 != End)
3411 if (Body[Pos] !=
'$' || Pos + 1 == End)
3413 char Next = Body[Pos + 1];
3414 if (Next ==
'$' || Next ==
'n' ||
3415 isdigit(static_cast<unsigned char>(Next)))
3423 if (Body[Pos] ==
'$') {
3424 switch (Body[Pos + 1]) {
3431 PositionalParametersFound =
true;
3436 PositionalParametersFound =
true;
3442 unsigned I = Pos + 1;
3446 const char *Begin = Body.
data() + Pos + 1;
3449 for (; Index < NParameters; ++Index)
3450 if (Parameters[Index].Name ==
Argument)
3453 if (Index == NParameters) {
3454 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
3460 NamedParametersFound =
true;
3468 if (!NamedParametersFound && PositionalParametersFound)
3469 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
3470 "used in macro body, possible positional parameter "
3471 "found in body which will have no effect");
3476 bool AsmParser::parseDirectiveExitMacro(
StringRef Directive) {
3477 if (getLexer().isNot(AsmToken::EndOfStatement))
3478 return TokError(
"unexpected token in '" + Directive +
"' directive");
3480 if (!isInsideMacroInstantiation())
3481 return TokError(
"unexpected '" + Directive +
"' in file, "
3482 "no current macro definition");
3485 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
3486 TheCondState = TheCondStack.back();
3487 TheCondStack.pop_back();
3497 bool AsmParser::parseDirectiveEndMacro(
StringRef Directive) {
3498 if (getLexer().isNot(AsmToken::EndOfStatement))
3499 return TokError(
"unexpected token in '" + Directive +
"' directive");
3503 if (isInsideMacroInstantiation()) {
3510 return TokError(
"unexpected '" + Directive +
"' in file, "
3511 "no current macro definition");
3516 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
3518 if (parseIdentifier(Name))
3519 return TokError(
"expected identifier in '.purgem' directive");
3521 if (getLexer().isNot(AsmToken::EndOfStatement))
3522 return TokError(
"unexpected token in '.purgem' directive");
3524 if (!lookupMacro(Name))
3525 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
3527 undefineMacro(Name);
3533 bool AsmParser::parseDirectiveBundleAlignMode() {
3534 checkForValidSection();
3538 SMLoc ExprLoc = getLexer().getLoc();
3539 int64_t AlignSizePow2;
3540 if (parseAbsoluteExpression(AlignSizePow2))
3542 else if (getLexer().isNot(AsmToken::EndOfStatement))
3543 return TokError(
"unexpected token after expression in"
3544 " '.bundle_align_mode' directive");
3545 else if (AlignSizePow2 < 0 || AlignSizePow2 > 30)
3546 return Error(ExprLoc,
3547 "invalid bundle alignment size (expected between 0 and 30)");
3553 getStreamer().EmitBundleAlignMode(static_cast<unsigned>(AlignSizePow2));
3559 bool AsmParser::parseDirectiveBundleLock() {
3560 checkForValidSection();
3561 bool AlignToEnd =
false;
3563 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3565 SMLoc Loc = getTok().getLoc();
3566 const char *kInvalidOptionError =
3567 "invalid option for '.bundle_lock' directive";
3569 if (parseIdentifier(Option))
3570 return Error(Loc, kInvalidOptionError);
3572 if (Option !=
"align_to_end")
3573 return Error(Loc, kInvalidOptionError);
3574 else if (getLexer().isNot(AsmToken::EndOfStatement))
3576 "unexpected token after '.bundle_lock' directive option");
3582 getStreamer().EmitBundleLock(AlignToEnd);
3588 bool AsmParser::parseDirectiveBundleUnlock() {
3589 checkForValidSection();
3591 if (getLexer().isNot(AsmToken::EndOfStatement))
3592 return TokError(
"unexpected token in '.bundle_unlock' directive");
3595 getStreamer().EmitBundleUnlock();
3601 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
3602 checkForValidSection();
3605 if (parseAbsoluteExpression(NumBytes))
3608 int64_t FillExpr = 0;
3609 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3610 if (getLexer().isNot(AsmToken::Comma))
3611 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
3614 if (parseAbsoluteExpression(FillExpr))
3617 if (getLexer().isNot(AsmToken::EndOfStatement))
3618 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
3624 return TokError(
"invalid number of bytes in '" +
Twine(IDVal) +
3628 getStreamer().EmitFill(NumBytes, FillExpr);
3635 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
3636 checkForValidSection();
3640 if (parseExpression(Value))
3644 getStreamer().EmitSLEB128Value(Value);
3646 getStreamer().EmitULEB128Value(Value);
3648 if (getLexer().is(AsmToken::EndOfStatement))
3651 if (getLexer().isNot(AsmToken::Comma))
3652 return TokError(
"unexpected token in directive");
3661 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
3662 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3665 SMLoc Loc = getTok().getLoc();
3667 if (parseIdentifier(Name))
3668 return Error(Loc,
"expected identifier in directive");
3670 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
3674 return Error(Loc,
"non-local symbol required in directive");
3676 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
3677 return Error(Loc,
"unable to emit symbol attribute");
3679 if (getLexer().is(AsmToken::EndOfStatement))
3682 if (getLexer().isNot(AsmToken::Comma))
3683 return TokError(
"unexpected token in directive");
3694 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
3695 checkForValidSection();
3697 SMLoc IDLoc = getLexer().getLoc();
3699 if (parseIdentifier(Name))
3700 return TokError(
"expected identifier in directive");
3703 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
3705 if (getLexer().isNot(AsmToken::Comma))
3706 return TokError(
"unexpected token in directive");
3710 SMLoc SizeLoc = getLexer().getLoc();
3711 if (parseAbsoluteExpression(Size))
3714 int64_t Pow2Alignment = 0;
3715 SMLoc Pow2AlignmentLoc;
3716 if (getLexer().is(AsmToken::Comma)) {
3718 Pow2AlignmentLoc = getLexer().getLoc();
3719 if (parseAbsoluteExpression(Pow2Alignment))
3724 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
3727 if ((!IsLocal && Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) ||
3730 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
3731 Pow2Alignment =
Log2_64(Pow2Alignment);
3735 if (getLexer().isNot(AsmToken::EndOfStatement))
3736 return TokError(
"unexpected token in '.comm' or '.lcomm' directive");
3743 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't "
3744 "be less than zero");
3749 if (Pow2Alignment < 0)
3750 return Error(Pow2AlignmentLoc,
"invalid '.comm' or '.lcomm' directive "
3751 "alignment, can't be less than zero");
3754 return Error(IDLoc,
"invalid symbol redefinition");
3758 getStreamer().EmitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment);
3762 getStreamer().EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
3768 bool AsmParser::parseDirectiveAbort() {
3770 SMLoc Loc = getLexer().getLoc();
3772 StringRef Str = parseStringToEndOfStatement();
3773 if (getLexer().isNot(AsmToken::EndOfStatement))
3774 return TokError(
"unexpected token in '.abort' directive");
3779 Error(Loc,
".abort detected. Assembly stopping.");
3781 Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
3789 bool AsmParser::parseDirectiveInclude() {
3791 return TokError(
"expected string in '.include' directive");
3794 std::string Filename;
3795 if (parseEscapedString(Filename))
3797 SMLoc IncludeLoc = getLexer().getLoc();
3800 if (getLexer().isNot(AsmToken::EndOfStatement))
3801 return TokError(
"unexpected token in '.include' directive");
3805 if (enterIncludeFile(Filename)) {
3806 Error(IncludeLoc,
"Could not find include file '" + Filename +
"'");
3815 bool AsmParser::parseDirectiveIncbin() {
3817 return TokError(
"expected string in '.incbin' directive");
3820 std::string Filename;
3821 if (parseEscapedString(Filename))
3823 SMLoc IncbinLoc = getLexer().getLoc();
3826 if (getLexer().isNot(AsmToken::EndOfStatement))
3827 return TokError(
"unexpected token in '.incbin' directive");
3830 if (processIncbinFile(Filename)) {
3831 Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
3840 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc, DirectiveKind DirKind) {
3841 TheCondStack.push_back(TheCondState);
3842 TheCondState.TheCond = AsmCond::IfCond;
3843 if (TheCondState.Ignore) {
3844 eatToEndOfStatement();
3847 if (parseAbsoluteExpression(ExprValue))
3850 if (getLexer().isNot(AsmToken::EndOfStatement))
3851 return TokError(
"unexpected token in '.if' directive");
3862 ExprValue = ExprValue == 0;
3865 ExprValue = ExprValue >= 0;
3868 ExprValue = ExprValue > 0;
3871 ExprValue = ExprValue <= 0;
3874 ExprValue = ExprValue < 0;
3878 TheCondState.CondMet = ExprValue;
3879 TheCondState.Ignore = !TheCondState.CondMet;
3887 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
3888 TheCondStack.push_back(TheCondState);
3889 TheCondState.TheCond = AsmCond::IfCond;
3891 if (TheCondState.Ignore) {
3892 eatToEndOfStatement();
3894 StringRef Str = parseStringToEndOfStatement();
3896 if (getLexer().isNot(AsmToken::EndOfStatement))
3897 return TokError(
"unexpected token in '.ifb' directive");
3901 TheCondState.CondMet = ExpectBlank == Str.
empty();
3902 TheCondState.Ignore = !TheCondState.CondMet;
3911 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
3912 TheCondStack.push_back(TheCondState);
3913 TheCondState.TheCond = AsmCond::IfCond;
3915 if (TheCondState.Ignore) {
3916 eatToEndOfStatement();
3920 if (getLexer().isNot(AsmToken::Comma))
3921 return TokError(
"unexpected token in '.ifc' directive");
3925 StringRef Str2 = parseStringToEndOfStatement();
3927 if (getLexer().isNot(AsmToken::EndOfStatement))
3928 return TokError(
"unexpected token in '.ifc' directive");
3932 TheCondState.CondMet = ExpectEqual == (Str1.
trim() == Str2.
trim());
3933 TheCondState.Ignore = !TheCondState.CondMet;
3941 bool AsmParser::parseDirectiveIfeqs(
SMLoc DirectiveLoc,
bool ExpectEqual) {
3944 TokError(
"expected string parameter for '.ifeqs' directive");
3946 TokError(
"expected string parameter for '.ifnes' directive");
3947 eatToEndOfStatement();
3951 StringRef String1 = getTok().getStringContents();
3954 if (Lexer.isNot(AsmToken::Comma)) {
3956 TokError(
"expected comma after first string for '.ifeqs' directive");
3958 TokError(
"expected comma after first string for '.ifnes' directive");
3959 eatToEndOfStatement();
3967 TokError(
"expected string parameter for '.ifeqs' directive");
3969 TokError(
"expected string parameter for '.ifnes' directive");
3970 eatToEndOfStatement();
3974 StringRef String2 = getTok().getStringContents();
3977 TheCondStack.push_back(TheCondState);
3978 TheCondState.TheCond = AsmCond::IfCond;
3979 TheCondState.CondMet = ExpectEqual == (String1 == String2);
3980 TheCondState.Ignore = !TheCondState.CondMet;
3987 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
3989 TheCondStack.push_back(TheCondState);
3990 TheCondState.TheCond = AsmCond::IfCond;
3992 if (TheCondState.Ignore) {
3993 eatToEndOfStatement();
3995 if (parseIdentifier(Name))
3996 return TokError(
"expected identifier after '.ifdef'");
4000 MCSymbol *Sym = getContext().lookupSymbol(Name);
4003 TheCondState.CondMet = (Sym && !Sym->
isUndefined());
4005 TheCondState.CondMet = (!Sym || Sym->
isUndefined());
4006 TheCondState.Ignore = !TheCondState.CondMet;
4014 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
4015 if (TheCondState.TheCond != AsmCond::IfCond &&
4016 TheCondState.TheCond != AsmCond::ElseIfCond)
4017 Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow a .if or "
4019 TheCondState.TheCond = AsmCond::ElseIfCond;
4021 bool LastIgnoreState =
false;
4022 if (!TheCondStack.empty())
4023 LastIgnoreState = TheCondStack.back().Ignore;
4024 if (LastIgnoreState || TheCondState.CondMet) {
4025 TheCondState.Ignore =
true;
4026 eatToEndOfStatement();
4029 if (parseAbsoluteExpression(ExprValue))
4032 if (getLexer().isNot(AsmToken::EndOfStatement))
4033 return TokError(
"unexpected token in '.elseif' directive");
4036 TheCondState.CondMet = ExprValue;
4037 TheCondState.Ignore = !TheCondState.CondMet;
4045 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
4046 if (getLexer().isNot(AsmToken::EndOfStatement))
4047 return TokError(
"unexpected token in '.else' directive");
4051 if (TheCondState.TheCond != AsmCond::IfCond &&
4052 TheCondState.TheCond != AsmCond::ElseIfCond)
4053 Error(DirectiveLoc,
"Encountered a .else that doesn't follow a .if or an "
4055 TheCondState.TheCond = AsmCond::ElseCond;
4056 bool LastIgnoreState =
false;
4057 if (!TheCondStack.empty())
4058 LastIgnoreState = TheCondStack.back().Ignore;
4059 if (LastIgnoreState || TheCondState.CondMet)
4060 TheCondState.Ignore =
true;
4062 TheCondState.Ignore =
false;
4069 bool AsmParser::parseDirectiveEnd(
SMLoc DirectiveLoc) {
4070 if (getLexer().isNot(AsmToken::EndOfStatement))
4071 return TokError(
"unexpected token in '.end' directive");
4084 bool AsmParser::parseDirectiveError(
SMLoc L,
bool WithMessage) {
4085 if (!TheCondStack.empty()) {
4086 if (TheCondStack.back().Ignore) {
4087 eatToEndOfStatement();
4093 return Error(L,
".err encountered");
4095 StringRef Message =
".error directive invoked in source file";
4096 if (Lexer.isNot(AsmToken::EndOfStatement)) {
4098 TokError(
".error argument must be a string");
4099 eatToEndOfStatement();
4103 Message = getTok().getStringContents();
4113 bool AsmParser::parseDirectiveWarning(
SMLoc L) {
4114 if (!TheCondStack.empty()) {
4115 if (TheCondStack.back().Ignore) {
4116 eatToEndOfStatement();
4121 StringRef Message =
".warning directive invoked in source file";
4122 if (Lexer.isNot(AsmToken::EndOfStatement)) {
4124 TokError(
".warning argument must be a string");
4125 eatToEndOfStatement();
4129 Message = getTok().getStringContents();
4133 Warning(L, Message);
4139 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
4140 if (getLexer().isNot(AsmToken::EndOfStatement))
4141 return TokError(
"unexpected token in '.endif' directive");
4145 if ((TheCondState.TheCond == AsmCond::NoCond) || TheCondStack.empty())
4146 Error(DirectiveLoc,
"Encountered a .endif that doesn't follow a .if or "
4148 if (!TheCondStack.empty()) {
4149 TheCondState = TheCondStack.back();
4150 TheCondStack.pop_back();
4156 void AsmParser::initializeDirectiveKindMap() {
4157 DirectiveKindMap[
".set"] = DK_SET;
4158 DirectiveKindMap[
".equ"] = DK_EQU;
4159 DirectiveKindMap[
".equiv"] = DK_EQUIV;
4160 DirectiveKindMap[
".ascii"] = DK_ASCII;
4161 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
4162 DirectiveKindMap[
".string"] = DK_STRING;
4163 DirectiveKindMap[
".byte"] = DK_BYTE;
4164 DirectiveKindMap[
".short"] = DK_SHORT;
4165 DirectiveKindMap[
".value"] = DK_VALUE;
4166 DirectiveKindMap[
".2byte"] = DK_2BYTE;
4167 DirectiveKindMap[
".long"] = DK_LONG;
4168 DirectiveKindMap[
".int"] = DK_INT;
4169 DirectiveKindMap[
".4byte"] = DK_4BYTE;
4170 DirectiveKindMap[
".quad"] = DK_QUAD;
4171 DirectiveKindMap[
".8byte"] = DK_8BYTE;
4172 DirectiveKindMap[
".octa"] = DK_OCTA;
4173 DirectiveKindMap[
".single"] = DK_SINGLE;
4174 DirectiveKindMap[
".float"] = DK_FLOAT;
4175 DirectiveKindMap[
".double"] = DK_DOUBLE;
4176 DirectiveKindMap[
".align"] = DK_ALIGN;
4177 DirectiveKindMap[
".align32"] = DK_ALIGN32;
4178 DirectiveKindMap[
".balign"] = DK_BALIGN;
4179 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
4180 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
4181 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
4182 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
4183 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
4184 DirectiveKindMap[
".org"] = DK_ORG;
4185 DirectiveKindMap[
".fill"] = DK_FILL;
4186 DirectiveKindMap[
".zero"] = DK_ZERO;
4187 DirectiveKindMap[
".extern"] = DK_EXTERN;
4188 DirectiveKindMap[
".globl"] = DK_GLOBL;
4189 DirectiveKindMap[
".global"] = DK_GLOBAL;
4190 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
4191 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
4192 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
4193 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
4194 DirectiveKindMap[
".reference"] = DK_REFERENCE;
4195 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
4196 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
4197 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
4198 DirectiveKindMap[
".comm"] = DK_COMM;
4199 DirectiveKindMap[
".common"] = DK_COMMON;
4200 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
4201 DirectiveKindMap[
".abort"] = DK_ABORT;
4202 DirectiveKindMap[
".include"] = DK_INCLUDE;
4203 DirectiveKindMap[
".incbin"] = DK_INCBIN;
4204 DirectiveKindMap[
".code16"] = DK_CODE16;
4205 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
4206 DirectiveKindMap[
".rept"] = DK_REPT;
4207 DirectiveKindMap[
".rep"] = DK_REPT;
4208 DirectiveKindMap[
".irp"] = DK_IRP;
4209 DirectiveKindMap[
".irpc"] = DK_IRPC;
4210 DirectiveKindMap[
".endr"] = DK_ENDR;
4211 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
4212 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
4213 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
4214 DirectiveKindMap[
".if"] = DK_IF;
4215 DirectiveKindMap[
".ifeq"] = DK_IFEQ;
4216 DirectiveKindMap[
".ifge"] = DK_IFGE;
4217 DirectiveKindMap[
".ifgt"] = DK_IFGT;
4218 DirectiveKindMap[
".ifle"] = DK_IFLE;
4219 DirectiveKindMap[
".iflt"] = DK_IFLT;
4220 DirectiveKindMap[
".ifne"] = DK_IFNE;
4221 DirectiveKindMap[
".ifb"] = DK_IFB;
4222 DirectiveKindMap[
".ifnb"] = DK_IFNB;
4223 DirectiveKindMap[
".ifc"] = DK_IFC;
4224 DirectiveKindMap[
".ifeqs"] = DK_IFEQS;
4225 DirectiveKindMap[
".ifnc"] = DK_IFNC;
4226 DirectiveKindMap[
".ifnes"] = DK_IFNES;
4227 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
4228 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
4229 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
4230 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
4231 DirectiveKindMap[
".else"] = DK_ELSE;
4232 DirectiveKindMap[
".end"] = DK_END;
4233 DirectiveKindMap[
".endif"] = DK_ENDIF;
4234 DirectiveKindMap[
".skip"] = DK_SKIP;
4235 DirectiveKindMap[
".space"] = DK_SPACE;
4236 DirectiveKindMap[
".file"] = DK_FILE;
4237 DirectiveKindMap[
".line"] = DK_LINE;
4238 DirectiveKindMap[
".loc"] = DK_LOC;
4239 DirectiveKindMap[
".stabs"] = DK_STABS;
4240 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
4241 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
4242 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
4243 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
4244 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
4245 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
4246 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
4247 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
4248 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
4249 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
4250 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
4251 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
4252 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
4253 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
4254 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
4255 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
4256 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
4257 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
4258 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
4259 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
4260 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
4261 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
4262 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
4263 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
4264 DirectiveKindMap[
".macro"] = DK_MACRO;
4265 DirectiveKindMap[
".exitm"] = DK_EXITM;
4266 DirectiveKindMap[
".endm"] = DK_ENDM;
4267 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
4268 DirectiveKindMap[
".purgem"] = DK_PURGEM;
4269 DirectiveKindMap[
".err"] = DK_ERR;
4270 DirectiveKindMap[
".error"] = DK_ERROR;
4271 DirectiveKindMap[
".warning"] = DK_WARNING;
4274 MCAsmMacro *AsmParser::parseMacroLikeBody(
SMLoc DirectiveLoc) {
4275 AsmToken EndToken, StartToken = getTok();
4277 unsigned NestLevel = 0;
4281 Error(DirectiveLoc,
"no matching '.endr' in definition");
4285 if (Lexer.is(AsmToken::Identifier) &&
4286 (getTok().getIdentifier() ==
".rept")) {
4291 if (Lexer.is(AsmToken::Identifier) && getTok().getIdentifier() ==
".endr") {
4292 if (NestLevel == 0) {
4293 EndToken = getTok();
4295 if (Lexer.isNot(AsmToken::EndOfStatement)) {
4296 TokError(
"unexpected token in '.endr' directive");
4305 eatToEndOfStatement();
4313 MacroLikeBodies.emplace_back(
StringRef(), Body, MCAsmMacroParameters());
4314 return &MacroLikeBodies.back();
4317 void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
4321 std::unique_ptr<MemoryBuffer> Instantiation =
4322 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
4326 MacroInstantiation *MI =
new MacroInstantiation(
4327 DirectiveLoc, CurBuffer, getTok().getLoc(), TheCondStack.size());
4328 ActiveMacros.push_back(MI);
4338 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc,
StringRef Dir) {
4340 SMLoc CountLoc = getTok().getLoc();
4341 if (parseExpression(CountExpr))
4345 if (!CountExpr->evaluateAsAbsolute(Count)) {
4346 eatToEndOfStatement();
4347 return Error(CountLoc,
"unexpected token in '" + Dir +
"' directive");
4351 return Error(CountLoc,
"Count is negative");
4353 if (Lexer.isNot(AsmToken::EndOfStatement))
4354 return TokError(
"unexpected token in '" + Dir +
"' directive");
4360 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
4370 if (expandMacro(OS, M->Body,
None,
None,
false, getTok().getLoc()))
4373 instantiateMacroLikeBody(M, DirectiveLoc, OS);
4380 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
4381 MCAsmMacroParameter Parameter;
4383 if (parseIdentifier(Parameter.Name))
4384 return TokError(
"expected identifier in '.irp' directive");
4386 if (Lexer.isNot(AsmToken::Comma))
4387 return TokError(
"expected comma in '.irp' directive");
4391 MCAsmMacroArguments
A;
4392 if (parseMacroArguments(
nullptr, A))
4399 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
4408 for (MCAsmMacroArguments::iterator i = A.begin(), e = A.end(); i != e; ++i) {
4411 if (expandMacro(OS, M->Body, Parameter, *i,
true, getTok().getLoc()))
4415 instantiateMacroLikeBody(M, DirectiveLoc, OS);
4422 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
4423 MCAsmMacroParameter Parameter;
4425 if (parseIdentifier(Parameter.Name))
4426 return TokError(
"expected identifier in '.irpc' directive");
4428 if (Lexer.isNot(AsmToken::Comma))
4429 return TokError(
"expected comma in '.irpc' directive");
4433 MCAsmMacroArguments
A;
4434 if (parseMacroArguments(
nullptr, A))
4437 if (A.size() != 1 || A.front().size() != 1)
4438 return TokError(
"unexpected token in '.irpc' directive");
4444 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
4454 for (std::size_t I = 0, End = Values.
size(); I != End; ++
I) {
4455 MCAsmMacroArgument Arg;
4456 Arg.emplace_back(AsmToken::Identifier, Values.
slice(I, I + 1));
4460 if (expandMacro(OS, M->Body, Parameter, Arg,
true, getTok().getLoc()))
4464 instantiateMacroLikeBody(M, DirectiveLoc, OS);
4469 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
4470 if (ActiveMacros.empty())
4471 return TokError(
"unmatched '.endr' directive");
4475 assert(getLexer().is(AsmToken::EndOfStatement));
4481 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
4484 SMLoc ExprLoc = getLexer().getLoc();
4485 if (parseExpression(Value))
4489 return Error(ExprLoc,
"unexpected expression in _emit");
4490 uint64_t IntValue = MCE->
getValue();
4492 return Error(ExprLoc,
"literal value out of range for directive");
4498 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
4500 SMLoc ExprLoc = getLexer().getLoc();
4501 if (parseExpression(Value))
4505 return Error(ExprLoc,
"unexpected expression in align");
4506 uint64_t IntValue = MCE->
getValue();
4508 return Error(ExprLoc,
"literal value not a power of two greater then zero");
4510 Info.AsmRewrites->push_back(
4538 bool AsmParser::parseMSInlineAsm(
4539 void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs,
4540 unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool> > &OpDecls,
4558 unsigned InputIdx = 0;
4559 unsigned OutputIdx = 0;
4561 ParseStatementInfo Info(&AsmStrRewrites);
4562 if (parseStatement(Info, &SI))
4565 if (Info.ParseError)
4568 if (Info.Opcode == ~0U)
4574 for (
unsigned i = 1, e = Info.ParsedOperands.size(); i != e; ++i) {
4578 if (Operand.
isImm())
4583 !getTargetParser().OmitRegisterFromClobberLists(Operand.
getReg())) {
4593 if (SymName.
empty())
4600 bool isOutput = (i == 1) && Desc.
mayStore();
4601 SMLoc Start = SMLoc::getFromPointer(SymName.
data());
4619 ClobberRegs.
insert(ClobberRegs.
end(), ImpDefs.begin(), ImpDefs.end());
4623 NumOutputs = OutputDecls.
size();
4624 NumInputs = InputDecls.
size();
4628 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
4630 Clobbers.
assign(ClobberRegs.
size(), std::string());
4631 for (
unsigned I = 0, E = ClobberRegs.
size(); I != E; ++
I) {
4637 if (NumOutputs || NumInputs) {
4638 unsigned NumExprs = NumOutputs + NumInputs;
4639 OpDecls.resize(NumExprs);
4640 Constraints.
resize(NumExprs);
4641 for (
unsigned i = 0; i < NumOutputs; ++i) {
4642 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
4643 Constraints[i] = OutputConstraints[i];
4645 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) {
4646 OpDecls[j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
4647 Constraints[j] = InputConstraints[i];
4652 std::string AsmStringIR;
4656 const char *AsmStart = ASMString.
begin();
4657 const char *AsmEnd = ASMString.
end();
4659 for (
const AsmRewrite &AR : AsmStrRewrites) {
4665 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
4668 if (
unsigned Len = Loc - AsmStart)
4673 AsmStart = Loc + AR.Len;
4677 unsigned AdditionalSkip = 0;
4683 OS <<
"$$" << AR.Val;
4692 OS <<
'$' << InputIdx++;
4695 OS <<
'$' << OutputIdx++;
4700 case 8: OS <<
"byte ptr ";
break;
4701 case 16: OS <<
"word ptr ";
break;
4702 case 32: OS <<
"dword ptr ";
break;
4703 case 64: OS <<
"qword ptr ";
break;
4704 case 80: OS <<
"xword ptr ";
break;
4705 case 128: OS <<
"xmmword ptr ";
break;
4706 case 256: OS <<
"ymmword ptr ";
break;
4713 unsigned Val = AR.Val;
4714 OS <<
".align " << Val;
4717 assert(Val < 10 &&
"Expected alignment less then 2^10.");
4718 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
4724 if (AsmStringIR.back() !=
'.')
4731 AsmStart = Loc + AR.Len + AdditionalSkip;
4735 if (AsmStart != AsmEnd)
4736 OS <<
StringRef(AsmStart, AsmEnd - AsmStart);
4738 AsmString = OS.
str();
4743 namespace MCParserUtils {
4766 Sym, static_cast<const MCUnaryExpr *>(Value)->getSubExpr());
4781 Parser.
TokError(
"missing expression");
4791 return Parser.
TokError(
"unexpected token in assignment");
4805 return Parser.
Error(EqualLoc,
"Recursive use of '" + Name +
"'");
4811 return Parser.
Error(EqualLoc,
"redefinition of '" + Name +
"'");
4813 return Parser.
Error(EqualLoc,
"invalid assignment to '" + Name +
"'");
4815 return Parser.
Error(EqualLoc,
4816 "invalid reassignment of non-absolute variable '" +
4821 }
else if (Name ==
".") {
4823 Parser.
Error(EqualLoc,
"expected absolute expression");
4842 return new AsmParser(SM, C, Out, MAI);
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
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
int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
const ValueTy & getValue() const
const uint16_t * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual ~MCAsmParserSemaCallback()
LLVM Argument representation.
uint64_t getZExtValue() const
Get zero extended value.
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
bool doesAllowAtInName() const
const MCSymbol & getSymbol() const
#define DWARF2_FLAG_PROLOGUE_END
const char * getPointer() const
size_t size() const
size - Get the string size.
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.
void * getDiagContext() const
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
MCAsmParserExtension * createDarwinAsmParser()
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
StringRef getBuffer() const
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
std::string str() const
str - Get the contents as an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
const_iterator begin(StringRef path)
Get begin iterator over path.
SMLoc getLoc() const
Get the current source location.
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
MCAsmParserExtension * createELFAsmParser()
unsigned getMainFileID() const
bool TokError(const Twine &Msg, ArrayRef< SMRange > Ranges=None)
Report an error at the current lexer location.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const MCExpr * getVariableValue() const
getVariableValue() - Get the value for variable symbols.
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...
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.
bool isIntN(unsigned N, const APInt &APIVal)
Check if the specified APInt has a N-bits unsigned integer value.
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *Value)
Returns whether the given symbol is used anywhere in the given expression, or subexpressions.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
Environment getObjectFileType() const
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
virtual bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value=0)
Emit some number of copies of Value until the byte offset Offset is reached.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
virtual void * getOpDecl()
StringRef getConstraint()
size_t size() const
size - Get the array size.
virtual void printRegName(raw_ostream &OS, unsigned RegNo) const
Print the assembler register name.
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
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...
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
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.
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.
.weak_def_can_be_hidden (MachO)
StringRef trim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left and right removed...
void setRedefinable(bool Value)
Mark this symbol as redefinable.
#define DWARF2_FLAG_EPILOGUE_BEGIN
bool shouldUseLogicalShr() const
void(* DiagHandlerTy)(const SMDiagnostic &, void *Context)
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Interface to description of machine instruction set.
virtual MCAsmLexer & getLexer()=0
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &)
Create an MCAsmParser instance.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Generic Sema callback for assembly parser.
#define DWARF2_FLAG_BASIC_BLOCK
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.
iterator erase(iterator I)
MCAsmParserExtension * createCOFFAsmParser()
virtual bool Error(SMLoc L, const Twine &Msg, ArrayRef< SMRange > Ranges=None)=0
Emit an error at the location L, with the message Msg.
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.
const char * getPrivateLabelPrefix() const
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
virtual void InitSections(bool NoExecStack)
Create the default sections and set the initial one.
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
SourceMgr::DiagKind getKind() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Promote Memory to Register
MCSymbol * getBeginSymbol()
SMLoc getParentIncludeLoc(unsigned i) const
void setUsed(bool Value) const
bool is(TokenKind K) const
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Class for arbitrary precision integers.
bool isUInt< 32 >(uint64_t x)
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
bool isPowerOf2_64(uint64_t Value)
isPowerOf2_64 - This function returns true if the argument is a power of two 0 (64 bit edition...
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
iterator insert(iterator I, T &&Elt)
#define DWARF2_LINE_DEFAULT_IS_STMT
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs...
StringRef str()
Flushes the stream contents to the target vector and return a StringRef for the vector contents...
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
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...
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.
References to labels and assigned expressions.
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
char front() const
front - Get the first character in the string.
const ARM::ArchExtKind Kind
A raw_ostream that writes to an std::string.
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
const char AsmRewritePrecedence[]
LLVM Value Representation.
bool useParensForSymbolVariant() const
const MCObjectFileInfo * getObjectFileInfo() const
bool hasSubsectionsViaSymbols() const
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
This class implements an extremely fast bulk output stream that can only output to a stream...
std::string Hash(const Unit &U)
unsigned getMCOperandNum()
C - The default llvm calling convention, compatible with C.
StringRef - Represent a constant reference to a string, i.e.
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
const SourceMgr * getSourceMgr() const
Target specific expression.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label? Only valid when par...
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Represents a location in source code.
static void Split(std::vector< std::string > &V, StringRef S)
Split - Splits a string of comma separated items in to a vector of strings.
bool isUIntN(unsigned N, uint64_t x)
isUIntN - Checks if an unsigned integer fits into the given (dynamic) bit width.
DiagHandlerTy getDiagHandler() const
ConditionalAssemblyType TheCond
unsigned Log2_64(uint64_t Value)
Log2_64 - This function returns the floor log base 2 of the specified value, -1 if the value is zero...
std::string lower() const
virtual bool isReg() const =0
isReg - Is this a register operand?
bool empty() const
empty - Check if the string is empty.
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...
void setBeginSymbol(MCSymbol *Sym)