[cfe-commits] r57406 - in /cfe/trunk: Driver/RewriteTest.cpp Driver/clang.cpp Driver/clang.h clang.xcodeproj/project.pbxproj

Chris Lattner sabre at nondot.org
Sat Oct 11 22:29:21 PDT 2008


Author: lattner
Date: Sun Oct 12 00:29:20 2008
New Revision: 57406

URL: http://llvm.org/viewvc/llvm-project?rev=57406&view=rev
Log:
Add a new -rewrite-test option, which is basically a 
playground to experiment with some new rewriter approaches. For now
it is probably the most complex version of 'cat' ever invented.

Added:
    cfe/trunk/Driver/RewriteTest.cpp
Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/Driver/clang.h
    cfe/trunk/clang.xcodeproj/project.pbxproj

Added: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=57406&view=auto

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (added)
+++ cfe/trunk/Driver/RewriteTest.cpp Sun Oct 12 00:29:20 2008
@@ -0,0 +1,41 @@
+//===--- RewriteTest.cpp - Rewriter playground ----------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a testbed.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Rewrite/TokenRewriter.h"
+#include "clang.h"
+#include "clang/Lex/Preprocessor.h"
+#include <iostream>
+
+void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
+                          const std::string &OutFileName) {
+  SourceManager &SM = PP.getSourceManager();
+  const LangOptions &LangOpts = PP.getLangOptions();
+
+  std::pair<const char*,const char*> File =SM.getBufferData(SM.getMainFileID());
+  
+  // Create a lexer to lex all the tokens of the main file in raw mode.  Even
+  // though it is in raw mode, it will not return comments.
+  Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
+               LangOpts, File.first, File.second);
+  
+  RawLex.SetKeepWhitespaceMode(true);
+  
+  Token RawTok;
+  RawLex.LexFromRawLexer(RawTok);
+  while (RawTok.isNot(tok::eof)) {
+    std::cout << PP.getSpelling(RawTok);
+    RawLex.LexFromRawLexer(RawTok);
+  }
+  
+  
+}
\ No newline at end of file

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=57406&r1=57405&r2=57406&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Sun Oct 12 00:29:20 2008
@@ -66,6 +66,7 @@
   RewriteObjC,                  // ObjC->C Rewriter.
   RewriteBlocks,                // ObjC->C Rewriter for Blocks.
   RewriteMacros,                // Expand macros but not #includes.
+  RewriteTest,                  // Rewriter playground
   HTMLTest,                     // HTML displayer testing stuff.
   EmitLLVM,                     // Emit a .ll file.
   EmitBC,                       // Emit a .bc file.
@@ -119,6 +120,8 @@
                         "Build ASTs then convert to LLVM, emit .bc file"),
              clEnumValN(SerializeAST, "serialize",
                         "Build ASTs and emit .ast file"),
+             clEnumValN(RewriteTest, "rewrite-test",
+                        "Rewriter playground"),
              clEnumValN(RewriteObjC, "rewrite-objc",
                         "Rewrite ObjC into C (code rewriter example)"),
              clEnumValN(RewriteMacros, "rewrite-macros",
@@ -1173,6 +1176,11 @@
     RewriteMacrosInInput(PP, InFile, OutputFile);
     ClearSourceMgr = true;
     break;
+      
+  case RewriteTest:
+    DoRewriteTest(PP, InFile, OutputFile);
+    ClearSourceMgr = true;
+    break;
   }
   
   if (Consumer) {

Modified: cfe/trunk/Driver/clang.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.h?rev=57406&r1=57405&r2=57406&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.h (original)
+++ cfe/trunk/Driver/clang.h Sun Oct 12 00:29:20 2008
@@ -32,6 +32,10 @@
 /// RewriteMacrosInInput - Implement -rewrite-macros mode.
 void RewriteMacrosInInput(Preprocessor &PP, const std::string &InFileName,
                           const std::string& OutFile);
+
+void DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
+                   const std::string &OutFileName);
+    
   
 /// CreatePrintParserActionsAction - Return the actions implementation that
 /// implements the -parse-print-callbacks option.

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=57406&r1=57405&r2=57406&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Sun Oct 12 00:29:20 2008
@@ -122,6 +122,7 @@
 		DE4772FA0C10EAE5002239E8 /* CGStmt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4772F90C10EAE5002239E8 /* CGStmt.cpp */; };
 		DE4772FC0C10EAEC002239E8 /* CGExpr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */; };
 		DE47999C0D2EBE1A00706D2D /* SemaExprObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE47999B0D2EBE1A00706D2D /* SemaExprObjC.cpp */; };
+		DE4DC79E0EA1C09E00069E5A /* RewriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */; };
 		DE5932D10AD60FF400BC794C /* clang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CD0AD60FF400BC794C /* clang.cpp */; };
 		DE5932D20AD60FF400BC794C /* clang.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE5932CE0AD60FF400BC794C /* clang.h */; };
 		DE5932D30AD60FF400BC794C /* PrintParserCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CF0AD60FF400BC794C /* PrintParserCallbacks.cpp */; };
@@ -443,6 +444,8 @@
 		DE4772F90C10EAE5002239E8 /* CGStmt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGStmt.cpp; path = lib/CodeGen/CGStmt.cpp; sourceTree = "<group>"; tabWidth = 2; };
 		DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGExpr.cpp; path = lib/CodeGen/CGExpr.cpp; sourceTree = "<group>"; tabWidth = 2; };
 		DE47999B0D2EBE1A00706D2D /* SemaExprObjC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaExprObjC.cpp; path = lib/Sema/SemaExprObjC.cpp; sourceTree = "<group>"; tabWidth = 2; };
+		DE4DC7980EA1BE4400069E5A /* TokenRewriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenRewriter.h; path = clang/Rewrite/TokenRewriter.h; sourceTree = "<group>"; };
+		DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RewriteTest.cpp; path = Driver/RewriteTest.cpp; sourceTree = "<group>"; };
 		DE53370B0CE2D96F00D9A028 /* RewriteRope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RewriteRope.h; path = clang/Rewrite/RewriteRope.h; sourceTree = "<group>"; };
 		DE5932CD0AD60FF400BC794C /* clang.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = clang.cpp; path = Driver/clang.cpp; sourceTree = "<group>"; };
 		DE5932CE0AD60FF400BC794C /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = clang.h; path = Driver/clang.h; sourceTree = "<group>"; };
@@ -883,6 +886,7 @@
 				9030C1090E807A9300941490 /* RewriteBlocks.cpp */,
 				DEA0EBD90DD2D3C8007A02A9 /* RewriteMacros.cpp */,
 				035611E10DB40C8100D2EF2A /* RewriteObjC.cpp */,
+				DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */,
 				352981080CC58344008B5E84 /* SerializationTest.cpp */,
 			);
 			name = Driver;
@@ -1057,6 +1061,7 @@
 				35F2BE7B0DAC2963006E7668 /* HTMLRewrite.h */,
 				DEF7D9F60C9C8B1A0001F598 /* Rewriter.h */,
 				DE53370B0CE2D96F00D9A028 /* RewriteRope.h */,
+				DE4DC7980EA1BE4400069E5A /* TokenRewriter.h */,
 			);
 			name = Rewrite;
 			sourceTree = "<group>";
@@ -1253,6 +1258,7 @@
 				355106860E9A8507006A4E44 /* MemRegion.cpp in Sources */,
 				3551068C0E9A8546006A4E44 /* ParsePragma.cpp in Sources */,
 				3551068D0E9A8546006A4E44 /* ParseTentative.cpp in Sources */,
+				DE4DC79E0EA1C09E00069E5A /* RewriteTest.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};





More information about the cfe-commits mailing list