Dump the llvm::Module too.

This commit is contained in:
Vassil Vassilev 2013-10-09 15:28:06 +02:00 committed by sftnight
parent 308de089be
commit 082f3feab4
3 changed files with 27 additions and 5 deletions
include/cling/Interpreter
lib/Interpreter

@ -18,6 +18,7 @@ namespace clang {
}
namespace llvm {
class Module;
class raw_fd_ostream;
class raw_ostream;
}
@ -32,14 +33,18 @@ namespace cling {
llvm::OwningPtr<llvm::raw_fd_ostream> m_LookupTablesOS;
llvm::OwningPtr<llvm::raw_fd_ostream> m_IncludedFilesOS;
llvm::OwningPtr<llvm::raw_fd_ostream> m_ASTOS;
llvm::OwningPtr<llvm::raw_fd_ostream> m_LLVMModuleOS;
std::string m_LookupTablesFile;
std::string m_IncludedFilesFile;
std::string m_ASTFile;
std::string m_LLVMModuleFile;
clang::ASTContext& m_ASTContext;
llvm::Module& m_Module;
std::string m_DiffCommand;
std::string m_Name;
public:
ClangInternalState(clang::ASTContext& C, const std::string& Name);
ClangInternalState(clang::ASTContext& C, llvm::Module& M,
const std::string& Name);
~ClangInternalState();
///\Brief It is convenient the state object to be named so that can be
@ -68,6 +73,7 @@ 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);
private:
llvm::raw_fd_ostream* createOutputFile(llvm::StringRef OutFile,
std::string* TempPathName = 0,

@ -11,6 +11,7 @@
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
@ -23,8 +24,9 @@
using namespace clang;
namespace cling {
ClangInternalState::ClangInternalState(ASTContext& C, const std::string& name)
: m_ASTContext(C), m_DiffCommand("diff -u "), m_Name(name) {
ClangInternalState::ClangInternalState(ASTContext& C, llvm::Module& M,
const std::string& name)
: m_ASTContext(C), m_Module(M), m_DiffCommand("diff -u "), m_Name(name) {
store();
}
@ -33,17 +35,20 @@ namespace cling {
remove(m_LookupTablesFile.c_str());
remove(m_IncludedFilesFile.c_str());
remove(m_ASTFile.c_str());
remove(m_LLVMModuleFile.c_str());
}
void ClangInternalState::store() {
m_LookupTablesOS.reset(createOutputFile("lookup", &m_LookupTablesFile));
m_IncludedFilesOS.reset(createOutputFile("included", &m_IncludedFilesFile));
m_ASTOS.reset(createOutputFile("ast", &m_ASTFile));
m_LLVMModuleOS.reset(createOutputFile("module", &m_LLVMModuleFile));
printLookupTables(*m_LookupTablesOS.get(), m_ASTContext);
printIncludedFiles(*m_IncludedFilesOS.get(),
m_ASTContext.getSourceManager());
printAST(*m_ASTOS.get(), m_ASTContext);
printLLVMModule(*m_LLVMModuleOS.get(), m_Module);
}
namespace {
std::string getCurrentTimeAsString() {
@ -117,6 +122,12 @@ namespace cling {
llvm::errs() << differences << "\n";
differences = "";
}
if (differentContent(m_LLVMModuleFile, other.m_LLVMModuleFile, differences)){
llvm::errs() << "Differences in the llvm Module \n";
llvm::errs() << differences << "\n";
differences = "";
}
}
bool ClangInternalState::differentContent(const std::string& file1,
@ -177,4 +188,9 @@ namespace cling {
TU->print(Out, policy, Indentation, PrintInstantiation);
Out.flush();
}
void ClangInternalState::printLLVMModule(llvm::raw_ostream& Out,
llvm::Module& M) {
M.print(Out, /*AssemblyAnnotationWriter*/ 0);
}
} // end namespace cling

@ -315,7 +315,7 @@ namespace cling {
// This may induce deserialization
PushTransactionRAII RAII(this);
ClangInternalState* state
= new ClangInternalState(getCI()->getASTContext(), name);
= new ClangInternalState(getCI()->getASTContext(), *getModule(), name);
m_StoredStates.push_back(state);
}
@ -325,7 +325,7 @@ namespace cling {
ClangInternalState state(getCI()->getASTContext(), *getModule(), name);
for (unsigned i = 0, e = m_StoredStates.size(); i != e; ++i) {
if (m_StoredStates[i]->getName() == name) {
state->compare(*m_StoredStates[i]);
m_StoredStates[i]->compare(state);
m_StoredStates.erase(m_StoredStates.begin() + i);
break;
}