blob: 29c81443c9bbd785dbb870832a74463713ef47f5 [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
33you'll need to familiar with it.
34
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
69in this graph are tools, and edges signify that there is a
70transformation path between two tools (for example, assembly source
71produced by the compiler can be transformed into executable code by an
Mikhail Glushenkovee4d1d02008-05-30 06:16:32 +000072assembler). A special node named ``root`` is used to mark the graph
73entry points.
Mikhail Glushenkov1ce87222008-05-30 06:14:42 +000074
75Tool descriptions are basically lists of properties: most properties
76in the example above should be self-explanatory; the ``sink`` property
77means that all options lacking an explicit description should be
78forwarded to this tool.
79
80``LanguageMap`` associates a language name with a list of suffixes and
81is used for deciding which toolchain corresponds to a given input
82file.
83
84To learn more about LLVMC customization, refer to the reference
85manual and sample configuration files in the ``examples`` directory.
86
87References
88==========
89
90.. [1] TableGen Fundamentals
91 http://llvm.cs.uiuc.edu/docs/TableGenFundamentals.html
92