diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-07-20 20:18:03 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-07-20 20:18:03 +0000 |
commit | af82e3510b768f2f194eaebdea5924f4f506caed (patch) | |
tree | 4524c67f4cc442ffcd2c01f312243cf1f591c4c0 /clang/lib/Frontend/FrontendActions.cpp | |
parent | 14d74d649aba2ec3fe0d9a1fb7718d26053eeade (diff) | |
download | bcm5719-llvm-af82e3510b768f2f194eaebdea5924f4f506caed.tar.gz bcm5719-llvm-af82e3510b768f2f194eaebdea5924f4f506caed.zip |
Introduce a new lexer function to compute the "preamble" of a file,
which is the part of the file that contains all of the initial
comments, includes, and preprocessor directives that occur before any
of the actual code. Added a new -print-preamble cc1 action that is
only used for testing.
llvm-svn: 108913
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 3a53dee8061..4db9c11ee31 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -19,6 +19,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/Utils.h" #include "llvm/ADT/OwningPtr.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -192,3 +193,32 @@ void PrintPreprocessedAction::ExecuteAction() { DoPrintPreprocessedInput(CI.getPreprocessor(), OS, CI.getPreprocessorOutputOpts()); } + +void PrintPreambleAction::ExecuteAction() { + switch (getCurrentFileKind()) { + case IK_C: + case IK_CXX: + case IK_ObjC: + case IK_ObjCXX: + case IK_OpenCL: + break; + + case IK_None: + case IK_Asm: + case IK_PreprocessedC: + case IK_PreprocessedCXX: + case IK_PreprocessedObjC: + case IK_PreprocessedObjCXX: + case IK_AST: + case IK_LLVM_IR: + // We can't do anything with these. + return; + } + + llvm::MemoryBuffer *Buffer = llvm::MemoryBuffer::getFile(getCurrentFile()); + if (Buffer) { + unsigned Preamble = Lexer::ComputePreamble(Buffer); + llvm::outs().write(Buffer->getBufferStart(), Preamble); + delete Buffer; + } +} |