Index: include/llvm/MC/MCAsmMacro.h =================================================================== --- include/llvm/MC/MCAsmMacro.h +++ include/llvm/MC/MCAsmMacro.h @@ -11,6 +11,7 @@ #define LLVM_MC_MCASMMACRO_H #include "llvm/MC/MCParser/MCAsmLexer.h" +#include "llvm/Support/Debug.h" namespace llvm { @@ -21,6 +22,9 @@ bool Vararg = false; MCAsmMacroParameter() = default; + + void dump() const { dump(dbgs()); } + void dump(raw_ostream &OS) const; }; typedef std::vector MCAsmMacroParameters; @@ -32,6 +36,9 @@ public: MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P) : Name(N), Body(B), Parameters(std::move(P)) {} + + void dump() const { dump(dbgs()); } + void dump(raw_ostream &OS) const; }; } // namespace llvm Index: include/llvm/MC/MCContext.h =================================================================== --- include/llvm/MC/MCContext.h +++ include/llvm/MC/MCContext.h @@ -634,10 +634,17 @@ } void defineMacro(StringRef Name, MCAsmMacro Macro) { + DEBUG_WITH_TYPE("asm-macros", dbgs() << "Defining new macro:\n"; + Macro.dump()); MacroMap.insert(std::make_pair(Name, std::move(Macro))); } - void undefineMacro(StringRef Name) { MacroMap.erase(Name); } + void undefineMacro(StringRef Name) { + if (MacroMap.erase(Name)) { + DEBUG_WITH_TYPE("asm-macros", + dbgs() << "Un-defining macro: " << Name << "\n"); + } + } }; } // end namespace llvm Index: lib/MC/CMakeLists.txt =================================================================== --- lib/MC/CMakeLists.txt +++ lib/MC/CMakeLists.txt @@ -7,6 +7,7 @@ MCAsmInfoDarwin.cpp MCAsmInfoELF.cpp MCAsmInfoWasm.cpp + MCAsmMacro.cpp MCAsmStreamer.cpp MCAssembler.cpp MCCodeEmitter.cpp Index: lib/MC/MCAsmMacro.cpp =================================================================== --- /dev/null +++ lib/MC/MCAsmMacro.cpp @@ -0,0 +1,42 @@ +//===- MCAsmMacro.h - Assembly Macros ---------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/MC/MCAsmMacro.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +void MCAsmMacroParameter::dump(raw_ostream &OS) const { + OS << "\"" << Name << "\""; + if (Required) + OS << ":req"; + if (Vararg) + OS << ":vararg"; + if (!Value.empty()) { + OS << " = "; + bool first = true; + for (const AsmToken &T : Value) { + if (!first) + OS << ", "; + first = false; + T.dump(); + } + } + OS << "\n"; +} + +void MCAsmMacro::dump(raw_ostream &OS) const { + OS << "Macro " << Name << ":\n"; + OS << " Parameters:\n"; + for (const MCAsmMacroParameter &P : Parameters) { + OS << " "; + P.dump(); + } + OS << " (BEGIN BODY)" << Body << "(END BODY)\n"; +}