From: Eugene Zelenko Date: Tue, 7 Feb 2017 23:02:00 +0000 (+0000) Subject: [MC] Fix some Clang-tidy modernize and Include What You Use warnings; other minor... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f31871c702c2b6d09797a2c8f830d21d8f20175c;p=llvm [MC] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294369 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/ConstantPools.h b/include/llvm/MC/ConstantPools.h index f0c445dbe59..643902377dd 100644 --- a/include/llvm/MC/ConstantPools.h +++ b/include/llvm/MC/ConstantPools.h @@ -11,15 +11,17 @@ // //===----------------------------------------------------------------------===// - #ifndef LLVM_MC_CONSTANTPOOLS_H #define LLVM_MC_CONSTANTPOOLS_H +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/SMLoc.h" +#include namespace llvm { + class MCContext; class MCExpr; class MCSection; @@ -30,6 +32,7 @@ class MCSymbolRefExpr; struct ConstantPoolEntry { ConstantPoolEntry(MCSymbol *L, const MCExpr *Val, unsigned Sz, SMLoc Loc_) : Label(L), Value(Val), Size(Sz), Loc(Loc_) {} + MCSymbol *Label; const MCExpr *Value; unsigned Size; @@ -45,7 +48,7 @@ class ConstantPool { public: // Initialize a new empty constant pool - ConstantPool() {} + ConstantPool() = default; // Add a new entry to the constant pool in the next slot. // \param Value is the new entry to put in the constant pool. @@ -90,6 +93,7 @@ private: ConstantPool *getConstantPool(MCSection *Section); ConstantPool &getOrCreateConstantPool(MCSection *Section); }; + } // end namespace llvm -#endif +#endif // LLVM_MC_CONSTANTPOOLS_H diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 641e7899476..c29abaa03a6 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -10,33 +10,35 @@ #ifndef LLVM_MC_MCASSEMBLER_H #define LLVM_MC_MCASSEMBLER_H -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallPtrSet.h" -#include "llvm/ADT/ilist.h" -#include "llvm/ADT/ilist_node.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/iterator.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCFragment.h" -#include "llvm/MC/MCInst.h" #include "llvm/MC/MCLinkerOptimizationHint.h" -#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" +#include +#include +#include +#include +#include +#include namespace llvm { -class raw_ostream; + +class MCAsmBackend; class MCAsmLayout; -class MCAssembler; class MCContext; class MCCodeEmitter; -class MCExpr; class MCFragment; class MCObjectWriter; class MCSection; -class MCSubtargetInfo; class MCValue; -class MCAsmBackend; // FIXME: This really doesn't belong here. See comments below. struct IndirectSymbolData { @@ -90,9 +92,6 @@ public: } VersionMinInfoType; private: - MCAssembler(const MCAssembler &) = delete; - void operator=(const MCAssembler &) = delete; - MCContext &Context; MCAsmBackend &Backend; @@ -131,9 +130,9 @@ private: /// By default it's 0, which means bundling is disabled. unsigned BundleAlignSize; - unsigned RelaxAll : 1; - unsigned SubsectionsViaSymbols : 1; - unsigned IncrementalLinkerCompatible : 1; + bool RelaxAll : 1; + bool SubsectionsViaSymbols : 1; + bool IncrementalLinkerCompatible : 1; /// ELF specific e_header flags // It would be good if there were an MCELFAssembler class to hold this. @@ -148,7 +147,6 @@ private: VersionMinInfoType VersionMinInfo; -private: /// Evaluate a fixup to a relocatable expression and the value which should be /// placed into the fixup. /// @@ -201,6 +199,18 @@ private: MCFragment &F, const MCFixup &Fixup); public: + /// Construct a new assembler instance. + // + // FIXME: How are we going to parameterize this? Two obvious options are stay + // concrete and require clients to pass in a target like object. The other + // option is to make this abstract, and have targets provide concrete + // implementations as we do with AsmParser. + MCAssembler(MCContext &Context, MCAsmBackend &Backend, + MCCodeEmitter &Emitter, MCObjectWriter &Writer); + MCAssembler(const MCAssembler &) = delete; + MCAssembler &operator=(const MCAssembler &) = delete; + ~MCAssembler(); + /// Compute the effective fragment size assuming it is laid out at the given /// \p SectionAddress and \p FragmentOffset. uint64_t computeFragmentSize(const MCAsmLayout &Layout, @@ -240,17 +250,6 @@ public: VersionMinInfo.Update = Update; } -public: - /// Construct a new assembler instance. - // - // FIXME: How are we going to parameterize this? Two obvious options are stay - // concrete and require clients to pass in a target like object. The other - // option is to make this abstract, and have targets provide concrete - // implementations as we do with AsmParser. - MCAssembler(MCContext &Context, MCAsmBackend &Backend, - MCCodeEmitter &Emitter, MCObjectWriter &Writer); - ~MCAssembler(); - /// Reuse an assembler instance /// void reset(); @@ -425,4 +424,4 @@ uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *F, } // end namespace llvm -#endif +#endif // LLVM_MC_MCASSEMBLER_H diff --git a/include/llvm/MC/MCELFObjectWriter.h b/include/llvm/MC/MCELFObjectWriter.h index 376e2182131..f22fc11f9b0 100644 --- a/include/llvm/MC/MCELFObjectWriter.h +++ b/include/llvm/MC/MCELFObjectWriter.h @@ -1,4 +1,4 @@ -//===-- llvm/MC/MCELFObjectWriter.h - ELF Object Writer ---------*- C++ -*-===// +//===- llvm/MC/MCELFObjectWriter.h - ELF Object Writer ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -11,22 +11,21 @@ #define LLVM_MC_MCELFOBJECTWRITER_H #include "llvm/ADT/Triple.h" -#include "llvm/MC/MCValue.h" -#include "llvm/Support/DataTypes.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ELF.h" #include "llvm/Support/raw_ostream.h" +#include #include namespace llvm { + class MCAssembler; class MCContext; class MCFixup; -class MCFragment; class MCObjectWriter; class MCSymbol; class MCSymbolELF; class MCValue; -class raw_pwrite_stream; struct ELFRelocationEntry { uint64_t Offset; // Where is the relocation. @@ -47,6 +46,7 @@ struct ELFRelocationEntry { << ", Addend=" << Addend << ", OriginalSymbol=" << OriginalSymbol << ", OriginalAddend=" << OriginalAddend; } + void dump() const { print(errs()); } }; @@ -58,12 +58,12 @@ class MCELFObjectTargetWriter { const unsigned IsN64 : 1; protected: - - MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_, - uint16_t EMachine_, bool HasRelocationAddend, - bool IsN64=false); + MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_, uint16_t EMachine_, + bool HasRelocationAddend, bool IsN64 = false); public: + virtual ~MCELFObjectTargetWriter() = default; + static uint8_t getOSABI(Triple::OSType OSType) { switch (OSType) { case Triple::CloudABI: @@ -76,8 +76,6 @@ public: } } - virtual ~MCELFObjectTargetWriter() {} - virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const = 0; @@ -144,6 +142,7 @@ public: MCObjectWriter *createELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS, bool IsLittleEndian); -} // End llvm namespace -#endif +} // end namespace llvm + +#endif // LLVM_MC_MCELFOBJECTWRITER_H diff --git a/include/llvm/MC/MCELFStreamer.h b/include/llvm/MC/MCELFStreamer.h index a5c26384435..29791efb92f 100644 --- a/include/llvm/MC/MCELFStreamer.h +++ b/include/llvm/MC/MCELFStreamer.h @@ -10,27 +10,24 @@ #ifndef LLVM_MC_MCELFSTREAMER_H #define LLVM_MC_MCELFSTREAMER_H -#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCObjectStreamer.h" -#include "llvm/MC/SectionKind.h" -#include "llvm/Support/DataTypes.h" namespace llvm { + class MCAsmBackend; -class MCAssembler; class MCCodeEmitter; class MCExpr; class MCInst; -class raw_ostream; class MCELFStreamer : public MCObjectStreamer { public: MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter) - : MCObjectStreamer(Context, TAB, OS, Emitter), SeenIdent(false) {} + : MCObjectStreamer(Context, TAB, OS, Emitter) {} - ~MCELFStreamer() override; + ~MCELFStreamer() override = default; /// state management void reset() override { @@ -91,11 +88,11 @@ private: /// \brief Merge the content of the fragment \p EF into the fragment \p DF. void mergeFragment(MCDataFragment *, MCDataFragment *); - bool SeenIdent; + bool SeenIdent = false; /// BundleGroups - The stack of fragments holding the bundle-locked /// instructions. - llvm::SmallVector BundleGroups; + SmallVector BundleGroups; }; MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, @@ -105,4 +102,4 @@ MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, } // end namespace llvm -#endif +#endif // LLVM_MC_MCELFSTREAMER_H diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h index 8e40d268005..515e441a16c 100644 --- a/include/llvm/MC/MCExpr.h +++ b/include/llvm/MC/MCExpr.h @@ -11,11 +11,11 @@ #define LLVM_MC_MCEXPR_H #include "llvm/ADT/DenseMap.h" -#include "llvm/Support/Casting.h" -#include "llvm/Support/DataTypes.h" #include "llvm/Support/SMLoc.h" +#include namespace llvm { + class MCAsmInfo; class MCAsmLayout; class MCAssembler; @@ -46,9 +46,6 @@ private: ExprKind Kind; SMLoc Loc; - MCExpr(const MCExpr&) = delete; - void operator=(const MCExpr&) = delete; - bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, const MCAsmLayout *Layout, const SectionAddrMap *Addrs) const; @@ -66,6 +63,9 @@ protected: const SectionAddrMap *Addrs, bool InSet) const; public: + MCExpr(const MCExpr &) = delete; + MCExpr &operator=(const MCExpr &) = delete; + /// \name Accessors /// @{ @@ -359,15 +359,19 @@ public: static const MCUnaryExpr *create(Opcode Op, const MCExpr *Expr, MCContext &Ctx); + static const MCUnaryExpr *createLNot(const MCExpr *Expr, MCContext &Ctx) { return create(LNot, Expr, Ctx); } + static const MCUnaryExpr *createMinus(const MCExpr *Expr, MCContext &Ctx) { return create(Minus, Expr, Ctx); } + static const MCUnaryExpr *createNot(const MCExpr *Expr, MCContext &Ctx) { return create(Not, Expr, Ctx); } + static const MCUnaryExpr *createPlus(const MCExpr *Expr, MCContext &Ctx) { return create(Plus, Expr, Ctx); } @@ -433,78 +437,97 @@ public: static const MCBinaryExpr *create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc = SMLoc()); + static const MCBinaryExpr *createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Add, LHS, RHS, Ctx); } + static const MCBinaryExpr *createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(And, LHS, RHS, Ctx); } + static const MCBinaryExpr *createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Div, LHS, RHS, Ctx); } + static const MCBinaryExpr *createEQ(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(EQ, LHS, RHS, Ctx); } + static const MCBinaryExpr *createGT(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(GT, LHS, RHS, Ctx); } + static const MCBinaryExpr *createGTE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(GTE, LHS, RHS, Ctx); } + static const MCBinaryExpr *createLAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(LAnd, LHS, RHS, Ctx); } + static const MCBinaryExpr *createLOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(LOr, LHS, RHS, Ctx); } + static const MCBinaryExpr *createLT(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(LT, LHS, RHS, Ctx); } + static const MCBinaryExpr *createLTE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(LTE, LHS, RHS, Ctx); } + static const MCBinaryExpr *createMod(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Mod, LHS, RHS, Ctx); } + static const MCBinaryExpr *createMul(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Mul, LHS, RHS, Ctx); } + static const MCBinaryExpr *createNE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(NE, LHS, RHS, Ctx); } + static const MCBinaryExpr *createOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Or, LHS, RHS, Ctx); } + static const MCBinaryExpr *createShl(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Shl, LHS, RHS, Ctx); } + static const MCBinaryExpr *createAShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(AShr, LHS, RHS, Ctx); } + static const MCBinaryExpr *createLShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(LShr, LHS, RHS, Ctx); } + static const MCBinaryExpr *createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Sub, LHS, RHS, Ctx); } + static const MCBinaryExpr *createXor(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx) { return create(Xor, LHS, RHS, Ctx); @@ -537,9 +560,11 @@ public: /// MCExprs are bump pointer allocated and not destructed. class MCTargetExpr : public MCExpr { virtual void anchor(); + protected: MCTargetExpr() : MCExpr(Target, SMLoc()) {} - virtual ~MCTargetExpr() {} + virtual ~MCTargetExpr() = default; + public: virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const = 0; virtual bool evaluateAsRelocatableImpl(MCValue &Res, @@ -557,4 +582,4 @@ public: } // end namespace llvm -#endif +#endif // LLVM_MC_MCEXPR_H diff --git a/include/llvm/MC/MCFragment.h b/include/llvm/MC/MCFragment.h index edb740f36d9..fc8257f90a9 100644 --- a/include/llvm/MC/MCFragment.h +++ b/include/llvm/MC/MCFragment.h @@ -10,25 +10,26 @@ #ifndef LLVM_MC_MCFRAGMENT_H #define LLVM_MC_MCFRAGMENT_H -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/ilist.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/ilist_node.h" -#include "llvm/ADT/iterator.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCInst.h" +#include "llvm/Support/SMLoc.h" +#include +#include namespace llvm { + class MCSection; -class MCSymbol; class MCSubtargetInfo; +class MCSymbol; class MCFragment : public ilist_node_with_parent { friend class MCAsmLayout; - MCFragment() = delete; - MCFragment(const MCFragment &) = delete; - void operator=(const MCFragment &) = delete; - public: enum FragmentType : uint8_t { FT_Align, @@ -86,6 +87,10 @@ protected: ~MCFragment(); public: + MCFragment() = delete; + MCFragment(const MCFragment &) = delete; + MCFragment &operator=(const MCFragment &) = delete; + /// Destroys the current fragment. /// /// This must be used instead of delete as MCFragment is non-virtual. @@ -131,7 +136,8 @@ public: class MCDummyFragment : public MCFragment { public: explicit MCDummyFragment(MCSection *Sec) - : MCFragment(FT_Dummy, false, 0, Sec){}; + : MCFragment(FT_Dummy, false, 0, Sec) {} + static bool classof(const MCFragment *F) { return F->getKind() == FT_Dummy; } }; @@ -271,7 +277,6 @@ public: }; class MCAlignFragment : public MCFragment { - /// Alignment - The alignment to ensure, in bytes. unsigned Alignment; @@ -319,7 +324,6 @@ public: }; class MCFillFragment : public MCFragment { - /// Value to use for filling bytes. uint8_t Value; @@ -339,7 +343,6 @@ public: }; class MCOrgFragment : public MCFragment { - /// Offset - The offset this fragment should start at. const MCExpr *Offset; @@ -371,7 +374,6 @@ public: }; class MCLEBFragment : public MCFragment { - /// Value - The value this fragment should contain. const MCExpr *Value; @@ -404,7 +406,6 @@ public: }; class MCDwarfLineAddrFragment : public MCFragment { - /// LineDelta - the value of the difference between the two line numbers /// between two .loc dwarf directives. int64_t LineDelta; @@ -441,7 +442,6 @@ public: }; class MCDwarfCallFrameFragment : public MCFragment { - /// AddrDelta - The expression for the difference of the two symbols that /// make up the address delta between two .cfi_* dwarf directives. const MCExpr *AddrDelta; @@ -561,4 +561,4 @@ public: } // end namespace llvm -#endif +#endif // LLVM_MC_MCFRAGMENT_H diff --git a/include/llvm/MC/MCMachObjectWriter.h b/include/llvm/MC/MCMachObjectWriter.h index 1a685dbd608..b93638f8640 100644 --- a/include/llvm/MC/MCMachObjectWriter.h +++ b/include/llvm/MC/MCMachObjectWriter.h @@ -1,4 +1,4 @@ -//===-- llvm/MC/MCMachObjectWriter.h - Mach Object Writer -------*- C++ -*-===// +//===- llvm/MC/MCMachObjectWriter.h - Mach Object Writer --------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -11,12 +11,15 @@ #define LLVM_MC_MCMACHOBJECTWRITER_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/StringTableBuilder.h" -#include "llvm/Support/DataTypes.h" #include "llvm/Support/MachO.h" +#include +#include +#include #include namespace llvm { @@ -95,8 +98,8 @@ class MachObjectWriter : public MCObjectWriter { : Sym(Sym), MRE(MRE) {} }; - llvm::DenseMap> Relocations; - llvm::DenseMap IndirectSymBase; + DenseMap> Relocations; + DenseMap IndirectSymBase; SectionAddrMap SectionAddress; @@ -271,6 +274,6 @@ MCObjectWriter *createMachObjectWriter(MCMachObjectTargetWriter *MOTW, raw_pwrite_stream &OS, bool IsLittleEndian); -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_MC_MCMACHOBJECTWRITER_H diff --git a/include/llvm/MC/MCParser/MCAsmParser.h b/include/llvm/MC/MCParser/MCAsmParser.h index c289f51f43f..84e1c8f5319 100644 --- a/include/llvm/MC/MCParser/MCAsmParser.h +++ b/include/llvm/MC/MCParser/MCAsmParser.h @@ -1,4 +1,4 @@ -//===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- C++ -*-===// +//===- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -10,16 +10,21 @@ #ifndef LLVM_MC_MCPARSER_MCASMPARSER_H #define LLVM_MC_MCPARSER_MCASMPARSER_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/StringRef.h" #include "llvm/ADT/Twine.h" -#include "llvm/MC/MCParser/AsmLexer.h" -#include "llvm/Support/DataTypes.h" +#include "llvm/MC/MCParser/MCAsmLexer.h" +#include "llvm/Support/SMLoc.h" +#include +#include +#include namespace llvm { + class MCAsmInfo; -class MCAsmLexer; class MCAsmParserExtension; class MCContext; class MCExpr; @@ -27,10 +32,7 @@ class MCInstPrinter; class MCInstrInfo; class MCStreamer; class MCTargetAsmParser; -class SMLoc; -class SMRange; class SourceMgr; -class Twine; class InlineAsmIdentifierInfo { public: @@ -51,12 +53,12 @@ public: class MCAsmParserSemaCallback { public: virtual ~MCAsmParserSemaCallback(); + virtual void *LookupInlineAsmIdentifier(StringRef &LineBuf, InlineAsmIdentifierInfo &Info, bool IsUnevaluatedContext) = 0; virtual StringRef LookupInlineAsmLabel(StringRef Identifier, SourceMgr &SM, SMLoc Location, bool Create) = 0; - virtual bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset) = 0; }; @@ -76,22 +78,21 @@ public: }; private: - MCAsmParser(const MCAsmParser &) = delete; - void operator=(const MCAsmParser &) = delete; - - MCTargetAsmParser *TargetParser; + MCTargetAsmParser *TargetParser = nullptr; unsigned ShowParsedOperands : 1; protected: // Can only create subclasses. MCAsmParser(); - bool HadError; + bool HadError = false; SmallVector PendingErrors; /// Flag tracking whether any errors have been encountered. public: + MCAsmParser(const MCAsmParser &) = delete; + MCAsmParser &operator=(const MCAsmParser &) = delete; virtual ~MCAsmParser(); virtual void addDirectiveHandler(StringRef Directive, @@ -190,8 +191,8 @@ public: bool parseIntToken(int64_t &V, const Twine &ErrMsg); - bool check(bool P, const llvm::Twine &Msg); - bool check(bool P, SMLoc Loc, const llvm::Twine &Msg); + bool check(bool P, const Twine &Msg); + bool check(bool P, SMLoc Loc, const Twine &Msg); /// \brief Parse an identifier or string (as a quoted identifier) and set \p /// Res to the identifier contents. @@ -260,6 +261,6 @@ public: MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &); -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_MC_MCPARSER_MCASMPARSER_H diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index 41f00a24dfb..cf3b52a7b68 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -15,17 +15,26 @@ #define LLVM_MC_MCSTREAMER_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCLinkerOptimizationHint.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCWinEH.h" -#include "llvm/Support/DataTypes.h" #include "llvm/Support/SMLoc.h" +#include +#include +#include #include +#include +#include namespace llvm { + +class AssemblerConstantPools; +class formatted_raw_ostream; class MCAsmBackend; class MCCodeEmitter; class MCContext; @@ -34,14 +43,10 @@ class MCInst; class MCInstPrinter; class MCSection; class MCStreamer; -class MCSymbolELF; class MCSymbolRefExpr; class MCSubtargetInfo; -class StringRef; -class Twine; class raw_ostream; -class formatted_raw_ostream; -class AssemblerConstantPools; +class Twine; typedef std::pair MCSectionSubPair; @@ -162,9 +167,6 @@ class MCStreamer { MCContext &Context; std::unique_ptr TargetStreamer; - MCStreamer(const MCStreamer &) = delete; - MCStreamer &operator=(const MCStreamer &) = delete; - std::vector DwarfFrameInfos; MCDwarfFrameInfo *getCurrentDwarfFrameInfo(); void EnsureValidDwarfFrame(); @@ -205,6 +207,8 @@ protected: virtual void EmitRawTextImpl(StringRef String); public: + MCStreamer(const MCStreamer &) = delete; + MCStreamer &operator=(const MCStreamer &) = delete; virtual ~MCStreamer(); void visitUsedExpr(const MCExpr &Expr); @@ -282,6 +286,7 @@ public: /// \brief Add explicit comment T. T is required to be a valid /// comment in the output and does not need to be escaped. virtual void addExplicitComment(const Twine &T); + /// \brief Emit added explicit comments. virtual void emitExplicitComments(); @@ -876,6 +881,7 @@ MCStreamer *createAsmStreamer(MCContext &Ctx, bool isVerboseAsm, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst); + } // end namespace llvm -#endif +#endif // LLVM_MC_MCSTREAMER_H diff --git a/include/llvm/MC/MCWinCOFFObjectWriter.h b/include/llvm/MC/MCWinCOFFObjectWriter.h index e2e95c7df71..57bed213aad 100644 --- a/include/llvm/MC/MCWinCOFFObjectWriter.h +++ b/include/llvm/MC/MCWinCOFFObjectWriter.h @@ -1,4 +1,4 @@ -//===-- llvm/MC/MCWinCOFFObjectWriter.h - Win COFF Object Writer *- C++ -*-===// +//===- llvm/MC/MCWinCOFFObjectWriter.h - Win COFF Object Writer -*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -11,22 +11,23 @@ #define LLVM_MC_MCWINCOFFOBJECTWRITER_H namespace llvm { + class MCAsmBackend; class MCFixup; class MCObjectWriter; class MCValue; -class raw_ostream; class raw_pwrite_stream; class MCWinCOFFObjectTargetWriter { virtual void anchor(); + const unsigned Machine; protected: MCWinCOFFObjectTargetWriter(unsigned Machine_); public: - virtual ~MCWinCOFFObjectTargetWriter() {} + virtual ~MCWinCOFFObjectTargetWriter() = default; unsigned getMachine() const { return Machine; } virtual unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup, @@ -42,6 +43,6 @@ class raw_pwrite_stream; /// \returns The constructed object writer. MCObjectWriter *createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, raw_pwrite_stream &OS); -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_MC_MCWINCOFFOBJECTWRITER_H diff --git a/include/llvm/MC/MCWinCOFFStreamer.h b/include/llvm/MC/MCWinCOFFStreamer.h index 63e44f2e67d..cf92d65f23d 100644 --- a/include/llvm/MC/MCWinCOFFStreamer.h +++ b/include/llvm/MC/MCWinCOFFStreamer.h @@ -14,16 +14,15 @@ #include "llvm/MC/MCObjectStreamer.h" namespace llvm { + class MCAsmBackend; class MCContext; class MCCodeEmitter; -class MCExpr; class MCInst; class MCSection; class MCSubtargetInfo; class MCSymbol; class StringRef; -class raw_ostream; class raw_pwrite_stream; class MCWinCOFFStreamer : public MCObjectStreamer { @@ -70,12 +69,13 @@ public: protected: const MCSymbol *CurSymbol; + void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override; private: void Error(const Twine &Msg) const; }; -} -#endif +} // end namespace llvm +#endif // LLVM_MC_MCWINCOFFSTREAMER_H diff --git a/lib/MC/ConstantPools.cpp b/lib/MC/ConstantPools.cpp index 9608c2c656b..8c94e278099 100644 --- a/lib/MC/ConstantPools.cpp +++ b/lib/MC/ConstantPools.cpp @@ -1,4 +1,4 @@ -//===- ConstantPools.cpp - ConstantPool class --*- C++ -*---------===// +//===- ConstantPools.cpp - ConstantPool class -----------------------------===// // // The LLVM Compiler Infrastructure // @@ -10,13 +10,16 @@ // This file implements the ConstantPool and AssemblerConstantPools classes. // //===----------------------------------------------------------------------===// -#include "llvm/ADT/MapVector.h" + #include "llvm/MC/ConstantPools.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/Support/Casting.h" using namespace llvm; + // // ConstantPool implementation // diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 9019d11b611..1d20ea7ca44 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -7,36 +7,49 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCAssembler.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" -#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAsmLayout.h" +#include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCCodeView.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCFixup.h" #include "llvm/MC/MCFixupKindInfo.h" +#include "llvm/MC/MCFragment.h" +#include "llvm/MC/MCInst.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/LEB128.h" -#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include #include +#include + using namespace llvm; #define DEBUG_TYPE "assembler" namespace { namespace stats { + STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total"); STATISTIC(EmittedRelaxableFragments, "Number of emitted assembler fragments - relaxable"); @@ -55,8 +68,9 @@ STATISTIC(FragmentLayouts, "Number of fragment layouts"); STATISTIC(ObjectBytes, "Number of emitted object file bytes"); STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps"); STATISTIC(RelaxedInstructions, "Number of relaxed instructions"); -} -} + +} // end namespace stats +} // end anonymous namespace // FIXME FIXME FIXME: There are number of places in this file where we convert // what is a 64-bit assembler value used for computation into a value in the @@ -73,8 +87,7 @@ MCAssembler::MCAssembler(MCContext &Context, MCAsmBackend &Backend, VersionMinInfo.Major = 0; // Major version == 0 for "none specified" } -MCAssembler::~MCAssembler() { -} +MCAssembler::~MCAssembler() = default; void MCAssembler::reset() { Sections.clear(); @@ -225,7 +238,6 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout, Value -= Layout.getSymbolOffset(Sym); } - bool ShouldAlignPC = Backend.getFixupKindInfo(Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsAlignedDownTo32Bits; assert((ShouldAlignPC ? IsPCRel : true) && @@ -647,7 +659,7 @@ std::pair MCAssembler::handleFixup(const MCAsmLayout &Layout, void MCAssembler::layout(MCAsmLayout &Layout) { DEBUG_WITH_TYPE("mc-dump", { - llvm::errs() << "assembler backend - pre-layout\n--\n"; + errs() << "assembler backend - pre-layout\n--\n"; dump(); }); // Create dummy fragments and assign section ordinals. @@ -677,14 +689,14 @@ void MCAssembler::layout(MCAsmLayout &Layout) { return; DEBUG_WITH_TYPE("mc-dump", { - llvm::errs() << "assembler backend - post-relaxation\n--\n"; + errs() << "assembler backend - post-relaxation\n--\n"; dump(); }); // Finalize the layout, including fragment lowering. finishLayout(Layout); DEBUG_WITH_TYPE("mc-dump", { - llvm::errs() << "assembler backend - final-layout\n--\n"; + errs() << "assembler backend - final-layout\n--\n"; dump(); }); // Allow the object writer a chance to perform post-layout binding (for diff --git a/lib/MC/MCELFObjectTargetWriter.cpp b/lib/MC/MCELFObjectTargetWriter.cpp index de645cac737..68fb5e7cbb3 100644 --- a/lib/MC/MCELFObjectTargetWriter.cpp +++ b/lib/MC/MCELFObjectTargetWriter.cpp @@ -7,10 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/STLExtras.h" #include "llvm/MC/MCELFObjectWriter.h" -#include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCValue.h" using namespace llvm; diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index 47e9189415e..9f2120ccfc9 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -11,30 +11,31 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCELFStreamer.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCInst.h" +#include "llvm/MC/MCFixup.h" +#include "llvm/MC/MCFragment.h" #include "llvm/MC/MCObjectFileInfo.h" -#include "llvm/MC/MCObjectStreamer.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionELF.h" +#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/MC/MCValue.h" -#include "llvm/Support/Debug.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ELF.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" +#include +#include using namespace llvm; @@ -42,9 +43,6 @@ bool MCELFStreamer::isBundleLocked() const { return getCurrentSectionOnly()->isBundleLocked(); } -MCELFStreamer::~MCELFStreamer() { -} - void MCELFStreamer::mergeFragment(MCDataFragment *DF, MCDataFragment *EF) { MCAssembler &Assembler = getAssembler(); @@ -621,15 +619,6 @@ void MCELFStreamer::FinishImpl() { this->MCObjectStreamer::FinishImpl(); } -MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB, - raw_pwrite_stream &OS, MCCodeEmitter *CE, - bool RelaxAll) { - MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE); - if (RelaxAll) - S->getAssembler().setRelaxAll(true); - return S; -} - void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) { llvm_unreachable("Generic ELF doesn't support this directive"); } @@ -663,3 +652,12 @@ void MCELFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { llvm_unreachable("ELF doesn't support this directive"); } + +MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB, + raw_pwrite_stream &OS, MCCodeEmitter *CE, + bool RelaxAll) { + MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE); + if (RelaxAll) + S->getAssembler().setRelaxAll(true); + return S; +} diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index 17ab97f6768..7522e921160 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -7,28 +7,35 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCExpr.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCExpr.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include +#include + using namespace llvm; #define DEBUG_TYPE "mcexpr" namespace { namespace stats { + STATISTIC(MCExprEvaluate, "Number of MCExpr evaluations"); -} -} + +} // end namespace stats +} // end anonymous namespace void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const { switch (getKind()) { @@ -44,7 +51,7 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const { // Parenthesize names that start with $ so that they don't look like // absolute names. bool UseParens = - !InParens && Sym.getName().size() && Sym.getName()[0] == '$'; + !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$'; if (UseParens) { OS << '('; Sym.print(OS, MAI); diff --git a/lib/MC/MCFragment.cpp b/lib/MC/MCFragment.cpp index da6ee7a0730..90b44177cf5 100644 --- a/lib/MC/MCFragment.cpp +++ b/lib/MC/MCFragment.cpp @@ -7,30 +7,29 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCFragment.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAssembler.h" -#include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCFixupKindInfo.h" +#include "llvm/MC/MCFixup.h" +#include "llvm/MC/MCFragment.h" #include "llvm/MC/MCSection.h" -#include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/LEB128.h" -#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include + using namespace llvm; -MCAsmLayout::MCAsmLayout(MCAssembler &Asm) - : Assembler(Asm), LastValidFragment() - { +MCAsmLayout::MCAsmLayout(MCAssembler &Asm) : Assembler(Asm) { // Compute the section layout order. Virtual sections must go last. for (MCSection &Sec : Asm) if (!Sec.isVirtualSection()) @@ -233,7 +232,7 @@ uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler, void ilist_alloc_traits::deleteNode(MCFragment *V) { V->destroy(); } -MCFragment::~MCFragment() { } +MCFragment::~MCFragment() = default; MCFragment::MCFragment(FragmentType Kind, bool HasInstructions, uint8_t BundlePadding, MCSection *Parent) @@ -294,8 +293,6 @@ void MCFragment::destroy() { } } -/* *** */ - // Debugging methods namespace llvm { @@ -307,11 +304,11 @@ raw_ostream &operator<<(raw_ostream &OS, const MCFixup &AF) { return OS; } -} +} // end namespace llvm #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void MCFragment::dump() { - raw_ostream &OS = llvm::errs(); + raw_ostream &OS = errs(); OS << "<"; switch (getKind()) { @@ -449,7 +446,7 @@ LLVM_DUMP_METHOD void MCFragment::dump() { } LLVM_DUMP_METHOD void MCAssembler::dump() { - raw_ostream &OS = llvm::errs(); + raw_ostream &OS = errs(); OS << " +#include using namespace llvm; @@ -83,18 +91,23 @@ public: void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override; void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; + void BeginCOFFSymbolDef(const MCSymbol *Symbol) override { llvm_unreachable("macho doesn't support this directive"); } + void EmitCOFFSymbolStorageClass(int StorageClass) override { llvm_unreachable("macho doesn't support this directive"); } + void EmitCOFFSymbolType(int Type) override { llvm_unreachable("macho doesn't support this directive"); } + void EndCOFFSymbolDef() override { llvm_unreachable("macho doesn't support this directive"); } + void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, diff --git a/lib/MC/MCParser/ELFAsmParser.cpp b/lib/MC/MCParser/ELFAsmParser.cpp index c7b53ec19d8..3bee12f6824 100644 --- a/lib/MC/MCParser/ELFAsmParser.cpp +++ b/lib/MC/MCParser/ELFAsmParser.cpp @@ -7,17 +7,29 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCParser/MCAsmParserExtension.h" #include "llvm/ADT/StringSwitch.h" -#include "llvm/ADT/Twine.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCParser/MCAsmLexer.h" +#include "llvm/MC/MCParser/MCAsmParser.h" +#include "llvm/MC/MCParser/MCAsmParserExtension.h" +#include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbolELF.h" +#include "llvm/MC/SectionKind.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/SMLoc.h" +#include +#include +#include + using namespace llvm; namespace { @@ -148,7 +160,7 @@ private: bool maybeParseUniqueID(int64_t &UniqueID); }; -} +} // end anonymous namespace /// ParseDirectiveSymbolAttribute /// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ] @@ -162,7 +174,7 @@ bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) { .Default(MCSA_Invalid); assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!"); if (getLexer().isNot(AsmToken::EndOfStatement)) { - for (;;) { + while (true) { StringRef Name; if (getParser().parseIdentifier(Name)) @@ -234,8 +246,7 @@ bool ELFAsmParser::ParseSectionName(StringRef &SectionName) { return false; } - for (;;) { - + while (true) { SMLoc PrevLoc = getLexer().getLoc(); if (getLexer().is(AsmToken::Comma) || getLexer().is(AsmToken::EndOfStatement)) @@ -784,4 +795,4 @@ MCAsmParserExtension *createELFAsmParser() { return new ELFAsmParser; } -} +} // end namespace llvm diff --git a/lib/MC/MCParser/MCAsmParser.cpp b/lib/MC/MCParser/MCAsmParser.cpp index 055bf5e8210..27b37f3e2df 100644 --- a/lib/MC/MCParser/MCAsmParser.cpp +++ b/lib/MC/MCParser/MCAsmParser.cpp @@ -7,22 +7,22 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCParser/MCAsmParser.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCParser/MCAsmLexer.h" +#include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCParser/MCParsedAsmOperand.h" #include "llvm/MC/MCParser/MCTargetAsmParser.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/SMLoc.h" #include "llvm/Support/raw_ostream.h" +#include + using namespace llvm; -MCAsmParser::MCAsmParser() - : TargetParser(nullptr), ShowParsedOperands(0), HadError(false), - PendingErrors() {} +MCAsmParser::MCAsmParser() : ShowParsedOperands(0) {} -MCAsmParser::~MCAsmParser() { -} +MCAsmParser::~MCAsmParser() = default; void MCAsmParser::setTargetParser(MCTargetAsmParser &P) { assert(!TargetParser && "Target parser is already initialized!"); @@ -121,7 +121,7 @@ bool MCAsmParser::addErrorSuffix(const Twine &Suffix) { bool MCAsmParser::parseMany(function_ref parseOne, bool hasComma) { if (parseOptionalToken(AsmToken::EndOfStatement)) return false; - while (1) { + while (true) { if (parseOne()) return true; if (parseOptionalToken(AsmToken::EndOfStatement)) diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index fb28f856f67..d0abd5d1dd3 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -7,36 +7,44 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCStreamer.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCCodeView.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCObjectFileInfo.h" -#include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionCOFF.h" +#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCWin64EH.h" +#include "llvm/MC/MCWinEH.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/COFF.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include -using namespace llvm; +#include +#include +#include -// Pin the vtables to this file. -MCTargetStreamer::~MCTargetStreamer() {} +using namespace llvm; MCTargetStreamer::MCTargetStreamer(MCStreamer &S) : Streamer(S) { S.setTargetStreamer(this); } +// Pin the vtables to this file. +MCTargetStreamer::~MCTargetStreamer() = default; + void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {} void MCTargetStreamer::finish() {} @@ -666,7 +674,7 @@ void MCStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) { void MCStreamer::EmitWinCFIPushFrame(bool Code) { EnsureValidWinFrameInfo(); - if (CurrentWinFrameInfo->Instructions.size() > 0) + if (!CurrentWinFrameInfo->Instructions.empty()) report_fatal_error("If present, PushMachFrame must be the first UOP"); MCSymbol *Label = EmitCFILabel(); diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index c4b35f5db9b..d9ccf0dd661 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -7,23 +7,36 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCMachObjectWriter.h" -#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" +#include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCFixupKindInfo.h" +#include "llvm/MC/MCFragment.h" +#include "llvm/MC/MCMachObjectWriter.h" #include "llvm/MC/MCObjectWriter.h" +#include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionMachO.h" +#include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbolMachO.h" #include "llvm/MC/MCValue.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MachO.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include #include + using namespace llvm; #define DEBUG_TYPE "mc" diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index afc5c6a14d1..86d76fbceb5 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -1,4 +1,4 @@ -//===-- llvm/MC/WinCOFFObjectWriter.cpp -------------------------*- C++ -*-===// +//===- llvm/MC/WinCOFFObjectWriter.cpp ------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -11,37 +11,48 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCWinCOFFObjectWriter.h" #include "llvm/ADT/DenseMap.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/Config/config.h" #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCObjectFileInfo.h" +#include "llvm/MC/MCFixup.h" +#include "llvm/MC/MCFragment.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionCOFF.h" +#include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbolCOFF.h" #include "llvm/MC/MCValue.h" +#include "llvm/MC/MCWinCOFFObjectWriter.h" #include "llvm/MC/StringTableBuilder.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/COFF.h" -#include "llvm/Support/Debug.h" #include "llvm/Support/Endian.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/JamCRC.h" -#include +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include #include +#include +#include +#include using namespace llvm; #define DEBUG_TYPE "WinCOFFObjectWriter" namespace { + typedef SmallString name; enum AuxiliaryType { @@ -57,7 +68,6 @@ struct AuxSymbol { COFF::Auxiliary Aux; }; -class COFFSymbol; class COFFSection; class COFFSymbol { @@ -69,13 +79,13 @@ public: name Name; int Index; AuxiliarySymbols Aux; - COFFSymbol *Other; - COFFSection *Section; - int Relocations; - - const MCSymbol *MC; + COFFSymbol *Other = nullptr; + COFFSection *Section = nullptr; + int Relocations = 0; + const MCSymbol *MC = nullptr; COFFSymbol(StringRef name); + void set_name_offset(uint32_t Offset); int64_t getIndex() const { return Index; } @@ -89,9 +99,10 @@ public: // This class contains staging data for a COFF relocation entry. struct COFFRelocation { COFF::relocation Data; - COFFSymbol *Symb; + COFFSymbol *Symb = nullptr; + + COFFRelocation() = default; - COFFRelocation() : Symb(nullptr) {} static size_t size() { return COFF::RelocationSize; } }; @@ -103,8 +114,8 @@ public: std::string Name; int Number; - MCSectionCOFF const *MCSection; - COFFSymbol *Symbol; + MCSectionCOFF const *MCSection = nullptr; + COFFSymbol *Symbol = nullptr; relocations Relocations; COFFSection(StringRef name); @@ -190,7 +201,8 @@ public: void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override; }; -} + +} // end anonymous namespace static inline void write_uint32_le(void *Data, uint32_t Value) { support::endian::write(Data, @@ -200,9 +212,7 @@ static inline void write_uint32_le(void *Data, uint32_t Value) { //------------------------------------------------------------------------------ // Symbol class implementation -COFFSymbol::COFFSymbol(StringRef name) - : Name(name.begin(), name.end()), Other(nullptr), Section(nullptr), - Relocations(0), MC(nullptr) { +COFFSymbol::COFFSymbol(StringRef name) : Name(name.begin(), name.end()) { memset(&Data, 0, sizeof(Data)); } @@ -217,8 +227,7 @@ void COFFSymbol::set_name_offset(uint32_t Offset) { //------------------------------------------------------------------------------ // Section class implementation -COFFSection::COFFSection(StringRef name) - : Name(name), MCSection(nullptr), Symbol(nullptr) { +COFFSection::COFFSection(StringRef name) : Name(name) { memset(&Header, 0, sizeof(Header)); } @@ -938,7 +947,7 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm, offset += Sec->Header.SizeOfRawData; } - if (Sec->Relocations.size() > 0) { + if (!Sec->Relocations.empty()) { bool RelocationsOverflow = Sec->Relocations.size() >= 0xffff; if (RelocationsOverflow) { @@ -1052,7 +1061,7 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm, SecDef.Aux.SectionDefinition.CheckSum = JC.getCRC(); } - if ((*i)->Relocations.size() > 0) { + if (!(*i)->Relocations.empty()) { assert(getStream().tell() == (*i)->Header.PointerToRelocations && "Section::PointerToRelocations is insane!"); diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 6383d879403..b3abd98a9f4 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -1,4 +1,4 @@ -//===-- llvm/MC/WinCOFFStreamer.cpp -----------------------------*- C++ -*-===// +//===- llvm/MC/WinCOFFStreamer.cpp ----------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -11,32 +11,36 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Triple.h" +#include "llvm/ADT/Twine.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCFixup.h" +#include "llvm/MC/MCFragment.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCObjectStreamer.h" #include "llvm/MC/MCSection.h" -#include "llvm/MC/MCSectionCOFF.h" -#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbolCOFF.h" -#include "llvm/MC/MCValue.h" #include "llvm/MC/MCWinCOFFStreamer.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/COFF.h" -#include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/SMLoc.h" +#include +#include +#include using namespace llvm; #define DEBUG_TYPE "WinCOFFStreamer" -namespace llvm { MCWinCOFFStreamer::MCWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB, MCCodeEmitter &CE, raw_pwrite_stream &OS) : MCObjectStreamer(Context, MAB, OS, &CE), CurSymbol(nullptr) {} @@ -295,5 +299,3 @@ void MCWinCOFFStreamer::FinishImpl() { void MCWinCOFFStreamer::Error(const Twine &Msg) const { getContext().reportError(SMLoc(), Msg); } -} -