diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-12-13 00:37:31 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-12-13 00:37:31 +0000 |
commit | a1fa3a19bf2c4553aa7e7f27ff2a1b3b2e2db62c (patch) | |
tree | 9856024e2b91a775359a1318a6c54c81435620e8 /Driver/clang.cpp | |
parent | 4319b8437d3262981ba784486e37a768eaa643d7 (diff) |
Implemented -serialize-ast option for the driver. This is not really tested
and is a work in progress.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44967 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/clang.cpp')
-rw-r--r-- | Driver/clang.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 76cad929d1..8c08d7cadc 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -53,6 +53,7 @@ Stats("stats", llvm::cl::desc("Print performance metrics and statistics")); enum ProgActions { RewriteTest, // Rewriter testing stuff. EmitLLVM, // Emit a .ll file. + SerializeAST, // Emit a .ast file. ASTPrint, // Parse ASTs and print them. ASTDump, // Parse ASTs and dump them. ASTView, // Parse ASTs and view them in Graphviz. @@ -107,6 +108,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "Run prototype serializtion code."), clEnumValN(EmitLLVM, "emit-llvm", "Build ASTs then convert to LLVM, emit .ll file"), + clEnumValN(SerializeAST, "serialize-ast", + "Build ASTs and emit .ast file"), clEnumValN(RewriteTest, "rewrite-test", "Playground for the code rewriter"), clEnumValEnd)); @@ -816,7 +819,8 @@ static void ParseFile(Preprocessor &PP, MinimalAction *PA, unsigned MainFileID){ /// CreateASTConsumer - Create the ASTConsumer for the corresponding program /// action. These consumers can operate on both ASTs that are freshly /// parsed from source files as well as those deserialized from Bitcode. -static ASTConsumer* CreateASTConsumer(Diagnostic& Diag, FileManager& FileMgr, +static ASTConsumer* CreateASTConsumer(const std::string& InFile, + Diagnostic& Diag, FileManager& FileMgr, const LangOptions& LangOpts) { switch (ProgAction) { default: @@ -850,6 +854,21 @@ static ASTConsumer* CreateASTConsumer(Diagnostic& Diag, FileManager& FileMgr, case EmitLLVM: return CreateLLVMEmitter(Diag, LangOpts); + case SerializeAST: { + // FIXME: Allow user to tailor where the file is written. + llvm::sys::Path FName = llvm::sys::Path::GetTemporaryDirectory(NULL); + FName.appendComponent((InFile + ".ast").c_str()); + + if (FName.makeUnique(true,NULL)) { + fprintf (stderr, "error: cannot create serialized file: '%s'\n", + FName.c_str()); + + return NULL; + } + + return CreateASTSerializer(FName, Diag, LangOpts); + } + case RewriteTest: return CreateCodeRewriterTest(Diag); } @@ -869,7 +888,8 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID, switch (ProgAction) { default: - Consumer = CreateASTConsumer(PP.getDiagnostics(), HeaderInfo.getFileMgr(), + Consumer = CreateASTConsumer(InFile, PP.getDiagnostics(), + HeaderInfo.getFileMgr(), PP.getLangOptions()); if (!Consumer) { @@ -964,7 +984,8 @@ static void ProcessSerializedFile(const std::string& InFile, Diagnostic& Diag, } TranslationUnit* TU = TranslationUnit::ReadBitcodeFile(Filename,FileMgr); - ASTConsumer* Consumer = CreateASTConsumer(Diag,FileMgr,TU->getLangOpts()); + ASTConsumer* Consumer = CreateASTConsumer(InFile,Diag, + FileMgr,TU->getLangOpts()); if (!Consumer) { fprintf(stderr, "Unsupported program action with serialized ASTs!\n"); |