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