From: Adrian Prantl Date: Wed, 17 Aug 2016 23:14:00 +0000 (+0000) Subject: Print the module format in clang -module-file-info. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2685deaab3782525ebe2dd77f851c1809ab49e56;p=clang Print the module format in clang -module-file-info. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279005 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 88ff7e0894..d83e98fc31 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -615,14 +615,19 @@ void DumpModuleInfoAction::ExecuteAction() { llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs(); Out << "Information for module file '" << getCurrentFile() << "':\n"; + auto &FileMgr = getCompilerInstance().getFileManager(); + auto Buffer = FileMgr.getBufferForFile(getCurrentFile()); + StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer(); + bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' && + Magic[2] == 'C' && Magic[3] == 'H'); + Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n"; Preprocessor &PP = getCompilerInstance().getPreprocessor(); DumpModuleInfoListener Listener(Out); HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); ASTReader::readASTFileControlBlock( - getCurrentFile(), getCompilerInstance().getFileManager(), - getCompilerInstance().getPCHContainerReader(), + getCurrentFile(), FileMgr, getCompilerInstance().getPCHContainerReader(), /*FindModuleFileExtensions=*/true, Listener, HSOpts.ModulesValidateDiagnosticOptions); } diff --git a/test/Modules/module_file_info.m b/test/Modules/module_file_info.m index 6f32659f97..fa841b7592 100644 --- a/test/Modules/module_file_info.m +++ b/test/Modules/module_file_info.m @@ -4,10 +4,14 @@ // RUN: rm -rf %t %t-obj // RUN: %clang_cc1 -w -Wunused -fmodules -fmodule-format=raw -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t -F %S/Inputs -DBLARG -DWIBBLE=WOBBLE -fmodule-feature myfeature %s // RUN: %clang_cc1 -module-file-info %t/DependsOnModule.pcm | FileCheck %s +// RUN: %clang_cc1 -module-file-info %t/DependsOnModule.pcm | FileCheck %s --check-prefix=RAW // RUN: %clang_cc1 -w -Wunused -fmodules -fmodule-format=obj -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-obj -F %S/Inputs -DBLARG -DWIBBLE=WOBBLE -fmodule-feature myfeature %s // RUN: %clang_cc1 -module-file-info %t-obj/DependsOnModule.pcm | FileCheck %s +// RUN: %clang_cc1 -module-file-info %t-obj/DependsOnModule.pcm | FileCheck %s --check-prefix=OBJ +// RAW: Module format: raw +// OBJ: Module format: obj // CHECK: Generated by this Clang: // CHECK: Module name: DependsOnModule