| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 1 | <?xml version="1.0" encoding="utf-8" ?> | 
|  | 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | 
|  | 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 4 | <head> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 6 | <meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" /> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 7 | <title>Customizing LLVMC: Reference Manual</title> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 8 | <link rel="stylesheet" href="llvm-rst.css" type="text/css" /> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 9 | </head> | 
|  | 10 | <body> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 11 | <div class="document" id="customizing-llvmc-reference-manual"> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 12 | <h1 class="title">Customizing LLVMC: Reference Manual</h1> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 13 | <div class="contents topic"> | 
|  | 14 | <p class="topic-title first"><a id="contents" name="contents">Contents</a></p> | 
|  | 15 | <ul class="simple"> | 
|  | 16 | <li><a class="reference" href="#introduction" id="id4" name="id4">Introduction</a></li> | 
|  | 17 | <li><a class="reference" href="#compiling-with-llvmc" id="id5" name="id5">Compiling with LLVMC</a></li> | 
|  | 18 | <li><a class="reference" href="#predefined-options" id="id6" name="id6">Predefined options</a></li> | 
|  | 19 | <li><a class="reference" href="#compiling-llvmc-plugins" id="id7" name="id7">Compiling LLVMC plugins</a></li> | 
|  | 20 | <li><a class="reference" href="#customizing-llvmc-the-compilation-graph" id="id8" name="id8">Customizing LLVMC: the compilation graph</a></li> | 
|  | 21 | <li><a class="reference" href="#describing-options" id="id9" name="id9">Describing options</a><ul> | 
|  | 22 | <li><a class="reference" href="#external-options" id="id10" name="id10">External options</a></li> | 
|  | 23 | </ul> | 
|  | 24 | </li> | 
|  | 25 | <li><a class="reference" href="#conditional-evaluation" id="id11" name="id11">Conditional evaluation</a></li> | 
|  | 26 | <li><a class="reference" href="#writing-a-tool-description" id="id12" name="id12">Writing a tool description</a><ul> | 
|  | 27 | <li><a class="reference" href="#actions" id="id13" name="id13">Actions</a></li> | 
|  | 28 | </ul> | 
|  | 29 | </li> | 
|  | 30 | <li><a class="reference" href="#language-map" id="id14" name="id14">Language map</a></li> | 
|  | 31 | <li><a class="reference" href="#more-advanced-topics" id="id15" name="id15">More advanced topics</a><ul> | 
|  | 32 | <li><a class="reference" href="#hooks-and-environment-variables" id="id16" name="id16">Hooks and environment variables</a></li> | 
|  | 33 | <li><a class="reference" href="#how-plugins-are-loaded" id="id17" name="id17">How plugins are loaded</a></li> | 
|  | 34 | <li><a class="reference" href="#debugging" id="id18" name="id18">Debugging</a></li> | 
|  | 35 | </ul> | 
|  | 36 | </li> | 
|  | 37 | </ul> | 
|  | 38 | </div> | 
|  | 39 | <div class="doc_author"> | 
|  | 40 | <p>Written by <a href="mailto:foldr@codedgers.com">Mikhail Glushenkov</a></p> | 
|  | 41 | </div><div class="section"> | 
|  | 42 | <h1><a class="toc-backref" href="#id4" id="introduction" name="introduction">Introduction</a></h1> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 43 | <p>LLVMC is a generic compiler driver, designed to be customizable and | 
|  | 44 | extensible. It plays the same role for LLVM as the <tt class="docutils literal"><span class="pre">gcc</span></tt> program | 
|  | 45 | does for GCC - LLVMC's job is essentially to transform a set of input | 
|  | 46 | files into a set of targets depending on configuration rules and user | 
|  | 47 | options. What makes LLVMC different is that these transformation rules | 
|  | 48 | are completely customizable - in fact, LLVMC knows nothing about the | 
|  | 49 | specifics of transformation (even the command-line options are mostly | 
|  | 50 | not hard-coded) and regards the transformation structure as an | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 51 | abstract graph. The structure of this graph is completely determined | 
|  | 52 | by plugins, which can be either statically or dynamically linked. This | 
|  | 53 | makes it possible to easily adapt LLVMC for other purposes - for | 
|  | 54 | example, as a build tool for game resources.</p> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 55 | <p>Because LLVMC employs <a class="reference" href="http://llvm.cs.uiuc.edu/docs/TableGenFundamentals.html">TableGen</a> as its configuration language, you | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 56 | need to be familiar with it to customize LLVMC.</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 57 | </div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 58 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 59 | <h1><a class="toc-backref" href="#id5" id="compiling-with-llvmc" name="compiling-with-llvmc">Compiling with LLVMC</a></h1> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 60 | <p>LLVMC tries hard to be as compatible with <tt class="docutils literal"><span class="pre">gcc</span></tt> as possible, | 
|  | 61 | although there are some small differences. Most of the time, however, | 
|  | 62 | you shouldn't be able to notice them:</p> | 
|  | 63 | <pre class="literal-block"> | 
|  | 64 | $ # This works as expected: | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 65 | $ llvmc -O3 -Wall hello.cpp | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 66 | $ ./a.out | 
|  | 67 | hello | 
|  | 68 | </pre> | 
|  | 69 | <p>One nice feature of LLVMC is that one doesn't have to distinguish | 
|  | 70 | between different compilers for different languages (think <tt class="docutils literal"><span class="pre">g++</span></tt> and | 
|  | 71 | <tt class="docutils literal"><span class="pre">gcc</span></tt>) - the right toolchain is chosen automatically based on input | 
|  | 72 | language names (which are, in turn, determined from file | 
|  | 73 | extensions). If you want to force files ending with ".c" to compile as | 
|  | 74 | C++, use the <tt class="docutils literal"><span class="pre">-x</span></tt> option, just like you would do it with <tt class="docutils literal"><span class="pre">gcc</span></tt>:</p> | 
|  | 75 | <pre class="literal-block"> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 76 | $ # hello.c is really a C++ file | 
|  | 77 | $ llvmc -x c++ hello.c | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 78 | $ ./a.out | 
|  | 79 | hello | 
|  | 80 | </pre> | 
|  | 81 | <p>On the other hand, when using LLVMC as a linker to combine several C++ | 
|  | 82 | object files you should provide the <tt class="docutils literal"><span class="pre">--linker</span></tt> option since it's | 
|  | 83 | impossible for LLVMC to choose the right linker in that case:</p> | 
|  | 84 | <pre class="literal-block"> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 85 | $ llvmc -c hello.cpp | 
|  | 86 | $ llvmc hello.o | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 87 | [A lot of link-time errors skipped] | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 88 | $ llvmc --linker=c++ hello.o | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 89 | $ ./a.out | 
|  | 90 | hello | 
|  | 91 | </pre> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 92 | <p>By default, LLVMC uses <tt class="docutils literal"><span class="pre">llvm-gcc</span></tt> to compile the source code. It is | 
|  | 93 | also possible to choose the work-in-progress <tt class="docutils literal"><span class="pre">clang</span></tt> compiler with | 
|  | 94 | the <tt class="docutils literal"><span class="pre">-clang</span></tt> option.</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 95 | </div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 96 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 97 | <h1><a class="toc-backref" href="#id6" id="predefined-options" name="predefined-options">Predefined options</a></h1> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 98 | <p>LLVMC has some built-in options that can't be overridden in the | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 99 | configuration libraries:</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 100 | <ul class="simple"> | 
|  | 101 | <li><tt class="docutils literal"><span class="pre">-o</span> <span class="pre">FILE</span></tt> - Output file name.</li> | 
|  | 102 | <li><tt class="docutils literal"><span class="pre">-x</span> <span class="pre">LANGUAGE</span></tt> - Specify the language of the following input files | 
|  | 103 | until the next -x option.</li> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 104 | <li><tt class="docutils literal"><span class="pre">-load</span> <span class="pre">PLUGIN_NAME</span></tt> - Load the specified plugin DLL. Example: | 
|  | 105 | <tt class="docutils literal"><span class="pre">-load</span> <span class="pre">$LLVM_DIR/Release/lib/LLVMCSimple.so</span></tt>.</li> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 106 | <li><tt class="docutils literal"><span class="pre">-v</span></tt> - Enable verbose mode, i.e. print out all executed commands.</li> | 
|  | 107 | <li><tt class="docutils literal"><span class="pre">--view-graph</span></tt> - Show a graphical representation of the compilation | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 108 | graph. Requires that you have <tt class="docutils literal"><span class="pre">dot</span></tt> and <tt class="docutils literal"><span class="pre">gv</span></tt> programs | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 109 | installed. Hidden option, useful for debugging.</li> | 
|  | 110 | <li><tt class="docutils literal"><span class="pre">--write-graph</span></tt> - Write a <tt class="docutils literal"><span class="pre">compilation-graph.dot</span></tt> file in the | 
|  | 111 | current directory with the compilation graph description in the | 
|  | 112 | Graphviz format. Hidden option, useful for debugging.</li> | 
|  | 113 | <li><tt class="docutils literal"><span class="pre">--save-temps</span></tt> - Write temporary files to the current directory | 
|  | 114 | and do not delete them on exit. Hidden option, useful for debugging.</li> | 
|  | 115 | <li><tt class="docutils literal"><span class="pre">--help</span></tt>, <tt class="docutils literal"><span class="pre">--help-hidden</span></tt>, <tt class="docutils literal"><span class="pre">--version</span></tt> - These options have | 
|  | 116 | their standard meaning.</li> | 
|  | 117 | </ul> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 118 | </div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 119 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 120 | <h1><a class="toc-backref" href="#id7" id="compiling-llvmc-plugins" name="compiling-llvmc-plugins">Compiling LLVMC plugins</a></h1> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 121 | <p>It's easiest to start working on your own LLVMC plugin by copying the | 
|  | 122 | skeleton project which lives under <tt class="docutils literal"><span class="pre">$LLVMC_DIR/plugins/Simple</span></tt>:</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 123 | <pre class="literal-block"> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 124 | $ cd $LLVMC_DIR/plugins | 
|  | 125 | $ cp -r Simple MyPlugin | 
|  | 126 | $ cd MyPlugin | 
|  | 127 | $ ls | 
|  | 128 | Makefile PluginMain.cpp Simple.td | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 129 | </pre> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 130 | <p>As you can see, our basic plugin consists of only two files (not | 
|  | 131 | counting the build script). <tt class="docutils literal"><span class="pre">Simple.td</span></tt> contains TableGen | 
|  | 132 | description of the compilation graph; its format is documented in the | 
|  | 133 | following sections. <tt class="docutils literal"><span class="pre">PluginMain.cpp</span></tt> is just a helper file used to | 
|  | 134 | compile the auto-generated C++ code produced from TableGen source. It | 
|  | 135 | can also contain hook definitions (see <a class="reference" href="#hooks">below</a>).</p> | 
|  | 136 | <p>The first thing that you should do is to change the <tt class="docutils literal"><span class="pre">LLVMC_PLUGIN</span></tt> | 
|  | 137 | variable in the <tt class="docutils literal"><span class="pre">Makefile</span></tt> to avoid conflicts (since this variable | 
|  | 138 | is used to name the resulting library):</p> | 
|  | 139 | <pre class="literal-block"> | 
|  | 140 | LLVMC_PLUGIN=MyPlugin | 
|  | 141 | </pre> | 
|  | 142 | <p>It is also a good idea to rename <tt class="docutils literal"><span class="pre">Simple.td</span></tt> to something less | 
|  | 143 | generic:</p> | 
|  | 144 | <pre class="literal-block"> | 
|  | 145 | $ mv Simple.td MyPlugin.td | 
|  | 146 | </pre> | 
|  | 147 | <p>Note that the plugin source directory must be placed under | 
|  | 148 | <tt class="docutils literal"><span class="pre">$LLVMC_DIR/plugins</span></tt> to make use of the existing build | 
|  | 149 | infrastructure. To build a version of the LLVMC executable called | 
|  | 150 | <tt class="docutils literal"><span class="pre">mydriver</span></tt> with your plugin compiled in, use the following command:</p> | 
|  | 151 | <pre class="literal-block"> | 
|  | 152 | $ cd $LLVMC_DIR | 
|  | 153 | $ make BUILTIN_PLUGINS=MyPlugin DRIVER_NAME=mydriver | 
|  | 154 | </pre> | 
|  | 155 | <p>To build your plugin as a dynamic library, just <tt class="docutils literal"><span class="pre">cd</span></tt> to its source | 
|  | 156 | directory and run <tt class="docutils literal"><span class="pre">make</span></tt>. The resulting file will be called | 
|  | 157 | <tt class="docutils literal"><span class="pre">LLVMC$(LLVMC_PLUGIN).$(DLL_EXTENSION)</span></tt> (in our case, | 
|  | 158 | <tt class="docutils literal"><span class="pre">LLVMCMyPlugin.so</span></tt>). This library can be then loaded in with the | 
|  | 159 | <tt class="docutils literal"><span class="pre">-load</span></tt> option. Example:</p> | 
|  | 160 | <pre class="literal-block"> | 
|  | 161 | $ cd $LLVMC_DIR/plugins/Simple | 
|  | 162 | $ make | 
|  | 163 | $ llvmc -load $LLVM_DIR/Release/lib/LLVMCSimple.so | 
|  | 164 | </pre> | 
|  | 165 | <p>Sometimes, you will want a 'bare-bones' version of LLVMC that has no | 
|  | 166 | built-in plugins. It can be compiled with the following command:</p> | 
|  | 167 | <pre class="literal-block"> | 
|  | 168 | $ cd $LLVMC_DIR | 
|  | 169 | $ make BUILTIN_PLUGINS="" | 
|  | 170 | </pre> | 
|  | 171 | </div> | 
|  | 172 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 173 | <h1><a class="toc-backref" href="#id8" id="customizing-llvmc-the-compilation-graph" name="customizing-llvmc-the-compilation-graph">Customizing LLVMC: the compilation graph</a></h1> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 174 | <p>Each TableGen configuration file should include the common | 
|  | 175 | definitions:</p> | 
|  | 176 | <pre class="literal-block"> | 
|  | 177 | include "llvm/CompilerDriver/Common.td" | 
|  | 178 | </pre> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 179 | <p>Internally, LLVMC stores information about possible source | 
|  | 180 | transformations in form of a graph. Nodes in this graph represent | 
|  | 181 | tools, and edges between two nodes represent a transformation path. A | 
|  | 182 | special "root" node is used to mark entry points for the | 
|  | 183 | transformations. LLVMC also assigns a weight to each edge (more on | 
|  | 184 | this later) to choose between several alternative edges.</p> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 185 | <p>The definition of the compilation graph (see file | 
|  | 186 | <tt class="docutils literal"><span class="pre">plugins/Base/Base.td</span></tt> for an example) is just a list of edges:</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 187 | <pre class="literal-block"> | 
|  | 188 | def CompilationGraph : CompilationGraph<[ | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 189 | Edge<"root", "llvm_gcc_c">, | 
|  | 190 | Edge<"root", "llvm_gcc_assembler">, | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 191 | ... | 
|  | 192 |  | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 193 | Edge<"llvm_gcc_c", "llc">, | 
|  | 194 | Edge<"llvm_gcc_cpp", "llc">, | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 195 | ... | 
|  | 196 |  | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 197 | OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), | 
|  | 198 | (inc_weight))>, | 
|  | 199 | OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), | 
|  | 200 | (inc_weight))>, | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 201 | ... | 
|  | 202 |  | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 203 | OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker", | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 204 | (case (input_languages_contain "c++"), (inc_weight), | 
|  | 205 | (or (parameter_equals "linker", "g++"), | 
|  | 206 | (parameter_equals "linker", "c++")), (inc_weight))>, | 
|  | 207 | ... | 
|  | 208 |  | 
|  | 209 | ]>; | 
|  | 210 | </pre> | 
|  | 211 | <p>As you can see, the edges can be either default or optional, where | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 212 | optional edges are differentiated by an additional <tt class="docutils literal"><span class="pre">case</span></tt> expression | 
|  | 213 | used to calculate the weight of this edge. Notice also that we refer | 
|  | 214 | to tools via their names (as strings). This makes it possible to add | 
|  | 215 | edges to an existing compilation graph in plugins without having to | 
|  | 216 | know about all tool definitions used in the graph.</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 217 | <p>The default edges are assigned a weight of 1, and optional edges get a | 
|  | 218 | weight of 0 + 2*N where N is the number of tests that evaluated to | 
|  | 219 | true in the <tt class="docutils literal"><span class="pre">case</span></tt> expression. It is also possible to provide an | 
|  | 220 | integer parameter to <tt class="docutils literal"><span class="pre">inc_weight</span></tt> and <tt class="docutils literal"><span class="pre">dec_weight</span></tt> - in this case, | 
|  | 221 | the weight is increased (or decreased) by the provided value instead | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 222 | of the default 2. It is also possible to change the default weight of | 
|  | 223 | an optional edge by using the <tt class="docutils literal"><span class="pre">default</span></tt> clause of the <tt class="docutils literal"><span class="pre">case</span></tt> | 
|  | 224 | construct.</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 225 | <p>When passing an input file through the graph, LLVMC picks the edge | 
|  | 226 | with the maximum weight. To avoid ambiguity, there should be only one | 
|  | 227 | default edge between two nodes (with the exception of the root node, | 
|  | 228 | which gets a special treatment - there you are allowed to specify one | 
|  | 229 | default edge <em>per language</em>).</p> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 230 | <p>When multiple plugins are loaded, their compilation graphs are merged | 
|  | 231 | together. Since multiple edges that have the same end nodes are not | 
|  | 232 | allowed (i.e. the graph is not a multigraph), an edge defined in | 
|  | 233 | several plugins will be replaced by the definition from the plugin | 
|  | 234 | that was loaded last. Plugin load order can be controlled by using the | 
|  | 235 | plugin priority feature described above.</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 236 | <p>To get a visual representation of the compilation graph (useful for | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 237 | debugging), run <tt class="docutils literal"><span class="pre">llvmc</span> <span class="pre">--view-graph</span></tt>. You will need <tt class="docutils literal"><span class="pre">dot</span></tt> and | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 238 | <tt class="docutils literal"><span class="pre">gsview</span></tt> installed for this to work properly.</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 239 | </div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 240 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 241 | <h1><a class="toc-backref" href="#id9" id="describing-options" name="describing-options">Describing options</a></h1> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 242 | <p>Command-line options that the plugin supports are defined by using an | 
|  | 243 | <tt class="docutils literal"><span class="pre">OptionList</span></tt>:</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 244 | <pre class="literal-block"> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 245 | def Options : OptionList<[ | 
|  | 246 | (switch_option "E", (help "Help string")), | 
|  | 247 | (alias_option "quiet", "q") | 
|  | 248 | ... | 
|  | 249 | ]>; | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 250 | </pre> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 251 | <p>As you can see, the option list is just a list of DAGs, where each DAG | 
|  | 252 | is an option description consisting of the option name and some | 
|  | 253 | properties. A plugin can define more than one option list (they are | 
|  | 254 | all merged together in the end), which can be handy if one wants to | 
|  | 255 | separate option groups syntactically.</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 256 | <ul> | 
|  | 257 | <li><p class="first">Possible option types:</p> | 
|  | 258 | <blockquote> | 
|  | 259 | <ul class="simple"> | 
|  | 260 | <li><tt class="docutils literal"><span class="pre">switch_option</span></tt> - a simple boolean switch, for example <tt class="docutils literal"><span class="pre">-time</span></tt>.</li> | 
|  | 261 | <li><tt class="docutils literal"><span class="pre">parameter_option</span></tt> - option that takes an argument, for example | 
|  | 262 | <tt class="docutils literal"><span class="pre">-std=c99</span></tt>;</li> | 
|  | 263 | <li><tt class="docutils literal"><span class="pre">parameter_list_option</span></tt> - same as the above, but more than one | 
|  | 264 | occurence of the option is allowed.</li> | 
|  | 265 | <li><tt class="docutils literal"><span class="pre">prefix_option</span></tt> - same as the parameter_option, but the option name | 
|  | 266 | and parameter value are not separated.</li> | 
|  | 267 | <li><tt class="docutils literal"><span class="pre">prefix_list_option</span></tt> - same as the above, but more than one | 
|  | 268 | occurence of the option is allowed; example: <tt class="docutils literal"><span class="pre">-lm</span> <span class="pre">-lpthread</span></tt>.</li> | 
|  | 269 | <li><tt class="docutils literal"><span class="pre">alias_option</span></tt> - a special option type for creating | 
|  | 270 | aliases. Unlike other option types, aliases are not allowed to | 
|  | 271 | have any properties besides the aliased option name. Usage | 
|  | 272 | example: <tt class="docutils literal"><span class="pre">(alias_option</span> <span class="pre">"preprocess",</span> <span class="pre">"E")</span></tt></li> | 
|  | 273 | </ul> | 
|  | 274 | </blockquote> | 
|  | 275 | </li> | 
|  | 276 | <li><p class="first">Possible option properties:</p> | 
|  | 277 | <blockquote> | 
|  | 278 | <ul class="simple"> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 279 | <li><tt class="docutils literal"><span class="pre">help</span></tt> - help string associated with this option. Used for | 
|  | 280 | <tt class="docutils literal"><span class="pre">--help</span></tt> output.</li> | 
|  | 281 | <li><tt class="docutils literal"><span class="pre">required</span></tt> - this option is obligatory.</li> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 282 | <li><tt class="docutils literal"><span class="pre">hidden</span></tt> - this option should not appear in the <tt class="docutils literal"><span class="pre">--help</span></tt> | 
|  | 283 | output (but should appear in the <tt class="docutils literal"><span class="pre">--help-hidden</span></tt> output).</li> | 
|  | 284 | <li><tt class="docutils literal"><span class="pre">really_hidden</span></tt> - the option should not appear in any help | 
|  | 285 | output.</li> | 
|  | 286 | <li><tt class="docutils literal"><span class="pre">extern</span></tt> - this option is defined in some other plugin, see below.</li> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 287 | </ul> | 
|  | 288 | </blockquote> | 
|  | 289 | </li> | 
|  | 290 | </ul> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 291 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 292 | <h2><a class="toc-backref" href="#id10" id="external-options" name="external-options">External options</a></h2> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 293 | <p>Sometimes, when linking several plugins together, one plugin needs to | 
|  | 294 | access options defined in some other plugin. Because of the way | 
|  | 295 | options are implemented, such options should be marked as | 
|  | 296 | <tt class="docutils literal"><span class="pre">extern</span></tt>. This is what the <tt class="docutils literal"><span class="pre">extern</span></tt> option property is | 
|  | 297 | for. Example:</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 298 | <pre class="literal-block"> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 299 | ... | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 300 | (switch_option "E", (extern)) | 
|  | 301 | ... | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 302 | </pre> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 303 | <p>See also the section on plugin <a class="reference" href="#priorities">priorities</a>.</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 304 | </div> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 305 | </div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 306 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 307 | <h1><a class="toc-backref" href="#id11" id="conditional-evaluation" name="conditional-evaluation"><span id="case"></span>Conditional evaluation</a></h1> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 308 | <p>The 'case' construct is the main means by which programmability is | 
|  | 309 | achieved in LLVMC. It can be used to calculate edge weights, program | 
|  | 310 | actions and modify the shell commands to be executed. The 'case' | 
|  | 311 | expression is designed after the similarly-named construct in | 
|  | 312 | functional languages and takes the form <tt class="docutils literal"><span class="pre">(case</span> <span class="pre">(test_1),</span> <span class="pre">statement_1,</span> | 
|  | 313 | <span class="pre">(test_2),</span> <span class="pre">statement_2,</span> <span class="pre">...</span> <span class="pre">(test_N),</span> <span class="pre">statement_N)</span></tt>. The statements | 
|  | 314 | are evaluated only if the corresponding tests evaluate to true.</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 315 | <p>Examples:</p> | 
|  | 316 | <pre class="literal-block"> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 317 | // Edge weight calculation | 
|  | 318 |  | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 319 | // Increases edge weight by 5 if "-A" is provided on the | 
|  | 320 | // command-line, and by 5 more if "-B" is also provided. | 
|  | 321 | (case | 
|  | 322 | (switch_on "A"), (inc_weight 5), | 
|  | 323 | (switch_on "B"), (inc_weight 5)) | 
|  | 324 |  | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 325 |  | 
|  | 326 | // Tool command line specification | 
|  | 327 |  | 
|  | 328 | // Evaluates to "cmdline1" if the option "-A" is provided on the | 
|  | 329 | // command line; to "cmdline2" if "-B" is provided; | 
|  | 330 | // otherwise to "cmdline3". | 
|  | 331 |  | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 332 | (case | 
|  | 333 | (switch_on "A"), "cmdline1", | 
|  | 334 | (switch_on "B"), "cmdline2", | 
|  | 335 | (default), "cmdline3") | 
|  | 336 | </pre> | 
|  | 337 | <p>Note the slight difference in 'case' expression handling in contexts | 
|  | 338 | of edge weights and command line specification - in the second example | 
|  | 339 | the value of the <tt class="docutils literal"><span class="pre">"B"</span></tt> switch is never checked when switch <tt class="docutils literal"><span class="pre">"A"</span></tt> is | 
|  | 340 | enabled, and the whole expression always evaluates to <tt class="docutils literal"><span class="pre">"cmdline1"</span></tt> in | 
|  | 341 | that case.</p> | 
|  | 342 | <p>Case expressions can also be nested, i.e. the following is legal:</p> | 
|  | 343 | <pre class="literal-block"> | 
|  | 344 | (case (switch_on "E"), (case (switch_on "o"), ..., (default), ...) | 
|  | 345 | (default), ...) | 
|  | 346 | </pre> | 
|  | 347 | <p>You should, however, try to avoid doing that because it hurts | 
|  | 348 | readability. It is usually better to split tool descriptions and/or | 
|  | 349 | use TableGen inheritance instead.</p> | 
|  | 350 | <ul class="simple"> | 
|  | 351 | <li>Possible tests are:<ul> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 352 | <li><tt class="docutils literal"><span class="pre">switch_on</span></tt> - Returns true if a given command-line switch is | 
|  | 353 | provided by the user. Example: <tt class="docutils literal"><span class="pre">(switch_on</span> <span class="pre">"opt")</span></tt>.</li> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 354 | <li><tt class="docutils literal"><span class="pre">parameter_equals</span></tt> - Returns true if a command-line parameter equals | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 355 | a given value. | 
|  | 356 | Example: <tt class="docutils literal"><span class="pre">(parameter_equals</span> <span class="pre">"W",</span> <span class="pre">"all")</span></tt>.</li> | 
|  | 357 | <li><tt class="docutils literal"><span class="pre">element_in_list</span></tt> - Returns true if a command-line parameter | 
|  | 358 | list contains a given value. | 
|  | 359 | Example: <tt class="docutils literal"><span class="pre">(parameter_in_list</span> <span class="pre">"l",</span> <span class="pre">"pthread")</span></tt>.</li> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 360 | <li><tt class="docutils literal"><span class="pre">input_languages_contain</span></tt> - Returns true if a given language | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 361 | belongs to the current input language set. | 
|  | 362 | Example: <tt class="docutils literal"><span class="pre">(input_languages_contain</span> <span class="pre">"c++")</span></tt>.</li> | 
|  | 363 | <li><tt class="docutils literal"><span class="pre">in_language</span></tt> - Evaluates to true if the input file language | 
|  | 364 | equals to the argument. At the moment works only with <tt class="docutils literal"><span class="pre">cmd_line</span></tt> | 
|  | 365 | and <tt class="docutils literal"><span class="pre">actions</span></tt> (on non-join nodes). | 
|  | 366 | Example: <tt class="docutils literal"><span class="pre">(in_language</span> <span class="pre">"c++")</span></tt>.</li> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 367 | <li><tt class="docutils literal"><span class="pre">not_empty</span></tt> - Returns true if a given option (which should be | 
|  | 368 | either a parameter or a parameter list) is set by the | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 369 | user. | 
|  | 370 | Example: <tt class="docutils literal"><span class="pre">(not_empty</span> <span class="pre">"o")</span></tt>.</li> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 371 | <li><tt class="docutils literal"><span class="pre">default</span></tt> - Always evaluates to true. Should always be the last | 
|  | 372 | test in the <tt class="docutils literal"><span class="pre">case</span></tt> expression.</li> | 
|  | 373 | <li><tt class="docutils literal"><span class="pre">and</span></tt> - A standard logical combinator that returns true iff all | 
|  | 374 | of its arguments return true. Used like this: <tt class="docutils literal"><span class="pre">(and</span> <span class="pre">(test1),</span> | 
|  | 375 | <span class="pre">(test2),</span> <span class="pre">...</span> <span class="pre">(testN))</span></tt>. Nesting of <tt class="docutils literal"><span class="pre">and</span></tt> and <tt class="docutils literal"><span class="pre">or</span></tt> is allowed, | 
|  | 376 | but not encouraged.</li> | 
|  | 377 | <li><tt class="docutils literal"><span class="pre">or</span></tt> - Another logical combinator that returns true only if any | 
|  | 378 | one of its arguments returns true. Example: <tt class="docutils literal"><span class="pre">(or</span> <span class="pre">(test1),</span> | 
|  | 379 | <span class="pre">(test2),</span> <span class="pre">...</span> <span class="pre">(testN))</span></tt>.</li> | 
|  | 380 | </ul> | 
|  | 381 | </li> | 
|  | 382 | </ul> | 
| Reid Spencer | 46d2192 | 2004-08-22 18:06:59 +0000 | [diff] [blame] | 383 | </div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 384 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 385 | <h1><a class="toc-backref" href="#id12" id="writing-a-tool-description" name="writing-a-tool-description">Writing a tool description</a></h1> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 386 | <p>As was said earlier, nodes in the compilation graph represent tools, | 
|  | 387 | which are described separately. A tool definition looks like this | 
|  | 388 | (taken from the <tt class="docutils literal"><span class="pre">include/llvm/CompilerDriver/Tools.td</span></tt> file):</p> | 
|  | 389 | <pre class="literal-block"> | 
|  | 390 | def llvm_gcc_cpp : Tool<[ | 
|  | 391 | (in_language "c++"), | 
|  | 392 | (out_language "llvm-assembler"), | 
|  | 393 | (output_suffix "bc"), | 
|  | 394 | (cmd_line "llvm-g++ -c $INFILE -o $OUTFILE -emit-llvm"), | 
|  | 395 | (sink) | 
|  | 396 | ]>; | 
|  | 397 | </pre> | 
|  | 398 | <p>This defines a new tool called <tt class="docutils literal"><span class="pre">llvm_gcc_cpp</span></tt>, which is an alias for | 
|  | 399 | <tt class="docutils literal"><span class="pre">llvm-g++</span></tt>. As you can see, a tool definition is just a list of | 
|  | 400 | properties; most of them should be self-explanatory. The <tt class="docutils literal"><span class="pre">sink</span></tt> | 
|  | 401 | property means that this tool should be passed all command-line | 
|  | 402 | options that aren't mentioned in the option list.</p> | 
|  | 403 | <p>The complete list of all currently implemented tool properties follows.</p> | 
|  | 404 | <ul class="simple"> | 
|  | 405 | <li>Possible tool properties:<ul> | 
|  | 406 | <li><tt class="docutils literal"><span class="pre">in_language</span></tt> - input language name. Can be either a string or a | 
|  | 407 | list, in case the tool supports multiple input languages.</li> | 
|  | 408 | <li><tt class="docutils literal"><span class="pre">out_language</span></tt> - output language name. Tools are not allowed to | 
|  | 409 | have multiple output languages.</li> | 
|  | 410 | <li><tt class="docutils literal"><span class="pre">output_suffix</span></tt> - output file suffix. Can also be changed | 
|  | 411 | dynamically, see documentation on actions.</li> | 
|  | 412 | <li><tt class="docutils literal"><span class="pre">cmd_line</span></tt> - the actual command used to run the tool. You can | 
|  | 413 | use <tt class="docutils literal"><span class="pre">$INFILE</span></tt> and <tt class="docutils literal"><span class="pre">$OUTFILE</span></tt> variables, output redirection | 
|  | 414 | with <tt class="docutils literal"><span class="pre">></span></tt>, hook invocations (<tt class="docutils literal"><span class="pre">$CALL</span></tt>), environment variables | 
|  | 415 | (via <tt class="docutils literal"><span class="pre">$ENV</span></tt>) and the <tt class="docutils literal"><span class="pre">case</span></tt> construct.</li> | 
|  | 416 | <li><tt class="docutils literal"><span class="pre">join</span></tt> - this tool is a "join node" in the graph, i.e. it gets a | 
|  | 417 | list of input files and joins them together. Used for linkers.</li> | 
|  | 418 | <li><tt class="docutils literal"><span class="pre">sink</span></tt> - all command-line options that are not handled by other | 
|  | 419 | tools are passed to this tool.</li> | 
|  | 420 | <li><tt class="docutils literal"><span class="pre">actions</span></tt> - A single big <tt class="docutils literal"><span class="pre">case</span></tt> expression that specifies how | 
|  | 421 | this tool reacts on command-line options (described in more detail | 
|  | 422 | below).</li> | 
|  | 423 | </ul> | 
|  | 424 | </li> | 
|  | 425 | </ul> | 
|  | 426 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 427 | <h2><a class="toc-backref" href="#id13" id="actions" name="actions">Actions</a></h2> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 428 | <p>A tool often needs to react to command-line options, and this is | 
|  | 429 | precisely what the <tt class="docutils literal"><span class="pre">actions</span></tt> property is for. The next example | 
|  | 430 | illustrates this feature:</p> | 
|  | 431 | <pre class="literal-block"> | 
|  | 432 | def llvm_gcc_linker : Tool<[ | 
|  | 433 | (in_language "object-code"), | 
|  | 434 | (out_language "executable"), | 
|  | 435 | (output_suffix "out"), | 
|  | 436 | (cmd_line "llvm-gcc $INFILE -o $OUTFILE"), | 
|  | 437 | (join), | 
|  | 438 | (actions (case (not_empty "L"), (forward "L"), | 
|  | 439 | (not_empty "l"), (forward "l"), | 
|  | 440 | (not_empty "dummy"), | 
|  | 441 | [(append_cmd "-dummy1"), (append_cmd "-dummy2")]) | 
|  | 442 | ]>; | 
|  | 443 | </pre> | 
|  | 444 | <p>The <tt class="docutils literal"><span class="pre">actions</span></tt> tool property is implemented on top of the omnipresent | 
|  | 445 | <tt class="docutils literal"><span class="pre">case</span></tt> expression. It associates one or more different <em>actions</em> | 
|  | 446 | with given conditions - in the example, the actions are <tt class="docutils literal"><span class="pre">forward</span></tt>, | 
|  | 447 | which forwards a given option unchanged, and <tt class="docutils literal"><span class="pre">append_cmd</span></tt>, which | 
|  | 448 | appends a given string to the tool execution command. Multiple actions | 
|  | 449 | can be associated with a single condition by using a list of actions | 
|  | 450 | (used in the example to append some dummy options). The same <tt class="docutils literal"><span class="pre">case</span></tt> | 
|  | 451 | construct can also be used in the <tt class="docutils literal"><span class="pre">cmd_line</span></tt> property to modify the | 
|  | 452 | tool command line.</p> | 
|  | 453 | <p>The "join" property used in the example means that this tool behaves | 
|  | 454 | like a linker.</p> | 
|  | 455 | <p>The list of all possible actions follows.</p> | 
|  | 456 | <ul> | 
|  | 457 | <li><p class="first">Possible actions:</p> | 
|  | 458 | <blockquote> | 
|  | 459 | <ul class="simple"> | 
|  | 460 | <li><tt class="docutils literal"><span class="pre">append_cmd</span></tt> - append a string to the tool invocation | 
|  | 461 | command. | 
|  | 462 | Example: <tt class="docutils literal"><span class="pre">(case</span> <span class="pre">(switch_on</span> <span class="pre">"pthread"),</span> <span class="pre">(append_cmd</span> <span class="pre">"-lpthread"))</span></tt></li> | 
|  | 463 | <li><tt class="docutils literal"><span class="pre">forward</span></tt> - forward an option unchanged. | 
|  | 464 | Example: <tt class="docutils literal"><span class="pre">(forward</span> <span class="pre">"Wall")</span></tt>.</li> | 
|  | 465 | <li><tt class="docutils literal"><span class="pre">forward_as</span></tt> - Change the name of an option, but forward the | 
|  | 466 | argument unchanged. | 
|  | 467 | Example: <tt class="docutils literal"><span class="pre">(forward_as</span> <span class="pre">"O0"</span> <span class="pre">"--disable-optimization")</span></tt>.</li> | 
|  | 468 | <li><tt class="docutils literal"><span class="pre">output_suffix</span></tt> - modify the output suffix of this | 
|  | 469 | tool. | 
|  | 470 | Example: <tt class="docutils literal"><span class="pre">(output_suffix</span> <span class="pre">"i")</span></tt>.</li> | 
|  | 471 | <li><tt class="docutils literal"><span class="pre">stop_compilation</span></tt> - stop compilation after this tool processes | 
|  | 472 | its input. Used without arguments.</li> | 
|  | 473 | <li><tt class="docutils literal"><span class="pre">unpack_values</span></tt> - used for for splitting and forwarding | 
|  | 474 | comma-separated lists of options, e.g. <tt class="docutils literal"><span class="pre">-Wa,-foo=bar,-baz</span></tt> is | 
|  | 475 | converted to <tt class="docutils literal"><span class="pre">-foo=bar</span> <span class="pre">-baz</span></tt> and appended to the tool invocation | 
|  | 476 | command. | 
|  | 477 | Example: <tt class="docutils literal"><span class="pre">(unpack_values</span> <span class="pre">"Wa,")</span></tt>.</li> | 
|  | 478 | </ul> | 
|  | 479 | </blockquote> | 
|  | 480 | </li> | 
|  | 481 | </ul> | 
|  | 482 | </div> | 
|  | 483 | </div> | 
|  | 484 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 485 | <h1><a class="toc-backref" href="#id14" id="language-map" name="language-map">Language map</a></h1> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 486 | <p>If you are adding support for a new language to LLVMC, you'll need to | 
|  | 487 | modify the language map, which defines mappings from file extensions | 
|  | 488 | to language names. It is used to choose the proper toolchain(s) for a | 
|  | 489 | given input file set. Language map definition looks like this:</p> | 
| Anton Korobeynikov | 7412031 | 2008-06-09 04:15:49 +0000 | [diff] [blame] | 490 | <pre class="literal-block"> | 
|  | 491 | def LanguageMap : LanguageMap< | 
|  | 492 | [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>, | 
|  | 493 | LangToSuffixes<"c", ["c"]>, | 
|  | 494 | ... | 
|  | 495 | ]>; | 
|  | 496 | </pre> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 497 | <p>For example, without those definitions the following command wouldn't work:</p> | 
|  | 498 | <pre class="literal-block"> | 
|  | 499 | $ llvmc hello.cpp | 
|  | 500 | llvmc: Unknown suffix: cpp | 
|  | 501 | </pre> | 
|  | 502 | <p>The language map entries should be added only for tools that are | 
|  | 503 | linked with the root node. Since tools are not allowed to have | 
|  | 504 | multiple output languages, for nodes "inside" the graph the input and | 
|  | 505 | output languages should match. This is enforced at compile-time.</p> | 
| Reid Spencer | 46d2192 | 2004-08-22 18:06:59 +0000 | [diff] [blame] | 506 | </div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 507 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 508 | <h1><a class="toc-backref" href="#id15" id="more-advanced-topics" name="more-advanced-topics">More advanced topics</a></h1> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 509 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 510 | <h2><a class="toc-backref" href="#id16" id="hooks-and-environment-variables" name="hooks-and-environment-variables"><span id="hooks"></span>Hooks and environment variables</a></h2> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 511 | <p>Normally, LLVMC executes programs from the system <tt class="docutils literal"><span class="pre">PATH</span></tt>. Sometimes, | 
|  | 512 | this is not sufficient: for example, we may want to specify tool names | 
|  | 513 | in the configuration file. This can be achieved via the mechanism of | 
|  | 514 | hooks - to write your own hooks, just add their definitions to the | 
|  | 515 | <tt class="docutils literal"><span class="pre">PluginMain.cpp</span></tt> or drop a <tt class="docutils literal"><span class="pre">.cpp</span></tt> file into the | 
|  | 516 | <tt class="docutils literal"><span class="pre">$LLVMC_DIR/driver</span></tt> directory. Hooks should live in the <tt class="docutils literal"><span class="pre">hooks</span></tt> | 
|  | 517 | namespace and have the signature <tt class="docutils literal"><span class="pre">std::string</span> <span class="pre">hooks::MyHookName</span> | 
|  | 518 | <span class="pre">(void)</span></tt>. They can be used from the <tt class="docutils literal"><span class="pre">cmd_line</span></tt> tool property:</p> | 
|  | 519 | <pre class="literal-block"> | 
|  | 520 | (cmd_line "$CALL(MyHook)/path/to/file -o $CALL(AnotherHook)") | 
|  | 521 | </pre> | 
|  | 522 | <p>It is also possible to use environment variables in the same manner:</p> | 
|  | 523 | <pre class="literal-block"> | 
|  | 524 | (cmd_line "$ENV(VAR1)/path/to/file -o $ENV(VAR2)") | 
|  | 525 | </pre> | 
|  | 526 | <p>To change the command line string based on user-provided options use | 
|  | 527 | the <tt class="docutils literal"><span class="pre">case</span></tt> expression (documented <a class="reference" href="#case">above</a>):</p> | 
|  | 528 | <pre class="literal-block"> | 
|  | 529 | (cmd_line | 
|  | 530 | (case | 
|  | 531 | (switch_on "E"), | 
|  | 532 | "llvm-g++ -E -x c $INFILE -o $OUTFILE", | 
|  | 533 | (default), | 
|  | 534 | "llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm")) | 
|  | 535 | </pre> | 
|  | 536 | </div> | 
|  | 537 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 538 | <h2><a class="toc-backref" href="#id17" id="how-plugins-are-loaded" name="how-plugins-are-loaded"><span id="priorities"></span>How plugins are loaded</a></h2> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 539 | <p>It is possible for LLVMC plugins to depend on each other. For example, | 
|  | 540 | one can create edges between nodes defined in some other plugin. To | 
|  | 541 | make this work, however, that plugin should be loaded first. To | 
|  | 542 | achieve this, the concept of plugin priority was introduced. By | 
|  | 543 | default, every plugin has priority zero; to specify the priority | 
|  | 544 | explicitly, put the following line in your plugin's TableGen file:</p> | 
|  | 545 | <pre class="literal-block"> | 
|  | 546 | def Priority : PluginPriority<$PRIORITY_VALUE>; | 
|  | 547 | # Where PRIORITY_VALUE is some integer > 0 | 
|  | 548 | </pre> | 
|  | 549 | <p>Plugins are loaded in order of their (increasing) priority, starting | 
|  | 550 | with 0. Therefore, the plugin with the highest priority value will be | 
|  | 551 | loaded last.</p> | 
|  | 552 | </div> | 
|  | 553 | <div class="section"> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 554 | <h2><a class="toc-backref" href="#id18" id="debugging" name="debugging">Debugging</a></h2> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 555 | <p>When writing LLVMC plugins, it can be useful to get a visual view of | 
|  | 556 | the resulting compilation graph. This can be achieved via the command | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 557 | line option <tt class="docutils literal"><span class="pre">--view-graph</span></tt>. This command assumes that <a class="reference" href="http://www.graphviz.org/">Graphviz</a> and | 
|  | 558 | <a class="reference" href="http://pages.cs.wisc.edu/~ghost/">Ghostview</a> are installed. There is also a <tt class="docutils literal"><span class="pre">--dump-graph</span></tt> option that | 
|  | 559 | creates a Graphviz source file (<tt class="docutils literal"><span class="pre">compilation-graph.dot</span></tt>) in the | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 560 | current directory.</p> | 
| Mikhail Glushenkov | 9053154 | 2008-12-11 23:43:14 +0000 | [diff] [blame] | 561 | <hr /> | 
| Anton Korobeynikov | 28b6670 | 2008-06-09 04:17:51 +0000 | [diff] [blame] | 562 | <address> | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 563 | <a href="http://jigsaw.w3.org/css-validator/check/referer"> | 
|  | 564 | <img src="http://jigsaw.w3.org/css-validator/images/vcss-blue" | 
|  | 565 | alt="Valid CSS" /></a> | 
|  | 566 | <a href="http://validator.w3.org/check?uri=referer"> | 
|  | 567 | <img src="http://www.w3.org/Icons/valid-xhtml10-blue" | 
|  | 568 | alt="Valid XHTML 1.0 Transitional"/></a> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 569 |  | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 570 | <a href="mailto:foldr@codedgers.com">Mikhail Glushenkov</a><br /> | 
|  | 571 | <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br /> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 572 |  | 
| Mikhail Glushenkov | d565203 | 2008-12-13 02:28:58 +0000 | [diff] [blame^] | 573 | Last modified: $Date: 2008-12-11 11:34:48 -0600 (Thu, 11 Dec 2008) $ | 
|  | 574 | </address></div> | 
| Mikhail Glushenkov | 68319f8 | 2008-12-11 23:24:40 +0000 | [diff] [blame] | 575 | </div> | 
|  | 576 | </div> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 577 | </body> | 
|  | 578 | </html> |