blob: fc687f1667511468f6742a4f6a73184c6c19b780 [file] [log] [blame]
Anton Korobeynikov74120312008-06-09 04:15:49 +00001<?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 Spencerb1254a12004-08-09 03:08:29 +00004<head>
Anton Korobeynikov74120312008-06-09 04:15:49 +00005<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Mikhail Glushenkov68319f82008-12-11 23:24:40 +00006<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
Anton Korobeynikov74120312008-06-09 04:15:49 +00007<title>Customizing LLVMC: Reference Manual</title>
Mikhail Glushenkov8cc82882008-12-13 17:50:58 +00008<link rel="stylesheet" href="llvm.css" type="text/css" />
Reid Spencerb1254a12004-08-09 03:08:29 +00009</head>
10<body>
Anton Korobeynikov74120312008-06-09 04:15:49 +000011<div class="document" id="customizing-llvmc-reference-manual">
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000012<h1 class="title">Customizing LLVMC: Reference Manual</h1>
Mikhail Glushenkov23f522a2008-12-13 17:51:47 +000013<!-- This file was automatically generated by rst2html.
14Please do not edit directly!
15The ReST source lives in the directory 'tools/llvmc/doc'. -->
Mikhail Glushenkovd5652032008-12-13 02:28:58 +000016<div class="contents topic">
17<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
18<ul class="simple">
19<li><a class="reference" href="#introduction" id="id4" name="id4">Introduction</a></li>
20<li><a class="reference" href="#compiling-with-llvmc" id="id5" name="id5">Compiling with LLVMC</a></li>
21<li><a class="reference" href="#predefined-options" id="id6" name="id6">Predefined options</a></li>
22<li><a class="reference" href="#compiling-llvmc-plugins" id="id7" name="id7">Compiling LLVMC plugins</a></li>
23<li><a class="reference" href="#customizing-llvmc-the-compilation-graph" id="id8" name="id8">Customizing LLVMC: the compilation graph</a></li>
24<li><a class="reference" href="#describing-options" id="id9" name="id9">Describing options</a><ul>
25<li><a class="reference" href="#external-options" id="id10" name="id10">External options</a></li>
26</ul>
27</li>
28<li><a class="reference" href="#conditional-evaluation" id="id11" name="id11">Conditional evaluation</a></li>
29<li><a class="reference" href="#writing-a-tool-description" id="id12" name="id12">Writing a tool description</a><ul>
30<li><a class="reference" href="#actions" id="id13" name="id13">Actions</a></li>
31</ul>
32</li>
33<li><a class="reference" href="#language-map" id="id14" name="id14">Language map</a></li>
34<li><a class="reference" href="#more-advanced-topics" id="id15" name="id15">More advanced topics</a><ul>
35<li><a class="reference" href="#hooks-and-environment-variables" id="id16" name="id16">Hooks and environment variables</a></li>
36<li><a class="reference" href="#how-plugins-are-loaded" id="id17" name="id17">How plugins are loaded</a></li>
37<li><a class="reference" href="#debugging" id="id18" name="id18">Debugging</a></li>
38</ul>
39</li>
40</ul>
41</div>
42<div class="doc_author">
43<p>Written by <a href="mailto:foldr@codedgers.com">Mikhail Glushenkov</a></p>
44</div><div class="section">
45<h1><a class="toc-backref" href="#id4" id="introduction" name="introduction">Introduction</a></h1>
Anton Korobeynikov74120312008-06-09 04:15:49 +000046<p>LLVMC is a generic compiler driver, designed to be customizable and
47extensible. It plays the same role for LLVM as the <tt class="docutils literal"><span class="pre">gcc</span></tt> program
48does for GCC - LLVMC's job is essentially to transform a set of input
49files into a set of targets depending on configuration rules and user
50options. What makes LLVMC different is that these transformation rules
51are completely customizable - in fact, LLVMC knows nothing about the
52specifics of transformation (even the command-line options are mostly
53not hard-coded) and regards the transformation structure as an
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000054abstract graph. The structure of this graph is completely determined
55by plugins, which can be either statically or dynamically linked. This
56makes it possible to easily adapt LLVMC for other purposes - for
57example, as a build tool for game resources.</p>
Mikhail Glushenkovd5652032008-12-13 02:28:58 +000058<p>Because LLVMC employs <a class="reference" href="http://llvm.cs.uiuc.edu/docs/TableGenFundamentals.html">TableGen</a> as its configuration language, you
Anton Korobeynikov74120312008-06-09 04:15:49 +000059need to be familiar with it to customize LLVMC.</p>
Reid Spencerb1254a12004-08-09 03:08:29 +000060</div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000061<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +000062<h1><a class="toc-backref" href="#id5" id="compiling-with-llvmc" name="compiling-with-llvmc">Compiling with LLVMC</a></h1>
Anton Korobeynikov74120312008-06-09 04:15:49 +000063<p>LLVMC tries hard to be as compatible with <tt class="docutils literal"><span class="pre">gcc</span></tt> as possible,
64although there are some small differences. Most of the time, however,
65you shouldn't be able to notice them:</p>
66<pre class="literal-block">
67$ # This works as expected:
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000068$ llvmc -O3 -Wall hello.cpp
Anton Korobeynikov74120312008-06-09 04:15:49 +000069$ ./a.out
70hello
71</pre>
72<p>One nice feature of LLVMC is that one doesn't have to distinguish
73between different compilers for different languages (think <tt class="docutils literal"><span class="pre">g++</span></tt> and
74<tt class="docutils literal"><span class="pre">gcc</span></tt>) - the right toolchain is chosen automatically based on input
75language names (which are, in turn, determined from file
76extensions). If you want to force files ending with &quot;.c&quot; to compile as
77C++, 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>
78<pre class="literal-block">
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000079$ # hello.c is really a C++ file
80$ llvmc -x c++ hello.c
Anton Korobeynikov74120312008-06-09 04:15:49 +000081$ ./a.out
82hello
83</pre>
84<p>On the other hand, when using LLVMC as a linker to combine several C++
85object files you should provide the <tt class="docutils literal"><span class="pre">--linker</span></tt> option since it's
86impossible for LLVMC to choose the right linker in that case:</p>
87<pre class="literal-block">
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000088$ llvmc -c hello.cpp
89$ llvmc hello.o
Anton Korobeynikov74120312008-06-09 04:15:49 +000090[A lot of link-time errors skipped]
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000091$ llvmc --linker=c++ hello.o
Anton Korobeynikov74120312008-06-09 04:15:49 +000092$ ./a.out
93hello
94</pre>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000095<p>By default, LLVMC uses <tt class="docutils literal"><span class="pre">llvm-gcc</span></tt> to compile the source code. It is
96also possible to choose the work-in-progress <tt class="docutils literal"><span class="pre">clang</span></tt> compiler with
97the <tt class="docutils literal"><span class="pre">-clang</span></tt> option.</p>
Reid Spencerb1254a12004-08-09 03:08:29 +000098</div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +000099<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000100<h1><a class="toc-backref" href="#id6" id="predefined-options" name="predefined-options">Predefined options</a></h1>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000101<p>LLVMC has some built-in options that can't be overridden in the
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000102configuration libraries:</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000103<ul class="simple">
104<li><tt class="docutils literal"><span class="pre">-o</span> <span class="pre">FILE</span></tt> - Output file name.</li>
105<li><tt class="docutils literal"><span class="pre">-x</span> <span class="pre">LANGUAGE</span></tt> - Specify the language of the following input files
106until the next -x option.</li>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000107<li><tt class="docutils literal"><span class="pre">-load</span> <span class="pre">PLUGIN_NAME</span></tt> - Load the specified plugin DLL. Example:
108<tt class="docutils literal"><span class="pre">-load</span> <span class="pre">$LLVM_DIR/Release/lib/LLVMCSimple.so</span></tt>.</li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000109<li><tt class="docutils literal"><span class="pre">-v</span></tt> - Enable verbose mode, i.e. print out all executed commands.</li>
Mikhail Glushenkovf8c430b2009-01-09 16:16:27 +0000110<li><tt class="docutils literal"><span class="pre">--check-graph</span></tt> - Check the compilation for common errors like
111mismatched output/input language names, multiple default edges and
112cycles. Hidden option, useful for debugging.</li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000113<li><tt class="docutils literal"><span class="pre">--view-graph</span></tt> - Show a graphical representation of the compilation
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000114graph. 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 Korobeynikov74120312008-06-09 04:15:49 +0000115installed. Hidden option, useful for debugging.</li>
116<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
117current directory with the compilation graph description in the
118Graphviz format. Hidden option, useful for debugging.</li>
119<li><tt class="docutils literal"><span class="pre">--save-temps</span></tt> - Write temporary files to the current directory
120and do not delete them on exit. Hidden option, useful for debugging.</li>
121<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
122their standard meaning.</li>
123</ul>
Reid Spencerb1254a12004-08-09 03:08:29 +0000124</div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000125<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000126<h1><a class="toc-backref" href="#id7" id="compiling-llvmc-plugins" name="compiling-llvmc-plugins">Compiling LLVMC plugins</a></h1>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000127<p>It's easiest to start working on your own LLVMC plugin by copying the
128skeleton project which lives under <tt class="docutils literal"><span class="pre">$LLVMC_DIR/plugins/Simple</span></tt>:</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000129<pre class="literal-block">
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000130$ cd $LLVMC_DIR/plugins
131$ cp -r Simple MyPlugin
132$ cd MyPlugin
133$ ls
134Makefile PluginMain.cpp Simple.td
Anton Korobeynikov74120312008-06-09 04:15:49 +0000135</pre>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000136<p>As you can see, our basic plugin consists of only two files (not
137counting the build script). <tt class="docutils literal"><span class="pre">Simple.td</span></tt> contains TableGen
138description of the compilation graph; its format is documented in the
139following sections. <tt class="docutils literal"><span class="pre">PluginMain.cpp</span></tt> is just a helper file used to
140compile the auto-generated C++ code produced from TableGen source. It
141can also contain hook definitions (see <a class="reference" href="#hooks">below</a>).</p>
142<p>The first thing that you should do is to change the <tt class="docutils literal"><span class="pre">LLVMC_PLUGIN</span></tt>
143variable in the <tt class="docutils literal"><span class="pre">Makefile</span></tt> to avoid conflicts (since this variable
144is used to name the resulting library):</p>
145<pre class="literal-block">
146LLVMC_PLUGIN=MyPlugin
147</pre>
148<p>It is also a good idea to rename <tt class="docutils literal"><span class="pre">Simple.td</span></tt> to something less
149generic:</p>
150<pre class="literal-block">
151$ mv Simple.td MyPlugin.td
152</pre>
153<p>Note that the plugin source directory must be placed under
154<tt class="docutils literal"><span class="pre">$LLVMC_DIR/plugins</span></tt> to make use of the existing build
155infrastructure. To build a version of the LLVMC executable called
156<tt class="docutils literal"><span class="pre">mydriver</span></tt> with your plugin compiled in, use the following command:</p>
157<pre class="literal-block">
158$ cd $LLVMC_DIR
159$ make BUILTIN_PLUGINS=MyPlugin DRIVER_NAME=mydriver
160</pre>
161<p>To build your plugin as a dynamic library, just <tt class="docutils literal"><span class="pre">cd</span></tt> to its source
162directory and run <tt class="docutils literal"><span class="pre">make</span></tt>. The resulting file will be called
163<tt class="docutils literal"><span class="pre">LLVMC$(LLVMC_PLUGIN).$(DLL_EXTENSION)</span></tt> (in our case,
164<tt class="docutils literal"><span class="pre">LLVMCMyPlugin.so</span></tt>). This library can be then loaded in with the
165<tt class="docutils literal"><span class="pre">-load</span></tt> option. Example:</p>
166<pre class="literal-block">
167$ cd $LLVMC_DIR/plugins/Simple
168$ make
169$ llvmc -load $LLVM_DIR/Release/lib/LLVMCSimple.so
170</pre>
171<p>Sometimes, you will want a 'bare-bones' version of LLVMC that has no
172built-in plugins. It can be compiled with the following command:</p>
173<pre class="literal-block">
174$ cd $LLVMC_DIR
175$ make BUILTIN_PLUGINS=&quot;&quot;
176</pre>
177</div>
178<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000179<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 Glushenkov68319f82008-12-11 23:24:40 +0000180<p>Each TableGen configuration file should include the common
181definitions:</p>
182<pre class="literal-block">
183include &quot;llvm/CompilerDriver/Common.td&quot;
184</pre>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000185<p>Internally, LLVMC stores information about possible source
186transformations in form of a graph. Nodes in this graph represent
187tools, and edges between two nodes represent a transformation path. A
188special &quot;root&quot; node is used to mark entry points for the
189transformations. LLVMC also assigns a weight to each edge (more on
190this later) to choose between several alternative edges.</p>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000191<p>The definition of the compilation graph (see file
192<tt class="docutils literal"><span class="pre">plugins/Base/Base.td</span></tt> for an example) is just a list of edges:</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000193<pre class="literal-block">
194def CompilationGraph : CompilationGraph&lt;[
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000195 Edge&lt;&quot;root&quot;, &quot;llvm_gcc_c&quot;&gt;,
196 Edge&lt;&quot;root&quot;, &quot;llvm_gcc_assembler&quot;&gt;,
Anton Korobeynikov74120312008-06-09 04:15:49 +0000197 ...
198
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000199 Edge&lt;&quot;llvm_gcc_c&quot;, &quot;llc&quot;&gt;,
200 Edge&lt;&quot;llvm_gcc_cpp&quot;, &quot;llc&quot;&gt;,
Anton Korobeynikov74120312008-06-09 04:15:49 +0000201 ...
202
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000203 OptionalEdge&lt;&quot;llvm_gcc_c&quot;, &quot;opt&quot;, (case (switch_on &quot;opt&quot;),
204 (inc_weight))&gt;,
205 OptionalEdge&lt;&quot;llvm_gcc_cpp&quot;, &quot;opt&quot;, (case (switch_on &quot;opt&quot;),
206 (inc_weight))&gt;,
Anton Korobeynikov74120312008-06-09 04:15:49 +0000207 ...
208
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000209 OptionalEdge&lt;&quot;llvm_gcc_assembler&quot;, &quot;llvm_gcc_cpp_linker&quot;,
Anton Korobeynikov74120312008-06-09 04:15:49 +0000210 (case (input_languages_contain &quot;c++&quot;), (inc_weight),
211 (or (parameter_equals &quot;linker&quot;, &quot;g++&quot;),
212 (parameter_equals &quot;linker&quot;, &quot;c++&quot;)), (inc_weight))&gt;,
213 ...
214
215 ]&gt;;
216</pre>
217<p>As you can see, the edges can be either default or optional, where
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000218optional edges are differentiated by an additional <tt class="docutils literal"><span class="pre">case</span></tt> expression
219used to calculate the weight of this edge. Notice also that we refer
220to tools via their names (as strings). This makes it possible to add
221edges to an existing compilation graph in plugins without having to
222know about all tool definitions used in the graph.</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000223<p>The default edges are assigned a weight of 1, and optional edges get a
224weight of 0 + 2*N where N is the number of tests that evaluated to
225true in the <tt class="docutils literal"><span class="pre">case</span></tt> expression. It is also possible to provide an
226integer 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,
227the weight is increased (or decreased) by the provided value instead
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000228of the default 2. It is also possible to change the default weight of
229an 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>
230construct.</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000231<p>When passing an input file through the graph, LLVMC picks the edge
232with the maximum weight. To avoid ambiguity, there should be only one
233default edge between two nodes (with the exception of the root node,
234which gets a special treatment - there you are allowed to specify one
235default edge <em>per language</em>).</p>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000236<p>When multiple plugins are loaded, their compilation graphs are merged
237together. Since multiple edges that have the same end nodes are not
238allowed (i.e. the graph is not a multigraph), an edge defined in
239several plugins will be replaced by the definition from the plugin
240that was loaded last. Plugin load order can be controlled by using the
241plugin priority feature described above.</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000242<p>To get a visual representation of the compilation graph (useful for
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000243debugging), 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 Korobeynikov74120312008-06-09 04:15:49 +0000244<tt class="docutils literal"><span class="pre">gsview</span></tt> installed for this to work properly.</p>
Reid Spencerb1254a12004-08-09 03:08:29 +0000245</div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000246<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000247<h1><a class="toc-backref" href="#id9" id="describing-options" name="describing-options">Describing options</a></h1>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000248<p>Command-line options that the plugin supports are defined by using an
249<tt class="docutils literal"><span class="pre">OptionList</span></tt>:</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000250<pre class="literal-block">
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000251def Options : OptionList&lt;[
252(switch_option &quot;E&quot;, (help &quot;Help string&quot;)),
253(alias_option &quot;quiet&quot;, &quot;q&quot;)
254...
255]&gt;;
Anton Korobeynikov74120312008-06-09 04:15:49 +0000256</pre>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000257<p>As you can see, the option list is just a list of DAGs, where each DAG
258is an option description consisting of the option name and some
259properties. A plugin can define more than one option list (they are
260all merged together in the end), which can be handy if one wants to
261separate option groups syntactically.</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000262<ul>
263<li><p class="first">Possible option types:</p>
264<blockquote>
265<ul class="simple">
Mikhail Glushenkov5303c752009-01-28 03:47:38 +0000266<li><tt class="docutils literal"><span class="pre">switch_option</span></tt> - a simple boolean switch without arguments, for example
267<tt class="docutils literal"><span class="pre">-O2</span></tt> or <tt class="docutils literal"><span class="pre">-time</span></tt>. At most one occurrence is allowed.</li>
268<li><tt class="docutils literal"><span class="pre">parameter_option</span></tt> - option that takes one argument, for example
269<tt class="docutils literal"><span class="pre">-std=c99</span></tt>. It is also allowed to use spaces instead of the equality
270sign: <tt class="docutils literal"><span class="pre">-std</span> <span class="pre">c99</span></tt>. At most one occurrence is allowed.</li>
271<li><tt class="docutils literal"><span class="pre">parameter_list_option</span></tt> - same as the above, but more than one option
272occurence is allowed.</li>
273<li><tt class="docutils literal"><span class="pre">prefix_option</span></tt> - same as the parameter_option, but the option name and
274argument do not have to be separated. Example: <tt class="docutils literal"><span class="pre">-ofile</span></tt>. This can be also
275specified as <tt class="docutils literal"><span class="pre">-o</span> <span class="pre">file</span></tt>; however, <tt class="docutils literal"><span class="pre">-o=file</span></tt> will be parsed incorrectly
276(<tt class="docutils literal"><span class="pre">=file</span></tt> will be interpreted as option value). At most one occurrence is
277allowed.</li>
278<li><tt class="docutils literal"><span class="pre">prefix_list_option</span></tt> - same as the above, but more than one occurence of
279the option is allowed; example: <tt class="docutils literal"><span class="pre">-lm</span> <span class="pre">-lpthread</span></tt>.</li>
280<li><tt class="docutils literal"><span class="pre">alias_option</span></tt> - a special option type for creating aliases. Unlike other
281option types, aliases are not allowed to have any properties besides the
282aliased option name. Usage example: <tt class="docutils literal"><span class="pre">(alias_option</span> <span class="pre">&quot;preprocess&quot;,</span> <span class="pre">&quot;E&quot;)</span></tt></li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000283</ul>
284</blockquote>
285</li>
286<li><p class="first">Possible option properties:</p>
287<blockquote>
288<ul class="simple">
Mikhail Glushenkov5303c752009-01-28 03:47:38 +0000289<li><tt class="docutils literal"><span class="pre">help</span></tt> - help string associated with this option. Used for <tt class="docutils literal"><span class="pre">--help</span></tt>
290output.</li>
291<li><tt class="docutils literal"><span class="pre">required</span></tt> - this option must be specified exactly once (or, in case of
292the list options without the <tt class="docutils literal"><span class="pre">multi_val</span></tt> property, at least
293once). Incompatible with <tt class="docutils literal"><span class="pre">zero_or_one</span></tt> and <tt class="docutils literal"><span class="pre">one_or_more</span></tt>.</li>
294<li><tt class="docutils literal"><span class="pre">one_or_more</span></tt> - the option must be specified at least one time. Useful
295only for list options in conjunction with <tt class="docutils literal"><span class="pre">multi_val</span></tt>; for ordinary lists
296it is synonymous with <tt class="docutils literal"><span class="pre">required</span></tt>. Incompatible with <tt class="docutils literal"><span class="pre">required</span></tt> and
297<tt class="docutils literal"><span class="pre">zero_or_one</span></tt>.</li>
298<li><tt class="docutils literal"><span class="pre">zero_or_one</span></tt> - the option can be specified zero or one times. Useful
299only for list options in conjunction with <tt class="docutils literal"><span class="pre">multi_val</span></tt>. Incompatible with
300<tt class="docutils literal"><span class="pre">required</span></tt> and <tt class="docutils literal"><span class="pre">one_or_more</span></tt>.</li>
Mikhail Glushenkovf9b1d792009-01-15 02:42:40 +0000301<li><tt class="docutils literal"><span class="pre">hidden</span></tt> - the description of this option will not appear in
302the <tt class="docutils literal"><span class="pre">--help</span></tt> output (but will appear in the <tt class="docutils literal"><span class="pre">--help-hidden</span></tt>
303output).</li>
304<li><tt class="docutils literal"><span class="pre">really_hidden</span></tt> - the option will not be mentioned in any help
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000305output.</li>
Mikhail Glushenkov5303c752009-01-28 03:47:38 +0000306<li><tt class="docutils literal"><span class="pre">multi_val</span> <span class="pre">n</span></tt> - this option takes <em>n</em> arguments (can be useful in some
307special cases). Usage example: <tt class="docutils literal"><span class="pre">(parameter_list_option</span> <span class="pre">&quot;foo&quot;,</span> <span class="pre">(multi_val</span>
308<span class="pre">3))</span></tt>. Only list options can have this attribute; you can, however, use
309the <tt class="docutils literal"><span class="pre">one_or_more</span></tt> and <tt class="docutils literal"><span class="pre">zero_or_one</span></tt> properties.</li>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000310<li><tt class="docutils literal"><span class="pre">extern</span></tt> - this option is defined in some other plugin, see below.</li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000311</ul>
312</blockquote>
313</li>
314</ul>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000315<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000316<h2><a class="toc-backref" href="#id10" id="external-options" name="external-options">External options</a></h2>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000317<p>Sometimes, when linking several plugins together, one plugin needs to
318access options defined in some other plugin. Because of the way
Mikhail Glushenkovf9b1d792009-01-15 02:42:40 +0000319options are implemented, such options must be marked as
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000320<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
321for. Example:</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000322<pre class="literal-block">
Anton Korobeynikov74120312008-06-09 04:15:49 +0000323...
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000324(switch_option &quot;E&quot;, (extern))
325...
Anton Korobeynikov74120312008-06-09 04:15:49 +0000326</pre>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000327<p>See also the section on plugin <a class="reference" href="#priorities">priorities</a>.</p>
Reid Spencerb1254a12004-08-09 03:08:29 +0000328</div>
Reid Spencerb1254a12004-08-09 03:08:29 +0000329</div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000330<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000331<h1><a class="toc-backref" href="#id11" id="conditional-evaluation" name="conditional-evaluation"><span id="case"></span>Conditional evaluation</a></h1>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000332<p>The 'case' construct is the main means by which programmability is
333achieved in LLVMC. It can be used to calculate edge weights, program
334actions and modify the shell commands to be executed. The 'case'
335expression is designed after the similarly-named construct in
336functional 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>
337<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
338are evaluated only if the corresponding tests evaluate to true.</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000339<p>Examples:</p>
340<pre class="literal-block">
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000341// Edge weight calculation
342
Anton Korobeynikov74120312008-06-09 04:15:49 +0000343// Increases edge weight by 5 if &quot;-A&quot; is provided on the
344// command-line, and by 5 more if &quot;-B&quot; is also provided.
345(case
346 (switch_on &quot;A&quot;), (inc_weight 5),
347 (switch_on &quot;B&quot;), (inc_weight 5))
348
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000349
350// Tool command line specification
351
352// Evaluates to &quot;cmdline1&quot; if the option &quot;-A&quot; is provided on the
353// command line; to &quot;cmdline2&quot; if &quot;-B&quot; is provided;
354// otherwise to &quot;cmdline3&quot;.
355
Anton Korobeynikov74120312008-06-09 04:15:49 +0000356(case
357 (switch_on &quot;A&quot;), &quot;cmdline1&quot;,
358 (switch_on &quot;B&quot;), &quot;cmdline2&quot;,
359 (default), &quot;cmdline3&quot;)
360</pre>
361<p>Note the slight difference in 'case' expression handling in contexts
362of edge weights and command line specification - in the second example
363the value of the <tt class="docutils literal"><span class="pre">&quot;B&quot;</span></tt> switch is never checked when switch <tt class="docutils literal"><span class="pre">&quot;A&quot;</span></tt> is
364enabled, and the whole expression always evaluates to <tt class="docutils literal"><span class="pre">&quot;cmdline1&quot;</span></tt> in
365that case.</p>
366<p>Case expressions can also be nested, i.e. the following is legal:</p>
367<pre class="literal-block">
368(case (switch_on &quot;E&quot;), (case (switch_on &quot;o&quot;), ..., (default), ...)
369 (default), ...)
370</pre>
371<p>You should, however, try to avoid doing that because it hurts
372readability. It is usually better to split tool descriptions and/or
373use TableGen inheritance instead.</p>
374<ul class="simple">
375<li>Possible tests are:<ul>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000376<li><tt class="docutils literal"><span class="pre">switch_on</span></tt> - Returns true if a given command-line switch is
377provided by the user. Example: <tt class="docutils literal"><span class="pre">(switch_on</span> <span class="pre">&quot;opt&quot;)</span></tt>.</li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000378<li><tt class="docutils literal"><span class="pre">parameter_equals</span></tt> - Returns true if a command-line parameter equals
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000379a given value.
380Example: <tt class="docutils literal"><span class="pre">(parameter_equals</span> <span class="pre">&quot;W&quot;,</span> <span class="pre">&quot;all&quot;)</span></tt>.</li>
381<li><tt class="docutils literal"><span class="pre">element_in_list</span></tt> - Returns true if a command-line parameter
382list contains a given value.
383Example: <tt class="docutils literal"><span class="pre">(parameter_in_list</span> <span class="pre">&quot;l&quot;,</span> <span class="pre">&quot;pthread&quot;)</span></tt>.</li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000384<li><tt class="docutils literal"><span class="pre">input_languages_contain</span></tt> - Returns true if a given language
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000385belongs to the current input language set.
386Example: <tt class="docutils literal"><span class="pre">(input_languages_contain</span> <span class="pre">&quot;c++&quot;)</span></tt>.</li>
387<li><tt class="docutils literal"><span class="pre">in_language</span></tt> - Evaluates to true if the input file language
388equals to the argument. At the moment works only with <tt class="docutils literal"><span class="pre">cmd_line</span></tt>
389and <tt class="docutils literal"><span class="pre">actions</span></tt> (on non-join nodes).
390Example: <tt class="docutils literal"><span class="pre">(in_language</span> <span class="pre">&quot;c++&quot;)</span></tt>.</li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000391<li><tt class="docutils literal"><span class="pre">not_empty</span></tt> - Returns true if a given option (which should be
392either a parameter or a parameter list) is set by the
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000393user.
394Example: <tt class="docutils literal"><span class="pre">(not_empty</span> <span class="pre">&quot;o&quot;)</span></tt>.</li>
Mikhail Glushenkov2d0484c2008-12-17 02:47:30 +0000395<li><tt class="docutils literal"><span class="pre">empty</span></tt> - The opposite of <tt class="docutils literal"><span class="pre">not_empty</span></tt>. Equivalent to <tt class="docutils literal"><span class="pre">(not</span> <span class="pre">(not_empty</span>
396<span class="pre">X))</span></tt>. Provided for convenience.</li>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000397<li><tt class="docutils literal"><span class="pre">default</span></tt> - Always evaluates to true. Should always be the last
398test in the <tt class="docutils literal"><span class="pre">case</span></tt> expression.</li>
399<li><tt class="docutils literal"><span class="pre">and</span></tt> - A standard logical combinator that returns true iff all
400of its arguments return true. Used like this: <tt class="docutils literal"><span class="pre">(and</span> <span class="pre">(test1),</span>
401<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,
402but not encouraged.</li>
403<li><tt class="docutils literal"><span class="pre">or</span></tt> - Another logical combinator that returns true only if any
404one of its arguments returns true. Example: <tt class="docutils literal"><span class="pre">(or</span> <span class="pre">(test1),</span>
405<span class="pre">(test2),</span> <span class="pre">...</span> <span class="pre">(testN))</span></tt>.</li>
406</ul>
407</li>
408</ul>
Reid Spencer46d21922004-08-22 18:06:59 +0000409</div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000410<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000411<h1><a class="toc-backref" href="#id12" id="writing-a-tool-description" name="writing-a-tool-description">Writing a tool description</a></h1>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000412<p>As was said earlier, nodes in the compilation graph represent tools,
413which are described separately. A tool definition looks like this
414(taken from the <tt class="docutils literal"><span class="pre">include/llvm/CompilerDriver/Tools.td</span></tt> file):</p>
415<pre class="literal-block">
416def llvm_gcc_cpp : Tool&lt;[
417 (in_language &quot;c++&quot;),
418 (out_language &quot;llvm-assembler&quot;),
419 (output_suffix &quot;bc&quot;),
420 (cmd_line &quot;llvm-g++ -c $INFILE -o $OUTFILE -emit-llvm&quot;),
421 (sink)
422 ]&gt;;
423</pre>
424<p>This defines a new tool called <tt class="docutils literal"><span class="pre">llvm_gcc_cpp</span></tt>, which is an alias for
425<tt class="docutils literal"><span class="pre">llvm-g++</span></tt>. As you can see, a tool definition is just a list of
426properties; most of them should be self-explanatory. The <tt class="docutils literal"><span class="pre">sink</span></tt>
427property means that this tool should be passed all command-line
428options that aren't mentioned in the option list.</p>
429<p>The complete list of all currently implemented tool properties follows.</p>
430<ul class="simple">
431<li>Possible tool properties:<ul>
432<li><tt class="docutils literal"><span class="pre">in_language</span></tt> - input language name. Can be either a string or a
433list, in case the tool supports multiple input languages.</li>
434<li><tt class="docutils literal"><span class="pre">out_language</span></tt> - output language name. Tools are not allowed to
435have multiple output languages.</li>
436<li><tt class="docutils literal"><span class="pre">output_suffix</span></tt> - output file suffix. Can also be changed
437dynamically, see documentation on actions.</li>
438<li><tt class="docutils literal"><span class="pre">cmd_line</span></tt> - the actual command used to run the tool. You can
439use <tt class="docutils literal"><span class="pre">$INFILE</span></tt> and <tt class="docutils literal"><span class="pre">$OUTFILE</span></tt> variables, output redirection
440with <tt class="docutils literal"><span class="pre">&gt;</span></tt>, hook invocations (<tt class="docutils literal"><span class="pre">$CALL</span></tt>), environment variables
441(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>
442<li><tt class="docutils literal"><span class="pre">join</span></tt> - this tool is a &quot;join node&quot; in the graph, i.e. it gets a
443list of input files and joins them together. Used for linkers.</li>
444<li><tt class="docutils literal"><span class="pre">sink</span></tt> - all command-line options that are not handled by other
445tools are passed to this tool.</li>
446<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
447this tool reacts on command-line options (described in more detail
448below).</li>
449</ul>
450</li>
451</ul>
452<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000453<h2><a class="toc-backref" href="#id13" id="actions" name="actions">Actions</a></h2>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000454<p>A tool often needs to react to command-line options, and this is
455precisely what the <tt class="docutils literal"><span class="pre">actions</span></tt> property is for. The next example
456illustrates this feature:</p>
457<pre class="literal-block">
458def llvm_gcc_linker : Tool&lt;[
459 (in_language &quot;object-code&quot;),
460 (out_language &quot;executable&quot;),
461 (output_suffix &quot;out&quot;),
462 (cmd_line &quot;llvm-gcc $INFILE -o $OUTFILE&quot;),
463 (join),
464 (actions (case (not_empty &quot;L&quot;), (forward &quot;L&quot;),
465 (not_empty &quot;l&quot;), (forward &quot;l&quot;),
466 (not_empty &quot;dummy&quot;),
467 [(append_cmd &quot;-dummy1&quot;), (append_cmd &quot;-dummy2&quot;)])
468 ]&gt;;
469</pre>
470<p>The <tt class="docutils literal"><span class="pre">actions</span></tt> tool property is implemented on top of the omnipresent
471<tt class="docutils literal"><span class="pre">case</span></tt> expression. It associates one or more different <em>actions</em>
472with given conditions - in the example, the actions are <tt class="docutils literal"><span class="pre">forward</span></tt>,
473which forwards a given option unchanged, and <tt class="docutils literal"><span class="pre">append_cmd</span></tt>, which
474appends a given string to the tool execution command. Multiple actions
475can be associated with a single condition by using a list of actions
476(used in the example to append some dummy options). The same <tt class="docutils literal"><span class="pre">case</span></tt>
477construct can also be used in the <tt class="docutils literal"><span class="pre">cmd_line</span></tt> property to modify the
478tool command line.</p>
479<p>The &quot;join&quot; property used in the example means that this tool behaves
480like a linker.</p>
481<p>The list of all possible actions follows.</p>
482<ul>
483<li><p class="first">Possible actions:</p>
484<blockquote>
485<ul class="simple">
486<li><tt class="docutils literal"><span class="pre">append_cmd</span></tt> - append a string to the tool invocation
487command.
Mikhail Glushenkov2d0484c2008-12-17 02:47:30 +0000488Example: <tt class="docutils literal"><span class="pre">(case</span> <span class="pre">(switch_on</span> <span class="pre">&quot;pthread&quot;),</span> <span class="pre">(append_cmd</span>
489<span class="pre">&quot;-lpthread&quot;))</span></tt></li>
490<li><tt class="docutils literal"><span class="pre">error`</span> <span class="pre">-</span> <span class="pre">exit</span> <span class="pre">with</span> <span class="pre">error.</span>
491<span class="pre">Example:</span> <span class="pre">``(error</span> <span class="pre">&quot;Mixing</span> <span class="pre">-c</span> <span class="pre">and</span> <span class="pre">-S</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">allowed!&quot;)</span></tt>.</li>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000492<li><tt class="docutils literal"><span class="pre">forward</span></tt> - forward an option unchanged.
493Example: <tt class="docutils literal"><span class="pre">(forward</span> <span class="pre">&quot;Wall&quot;)</span></tt>.</li>
494<li><tt class="docutils literal"><span class="pre">forward_as</span></tt> - Change the name of an option, but forward the
495argument unchanged.
496Example: <tt class="docutils literal"><span class="pre">(forward_as</span> <span class="pre">&quot;O0&quot;</span> <span class="pre">&quot;--disable-optimization&quot;)</span></tt>.</li>
497<li><tt class="docutils literal"><span class="pre">output_suffix</span></tt> - modify the output suffix of this
498tool.
499Example: <tt class="docutils literal"><span class="pre">(output_suffix</span> <span class="pre">&quot;i&quot;)</span></tt>.</li>
500<li><tt class="docutils literal"><span class="pre">stop_compilation</span></tt> - stop compilation after this tool processes
501its input. Used without arguments.</li>
502<li><tt class="docutils literal"><span class="pre">unpack_values</span></tt> - used for for splitting and forwarding
503comma-separated lists of options, e.g. <tt class="docutils literal"><span class="pre">-Wa,-foo=bar,-baz</span></tt> is
504converted to <tt class="docutils literal"><span class="pre">-foo=bar</span> <span class="pre">-baz</span></tt> and appended to the tool invocation
505command.
506Example: <tt class="docutils literal"><span class="pre">(unpack_values</span> <span class="pre">&quot;Wa,&quot;)</span></tt>.</li>
507</ul>
508</blockquote>
509</li>
510</ul>
511</div>
512</div>
513<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000514<h1><a class="toc-backref" href="#id14" id="language-map" name="language-map">Language map</a></h1>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000515<p>If you are adding support for a new language to LLVMC, you'll need to
516modify the language map, which defines mappings from file extensions
517to language names. It is used to choose the proper toolchain(s) for a
518given input file set. Language map definition looks like this:</p>
Anton Korobeynikov74120312008-06-09 04:15:49 +0000519<pre class="literal-block">
520def LanguageMap : LanguageMap&lt;
521 [LangToSuffixes&lt;&quot;c++&quot;, [&quot;cc&quot;, &quot;cp&quot;, &quot;cxx&quot;, &quot;cpp&quot;, &quot;CPP&quot;, &quot;c++&quot;, &quot;C&quot;]&gt;,
522 LangToSuffixes&lt;&quot;c&quot;, [&quot;c&quot;]&gt;,
523 ...
524 ]&gt;;
525</pre>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000526<p>For example, without those definitions the following command wouldn't work:</p>
527<pre class="literal-block">
528$ llvmc hello.cpp
529llvmc: Unknown suffix: cpp
530</pre>
531<p>The language map entries should be added only for tools that are
532linked with the root node. Since tools are not allowed to have
533multiple output languages, for nodes &quot;inside&quot; the graph the input and
534output languages should match. This is enforced at compile-time.</p>
Reid Spencer46d21922004-08-22 18:06:59 +0000535</div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000536<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000537<h1><a class="toc-backref" href="#id15" id="more-advanced-topics" name="more-advanced-topics">More advanced topics</a></h1>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000538<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000539<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 Glushenkov68319f82008-12-11 23:24:40 +0000540<p>Normally, LLVMC executes programs from the system <tt class="docutils literal"><span class="pre">PATH</span></tt>. Sometimes,
Mikhail Glushenkov5303c752009-01-28 03:47:38 +0000541this is not sufficient: for example, we may want to specify tool paths
542or names in the configuration file. This can be easily achieved via
543the hooks mechanism. To write your own hooks, just add their
544definitions to the <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
545your plugin directory. Hooks should live in the <tt class="docutils literal"><span class="pre">hooks</span></tt> namespace
546and have the signature <tt class="docutils literal"><span class="pre">std::string</span> <span class="pre">hooks::MyHookName</span> <span class="pre">([const</span> <span class="pre">char*</span>
547<span class="pre">Arg0</span> <span class="pre">[</span> <span class="pre">const</span> <span class="pre">char*</span> <span class="pre">Arg2</span> <span class="pre">[,</span> <span class="pre">...]]])</span></tt>. They can be used from the
548<tt class="docutils literal"><span class="pre">cmd_line</span></tt> tool property:</p>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000549<pre class="literal-block">
550(cmd_line &quot;$CALL(MyHook)/path/to/file -o $CALL(AnotherHook)&quot;)
551</pre>
Mikhail Glushenkov5303c752009-01-28 03:47:38 +0000552<p>To pass arguments to hooks, use the following syntax:</p>
553<pre class="literal-block">
554(cmd_line &quot;$CALL(MyHook, 'Arg1', 'Arg2', 'Arg # 3')/path/to/file -o1 -o2&quot;)
555</pre>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000556<p>It is also possible to use environment variables in the same manner:</p>
557<pre class="literal-block">
558(cmd_line &quot;$ENV(VAR1)/path/to/file -o $ENV(VAR2)&quot;)
559</pre>
560<p>To change the command line string based on user-provided options use
561the <tt class="docutils literal"><span class="pre">case</span></tt> expression (documented <a class="reference" href="#case">above</a>):</p>
562<pre class="literal-block">
563(cmd_line
564 (case
565 (switch_on &quot;E&quot;),
566 &quot;llvm-g++ -E -x c $INFILE -o $OUTFILE&quot;,
567 (default),
568 &quot;llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm&quot;))
569</pre>
570</div>
571<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000572<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 Glushenkov68319f82008-12-11 23:24:40 +0000573<p>It is possible for LLVMC plugins to depend on each other. For example,
574one can create edges between nodes defined in some other plugin. To
575make this work, however, that plugin should be loaded first. To
576achieve this, the concept of plugin priority was introduced. By
577default, every plugin has priority zero; to specify the priority
578explicitly, put the following line in your plugin's TableGen file:</p>
579<pre class="literal-block">
580def Priority : PluginPriority&lt;$PRIORITY_VALUE&gt;;
581# Where PRIORITY_VALUE is some integer &gt; 0
582</pre>
583<p>Plugins are loaded in order of their (increasing) priority, starting
584with 0. Therefore, the plugin with the highest priority value will be
585loaded last.</p>
586</div>
587<div class="section">
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000588<h2><a class="toc-backref" href="#id18" id="debugging" name="debugging">Debugging</a></h2>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000589<p>When writing LLVMC plugins, it can be useful to get a visual view of
590the resulting compilation graph. This can be achieved via the command
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000591line 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
592<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
593creates a Graphviz source file (<tt class="docutils literal"><span class="pre">compilation-graph.dot</span></tt>) in the
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000594current directory.</p>
Mikhail Glushenkovf9b1d792009-01-15 02:42:40 +0000595<p>Another useful <tt class="docutils literal"><span class="pre">llvmc</span></tt> option is <tt class="docutils literal"><span class="pre">--check-graph</span></tt>. It checks the
596compilation graph for common errors like mismatched output/input
597language names, multiple default edges and cycles. These checks can't
598be performed at compile-time because the plugins can load code
599dynamically. When invoked with <tt class="docutils literal"><span class="pre">--check-graph</span></tt>, <tt class="docutils literal"><span class="pre">llvmc</span></tt> doesn't
600perform any compilation tasks and returns the number of encountered
601errors as its status code.</p>
Mikhail Glushenkov90531542008-12-11 23:43:14 +0000602<hr />
Anton Korobeynikov28b66702008-06-09 04:17:51 +0000603<address>
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000604<a href="http://jigsaw.w3.org/css-validator/check/referer">
605<img src="http://jigsaw.w3.org/css-validator/images/vcss-blue"
606 alt="Valid CSS" /></a>
607<a href="http://validator.w3.org/check?uri=referer">
608<img src="http://www.w3.org/Icons/valid-xhtml10-blue"
609 alt="Valid XHTML 1.0 Transitional"/></a>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000610
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000611<a href="mailto:foldr@codedgers.com">Mikhail Glushenkov</a><br />
612<a href="http://llvm.org">LLVM Compiler Infrastructure</a><br />
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000613
Mikhail Glushenkov564b75a2009-01-15 02:04:54 +0000614Last modified: $Date: 2008-12-11 11:34:48 -0600 (Thu, 11 Dec 2008) $
Mikhail Glushenkovd5652032008-12-13 02:28:58 +0000615</address></div>
Mikhail Glushenkov68319f82008-12-11 23:24:40 +0000616</div>
617</div>
Reid Spencerb1254a12004-08-09 03:08:29 +0000618</body>
619</html>