48 cl::desc(
"Consider warnings as error"));
55 typedef std::vector<AsmToken> MCAsmMacroArgument;
56 typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
57 typedef std::pair<StringRef, MCAsmMacroArgument> MCAsmMacroParameter;
58 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
63 MCAsmMacroParameters Parameters;
67 Name(N), Body(B), Parameters(P) {}
69 MCAsmMacro(
const MCAsmMacro& Other)
70 :
Name(Other.
Name), Body(Other.Body), Parameters(Other.Parameters) {}
75 struct MacroInstantiation {
77 const MCAsmMacro *TheMacro;
83 SMLoc InstantiationLoc;
92 MacroInstantiation(
const MCAsmMacro *M,
SMLoc IL,
int EB,
SMLoc EL,
96 struct ParseStatementInfo {
108 ParseStatementInfo() : Opcode(~0U), ParseError(
false), AsmRewrites(0) {}
110 : Opcode(~0), ParseError(
false), AsmRewrites(rewrites) {}
112 ~ParseStatementInfo() {
114 for (
unsigned i = 0, e = ParsedOperands.size(); i != e; ++i)
115 delete ParsedOperands[i];
116 ParsedOperands.clear();
123 void operator=(const AsmParser &) LLVM_DELETED_FUNCTION;
130 SourceMgr::DiagHandlerTy SavedDiagHandler;
131 void *SavedDiagContext;
139 std::vector<
AsmCond> TheCondStack;
144 StringMap<ExtensionDirectiveHandler> ExtensionDirectiveMap;
150 std::vector<MacroInstantiation*> ActiveMacros;
153 std::deque<MCAsmMacro> MacroLikeBodies;
156 unsigned MacrosEnabledFlag : 1;
159 unsigned HadError : 1;
163 int64_t CppHashLineNumber;
170 SMLoc LastQueryIDLoc;
172 unsigned LastQueryLine;
175 unsigned AssemblerDialect;
181 bool ParsingInlineAsm;
186 virtual ~AsmParser();
188 virtual
bool Run(
bool NoInitialTextSection,
bool NoFinalize =
false);
190 virtual
void addDirectiveHandler(
StringRef Directive,
191 ExtensionDirectiveHandler Handler) {
192 ExtensionDirectiveMap[Directive] = Handler;
200 virtual MCAsmLexer &getLexer() {
return Lexer; }
201 virtual MCContext &getContext() {
return Ctx; }
202 virtual MCStreamer &getStreamer() {
return Out; }
203 virtual unsigned getAssemblerDialect() {
204 if (AssemblerDialect == ~0U)
205 return MAI.getAssemblerDialect();
207 return AssemblerDialect;
209 virtual void setAssemblerDialect(
unsigned i) {
210 AssemblerDialect = i;
213 virtual bool Warning(
SMLoc L,
const Twine &Msg,
220 void setParsingInlineAsm(
bool V) { ParsingInlineAsm = V; }
221 bool isParsingInlineAsm() {
return ParsingInlineAsm; }
223 bool parseMSInlineAsm(
void *AsmLoc, std::string &AsmString,
224 unsigned &NumOutputs,
unsigned &NumInputs,
232 bool parseExpression(
const MCExpr *&Res);
233 virtual bool parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc);
234 virtual bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
235 virtual bool parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc);
236 virtual bool parseAbsoluteExpression(int64_t &Res);
240 virtual bool parseIdentifier(
StringRef &Res);
241 virtual void eatToEndOfStatement();
243 virtual void checkForValidSection();
248 bool parseStatement(ParseStatementInfo &Info);
249 void eatToEndOfLine();
250 bool parseCppHashLineFilenameComment(
const SMLoc &L);
253 MCAsmMacroParameters Parameters);
255 const MCAsmMacroParameters &Parameters,
256 const MCAsmMacroArguments &
A,
260 bool areMacrosEnabled() {
return MacrosEnabledFlag;}
263 void setMacrosEnabled(
bool Flag) {MacrosEnabledFlag = Flag;}
277 bool isInsideMacroInstantiation() {
return !ActiveMacros.empty();}
283 bool handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc);
286 void handleMacroExit();
291 bool parseMacroArgument(MCAsmMacroArgument &MA,
295 bool parseMacroArguments(
const MCAsmMacro *M, MCAsmMacroArguments &
A);
297 void printMacroInstantiations();
302 static void DiagHandler(
const SMDiagnostic &Diag,
void *Context);
305 bool enterIncludeFile(
const std::string &Filename);
309 bool processIncbinFile(
const std::string &Filename);
317 void jumpToLoc(
SMLoc Loc,
int InBuffer=-1);
322 virtual StringRef parseStringToEndOfStatement();
329 bool NoDeadStrip =
false);
331 bool parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
SMLoc &EndLoc);
332 bool parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
333 bool parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc);
335 bool parseRegisterOrRegisterNumber(int64_t &
Register,
SMLoc DirectiveLoc);
340 DK_SET, DK_EQU, DK_EQUIV, DK_ASCII, DK_ASCIZ, DK_STRING, DK_BYTE, DK_SHORT,
341 DK_VALUE, DK_2BYTE, DK_LONG, DK_INT, DK_4BYTE, DK_QUAD, DK_8BYTE, DK_SINGLE,
342 DK_FLOAT, DK_DOUBLE, DK_ALIGN, DK_ALIGN32, DK_BALIGN, DK_BALIGNW,
343 DK_BALIGNL, DK_P2ALIGN, DK_P2ALIGNW, DK_P2ALIGNL, DK_ORG, DK_FILL, DK_ENDR,
344 DK_BUNDLE_ALIGN_MODE, DK_BUNDLE_LOCK, DK_BUNDLE_UNLOCK,
345 DK_ZERO, DK_EXTERN, DK_GLOBL, DK_GLOBAL,
346 DK_LAZY_REFERENCE, DK_NO_DEAD_STRIP, DK_SYMBOL_RESOLVER, DK_PRIVATE_EXTERN,
347 DK_REFERENCE, DK_WEAK_DEFINITION, DK_WEAK_REFERENCE,
348 DK_WEAK_DEF_CAN_BE_HIDDEN, DK_COMM, DK_COMMON, DK_LCOMM, DK_ABORT,
349 DK_INCLUDE, DK_INCBIN, DK_CODE16, DK_CODE16GCC, DK_REPT, DK_IRP, DK_IRPC,
350 DK_IF, DK_IFB, DK_IFNB, DK_IFC, DK_IFNC, DK_IFDEF, DK_IFNDEF, DK_IFNOTDEF,
351 DK_ELSEIF, DK_ELSE, DK_ENDIF,
352 DK_SPACE, DK_SKIP, DK_FILE, DK_LINE, DK_LOC, DK_STABS,
353 DK_CFI_SECTIONS, DK_CFI_STARTPROC, DK_CFI_ENDPROC, DK_CFI_DEF_CFA,
354 DK_CFI_DEF_CFA_OFFSET, DK_CFI_ADJUST_CFA_OFFSET, DK_CFI_DEF_CFA_REGISTER,
355 DK_CFI_OFFSET, DK_CFI_REL_OFFSET, DK_CFI_PERSONALITY, DK_CFI_LSDA,
356 DK_CFI_REMEMBER_STATE, DK_CFI_RESTORE_STATE, DK_CFI_SAME_VALUE,
357 DK_CFI_RESTORE, DK_CFI_ESCAPE, DK_CFI_SIGNAL_FRAME, DK_CFI_UNDEFINED,
358 DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE,
359 DK_MACROS_ON, DK_MACROS_OFF, DK_MACRO, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
360 DK_SLEB128, DK_ULEB128
368 bool parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated);
369 bool parseDirectiveValue(
unsigned Size);
371 bool parseDirectiveFill();
372 bool parseDirectiveZero();
374 bool parseDirectiveSet(
StringRef IDVal,
bool allow_redef);
375 bool parseDirectiveOrg();
377 bool parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize);
380 bool parseDirectiveFile(
SMLoc DirectiveLoc);
381 bool parseDirectiveLine();
382 bool parseDirectiveLoc();
383 bool parseDirectiveStabs();
386 bool parseDirectiveCFIRegister(
SMLoc DirectiveLoc);
387 bool parseDirectiveCFIWindowSave();
388 bool parseDirectiveCFISections();
389 bool parseDirectiveCFIStartProc();
390 bool parseDirectiveCFIEndProc();
391 bool parseDirectiveCFIDefCfaOffset();
392 bool parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc);
393 bool parseDirectiveCFIAdjustCfaOffset();
394 bool parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc);
395 bool parseDirectiveCFIOffset(
SMLoc DirectiveLoc);
396 bool parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc);
397 bool parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality);
398 bool parseDirectiveCFIRememberState();
399 bool parseDirectiveCFIRestoreState();
400 bool parseDirectiveCFISameValue(
SMLoc DirectiveLoc);
401 bool parseDirectiveCFIRestore(
SMLoc DirectiveLoc);
402 bool parseDirectiveCFIEscape();
403 bool parseDirectiveCFISignalFrame();
404 bool parseDirectiveCFIUndefined(
SMLoc DirectiveLoc);
407 bool parseDirectivePurgeMacro(
SMLoc DirectiveLoc);
408 bool parseDirectiveEndMacro(
StringRef Directive);
409 bool parseDirectiveMacro(
SMLoc DirectiveLoc);
410 bool parseDirectiveMacrosOnOff(
StringRef Directive);
413 bool parseDirectiveBundleAlignMode();
415 bool parseDirectiveBundleLock();
417 bool parseDirectiveBundleUnlock();
420 bool parseDirectiveSpace(
StringRef IDVal);
423 bool parseDirectiveLEB128(
bool Signed);
429 bool parseDirectiveComm(
bool IsLocal);
431 bool parseDirectiveAbort();
432 bool parseDirectiveInclude();
433 bool parseDirectiveIncbin();
435 bool parseDirectiveIf(
SMLoc DirectiveLoc);
437 bool parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank);
439 bool parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual);
441 bool parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined);
442 bool parseDirectiveElseIf(
SMLoc DirectiveLoc);
443 bool parseDirectiveElse(
SMLoc DirectiveLoc);
444 bool parseDirectiveEndIf(
SMLoc DirectiveLoc);
445 virtual bool parseEscapedString(std::string &Data);
451 MCAsmMacro *parseMacroLikeBody(
SMLoc DirectiveLoc);
452 void instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
454 bool parseDirectiveRept(
SMLoc DirectiveLoc);
455 bool parseDirectiveIrp(
SMLoc DirectiveLoc);
456 bool parseDirectiveIrpc(
SMLoc DirectiveLoc);
457 bool parseDirectiveEndr(
SMLoc DirectiveLoc);
460 bool parseDirectiveMSEmit(
SMLoc DirectiveLoc, ParseStatementInfo &Info,
464 bool parseDirectiveMSAlign(
SMLoc DirectiveLoc, ParseStatementInfo &Info);
466 void initializeDirectiveKindMap();
482 : Lexer(_MAI), Ctx(_Ctx), Out(_Out), MAI(_MAI),
SrcMgr(_SM),
483 PlatformParser(0), CurBuffer(0), MacrosEnabledFlag(
true),
484 CppHashLineNumber(0), AssemblerDialect(~0U), IsDarwin(
false),
485 ParsingInlineAsm(
false) {
499 PlatformParser->Initialize(*
this);
502 PlatformParser->Initialize(*
this);
506 PlatformParser->Initialize(*
this);
509 initializeDirectiveKindMap();
512 AsmParser::~AsmParser() {
513 assert(ActiveMacros.empty() &&
"Unexpected active macro instantiation!");
519 delete it->getValue();
521 delete PlatformParser;
524 void AsmParser::printMacroInstantiations() {
526 for (std::vector<MacroInstantiation *>::const_reverse_iterator
527 it = ActiveMacros.rbegin(),
528 ie = ActiveMacros.rend();
530 printMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
531 "while in macro instantiation");
536 return Error(L, Msg, Ranges);
537 printMessage(L, SourceMgr::DK_Warning, Msg, Ranges);
538 printMacroInstantiations();
544 printMessage(L, SourceMgr::DK_Error, Msg, Ranges);
545 printMacroInstantiations();
549 bool AsmParser::enterIncludeFile(
const std::string &Filename) {
550 std::string IncludedFile;
565 bool AsmParser::processIncbinFile(
const std::string &Filename) {
566 std::string IncludedFile;
576 void AsmParser::jumpToLoc(
SMLoc Loc,
int InBuffer) {
577 if (InBuffer != -1) {
578 CurBuffer = InBuffer;
592 if (ParentIncludeLoc !=
SMLoc()) {
593 jumpToLoc(ParentIncludeLoc);
599 Error(Lexer.getErrLoc(), Lexer.getErr());
604 bool AsmParser::Run(
bool NoInitialTextSection,
bool NoFinalize) {
606 if (!NoInitialTextSection)
613 AsmCond StartingCondState = TheCondState;
617 if (getContext().getGenDwarfForAssembly()) {
618 getContext().setGenDwarfSection(getStreamer().getCurrentSection().first);
619 MCSymbol *SectionStartSym = getContext().CreateTempSymbol();
620 getStreamer().EmitLabel(SectionStartSym);
621 getContext().setGenDwarfSectionStartSym(SectionStartSym);
622 getStreamer().EmitDwarfFileDirective(getContext().nextGenDwarfFileNumber(),
624 getContext().getMainFileName());
629 ParseStatementInfo Info;
630 if (!parseStatement(Info))
635 assert(HadError &&
"Parse statement returned an error, but none emitted!");
636 eatToEndOfStatement();
639 if (TheCondState.TheCond != StartingCondState.
TheCond ||
640 TheCondState.Ignore != StartingCondState.
Ignore)
641 return TokError(
"unmatched .ifs or .elses");
645 getContext().getMCDwarfFiles();
646 for (
unsigned i = 1; i < MCDwarfFiles.
size(); i++) {
647 if (!MCDwarfFiles[i])
648 TokError(
"unassigned file number: " +
Twine(i) +
" for .file directives");
655 if (!NoFinalize && MAI.hasSubsectionsViaSymbols()) {
669 getLexer().getLoc(), SourceMgr::DK_Error,
670 "assembler local symbol '" + Sym->
getName() +
"' not defined");
676 if (!HadError && !NoFinalize)
682 void AsmParser::checkForValidSection() {
683 if (!ParsingInlineAsm && !getStreamer().getCurrentSection().first) {
684 TokError(
"expected section directive before assembly directive");
685 Out.InitToTextSection();
690 void AsmParser::eatToEndOfStatement() {
691 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
695 if (Lexer.is(AsmToken::EndOfStatement))
699 StringRef AsmParser::parseStringToEndOfStatement() {
700 const char *Start = getTok().getLoc().getPointer();
702 while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(
AsmToken::Eof))
705 const char *End = getTok().getLoc().getPointer();
709 StringRef AsmParser::parseStringToComma() {
710 const char *Start = getTok().getLoc().getPointer();
712 while (Lexer.isNot(AsmToken::EndOfStatement) &&
716 const char *End = getTok().getLoc().getPointer();
725 bool AsmParser::parseParenExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
726 if (parseExpression(Res))
728 if (Lexer.isNot(AsmToken::RParen))
729 return TokError(
"expected ')' in parentheses expression");
730 EndLoc = Lexer.getTok().getEndLoc();
740 bool AsmParser::parseBracketExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
741 if (parseExpression(Res))
743 if (Lexer.isNot(AsmToken::RBrac))
744 return TokError(
"expected ']' in brackets expression");
745 EndLoc = Lexer.getTok().getEndLoc();
756 bool AsmParser::parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc) {
757 SMLoc FirstTokenLoc = getLexer().getLoc();
759 switch (FirstTokenKind) {
761 return TokError(
"unknown token in expression");
765 case AsmToken::Exclaim:
767 if (parsePrimaryExpr(Res, EndLoc))
769 Res = MCUnaryExpr::CreateLNot(Res, getContext());
771 case AsmToken::Dollar:
774 case AsmToken::Identifier: {
776 if (parseIdentifier(Identifier)) {
777 if (FirstTokenKind == AsmToken::Dollar) {
778 if (Lexer.getMAI().getDollarIsPC()) {
781 MCSymbol *Sym = Ctx.CreateTempSymbol();
783 Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None,
785 EndLoc = FirstTokenLoc;
788 return Error(FirstTokenLoc,
"invalid token in expression");
793 EndLoc = SMLoc::getFromPointer(Identifier.
end());
798 std::pair<StringRef, StringRef>
Split = Identifier.
split(
'@');
801 if (Split.first.size() != Identifier.
size()) {
802 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
803 if (Variant != MCSymbolRefExpr::VK_Invalid) {
804 SymbolName = Split.first;
805 }
else if (MAI.doesAllowAtInName()) {
806 Variant = MCSymbolRefExpr::VK_None;
808 Variant = MCSymbolRefExpr::VK_None;
809 return TokError(
"invalid variant '" + Split.second +
"'");
813 MCSymbol *Sym = getContext().GetOrCreateSymbol(SymbolName);
819 return Error(EndLoc,
"unexpected modifier on variable reference");
826 Res = MCSymbolRefExpr::Create(Sym, Variant, getContext());
829 case AsmToken::Integer: {
830 SMLoc Loc = getTok().getLoc();
831 int64_t
IntVal = getTok().getIntVal();
832 Res = MCConstantExpr::Create(IntVal, getContext());
833 EndLoc = Lexer.getTok().getEndLoc();
836 if (Lexer.getKind() == AsmToken::Identifier) {
839 std::pair<StringRef, StringRef> Split = IDVal.
split(
'@');
841 if (Split.first.size() != IDVal.
size()) {
842 Variant = MCSymbolRefExpr::getVariantKindForName(Split.second);
843 if (Variant == MCSymbolRefExpr::VK_Invalid) {
844 Variant = MCSymbolRefExpr::VK_None;
845 return TokError(
"invalid variant '" + Split.second +
"'");
849 if (IDVal ==
"f" || IDVal ==
"b") {
851 Ctx.GetDirectionalLocalSymbol(IntVal, IDVal ==
"f" ? 1 : 0);
852 Res = MCSymbolRefExpr::Create(Sym, Variant, getContext());
854 return Error(Loc,
"invalid reference to undefined symbol");
855 EndLoc = Lexer.getTok().getEndLoc();
861 case AsmToken::Real: {
862 APFloat RealVal(APFloat::IEEEdouble, getTok().getString());
863 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
864 Res = MCConstantExpr::Create(IntVal, getContext());
865 EndLoc = Lexer.getTok().getEndLoc();
869 case AsmToken::Dot: {
872 MCSymbol *Sym = Ctx.CreateTempSymbol();
874 Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext());
875 EndLoc = Lexer.getTok().getEndLoc();
879 case AsmToken::LParen:
881 return parseParenExpr(Res, EndLoc);
882 case AsmToken::LBrac:
883 if (!PlatformParser->HasBracketExpressions())
884 return TokError(
"brackets expression not supported on this target");
886 return parseBracketExpr(Res, EndLoc);
887 case AsmToken::Minus:
889 if (parsePrimaryExpr(Res, EndLoc))
891 Res = MCUnaryExpr::CreateMinus(Res, getContext());
895 if (parsePrimaryExpr(Res, EndLoc))
897 Res = MCUnaryExpr::CreatePlus(Res, getContext());
899 case AsmToken::Tilde:
901 if (parsePrimaryExpr(Res, EndLoc))
903 Res = MCUnaryExpr::CreateNot(Res, getContext());
908 bool AsmParser::parseExpression(
const MCExpr *&Res) {
910 return parseExpression(Res, EndLoc);
914 AsmParser::applyModifierToExpr(
const MCExpr *E,
917 const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
927 case MCExpr::SymbolRef: {
930 if (SRE->
getKind() != MCSymbolRefExpr::VK_None) {
931 TokError(
"invalid variant on expression '" + getTok().getIdentifier() +
932 "' (already modified)");
936 return MCSymbolRefExpr::Create(&SRE->
getSymbol(), Variant, getContext());
939 case MCExpr::Unary: {
944 return MCUnaryExpr::Create(UE->
getOpcode(), Sub, getContext());
947 case MCExpr::Binary: {
949 const MCExpr *LHS = applyModifierToExpr(BE->
getLHS(), Variant);
950 const MCExpr *RHS = applyModifierToExpr(BE->
getRHS(), Variant);
960 return MCBinaryExpr::Create(BE->
getOpcode(), LHS, RHS, getContext());
977 bool AsmParser::parseExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
980 if (parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
986 if (Lexer.getKind() == AsmToken::At) {
989 if (Lexer.isNot(AsmToken::Identifier))
990 return TokError(
"unexpected symbol modifier following '@'");
993 MCSymbolRefExpr::getVariantKindForName(getTok().getIdentifier());
994 if (Variant == MCSymbolRefExpr::VK_Invalid)
995 return TokError(
"invalid variant '" + getTok().getIdentifier() +
"'");
997 const MCExpr *ModifiedRes = applyModifierToExpr(Res, Variant);
999 return TokError(
"invalid modifier '" + getTok().getIdentifier() +
1000 "' (no symbols present)");
1009 if (Res->EvaluateAsAbsolute(Value))
1010 Res = MCConstantExpr::Create(Value, getContext());
1015 bool AsmParser::parseParenExpression(
const MCExpr *&Res,
SMLoc &EndLoc) {
1017 return parseParenExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc);
1020 bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
1023 SMLoc StartLoc = Lexer.getLoc();
1024 if (parseExpression(Expr))
1027 if (!Expr->EvaluateAsAbsolute(Res))
1028 return Error(StartLoc,
"expected absolute expression");
1040 case AsmToken::AmpAmp:
1041 Kind = MCBinaryExpr::LAnd;
1043 case AsmToken::PipePipe:
1044 Kind = MCBinaryExpr::LOr;
1050 case AsmToken::Pipe:
1053 case AsmToken::Caret:
1061 case AsmToken::EqualEqual:
1064 case AsmToken::ExclaimEqual:
1065 case AsmToken::LessGreater:
1071 case AsmToken::LessEqual:
1072 Kind = MCBinaryExpr::LTE;
1074 case AsmToken::Greater:
1077 case AsmToken::GreaterEqual:
1078 Kind = MCBinaryExpr::GTE;
1082 case AsmToken::LessLess:
1083 Kind = MCBinaryExpr::Shl;
1085 case AsmToken::GreaterGreater:
1086 Kind = MCBinaryExpr::Shr;
1090 case AsmToken::Plus:
1091 Kind = MCBinaryExpr::Add;
1093 case AsmToken::Minus:
1094 Kind = MCBinaryExpr::Sub;
1098 case AsmToken::Star:
1099 Kind = MCBinaryExpr::Mul;
1101 case AsmToken::Slash:
1102 Kind = MCBinaryExpr::Div;
1104 case AsmToken::Percent:
1105 Kind = MCBinaryExpr::Mod;
1112 bool AsmParser::parseBinOpRHS(
unsigned Precedence,
const MCExpr *&Res,
1120 if (TokPrec < Precedence)
1127 if (parsePrimaryExpr(RHS, EndLoc))
1134 if (TokPrec < NextTokPrec && parseBinOpRHS(TokPrec + 1, RHS, EndLoc))
1138 Res = MCBinaryExpr::Create(Kind, Res, RHS, getContext());
1146 bool AsmParser::parseStatement(ParseStatementInfo &Info) {
1147 if (Lexer.is(AsmToken::EndOfStatement)) {
1157 int64_t LocalLabelVal = -1;
1159 if (Lexer.is(AsmToken::Hash))
1160 return parseCppHashLineFilenameComment(IDLoc);
1163 if (Lexer.is(AsmToken::Integer)) {
1164 LocalLabelVal = getTok().getIntVal();
1165 if (LocalLabelVal < 0) {
1166 if (!TheCondState.Ignore)
1167 return TokError(
"unexpected token at start of statement");
1170 IDVal = getTok().getString();
1172 if (Lexer.getKind() != AsmToken::Colon) {
1173 if (!TheCondState.Ignore)
1174 return TokError(
"unexpected token at start of statement");
1177 }
else if (Lexer.is(AsmToken::Dot)) {
1181 }
else if (parseIdentifier(IDVal)) {
1182 if (!TheCondState.Ignore)
1183 return TokError(
"unexpected token at start of statement");
1191 DirectiveKindMap.find(IDVal);
1192 DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
1199 return parseDirectiveIf(IDLoc);
1201 return parseDirectiveIfb(IDLoc,
true);
1203 return parseDirectiveIfb(IDLoc,
false);
1205 return parseDirectiveIfc(IDLoc,
true);
1207 return parseDirectiveIfc(IDLoc,
false);
1209 return parseDirectiveIfdef(IDLoc,
true);
1212 return parseDirectiveIfdef(IDLoc,
false);
1214 return parseDirectiveElseIf(IDLoc);
1216 return parseDirectiveElse(IDLoc);
1218 return parseDirectiveEndIf(IDLoc);
1223 if (TheCondState.Ignore) {
1224 eatToEndOfStatement();
1231 switch (Lexer.getKind()) {
1232 case AsmToken::Colon: {
1233 checkForValidSection();
1240 return Error(IDLoc,
"invalid use of pseudo-symbol '.' as a label");
1248 if (LocalLabelVal == -1)
1249 Sym = getContext().GetOrCreateSymbol(IDVal);
1251 Sym = Ctx.CreateDirectionalLocalSymbol(LocalLabelVal);
1253 return Error(IDLoc,
"invalid symbol redefinition");
1256 if (!ParsingInlineAsm)
1261 if (getContext().getGenDwarfForAssembly())
1262 MCGenDwarfLabelEntry::Make(Sym, &getStreamer(), getSourceManager(),
1265 getTargetParser().onLabelParsed(Sym);
1269 if (Lexer.is(AsmToken::EndOfStatement)) {
1278 case AsmToken::Equal:
1282 return parseAssignment(IDVal,
true);
1289 if (areMacrosEnabled())
1290 if (
const MCAsmMacro *M = lookupMacro(IDVal)) {
1291 return handleMacroEntry(M, IDLoc);
1297 if (IDVal[0] ==
'.' && IDVal !=
".") {
1311 if (!getTargetParser().ParseDirective(ID))
1316 std::pair<MCAsmParserExtension *, DirectiveHandler> Handler =
1317 ExtensionDirectiveMap.lookup(IDVal);
1319 return (*Handler.second)(Handler.first, IDVal, IDLoc);
1328 return parseDirectiveSet(IDVal,
true);
1330 return parseDirectiveSet(IDVal,
false);
1332 return parseDirectiveAscii(IDVal,
false);
1335 return parseDirectiveAscii(IDVal,
true);
1337 return parseDirectiveValue(1);
1341 return parseDirectiveValue(2);
1345 return parseDirectiveValue(4);
1348 return parseDirectiveValue(8);
1351 return parseDirectiveRealValue(APFloat::IEEEsingle);
1353 return parseDirectiveRealValue(APFloat::IEEEdouble);
1355 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1356 return parseDirectiveAlign(IsPow2, 1);
1359 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
1360 return parseDirectiveAlign(IsPow2, 4);
1363 return parseDirectiveAlign(
false, 1);
1365 return parseDirectiveAlign(
false, 2);
1367 return parseDirectiveAlign(
false, 4);
1369 return parseDirectiveAlign(
true, 1);
1371 return parseDirectiveAlign(
true, 2);
1373 return parseDirectiveAlign(
true, 4);
1375 return parseDirectiveOrg();
1377 return parseDirectiveFill();
1379 return parseDirectiveZero();
1381 eatToEndOfStatement();
1385 return parseDirectiveSymbolAttribute(
MCSA_Global);
1386 case DK_LAZY_REFERENCE:
1388 case DK_NO_DEAD_STRIP:
1390 case DK_SYMBOL_RESOLVER:
1392 case DK_PRIVATE_EXTERN:
1396 case DK_WEAK_DEFINITION:
1398 case DK_WEAK_REFERENCE:
1400 case DK_WEAK_DEF_CAN_BE_HIDDEN:
1404 return parseDirectiveComm(
false);
1406 return parseDirectiveComm(
true);
1408 return parseDirectiveAbort();
1410 return parseDirectiveInclude();
1412 return parseDirectiveIncbin();
1415 return TokError(
Twine(IDVal) +
" not supported yet");
1417 return parseDirectiveRept(IDLoc);
1419 return parseDirectiveIrp(IDLoc);
1421 return parseDirectiveIrpc(IDLoc);
1423 return parseDirectiveEndr(IDLoc);
1424 case DK_BUNDLE_ALIGN_MODE:
1425 return parseDirectiveBundleAlignMode();
1426 case DK_BUNDLE_LOCK:
1427 return parseDirectiveBundleLock();
1428 case DK_BUNDLE_UNLOCK:
1429 return parseDirectiveBundleUnlock();
1431 return parseDirectiveLEB128(
true);
1433 return parseDirectiveLEB128(
false);
1436 return parseDirectiveSpace(IDVal);
1438 return parseDirectiveFile(IDLoc);
1440 return parseDirectiveLine();
1442 return parseDirectiveLoc();
1444 return parseDirectiveStabs();
1445 case DK_CFI_SECTIONS:
1446 return parseDirectiveCFISections();
1447 case DK_CFI_STARTPROC:
1448 return parseDirectiveCFIStartProc();
1449 case DK_CFI_ENDPROC:
1450 return parseDirectiveCFIEndProc();
1451 case DK_CFI_DEF_CFA:
1452 return parseDirectiveCFIDefCfa(IDLoc);
1453 case DK_CFI_DEF_CFA_OFFSET:
1454 return parseDirectiveCFIDefCfaOffset();
1455 case DK_CFI_ADJUST_CFA_OFFSET:
1456 return parseDirectiveCFIAdjustCfaOffset();
1457 case DK_CFI_DEF_CFA_REGISTER:
1458 return parseDirectiveCFIDefCfaRegister(IDLoc);
1460 return parseDirectiveCFIOffset(IDLoc);
1461 case DK_CFI_REL_OFFSET:
1462 return parseDirectiveCFIRelOffset(IDLoc);
1463 case DK_CFI_PERSONALITY:
1464 return parseDirectiveCFIPersonalityOrLsda(
true);
1466 return parseDirectiveCFIPersonalityOrLsda(
false);
1467 case DK_CFI_REMEMBER_STATE:
1468 return parseDirectiveCFIRememberState();
1469 case DK_CFI_RESTORE_STATE:
1470 return parseDirectiveCFIRestoreState();
1471 case DK_CFI_SAME_VALUE:
1472 return parseDirectiveCFISameValue(IDLoc);
1473 case DK_CFI_RESTORE:
1474 return parseDirectiveCFIRestore(IDLoc);
1476 return parseDirectiveCFIEscape();
1477 case DK_CFI_SIGNAL_FRAME:
1478 return parseDirectiveCFISignalFrame();
1479 case DK_CFI_UNDEFINED:
1480 return parseDirectiveCFIUndefined(IDLoc);
1481 case DK_CFI_REGISTER:
1482 return parseDirectiveCFIRegister(IDLoc);
1483 case DK_CFI_WINDOW_SAVE:
1484 return parseDirectiveCFIWindowSave();
1487 return parseDirectiveMacrosOnOff(IDVal);
1489 return parseDirectiveMacro(IDLoc);
1492 return parseDirectiveEndMacro(IDVal);
1494 return parseDirectivePurgeMacro(IDLoc);
1497 return Error(IDLoc,
"unknown directive");
1501 if (ParsingInlineAsm && (IDVal ==
"_emit" || IDVal ==
"__emit" ||
1502 IDVal ==
"_EMIT" || IDVal ==
"__EMIT"))
1503 return parseDirectiveMSEmit(IDLoc, Info, IDVal.
size());
1506 if (ParsingInlineAsm && (IDVal ==
"align" || IDVal ==
"ALIGN"))
1507 return parseDirectiveMSAlign(IDLoc, Info);
1509 checkForValidSection();
1512 std::string OpcodeStr = IDVal.
lower();
1514 bool HadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, IDLoc,
1515 Info.ParsedOperands);
1516 Info.ParseError = HadError;
1519 if (getShowParsedOperands()) {
1522 OS <<
"parsed instruction: [";
1523 for (
unsigned i = 0; i != Info.ParsedOperands.size(); ++i) {
1526 Info.ParsedOperands[i]->print(OS);
1530 printMessage(IDLoc, SourceMgr::DK_Note, OS.str());
1536 if (!HadError && getContext().getGenDwarfForAssembly() &&
1537 getContext().getGenDwarfSection() ==
1538 getStreamer().getCurrentSection().first) {
1546 getContext().getMCDwarfFiles();
1547 if (CppHashFilename.size() != 0) {
1548 if (MCDwarfFiles[getContext().getGenDwarfFileNumber()]->getName() !=
1550 getStreamer().EmitDwarfFileDirective(
1551 getContext().nextGenDwarfFileNumber(),
StringRef(),
1557 unsigned CppHashLocLineNo;
1558 if (LastQueryIDLoc == CppHashLoc && LastQueryBuffer == CppHashBuf)
1559 CppHashLocLineNo = LastQueryLine;
1562 LastQueryLine = CppHashLocLineNo;
1563 LastQueryIDLoc = CppHashLoc;
1564 LastQueryBuffer = CppHashBuf;
1566 Line = CppHashLineNumber - 1 + (Line - CppHashLocLineNo);
1569 getStreamer().EmitDwarfLocDirective(
1570 getContext().getGenDwarfFileNumber(), Line, 0,
1578 HadError = getTargetParser().MatchAndEmitInstruction(
1579 IDLoc, Info.Opcode, Info.ParsedOperands, Out, ErrorInfo,
1590 void AsmParser::eatToEndOfLine() {
1591 if (!Lexer.is(AsmToken::EndOfStatement))
1592 Lexer.LexUntilEndOfLine();
1600 bool AsmParser::parseCppHashLineFilenameComment(
const SMLoc &L) {
1603 if (getLexer().isNot(AsmToken::Integer)) {
1610 int64_t LineNumber = getTok().getIntVal();
1618 StringRef Filename = getTok().getString();
1620 Filename = Filename.
substr(1, Filename.
size() - 2);
1624 CppHashFilename = Filename;
1625 CppHashLineNumber = LineNumber;
1626 CppHashBuf = CurBuffer;
1635 void AsmParser::DiagHandler(
const SMDiagnostic &Diag,
void *Context) {
1636 const AsmParser *Parser =
static_cast<const AsmParser *
>(Context);
1642 int CppHashBuf = Parser->SrcMgr.FindBufferContainingLoc(Parser->CppHashLoc);
1647 if (!Parser->SavedDiagHandler && DiagCurBuffer > 0) {
1655 if (!Parser->CppHashLineNumber || &DiagSrcMgr != &Parser->SrcMgr ||
1656 DiagBuf != CppHashBuf) {
1657 if (Parser->SavedDiagHandler)
1658 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
1667 const std::string &Filename = Parser->CppHashFilename;
1670 int CppHashLocLineNo =
1671 Parser->SrcMgr.FindLineNumber(Parser->CppHashLoc, CppHashBuf);
1673 Parser->CppHashLineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo);
1679 if (Parser->SavedDiagHandler)
1680 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
1682 NewDiag.print(0, OS);
1690 return isalnum(static_cast<unsigned char>(c)) || c ==
'_' || c ==
'$' ||
1695 const MCAsmMacroParameters &Parameters,
1696 const MCAsmMacroArguments &
A,
const SMLoc &L) {
1697 unsigned NParameters = Parameters.size();
1698 if (NParameters != 0 && NParameters != A.size())
1699 return Error(L,
"Wrong number of arguments");
1703 while (!Body.
empty()) {
1705 std::size_t End = Body.
size(), Pos = 0;
1706 for (; Pos != End; ++Pos) {
1710 if (Body[Pos] !=
'$' || Pos + 1 == End)
1713 char Next = Body[Pos + 1];
1714 if (Next ==
'$' || Next ==
'n' ||
1715 isdigit(static_cast<unsigned char>(Next)))
1719 if (Body[Pos] ==
'\\' && Pos + 1 != End)
1725 OS << Body.
slice(0, Pos);
1732 switch (Body[Pos + 1]) {
1746 unsigned Index = Body[Pos + 1] -
'0';
1747 if (Index >= A.size())
1751 for (MCAsmMacroArgument::const_iterator it = A[Index].
begin(),
1752 ie = A[Index].
end();
1754 OS << it->getString();
1760 unsigned I = Pos + 1;
1764 const char *Begin = Body.
data() + Pos + 1;
1767 for (; Index < NParameters; ++Index)
1768 if (Parameters[Index].first ==
Argument)
1771 if (Index == NParameters) {
1772 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
1779 for (MCAsmMacroArgument::const_iterator it = A[Index].
begin(),
1780 ie = A[Index].
end();
1783 OS << it->getStringContents();
1785 OS << it->getString();
1797 MacroInstantiation::MacroInstantiation(
const MCAsmMacro *M,
SMLoc IL,
int EB,
1799 : TheMacro(M), Instantiation(I), InstantiationLoc(IL), ExitBuffer(EB),
1806 case AsmToken::Plus:
1807 case AsmToken::Minus:
1808 case AsmToken::Tilde:
1809 case AsmToken::Slash:
1810 case AsmToken::Star:
1812 case AsmToken::Equal:
1813 case AsmToken::EqualEqual:
1814 case AsmToken::Pipe:
1815 case AsmToken::PipePipe:
1816 case AsmToken::Caret:
1818 case AsmToken::AmpAmp:
1819 case AsmToken::Exclaim:
1820 case AsmToken::ExclaimEqual:
1821 case AsmToken::Percent:
1823 case AsmToken::LessEqual:
1824 case AsmToken::LessLess:
1825 case AsmToken::LessGreater:
1826 case AsmToken::Greater:
1827 case AsmToken::GreaterEqual:
1828 case AsmToken::GreaterGreater:
1833 bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
1835 unsigned ParenLevel = 0;
1836 unsigned AddTokens = 0;
1840 Lexer.setSkipSpace(
false);
1844 Lexer.setSkipSpace(
true);
1845 return TokError(
"unexpected token in macro instantiation");
1848 if (ParenLevel == 0 && Lexer.is(AsmToken::Comma)) {
1851 ArgumentDelimiter = AsmToken::Comma;
1852 else if (ArgumentDelimiter != AsmToken::Comma) {
1853 Lexer.setSkipSpace(
true);
1854 return TokError(
"expected ' ' for macro argument separator");
1859 if (Lexer.is(AsmToken::Space)) {
1865 if (ArgumentDelimiter == AsmToken::Space ||
1870 const char *NextChar = getTok().getEndLoc().getPointer();
1871 if (*NextChar ==
' ')
1875 if (!AddTokens && ParenLevel == 0) {
1878 ArgumentDelimiter = AsmToken::Space;
1886 if (Lexer.is(AsmToken::EndOfStatement))
1890 if (Lexer.is(AsmToken::LParen))
1892 else if (Lexer.is(AsmToken::RParen) && ParenLevel)
1896 MA.push_back(getTok());
1902 Lexer.setSkipSpace(
true);
1903 if (ParenLevel != 0)
1904 return TokError(
"unbalanced parentheses in macro argument");
1909 bool AsmParser::parseMacroArguments(
const MCAsmMacro *M,
1910 MCAsmMacroArguments &A) {
1911 const unsigned NParameters = M ? M->Parameters.size() : 0;
1919 for (
unsigned Parameter = 0; !NParameters || Parameter < NParameters;
1921 MCAsmMacroArgument MA;
1923 if (parseMacroArgument(MA, ArgumentDelimiter))
1926 if (!MA.empty() || !NParameters)
1928 else if (NParameters) {
1929 if (!M->Parameters[Parameter].second.empty())
1930 A.push_back(M->Parameters[Parameter].second);
1936 if (Lexer.is(AsmToken::EndOfStatement)) {
1937 if (NParameters && Parameter < NParameters - 1) {
1938 if (M->Parameters[Parameter + 1].second.empty())
1939 return TokError(
"macro argument '" +
1940 Twine(M->Parameters[Parameter + 1].first) +
1948 if (Lexer.is(AsmToken::Comma))
1951 return TokError(
"Too many arguments");
1956 return (I == MacroMap.end()) ? NULL : I->getValue();
1959 void AsmParser::defineMacro(
StringRef Name,
const MCAsmMacro &Macro) {
1960 MacroMap[
Name] =
new MCAsmMacro(Macro);
1963 void AsmParser::undefineMacro(
StringRef Name) {
1965 if (I != MacroMap.end()) {
1966 delete I->getValue();
1971 bool AsmParser::handleMacroEntry(
const MCAsmMacro *M,
SMLoc NameLoc) {
1974 if (ActiveMacros.size() == 20)
1975 return TokError(
"macros cannot be nested more than 20 levels deep");
1977 MCAsmMacroArguments
A;
1978 if (parseMacroArguments(M, A))
1984 while (!A.empty() && A.back().empty())
1993 if (expandMacro(OS, Body, M->Parameters, A, getTok().getLoc()))
1998 OS <<
".endmacro\n";
2001 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
2005 MacroInstantiation *
MI =
new MacroInstantiation(
2006 M, NameLoc, CurBuffer, getTok().getLoc(), Instantiation);
2007 ActiveMacros.push_back(MI);
2017 void AsmParser::handleMacroExit() {
2019 jumpToLoc(ActiveMacros.back()->ExitLoc, ActiveMacros.back()->ExitBuffer);
2023 delete ActiveMacros.back();
2024 ActiveMacros.pop_back();
2029 case MCExpr::Binary: {
2033 case MCExpr::Target:
2036 case MCExpr::SymbolRef: {
2044 return isUsedIn(Sym, static_cast<const MCUnaryExpr *>(Value)->getSubExpr());
2050 bool AsmParser::parseAssignment(
StringRef Name,
bool allow_redef,
2053 SMLoc EqualLoc = Lexer.getLoc();
2056 if (parseExpression(Value))
2063 if (Lexer.isNot(AsmToken::EndOfStatement))
2064 return TokError(
"unexpected token in assignment");
2068 return Error(EqualLoc, (
"assignment to pseudo-symbol '.' is unsupported "
2069 "(use '.space' or '.org').)"));
2077 MCSymbol *Sym = getContext().LookupSymbol(Name);
2084 return Error(EqualLoc,
"Recursive use of '" + Name +
"'");
2090 return Error(EqualLoc,
"redefinition of '" + Name +
"'");
2092 return Error(EqualLoc,
"invalid assignment to '" + Name +
"'");
2094 return Error(EqualLoc,
"invalid reassignment of non-absolute variable '" +
2100 Sym = getContext().GetOrCreateSymbol(Name);
2105 Out.EmitAssignment(Sym, Value);
2115 bool AsmParser::parseIdentifier(
StringRef &Res) {
2121 if (Lexer.is(AsmToken::Dollar) || Lexer.is(AsmToken::At)) {
2122 SMLoc PrefixLoc = getLexer().getLoc();
2126 if (Lexer.isNot(AsmToken::Identifier))
2130 if (PrefixLoc.
getPointer() + 1 != getTok().getLoc().getPointer())
2143 Res = getTok().getIdentifier();
2154 bool AsmParser::parseDirectiveSet(
StringRef IDVal,
bool allow_redef) {
2157 if (parseIdentifier(Name))
2158 return TokError(
"expected identifier after '" +
Twine(IDVal) +
"'");
2160 if (getLexer().isNot(AsmToken::Comma))
2161 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"'");
2164 return parseAssignment(Name, allow_redef,
true);
2167 bool AsmParser::parseEscapedString(std::string &Data) {
2171 StringRef Str = getTok().getStringContents();
2172 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
2173 if (Str[i] !=
'\\') {
2182 return TokError(
"unexpected backslash at end of string");
2185 if ((
unsigned)(Str[i] -
'0') <= 7) {
2187 unsigned Value = Str[i] -
'0';
2189 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2191 Value = Value * 8 + (Str[i] -
'0');
2193 if (i + 1 != e && ((
unsigned)(Str[i + 1] -
'0')) <= 7) {
2195 Value = Value * 8 + (Str[i] -
'0');
2200 return TokError(
"invalid octal escape sequence (out of range)");
2202 Data += (
unsigned char)Value;
2210 return TokError(
"invalid escape sequence (unrecognized character)");
2212 case 'b': Data +=
'\b';
break;
2213 case 'f': Data +=
'\f';
break;
2214 case 'n': Data +=
'\n';
break;
2215 case 'r': Data +=
'\r';
break;
2216 case 't': Data +=
'\t';
break;
2217 case '"': Data +=
'"';
break;
2218 case '\\': Data +=
'\\';
break;
2227 bool AsmParser::parseDirectiveAscii(
StringRef IDVal,
bool ZeroTerminated) {
2228 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2229 checkForValidSection();
2233 return TokError(
"expected string in '" +
Twine(IDVal) +
"' directive");
2236 if (parseEscapedString(Data))
2239 getStreamer().EmitBytes(Data);
2241 getStreamer().EmitBytes(
StringRef(
"\0", 1));
2245 if (getLexer().is(AsmToken::EndOfStatement))
2248 if (getLexer().isNot(AsmToken::Comma))
2249 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
2260 bool AsmParser::parseDirectiveValue(
unsigned Size) {
2261 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2262 checkForValidSection();
2266 SMLoc ExprLoc = getLexer().getLoc();
2267 if (parseExpression(Value))
2271 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2272 assert(Size <= 8 &&
"Invalid size");
2273 uint64_t IntValue = MCE->getValue();
2274 if (!
isUIntN(8 * Size, IntValue) && !
isIntN(8 * Size, IntValue))
2275 return Error(ExprLoc,
"literal value out of range for directive");
2276 getStreamer().EmitIntValue(IntValue, Size);
2278 getStreamer().EmitValue(Value, Size);
2280 if (getLexer().is(AsmToken::EndOfStatement))
2284 if (getLexer().isNot(AsmToken::Comma))
2285 return TokError(
"unexpected token in directive");
2296 bool AsmParser::parseDirectiveRealValue(
const fltSemantics &Semantics) {
2297 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2298 checkForValidSection();
2304 if (getLexer().is(AsmToken::Minus)) {
2307 }
else if (getLexer().is(AsmToken::Plus))
2310 if (getLexer().isNot(AsmToken::Integer) &&
2311 getLexer().isNot(AsmToken::Real) &&
2312 getLexer().isNot(AsmToken::Identifier))
2313 return TokError(
"unexpected token in directive");
2318 if (getLexer().is(AsmToken::Identifier)) {
2320 Value = APFloat::getInf(Semantics);
2322 Value = APFloat::getNaN(Semantics,
false, ~0);
2324 return TokError(
"invalid floating point literal");
2325 }
else if (Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven) ==
2326 APFloat::opInvalidOp)
2327 return TokError(
"invalid floating point literal");
2335 APInt AsInt = Value.bitcastToAPInt();
2339 if (getLexer().is(AsmToken::EndOfStatement))
2342 if (getLexer().isNot(AsmToken::Comma))
2343 return TokError(
"unexpected token in directive");
2354 bool AsmParser::parseDirectiveZero() {
2355 checkForValidSection();
2358 if (parseAbsoluteExpression(NumBytes))
2362 if (getLexer().is(AsmToken::Comma)) {
2364 if (parseAbsoluteExpression(Val))
2368 if (getLexer().isNot(AsmToken::EndOfStatement))
2369 return TokError(
"unexpected token in '.zero' directive");
2373 getStreamer().EmitFill(NumBytes, Val);
2380 bool AsmParser::parseDirectiveFill() {
2381 checkForValidSection();
2384 if (parseAbsoluteExpression(NumValues))
2387 int64_t FillSize = 1;
2388 int64_t FillExpr = 0;
2390 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2391 if (getLexer().isNot(AsmToken::Comma))
2392 return TokError(
"unexpected token in '.fill' directive");
2395 if (parseAbsoluteExpression(FillSize))
2398 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2399 if (getLexer().isNot(AsmToken::Comma))
2400 return TokError(
"unexpected token in '.fill' directive");
2403 if (parseAbsoluteExpression(FillExpr))
2406 if (getLexer().isNot(AsmToken::EndOfStatement))
2407 return TokError(
"unexpected token in '.fill' directive");
2413 if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8)
2414 return TokError(
"invalid '.fill' size, expected 1, 2, 4, or 8");
2416 for (uint64_t i = 0, e = NumValues; i != e; ++i)
2417 getStreamer().EmitIntValue(FillExpr, FillSize);
2424 bool AsmParser::parseDirectiveOrg() {
2425 checkForValidSection();
2428 SMLoc Loc = getTok().getLoc();
2429 if (parseExpression(Offset))
2433 int64_t FillExpr = 0;
2434 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2435 if (getLexer().isNot(AsmToken::Comma))
2436 return TokError(
"unexpected token in '.org' directive");
2439 if (parseAbsoluteExpression(FillExpr))
2442 if (getLexer().isNot(AsmToken::EndOfStatement))
2443 return TokError(
"unexpected token in '.org' directive");
2451 if (getStreamer().EmitValueToOffset(Offset, FillExpr))
2452 return Error(Loc,
"expected assembly-time absolute expression");
2459 bool AsmParser::parseDirectiveAlign(
bool IsPow2,
unsigned ValueSize) {
2460 checkForValidSection();
2462 SMLoc AlignmentLoc = getLexer().getLoc();
2464 if (parseAbsoluteExpression(Alignment))
2468 bool HasFillExpr =
false;
2469 int64_t FillExpr = 0;
2470 int64_t MaxBytesToFill = 0;
2471 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2472 if (getLexer().isNot(AsmToken::Comma))
2473 return TokError(
"unexpected token in directive");
2479 if (getLexer().isNot(AsmToken::Comma)) {
2481 if (parseAbsoluteExpression(FillExpr))
2485 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2486 if (getLexer().isNot(AsmToken::Comma))
2487 return TokError(
"unexpected token in directive");
2490 MaxBytesLoc = getLexer().getLoc();
2491 if (parseAbsoluteExpression(MaxBytesToFill))
2494 if (getLexer().isNot(AsmToken::EndOfStatement))
2495 return TokError(
"unexpected token in directive");
2507 if (Alignment >= 32) {
2508 Error(AlignmentLoc,
"invalid alignment value");
2512 Alignment = 1ULL << Alignment;
2516 Error(AlignmentLoc,
"alignment must be a power of 2");
2521 if (MaxBytesToFill < 1) {
2522 Error(MaxBytesLoc,
"alignment directive can never be satisfied in this "
2523 "many bytes, ignoring maximum bytes expression");
2527 if (MaxBytesToFill >= Alignment) {
2528 Warning(MaxBytesLoc,
"maximum bytes expression exceeds alignment and "
2536 bool UseCodeAlign = getStreamer().getCurrentSection().first->UseCodeAlign();
2537 if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) &&
2538 ValueSize == 1 && UseCodeAlign) {
2539 getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill);
2542 getStreamer().EmitValueToAlignment(Alignment, FillExpr, ValueSize,
2552 bool AsmParser::parseDirectiveFile(
SMLoc DirectiveLoc) {
2554 int64_t FileNumber = -1;
2555 SMLoc FileNumberLoc = getLexer().getLoc();
2556 if (getLexer().is(AsmToken::Integer)) {
2557 FileNumber = getTok().getIntVal();
2561 return TokError(
"file number less than one");
2565 return TokError(
"unexpected token in '.file' directive");
2569 std::string Path = getTok().getString();
2570 if (parseEscapedString(Path))
2576 std::string FilenameData;
2578 if (FileNumber == -1)
2579 return TokError(
"explicit path specified, but no file number");
2580 if (parseEscapedString(FilenameData))
2582 Filename = FilenameData;
2589 if (getLexer().isNot(AsmToken::EndOfStatement))
2590 return TokError(
"unexpected token in '.file' directive");
2592 if (FileNumber == -1)
2593 getStreamer().EmitFileDirective(Filename);
2595 if (getContext().getGenDwarfForAssembly() ==
true)
2597 "input can't have .file dwarf directives when -g is "
2598 "used to generate dwarf debug info for assembly code");
2600 if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename))
2601 Error(FileNumberLoc,
"file number already allocated");
2609 bool AsmParser::parseDirectiveLine() {
2610 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2611 if (getLexer().isNot(AsmToken::Integer))
2612 return TokError(
"unexpected token in '.line' directive");
2614 int64_t LineNumber = getTok().getIntVal();
2621 if (getLexer().isNot(AsmToken::EndOfStatement))
2622 return TokError(
"unexpected token in '.line' directive");
2634 bool AsmParser::parseDirectiveLoc() {
2635 if (getLexer().isNot(AsmToken::Integer))
2636 return TokError(
"unexpected token in '.loc' directive");
2637 int64_t FileNumber = getTok().getIntVal();
2639 return TokError(
"file number less than one in '.loc' directive");
2640 if (!getContext().isValidDwarfFileNumber(FileNumber))
2641 return TokError(
"unassigned file number in '.loc' directive");
2644 int64_t LineNumber = 0;
2645 if (getLexer().is(AsmToken::Integer)) {
2646 LineNumber = getTok().getIntVal();
2648 return TokError(
"line number less than zero in '.loc' directive");
2652 int64_t ColumnPos = 0;
2653 if (getLexer().is(AsmToken::Integer)) {
2654 ColumnPos = getTok().getIntVal();
2656 return TokError(
"column position less than zero in '.loc' directive");
2662 int64_t Discriminator = 0;
2663 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2665 if (getLexer().is(AsmToken::EndOfStatement))
2669 SMLoc Loc = getTok().getLoc();
2670 if (parseIdentifier(Name))
2671 return TokError(
"unexpected token in '.loc' directive");
2673 if (Name ==
"basic_block")
2675 else if (Name ==
"prologue_end")
2677 else if (Name ==
"epilogue_begin")
2679 else if (Name ==
"is_stmt") {
2680 Loc = getTok().getLoc();
2682 if (parseExpression(Value))
2685 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2686 int Value = MCE->getValue();
2688 Flags &= ~DWARF2_FLAG_IS_STMT;
2689 else if (Value == 1)
2692 return Error(Loc,
"is_stmt value not 0 or 1");
2694 return Error(Loc,
"is_stmt value not the constant value of 0 or 1");
2696 }
else if (Name ==
"isa") {
2697 Loc = getTok().getLoc();
2699 if (parseExpression(Value))
2702 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
2703 int Value = MCE->getValue();
2705 return Error(Loc,
"isa number less than zero");
2708 return Error(Loc,
"isa number not a constant value");
2710 }
else if (Name ==
"discriminator") {
2711 if (parseAbsoluteExpression(Discriminator))
2714 return Error(Loc,
"unknown sub-directive in '.loc' directive");
2717 if (getLexer().is(AsmToken::EndOfStatement))
2722 getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags,
2730 bool AsmParser::parseDirectiveStabs() {
2731 return TokError(
"unsupported directive '.stabs'");
2736 bool AsmParser::parseDirectiveCFISections() {
2741 if (parseIdentifier(Name))
2742 return TokError(
"Expected an identifier");
2744 if (Name ==
".eh_frame")
2746 else if (Name ==
".debug_frame")
2749 if (getLexer().is(AsmToken::Comma)) {
2752 if (parseIdentifier(Name))
2753 return TokError(
"Expected an identifier");
2755 if (Name ==
".eh_frame")
2757 else if (Name ==
".debug_frame")
2761 getStreamer().EmitCFISections(EH, Debug);
2767 bool AsmParser::parseDirectiveCFIStartProc() {
2768 getStreamer().EmitCFIStartProc();
2774 bool AsmParser::parseDirectiveCFIEndProc() {
2775 getStreamer().EmitCFIEndProc();
2780 bool AsmParser::parseRegisterOrRegisterNumber(int64_t &
Register,
2781 SMLoc DirectiveLoc) {
2784 if (getLexer().isNot(AsmToken::Integer)) {
2785 if (getTargetParser().ParseRegister(RegNo, DirectiveLoc, DirectiveLoc))
2787 Register = getContext().getRegisterInfo()->getDwarfRegNum(RegNo,
true);
2789 return parseAbsoluteExpression(Register);
2796 bool AsmParser::parseDirectiveCFIDefCfa(
SMLoc DirectiveLoc) {
2797 int64_t Register = 0;
2798 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
2801 if (getLexer().isNot(AsmToken::Comma))
2802 return TokError(
"unexpected token in directive");
2806 if (parseAbsoluteExpression(Offset))
2809 getStreamer().EmitCFIDefCfa(Register, Offset);
2815 bool AsmParser::parseDirectiveCFIDefCfaOffset() {
2817 if (parseAbsoluteExpression(Offset))
2820 getStreamer().EmitCFIDefCfaOffset(Offset);
2826 bool AsmParser::parseDirectiveCFIRegister(
SMLoc DirectiveLoc) {
2827 int64_t Register1 = 0;
2828 if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc))
2831 if (getLexer().isNot(AsmToken::Comma))
2832 return TokError(
"unexpected token in directive");
2835 int64_t Register2 = 0;
2836 if (parseRegisterOrRegisterNumber(Register2, DirectiveLoc))
2839 getStreamer().EmitCFIRegister(Register1, Register2);
2845 bool AsmParser::parseDirectiveCFIWindowSave() {
2846 getStreamer().EmitCFIWindowSave();
2852 bool AsmParser::parseDirectiveCFIAdjustCfaOffset() {
2853 int64_t Adjustment = 0;
2854 if (parseAbsoluteExpression(Adjustment))
2857 getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
2863 bool AsmParser::parseDirectiveCFIDefCfaRegister(
SMLoc DirectiveLoc) {
2864 int64_t Register = 0;
2865 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
2868 getStreamer().EmitCFIDefCfaRegister(Register);
2874 bool AsmParser::parseDirectiveCFIOffset(
SMLoc DirectiveLoc) {
2875 int64_t Register = 0;
2878 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
2881 if (getLexer().isNot(AsmToken::Comma))
2882 return TokError(
"unexpected token in directive");
2885 if (parseAbsoluteExpression(Offset))
2888 getStreamer().EmitCFIOffset(Register, Offset);
2894 bool AsmParser::parseDirectiveCFIRelOffset(
SMLoc DirectiveLoc) {
2895 int64_t Register = 0;
2897 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
2900 if (getLexer().isNot(AsmToken::Comma))
2901 return TokError(
"unexpected token in directive");
2905 if (parseAbsoluteExpression(Offset))
2908 getStreamer().EmitCFIRelOffset(Register, Offset);
2913 if (Encoding & ~0xff)
2919 const unsigned Format = Encoding & 0xf;
2926 const unsigned Application = Encoding & 0x70;
2938 bool AsmParser::parseDirectiveCFIPersonalityOrLsda(
bool IsPersonality) {
2939 int64_t Encoding = 0;
2940 if (parseAbsoluteExpression(Encoding))
2946 return TokError(
"unsupported encoding.");
2948 if (getLexer().isNot(AsmToken::Comma))
2949 return TokError(
"unexpected token in directive");
2953 if (parseIdentifier(Name))
2954 return TokError(
"expected identifier in directive");
2956 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
2959 getStreamer().EmitCFIPersonality(Sym, Encoding);
2961 getStreamer().EmitCFILsda(Sym, Encoding);
2967 bool AsmParser::parseDirectiveCFIRememberState() {
2968 getStreamer().EmitCFIRememberState();
2974 bool AsmParser::parseDirectiveCFIRestoreState() {
2975 getStreamer().EmitCFIRestoreState();
2981 bool AsmParser::parseDirectiveCFISameValue(
SMLoc DirectiveLoc) {
2982 int64_t Register = 0;
2984 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
2987 getStreamer().EmitCFISameValue(Register);
2993 bool AsmParser::parseDirectiveCFIRestore(
SMLoc DirectiveLoc) {
2994 int64_t Register = 0;
2995 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
2998 getStreamer().EmitCFIRestore(Register);
3004 bool AsmParser::parseDirectiveCFIEscape() {
3007 if (parseAbsoluteExpression(CurrValue))
3010 Values.push_back((uint8_t)CurrValue);
3012 while (getLexer().is(AsmToken::Comma)) {
3015 if (parseAbsoluteExpression(CurrValue))
3018 Values.push_back((uint8_t)CurrValue);
3021 getStreamer().EmitCFIEscape(Values);
3027 bool AsmParser::parseDirectiveCFISignalFrame() {
3028 if (getLexer().isNot(AsmToken::EndOfStatement))
3029 return Error(getLexer().getLoc(),
3030 "unexpected token in '.cfi_signal_frame'");
3032 getStreamer().EmitCFISignalFrame();
3038 bool AsmParser::parseDirectiveCFIUndefined(
SMLoc DirectiveLoc) {
3039 int64_t Register = 0;
3041 if (parseRegisterOrRegisterNumber(Register, DirectiveLoc))
3044 getStreamer().EmitCFIUndefined(Register);
3051 bool AsmParser::parseDirectiveMacrosOnOff(
StringRef Directive) {
3052 if (getLexer().isNot(AsmToken::EndOfStatement))
3053 return Error(getLexer().getLoc(),
3054 "unexpected token in '" + Directive +
"' directive");
3056 setMacrosEnabled(Directive ==
".macros_on");
3062 bool AsmParser::parseDirectiveMacro(
SMLoc DirectiveLoc) {
3064 if (parseIdentifier(Name))
3065 return TokError(
"expected identifier in '.macro' directive");
3067 MCAsmMacroParameters Parameters;
3071 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3073 MCAsmMacroParameter Parameter;
3074 if (parseIdentifier(Parameter.first))
3075 return TokError(
"expected identifier in '.macro' directive");
3077 if (getLexer().is(AsmToken::Equal)) {
3079 if (parseMacroArgument(Parameter.second, ArgumentDelimiter))
3083 Parameters.push_back(Parameter);
3085 if (getLexer().is(AsmToken::Comma))
3087 else if (getLexer().is(AsmToken::EndOfStatement))
3095 AsmToken EndToken, StartToken = getTok();
3101 return Error(DirectiveLoc,
"no matching '.endmacro' in definition");
3104 if (getLexer().is(AsmToken::Identifier) &&
3105 (getTok().getIdentifier() ==
".endm" ||
3106 getTok().getIdentifier() ==
".endmacro")) {
3107 EndToken = getTok();
3109 if (getLexer().isNot(AsmToken::EndOfStatement))
3110 return TokError(
"unexpected token in '" + EndToken.
getIdentifier() +
3116 eatToEndOfStatement();
3119 if (lookupMacro(Name)) {
3120 return Error(DirectiveLoc,
"macro '" + Name +
"' is already defined");
3126 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
3127 defineMacro(Name, MCAsmMacro(Name, Body, Parameters));
3145 void AsmParser::checkForBadMacro(
SMLoc DirectiveLoc,
StringRef Name,
3147 MCAsmMacroParameters Parameters) {
3150 unsigned NParameters = Parameters.size();
3151 if (NParameters == 0)
3154 bool NamedParametersFound =
false;
3155 bool PositionalParametersFound =
false;
3160 while (!Body.
empty()) {
3162 std::size_t End = Body.
size(), Pos = 0;
3163 for (; Pos != End; ++Pos) {
3166 if (Body[Pos] ==
'\\' && Pos + 1 != End)
3170 if (Body[Pos] !=
'$' || Pos + 1 == End)
3172 char Next = Body[Pos + 1];
3173 if (Next ==
'$' || Next ==
'n' ||
3174 isdigit(static_cast<unsigned char>(Next)))
3182 if (Body[Pos] ==
'$') {
3183 switch (Body[Pos + 1]) {
3190 PositionalParametersFound =
true;
3195 PositionalParametersFound =
true;
3201 unsigned I = Pos + 1;
3205 const char *Begin = Body.
data() + Pos + 1;
3208 for (; Index < NParameters; ++Index)
3209 if (Parameters[Index].first ==
Argument)
3212 if (Index == NParameters) {
3213 if (Body[Pos + 1] ==
'(' && Body[Pos + 2] ==
')')
3219 NamedParametersFound =
true;
3227 if (!NamedParametersFound && PositionalParametersFound)
3228 Warning(DirectiveLoc,
"macro defined with named parameters which are not "
3229 "used in macro body, possible positional parameter "
3230 "found in body which will have no effect");
3236 bool AsmParser::parseDirectiveEndMacro(
StringRef Directive) {
3237 if (getLexer().isNot(AsmToken::EndOfStatement))
3238 return TokError(
"unexpected token in '" + Directive +
"' directive");
3242 if (isInsideMacroInstantiation()) {
3249 return TokError(
"unexpected '" + Directive +
"' in file, "
3250 "no current macro definition");
3255 bool AsmParser::parseDirectivePurgeMacro(
SMLoc DirectiveLoc) {
3257 if (parseIdentifier(Name))
3258 return TokError(
"expected identifier in '.purgem' directive");
3260 if (getLexer().isNot(AsmToken::EndOfStatement))
3261 return TokError(
"unexpected token in '.purgem' directive");
3263 if (!lookupMacro(Name))
3264 return Error(DirectiveLoc,
"macro '" + Name +
"' is not defined");
3266 undefineMacro(Name);
3272 bool AsmParser::parseDirectiveBundleAlignMode() {
3273 checkForValidSection();
3277 SMLoc ExprLoc = getLexer().getLoc();
3278 int64_t AlignSizePow2;
3279 if (parseAbsoluteExpression(AlignSizePow2))
3281 else if (getLexer().isNot(AsmToken::EndOfStatement))
3282 return TokError(
"unexpected token after expression in"
3283 " '.bundle_align_mode' directive");
3284 else if (AlignSizePow2 < 0 || AlignSizePow2 > 30)
3285 return Error(ExprLoc,
3286 "invalid bundle alignment size (expected between 0 and 30)");
3292 getStreamer().EmitBundleAlignMode(static_cast<unsigned>(AlignSizePow2));
3298 bool AsmParser::parseDirectiveBundleLock() {
3299 checkForValidSection();
3300 bool AlignToEnd =
false;
3302 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3304 SMLoc Loc = getTok().getLoc();
3305 const char *kInvalidOptionError =
3306 "invalid option for '.bundle_lock' directive";
3308 if (parseIdentifier(Option))
3309 return Error(Loc, kInvalidOptionError);
3311 if (Option !=
"align_to_end")
3312 return Error(Loc, kInvalidOptionError);
3313 else if (getLexer().isNot(AsmToken::EndOfStatement))
3315 "unexpected token after '.bundle_lock' directive option");
3321 getStreamer().EmitBundleLock(AlignToEnd);
3327 bool AsmParser::parseDirectiveBundleUnlock() {
3328 checkForValidSection();
3330 if (getLexer().isNot(AsmToken::EndOfStatement))
3331 return TokError(
"unexpected token in '.bundle_unlock' directive");
3334 getStreamer().EmitBundleUnlock();
3340 bool AsmParser::parseDirectiveSpace(
StringRef IDVal) {
3341 checkForValidSection();
3344 if (parseAbsoluteExpression(NumBytes))
3347 int64_t FillExpr = 0;
3348 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3349 if (getLexer().isNot(AsmToken::Comma))
3350 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
3353 if (parseAbsoluteExpression(FillExpr))
3356 if (getLexer().isNot(AsmToken::EndOfStatement))
3357 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
3363 return TokError(
"invalid number of bytes in '" +
Twine(IDVal) +
3367 getStreamer().EmitFill(NumBytes, FillExpr);
3374 bool AsmParser::parseDirectiveLEB128(
bool Signed) {
3375 checkForValidSection();
3378 if (parseExpression(Value))
3381 if (getLexer().isNot(AsmToken::EndOfStatement))
3382 return TokError(
"unexpected token in directive");
3385 getStreamer().EmitSLEB128Value(Value);
3387 getStreamer().EmitULEB128Value(Value);
3394 bool AsmParser::parseDirectiveSymbolAttribute(
MCSymbolAttr Attr) {
3395 if (getLexer().isNot(AsmToken::EndOfStatement)) {
3398 SMLoc Loc = getTok().getLoc();
3400 if (parseIdentifier(Name))
3401 return Error(Loc,
"expected identifier in directive");
3403 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
3407 return Error(Loc,
"non-local symbol required in directive");
3409 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
3410 return Error(Loc,
"unable to emit symbol attribute");
3412 if (getLexer().is(AsmToken::EndOfStatement))
3415 if (getLexer().isNot(AsmToken::Comma))
3416 return TokError(
"unexpected token in directive");
3427 bool AsmParser::parseDirectiveComm(
bool IsLocal) {
3428 checkForValidSection();
3430 SMLoc IDLoc = getLexer().getLoc();
3432 if (parseIdentifier(Name))
3433 return TokError(
"expected identifier in directive");
3436 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
3438 if (getLexer().isNot(AsmToken::Comma))
3439 return TokError(
"unexpected token in directive");
3443 SMLoc SizeLoc = getLexer().getLoc();
3444 if (parseAbsoluteExpression(Size))
3447 int64_t Pow2Alignment = 0;
3448 SMLoc Pow2AlignmentLoc;
3449 if (getLexer().is(AsmToken::Comma)) {
3451 Pow2AlignmentLoc = getLexer().getLoc();
3452 if (parseAbsoluteExpression(Pow2Alignment))
3457 return Error(Pow2AlignmentLoc,
"alignment not supported on this target");
3460 if ((!IsLocal && Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) ||
3463 return Error(Pow2AlignmentLoc,
"alignment must be a power of 2");
3464 Pow2Alignment =
Log2_64(Pow2Alignment);
3468 if (getLexer().isNot(AsmToken::EndOfStatement))
3469 return TokError(
"unexpected token in '.comm' or '.lcomm' directive");
3476 return Error(SizeLoc,
"invalid '.comm' or '.lcomm' directive size, can't "
3477 "be less than zero");
3482 if (Pow2Alignment < 0)
3483 return Error(Pow2AlignmentLoc,
"invalid '.comm' or '.lcomm' directive "
3484 "alignment, can't be less than zero");
3487 return Error(IDLoc,
"invalid symbol redefinition");
3491 getStreamer().EmitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment);
3495 getStreamer().EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
3501 bool AsmParser::parseDirectiveAbort() {
3503 SMLoc Loc = getLexer().getLoc();
3505 StringRef Str = parseStringToEndOfStatement();
3506 if (getLexer().isNot(AsmToken::EndOfStatement))
3507 return TokError(
"unexpected token in '.abort' directive");
3512 Error(Loc,
".abort detected. Assembly stopping.");
3514 Error(Loc,
".abort '" + Str +
"' detected. Assembly stopping.");
3522 bool AsmParser::parseDirectiveInclude() {
3524 return TokError(
"expected string in '.include' directive");
3527 std::string Filename;
3528 if (parseEscapedString(Filename))
3530 SMLoc IncludeLoc = getLexer().getLoc();
3533 if (getLexer().isNot(AsmToken::EndOfStatement))
3534 return TokError(
"unexpected token in '.include' directive");
3538 if (enterIncludeFile(Filename)) {
3539 Error(IncludeLoc,
"Could not find include file '" + Filename +
"'");
3548 bool AsmParser::parseDirectiveIncbin() {
3550 return TokError(
"expected string in '.incbin' directive");
3553 std::string Filename;
3554 if (parseEscapedString(Filename))
3556 SMLoc IncbinLoc = getLexer().getLoc();
3559 if (getLexer().isNot(AsmToken::EndOfStatement))
3560 return TokError(
"unexpected token in '.incbin' directive");
3563 if (processIncbinFile(Filename)) {
3564 Error(IncbinLoc,
"Could not find incbin file '" + Filename +
"'");
3573 bool AsmParser::parseDirectiveIf(
SMLoc DirectiveLoc) {
3574 TheCondStack.push_back(TheCondState);
3575 TheCondState.TheCond = AsmCond::IfCond;
3576 if (TheCondState.Ignore) {
3577 eatToEndOfStatement();
3580 if (parseAbsoluteExpression(ExprValue))
3583 if (getLexer().isNot(AsmToken::EndOfStatement))
3584 return TokError(
"unexpected token in '.if' directive");
3588 TheCondState.CondMet = ExprValue;
3589 TheCondState.Ignore = !TheCondState.CondMet;
3597 bool AsmParser::parseDirectiveIfb(
SMLoc DirectiveLoc,
bool ExpectBlank) {
3598 TheCondStack.push_back(TheCondState);
3599 TheCondState.TheCond = AsmCond::IfCond;
3601 if (TheCondState.Ignore) {
3602 eatToEndOfStatement();
3604 StringRef Str = parseStringToEndOfStatement();
3606 if (getLexer().isNot(AsmToken::EndOfStatement))
3607 return TokError(
"unexpected token in '.ifb' directive");
3611 TheCondState.CondMet = ExpectBlank == Str.
empty();
3612 TheCondState.Ignore = !TheCondState.CondMet;
3620 bool AsmParser::parseDirectiveIfc(
SMLoc DirectiveLoc,
bool ExpectEqual) {
3621 TheCondStack.push_back(TheCondState);
3622 TheCondState.TheCond = AsmCond::IfCond;
3624 if (TheCondState.Ignore) {
3625 eatToEndOfStatement();
3629 if (getLexer().isNot(AsmToken::Comma))
3630 return TokError(
"unexpected token in '.ifc' directive");
3634 StringRef Str2 = parseStringToEndOfStatement();
3636 if (getLexer().isNot(AsmToken::EndOfStatement))
3637 return TokError(
"unexpected token in '.ifc' directive");
3641 TheCondState.CondMet = ExpectEqual == (Str1 == Str2);
3642 TheCondState.Ignore = !TheCondState.CondMet;
3650 bool AsmParser::parseDirectiveIfdef(
SMLoc DirectiveLoc,
bool expect_defined) {
3652 TheCondStack.push_back(TheCondState);
3653 TheCondState.TheCond = AsmCond::IfCond;
3655 if (TheCondState.Ignore) {
3656 eatToEndOfStatement();
3658 if (parseIdentifier(Name))
3659 return TokError(
"expected identifier after '.ifdef'");
3663 MCSymbol *Sym = getContext().LookupSymbol(Name);
3666 TheCondState.CondMet = (Sym != NULL && !Sym->
isUndefined());
3668 TheCondState.CondMet = (Sym == NULL || Sym->
isUndefined());
3669 TheCondState.Ignore = !TheCondState.CondMet;
3677 bool AsmParser::parseDirectiveElseIf(
SMLoc DirectiveLoc) {
3678 if (TheCondState.TheCond != AsmCond::IfCond &&
3679 TheCondState.TheCond != AsmCond::ElseIfCond)
3680 Error(DirectiveLoc,
"Encountered a .elseif that doesn't follow a .if or "
3682 TheCondState.TheCond = AsmCond::ElseIfCond;
3684 bool LastIgnoreState =
false;
3685 if (!TheCondStack.empty())
3686 LastIgnoreState = TheCondStack.back().Ignore;
3687 if (LastIgnoreState || TheCondState.CondMet) {
3688 TheCondState.Ignore =
true;
3689 eatToEndOfStatement();
3692 if (parseAbsoluteExpression(ExprValue))
3695 if (getLexer().isNot(AsmToken::EndOfStatement))
3696 return TokError(
"unexpected token in '.elseif' directive");
3699 TheCondState.CondMet = ExprValue;
3700 TheCondState.Ignore = !TheCondState.CondMet;
3708 bool AsmParser::parseDirectiveElse(
SMLoc DirectiveLoc) {
3709 if (getLexer().isNot(AsmToken::EndOfStatement))
3710 return TokError(
"unexpected token in '.else' directive");
3714 if (TheCondState.TheCond != AsmCond::IfCond &&
3715 TheCondState.TheCond != AsmCond::ElseIfCond)
3716 Error(DirectiveLoc,
"Encountered a .else that doesn't follow a .if or an "
3718 TheCondState.TheCond = AsmCond::ElseCond;
3719 bool LastIgnoreState =
false;
3720 if (!TheCondStack.empty())
3721 LastIgnoreState = TheCondStack.back().Ignore;
3722 if (LastIgnoreState || TheCondState.CondMet)
3723 TheCondState.Ignore =
true;
3725 TheCondState.Ignore =
false;
3732 bool AsmParser::parseDirectiveEndIf(
SMLoc DirectiveLoc) {
3733 if (getLexer().isNot(AsmToken::EndOfStatement))
3734 return TokError(
"unexpected token in '.endif' directive");
3738 if ((TheCondState.TheCond == AsmCond::NoCond) || TheCondStack.empty())
3739 Error(DirectiveLoc,
"Encountered a .endif that doesn't follow a .if or "
3741 if (!TheCondStack.empty()) {
3742 TheCondState = TheCondStack.back();
3743 TheCondStack.pop_back();
3749 void AsmParser::initializeDirectiveKindMap() {
3750 DirectiveKindMap[
".set"] = DK_SET;
3751 DirectiveKindMap[
".equ"] = DK_EQU;
3752 DirectiveKindMap[
".equiv"] = DK_EQUIV;
3753 DirectiveKindMap[
".ascii"] = DK_ASCII;
3754 DirectiveKindMap[
".asciz"] = DK_ASCIZ;
3755 DirectiveKindMap[
".string"] = DK_STRING;
3756 DirectiveKindMap[
".byte"] = DK_BYTE;
3757 DirectiveKindMap[
".short"] = DK_SHORT;
3758 DirectiveKindMap[
".value"] = DK_VALUE;
3759 DirectiveKindMap[
".2byte"] = DK_2BYTE;
3760 DirectiveKindMap[
".long"] = DK_LONG;
3761 DirectiveKindMap[
".int"] = DK_INT;
3762 DirectiveKindMap[
".4byte"] = DK_4BYTE;
3763 DirectiveKindMap[
".quad"] = DK_QUAD;
3764 DirectiveKindMap[
".8byte"] = DK_8BYTE;
3765 DirectiveKindMap[
".single"] = DK_SINGLE;
3766 DirectiveKindMap[
".float"] = DK_FLOAT;
3767 DirectiveKindMap[
".double"] = DK_DOUBLE;
3768 DirectiveKindMap[
".align"] = DK_ALIGN;
3769 DirectiveKindMap[
".align32"] = DK_ALIGN32;
3770 DirectiveKindMap[
".balign"] = DK_BALIGN;
3771 DirectiveKindMap[
".balignw"] = DK_BALIGNW;
3772 DirectiveKindMap[
".balignl"] = DK_BALIGNL;
3773 DirectiveKindMap[
".p2align"] = DK_P2ALIGN;
3774 DirectiveKindMap[
".p2alignw"] = DK_P2ALIGNW;
3775 DirectiveKindMap[
".p2alignl"] = DK_P2ALIGNL;
3776 DirectiveKindMap[
".org"] = DK_ORG;
3777 DirectiveKindMap[
".fill"] = DK_FILL;
3778 DirectiveKindMap[
".zero"] = DK_ZERO;
3779 DirectiveKindMap[
".extern"] = DK_EXTERN;
3780 DirectiveKindMap[
".globl"] = DK_GLOBL;
3781 DirectiveKindMap[
".global"] = DK_GLOBAL;
3782 DirectiveKindMap[
".lazy_reference"] = DK_LAZY_REFERENCE;
3783 DirectiveKindMap[
".no_dead_strip"] = DK_NO_DEAD_STRIP;
3784 DirectiveKindMap[
".symbol_resolver"] = DK_SYMBOL_RESOLVER;
3785 DirectiveKindMap[
".private_extern"] = DK_PRIVATE_EXTERN;
3786 DirectiveKindMap[
".reference"] = DK_REFERENCE;
3787 DirectiveKindMap[
".weak_definition"] = DK_WEAK_DEFINITION;
3788 DirectiveKindMap[
".weak_reference"] = DK_WEAK_REFERENCE;
3789 DirectiveKindMap[
".weak_def_can_be_hidden"] = DK_WEAK_DEF_CAN_BE_HIDDEN;
3790 DirectiveKindMap[
".comm"] = DK_COMM;
3791 DirectiveKindMap[
".common"] = DK_COMMON;
3792 DirectiveKindMap[
".lcomm"] = DK_LCOMM;
3793 DirectiveKindMap[
".abort"] = DK_ABORT;
3794 DirectiveKindMap[
".include"] = DK_INCLUDE;
3795 DirectiveKindMap[
".incbin"] = DK_INCBIN;
3796 DirectiveKindMap[
".code16"] = DK_CODE16;
3797 DirectiveKindMap[
".code16gcc"] = DK_CODE16GCC;
3798 DirectiveKindMap[
".rept"] = DK_REPT;
3799 DirectiveKindMap[
".irp"] = DK_IRP;
3800 DirectiveKindMap[
".irpc"] = DK_IRPC;
3801 DirectiveKindMap[
".endr"] = DK_ENDR;
3802 DirectiveKindMap[
".bundle_align_mode"] = DK_BUNDLE_ALIGN_MODE;
3803 DirectiveKindMap[
".bundle_lock"] = DK_BUNDLE_LOCK;
3804 DirectiveKindMap[
".bundle_unlock"] = DK_BUNDLE_UNLOCK;
3805 DirectiveKindMap[
".if"] = DK_IF;
3806 DirectiveKindMap[
".ifb"] = DK_IFB;
3807 DirectiveKindMap[
".ifnb"] = DK_IFNB;
3808 DirectiveKindMap[
".ifc"] = DK_IFC;
3809 DirectiveKindMap[
".ifnc"] = DK_IFNC;
3810 DirectiveKindMap[
".ifdef"] = DK_IFDEF;
3811 DirectiveKindMap[
".ifndef"] = DK_IFNDEF;
3812 DirectiveKindMap[
".ifnotdef"] = DK_IFNOTDEF;
3813 DirectiveKindMap[
".elseif"] = DK_ELSEIF;
3814 DirectiveKindMap[
".else"] = DK_ELSE;
3815 DirectiveKindMap[
".endif"] = DK_ENDIF;
3816 DirectiveKindMap[
".skip"] = DK_SKIP;
3817 DirectiveKindMap[
".space"] = DK_SPACE;
3818 DirectiveKindMap[
".file"] = DK_FILE;
3819 DirectiveKindMap[
".line"] = DK_LINE;
3820 DirectiveKindMap[
".loc"] = DK_LOC;
3821 DirectiveKindMap[
".stabs"] = DK_STABS;
3822 DirectiveKindMap[
".sleb128"] = DK_SLEB128;
3823 DirectiveKindMap[
".uleb128"] = DK_ULEB128;
3824 DirectiveKindMap[
".cfi_sections"] = DK_CFI_SECTIONS;
3825 DirectiveKindMap[
".cfi_startproc"] = DK_CFI_STARTPROC;
3826 DirectiveKindMap[
".cfi_endproc"] = DK_CFI_ENDPROC;
3827 DirectiveKindMap[
".cfi_def_cfa"] = DK_CFI_DEF_CFA;
3828 DirectiveKindMap[
".cfi_def_cfa_offset"] = DK_CFI_DEF_CFA_OFFSET;
3829 DirectiveKindMap[
".cfi_adjust_cfa_offset"] = DK_CFI_ADJUST_CFA_OFFSET;
3830 DirectiveKindMap[
".cfi_def_cfa_register"] = DK_CFI_DEF_CFA_REGISTER;
3831 DirectiveKindMap[
".cfi_offset"] = DK_CFI_OFFSET;
3832 DirectiveKindMap[
".cfi_rel_offset"] = DK_CFI_REL_OFFSET;
3833 DirectiveKindMap[
".cfi_personality"] = DK_CFI_PERSONALITY;
3834 DirectiveKindMap[
".cfi_lsda"] = DK_CFI_LSDA;
3835 DirectiveKindMap[
".cfi_remember_state"] = DK_CFI_REMEMBER_STATE;
3836 DirectiveKindMap[
".cfi_restore_state"] = DK_CFI_RESTORE_STATE;
3837 DirectiveKindMap[
".cfi_same_value"] = DK_CFI_SAME_VALUE;
3838 DirectiveKindMap[
".cfi_restore"] = DK_CFI_RESTORE;
3839 DirectiveKindMap[
".cfi_escape"] = DK_CFI_ESCAPE;
3840 DirectiveKindMap[
".cfi_signal_frame"] = DK_CFI_SIGNAL_FRAME;
3841 DirectiveKindMap[
".cfi_undefined"] = DK_CFI_UNDEFINED;
3842 DirectiveKindMap[
".cfi_register"] = DK_CFI_REGISTER;
3843 DirectiveKindMap[
".cfi_window_save"] = DK_CFI_WINDOW_SAVE;
3844 DirectiveKindMap[
".macros_on"] = DK_MACROS_ON;
3845 DirectiveKindMap[
".macros_off"] = DK_MACROS_OFF;
3846 DirectiveKindMap[
".macro"] = DK_MACRO;
3847 DirectiveKindMap[
".endm"] = DK_ENDM;
3848 DirectiveKindMap[
".endmacro"] = DK_ENDMACRO;
3849 DirectiveKindMap[
".purgem"] = DK_PURGEM;
3852 MCAsmMacro *AsmParser::parseMacroLikeBody(
SMLoc DirectiveLoc) {
3853 AsmToken EndToken, StartToken = getTok();
3855 unsigned NestLevel = 0;
3859 Error(DirectiveLoc,
"no matching '.endr' in definition");
3863 if (Lexer.is(AsmToken::Identifier) &&
3864 (getTok().getIdentifier() ==
".rept")) {
3869 if (Lexer.is(AsmToken::Identifier) && getTok().getIdentifier() ==
".endr") {
3870 if (NestLevel == 0) {
3871 EndToken = getTok();
3873 if (Lexer.isNot(AsmToken::EndOfStatement)) {
3874 TokError(
"unexpected token in '.endr' directive");
3883 eatToEndOfStatement();
3892 MCAsmMacroParameters Parameters;
3893 MacroLikeBodies.push_back(MCAsmMacro(Name, Body, Parameters));
3894 return &MacroLikeBodies.back();
3897 void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M,
SMLoc DirectiveLoc,
3902 MemoryBuffer::getMemBufferCopy(OS.
str(),
"<instantiation>");
3906 MacroInstantiation *MI =
new MacroInstantiation(
3907 M, DirectiveLoc, CurBuffer, getTok().getLoc(), Instantiation);
3908 ActiveMacros.push_back(MI);
3916 bool AsmParser::parseDirectiveRept(
SMLoc DirectiveLoc) {
3918 if (parseAbsoluteExpression(Count))
3919 return TokError(
"unexpected token in '.rept' directive");
3922 return TokError(
"Count is negative");
3924 if (Lexer.isNot(AsmToken::EndOfStatement))
3925 return TokError(
"unexpected token in '.rept' directive");
3931 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
3938 MCAsmMacroParameters Parameters;
3939 MCAsmMacroArguments
A;
3942 if (expandMacro(OS, M->Body, Parameters, A, getTok().getLoc()))
3945 instantiateMacroLikeBody(M, DirectiveLoc, OS);
3952 bool AsmParser::parseDirectiveIrp(
SMLoc DirectiveLoc) {
3953 MCAsmMacroParameters Parameters;
3954 MCAsmMacroParameter Parameter;
3956 if (parseIdentifier(Parameter.first))
3957 return TokError(
"expected identifier in '.irp' directive");
3959 Parameters.push_back(Parameter);
3961 if (Lexer.isNot(AsmToken::Comma))
3962 return TokError(
"expected comma in '.irp' directive");
3966 MCAsmMacroArguments
A;
3967 if (parseMacroArguments(0, A))
3974 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
3983 for (MCAsmMacroArguments::iterator i = A.begin(), e = A.end(); i != e; ++i) {
3984 MCAsmMacroArguments Args;
3987 if (expandMacro(OS, M->Body, Parameters, Args, getTok().getLoc()))
3991 instantiateMacroLikeBody(M, DirectiveLoc, OS);
3998 bool AsmParser::parseDirectiveIrpc(
SMLoc DirectiveLoc) {
3999 MCAsmMacroParameters Parameters;
4000 MCAsmMacroParameter Parameter;
4002 if (parseIdentifier(Parameter.first))
4003 return TokError(
"expected identifier in '.irpc' directive");
4005 Parameters.push_back(Parameter);
4007 if (Lexer.isNot(AsmToken::Comma))
4008 return TokError(
"expected comma in '.irpc' directive");
4012 MCAsmMacroArguments
A;
4013 if (parseMacroArguments(0, A))
4016 if (A.size() != 1 || A.front().size() != 1)
4017 return TokError(
"unexpected token in '.irpc' directive");
4023 MCAsmMacro *M = parseMacroLikeBody(DirectiveLoc);
4033 std::size_t
I, End = Values.
size();
4034 for (I = 0; I < End; ++
I) {
4035 MCAsmMacroArgument Arg;
4036 Arg.push_back(
AsmToken(AsmToken::Identifier, Values.
slice(I, I + 1)));
4038 MCAsmMacroArguments Args;
4039 Args.push_back(Arg);
4041 if (expandMacro(OS, M->Body, Parameters, Args, getTok().getLoc()))
4045 instantiateMacroLikeBody(M, DirectiveLoc, OS);
4050 bool AsmParser::parseDirectiveEndr(
SMLoc DirectiveLoc) {
4051 if (ActiveMacros.empty())
4052 return TokError(
"unmatched '.endr' directive");
4056 assert(getLexer().is(AsmToken::EndOfStatement));
4062 bool AsmParser::parseDirectiveMSEmit(
SMLoc IDLoc, ParseStatementInfo &Info,
4065 SMLoc ExprLoc = getLexer().getLoc();
4066 if (parseExpression(Value))
4070 return Error(ExprLoc,
"unexpected expression in _emit");
4071 uint64_t IntValue = MCE->
getValue();
4073 return Error(ExprLoc,
"literal value out of range for directive");
4079 bool AsmParser::parseDirectiveMSAlign(
SMLoc IDLoc, ParseStatementInfo &Info) {
4081 SMLoc ExprLoc = getLexer().getLoc();
4082 if (parseExpression(Value))
4086 return Error(ExprLoc,
"unexpected expression in align");
4087 uint64_t IntValue = MCE->
getValue();
4089 return Error(ExprLoc,
"literal value not a power of two greater then zero");
4091 Info.AsmRewrites->push_back(
4119 bool AsmParser::parseMSInlineAsm(
4120 void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs,
4121 unsigned &NumInputs,
SmallVectorImpl<std::pair<void *, bool> > &OpDecls,
4139 unsigned InputIdx = 0;
4140 unsigned OutputIdx = 0;
4142 ParseStatementInfo Info(&AsmStrRewrites);
4143 if (parseStatement(Info))
4146 if (Info.ParseError)
4149 if (Info.Opcode == ~0U)
4155 for (
unsigned i = 1, e = Info.ParsedOperands.size(); i != e; ++i) {
4159 if (Operand->
isImm())
4173 if (SymName.
empty())
4180 bool isOutput = (i == 1) && Desc.
mayStore();
4181 SMLoc Start = SMLoc::getFromPointer(SymName.
data());
4198 NumOutputs = OutputDecls.
size();
4199 NumInputs = InputDecls.
size();
4203 ClobberRegs.
erase(std::unique(ClobberRegs.
begin(), ClobberRegs.
end()),
4205 Clobbers.
assign(ClobberRegs.
size(), std::string());
4206 for (
unsigned I = 0, E = ClobberRegs.
size(); I != E; ++
I) {
4212 if (NumOutputs || NumInputs) {
4213 unsigned NumExprs = NumOutputs + NumInputs;
4214 OpDecls.resize(NumExprs);
4215 Constraints.
resize(NumExprs);
4216 for (
unsigned i = 0; i < NumOutputs; ++i) {
4217 OpDecls[i] = std::make_pair(OutputDecls[i], OutputDeclsAddressOf[i]);
4218 Constraints[i] = OutputConstraints[i];
4220 for (
unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) {
4221 OpDecls[j] = std::make_pair(InputDecls[i], InputDeclsAddressOf[i]);
4222 Constraints[j] = InputConstraints[i];
4227 std::string AsmStringIR;
4233 E = AsmStrRewrites.
end();
4240 assert(Loc >= AsmStart &&
"Expected Loc to be at or after Start!");
4243 unsigned Len = Loc - AsmStart;
4249 AsmStart = Loc + (*I).Len;
4253 unsigned AdditionalSkip = 0;
4259 OS <<
"$$" << (*I).Val;
4265 OS <<
'$' << InputIdx++;
4268 OS <<
'$' << OutputIdx++;
4273 case 8: OS <<
"byte ptr ";
break;
4274 case 16: OS <<
"word ptr ";
break;
4275 case 32: OS <<
"dword ptr ";
break;
4276 case 64: OS <<
"qword ptr ";
break;
4277 case 80: OS <<
"xword ptr ";
break;
4278 case 128: OS <<
"xmmword ptr ";
break;
4279 case 256: OS <<
"ymmword ptr ";
break;
4286 unsigned Val = (*I).Val;
4287 OS <<
".align " << Val;
4290 assert(Val < 10 &&
"Expected alignment less then 2^10.");
4291 AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;
4300 AsmStart = Loc + (*I).Len + AdditionalSkip;
4304 if (AsmStart != AsmEnd)
4305 OS <<
StringRef(AsmStart, AsmEnd - AsmStart);
4307 AsmString = OS.
str();
4314 return new AsmParser(SM, C, Out, MAI);
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
const ValueTy & getValue() const
virtual ~MCAsmParserSemaCallback()
LLVM Argument representation.
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
const MCSymbol & getSymbol() const
#define DWARF2_FLAG_PROLOGUE_END
const char * getPointer() const
size_t size() const
size - Get the string size.
const char * getBufferStart() const
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions. Register definitions always occur...
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool mayStore() const
Return true if this instruction could possibly modify memory. Instructions with this flag set are not...
void * getDiagContext() const
std::pair< StringRef, StringRef > split(char Separator) const
MCAsmParserExtension * createDarwinAsmParser()
StringRef substr(size_t Start, size_t N=npos) const
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
StringRef getBuffer() const
std::string str() const
str - Get the contents as an std::string.
const_iterator begin(StringRef path)
Get begin iterator over path.
MCAsmParserExtension * createELFAsmParser()
static bool isIdentifierChar(char c)
AsmLexer - Lexer class for assembly files.
#define DWARF2_FLAG_IS_STMT
#define llvm_unreachable(msg)
const MCExpr * getVariableValue() const
getVariableValue() - Get the value for variable symbols.
StringRef getLineContents() const
void assign(unsigned NumElts, const T &Elt)
AsmToken - Target independent representation for an assembler token.
ID
LLVM Calling Convention Representation.
virtual StringRef getSymName()
size_t AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
bool isIntN(unsigned N, const APInt &APIVal)
Check if the specified APInt has a N-bits unsigned integer value.
const char * data() const
MCUnaryExpr - Unary assembler expressions.
static bool isOperator(AsmToken::TokenKind kind)
StringRef getMessage() const
static int rewritesSort(const AsmRewrite *AsmRewriteA, const AsmRewrite *AsmRewriteB)
virtual void * getOpDecl()
static cl::opt< bool > FatalAssemblerWarnings("fatal-assembler-warnings", cl::desc("Consider warnings as error"))
StringRef getConstraint()
virtual void printRegName(raw_ostream &OS, unsigned RegNo) const
printRegName - Print the assembler register name.
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
const MCExpr * getLHS() const
getLHS - Get the left-hand side expression of the binary operator.
bool isUsed() const
isUsed - Check if this is used.
friend const_iterator end(StringRef path)
Get end iterator over path.
void array_pod_sort(IteratorTy Start, IteratorTy End)
static unsigned getBinOpPrecedence(AsmToken::TokenKind K, MCBinaryExpr::Opcode &Kind)
.weak_def_can_be_hidden (MachO)
#define DWARF2_FLAG_EPILOGUE_BEGIN
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.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &)
Create an MCAsmParser instance.
unsigned getBitWidth() const
Return the number of bits in the APInt.
MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
#define DWARF2_FLAG_BASIC_BLOCK
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
virtual unsigned getReg() const =0
iterator erase(iterator I)
MCAsmParserExtension * createCOFFAsmParser()
MCBinaryExpr - Binary assembler expressions.
static bool isValidEncoding(int64_t Encoding)
const MCInstrDesc & get(unsigned Opcode) const
static void Split(std::vector< std::string > &V, const StringRef S)
bool hasMicrosoftFastStdCallMangling() const
SourceMgr::DiagKind getKind() const
Promote Memory to Register
SMLoc getParentIncludeLoc(unsigned i) const
void setUsed(bool Value) const
bool is(TokenKind K) const
#define LLVM_DELETED_FUNCTION
Class for arbitrary precision integers.
unsigned FindLineNumber(SMLoc Loc, int BufferID=-1) const
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
bool isPowerOf2_64(uint64_t Value)
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true) const
#define DWARF2_LINE_DEFAULT_IS_STMT
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
const MCExpr * getRHS() const
getRHS - Get the right-hand side expression of the binary operator.
StringRef getIdentifier() const
const MCExpr * getSubExpr() const
getSubExpr - Get the child of this unary expression.
StringRef getName() const
getName - Get the symbol name.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
virtual bool isImm() const =0
isImm - Is this an immediate operand?
Opcode getOpcode() const
getOpcode - Get the kind of this binary expression.
int FindBufferContainingLoc(SMLoc Loc) const
const char * getBufferEnd() const
bool isVariable() const
isVariable - Check if this is a variable symbol.
VariantKind getKind() const
char front() const
front - Get the first character in the string.
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
const char AsmRewritePrecedence[]
LLVM Value Representation.
bool hasSubsectionsViaSymbols() const
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
static bool isUsedIn(const MCSymbol *Sym, const MCExpr *Value)
void setDiagHandler(DiagHandlerTy DH, void *Ctx=0)
unsigned getMCOperandNum()
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
const SourceMgr * getSourceMgr() const
StringRef slice(size_t Start, size_t End) const
virtual bool needAddressOf() const
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Represents a location in source code.
bool isUIntN(unsigned N, uint64_t x)
size_t AddNewSourceBuffer(MemoryBuffer *F, SMLoc IncludeLoc)
DiagHandlerTy getDiagHandler() const
ConditionalAssemblyType TheCond
unsigned Log2_64(uint64_t Value)
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
getOpcode - Get the kind of this unary expression.