1 ===================================
2 Customizing LLVMC: Reference Manual
3 ===================================
5 This file was automatically generated by rst2html.
6 Please do not edit directly!
7 The ReST source lives in the directory 'tools/llvmc/doc'.
13 <div class="doc_author">
14 <p>Written by <a href="mailto:foldr@codedgers.com">Mikhail Glushenkov</a></p>
20 LLVMC is a generic compiler driver, designed to be customizable and
21 extensible. It plays the same role for LLVM as the ``gcc`` program does for
22 GCC - LLVMC's job is essentially to transform a set of input files into a set of
23 targets depending on configuration rules and user options. What makes LLVMC
24 different is that these transformation rules are completely customizable - in
25 fact, LLVMC knows nothing about the specifics of transformation (even the
26 command-line options are mostly not hard-coded) and regards the transformation
27 structure as an abstract graph. The structure of this graph is described in
28 high-level TableGen code, from which an efficient C++ representation is
29 automatically derived. This makes it possible to adapt LLVMC for other
30 purposes - for example, as a build tool for game resources.
32 Because LLVMC employs TableGen_ as its configuration language, you
33 need to be familiar with it to customize LLVMC.
35 .. _TableGen: http://llvm.org/docs/TableGenFundamentals.html
38 Compiling with ``llvmc``
39 ========================
41 LLVMC tries hard to be as compatible with ``gcc`` as possible,
42 although there are some small differences. Most of the time, however,
43 you shouldn't be able to notice them::
45 $ # This works as expected:
46 $ llvmc -O3 -Wall hello.cpp
50 One nice feature of LLVMC is that one doesn't have to distinguish between
51 different compilers for different languages (think ``g++`` vs. ``gcc``) - the
52 right toolchain is chosen automatically based on input language names (which
53 are, in turn, determined from file extensions). If you want to force files
54 ending with ".c" to compile as C++, use the ``-x`` option, just like you would
57 $ # hello.c is really a C++ file
58 $ llvmc -x c++ hello.c
62 On the other hand, when using LLVMC as a linker to combine several C++
63 object files you should provide the ``--linker`` option since it's
64 impossible for LLVMC to choose the right linker in that case::
68 [A lot of link-time errors skipped]
69 $ llvmc --linker=c++ hello.o
73 By default, LLVMC uses ``llvm-gcc`` to compile the source code. It is also
74 possible to choose the ``clang`` compiler with the ``-clang`` option.
80 LLVMC has some built-in options that can't be overridden in the TableGen code:
82 * ``-o FILE`` - Output file name.
84 * ``-x LANGUAGE`` - Specify the language of the following input files
85 until the next -x option.
87 * ``-v`` - Enable verbose mode, i.e. print out all executed commands.
89 * ``--save-temps`` - Write temporary files to the current directory and do not
90 delete them on exit. This option can also take an argument: the
91 ``--save-temps=obj`` switch will write files into the directory specified with
92 the ``-o`` option. The ``--save-temps=cwd`` and ``--save-temps`` switches are
93 both synonyms for the default behaviour.
95 * ``--temp-dir DIRECTORY`` - Store temporary files in the given directory. This
96 directory is deleted on exit unless ``--save-temps`` is specified. If
97 ``--save-temps=obj`` is also specified, ``--temp-dir`` is given the
100 * ``--check-graph`` - Check the compilation for common errors like mismatched
101 output/input language names, multiple default edges and cycles. Exit with code
102 zero if no errors were found, and return the number of found errors
103 otherwise. Hidden option, useful for debugging.
105 * ``--view-graph`` - Show a graphical representation of the compilation graph
106 and exit. Requires that you have ``dot`` and ``gv`` programs installed. Hidden
107 option, useful for debugging.
109 * ``--write-graph`` - Write a ``compilation-graph.dot`` file in the current
110 directory with the compilation graph description in Graphviz format (identical
111 to the file used by the ``--view-graph`` option). The ``-o`` option can be
112 used to set the output file name. Hidden option, useful for debugging.
114 * ``--help``, ``--help-hidden``, ``--version`` - These options have
115 their standard meaning.
117 Compiling LLVMC-based drivers
118 =============================
120 It's easiest to start working on your own LLVMC driver by copying the skeleton
121 project which lives under ``$LLVMC_DIR/examples/Skeleton``::
123 $ cd $LLVMC_DIR/examples
124 $ cp -r Skeleton MyDriver
127 AutoGenerated.td Hooks.cpp Main.cpp Makefile
129 As you can see, our basic driver consists of only three files (not counting the
130 build script). ``AutoGenerated.td`` contains TableGen description of the
131 compilation graph; its format is documented in the following
132 sections. ``Hooks.cpp`` is an empty file that should be used for hook
133 definitions (see `below`__). ``Main.cpp`` is just a helper used to compile the
134 auto-generated C++ code produced from TableGen source.
138 The first thing that you should do is to change the ``LLVMC_BASED_DRIVER``
139 variable in the ``Makefile``::
141 LLVMC_BASED_DRIVER=MyDriver
143 It can also be a good idea to put your TableGen code into a file with a less
147 $ vim AutoGenerated.td
149 include "MyDriver.td"
151 If you have more than one TableGen source file, they all should be included from
152 ``AutoGenerated.td``, since this file is used by the build system to generate
155 To build your driver, just ``cd`` to its source directory and run ``make``. The
156 resulting executable will be put into ``$LLVM_OBJ_DIR/$(BuildMode)/bin``.
158 If you're compiling LLVM with different source and object directories, then you
159 must perform the following additional steps before running ``make``::
161 # LLVMC_SRC_DIR = $LLVM_SRC_DIR/tools/llvmc/
162 # LLVMC_OBJ_DIR = $LLVM_OBJ_DIR/tools/llvmc/
163 $ mkdir $LLVMC_OBJ_DIR/examples/MyDriver/
164 $ cp $LLVMC_SRC_DIR/examples/MyDriver/Makefile \
165 $LLVMC_OBJ_DIR/examples/MyDriver/
166 $ cd $LLVMC_OBJ_DIR/examples/MyDriver
170 Customizing LLVMC: the compilation graph
171 ========================================
173 Each TableGen configuration file should include the common definitions::
175 include "llvm/CompilerDriver/Common.td"
177 Internally, LLVMC stores information about possible source transformations in
178 form of a graph. Nodes in this graph represent tools, and edges between two
179 nodes represent a transformation path. A special "root" node is used to mark
180 entry points for the transformations. LLVMC also assigns a weight to each edge
181 (more on this later) to choose between several alternative edges.
183 The definition of the compilation graph (see file ``llvmc/src/Base.td`` for an
184 example) is just a list of edges::
186 def CompilationGraph : CompilationGraph<[
187 Edge<"root", "llvm_gcc_c">,
188 Edge<"root", "llvm_gcc_assembler">,
191 Edge<"llvm_gcc_c", "llc">,
192 Edge<"llvm_gcc_cpp", "llc">,
195 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"),
197 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"),
201 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
202 (case (input_languages_contain "c++"), (inc_weight),
203 (or (parameter_equals "linker", "g++"),
204 (parameter_equals "linker", "c++")), (inc_weight))>,
209 As you can see, the edges can be either default or optional, where optional
210 edges are differentiated by an additional ``case`` expression used to calculate
211 the weight of this edge. Notice also that we refer to tools via their names (as
212 strings). This makes it possible to add edges to an existing compilation graph
213 without having to know about all tool definitions used in the graph.
215 The default edges are assigned a weight of 1, and optional edges get a weight of
216 0 + 2*N where N is the number of tests that evaluated to true in the ``case``
217 expression. It is also possible to provide an integer parameter to
218 ``inc_weight`` and ``dec_weight`` - in this case, the weight is increased (or
219 decreased) by the provided value instead of the default 2. Default weight of an
220 optional edge can be changed by using the ``default`` clause of the ``case``
223 When passing an input file through the graph, LLVMC picks the edge with the
224 maximum weight. To avoid ambiguity, there should be only one default edge
225 between two nodes (with the exception of the root node, which gets a special
226 treatment - there you are allowed to specify one default edge *per language*).
228 When multiple compilation graphs are defined, they are merged together. Multiple
229 edges with the same end nodes are not allowed (i.e. the graph is not a
230 multigraph), and will lead to a compile-time error.
232 To get a visual representation of the compilation graph (useful for debugging),
233 run ``llvmc --view-graph``. You will need ``dot`` and ``gsview`` installed for
234 this to work properly.
239 Command-line options supported by the driver are defined by using an
242 def Options : OptionList<[
243 (switch_option "E", (help "Help string")),
244 (alias_option "quiet", "q")
248 As you can see, the option list is just a list of DAGs, where each DAG is an
249 option description consisting of the option name and some properties. More than
250 one option list can be defined (they are all merged together in the end), which
251 can be handy if one wants to separate option groups syntactically.
253 * Possible option types:
255 - ``switch_option`` - a simple boolean switch without arguments, for example
256 ``-O2`` or ``-time``. At most one occurrence is allowed by default.
258 - ``parameter_option`` - option that takes one argument, for example
259 ``-std=c99``. It is also allowed to use spaces instead of the equality
260 sign: ``-std c99``. At most one occurrence is allowed.
262 - ``parameter_list_option`` - same as the above, but more than one option
263 occurrence is allowed.
265 - ``prefix_option`` - same as the parameter_option, but the option name and
266 argument do not have to be separated. Example: ``-ofile``. This can be also
267 specified as ``-o file``; however, ``-o=file`` will be parsed incorrectly
268 (``=file`` will be interpreted as option value). At most one occurrence is
271 - ``prefix_list_option`` - same as the above, but more than one occurrence of
272 the option is allowed; example: ``-lm -lpthread``.
274 - ``alias_option`` - a special option type for creating aliases. Unlike other
275 option types, aliases are not allowed to have any properties besides the
277 Usage example: ``(alias_option "preprocess", "E")``
279 - ``switch_list_option`` - like ``switch_option`` with the ``zero_or_more``
280 property, but remembers how many times the switch was turned on. Useful
281 mostly for forwarding. Example: when ``-foo`` is a switch option (with the
282 ``zero_or_more`` property), the command ``driver -foo -foo`` is forwarded
283 as ``some-tool -foo``, but when ``-foo`` is a switch list, the same command
284 is forwarded as ``some-tool -foo -foo``.
287 * Possible option properties:
289 - ``help`` - help string associated with this option. Used for ``--help``
292 - ``required`` - this option must be specified exactly once (or, in case of
293 the list options without the ``multi_val`` property, at least
294 once). Incompatible with ``optional`` and ``one_or_more``.
296 - ``optional`` - the option can be specified either zero times or exactly
297 once. The default for switch options. Useful only for list options in
298 conjunction with ``multi_val``. Incompatible with ``required``,
299 ``zero_or_more`` and ``one_or_more``.
301 - ``one_or_more`` - the option must be specified at least once. Can be useful
302 to allow switch options be both obligatory and be specified multiple
303 times. For list options is useful only in conjunction with ``multi_val``;
304 for ordinary it is synonymous with ``required``. Incompatible with
305 ``required``, ``optional`` and ``zero_or_more``.
307 - ``zero_or_more`` - the option can be specified zero or more times. Useful
308 to allow a single switch option to be specified more than
309 once. Incompatible with ``required``, ``optional`` and ``one_or_more``.
311 - ``hidden`` - the description of this option will not appear in
312 the ``--help`` output (but will appear in the ``--help-hidden``
315 - ``really_hidden`` - the option will not be mentioned in any help
318 - ``comma_separated`` - Indicates that any commas specified for an option's
319 value should be used to split the value up into multiple values for the
320 option. This property is valid only for list options. In conjunction with
321 ``forward_value`` can be used to implement option forwarding in style of
324 - ``multi_val n`` - this option takes *n* arguments (can be useful in some
325 special cases). Usage example: ``(parameter_list_option "foo", (multi_val
326 3))``; the command-line syntax is '-foo a b c'. Only list options can have
327 this attribute; you can, however, use the ``one_or_more``, ``optional``
328 and ``required`` properties.
330 - ``init`` - this option has a default value, either a string (if it is a
331 parameter), or a boolean (if it is a switch; as in C++, boolean constants
332 are called ``true`` and ``false``). List options can't have ``init``
334 Usage examples: ``(switch_option "foo", (init true))``; ``(prefix_option
335 "bar", (init "baz"))``.
339 Conditional evaluation
340 ======================
342 The 'case' construct is the main means by which programmability is achieved in
343 LLVMC. It can be used to calculate edge weights, program actions and modify the
344 shell commands to be executed. The 'case' expression is designed after the
345 similarly-named construct in functional languages and takes the form ``(case
346 (test_1), statement_1, (test_2), statement_2, ... (test_N), statement_N)``. The
347 statements are evaluated only if the corresponding tests evaluate to true.
351 // Edge weight calculation
353 // Increases edge weight by 5 if "-A" is provided on the
354 // command-line, and by 5 more if "-B" is also provided.
356 (switch_on "A"), (inc_weight 5),
357 (switch_on "B"), (inc_weight 5))
360 // Tool command line specification
362 // Evaluates to "cmdline1" if the option "-A" is provided on the
363 // command line; to "cmdline2" if "-B" is provided;
364 // otherwise to "cmdline3".
367 (switch_on "A"), "cmdline1",
368 (switch_on "B"), "cmdline2",
369 (default), "cmdline3")
371 Note the slight difference in 'case' expression handling in contexts of edge
372 weights and command line specification - in the second example the value of the
373 ``"B"`` switch is never checked when switch ``"A"`` is enabled, and the whole
374 expression always evaluates to ``"cmdline1"`` in that case.
376 Case expressions can also be nested, i.e. the following is legal::
378 (case (switch_on "E"), (case (switch_on "o"), ..., (default), ...)
381 You should, however, try to avoid doing that because it hurts readability. It is
382 usually better to split tool descriptions and/or use TableGen inheritance
385 * Possible tests are:
387 - ``switch_on`` - Returns true if a given command-line switch is provided by
388 the user. Can be given multiple arguments, in that case ``(switch_on "foo",
389 "bar", "baz")`` is equivalent to ``(and (switch_on "foo"), (switch_on
390 "bar"), (switch_on "baz"))``.
391 Example: ``(switch_on "opt")``.
393 - ``any_switch_on`` - Given a number of switch options, returns true if any of
394 the switches is turned on.
395 Example: ``(any_switch_on "foo", "bar", "baz")`` is equivalent to ``(or
396 (switch_on "foo"), (switch_on "bar"), (switch_on "baz"))``.
398 - ``parameter_equals`` - Returns true if a command-line parameter (first
399 argument) equals a given value (second argument).
400 Example: ``(parameter_equals "W", "all")``.
402 - ``element_in_list`` - Returns true if a command-line parameter list (first
403 argument) contains a given value (second argument).
404 Example: ``(element_in_list "l", "pthread")``.
406 - ``input_languages_contain`` - Returns true if a given language
407 belongs to the current input language set.
408 Example: ``(input_languages_contain "c++")``.
410 - ``in_language`` - Evaluates to true if the input file language is equal to
411 the argument. At the moment works only with ``command`` and ``actions`` (on
413 Example: ``(in_language "c++")``.
415 - ``not_empty`` - Returns true if a given option (which should be either a
416 parameter or a parameter list) is set by the user. Like ``switch_on``, can
417 be also given multiple arguments.
418 Examples: ``(not_empty "o")``, ``(not_empty "o", "l")``.
420 - ``any_not_empty`` - Returns true if ``not_empty`` returns true for any of
421 the provided options.
422 Example: ``(any_not_empty "foo", "bar", "baz")`` is equivalent to ``(or
423 (not_empty "foo"), (not_empty "bar"), (not_empty "baz"))``.
425 - ``empty`` - The opposite of ``not_empty``. Equivalent to ``(not (not_empty
426 X))``. Can be given multiple arguments.
428 - ``any_not_empty`` - Returns true if ``not_empty`` returns true for any of
429 the provided options.
430 Example: ``(any_empty "foo", "bar", "baz")`` is equivalent to ``(or
431 (not_empty "foo"), (not_empty "bar"), (not_empty "baz"))``.
433 - ``single_input_file`` - Returns true if there was only one input file
434 provided on the command-line. Used without arguments:
435 ``(single_input_file)``.
437 - ``multiple_input_files`` - Equivalent to ``(not (single_input_file))`` (the
438 case of zero input files is considered an error).
440 - ``default`` - Always evaluates to true. Should always be the last
441 test in the ``case`` expression.
443 - ``and`` - A standard logical combinator that returns true iff all of
444 its arguments return true. Used like this: ``(and (test1), (test2),
445 ... (testN))``. Nesting of ``and`` and ``or`` is allowed, but not
448 - ``or`` - A logical combinator that returns true iff any of its arguments
450 Example: ``(or (test1), (test2), ... (testN))``.
452 - ``not`` - Standard unary logical combinator that negates its
454 Example: ``(not (or (test1), (test2), ... (testN)))``.
457 Writing a tool description
458 ==========================
460 As was said earlier, nodes in the compilation graph represent tools, which are
461 described separately. A tool definition looks like this (taken from the
462 ``llvmc/src/Base.td`` file)::
464 def llvm_gcc_cpp : Tool<[
466 (out_language "llvm-assembler"),
467 (output_suffix "bc"),
468 (command "llvm-g++ -c -emit-llvm"),
472 This defines a new tool called ``llvm_gcc_cpp``, which is an alias for
473 ``llvm-g++``. As you can see, a tool definition is just a list of properties;
474 most of them should be self-explanatory. The ``sink`` property means that this
475 tool should be passed all command-line options that aren't mentioned in the
478 The complete list of all currently implemented tool properties follows.
480 * Possible tool properties:
482 - ``in_language`` - input language name. Can be given multiple arguments, in
483 case the tool supports multiple input languages. Used for typechecking and
484 mapping file extensions to tools.
486 - ``out_language`` - output language name. Multiple output languages are
487 allowed. Used for typechecking the compilation graph.
489 - ``output_suffix`` - output file suffix. Can also be changed dynamically, see
490 documentation on `actions`__.
494 - ``command`` - the actual command used to run the tool. You can use output
495 redirection with ``>``, hook invocations (``$CALL``), environment variables
496 (via ``$ENV``) and the ``case`` construct.
498 - ``join`` - this tool is a "join node" in the graph, i.e. it gets a list of
499 input files and joins them together. Used for linkers.
501 - ``sink`` - all command-line options that are not handled by other tools are
504 - ``actions`` - A single big ``case`` expression that specifies how this tool
505 reacts on command-line options (described in more detail `below`__).
509 - ``out_file_option``, ``in_file_option`` - Options appended to the
510 ``command`` string to designate output and input files. Default values are
511 ``"-o"`` and ``""``, respectively.
518 A tool often needs to react to command-line options, and this is precisely what
519 the ``actions`` property is for. The next example illustrates this feature::
521 def llvm_gcc_linker : Tool<[
522 (in_language "object-code"),
523 (out_language "executable"),
524 (output_suffix "out"),
525 (command "llvm-gcc"),
527 (actions (case (not_empty "L"), (forward "L"),
528 (not_empty "l"), (forward "l"),
530 [(append_cmd "-dummy1"), (append_cmd "-dummy2")])
533 The ``actions`` tool property is implemented on top of the omnipresent ``case``
534 expression. It associates one or more different *actions* with given
535 conditions - in the example, the actions are ``forward``, which forwards a given
536 option unchanged, and ``append_cmd``, which appends a given string to the tool
537 execution command. Multiple actions can be associated with a single condition by
538 using a list of actions (used in the example to append some dummy options). The
539 same ``case`` construct can also be used in the ``cmd_line`` property to modify
540 the tool command line.
542 The "join" property used in the example means that this tool behaves like a
545 The list of all possible actions follows.
549 - ``append_cmd`` - Append a string to the tool invocation command.
550 Example: ``(case (switch_on "pthread"), (append_cmd "-lpthread"))``.
552 - ``error`` - Exit with error.
553 Example: ``(error "Mixing -c and -S is not allowed!")``.
555 - ``warning`` - Print a warning.
556 Example: ``(warning "Specifying both -O1 and -O2 is meaningless!")``.
558 - ``forward`` - Forward the option unchanged.
559 Example: ``(forward "Wall")``.
561 - ``forward_as`` - Change the option's name, but forward the argument
563 Example: ``(forward_as "O0", "--disable-optimization")``.
565 - ``forward_value`` - Forward only option's value. Cannot be used with switch
566 options (since they don't have values), but works fine with lists.
567 Example: ``(forward_value "Wa,")``.
569 - ``forward_transformed_value`` - As above, but applies a hook to the
570 option's value before forwarding (see `below`__). When
571 ``forward_transformed_value`` is applied to a list
572 option, the hook must have signature
573 ``std::string hooks::HookName (const std::vector<std::string>&)``.
574 Example: ``(forward_transformed_value "m", "ConvertToMAttr")``.
578 - ``output_suffix`` - Modify the output suffix of this tool.
579 Example: ``(output_suffix "i")``.
581 - ``stop_compilation`` - Stop compilation after this tool processes its
582 input. Used without arguments.
583 Example: ``(stop_compilation)``.
589 If you are adding support for a new language to LLVMC, you'll need to modify the
590 language map, which defines mappings from file extensions to language names. It
591 is used to choose the proper toolchain(s) for a given input file set. Language
592 map definition looks like this::
594 def LanguageMap : LanguageMap<
595 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
596 LangToSuffixes<"c", ["c"]>,
600 For example, without those definitions the following command wouldn't work::
603 llvmc: Unknown suffix: cpp
605 The language map entries are needed only for the tools that are linked from the
606 root node. A tool can have multiple output languages.
611 It is sometimes useful to run error-checking code before processing the
612 compilation graph. For example, if optimization options "-O1" and "-O2" are
613 implemented as switches, we might want to output a warning if the user invokes
614 the driver with both of these options enabled.
616 The ``OptionPreprocessor`` feature is reserved specially for these
617 occasions. Example (adapted from ``llvm/src/Base.td.in``)::
620 def Preprocess : OptionPreprocessor<
621 (case (not (any_switch_on "O0", "O1", "O2", "O3")),
623 (and (switch_on "O3"), (any_switch_on "O0", "O1", "O2")),
624 (unset_option "O0", "O1", "O2"),
625 (and (switch_on "O2"), (any_switch_on "O0", "O1")),
626 (unset_option "O0", "O1"),
627 (and (switch_on "O1"), (switch_on "O0")),
631 Here, ``OptionPreprocessor`` is used to unset all spurious ``-O`` options so
632 that they are not forwarded to the compiler. If no optimization options are
633 specified, ``-O2`` is enabled.
635 ``OptionPreprocessor`` is basically a single big ``case`` expression, which is
636 evaluated only once right after the driver is started. The only allowed actions
637 in ``OptionPreprocessor`` are ``error``, ``warning``, and two special actions:
638 ``unset_option`` and ``set_option``. As their names suggest, they can be used to
639 set or unset a given option. To set an option with ``set_option``, use the
640 two-argument form: ``(set_option "parameter", VALUE)``. Here, ``VALUE`` can be
641 either a string, a string list, or a boolean constant.
643 For convenience, ``set_option`` and ``unset_option`` also work with multiple
644 arguments. That is, instead of ``[(unset_option "A"), (unset_option "B")]`` you
645 can use ``(unset_option "A", "B")``. Obviously, ``(set_option "A", "B")`` is
646 only valid if both ``A`` and ``B`` are switches.
654 Hooks and environment variables
655 -------------------------------
657 Normally, LLVMC searches for programs in the system ``PATH``. Sometimes, this is
658 not sufficient: for example, we may want to specify tool paths or names in the
659 configuration file. This can be achieved via the hooks mechanism. To write your
660 own hooks, add their definitions to the ``Hooks.cpp`` or drop a ``.cpp`` file
661 into your driver directory. Hooks should live in the ``hooks`` namespace and
662 have the signature ``std::string hooks::MyHookName ([const char* Arg0 [ const
663 char* Arg2 [, ...]]])``. They can be used from the ``command`` tool property::
665 (command "$CALL(MyHook)/path/to/file -o $CALL(AnotherHook)")
667 To pass arguments to hooks, use the following syntax::
669 (command "$CALL(MyHook, 'Arg1', 'Arg2', 'Arg # 3')/path/to/file -o1 -o2")
671 It is also possible to use environment variables in the same manner::
673 (command "$ENV(VAR1)/path/to/file -o $ENV(VAR2)")
675 To change the command line string based on user-provided options use
676 the ``case`` expression (documented `above`__)::
681 "llvm-g++ -E -x c $INFILE -o $OUTFILE",
683 "llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm"))
690 When writing LLVMC-based drivers, it can be useful to get a visual view of the
691 resulting compilation graph. This can be achieved via the command line option
692 ``--view-graph`` (which assumes that Graphviz_ and Ghostview_ are
693 installed). There is also a ``--write-graph`` option that creates a Graphviz
694 source file (``compilation-graph.dot``) in the current directory.
696 Another useful ``llvmc`` option is ``--check-graph``. It checks the compilation
697 graph for common errors like mismatched output/input language names, multiple
698 default edges and cycles. When invoked with ``--check-graph``, ``llvmc`` doesn't
699 perform any compilation tasks and returns the number of encountered errors as
700 its status code. In the future, these checks will be performed at compile-time
701 and this option will disappear.
703 .. _Graphviz: http://www.graphviz.org/
704 .. _Ghostview: http://pages.cs.wisc.edu/~ghost/
706 Conditioning on the executable name
707 -----------------------------------
709 For now, the executable name (the value passed to the driver in ``argv[0]``) is
710 accessible only in the C++ code (i.e. hooks). Use the following code::
713 extern const char* ProgramName;
718 std::string MyHook() {
720 if (strcmp(ProgramName, "mydriver") == 0) {
725 } // end namespace hooks
727 In general, you're encouraged not to make the behaviour dependent on the
728 executable file name, and use command-line switches instead. See for example how
729 the ``llvmc`` program behaves when it needs to choose the correct linker options
730 (think ``g++`` vs. ``gcc``).
736 <a href="http://jigsaw.w3.org/css-validator/check/referer">
737 <img src="http://jigsaw.w3.org/css-validator/images/vcss-blue"
738 alt="Valid CSS" /></a>
739 <a href="http://validator.w3.org/check?uri=referer">
740 <img src="http://www.w3.org/Icons/valid-xhtml10-blue"
741 alt="Valid XHTML 1.0 Transitional"/></a>
743 <a href="mailto:foldr@codedgers.com">Mikhail Glushenkov</a><br />
744 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br />
746 Last modified: $Date: 2008-12-11 11:34:48 -0600 (Thu, 11 Dec 2008) $