llvm-mc: Add -show-inst-operands, for dumping the parsed instruction representation...
authorDaniel Dunbar <daniel@zuster.org>
Wed, 11 Aug 2010 06:37:09 +0000 (06:37 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 11 Aug 2010 06:37:09 +0000 (06:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110791 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/MCAsmParser.h
lib/MC/MCParser/AsmParser.cpp
lib/MC/MCParser/MCAsmParser.cpp
tools/llvm-mc/llvm-mc.cpp

index 9457987d230052e004567faf3622280ccbac1db2..b37d46cc5a25ddd4bc42b32d91d388055e976bc9 100644 (file)
@@ -39,6 +39,8 @@ private:
 
   TargetAsmParser *TargetParser;
 
+  unsigned ShowParsedOperands : 1;
+
 protected: // Can only create subclasses.
   MCAsmParser();
 
@@ -61,6 +63,9 @@ public:
   TargetAsmParser &getTargetParser() const { return *TargetParser; }
   void setTargetParser(TargetAsmParser &P);
 
+  bool getShowParsedOperands() const { return ShowParsedOperands; }
+  void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
+
   /// Run - Run the parser on the input source buffer.
   virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
 
index 70a37e3009b61c6b259f02a9bed7a13340695e14..016f8f96a36f4bd500cbf00268d711d365d6bcb6 100644 (file)
@@ -916,6 +916,21 @@ bool AsmParser::ParseStatement() {
   if (!HadError && Lexer.isNot(AsmToken::EndOfStatement))
     HadError = TokError("unexpected token in argument list");
 
+  // Dump the parsed representation, if requested.
+  if (getShowParsedOperands()) {
+    SmallString<256> Str;
+    raw_svector_ostream OS(Str);
+    OS << "parsed instruction: [";
+    for (unsigned i = 0; i != ParsedOperands.size(); ++i) {
+      if (i != 0)
+        OS << ", ";
+      ParsedOperands[i]->dump(OS);
+    }
+    OS << "]";
+
+    PrintMessage(IDLoc, OS.str(), "note");
+  }
+
   // If parsing succeeded, match the instruction.
   if (!HadError) {
     MCInst Inst;
index 0e0533b737016050f2d71b59ea726ed7dd66b429..70295efc613ca0a6bebb23d087f4919118f82e7c 100644 (file)
@@ -15,7 +15,7 @@
 #include "llvm/Target/TargetAsmParser.h"
 using namespace llvm;
 
-MCAsmParser::MCAsmParser() : TargetParser(0) {
+MCAsmParser::MCAsmParser() : TargetParser(0), ShowParsedOperands(0) {
 }
 
 MCAsmParser::~MCAsmParser() {
index 33531f18be1c1d6d6aabdcee68fed2792ca71ef5..94b11ebe64c66d6fe547c79555b83e21150bcfe5 100644 (file)
@@ -51,6 +51,10 @@ ShowEncoding("show-encoding", cl::desc("Show instruction encodings"));
 static cl::opt<bool>
 ShowInst("show-inst", cl::desc("Show internal instruction representation"));
 
+static cl::opt<bool>
+ShowInstOperands("show-inst-operands",
+                 cl::desc("Show instructions operands as parsed"));
+
 static cl::opt<unsigned>
 OutputAsmVariant("output-asm-variant",
                  cl::desc("Syntax variant to use for output printing"));
@@ -320,6 +324,7 @@ static int AssembleInput(const char *ProgName) {
     return 1;
   }
 
+  Parser->setShowParsedOperands(ShowInstOperands);
   Parser->setTargetParser(*TAP.get());
 
   int Res = Parser->Run(NoInitialTextSection);