[clang] bae1ada - [docs] [C++20] [Modules] Document how to import modules in clang-repl
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 24 00:15:10 PST 2024
Author: Chuanqi Xu
Date: 2024-01-24T16:14:14+08:00
New Revision: bae1adae1c7cdf3b0bd618fc9cd5af251dc901ed
URL: https://github.com/llvm/llvm-project/commit/bae1adae1c7cdf3b0bd618fc9cd5af251dc901ed
DIFF: https://github.com/llvm/llvm-project/commit/bae1adae1c7cdf3b0bd618fc9cd5af251dc901ed.diff
LOG: [docs] [C++20] [Modules] Document how to import modules in clang-repl
We support to import C++20 named modules now in in clang-repl in
https://github.com/llvm/llvm-project/commit/dd3e6c87f3f4affd17d05a4d25fa77d224a98d94.
Then we should document how can we do that.
Added:
Modified:
clang/docs/StandardCPlusPlusModules.rst
Removed:
################################################################################
diff --git a/clang/docs/StandardCPlusPlusModules.rst b/clang/docs/StandardCPlusPlusModules.rst
index 81043ff25be02ea..4e853990a7338a1 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -1213,6 +1213,45 @@ instead a real binary. There are 4 potential solutions to the problem:
$ clang-scan-deps -format=p1689 -- <path-to-compiler-executable>/clang++ -std=c++20 -resource-dir <resource-dir> mod.cppm -c -o mod.o
+Import modules with clang-repl
+==============================
+
+We're able to import C++20 named modules with clang-repl.
+
+Let's start with a simple example:
+
+.. code-block:: c++
+
+ // M.cppm
+ export module M;
+ export const char* Hello() {
+ return "Hello Interpreter for Modules!";
+ }
+
+We still need to compile the named module in ahead.
+
+.. code-block:: console
+
+ $ clang++ -std=c++20 M.cppm --precompile -o M.pcm
+ $ clang++ M.pcm -c -o M.o
+ $ clang++ -shared M.o -o libM.so
+
+Note that we need to compile the module unit into a dynamic library so that the clang-repl
+can load the object files of the module units.
+
+Then we are able to import module ``M`` in clang-repl.
+
+.. code-block:: console
+
+ $ clang-repl -Xcc=-std=c++20 -Xcc=-fprebuilt-module-path=.
+ # We need to load the dynamic library first before importing the modules.
+ clang-repl> %lib libM.so
+ clang-repl> import M;
+ clang-repl> extern "C" int printf(const char *, ...);
+ clang-repl> printf("%s\n", Hello());
+ Hello Interpreter for Modules!
+ clang-repl> %quit
+
Possible Questions
==================
More information about the cfe-commits
mailing list