blob: 62e2ef41a8bc338ba22fc2a2b50dd28547d3413f [file] [log] [blame]
Mikhail Glushenkov270cae32008-05-30 06:25:24 +00001===================================
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +00002Customizing LLVMC: Reference Manual
3===================================
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +00004
Mikhail Glushenkov77ddce92008-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 Glushenkov83237482008-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 Korobeynikovac67b7e2008-03-23 08:57:20 +000017
Mikhail Glushenkov77ddce92008-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 Korobeynikovac67b7e2008-03-23 08:57:20 +000020
Mikhail Glushenkov270cae32008-05-30 06:25:24 +000021
22.. contents::
23
24
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +000025Compiling with LLVMC
Mikhail Glushenkov270cae32008-05-30 06:25:24 +000026====================
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000027
Mikhail Glushenkovcd0858e2008-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 Korobeynikovac67b7e2008-03-23 08:57:20 +000031
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +000032 $ # This works as expected:
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +000033 $ llvmc2 -O3 -Wall hello.cpp
34 $ ./a.out
35 hello
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000036
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +000037One nice feature of LLVMC is that one doesn't have to distinguish
Mikhail Glushenkov77ddce92008-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 Glushenkovcd0858e2008-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 Korobeynikovac67b7e2008-03-23 08:57:20 +000043
Mikhail Glushenkov77ddce92008-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 Korobeynikovac67b7e2008-03-23 08:57:20 +000048
Mikhail Glushenkov77ddce92008-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 Korobeynikovac67b7e2008-03-23 08:57:20 +000052
Mikhail Glushenkov77ddce92008-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 Korobeynikovac67b7e2008-03-23 08:57:20 +000059
Mikhail Glushenkov83237482008-10-15 09:29:13 +000060
Mikhail Glushenkov270cae32008-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 Glushenkov83237482008-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 Glushenkov270cae32008-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 Glushenkov9ecd30c2008-09-22 20:48:48 +000078 graph. Requires that you have ``dot`` and ``gv`` programs
Mikhail Glushenkov270cae32008-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 Glushenkov73296102008-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 Glushenkov77ddce92008-05-06 18:17:19 +000091
Mikhail Glushenkov83237482008-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 Glushenkovcc30d9c2008-10-16 14:02:29 +0000124Note that the plugin source directory should be placed under
Mikhail Glushenkov83237482008-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 Glushenkov77ddce92008-05-06 18:17:19 +0000152Customizing LLVMC: the compilation graph
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000153========================================
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000154
Mikhail Glushenkov83237482008-10-15 09:29:13 +0000155Each TableGen configuration file should include the common
156definitions::
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000157
Mikhail Glushenkov83237482008-10-15 09:29:13 +0000158 include "llvm/CompilerDriver/Common.td"
159 // And optionally:
160 // include "llvm/CompilerDriver/Tools.td"
161 // which contains tool definitions.
Mikhail Glushenkovcd0858e2008-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 Glushenkov83237482008-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 Glushenkov77ddce92008-05-06 18:17:19 +0000172
173 def CompilationGraph : CompilationGraph<[
174 Edge<root, llvm_gcc_c>,
175 Edge<root, llvm_gcc_assembler>,
176 ...
177
178 Edge<llvm_gcc_c, llc>,
179 Edge<llvm_gcc_cpp, llc>,
180 ...
181
182 OptionalEdge<llvm_gcc_c, opt, [(switch_on "opt")]>,
183 OptionalEdge<llvm_gcc_cpp, opt, [(switch_on "opt")]>,
184 ...
185
186 OptionalEdge<llvm_gcc_assembler, llvm_gcc_cpp_linker,
Mikhail Glushenkovcd0858e2008-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 Glushenkov77ddce92008-05-06 18:17:19 +0000190 ...
191
192 ]>;
193
194As you can see, the edges can be either default or optional, where
Mikhail Glushenkov83237482008-10-15 09:29:13 +0000195optional edges are differentiated by an additional ``case`` expression
196used to calculate the weight of this edge.
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000197
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000198The default edges are assigned a weight of 1, and optional edges get a
199weight of 0 + 2*N where N is the number of tests that evaluated to
200true in the ``case`` expression. It is also possible to provide an
201integer parameter to ``inc_weight`` and ``dec_weight`` - in this case,
202the weight is increased (or decreased) by the provided value instead
203of the default 2.
204
205When passing an input file through the graph, LLVMC picks the edge
206with the maximum weight. To avoid ambiguity, there should be only one
207default edge between two nodes (with the exception of the root node,
208which gets a special treatment - there you are allowed to specify one
209default edge *per language*).
210
211To get a visual representation of the compilation graph (useful for
212debugging), run ``llvmc2 --view-graph``. You will need ``dot`` and
213``gsview`` installed for this to work properly.
214
215
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000216Writing a tool description
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000217==========================
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000218
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000219As was said earlier, nodes in the compilation graph represent tools,
220which are described separately. A tool definition looks like this
Mikhail Glushenkov83237482008-10-15 09:29:13 +0000221(taken from the ``include/llvm/CompilerDriver/Tools.td`` file)::
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000222
223 def llvm_gcc_cpp : Tool<[
224 (in_language "c++"),
225 (out_language "llvm-assembler"),
226 (output_suffix "bc"),
227 (cmd_line "llvm-g++ -c $INFILE -o $OUTFILE -emit-llvm"),
228 (sink)
229 ]>;
230
231This defines a new tool called ``llvm_gcc_cpp``, which is an alias for
232``llvm-g++``. As you can see, a tool definition is just a list of
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000233properties; most of them should be self-explanatory. The ``sink``
234property means that this tool should be passed all command-line
235options that lack explicit descriptions.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000236
237The complete list of the currently implemented tool properties follows:
238
239* Possible tool properties:
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000240
Mikhail Glushenkov5ccf28f2008-09-22 20:45:17 +0000241 - ``in_language`` - input language name. Can be either a string or a
242 list, in case the tool supports multiple input languages.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000243
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000244 - ``out_language`` - output language name.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000245
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000246 - ``output_suffix`` - output file suffix.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000247
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000248 - ``cmd_line`` - the actual command used to run the tool. You can
249 use ``$INFILE`` and ``$OUTFILE`` variables, output redirection
250 with ``>``, hook invocations (``$CALL``), environment variables
251 (via ``$ENV``) and the ``case`` construct (more on this below).
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000252
253 - ``join`` - this tool is a "join node" in the graph, i.e. it gets a
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000254 list of input files and joins them together. Used for linkers.
255
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000256 - ``sink`` - all command-line options that are not handled by other
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000257 tools are passed to this tool.
258
259The next tool definition is slightly more complex::
260
261 def llvm_gcc_linker : Tool<[
262 (in_language "object-code"),
263 (out_language "executable"),
264 (output_suffix "out"),
265 (cmd_line "llvm-gcc $INFILE -o $OUTFILE"),
266 (join),
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000267 (prefix_list_option "L", (forward),
268 (help "add a directory to link path")),
269 (prefix_list_option "l", (forward),
270 (help "search a library when linking")),
271 (prefix_list_option "Wl", (unpack_values),
272 (help "pass options to linker"))
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000273 ]>;
274
275This tool has a "join" property, which means that it behaves like a
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000276linker. This tool also defines several command-line options: ``-l``,
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000277``-L`` and ``-Wl`` which have their usual meaning. An option has two
278attributes: a name and a (possibly empty) list of properties. All
279currently implemented option types and properties are described below:
280
281* Possible option types:
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000282
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000283 - ``switch_option`` - a simple boolean switch, for example ``-time``.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000284
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000285 - ``parameter_option`` - option that takes an argument, for example
286 ``-std=c99``;
287
288 - ``parameter_list_option`` - same as the above, but more than one
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000289 occurence of the option is allowed.
290
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000291 - ``prefix_option`` - same as the parameter_option, but the option name
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000292 and parameter value are not separated.
293
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000294 - ``prefix_list_option`` - same as the above, but more than one
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000295 occurence of the option is allowed; example: ``-lm -lpthread``.
296
Mikhail Glushenkov0ab8ac32008-05-30 06:28:00 +0000297 - ``alias_option`` - a special option type for creating
298 aliases. Unlike other option types, aliases are not allowed to
299 have any properties besides the aliased option name. Usage
300 example: ``(alias_option "preprocess", "E")``
301
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000302
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000303* Possible option properties:
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000304
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000305 - ``append_cmd`` - append a string to the tool invocation command.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000306
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000307 - ``forward`` - forward this option unchanged.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000308
Mikhail Glushenkovfdee9542008-09-22 20:46:19 +0000309 - ``forward_as`` - Change the name of this option, but forward the
310 argument unchanged. Example: ``(forward_as "--disable-optimize")``.
311
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000312 - ``output_suffix`` - modify the output suffix of this
Mikhail Glushenkovfdee9542008-09-22 20:46:19 +0000313 tool. Example: ``(switch "E", (output_suffix "i")``.
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000314
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000315 - ``stop_compilation`` - stop compilation after this phase.
316
317 - ``unpack_values`` - used for for splitting and forwarding
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000318 comma-separated lists of options, e.g. ``-Wa,-foo=bar,-baz`` is
319 converted to ``-foo=bar -baz`` and appended to the tool invocation
320 command.
321
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000322 - ``help`` - help string associated with this option. Used for
323 ``--help`` output.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000324
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000325 - ``required`` - this option is obligatory.
326
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000327
Mikhail Glushenkov0ab8ac32008-05-30 06:28:00 +0000328Option list - specifying all options in a single place
329======================================================
330
331It can be handy to have all information about options gathered in a
332single place to provide an overview. This can be achieved by using a
333so-called ``OptionList``::
334
335 def Options : OptionList<[
336 (switch_option "E", (help "Help string")),
337 (alias_option "quiet", "q")
338 ...
339 ]>;
340
341``OptionList`` is also a good place to specify option aliases.
342
343Tool-specific option properties like ``append_cmd`` have (obviously)
344no meaning in the context of ``OptionList``, so the only properties
345allowed there are ``help`` and ``required``.
346
347Option lists are used at the file scope. See file
Mikhail Glushenkov83237482008-10-15 09:29:13 +0000348``plugins/Clang/Clang.td`` for an example of ``OptionList`` usage.
349
350.. _hooks:
Mikhail Glushenkov0ab8ac32008-05-30 06:28:00 +0000351
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000352Using hooks and environment variables in the ``cmd_line`` property
353==================================================================
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000354
355Normally, LLVMC executes programs from the system ``PATH``. Sometimes,
356this is not sufficient: for example, we may want to specify tool names
357in the configuration file. This can be achieved via the mechanism of
Mikhail Glushenkov83237482008-10-15 09:29:13 +0000358hooks - to write your own hooks, just add their definitions to the
359``PluginMain.cpp`` or drop a ``.cpp`` file into the
360``$LLVMC_DIR/driver`` directory. Hooks should live in the ``hooks``
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000361namespace and have the signature ``std::string hooks::MyHookName
362(void)``. They can be used from the ``cmd_line`` tool property::
363
364 (cmd_line "$CALL(MyHook)/path/to/file -o $CALL(AnotherHook)")
365
366It is also possible to use environment variables in the same manner::
367
368 (cmd_line "$ENV(VAR1)/path/to/file -o $ENV(VAR2)")
369
370To change the command line string based on user-provided options use
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000371the ``case`` expression (documented below)::
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000372
373 (cmd_line
374 (case
375 (switch_on "E"),
376 "llvm-g++ -E -x c $INFILE -o $OUTFILE",
377 (default),
378 "llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm"))
379
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000380Conditional evaluation: the ``case`` expression
381===============================================
382
383The 'case' construct can be used to calculate weights of the optional
384edges and to choose between several alternative command line strings
385in the ``cmd_line`` tool property. It is designed after the
386similarly-named construct in functional languages and takes the form
387``(case (test_1), statement_1, (test_2), statement_2, ... (test_N),
388statement_N)``. The statements are evaluated only if the corresponding
389tests evaluate to true.
390
391Examples::
392
393 // Increases edge weight by 5 if "-A" is provided on the
394 // command-line, and by 5 more if "-B" is also provided.
395 (case
396 (switch_on "A"), (inc_weight 5),
397 (switch_on "B"), (inc_weight 5))
398
399 // Evaluates to "cmdline1" if option "-A" is provided on the
400 // command line, otherwise to "cmdline2"
401 (case
402 (switch_on "A"), "cmdline1",
403 (switch_on "B"), "cmdline2",
404 (default), "cmdline3")
405
406Note the slight difference in 'case' expression handling in contexts
407of edge weights and command line specification - in the second example
408the value of the ``"B"`` switch is never checked when switch ``"A"`` is
409enabled, and the whole expression always evaluates to ``"cmdline1"`` in
410that case.
411
412Case expressions can also be nested, i.e. the following is legal::
413
414 (case (switch_on "E"), (case (switch_on "o"), ..., (default), ...)
415 (default), ...)
416
417You should, however, try to avoid doing that because it hurts
418readability. It is usually better to split tool descriptions and/or
419use TableGen inheritance instead.
420
421* Possible tests are:
422
423 - ``switch_on`` - Returns true if a given command-line option is
424 provided by the user. Example: ``(switch_on "opt")``. Note that
425 you have to define all possible command-line options separately in
426 the tool descriptions. See the next section for the discussion of
427 different kinds of command-line options.
428
429 - ``parameter_equals`` - Returns true if a command-line parameter equals
430 a given value. Example: ``(parameter_equals "W", "all")``.
431
432 - ``element_in_list`` - Returns true if a command-line parameter list
433 includes a given value. Example: ``(parameter_in_list "l", "pthread")``.
434
435 - ``input_languages_contain`` - Returns true if a given language
436 belongs to the current input language set. Example:
Mikhail Glushenkov07376512008-09-22 20:48:22 +0000437 ``(input_languages_contain "c++")``.
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000438
439 - ``in_language`` - Evaluates to true if the language of the input
Mikhail Glushenkov07376512008-09-22 20:48:22 +0000440 file equals to the argument. At the moment works only with
441 ``cmd_line`` property on non-join nodes. Example: ``(in_language
442 "c++")``.
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000443
444 - ``not_empty`` - Returns true if a given option (which should be
445 either a parameter or a parameter list) is set by the
Mikhail Glushenkov07376512008-09-22 20:48:22 +0000446 user. Example: ``(not_empty "o")``.
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000447
448 - ``default`` - Always evaluates to true. Should always be the last
449 test in the ``case`` expression.
450
451 - ``and`` - A standard logical combinator that returns true iff all
452 of its arguments return true. Used like this: ``(and (test1),
453 (test2), ... (testN))``. Nesting of ``and`` and ``or`` is allowed,
454 but not encouraged.
455
456 - ``or`` - Another logical combinator that returns true only if any
457 one of its arguments returns true. Example: ``(or (test1),
458 (test2), ... (testN))``.
459
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000460
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000461Language map
Mikhail Glushenkov270cae32008-05-30 06:25:24 +0000462============
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000463
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000464One last thing that you will need to modify when adding support for a
465new language to LLVMC is the language map, which defines mappings from
Mikhail Glushenkov77ddce92008-05-06 18:17:19 +0000466file extensions to language names. It is used to choose the proper
Mikhail Glushenkovcd0858e2008-05-30 06:14:42 +0000467toolchain(s) for a given input file set. Language map definition is
468located in the file ``Tools.td`` and looks like this::
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000469
470 def LanguageMap : LanguageMap<
471 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
472 LangToSuffixes<"c", ["c"]>,
473 ...
474 ]>;
475
Mikhail Glushenkov9ecd30c2008-09-22 20:48:48 +0000476Debugging
477=========
478
479When writing LLVMC plugins, it can be useful to get a visual view of
480the resulting compilation graph. This can be achieved via the command
481line option ``--view-graph``. This command assumes that Graphviz [2]_ and
482Ghostview [3]_ are installed. There is also a ``--dump-graph`` option that
483creates a Graphviz source file(``compilation-graph.dot``) in the
484current directory.
485
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000486
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000487References
488==========
489
490.. [1] TableGen Fundamentals
491 http://llvm.cs.uiuc.edu/docs/TableGenFundamentals.html
Mikhail Glushenkov9ecd30c2008-09-22 20:48:48 +0000492
493.. [2] Graphviz
494 http://www.graphviz.org/
495
496.. [3] Ghostview
497 http://pages.cs.wisc.edu/~ghost/