]> granicus.if.org Git - clang/commitdiff
add scafolding to play around with and bring up the code rewriter.
authorChris Lattner <sabre@nondot.org>
Thu, 11 Oct 2007 00:43:27 +0000 (00:43 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 11 Oct 2007 00:43:27 +0000 (00:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42855 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.h
Driver/RewriteTest.cpp [new file with mode: 0644]
Driver/clang.cpp

index 4265672b95066e82f7b80671e668b60dbb578e5f..90b4f9735a82056102a5fb096467186f3134c48b 100644 (file)
@@ -27,6 +27,7 @@ ASTConsumer *CreateLiveVarAnalyzer();
 ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags);
 ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
 ASTConsumer *CreateLLVMEmitter(Diagnostic &Diags);
+ASTConsumer *CreateCodeRewriterTest();
 
 } // end clang namespace
 
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
new file mode 100644 (file)
index 0000000..ef1a9b0
--- /dev/null
@@ -0,0 +1,43 @@
+//===--- RewriteTest.cpp - Playground for the code rewriter ---------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Hacks and fun related to the code rewriter.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ASTConsumers.h"
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+
+using namespace clang;
+
+
+namespace {
+  class ASTViewer : public ASTConsumer {
+    SourceManager *SM;
+  public:
+    void Initialize(ASTContext &Context, unsigned MainFileID) {
+      SM = &Context.SourceMgr;
+    }
+    
+    virtual void HandleTopLevelDecl(Decl *D);
+  };
+}
+
+ASTConsumer *clang::CreateCodeRewriterTest() { return new ASTViewer(); }
+
+
+
+
+void ASTViewer::HandleTopLevelDecl(Decl *D) {
+  if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
+    if (ND->getName())
+      printf("%s\n", ND->getName());
+  
+}
index 9d8f71288f5aafe4cff2daf9ace93fc66492f9f1..6d9b6b0e4662fa9271acdc66e1fd11a228b04007 100644 (file)
@@ -49,6 +49,7 @@ static llvm::cl::opt<bool>
 Stats("stats", llvm::cl::desc("Print performance metrics and statistics"));
 
 enum ProgActions {
+  RewriteTest,                  // Rewriter testing stuff.
   EmitLLVM,                     // Emit a .ll file.
   ASTPrint,                     // Parse ASTs and print them.
   ASTDump,                      // Parse ASTs and dump them.
@@ -101,6 +102,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
                         "Flag warnings of uses of unitialized variables."),
              clEnumValN(EmitLLVM, "emit-llvm",
                         "Build ASTs then convert to LLVM, emit .ll file"),
+             clEnumValN(RewriteTest, "rewrite-test",
+                        "Playground for the code rewriter"),
              clEnumValEnd));
 
 static llvm::cl::opt<bool>
@@ -796,6 +799,10 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
   case EmitLLVM:
     Consumer = CreateLLVMEmitter(PP.getDiagnostics());
     break;
+    
+  case RewriteTest:
+    Consumer = CreateCodeRewriterTest();
+    break;
   }
   
   if (Consumer) {