diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-11-12 01:36:27 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-12 01:36:27 +0000 |
| commit | f7316732b8d082444c9809cde31d0fc9f1300369 (patch) | |
| tree | 41a3f50f2bc4e771c35bb3ef5c692ddcc9851e03 | |
| parent | f4408a29e1fb0030670e07aa00645df324a7deef (diff) | |
| download | bcm5719-llvm-f7316732b8d082444c9809cde31d0fc9f1300369.tar.gz bcm5719-llvm-f7316732b8d082444c9809cde31d0fc9f1300369.zip | |
clang-cc: Move non-Consumer action handling to common location, to expose the massive amount of redundancy we have introduced through blind copy-and-paste.
llvm-svn: 86922
| -rw-r--r-- | clang/tools/clang-cc/clang-cc.cpp | 128 |
1 files changed, 70 insertions, 58 deletions
diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index f6eec11c1c1..f6b38dfe154 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -678,41 +678,15 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, CompleteTranslationUnit = false; break; } - case DumpRawTokens: { - llvm::TimeRegion Timer(ClangFrontendTimer); - SourceManager &SM = PP.getSourceManager(); - // Start lexing the specified input file. - Lexer RawLex(SM.getMainFileID(), SM, PP.getLangOptions()); - RawLex.SetKeepWhitespaceMode(true); - Token RawTok; - RawLex.LexFromRawLexer(RawTok); - while (RawTok.isNot(tok::eof)) { - PP.DumpToken(RawTok, true); - fprintf(stderr, "\n"); - RawLex.LexFromRawLexer(RawTok); - } - ClearSourceMgr = true; - break; - } - case DumpTokens: { // Token dump mode. - llvm::TimeRegion Timer(ClangFrontendTimer); - Token Tok; - // Start preprocessing the specified input file. - PP.EnterMainSourceFile(); - do { - PP.Lex(Tok); - PP.DumpToken(Tok, true); - fprintf(stderr, "\n"); - } while (Tok.isNot(tok::eof)); - ClearSourceMgr = true; - break; - } + // Do any necessary set up for non-consumer actions. + case DumpRawTokens: + case DumpTokens: case RunPreprocessorOnly: - break; + case ParseNoop: + break; // No setup. - case GeneratePTH: { - llvm::TimeRegion Timer(ClangFrontendTimer); + case GeneratePTH: if (CompOpts.getOutputFile().empty() || CompOpts.getOutputFile() == "-") { // FIXME: Don't fail this way. // FIXME: Verify that we can actually seek in the given file. @@ -720,36 +694,13 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, ::exit(1); } OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath)); - CacheTokens(PP, static_cast<llvm::raw_fd_ostream*>(OS.get())); - ClearSourceMgr = true; break; - } case PrintPreprocessedInput: - OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath)); - break; - - case ParseNoop: - break; - - case ParsePrintCallbacks: { - llvm::TimeRegion Timer(ClangFrontendTimer); - OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath)); - ParseFile(PP, CreatePrintParserActionsAction(PP, OS.get())); - ClearSourceMgr = true; - break; - } - + case ParsePrintCallbacks: case RewriteMacros: - OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath)); - RewriteMacrosInInput(PP, OS.get()); - ClearSourceMgr = true; - break; - case RewriteTest: OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath)); - DoRewriteTest(PP, OS.get()); - ClearSourceMgr = true; break; } @@ -871,18 +822,45 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, switch (PA) { default: break; - case RunPreprocessorOnly: { // Just lex as fast as we can, no output. + case DumpRawTokens: { + llvm::TimeRegion Timer(ClangFrontendTimer); + SourceManager &SM = PP.getSourceManager(); + // Start lexing the specified input file. + Lexer RawLex(SM.getMainFileID(), SM, PP.getLangOptions()); + RawLex.SetKeepWhitespaceMode(true); + + Token RawTok; + RawLex.LexFromRawLexer(RawTok); + while (RawTok.isNot(tok::eof)) { + PP.DumpToken(RawTok, true); + fprintf(stderr, "\n"); + RawLex.LexFromRawLexer(RawTok); + } + ClearSourceMgr = true; + break; + } + + case DumpTokens: { llvm::TimeRegion Timer(ClangFrontendTimer); Token Tok; - // Start parsing the specified input file. + // Start preprocessing the specified input file. PP.EnterMainSourceFile(); do { PP.Lex(Tok); + PP.DumpToken(Tok, true); + fprintf(stderr, "\n"); } while (Tok.isNot(tok::eof)); ClearSourceMgr = true; break; } + case GeneratePTH: { + llvm::TimeRegion Timer(ClangFrontendTimer); + CacheTokens(PP, static_cast<llvm::raw_fd_ostream*>(OS.get())); + ClearSourceMgr = true; + break; + } + case ParseNoop: { llvm::TimeRegion Timer(ClangFrontendTimer); ParseFile(PP, new MinimalAction(PP)); @@ -890,11 +868,45 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, break; } + case ParsePrintCallbacks: { + llvm::TimeRegion Timer(ClangFrontendTimer); + ParseFile(PP, CreatePrintParserActionsAction(PP, OS.get())); + ClearSourceMgr = true; + break; + } + case PrintPreprocessedInput: { llvm::TimeRegion Timer(ClangFrontendTimer); DoPrintPreprocessedInput(PP, OS.get(), CompOpts.getPreprocessorOutputOpts()); ClearSourceMgr = true; + break; + } + + case RewriteMacros: { + llvm::TimeRegion Timer(ClangFrontendTimer); + RewriteMacrosInInput(PP, OS.get()); + ClearSourceMgr = true; + break; + } + + case RewriteTest: { + llvm::TimeRegion Timer(ClangFrontendTimer); + DoRewriteTest(PP, OS.get()); + ClearSourceMgr = true; + break; + } + + case RunPreprocessorOnly: { // Just lex as fast as we can, no output. + llvm::TimeRegion Timer(ClangFrontendTimer); + Token Tok; + // Start parsing the specified input file. + PP.EnterMainSourceFile(); + do { + PP.Lex(Tok); + } while (Tok.isNot(tok::eof)); + ClearSourceMgr = true; + break; } } |

