blob: 2d7825729873bd7e4e66972baa84401a677ecd7d [file] [log] [blame]
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +00001===================================
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +00002Customizing LLVMC: Reference Manual
3===================================
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +00004
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +00005LLVMC is a generic compiler driver, designed to be customizable and
6extensible. It plays the same role for LLVM as the ``gcc`` program
7does for GCC - LLVMC's job is essentially to transform a set of input
8files into a set of targets depending on configuration rules and user
9options. What makes LLVMC different is that these transformation rules
10are completely customizable - in fact, LLVMC knows nothing about the
11specifics of transformation (even the command-line options are mostly
12not hard-coded) and regards the transformation structure as an
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +000013abstract graph. The structure of this graph is completely determined
14by plugins, which can be either statically or dynamically linked. This
15makes it possible to easily adapt LLVMC for other purposes - for
16example, as a build tool for game resources.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000017
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000018Because LLVMC employs TableGen [1]_ as its configuration language, you
19need to be familiar with it to customize LLVMC.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000020
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +000021
22.. contents::
23
24
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000025Compiling with LLVMC
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +000026====================
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000027
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +000028LLVMC tries hard to be as compatible with ``gcc`` as possible,
29although there are some small differences. Most of the time, however,
30you shouldn't be able to notice them::
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000031
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +000032 $ # This works as expected:
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000033 $ llvmc2 -O3 -Wall hello.cpp
34 $ ./a.out
35 hello
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000036
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +000037One nice feature of LLVMC is that one doesn't have to distinguish
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000038between different compilers for different languages (think ``g++`` and
39``gcc``) - the right toolchain is chosen automatically based on input
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +000040language names (which are, in turn, determined from file
41extensions). If you want to force files ending with ".c" to compile as
42C++, use the ``-x`` option, just like you would do it with ``gcc``::
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000043
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000044 $ llvmc2 -x c hello.cpp
45 $ # hello.cpp is really a C file
46 $ ./a.out
47 hello
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000048
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000049On the other hand, when using LLVMC as a linker to combine several C++
50object files you should provide the ``--linker`` option since it's
51impossible for LLVMC to choose the right linker in that case::
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000052
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000053 $ llvmc2 -c hello.cpp
54 $ llvmc2 hello.o
55 [A lot of link-time errors skipped]
56 $ llvmc2 --linker=c++ hello.o
57 $ ./a.out
58 hello
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +000059
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +000060
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +000061Predefined options
62==================
63
64LLVMC has some built-in options that can't be overridden in the
65configuration files:
66
67* ``-o FILE`` - Output file name.
68
69* ``-x LANGUAGE`` - Specify the language of the following input files
70 until the next -x option.
71
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +000072* ``-load PLUGIN_NAME`` - Load the specified plugin DLL. Example:
73 ``-load $LLVM_DIR/Release/lib/LLVMCSimple.so``.
74
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +000075* ``-v`` - Enable verbose mode, i.e. print out all executed commands.
76
77* ``--view-graph`` - Show a graphical representation of the compilation
Mikhail Glushenkovf74495a2008-09-22 20:48:48 +000078 graph. Requires that you have ``dot`` and ``gv`` programs
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +000079 installed. Hidden option, useful for debugging.
80
81* ``--write-graph`` - Write a ``compilation-graph.dot`` file in the
82 current directory with the compilation graph description in the
83 Graphviz format. Hidden option, useful for debugging.
84
Mikhail Glushenkova5bdf6e2008-05-30 06:29:17 +000085* ``--save-temps`` - Write temporary files to the current directory
86 and do not delete them on exit. Hidden option, useful for debugging.
87
88* ``--help``, ``--help-hidden``, ``--version`` - These options have
89 their standard meaning.
90
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +000091
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +000092Compiling LLVMC plugins
93=======================
94
95It's easiest to start working on your own LLVMC plugin by copying the
96skeleton project which lives under ``$LLVMC_DIR/plugins/Simple``::
97
98 $ cd $LLVMC_DIR/plugins
99 $ cp -r Simple MyPlugin
100 $ cd MyPlugin
101 $ ls
102 Makefile PluginMain.cpp Simple.td
103
104As you can see, our basic plugin consists of only two files (not
105counting the build script). ``Simple.td`` contains TableGen
106description of the compilation graph; its format is documented in the
107following sections. ``PluginMain.cpp`` is just a helper file used to
108compile the auto-generated C++ code produced from TableGen source. It
109can also contain hook definitions (see `below`__).
110
111__ hooks_
112
113The first thing that you should do is to change the ``LLVMC_PLUGIN``
114variable in the ``Makefile`` to avoid conflicts (since this variable
115is used to name the resulting library)::
116
117 LLVMC_PLUGIN=MyPlugin
118
119It is also a good idea to rename ``Simple.td`` to something less
120generic::
121
122 $ mv Simple.td MyPlugin.td
123
Mikhail Glushenkov30207702008-10-16 14:02:29 +0000124Note that the plugin source directory should be placed under
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000125``$LLVMC_DIR/plugins`` to make use of the existing build
126infrastructure. To build a version of the LLVMC executable called
127``mydriver`` with your plugin compiled in, use the following command::
128
129 $ cd $LLVMC_DIR
130 $ make BUILTIN_PLUGINS=MyPlugin DRIVER_NAME=mydriver
131
132When linking plugins dynamically, you'll usually want a 'bare-bones'
133version of LLVMC that has no built-in plugins. It can be compiled with
134the following command::
135
136 $ cd $LLVMC_DIR
137 $ make BUILTIN_PLUGINS=""
138
139To build your plugin as a dynamic library, just ``cd`` to its source
140directory and run ``make``. The resulting file will be called
141``LLVMC$(LLVMC_PLUGIN).$(DLL_EXTENSION)`` (in our case,
142``LLVMCMyPlugin.so``). This library can be then loaded in with the
143``-load`` option. Example::
144
145 $ cd $LLVMC_DIR/plugins/Simple
146 $ make
147 $ llvmc2 -load $LLVM_DIR/Release/lib/LLVMCSimple.so
148
149In the future LLVMC will be able to load TableGen files directly.
150
151
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000152Customizing LLVMC: the compilation graph
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000153========================================
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000154
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000155Each TableGen configuration file should include the common
156definitions::
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000157
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000158 include "llvm/CompilerDriver/Common.td"
159 // And optionally:
160 // include "llvm/CompilerDriver/Tools.td"
Mikhail Glushenkovfa990682008-11-17 17:29:18 +0000161 // which contains some useful tool definitions.
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000162
163Internally, LLVMC stores information about possible source
164transformations in form of a graph. Nodes in this graph represent
165tools, and edges between two nodes represent a transformation path. A
166special "root" node is used to mark entry points for the
167transformations. LLVMC also assigns a weight to each edge (more on
168this later) to choose between several alternative edges.
169
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000170The definition of the compilation graph (see file
171``plugins/Base/Base.td`` for an example) is just a list of edges::
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000172
173 def CompilationGraph : CompilationGraph<[
Mikhail Glushenkovfa990682008-11-17 17:29:18 +0000174 Edge<"root", "llvm_gcc_c">,
175 Edge<"root", "llvm_gcc_assembler">,
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000176 ...
177
Mikhail Glushenkovfa990682008-11-17 17:29:18 +0000178 Edge<"llvm_gcc_c", "llc">,
179 Edge<"llvm_gcc_cpp", "llc">,
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000180 ...
181
Mikhail Glushenkovfa990682008-11-17 17:29:18 +0000182 OptionalEdge<"llvm_gcc_c", "opt", [(switch_on "opt")]>,
183 OptionalEdge<"llvm_gcc_cpp", "opt", [(switch_on "opt")]>,
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000184 ...
185
Mikhail Glushenkovfa990682008-11-17 17:29:18 +0000186 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000187 (case (input_languages_contain "c++"), (inc_weight),
188 (or (parameter_equals "linker", "g++"),
189 (parameter_equals "linker", "c++")), (inc_weight))>,
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000190 ...
191
192 ]>;
193
194As you can see, the edges can be either default or optional, where
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000195optional edges are differentiated by an additional ``case`` expression
Mikhail Glushenkovfa990682008-11-17 17:29:18 +0000196used to calculate the weight of this edge. Notice also that we refer
197to tools via their names (as strings). This allows us to add edges to
198an existing compilation graph without having to include all tool
199definitions that it uses.
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000200
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000201The default edges are assigned a weight of 1, and optional edges get a
202weight of 0 + 2*N where N is the number of tests that evaluated to
203true in the ``case`` expression. It is also possible to provide an
204integer parameter to ``inc_weight`` and ``dec_weight`` - in this case,
205the weight is increased (or decreased) by the provided value instead
206of the default 2.
207
208When passing an input file through the graph, LLVMC picks the edge
209with the maximum weight. To avoid ambiguity, there should be only one
210default edge between two nodes (with the exception of the root node,
211which gets a special treatment - there you are allowed to specify one
212default edge *per language*).
213
214To get a visual representation of the compilation graph (useful for
215debugging), run ``llvmc2 --view-graph``. You will need ``dot`` and
216``gsview`` installed for this to work properly.
217
218
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000219Writing a tool description
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000220==========================
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000221
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000222As was said earlier, nodes in the compilation graph represent tools,
223which are described separately. A tool definition looks like this
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000224(taken from the ``include/llvm/CompilerDriver/Tools.td`` file)::
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000225
226 def llvm_gcc_cpp : Tool<[
227 (in_language "c++"),
228 (out_language "llvm-assembler"),
229 (output_suffix "bc"),
230 (cmd_line "llvm-g++ -c $INFILE -o $OUTFILE -emit-llvm"),
231 (sink)
232 ]>;
233
234This defines a new tool called ``llvm_gcc_cpp``, which is an alias for
235``llvm-g++``. As you can see, a tool definition is just a list of
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000236properties; most of them should be self-explanatory. The ``sink``
237property means that this tool should be passed all command-line
238options that lack explicit descriptions.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000239
240The complete list of the currently implemented tool properties follows:
241
242* Possible tool properties:
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000243
Mikhail Glushenkovc178ead2008-09-22 20:45:17 +0000244 - ``in_language`` - input language name. Can be either a string or a
245 list, in case the tool supports multiple input languages.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000246
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000247 - ``out_language`` - output language name.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000248
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000249 - ``output_suffix`` - output file suffix.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000250
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000251 - ``cmd_line`` - the actual command used to run the tool. You can
252 use ``$INFILE`` and ``$OUTFILE`` variables, output redirection
253 with ``>``, hook invocations (``$CALL``), environment variables
254 (via ``$ENV``) and the ``case`` construct (more on this below).
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000255
256 - ``join`` - this tool is a "join node" in the graph, i.e. it gets a
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000257 list of input files and joins them together. Used for linkers.
258
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000259 - ``sink`` - all command-line options that are not handled by other
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000260 tools are passed to this tool.
261
262The next tool definition is slightly more complex::
263
264 def llvm_gcc_linker : Tool<[
265 (in_language "object-code"),
266 (out_language "executable"),
267 (output_suffix "out"),
268 (cmd_line "llvm-gcc $INFILE -o $OUTFILE"),
269 (join),
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000270 (prefix_list_option "L", (forward),
271 (help "add a directory to link path")),
272 (prefix_list_option "l", (forward),
273 (help "search a library when linking")),
274 (prefix_list_option "Wl", (unpack_values),
275 (help "pass options to linker"))
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000276 ]>;
277
278This tool has a "join" property, which means that it behaves like a
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000279linker. This tool also defines several command-line options: ``-l``,
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000280``-L`` and ``-Wl`` which have their usual meaning. An option has two
281attributes: a name and a (possibly empty) list of properties. All
282currently implemented option types and properties are described below:
283
284* Possible option types:
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000285
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000286 - ``switch_option`` - a simple boolean switch, for example ``-time``.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000287
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000288 - ``parameter_option`` - option that takes an argument, for example
289 ``-std=c99``;
290
291 - ``parameter_list_option`` - same as the above, but more than one
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000292 occurence of the option is allowed.
293
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000294 - ``prefix_option`` - same as the parameter_option, but the option name
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000295 and parameter value are not separated.
296
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000297 - ``prefix_list_option`` - same as the above, but more than one
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000298 occurence of the option is allowed; example: ``-lm -lpthread``.
299
Mikhail Glushenkov75ade502008-05-30 06:28:00 +0000300 - ``alias_option`` - a special option type for creating
301 aliases. Unlike other option types, aliases are not allowed to
302 have any properties besides the aliased option name. Usage
303 example: ``(alias_option "preprocess", "E")``
304
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000305
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000306* Possible option properties:
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000307
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000308 - ``append_cmd`` - append a string to the tool invocation command.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000309
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000310 - ``forward`` - forward this option unchanged.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000311
Mikhail Glushenkov50084e82008-09-22 20:46:19 +0000312 - ``forward_as`` - Change the name of this option, but forward the
313 argument unchanged. Example: ``(forward_as "--disable-optimize")``.
314
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000315 - ``output_suffix`` - modify the output suffix of this
Mikhail Glushenkov50084e82008-09-22 20:46:19 +0000316 tool. Example: ``(switch "E", (output_suffix "i")``.
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000317
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000318 - ``stop_compilation`` - stop compilation after this phase.
319
320 - ``unpack_values`` - used for for splitting and forwarding
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000321 comma-separated lists of options, e.g. ``-Wa,-foo=bar,-baz`` is
322 converted to ``-foo=bar -baz`` and appended to the tool invocation
323 command.
324
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000325 - ``help`` - help string associated with this option. Used for
326 ``--help`` output.
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000327
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000328 - ``required`` - this option is obligatory.
329
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000330
Mikhail Glushenkov75ade502008-05-30 06:28:00 +0000331Option list - specifying all options in a single place
332======================================================
333
334It can be handy to have all information about options gathered in a
335single place to provide an overview. This can be achieved by using a
336so-called ``OptionList``::
337
338 def Options : OptionList<[
339 (switch_option "E", (help "Help string")),
340 (alias_option "quiet", "q")
341 ...
342 ]>;
343
344``OptionList`` is also a good place to specify option aliases.
345
346Tool-specific option properties like ``append_cmd`` have (obviously)
347no meaning in the context of ``OptionList``, so the only properties
348allowed there are ``help`` and ``required``.
349
350Option lists are used at the file scope. See file
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000351``plugins/Clang/Clang.td`` for an example of ``OptionList`` usage.
352
353.. _hooks:
Mikhail Glushenkov75ade502008-05-30 06:28:00 +0000354
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000355Using hooks and environment variables in the ``cmd_line`` property
356==================================================================
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000357
358Normally, LLVMC executes programs from the system ``PATH``. Sometimes,
359this is not sufficient: for example, we may want to specify tool names
360in the configuration file. This can be achieved via the mechanism of
Mikhail Glushenkovbd51c232008-10-15 09:29:13 +0000361hooks - to write your own hooks, just add their definitions to the
362``PluginMain.cpp`` or drop a ``.cpp`` file into the
363``$LLVMC_DIR/driver`` directory. Hooks should live in the ``hooks``
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000364namespace and have the signature ``std::string hooks::MyHookName
365(void)``. They can be used from the ``cmd_line`` tool property::
366
367 (cmd_line "$CALL(MyHook)/path/to/file -o $CALL(AnotherHook)")
368
369It is also possible to use environment variables in the same manner::
370
371 (cmd_line "$ENV(VAR1)/path/to/file -o $ENV(VAR2)")
372
373To change the command line string based on user-provided options use
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000374the ``case`` expression (documented below)::
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000375
376 (cmd_line
377 (case
378 (switch_on "E"),
379 "llvm-g++ -E -x c $INFILE -o $OUTFILE",
380 (default),
381 "llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm"))
382
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000383Conditional evaluation: the ``case`` expression
384===============================================
385
386The 'case' construct can be used to calculate weights of the optional
387edges and to choose between several alternative command line strings
388in the ``cmd_line`` tool property. It is designed after the
389similarly-named construct in functional languages and takes the form
390``(case (test_1), statement_1, (test_2), statement_2, ... (test_N),
391statement_N)``. The statements are evaluated only if the corresponding
392tests evaluate to true.
393
394Examples::
395
396 // Increases edge weight by 5 if "-A" is provided on the
397 // command-line, and by 5 more if "-B" is also provided.
398 (case
399 (switch_on "A"), (inc_weight 5),
400 (switch_on "B"), (inc_weight 5))
401
402 // Evaluates to "cmdline1" if option "-A" is provided on the
403 // command line, otherwise to "cmdline2"
404 (case
405 (switch_on "A"), "cmdline1",
406 (switch_on "B"), "cmdline2",
407 (default), "cmdline3")
408
409Note the slight difference in 'case' expression handling in contexts
410of edge weights and command line specification - in the second example
411the value of the ``"B"`` switch is never checked when switch ``"A"`` is
412enabled, and the whole expression always evaluates to ``"cmdline1"`` in
413that case.
414
415Case expressions can also be nested, i.e. the following is legal::
416
417 (case (switch_on "E"), (case (switch_on "o"), ..., (default), ...)
418 (default), ...)
419
420You should, however, try to avoid doing that because it hurts
421readability. It is usually better to split tool descriptions and/or
422use TableGen inheritance instead.
423
424* Possible tests are:
425
426 - ``switch_on`` - Returns true if a given command-line option is
427 provided by the user. Example: ``(switch_on "opt")``. Note that
428 you have to define all possible command-line options separately in
429 the tool descriptions. See the next section for the discussion of
430 different kinds of command-line options.
431
432 - ``parameter_equals`` - Returns true if a command-line parameter equals
433 a given value. Example: ``(parameter_equals "W", "all")``.
434
435 - ``element_in_list`` - Returns true if a command-line parameter list
436 includes a given value. Example: ``(parameter_in_list "l", "pthread")``.
437
438 - ``input_languages_contain`` - Returns true if a given language
439 belongs to the current input language set. Example:
Mikhail Glushenkov56a625a2008-09-22 20:48:22 +0000440 ``(input_languages_contain "c++")``.
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000441
442 - ``in_language`` - Evaluates to true if the language of the input
Mikhail Glushenkov56a625a2008-09-22 20:48:22 +0000443 file equals to the argument. At the moment works only with
444 ``cmd_line`` property on non-join nodes. Example: ``(in_language
445 "c++")``.
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000446
447 - ``not_empty`` - Returns true if a given option (which should be
448 either a parameter or a parameter list) is set by the
Mikhail Glushenkov56a625a2008-09-22 20:48:22 +0000449 user. Example: ``(not_empty "o")``.
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000450
451 - ``default`` - Always evaluates to true. Should always be the last
452 test in the ``case`` expression.
453
454 - ``and`` - A standard logical combinator that returns true iff all
455 of its arguments return true. Used like this: ``(and (test1),
456 (test2), ... (testN))``. Nesting of ``and`` and ``or`` is allowed,
457 but not encouraged.
458
459 - ``or`` - Another logical combinator that returns true only if any
460 one of its arguments returns true. Example: ``(or (test1),
461 (test2), ... (testN))``.
462
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000463
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000464Language map
Mikhail Glushenkov772d9c92008-05-30 06:25:24 +0000465============
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000466
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000467One last thing that you will need to modify when adding support for a
468new language to LLVMC is the language map, which defines mappings from
Mikhail Glushenkov2e6a8442008-05-06 18:17:19 +0000469file extensions to language names. It is used to choose the proper
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +0000470toolchain(s) for a given input file set. Language map definition is
471located in the file ``Tools.td`` and looks like this::
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000472
473 def LanguageMap : LanguageMap<
474 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
475 LangToSuffixes<"c", ["c"]>,
476 ...
477 ]>;
478
Mikhail Glushenkovf74495a2008-09-22 20:48:48 +0000479Debugging
480=========
481
482When writing LLVMC plugins, it can be useful to get a visual view of
483the resulting compilation graph. This can be achieved via the command
484line option ``--view-graph``. This command assumes that Graphviz [2]_ and
485Ghostview [3]_ are installed. There is also a ``--dump-graph`` option that
486creates a Graphviz source file(``compilation-graph.dot``) in the
487current directory.
488
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000489
Anton Korobeynikove9ffb5b2008-03-23 08:57:20 +0000490References
491==========
492
493.. [1] TableGen Fundamentals
494 http://llvm.cs.uiuc.edu/docs/TableGenFundamentals.html
Mikhail Glushenkovf74495a2008-09-22 20:48:48 +0000495
496.. [2] Graphviz
497 http://www.graphviz.org/
498
499.. [3] Ghostview
500 http://pages.cs.wisc.edu/~ghost/