blob: 63b6de3abc596902bd05dcf3828c6d21155b3fd1 [file] [log] [blame]
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +00001Tutorial - Using LLVMC
2======================
3
4LLVMC is a generic compiler driver, which plays the same role for LLVM
5as the ``gcc`` program does for GCC - the difference being that LLVMC
6is designed to be more adaptable and easier to customize. This
7tutorial describes the basic usage and configuration of LLVMC.
8
9Compiling with LLVMC
10--------------------
11
12In general, LLVMC tries to be command-line compatible with ``gcc`` as
13much as possible, so most of the familiar options work::
14
15 $ llvmc2 -O3 -Wall hello.cpp
16 $ ./a.out
17 hello
18
19For further help on command-line LLVMC usage, refer to the ``llvmc
20--help`` output.
21
22Using LLVMC to generate toolchain drivers
23-----------------------------------------
24
25At the time of writing LLVMC does not support on-the-fly reloading of
26configuration, so it will be necessary to recompile its source
27code. LLVMC uses TableGen [1]_ as its configuration language, so
28you'll need to familiar with it.
29
30Start by compiling ``examples/Simple.td``, which is a simple wrapper
31for ``gcc``::
32
33 $ cd $LLVM_DIR/tools/llvmc2
34 $ make TOOLNAME=mygcc GRAPH=examples/Simple.td
35 $ edit hello.c
36 $ mygcc hello.c
37 $ ./hello.out
38 Hello
39
40Contents of the file ``Simple.td`` look like this::
41
42 // Include common definitions
43 include "Common.td"
44
45 // Tool descriptions
46 def gcc : Tool<
47 [(in_language "c"),
48 (out_language "executable"),
49 (output_suffix "out"),
50 (cmd_line "gcc $INFILE -o $OUTFILE"),
51 (sink)
52 ]>;
53
54 // Language map
55 def LanguageMap : LanguageMap<[LangToSuffixes<"c", ["c"]>]>;
56
57 // Compilation graph
58 def CompilationGraph : CompilationGraph<[Edge<root, gcc>]>;
59
60As you can see, this file consists of three parts: tool descriptions,
61language map, and the compilation graph definition.
62
63At the heart of LLVMC is the idea of a transformation graph: vertices
64in this graph are tools, and edges signify that there is a
65transformation path between two tools (for example, assembly source
66produced by the compiler can be transformed into executable code by an
67assembler). A special node named ``root`` is used to mark graph entry
68points.
69
70Tool descriptions are basically lists of properties: most properties
71in the example above should be self-explanatory; the ``sink`` property
72means that all options lacking an explicit description should be
73forwarded to this tool.
74
75``LanguageMap`` associates a language name with a list of suffixes and
76is used for deciding which toolchain corresponds to a given input
77file.
78
79To learn more about LLVMC customization, refer to the reference
80manual and sample configuration files in the ``examples`` directory.
81
82References
83==========
84
85.. [1] TableGen Fundamentals
86 http://llvm.cs.uiuc.edu/docs/TableGenFundamentals.html
87