#include "../Test.h" #include #include namespace { using namespace clice; TEST(clice, ModuleScanner) { using namespace clang::tooling::dependencies; DependencyScanningService service(ScanningMode::DependencyDirectivesScan, ScanningOutputFormat::P1689); DependencyScanningTool tool(service); foreachFile("ModuleScanner", [&](std::string file, llvm::StringRef content) { clang::tooling::CompileCommand command; command.Filename = file; command.CommandLine = {"clang++", "-std=c++20", file}; auto rule = tool.getP1689ModuleDependencyFile(command, "CWD"); if(rule) { llvm::outs() << "Module: " << rule->Provides->ModuleName << "\n"; llvm::outs() << "Module: " << rule->Provides->IsStdCXXModuleInterface << "\n"; for(auto& info: rule->Requires) { llvm::outs() << info.ModuleName << " -> " << info.SourcePath << "\n"; } } }); } TEST(clice, PCH) { const char* code = R"( #include int main(){ printf("Hello world"); return 0; } )"; std::vector compileArgs = { "clang++", "-std=c++20", "main.cpp", "-resource-dir", "/home/ykiko/C++/clice2/build/lib/clang/20", }; Compiler compiler; compiler.buildPCH("main.cpp", code, compileArgs); auto invocation = createInvocation("main.cpp", code, compileArgs); compiler.applyPCH(*invocation, "main.cpp", code, "/home/ykiko/C++/clice2/build/cache/xxx.pch"); auto instance = createInstance(std::move(invocation)); auto action = std::make_unique(); if(!action->BeginSourceFile(*instance, instance->getFrontendOpts().Inputs[0])) { llvm::errs() << "Failed to begin source file\n"; std::terminate(); } if(auto error = action->Execute()) { llvm::errs() << "Failed to execute action: " << error << "\n"; std::terminate(); } instance->getASTContext().getTranslationUnitDecl()->dump(); } TEST(clice, PCM) { const char* mod = R"( export module M; export constexpr int f() { return 42; } )"; const char* code = R"( import M; int main() { constexpr int x = f(); return x; } )"; std::vector compileArgs = { "clang++", "-std=c++20", "main.cpp", "-resource-dir", "/home/ykiko/C++/clice2/build/lib/clang/20", }; Compiler compiler; compiler.buildPCM("main.cpp", mod, compileArgs); auto invocation = createInvocation("main.cpp", code, compileArgs); // compiler.applyPCH(*invocation, "main.cpp", code, "/home/ykiko/C++/clice2/build/cache/xxx.pch"); invocation->getHeaderSearchOpts().PrebuiltModuleFiles.emplace("M", "/home/ykiko/C++/clice2/build/cache/xxx.pcm"); auto instance = createInstance(std::move(invocation)); auto action = std::make_unique(); if(!action->BeginSourceFile(*instance, instance->getFrontendOpts().Inputs[0])) { llvm::errs() << "Failed to begin source file\n"; std::terminate(); } if(auto error = action->Execute()) { llvm::errs() << "Failed to execute action: " << error << "\n"; std::terminate(); } instance->getASTContext().getTranslationUnitDecl()->dump(); } } // namespace