blob: 5c4e447ef5fd2d63f452f89c2e6baeb9e4228bba [file] [log] [blame]
Daniel Dunbar8305d012009-11-14 10:42:46 +00001//===--- 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"
Douglas Gregordb1cde72011-11-16 00:09:06 +000012#include "clang/Lex/HeaderSearch.h"
Daniel Dunbarc72cc502010-06-11 20:10:12 +000013#include "clang/Lex/Pragma.h"
Daniel Dunbar5f3b9972009-11-14 10:42:57 +000014#include "clang/Lex/Preprocessor.h"
15#include "clang/Parse/Parser.h"
Daniel Dunbar8305d012009-11-14 10:42:46 +000016#include "clang/Basic/FileManager.h"
Daniel Dunbar8305d012009-11-14 10:42:46 +000017#include "clang/Frontend/ASTConsumers.h"
18#include "clang/Frontend/ASTUnit.h"
19#include "clang/Frontend/CompilerInstance.h"
Daniel Dunbar8305d012009-11-14 10:42:46 +000020#include "clang/Frontend/FrontendDiagnostic.h"
21#include "clang/Frontend/Utils.h"
Sebastian Redl7faa2ec2010-08-18 23:56:37 +000022#include "clang/Serialization/ASTWriter.h"
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +000023#include "llvm/ADT/OwningPtr.h"
Douglas Gregorf033f1d2010-07-20 20:18:03 +000024#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbar8305d012009-11-14 10:42:46 +000025#include "llvm/Support/raw_ostream.h"
Douglas Gregor10efbaf2011-09-23 23:43:36 +000026#include "llvm/Support/system_error.h"
27
Daniel Dunbar8305d012009-11-14 10:42:46 +000028using namespace clang;
29
Daniel Dunbar5f3b9972009-11-14 10:42:57 +000030//===----------------------------------------------------------------------===//
Daniel Dunbar27585952010-03-19 19:44:04 +000031// Custom Actions
32//===----------------------------------------------------------------------===//
33
34ASTConsumer *InitOnlyAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000035 StringRef InFile) {
Daniel Dunbar27585952010-03-19 19:44:04 +000036 return new ASTConsumer();
37}
38
39void InitOnlyAction::ExecuteAction() {
40}
41
42//===----------------------------------------------------------------------===//
Daniel Dunbar5f3b9972009-11-14 10:42:57 +000043// AST Consumer Actions
44//===----------------------------------------------------------------------===//
45
Daniel Dunbar8305d012009-11-14 10:42:46 +000046ASTConsumer *ASTPrintAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000047 StringRef InFile) {
48 if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile))
Daniel Dunbar36043592009-12-03 09:13:30 +000049 return CreateASTPrinter(OS);
50 return 0;
Daniel Dunbar8305d012009-11-14 10:42:46 +000051}
52
Daniel Dunbar8305d012009-11-14 10:42:46 +000053ASTConsumer *ASTDumpAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000054 StringRef InFile) {
Daniel Dunbar8305d012009-11-14 10:42:46 +000055 return CreateASTDumper();
56}
57
John McCallf3514242010-11-24 11:21:45 +000058ASTConsumer *ASTDumpXMLAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000059 StringRef InFile) {
60 raw_ostream *OS;
John McCallf3514242010-11-24 11:21:45 +000061 if (CI.getFrontendOpts().OutputFile.empty())
62 OS = &llvm::outs();
63 else
64 OS = CI.createDefaultOutputFile(false, InFile);
65 if (!OS) return 0;
66 return CreateASTDumperXML(*OS);
67}
68
Daniel Dunbar8305d012009-11-14 10:42:46 +000069ASTConsumer *ASTViewAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000070 StringRef InFile) {
Daniel Dunbar8305d012009-11-14 10:42:46 +000071 return CreateASTViewer();
72}
73
74ASTConsumer *DeclContextPrintAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000075 StringRef InFile) {
Daniel Dunbar8305d012009-11-14 10:42:46 +000076 return CreateDeclContextPrinter();
77}
78
Daniel Dunbar8305d012009-11-14 10:42:46 +000079ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000080 StringRef InFile) {
Douglas Gregor1d715ac2010-08-03 08:14:03 +000081 std::string Sysroot;
Argyrios Kyrtzidis8e3df4d2011-02-15 17:54:22 +000082 std::string OutputFile;
Chris Lattner5f9e2722011-07-23 10:55:15 +000083 raw_ostream *OS = 0;
Douglas Gregor9293ba82011-08-25 22:35:51 +000084 if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS))
Daniel Dunbar8305d012009-11-14 10:42:46 +000085 return 0;
Douglas Gregor1d715ac2010-08-03 08:14:03 +000086
Douglas Gregor832d6202011-07-22 16:35:34 +000087 if (!CI.getFrontendOpts().RelocatablePCH)
88 Sysroot.clear();
Douglas Gregora8cc6ce2011-11-30 04:39:39 +000089 return new PCHGenerator(CI.getPreprocessor(), OutputFile, 0, Sysroot, OS);
Douglas Gregor1d715ac2010-08-03 08:14:03 +000090}
91
92bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000093 StringRef InFile,
Douglas Gregor1d715ac2010-08-03 08:14:03 +000094 std::string &Sysroot,
Argyrios Kyrtzidis8e3df4d2011-02-15 17:54:22 +000095 std::string &OutputFile,
Douglas Gregor9293ba82011-08-25 22:35:51 +000096 raw_ostream *&OS) {
Douglas Gregor1d715ac2010-08-03 08:14:03 +000097 Sysroot = CI.getHeaderSearchOpts().Sysroot;
98 if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
Sebastian Redl11c3dc42010-08-17 17:55:38 +000099 CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
Douglas Gregor1d715ac2010-08-03 08:14:03 +0000100 return true;
Daniel Dunbar8305d012009-11-14 10:42:46 +0000101 }
102
Daniel Dunbarc7a9cda2011-01-31 22:00:44 +0000103 // We use createOutputFile here because this is exposed via libclang, and we
104 // must disable the RemoveFileOnSignal behavior.
Argyrios Kyrtzidis7e909852011-07-28 00:45:10 +0000105 // We use a temporary to avoid race conditions.
Daniel Dunbarc7a9cda2011-01-31 22:00:44 +0000106 OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
Argyrios Kyrtzidis7e909852011-07-28 00:45:10 +0000107 /*RemoveFileOnSignal=*/false, InFile,
108 /*Extension=*/"", /*useTemporary=*/true);
Daniel Dunbar36043592009-12-03 09:13:30 +0000109 if (!OS)
Douglas Gregor1d715ac2010-08-03 08:14:03 +0000110 return true;
Daniel Dunbar36043592009-12-03 09:13:30 +0000111
Argyrios Kyrtzidis8e3df4d2011-02-15 17:54:22 +0000112 OutputFile = CI.getFrontendOpts().OutputFile;
Douglas Gregor1d715ac2010-08-03 08:14:03 +0000113 return false;
Daniel Dunbar8305d012009-11-14 10:42:46 +0000114}
115
Douglas Gregordb1cde72011-11-16 00:09:06 +0000116ASTConsumer *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
Douglas Gregora8cc6ce2011-11-30 04:39:39 +0000124 return new PCHGenerator(CI.getPreprocessor(), OutputFile, Module,
Douglas Gregordb1cde72011-11-16 00:09:06 +0000125 Sysroot, OS);
126}
127
Douglas Gregor261e75b2011-11-16 17:04:00 +0000128/// \brief Collect the set of header includes needed to construct the given
129/// module.
130///
131/// \param Module The module we're collecting includes from.
132/// \param ExplicitOnly Whether we should only add headers from explicit
133static void collectModuleHeaderIncludes(const LangOptions &LangOpts,
Douglas Gregor1a4761e2011-11-30 23:21:26 +0000134 clang::Module *Module,
Douglas Gregor261e75b2011-11-16 17:04:00 +0000135 bool ExplicitOnly,
136 llvm::SmallString<256> &Includes) {
137 if (!ExplicitOnly || Module->IsExplicit) {
138 // Add includes for each of these headers.
139 for (unsigned I = 0, N = Module->Headers.size(); I != N; ++I) {
140 if (LangOpts.ObjC1)
141 Includes += "#import \"";
142 else
143 Includes += "#include \"";
144 Includes += Module->Headers[I]->getName();
145 Includes += "\"\n";
146 }
147 }
148
149 // Recurse into submodules.
Douglas Gregor1a4761e2011-11-30 23:21:26 +0000150 for (llvm::StringMap<clang::Module *>::iterator
Douglas Gregor261e75b2011-11-16 17:04:00 +0000151 Sub = Module->SubModules.begin(),
152 SubEnd = Module->SubModules.end();
153 Sub != SubEnd; ++Sub) {
154 collectModuleHeaderIncludes(LangOpts, Sub->getValue(),
155 ExplicitOnly && !Module->IsExplicit,
156 Includes);
157 }
158}
159
Douglas Gregordb1cde72011-11-16 00:09:06 +0000160bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI,
161 StringRef Filename) {
162 // Find the module map file.
163 const FileEntry *ModuleMap = CI.getFileManager().getFile(Filename);
164 if (!ModuleMap) {
165 CI.getDiagnostics().Report(diag::err_module_map_not_found)
166 << Filename;
167 return false;
168 }
169
170 // Parse the module map file.
171 HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
172 if (HS.loadModuleMapFile(ModuleMap))
173 return false;
174
175 if (CI.getLangOpts().CurrentModule.empty()) {
176 CI.getDiagnostics().Report(diag::err_missing_module_name);
177
178 // FIXME: Eventually, we could consider asking whether there was just
179 // a single module described in the module map, and use that as a
180 // default. Then it would be fairly trivial to just "compile" a module
181 // map with a single module (the common case).
182 return false;
183 }
184
185 // Dig out the module definition.
Douglas Gregora8cc6ce2011-11-30 04:39:39 +0000186 Module = HS.getModule(CI.getLangOpts().CurrentModule, /*AllowSearch=*/false);
Douglas Gregordb1cde72011-11-16 00:09:06 +0000187 if (!Module) {
188 CI.getDiagnostics().Report(diag::err_missing_module)
189 << CI.getLangOpts().CurrentModule << Filename;
190
191 return false;
192 }
193
Douglas Gregor261e75b2011-11-16 17:04:00 +0000194 // Collect the set of #includes we need to build the module.
195 llvm::SmallString<256> HeaderContents;
196 collectModuleHeaderIncludes(CI.getLangOpts(), Module,
197 Module->UmbrellaHeader != 0, HeaderContents);
198 if (Module->UmbrellaHeader && HeaderContents.empty()) {
199 // Simple case: we have an umbrella header and there are no additional
200 // includes, we can just parse the umbrella header directly.
Douglas Gregordb1cde72011-11-16 00:09:06 +0000201 setCurrentFile(Module->UmbrellaHeader->getName(), getCurrentFileKind());
Douglas Gregor261e75b2011-11-16 17:04:00 +0000202 return true;
Douglas Gregordb1cde72011-11-16 00:09:06 +0000203 }
204
Douglas Gregor261e75b2011-11-16 17:04:00 +0000205 FileManager &FileMgr = CI.getFileManager();
206 llvm::SmallString<128> HeaderName;
207 time_t ModTime;
208 if (Module->UmbrellaHeader) {
209 // Read in the umbrella header.
210 // FIXME: Go through the source manager; the umbrella header may have
211 // been overridden.
212 std::string ErrorStr;
213 llvm::MemoryBuffer *UmbrellaContents
214 = FileMgr.getBufferForFile(Module->UmbrellaHeader, &ErrorStr);
215 if (!UmbrellaContents) {
216 CI.getDiagnostics().Report(diag::err_missing_umbrella_header)
217 << Module->UmbrellaHeader->getName() << ErrorStr;
218 return false;
219 }
220
221 // Combine the contents of the umbrella header with the automatically-
222 // generated includes.
223 llvm::SmallString<256> OldContents = HeaderContents;
224 HeaderContents = UmbrellaContents->getBuffer();
225 HeaderContents += "\n\n";
226 HeaderContents += "/* Module includes */\n";
227 HeaderContents += OldContents;
228
229 // Pretend that we're parsing the umbrella header.
230 HeaderName = Module->UmbrellaHeader->getName();
231 ModTime = Module->UmbrellaHeader->getModificationTime();
232
233 delete UmbrellaContents;
234 } else {
235 // Pick an innocuous-sounding name for the umbrella header.
236 HeaderName = Module->Name + ".h";
237 if (FileMgr.getFile(HeaderName, /*OpenFile=*/false,
238 /*CacheFailure=*/false)) {
239 // Try again!
240 HeaderName = Module->Name + "-module.h";
241 if (FileMgr.getFile(HeaderName, /*OpenFile=*/false,
242 /*CacheFailure=*/false)) {
243 // Pick something ridiculous and go with it.
244 HeaderName = Module->Name + "-module.hmod";
245 }
246 }
247 ModTime = time(0);
248 }
249
250 // Remap the contents of the header name we're using to our synthesized
251 // buffer.
252 const FileEntry *HeaderFile = FileMgr.getVirtualFile(HeaderName,
253 HeaderContents.size(),
254 ModTime);
255 llvm::MemoryBuffer *HeaderContentsBuf
256 = llvm::MemoryBuffer::getMemBufferCopy(HeaderContents);
257 CI.getSourceManager().overrideFileContents(HeaderFile, HeaderContentsBuf);
258
259 setCurrentFile(HeaderName, getCurrentFileKind());
Douglas Gregordb1cde72011-11-16 00:09:06 +0000260 return true;
261}
262
263bool GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI,
264 StringRef InFile,
265 std::string &Sysroot,
266 std::string &OutputFile,
267 raw_ostream *&OS) {
268 // If no output file was provided, figure out where this module would go
269 // in the module cache.
270 if (CI.getFrontendOpts().OutputFile.empty()) {
271 HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
272 llvm::SmallString<256> ModuleFileName(HS.getModuleCachePath());
273 llvm::sys::path::append(ModuleFileName,
274 CI.getLangOpts().CurrentModule + ".pcm");
275 CI.getFrontendOpts().OutputFile = ModuleFileName.str();
276 }
277
278 // We use createOutputFile here because this is exposed via libclang, and we
279 // must disable the RemoveFileOnSignal behavior.
280 // We use a temporary to avoid race conditions.
281 OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
282 /*RemoveFileOnSignal=*/false, InFile,
283 /*Extension=*/"", /*useTemporary=*/true);
284 if (!OS)
285 return true;
286
287 OutputFile = CI.getFrontendOpts().OutputFile;
288 return false;
289}
290
Daniel Dunbar8305d012009-11-14 10:42:46 +0000291ASTConsumer *SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000292 StringRef InFile) {
Daniel Dunbar8305d012009-11-14 10:42:46 +0000293 return new ASTConsumer();
294}
295
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000296//===----------------------------------------------------------------------===//
297// Preprocessor Actions
298//===----------------------------------------------------------------------===//
299
300void DumpRawTokensAction::ExecuteAction() {
301 Preprocessor &PP = getCompilerInstance().getPreprocessor();
302 SourceManager &SM = PP.getSourceManager();
303
304 // Start lexing the specified input file.
Chris Lattner6e290142009-11-30 04:18:44 +0000305 const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
306 Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOptions());
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000307 RawLex.SetKeepWhitespaceMode(true);
308
309 Token RawTok;
310 RawLex.LexFromRawLexer(RawTok);
311 while (RawTok.isNot(tok::eof)) {
312 PP.DumpToken(RawTok, true);
Daniel Dunbar33f57f82009-11-25 10:27:48 +0000313 llvm::errs() << "\n";
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000314 RawLex.LexFromRawLexer(RawTok);
315 }
316}
317
318void DumpTokensAction::ExecuteAction() {
319 Preprocessor &PP = getCompilerInstance().getPreprocessor();
320 // Start preprocessing the specified input file.
321 Token Tok;
Chris Lattnere127a0d2010-04-20 20:35:58 +0000322 PP.EnterMainSourceFile();
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000323 do {
324 PP.Lex(Tok);
325 PP.DumpToken(Tok, true);
Daniel Dunbar33f57f82009-11-25 10:27:48 +0000326 llvm::errs() << "\n";
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000327 } while (Tok.isNot(tok::eof));
328}
329
330void GeneratePTHAction::ExecuteAction() {
331 CompilerInstance &CI = getCompilerInstance();
332 if (CI.getFrontendOpts().OutputFile.empty() ||
333 CI.getFrontendOpts().OutputFile == "-") {
334 // FIXME: Don't fail this way.
335 // FIXME: Verify that we can actually seek in the given file.
Chris Lattner83e7a782010-04-07 22:58:06 +0000336 llvm::report_fatal_error("PTH requires a seekable file for output!");
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000337 }
338 llvm::raw_fd_ostream *OS =
339 CI.createDefaultOutputFile(true, getCurrentFile());
Daniel Dunbar36043592009-12-03 09:13:30 +0000340 if (!OS) return;
341
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000342 CacheTokens(CI.getPreprocessor(), OS);
343}
344
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000345void PreprocessOnlyAction::ExecuteAction() {
346 Preprocessor &PP = getCompilerInstance().getPreprocessor();
347
Daniel Dunbarc72cc502010-06-11 20:10:12 +0000348 // Ignore unknown pragmas.
Argyrios Kyrtzidis9b36c3f2010-07-13 09:07:17 +0000349 PP.AddPragmaHandler(new EmptyPragmaHandler());
Daniel Dunbarc72cc502010-06-11 20:10:12 +0000350
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000351 Token Tok;
352 // Start parsing the specified input file.
Chris Lattnere127a0d2010-04-20 20:35:58 +0000353 PP.EnterMainSourceFile();
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000354 do {
355 PP.Lex(Tok);
356 } while (Tok.isNot(tok::eof));
357}
358
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000359void PrintPreprocessedAction::ExecuteAction() {
360 CompilerInstance &CI = getCompilerInstance();
Douglas Gregor10efbaf2011-09-23 23:43:36 +0000361 // Output file may need to be set to 'Binary', to avoid converting Unix style
Steve Naroffd57d7c02010-01-05 17:33:23 +0000362 // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>).
Douglas Gregor10efbaf2011-09-23 23:43:36 +0000363 //
364 // Look to see what type of line endings the file uses. If there's a
365 // CRLF, then we won't open the file up in binary mode. If there is
366 // just an LF or CR, then we will open the file up in binary mode.
367 // In this fashion, the output format should match the input format, unless
368 // the input format has inconsistent line endings.
369 //
370 // This should be a relatively fast operation since most files won't have
371 // all of their source code on a single line. However, that is still a
372 // concern, so if we scan for too long, we'll just assume the file should
373 // be opened in binary mode.
374 bool BinaryMode = true;
375 bool InvalidFile = false;
376 const SourceManager& SM = CI.getSourceManager();
377 const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
378 &InvalidFile);
379 if (!InvalidFile) {
380 const char *cur = Buffer->getBufferStart();
381 const char *end = Buffer->getBufferEnd();
382 const char *next = (cur != end) ? cur + 1 : end;
383
384 // Limit ourselves to only scanning 256 characters into the source
385 // file. This is mostly a sanity check in case the file has no
386 // newlines whatsoever.
387 if (end - cur > 256) end = cur + 256;
388
389 while (next < end) {
390 if (*cur == 0x0D) { // CR
391 if (*next == 0x0A) // CRLF
392 BinaryMode = false;
393
394 break;
395 } else if (*cur == 0x0A) // LF
396 break;
397
398 ++cur, ++next;
399 }
400 }
401
402 raw_ostream *OS = CI.createDefaultOutputFile(BinaryMode, getCurrentFile());
Daniel Dunbar36043592009-12-03 09:13:30 +0000403 if (!OS) return;
404
Daniel Dunbar5f3b9972009-11-14 10:42:57 +0000405 DoPrintPreprocessedInput(CI.getPreprocessor(), OS,
406 CI.getPreprocessorOutputOpts());
407}
Douglas Gregorf033f1d2010-07-20 20:18:03 +0000408
409void PrintPreambleAction::ExecuteAction() {
410 switch (getCurrentFileKind()) {
411 case IK_C:
412 case IK_CXX:
413 case IK_ObjC:
414 case IK_ObjCXX:
415 case IK_OpenCL:
Peter Collingbourne895fcca2010-12-01 03:15:20 +0000416 case IK_CUDA:
Douglas Gregorf033f1d2010-07-20 20:18:03 +0000417 break;
418
419 case IK_None:
420 case IK_Asm:
421 case IK_PreprocessedC:
422 case IK_PreprocessedCXX:
423 case IK_PreprocessedObjC:
424 case IK_PreprocessedObjCXX:
425 case IK_AST:
426 case IK_LLVM_IR:
427 // We can't do anything with these.
428 return;
429 }
430
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +0000431 CompilerInstance &CI = getCompilerInstance();
432 llvm::MemoryBuffer *Buffer
Chris Lattner39b49bc2010-11-23 08:35:12 +0000433 = CI.getFileManager().getBufferForFile(getCurrentFile());
Douglas Gregorf033f1d2010-07-20 20:18:03 +0000434 if (Buffer) {
Argyrios Kyrtzidis03c107a2011-08-25 20:39:19 +0000435 unsigned Preamble = Lexer::ComputePreamble(Buffer, CI.getLangOpts()).first;
Douglas Gregorf033f1d2010-07-20 20:18:03 +0000436 llvm::outs().write(Buffer->getBufferStart(), Preamble);
437 delete Buffer;
438 }
439}