Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 1 | //===--- FrontendActions.cpp ----------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Frontend/FrontendActions.h" |
| 11 | #include "clang/AST/ASTConsumer.h" |
Daniel Dunbar | c72cc50 | 2010-06-11 20:10:12 +0000 | [diff] [blame] | 12 | #include "clang/Lex/Pragma.h" |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 13 | #include "clang/Lex/Preprocessor.h" |
| 14 | #include "clang/Parse/Parser.h" |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 15 | #include "clang/Basic/FileManager.h" |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 16 | #include "clang/Frontend/ASTConsumers.h" |
| 17 | #include "clang/Frontend/ASTUnit.h" |
| 18 | #include "clang/Frontend/CompilerInstance.h" |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/FrontendDiagnostic.h" |
| 20 | #include "clang/Frontend/Utils.h" |
Sebastian Redl | 7faa2ec | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 21 | #include "clang/Serialization/ASTWriter.h" |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/OwningPtr.h" |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MemoryBuffer.h" |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 10efbaf | 2011-09-23 23:43:36 +0000 | [diff] [blame] | 25 | #include "llvm/Support/system_error.h" |
| 26 | |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 29 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 30 | // Custom Actions |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | |
| 33 | ASTConsumer *InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 34 | StringRef InFile) { |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 35 | return new ASTConsumer(); |
| 36 | } |
| 37 | |
| 38 | void InitOnlyAction::ExecuteAction() { |
| 39 | } |
| 40 | |
| 41 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 42 | // AST Consumer Actions |
| 43 | //===----------------------------------------------------------------------===// |
| 44 | |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 45 | ASTConsumer *ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 46 | StringRef InFile) { |
| 47 | if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile)) |
Daniel Dunbar | 3604359 | 2009-12-03 09:13:30 +0000 | [diff] [blame] | 48 | return CreateASTPrinter(OS); |
| 49 | return 0; |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 52 | ASTConsumer *ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 53 | StringRef InFile) { |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 54 | return CreateASTDumper(); |
| 55 | } |
| 56 | |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 57 | ASTConsumer *ASTDumpXMLAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 58 | StringRef InFile) { |
| 59 | raw_ostream *OS; |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 60 | if (CI.getFrontendOpts().OutputFile.empty()) |
| 61 | OS = &llvm::outs(); |
| 62 | else |
| 63 | OS = CI.createDefaultOutputFile(false, InFile); |
| 64 | if (!OS) return 0; |
| 65 | return CreateASTDumperXML(*OS); |
| 66 | } |
| 67 | |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 68 | ASTConsumer *ASTViewAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 69 | StringRef InFile) { |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 70 | return CreateASTViewer(); |
| 71 | } |
| 72 | |
| 73 | ASTConsumer *DeclContextPrintAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 74 | StringRef InFile) { |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 75 | return CreateDeclContextPrinter(); |
| 76 | } |
| 77 | |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 78 | ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 79 | StringRef InFile) { |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 80 | std::string Sysroot; |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 81 | std::string OutputFile; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 82 | raw_ostream *OS = 0; |
Douglas Gregor | 9293ba8 | 2011-08-25 22:35:51 +0000 | [diff] [blame] | 83 | if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS)) |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 84 | return 0; |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 85 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 86 | if (!CI.getFrontendOpts().RelocatablePCH) |
| 87 | Sysroot.clear(); |
Douglas Gregor | b8691df | 2011-11-15 21:49:36 +0000 | [diff] [blame] | 88 | return new PCHGenerator(CI.getPreprocessor(), OutputFile, /*Module=*/false, |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 89 | Sysroot, OS); |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 93 | StringRef InFile, |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 94 | std::string &Sysroot, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 95 | std::string &OutputFile, |
Douglas Gregor | 9293ba8 | 2011-08-25 22:35:51 +0000 | [diff] [blame] | 96 | raw_ostream *&OS) { |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 97 | Sysroot = CI.getHeaderSearchOpts().Sysroot; |
| 98 | if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) { |
Sebastian Redl | 11c3dc4 | 2010-08-17 17:55:38 +0000 | [diff] [blame] | 99 | CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot); |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 100 | return true; |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Daniel Dunbar | c7a9cda | 2011-01-31 22:00:44 +0000 | [diff] [blame] | 103 | // We use createOutputFile here because this is exposed via libclang, and we |
| 104 | // must disable the RemoveFileOnSignal behavior. |
Argyrios Kyrtzidis | 7e90985 | 2011-07-28 00:45:10 +0000 | [diff] [blame] | 105 | // We use a temporary to avoid race conditions. |
Daniel Dunbar | c7a9cda | 2011-01-31 22:00:44 +0000 | [diff] [blame] | 106 | OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, |
Argyrios Kyrtzidis | 7e90985 | 2011-07-28 00:45:10 +0000 | [diff] [blame] | 107 | /*RemoveFileOnSignal=*/false, InFile, |
| 108 | /*Extension=*/"", /*useTemporary=*/true); |
Daniel Dunbar | 3604359 | 2009-12-03 09:13:30 +0000 | [diff] [blame] | 109 | if (!OS) |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 110 | return true; |
Daniel Dunbar | 3604359 | 2009-12-03 09:13:30 +0000 | [diff] [blame] | 111 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 112 | OutputFile = CI.getFrontendOpts().OutputFile; |
Douglas Gregor | 1d715ac | 2010-08-03 08:14:03 +0000 | [diff] [blame] | 113 | return false; |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Douglas Gregor | b8691df | 2011-11-15 21:49:36 +0000 | [diff] [blame] | 116 | ASTConsumer *GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, |
| 117 | StringRef InFile) { |
| 118 | std::string Sysroot; |
| 119 | std::string OutputFile; |
| 120 | raw_ostream *OS = 0; |
| 121 | if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS)) |
| 122 | return 0; |
| 123 | |
| 124 | if (!CI.getFrontendOpts().RelocatablePCH) |
| 125 | Sysroot.clear(); |
| 126 | return new PCHGenerator(CI.getPreprocessor(), OutputFile, /*Module=*/true, |
| 127 | Sysroot, OS); |
| 128 | } |
| 129 | |
| 130 | bool GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI, |
| 131 | StringRef InFile, |
| 132 | std::string &Sysroot, |
| 133 | std::string &OutputFile, |
| 134 | raw_ostream *&OS) { |
| 135 | Sysroot = CI.getHeaderSearchOpts().Sysroot; |
| 136 | if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) { |
| 137 | CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot); |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | // We use createOutputFile here because this is exposed via libclang, and we |
| 142 | // must disable the RemoveFileOnSignal behavior. |
| 143 | // We use a temporary to avoid race conditions. |
| 144 | OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, |
| 145 | /*RemoveFileOnSignal=*/false, InFile, |
| 146 | /*Extension=*/"", /*useTemporary=*/true); |
| 147 | if (!OS) |
| 148 | return true; |
| 149 | |
| 150 | OutputFile = CI.getFrontendOpts().OutputFile; |
| 151 | return false; |
| 152 | } |
| 153 | |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 154 | ASTConsumer *SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 155 | StringRef InFile) { |
Daniel Dunbar | 8305d01 | 2009-11-14 10:42:46 +0000 | [diff] [blame] | 156 | return new ASTConsumer(); |
| 157 | } |
| 158 | |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 159 | //===----------------------------------------------------------------------===// |
| 160 | // Preprocessor Actions |
| 161 | //===----------------------------------------------------------------------===// |
| 162 | |
| 163 | void DumpRawTokensAction::ExecuteAction() { |
| 164 | Preprocessor &PP = getCompilerInstance().getPreprocessor(); |
| 165 | SourceManager &SM = PP.getSourceManager(); |
| 166 | |
| 167 | // Start lexing the specified input file. |
Chris Lattner | 6e29014 | 2009-11-30 04:18:44 +0000 | [diff] [blame] | 168 | const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID()); |
| 169 | Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOptions()); |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 170 | RawLex.SetKeepWhitespaceMode(true); |
| 171 | |
| 172 | Token RawTok; |
| 173 | RawLex.LexFromRawLexer(RawTok); |
| 174 | while (RawTok.isNot(tok::eof)) { |
| 175 | PP.DumpToken(RawTok, true); |
Daniel Dunbar | 33f57f8 | 2009-11-25 10:27:48 +0000 | [diff] [blame] | 176 | llvm::errs() << "\n"; |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 177 | RawLex.LexFromRawLexer(RawTok); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | void DumpTokensAction::ExecuteAction() { |
| 182 | Preprocessor &PP = getCompilerInstance().getPreprocessor(); |
| 183 | // Start preprocessing the specified input file. |
| 184 | Token Tok; |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 185 | PP.EnterMainSourceFile(); |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 186 | do { |
| 187 | PP.Lex(Tok); |
| 188 | PP.DumpToken(Tok, true); |
Daniel Dunbar | 33f57f8 | 2009-11-25 10:27:48 +0000 | [diff] [blame] | 189 | llvm::errs() << "\n"; |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 190 | } while (Tok.isNot(tok::eof)); |
| 191 | } |
| 192 | |
| 193 | void GeneratePTHAction::ExecuteAction() { |
| 194 | CompilerInstance &CI = getCompilerInstance(); |
| 195 | if (CI.getFrontendOpts().OutputFile.empty() || |
| 196 | CI.getFrontendOpts().OutputFile == "-") { |
| 197 | // FIXME: Don't fail this way. |
| 198 | // FIXME: Verify that we can actually seek in the given file. |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 199 | llvm::report_fatal_error("PTH requires a seekable file for output!"); |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 200 | } |
| 201 | llvm::raw_fd_ostream *OS = |
| 202 | CI.createDefaultOutputFile(true, getCurrentFile()); |
Daniel Dunbar | 3604359 | 2009-12-03 09:13:30 +0000 | [diff] [blame] | 203 | if (!OS) return; |
| 204 | |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 205 | CacheTokens(CI.getPreprocessor(), OS); |
| 206 | } |
| 207 | |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 208 | void PreprocessOnlyAction::ExecuteAction() { |
| 209 | Preprocessor &PP = getCompilerInstance().getPreprocessor(); |
| 210 | |
Daniel Dunbar | c72cc50 | 2010-06-11 20:10:12 +0000 | [diff] [blame] | 211 | // Ignore unknown pragmas. |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 212 | PP.AddPragmaHandler(new EmptyPragmaHandler()); |
Daniel Dunbar | c72cc50 | 2010-06-11 20:10:12 +0000 | [diff] [blame] | 213 | |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 214 | Token Tok; |
| 215 | // Start parsing the specified input file. |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 216 | PP.EnterMainSourceFile(); |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 217 | do { |
| 218 | PP.Lex(Tok); |
| 219 | } while (Tok.isNot(tok::eof)); |
| 220 | } |
| 221 | |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 222 | void PrintPreprocessedAction::ExecuteAction() { |
| 223 | CompilerInstance &CI = getCompilerInstance(); |
Douglas Gregor | 10efbaf | 2011-09-23 23:43:36 +0000 | [diff] [blame] | 224 | // Output file may need to be set to 'Binary', to avoid converting Unix style |
Steve Naroff | d57d7c0 | 2010-01-05 17:33:23 +0000 | [diff] [blame] | 225 | // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>). |
Douglas Gregor | 10efbaf | 2011-09-23 23:43:36 +0000 | [diff] [blame] | 226 | // |
| 227 | // Look to see what type of line endings the file uses. If there's a |
| 228 | // CRLF, then we won't open the file up in binary mode. If there is |
| 229 | // just an LF or CR, then we will open the file up in binary mode. |
| 230 | // In this fashion, the output format should match the input format, unless |
| 231 | // the input format has inconsistent line endings. |
| 232 | // |
| 233 | // This should be a relatively fast operation since most files won't have |
| 234 | // all of their source code on a single line. However, that is still a |
| 235 | // concern, so if we scan for too long, we'll just assume the file should |
| 236 | // be opened in binary mode. |
| 237 | bool BinaryMode = true; |
| 238 | bool InvalidFile = false; |
| 239 | const SourceManager& SM = CI.getSourceManager(); |
| 240 | const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(), |
| 241 | &InvalidFile); |
| 242 | if (!InvalidFile) { |
| 243 | const char *cur = Buffer->getBufferStart(); |
| 244 | const char *end = Buffer->getBufferEnd(); |
| 245 | const char *next = (cur != end) ? cur + 1 : end; |
| 246 | |
| 247 | // Limit ourselves to only scanning 256 characters into the source |
| 248 | // file. This is mostly a sanity check in case the file has no |
| 249 | // newlines whatsoever. |
| 250 | if (end - cur > 256) end = cur + 256; |
| 251 | |
| 252 | while (next < end) { |
| 253 | if (*cur == 0x0D) { // CR |
| 254 | if (*next == 0x0A) // CRLF |
| 255 | BinaryMode = false; |
| 256 | |
| 257 | break; |
| 258 | } else if (*cur == 0x0A) // LF |
| 259 | break; |
| 260 | |
| 261 | ++cur, ++next; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | raw_ostream *OS = CI.createDefaultOutputFile(BinaryMode, getCurrentFile()); |
Daniel Dunbar | 3604359 | 2009-12-03 09:13:30 +0000 | [diff] [blame] | 266 | if (!OS) return; |
| 267 | |
Daniel Dunbar | 5f3b997 | 2009-11-14 10:42:57 +0000 | [diff] [blame] | 268 | DoPrintPreprocessedInput(CI.getPreprocessor(), OS, |
| 269 | CI.getPreprocessorOutputOpts()); |
| 270 | } |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 271 | |
| 272 | void PrintPreambleAction::ExecuteAction() { |
| 273 | switch (getCurrentFileKind()) { |
| 274 | case IK_C: |
| 275 | case IK_CXX: |
| 276 | case IK_ObjC: |
| 277 | case IK_ObjCXX: |
| 278 | case IK_OpenCL: |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 279 | case IK_CUDA: |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 280 | break; |
| 281 | |
| 282 | case IK_None: |
| 283 | case IK_Asm: |
| 284 | case IK_PreprocessedC: |
| 285 | case IK_PreprocessedCXX: |
| 286 | case IK_PreprocessedObjC: |
| 287 | case IK_PreprocessedObjCXX: |
| 288 | case IK_AST: |
| 289 | case IK_LLVM_IR: |
| 290 | // We can't do anything with these. |
| 291 | return; |
| 292 | } |
| 293 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 294 | CompilerInstance &CI = getCompilerInstance(); |
| 295 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 296 | = CI.getFileManager().getBufferForFile(getCurrentFile()); |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 297 | if (Buffer) { |
Argyrios Kyrtzidis | 03c107a | 2011-08-25 20:39:19 +0000 | [diff] [blame] | 298 | unsigned Preamble = Lexer::ComputePreamble(Buffer, CI.getLangOpts()).first; |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 299 | llvm::outs().write(Buffer->getBufferStart(), Preamble); |
| 300 | delete Buffer; |
| 301 | } |
| 302 | } |