[llvm] r326795 - [Asm] Add debug printing for assembler macros
Oliver Stannard via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 6 06:07:01 PST 2018
Author: olista01
Date: Tue Mar 6 06:07:01 2018
New Revision: 326795
URL: http://llvm.org/viewvc/llvm-project?rev=326795&view=rev
Log:
[Asm] Add debug printing for assembler macros
This adds some debug printing (gated behind the "asm-macros" debug flag) which
can help tracing complicated assembly macros.
Differential revision: https://reviews.llvm.org/D43937
Added:
llvm/trunk/lib/MC/MCAsmMacro.cpp
Modified:
llvm/trunk/include/llvm/MC/MCAsmMacro.h
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/CMakeLists.txt
Modified: llvm/trunk/include/llvm/MC/MCAsmMacro.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmMacro.h?rev=326795&r1=326794&r2=326795&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmMacro.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmMacro.h Tue Mar 6 06:07:01 2018
@@ -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 @@ struct MCAsmMacroParameter {
bool Vararg = false;
MCAsmMacroParameter() = default;
+
+ void dump() const { dump(dbgs()); }
+ void dump(raw_ostream &OS) const;
};
typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
@@ -32,6 +36,9 @@ struct MCAsmMacro {
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
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=326795&r1=326794&r2=326795&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Tue Mar 6 06:07:01 2018
@@ -634,10 +634,17 @@ namespace llvm {
}
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
Modified: llvm/trunk/lib/MC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/CMakeLists.txt?rev=326795&r1=326794&r2=326795&view=diff
==============================================================================
--- llvm/trunk/lib/MC/CMakeLists.txt (original)
+++ llvm/trunk/lib/MC/CMakeLists.txt Tue Mar 6 06:07:01 2018
@@ -7,6 +7,7 @@ add_llvm_library(LLVMMC
MCAsmInfoDarwin.cpp
MCAsmInfoELF.cpp
MCAsmInfoWasm.cpp
+ MCAsmMacro.cpp
MCAsmStreamer.cpp
MCAssembler.cpp
MCCodeEmitter.cpp
Added: llvm/trunk/lib/MC/MCAsmMacro.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmMacro.cpp?rev=326795&view=auto
==============================================================================
--- llvm/trunk/lib/MC/MCAsmMacro.cpp (added)
+++ llvm/trunk/lib/MC/MCAsmMacro.cpp Tue Mar 6 06:07:01 2018
@@ -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";
+}
More information about the llvm-commits
mailing list