diff --git a/include/cling/Interpreter/ClangInternalState.h b/include/cling/Interpreter/ClangInternalState.h index 8e47f218..2f9c74cf 100644 --- a/include/cling/Interpreter/ClangInternalState.h +++ b/include/cling/Interpreter/ClangInternalState.h @@ -18,6 +18,7 @@ namespace clang { class ASTContext; + class CodeGenerator; class SourceManager; class Preprocessor; } @@ -42,6 +43,7 @@ namespace cling { std::string m_MacrosFile; clang::ASTContext& m_ASTContext; clang::Preprocessor& m_Preprocessor; + clang::CodeGenerator* m_CodeGen; llvm::Module* m_Module; std::string m_DiffCommand; std::string m_Name; @@ -50,7 +52,8 @@ namespace cling { llvm::OwningPtr m_DiffPair; public: ClangInternalState(clang::ASTContext& AC, clang::Preprocessor& PP, - llvm::Module* M, const std::string& name); + llvm::Module* M, clang::CodeGenerator* CG, + const std::string& name); ~ClangInternalState(); ///\brief It is convenient the state object to be named so that can be @@ -81,7 +84,8 @@ namespace cling { static void printIncludedFiles(llvm::raw_ostream& Out, clang::SourceManager& SM); static void printAST(llvm::raw_ostream& Out, clang::ASTContext& C); - static void printLLVMModule(llvm::raw_ostream& Out, llvm::Module& M); + static void printLLVMModule(llvm::raw_ostream& Out, llvm::Module& M, + clang::CodeGenerator& CG); static void printMacroDefinitions(llvm::raw_ostream& Out, clang::Preprocessor& PP); private: diff --git a/lib/Interpreter/ClangInternalState.cpp b/lib/Interpreter/ClangInternalState.cpp index 3b851b81..147f45c2 100644 --- a/lib/Interpreter/ClangInternalState.cpp +++ b/lib/Interpreter/ClangInternalState.cpp @@ -14,6 +14,7 @@ #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/SourceManager.h" +#include "clang/CodeGen/ModuleBuilder.h" #include "llvm/ADT/SmallString.h" #include "llvm/IR/Module.h" @@ -37,9 +38,9 @@ using namespace clang; namespace cling { ClangInternalState::ClangInternalState(ASTContext& AC, Preprocessor& PP, - llvm::Module* M, + llvm::Module* M, CodeGenerator* CG, const std::string& name) - : m_ASTContext(AC), m_Preprocessor(PP), m_Module(M), + : m_ASTContext(AC), m_Preprocessor(PP), m_Module(M), m_CodeGen(CG), m_DiffCommand("diff -u --text "), m_Name(name), m_DiffPair(0) { store(); } @@ -74,7 +75,7 @@ namespace cling { m_ASTContext.getSourceManager()); printAST(*m_ASTOS.get(), m_ASTContext); if (m_Module) - printLLVMModule(*m_LLVMModuleOS.get(), *m_Module); + printLLVMModule(*m_LLVMModuleOS.get(), *m_Module, *m_CodeGen); printMacroDefinitions(*m_MacrosOS.get(), m_Preprocessor); } namespace { @@ -131,7 +132,7 @@ namespace cling { void ClangInternalState::compare(const std::string& name) { assert(name == m_Name && "Different names!?"); m_DiffPair.reset(new ClangInternalState(m_ASTContext, m_Preprocessor, - m_Module, name)); + m_Module, m_CodeGen, name)); std::string differences = ""; // Ignore the builtins typedef llvm::SmallVector Builtins; @@ -165,6 +166,7 @@ namespace cling { differences = ""; } if (m_Module) { + assert(m_CodeGen && "Must have CodeGen set"); // We want to skip the intrinsics builtinNames.clear(); for (llvm::Module::const_iterator I = m_Module->begin(), @@ -277,8 +279,10 @@ namespace cling { } void ClangInternalState::printLLVMModule(llvm::raw_ostream& Out, - llvm::Module& M) { + llvm::Module& M, + CodeGenerator& CG) { M.print(Out, /*AssemblyAnnotationWriter*/ 0); + CG.print(Out); } void ClangInternalState::printMacroDefinitions(llvm::raw_ostream& Out, diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index d0982455..1267e25c 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -310,7 +310,8 @@ namespace cling { PushTransactionRAII RAII(this); ClangInternalState* state = new ClangInternalState(getCI()->getASTContext(), - getCI()->getPreprocessor(), getModule(), name); + getCI()->getPreprocessor(), getModule(), + getCodeGenerator(), name); m_StoredStates.push_back(state); }