From da626b392dff4a5f7b516880dda5c2cd41146667 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 14 May 2019 14:12:08 +0300 Subject: [PATCH] Teach ACLiC to build modules. ACLiC now synthesizes a modulemap with a suffix _ACLiC_dict.modulemap. The file contains the source file to be compiled and the corresponding library. The modulemap is then passed to rootcling via -fmodule-map-file= flag to avoid naming clashes with possibly existing other modulemap files. This patch teaches cling to work with the -fmodule-map-file= flag. ACLiC supports automatic inclusion of Rtypes.h (making ClassDef macro available). Modules are built in isolation and are resilient to #include of Rtypes.h at rootcling startup time. We make module Core (containing Rtypes.h) visible via a newly implemented callback. --- include/cling/Interpreter/InterpreterCallbacks.h | 3 +++ lib/Interpreter/CIFactory.cpp | 7 +++++++ lib/Interpreter/InterpreterCallbacks.cpp | 6 ++++++ lib/Interpreter/MultiplexInterpreterCallbacks.h | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/include/cling/Interpreter/InterpreterCallbacks.h b/include/cling/Interpreter/InterpreterCallbacks.h index 5100fc73..0c1a7f0a 100644 --- a/include/cling/Interpreter/InterpreterCallbacks.h +++ b/include/cling/Interpreter/InterpreterCallbacks.h @@ -110,6 +110,9 @@ namespace cling { llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, const clang::Module* /*Imported*/) {} + virtual void EnteredSubmodule(clang::Module* M, + clang::SourceLocation ImportLoc, + bool ForPragma) {} virtual bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl& RecoveryPath); diff --git a/lib/Interpreter/CIFactory.cpp b/lib/Interpreter/CIFactory.cpp index 6c5d829c..113e742b 100644 --- a/lib/Interpreter/CIFactory.cpp +++ b/lib/Interpreter/CIFactory.cpp @@ -1236,6 +1236,13 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts, PP.getTargetInfo().getTriple()); } + for (const auto& Filename : FrontendOpts.ModuleMapFiles) { + if (auto* File = FM.getFile(Filename)) + PP.getHeaderSearchInfo().loadModuleMapFile(File, /*IsSystem*/ false); + else + CI->getDiagnostics().Report(diag::err_module_map_not_found) << Filename; + } + return CI.release(); // Passes over the ownership to the caller. } diff --git a/lib/Interpreter/InterpreterCallbacks.cpp b/lib/Interpreter/InterpreterCallbacks.cpp index 2106eca2..b4087935 100644 --- a/lib/Interpreter/InterpreterCallbacks.cpp +++ b/lib/Interpreter/InterpreterCallbacks.cpp @@ -49,6 +49,12 @@ namespace cling { SearchPath, RelativePath, Imported); } + void EnteredSubmodule(clang::Module* M, + clang::SourceLocation ImportLoc, + bool ForPragma) override { + m_Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma); + } + virtual bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl& RecoveryPath) { if (m_Callbacks) diff --git a/lib/Interpreter/MultiplexInterpreterCallbacks.h b/lib/Interpreter/MultiplexInterpreterCallbacks.h index 7d2bfe0e..61b9180e 100644 --- a/lib/Interpreter/MultiplexInterpreterCallbacks.h +++ b/lib/Interpreter/MultiplexInterpreterCallbacks.h @@ -41,6 +41,12 @@ namespace cling { Imported); } + void EnteredSubmodule(clang::Module* M, clang::SourceLocation ImportLoc, + bool ForPragma) override { + for (auto&& cb : m_Callbacks) + cb->EnteredSubmodule(M, ImportLoc, ForPragma); + } + bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl& RecoveryPath) override { bool result = false;