diff options
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/MCDisassembler/Disassembler.cpp | 29 | ||||
-rw-r--r-- | llvm/lib/MC/MCParser/AsmLexer.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/MC/MCParser/AsmParser.cpp | 65 |
3 files changed, 72 insertions, 37 deletions
diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/llvm/lib/MC/MCDisassembler/Disassembler.cpp index 21e8748b797..094ad7cc5eb 100644 --- a/llvm/lib/MC/MCDisassembler/Disassembler.cpp +++ b/llvm/lib/MC/MCDisassembler/Disassembler.cpp @@ -9,6 +9,9 @@ #include "Disassembler.h" #include "llvm-c/Disassembler.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Triple.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDisassembler/MCDisassembler.h" @@ -16,12 +19,19 @@ #include "llvm/MC/MCDisassembler/MCSymbolizer.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrDesc.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCInstrItineraries.h" #include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCSchedule.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetRegistry.h" +#include <cassert> +#include <cstddef> +#include <cstring> using namespace llvm; @@ -116,7 +126,7 @@ LLVMDisasmContextRef LLVMCreateDisasm(const char *TT, void *DisInfo, // LLVMDisasmDispose() disposes of the disassembler specified by the context. // void LLVMDisasmDispose(LLVMDisasmContextRef DCR){ - LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; + LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR); delete DC; } @@ -211,7 +221,6 @@ static int getLatency(LLVMDisasmContext *DC, const MCInst &Inst) { return Latency; } - /// \brief Emits latency information in DC->CommentStream for \p Inst, based /// on the information available in \p DC. static void emitLatency(LLVMDisasmContext *DC, const MCInst &Inst) { @@ -239,7 +248,7 @@ static void emitLatency(LLVMDisasmContext *DC, const MCInst &Inst) { size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, uint64_t BytesSize, uint64_t PC, char *OutString, size_t OutStringSize){ - LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; + LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR); // Wrap the pointer to the Bytes, BytesSize and PC in a MemoryObject. ArrayRef<uint8_t> Data(Bytes, BytesSize); @@ -288,21 +297,21 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, // int LLVMSetDisasmOptions(LLVMDisasmContextRef DCR, uint64_t Options){ if (Options & LLVMDisassembler_Option_UseMarkup){ - LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; + LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR); MCInstPrinter *IP = DC->getIP(); - IP->setUseMarkup(1); + IP->setUseMarkup(true); DC->addOptions(LLVMDisassembler_Option_UseMarkup); Options &= ~LLVMDisassembler_Option_UseMarkup; } if (Options & LLVMDisassembler_Option_PrintImmHex){ - LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; + LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR); MCInstPrinter *IP = DC->getIP(); - IP->setPrintImmHex(1); + IP->setPrintImmHex(true); DC->addOptions(LLVMDisassembler_Option_PrintImmHex); Options &= ~LLVMDisassembler_Option_PrintImmHex; } if (Options & LLVMDisassembler_Option_AsmPrinterVariant){ - LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; + LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR); // Try to set up the new instruction printer. const MCAsmInfo *MAI = DC->getAsmInfo(); const MCInstrInfo *MII = DC->getInstrInfo(); @@ -318,14 +327,14 @@ int LLVMSetDisasmOptions(LLVMDisasmContextRef DCR, uint64_t Options){ } } if (Options & LLVMDisassembler_Option_SetInstrComments) { - LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; + LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR); MCInstPrinter *IP = DC->getIP(); IP->setCommentStream(DC->CommentStream); DC->addOptions(LLVMDisassembler_Option_SetInstrComments); Options &= ~LLVMDisassembler_Option_SetInstrComments; } if (Options & LLVMDisassembler_Option_PrintLatency) { - LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; + LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR); DC->addOptions(LLVMDisassembler_Option_PrintLatency); Options &= ~LLVMDisassembler_Option_PrintLatency; } diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp index 832c39a2c75..71e35448919 100644 --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -11,16 +11,21 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCParser/AsmLexer.h" +#include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SMLoc.h" +#include <cassert> #include <cctype> -#include <cerrno> #include <cstdio> -#include <cstdlib> +#include <cstring> #include <tuple> +#include <string> +#include <utility> using namespace llvm; @@ -136,6 +141,7 @@ static bool IsIdentifierChar(char c, bool AllowAt) { return isalnum(c) || c == '_' || c == '$' || c == '.' || (c == '@' && AllowAt) || c == '?'; } + AsmToken AsmLexer::LexIdentifier() { // Check for floating point literals. if (CurPtr[-1] == '.' && isdigit(*CurPtr)) { @@ -225,7 +231,7 @@ static void SkipIgnoredIntegerSuffix(const char *&CurPtr) { static unsigned doLookAhead(const char *&CurPtr, unsigned DefaultRadix) { const char *FirstHex = nullptr; const char *LookAhead = CurPtr; - while (1) { + while (true) { if (isdigit(*LookAhead)) { ++LookAhead; } else if (isxdigit(*LookAhead)) { @@ -400,7 +406,6 @@ AsmToken AsmLexer::LexSingleQuote() { return AsmToken(AsmToken::Integer, Res, Value); } - /// LexQuote: String: "..." AsmToken AsmLexer::LexQuote() { int CurChar = getNextChar(); diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 7a6d5dbd2d3..46696609961 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -12,39 +12,58 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/APFloat.h" -#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrDesc.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCParser/AsmCond.h" #include "llvm/MC/MCParser/AsmLexer.h" +#include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCParser/MCAsmParserUtils.h" #include "llvm/MC/MCParser/MCParsedAsmOperand.h" #include "llvm/MC/MCParser/MCTargetAsmParser.h" #include "llvm/MC/MCRegisterInfo.h" -#include "llvm/MC/MCSectionMachO.h" +#include "llvm/MC/MCSection.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Dwarf.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SMLoc.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" +#include <algorithm> +#include <cassert> #include <cctype> +#include <cstddef> +#include <cstdint> #include <deque> +#include <memory> #include <sstream> #include <string> +#include <tuple> +#include <utility> #include <vector> + using namespace llvm; MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {} @@ -54,6 +73,7 @@ static cl::opt<unsigned> AsmMacroMaxNestingDepth( cl::desc("The maximum nesting depth allowed for assembly macros.")); namespace { + /// \brief Helper types for tracking macro definitions. typedef std::vector<AsmToken> MCAsmMacroArgument; typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments; @@ -119,6 +139,7 @@ struct ParseStatementInfo { class AsmParser : public MCAsmParser { AsmParser(const AsmParser &) = delete; void operator=(const AsmParser &) = delete; + private: AsmLexer Lexer; MCContext &Ctx; @@ -212,6 +233,7 @@ public: MCAsmLexer &getLexer() override { return Lexer; } MCContext &getContext() override { return Ctx; } MCStreamer &getStreamer() override { return Out; } + unsigned getAssemblerDialect() override { if (AssemblerDialect == ~0U) return MAI.getAssemblerDialect(); @@ -296,7 +318,6 @@ public: /// } private: - bool parseStatement(ParseStatementInfo &Info, MCAsmParserSemaCallback *SI); bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites); @@ -562,7 +583,8 @@ private: void initializeDirectiveKindMap(); }; -} + +} // end anonymous namespace namespace llvm { @@ -570,7 +592,7 @@ extern MCAsmParserExtension *createDarwinAsmParser(); extern MCAsmParserExtension *createELFAsmParser(); extern MCAsmParserExtension *createCOFFAsmParser(); -} +} // end namespace llvm enum { DEFAULT_ADDRSPACE = 0 }; @@ -708,7 +730,6 @@ const AsmToken &AsmParser::Lex() { } } - return *tok; } @@ -1415,7 +1436,7 @@ unsigned AsmParser::getBinOpPrecedence(AsmToken::TokenKind K, /// Res contains the LHS of the expression on input. bool AsmParser::parseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc) { - while (1) { + while (true) { MCBinaryExpr::Opcode Kind = MCBinaryExpr::Add; unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind); @@ -1631,8 +1652,6 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, getTargetParser().onLabelParsed(Sym); - - return false; } @@ -2239,6 +2258,7 @@ static bool isOperator(AsmToken::TokenKind kind) { } namespace { + class AsmLexerSkipSpaceRAII { public: AsmLexerSkipSpaceRAII(AsmLexer &Lexer, bool SkipSpace) : Lexer(Lexer) { @@ -2252,7 +2272,8 @@ public: private: AsmLexer &Lexer; }; -} + +} // end anonymous namespace bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA, bool Vararg) { @@ -2271,7 +2292,7 @@ bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA, bool Vararg) { bool SpaceEaten; - for (;;) { + while (true) { SpaceEaten = false; if (Lexer.is(AsmToken::Eof) || Lexer.is(AsmToken::Equal)) return TokError("unexpected token in macro instantiation"); @@ -2639,7 +2660,7 @@ bool AsmParser::parseDirectiveAscii(StringRef IDVal, bool ZeroTerminated) { if (getLexer().isNot(AsmToken::EndOfStatement)) { checkForValidSection(); - for (;;) { + while (true) { std::string Data; if (check(getTok().isNot(AsmToken::String), "expected string in '" + Twine(IDVal) + "' directive") || @@ -2713,7 +2734,7 @@ bool AsmParser::parseDirectiveValue(unsigned Size) { if (getLexer().isNot(AsmToken::EndOfStatement)) { checkForValidSection(); - for (;;) { + while (true) { const MCExpr *Value; SMLoc ExprLoc = getLexer().getLoc(); if (parseExpression(Value)) @@ -2748,7 +2769,7 @@ bool AsmParser::parseDirectiveOctaValue() { if (getLexer().isNot(AsmToken::EndOfStatement)) { checkForValidSection(); - for (;;) { + while (true) { if (getTok().is(AsmToken::Error)) return true; if (getTok().isNot(AsmToken::Integer) && getTok().isNot(AsmToken::BigNum)) @@ -2796,7 +2817,7 @@ bool AsmParser::parseDirectiveRealValue(const fltSemantics &Semantics) { if (getLexer().isNot(AsmToken::EndOfStatement)) { checkForValidSection(); - for (;;) { + while (true) { // We don't truly support arithmetic on floating point expressions, so we // have to manually parse unary prefixes. bool IsNeg = false; @@ -3147,7 +3168,7 @@ bool AsmParser::parseDirectiveLoc() { unsigned Isa = 0; int64_t Discriminator = 0; if (getLexer().isNot(AsmToken::EndOfStatement)) { - for (;;) { + while (true) { if (getLexer().is(AsmToken::EndOfStatement)) break; @@ -3819,7 +3840,7 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) { AsmToken EndToken, StartToken = getTok(); unsigned MacroDepth = 0; // Lex the macro definition. - for (;;) { + while (true) { // Ignore Lexing errors in macros. while (Lexer.is(AsmToken::Error)) { Lexer.Lex(); @@ -4125,7 +4146,7 @@ bool AsmParser::parseDirectiveLEB128(bool Signed) { checkForValidSection(); const MCExpr *Value; - for (;;) { + while (true) { if (parseExpression(Value)) return true; @@ -4149,7 +4170,7 @@ bool AsmParser::parseDirectiveLEB128(bool Signed) { /// ::= { ".globl", ".weak", ... } [ identifier ( , identifier )* ] bool AsmParser::parseDirectiveSymbolAttribute(MCSymbolAttr Attr) { if (getLexer().isNot(AsmToken::EndOfStatement)) { - for (;;) { + while (true) { StringRef Name; SMLoc Loc = getTok().getLoc(); @@ -4748,7 +4769,7 @@ MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) { AsmToken EndToken, StartToken = getTok(); unsigned NestLevel = 0; - for (;;) { + while (true) { // Check whether we have reached the end of the file. if (getLexer().is(AsmToken::Eof)) { Error(DirectiveLoc, "no matching '.endr' in definition"); @@ -5300,8 +5321,8 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef, return false; } -} // namespace MCParserUtils -} // namespace llvm +} // end namespace MCParserUtils +} // end namespace llvm /// \brief Create an MCAsmParser instance. MCAsmParser *llvm::createMCAsmParser(SourceMgr &SM, MCContext &C, |