From: Mikhail Glushenkov
-
-
$ mv Simple.td MyPlugin.td-
Note that the plugin source directory must be placed under -$LLVMC_DIR/plugins to make use of the existing build -infrastructure. To build a version of the LLVMC executable called -mydriver with your plugin compiled in, use the following command:
--$ cd $LLVMC_DIR -$ make BUILTIN_PLUGINS=MyPlugin DRIVER_NAME=mydriver -
To build your plugin as a dynamic library, just cd to its source directory and run make. The resulting file will be called LLVMC$(LLVMC_PLUGIN).$(DLL_EXTENSION) (in our case, @@ -172,15 +166,48 @@ $ cd $LLVMC_DIR/plugins/Simple $ make $ llvmc -load $LLVM_DIR/Release/lib/LLVMCSimple.so + +
By default, the llvmc executable consists of a driver core plus several +statically linked plugins (Base and Clang at the moment). You can +produce a standalone LLVMC-based driver executable by linking the core with your +own plugins. The recommended way to do this is by starting with the provided +Skeleton example ($LLVMC_DIR/example/Skeleton):
++$ cd $LLVMC_DIR/example/ +$ cp -r Skeleton mydriver +$ cd mydriver +$ vim Makefile +[...] +$ make ++
If you're compiling LLVM with different source and object directories, then you +must perform the following additional steps before running make:
++# LLVMC_SRC_DIR = $LLVM_SRC_DIR/tools/llvmc/ +# LLVMC_OBJ_DIR = $LLVM_OBJ_DIR/tools/llvmc/ +$ cp $LLVMC_SRC_DIR/example/mydriver/Makefile \ + $LLVMC_OBJ_DIR/example/mydriver/ +$ cd $LLVMC_OBJ_DIR/example/mydriver +$ make ++
Another way to do the same thing is by using the following command:
++$ cd $LLVMC_DIR +$ make LLVMC_BUILTIN_PLUGINS=MyPlugin LLVMC_BASED_DRIVER_NAME=mydriver ++
This works with both srcdir==objdir and srcdir != objdir, but assumes that the +plugin source directory was placed under $LLVMC_DIR/plugins.
Sometimes, you will want a 'bare-bones' version of LLVMC that has no built-in plugins. It can be compiled with the following command:
$ cd $LLVMC_DIR -$ make BUILTIN_PLUGINS="" +$ make LLVMC_BUILTIN_PLUGINS=""
Each TableGen configuration file should include the common definitions:
@@ -248,7 +275,7 @@ debugging), run llvmcgsview installed for this to work properly.
Command-line options that the plugin supports are defined by using an OptionList:
@@ -317,7 +344,7 @@ the one_or_more and <-External options
+External options
Sometimes, when linking several plugins together, one plugin needs to access options defined in some other plugin. Because of the way options are implemented, such options must be marked as @@ -332,7 +359,7 @@ for. Example:
The 'case' construct is the main means by which programmability is achieved in LLVMC. It can be used to calculate edge weights, program actions and modify the shell commands to be executed. The 'case' @@ -412,7 +439,7 @@ one of its arguments returns true. Example:
As was said earlier, nodes in the compilation graph represent tools, which are described separately. A tool definition looks like this (taken from the include/llvm/CompilerDriver/Tools.td file):
@@ -454,7 +481,7 @@ below).A tool often needs to react to command-line options, and this is precisely what the actions property is for. The next example illustrates this feature:
@@ -515,7 +542,7 @@ Example: (unpack_valuesIf you are adding support for a new language to LLVMC, you'll need to modify the language map, which defines mappings from file extensions to language names. It is used to choose the proper toolchain(s) for a @@ -538,9 +565,9 @@ multiple output languages, for nodes "inside" the graph the input and output languages should match. This is enforced at compile-time.
Normally, LLVMC executes programs from the system PATH. Sometimes, this is not sufficient: for example, we may want to specify tool paths or names in the configuration file. This can be easily achieved via @@ -573,7 +600,7 @@ the case expression (
It is possible for LLVMC plugins to depend on each other. For example, one can create edges between nodes defined in some other plugin. To make this work, however, that plugin should be loaded first. To @@ -589,7 +616,7 @@ with 0. Therefore, the plugin with the highest priority value will be loaded last.
When writing LLVMC plugins, it can be useful to get a visual view of
the resulting compilation graph. This can be achieved via the command
line option --view-graph. This command assumes that Graphviz and
diff --git a/docs/CompilerDriverTutorial.html b/docs/CompilerDriverTutorial.html
index a5780173795..897f9a9f895 100644
--- a/docs/CompilerDriverTutorial.html
+++ b/docs/CompilerDriverTutorial.html
@@ -50,21 +50,25 @@ command-line LLVMC usage, refer to the Using LLVMC to generate toolchain drivers
LLVMC plugins are written mostly using TableGen, so you need to
be familiar with it to get anything done. Start by compiling plugins/Simple/Simple.td, which is a primitive
-wrapper for gcc: Start by compiling example/Simple, which is a primitive wrapper for
+gcc: Here we link our plugin with the LLVMC core statically to form an
-executable file called mygcc. It is also possible to build our
-plugin as a standalone dynamic library; this is described in the
-reference manual. Here we link our plugin with the LLVMC core statically to form an executable
+file called mygcc. It is also possible to build our plugin as a dynamic
+library to be loaded by the llvmc executable (or any other LLVMC-based
+standalone driver); this is described in the reference manual. Contents of the file Simple.td look like this:
$ cd $LLVM_DIR/tools/llvmc
-$ make DRIVER_NAME=mygcc BUILTIN_PLUGINS=Simple
+
+ # NB: A less verbose way to compile standalone LLVMC-based drivers is
+ # described in the reference manual.
+
+$ make LLVMC_BASED_DRIVER_NAME=mygcc LLVMC_BUILTIN_PLUGINS=Simple
$ cat > hello.c
[...]
$ mygcc hello.c
$ ./hello.out
Hello
-
// Include common definitions