blob: 16e777cc3de19107dc0895af2208c5cfc524e48b [file] [log] [blame]
Reid Spencerb1254a12004-08-09 03:08:29 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3<head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title>The LLVM Compiler Driver (llvmc)</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
Reid Spenceraaa3da92004-08-17 09:18:37 +00007 <meta name="author" content="Reid Spencer">
Reid Spencerb1254a12004-08-09 03:08:29 +00008 <meta name="description"
9 content="A description of the use and design of the LLVM Compiler Driver.">
10</head>
11<body>
12<div class="doc_title">The LLVM Compiler Driver (llvmc)</div>
13<p class="doc_warning">NOTE: This document is a work in progress!</p>
14<ol>
15 <li><a href="#abstract">Abstract</a></li>
16 <li><a href="#introduction">Introduction</a>
17 <ol>
18 <li><a href="#purpose">Purpose</a></li>
19 <li><a href="#operation">Operation</a></li>
20 <li><a href="#phases">Phases</a></li>
21 <li><a href="#actions">Actions</a></li>
22 </ol>
23 </li>
Reid Spencerb1254a12004-08-09 03:08:29 +000024 <li><a href="#configuration">Configuration</a>
Reid Spencereefdae52004-08-21 22:37:42 +000025 <ol>
26 <li><a href="#overview">Overview</a></li>
27 <li><a href="#filetypes">Configuration Files</a></li>
28 <li><a href="#syntax">Syntax</a></li>
29 <li><a href="#substitutions">Substitutions</a></li>
30 <li><a href="#sample">Sample Config File</a></li>
31 </ol>
Reid Spencerb1254a12004-08-09 03:08:29 +000032 <li><a href="#glossary">Glossary</a>
33</ol>
34<div class="doc_author">
35<p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a>
36</p>
37</div>
38
39<!-- *********************************************************************** -->
40<div class="doc_section"> <a name="abstract">Abstract</a></div>
41<!-- *********************************************************************** -->
42<div class="doc_text">
43 <p>This document describes the requirements, design, and configuration of the
44 LLVM compiler driver, <tt>llvmc</tt>. The compiler driver knows about LLVM's
45 tool set and can be configured to know about a variety of compilers for
46 source languages. It uses this knowledge to execute the tools necessary
47 to accomplish general compilation, optimization, and linking tasks. The main
48 purpose of <tt>llvmc</tt> is to provide a simple and consistent interface to
49 all compilation tasks. This reduces the burden on the end user who can just
50 learn to use <tt>llvmc</tt> instead of the entire LLVM tool set and all the
51 source language compilers compatible with LLVM.</p>
52</div>
53<!-- *********************************************************************** -->
54<div class="doc_section"> <a name="introduction">Introduction</a></div>
55<!-- *********************************************************************** -->
56<div class="doc_text">
57 <p>The <tt>llvmc</tt> <a href="def_tool">tool</a> is a configurable compiler
58 <a href="def_driver">driver</a>. As such, it isn't the compiler, optimizer,
59 or linker itself but it drives (invokes) other software that perform those
60 tasks. If you are familiar with the GNU Compiler Collection's <tt>gcc</tt>
61 tool, <tt>llvmc</tt> is very similar.</p>
62 <p>The following introductory sections will help you understand why this tool
63 is necessary and what it does.</p>
64</div>
65
66<!-- _______________________________________________________________________ -->
67<div class="doc_subsection"><a name="purpose">Purpose</a></div>
68<div class="doc_text">
Reid Spencer46d21922004-08-22 18:06:59 +000069 <p><tt>llvmc</tt> was invented to make compilation of user programs with
70 LLVM-based tools easier. To accomplish this, <tt>llvmc</tt> strives to:</p>
Reid Spencerb1254a12004-08-09 03:08:29 +000071 <ul>
72 <li>Be the single point of access to most of the LLVM tool set.</li>
73 <li>Hide the complexities of the LLVM tools through a single interface.</li>
74 <li>Provide a consistent interface for compiling all languages.</li>
75 </ul>
76 <p>Additionally, <tt>llvmc</tt> makes it easier to write a compiler for use
77 with LLVM, because it:</p>
78 <ul>
79 <li>Makes integration of existing non-LLVM tools simple.</li>
Reid Spencer46d21922004-08-22 18:06:59 +000080 <li>Extends the capabilities of minimal compiler tools by optimizing their
Reid Spencerb1254a12004-08-09 03:08:29 +000081 output.</li>
82 <li>Reduces the number of interfaces a compiler writer must know about
83 before a working compiler can be completed (essentially only the VMCore
84 interfaces need to be understood).</li>
85 <li>Supports source language translator invocation via both dynamically
86 loadable shared objects and invocation of an executable.</li>
Reid Spenceraaa3da92004-08-17 09:18:37 +000087 </ul>
Reid Spencerb1254a12004-08-09 03:08:29 +000088</div>
89
90<!-- _______________________________________________________________________ -->
91<div class="doc_subsection"><a name="operation">Operation</a></div>
92<div class="doc_text">
93 <p>At a high level, <tt>llvmc</tt> operation is very simple. The basic action
94 taken by <tt>llvmc</tt> is to simply invoke some tool or set of tools to fill
95 the user's request for compilation. Every execution of <tt>llvmc</tt>takes the
Reid Spenceraaa3da92004-08-17 09:18:37 +000096 following sequence of steps:</p>
Reid Spencerb1254a12004-08-09 03:08:29 +000097 <dl>
98 <dt><b>Collect Command Line Options</b></dt>
99 <dd>The command line options provide the marching orders to <tt>llvmc</tt>
100 on what actions it should perform. This is the request the user is making
101 of <tt>llvmc</tt> and it is interpreted first. See the <tt>llvmc</tt>
102 <a href="CommandGuide/html/llvmc.html">manual page</a> for details on the
103 options.</dd>
104 <dt><b>Read Configuration Files</b></dt>
105 <dd>Based on the options and the suffixes of the filenames presented, a set
106 of configuration files are read to configure the actions <tt>llvmc</tt> will
Reid Spencer46d21922004-08-22 18:06:59 +0000107 take. Configuration files are provided by either LLVM or the
Reid Spenceraaa3da92004-08-17 09:18:37 +0000108 compiler tools that <tt>llvmc</tt> invokes. These files determine what
109 actions <tt>llvmc</tt> will take in response to the user's request. See
110 the section on <a href="#configuration">configuration</a> for more details.
111 </dd>
Reid Spencerb1254a12004-08-09 03:08:29 +0000112 <dt><b>Determine Phases To Execute</b></dt>
113 <dd>Based on the command line options and configuration files,
114 <tt>llvmc</tt> determines the compilation <a href="#phases">phases</a> that
115 must be executed by the user's request. This is the primary work of
116 <tt>llvmc</tt>.</dd>
117 <dt><b>Determine Actions To Execute</b></dt>
118 <dd>Each <a href="#phases">phase</a> to be executed can result in the
119 invocation of one or more <a href="#actions">actions</a>. An action is
120 either a whole program or a function in a dynamically linked shared library.
121 In this step, <tt>llvmc</tt> determines the sequence of actions that must be
122 executed. Actions will always be executed in a deterministic order.</dd>
123 <dt><b>Execute Actions</b></dt>
124 <dd>The <a href="#actions">actions</a> necessary to support the user's
125 original request are executed sequentially and deterministically. All
126 actions result in either the invocation of a whole program to perform the
127 action or the loading of a dynamically linkable shared library and invocation
128 of a standard interface function within that library.</dd>
129 <dt><b>Termination</b></dt>
130 <dd>If any action fails (returns a non-zero result code), <tt>llvmc</tt>
131 also fails and returns the result code from the failing action. If
132 everything succeeds, <tt>llvmc</tt> will return a zero result code.</dd>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000133 </dl>
Reid Spencerb1254a12004-08-09 03:08:29 +0000134 <p><tt>llvmc</tt>'s operation must be simple, regular and predictable.
135 Developers need to be able to rely on it to take a consistent approach to
136 compilation. For example, the invocation:</p>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000137 <code>
138 llvmc -O2 x.c y.c z.c -o xyz</code>
Reid Spencerb1254a12004-08-09 03:08:29 +0000139 <p>must produce <i>exactly</i> the same results as:</p>
Reid Spencer46d21922004-08-22 18:06:59 +0000140 <pre><tt>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000141 llvmc -O2 x.c
142 llvmc -O2 y.c
143 llvmc -O2 z.c
Reid Spencer46d21922004-08-22 18:06:59 +0000144 llvmc -O2 x.o y.o z.o -o xyz</tt></pre>
Reid Spencerb1254a12004-08-09 03:08:29 +0000145 <p>To accomplish this, <tt>llvmc</tt> uses a very simple goal oriented
146 procedure to do its work. The overall goal is to produce a functioning
147 executable. To accomplish this, <tt>llvmc</tt> always attempts to execute a
148 series of compilation <a href="#def_phase">phases</a> in the same sequence.
149 However, the user's options to <tt>llvmc</tt> can cause the sequence of phases
150 to start in the middle or finish early.</p>
151</div>
152
153<!-- _______________________________________________________________________ -->
154<div class="doc_subsection"><a name="phases"></a>Phases </div>
155<div class="doc_text">
156 <p><tt>llvmc</tt> breaks every compilation task into the following five
157 distinct phases:</p>
158 <dl><dt><b>Preprocessing</b></dt><dd>Not all languages support preprocessing;
159 but for those that do, this phase can be invoked. This phase is for
160 languages that provide combining, filtering, or otherwise altering with the
161 source language input before the translator parses it. Although C and C++
162 are the most common users of this phase, other languages may provide their
163 own preprocessor (whether its the C pre-processor or not).</dd>
164 </dl>
165 <dl><dt><b>Translation</b></dt><dd>The translation phase converts the source
166 language input into something that LLVM can interpret and use for
167 downstream phases. The translation is essentially from "non-LLVM form" to
168 "LLVM form".</dd>
169 </dl>
170 <dl><dt><b>Optimization</b></dt><dd>Once an LLVM Module has been obtained from
171 the translation phase, the program enters the optimization phase. This phase
172 attempts to optimize all of the input provided on the command line according
173 to the options provided.</dd>
174 </dl>
175 <dl><dt><b>Linking</b></dt><dd>The inputs are combined to form a complete
176 program.</dd>
177 </dl>
178 <p>The following table shows the inputs, outputs, and command line options
179 applicabe to each phase.</p>
180 <table>
181 <tr>
182 <th style="width: 10%">Phase</th>
183 <th style="width: 25%">Inputs</th>
184 <th style="width: 25%">Outputs</th>
185 <th style="width: 40%">Options</th>
186 </tr>
187 <tr><td><b>Preprocessing</b></td>
188 <td class="td_left"><ul><li>Source Language File</li></ul></td>
189 <td class="td_left"><ul><li>Source Language File</li></ul></td>
190 <td class="td_left"><dl>
191 <dt><tt>-E</tt></dt>
192 <dd>Stops the compilation after preprocessing</dd>
193 </dl></td>
194 </tr>
195 <tr>
196 <td><b>Translation</b></td>
197 <td class="td_left"><ul>
198 <li>Source Language File</li>
199 </ul></td>
200 <td class="td_left"><ul>
201 <li>LLVM Assembly</li>
202 <li>LLVM Bytecode</li>
203 <li>LLVM C++ IR</li>
204 </ul></td>
205 <td class="td_left"><dl>
206 <dt><tt>-c</tt></dt>
207 <dd>Stops the compilation after translation so that optimization and
208 linking are not done.</dd>
209 <dt><tt>-S</tt></dt>
210 <dd>Stops the compilation before object code is written so that only
211 assembly code remains.</dd>
212 </dl></td>
213 </tr>
214 <tr>
215 <td><b>Optimization</b></td>
216 <td class="td_left"><ul>
217 <li>LLVM Assembly</li>
218 <li>LLVM Bytecode</li>
219 </ul></td>
220 <td class="td_left"><ul>
221 <li>LLVM Bytecode</li>
222 </ul></td>
223 <td class="td_left"><dl>
224 <dt><tt>-Ox</tt>
Reid Spencer46d21922004-08-22 18:06:59 +0000225 <dd>This group of options controls the amount of optimization
Reid Spencerb1254a12004-08-09 03:08:29 +0000226 performed.</dd>
227 </dl></td>
228 </tr>
229 <tr>
230 <td><b>Linking</b></td>
231 <td class="td_left"><ul>
232 <li>LLVM Bytecode</li>
233 <li>Native Object Code</li>
234 <li>LLVM Library</li>
235 <li>Native Library</li>
236 </ul></td>
237 <td class="td_left"><ul>
238 <li>LLVM Bytecode Executable</li>
239 <li>Native Executable</li>
240 </ul></td>
241 <td class="td_left"><dl>
242 <dt><tt>-L</tt></dt><dd>Specifies a path for library search.</dd>
243 <dt><tt>-l</tt></dt><dd>Specifies a library to link in.</dd>
244 </dl></td>
245 </tr>
246 </table>
247</div>
248
249<!-- _______________________________________________________________________ -->
250<div class="doc_subsection"><a name="actions"></a>Actions</div>
251<div class="doc_text">
252 <p>An action, with regard to <tt>llvmc</tt> is a basic operation that it takes
253 in order to fulfill the user's request. Each phase of compilation will invoke
254 zero or more actions in order to accomplish that phase.</p>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000255 <p>Actions come in two forms:</p>
256 <ul>
Reid Spencerb1254a12004-08-09 03:08:29 +0000257 <li>Invokable Executables</li>
258 <li>Functions in a shared library</li>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000259 </ul>
Reid Spencerb1254a12004-08-09 03:08:29 +0000260</div>
261
262<!-- *********************************************************************** -->
Reid Spencerb1254a12004-08-09 03:08:29 +0000263<div class="doc_section"><a name="configuration">Configuration</a></div>
264<!-- *********************************************************************** -->
265<div class="doc_text">
266 <p>This section of the document describes the configuration files used by
267 <tt>llvmc</tt>. Configuration information is relatively static for a
Reid Spencer46d21922004-08-22 18:06:59 +0000268 given release of LLVM and a compiler tool. However, the details may
Reid Spencerb1254a12004-08-09 03:08:29 +0000269 change from release to release of either. Users are encouraged to simply use
Reid Spenceraaa3da92004-08-17 09:18:37 +0000270 the various options of the <tt>llvmc</tt> command and ignore the configuration
271 of the tool. These configuration files are for compiler writers and LLVM
272 developers. Those wishing to simply use <tt>llvmc</tt> don't need to understand
Reid Spencerb1254a12004-08-09 03:08:29 +0000273 this section but it may be instructive on how the tool works.</p>
274</div>
275
276<!-- _______________________________________________________________________ -->
277<div class="doc_subsection"><a name="overview"></a>Overview</div>
278<div class="doc_text">
279<p><tt>llvmc</tt> is highly configurable both on the command line and in
280configuration files. The options it understands are generic, consistent and
281simple by design. Furthermore, the <tt>llvmc</tt> options apply to the
282compilation of any LLVM enabled programming language. To be enabled as a
283supported source language compiler, a compiler writer must provide a
284configuration file that tells <tt>llvmc</tt> how to invoke the compiler
285and what its capabilities are. The purpose of the configuration files then
286is to allow compiler writers to specify to <tt>llvmc</tt> how the compiler
287should be invoked. Users may but are not advised to alter the compiler's
288<tt>llvmc</tt> configuration.</p>
289
290<p>Because <tt>llvmc</tt> just invokes other programs, it must deal with the
291available command line options for those programs regardless of whether they
Reid Spencer46d21922004-08-22 18:06:59 +0000292were written for LLVM or not. Furthermore, not all compiler tools will
293have the same capabilities. Some compiler tools will simply generate LLVM assembly
Reid Spencerb1254a12004-08-09 03:08:29 +0000294code, others will be able to generate fully optimized byte code. In general,
295<tt>llvmc</tt> doesn't make any assumptions about the capabilities or command
Reid Spenceraaa3da92004-08-17 09:18:37 +0000296line options of a sub-tool. It simply uses the details found in the
297configuration files and leaves it to the compiler writer to specify the
298configuration correctly.</p>
Reid Spencerb1254a12004-08-09 03:08:29 +0000299
Reid Spencer46d21922004-08-22 18:06:59 +0000300<p>This approach means that new compiler tools can be up and working very
301quickly. As a first cut, a tool can simply compile its source to raw
Reid Spencerb1254a12004-08-09 03:08:29 +0000302(unoptimized) bytecode or LLVM assembly and <tt>llvmc</tt> can be configured
303to pick up the slack (translate LLVM assembly to bytecode, optimize the
Reid Spencer46d21922004-08-22 18:06:59 +0000304bytecode, generate native assembly, link, etc.). In fact, the compiler tools
305need not use any LLVM libraries, and it could be written in any language
306(instead of C++). The configuration data will allow the full range of
307optimization, assembly, and linking capabilities that LLVM provides to be added
308to these kinds of tools. Enabling the rapid development of front-ends is one
309of the primary goals of <tt>llvmc</tt>.</p>
Reid Spencerb1254a12004-08-09 03:08:29 +0000310
Reid Spencer46d21922004-08-22 18:06:59 +0000311<p>As a compiler tool matures, it may utilize the LLVM libraries and tools
Reid Spencerb1254a12004-08-09 03:08:29 +0000312to more efficiently produce optimized bytecode directly in a single compilation
313and optimization program. In these cases, multiple tools would not be needed
314and the configuration data for the compiler would change.</p>
315
316<p>Configuring <tt>llvmc</tt> to the needs and capabilities of a source language
Reid Spencer46d21922004-08-22 18:06:59 +0000317compiler is relatively straight-forward. A compiler writer must provide a
Reid Spencerb1254a12004-08-09 03:08:29 +0000318definition of what to do for each of the five compilation phases for each of
319the optimization levels. The specification consists simply of prototypical
320command lines into which <tt>llvmc</tt> can substitute command line
321arguments and file names. Note that any given phase can be completely blank if
322the source language's compiler combines multiple phases into a single program.
323For example, quite often pre-processing, translation, and optimization are
324combined into a single program. The specification for such a compiler would have
325blank entries for pre-processing and translation but a full command line for
326optimization.</p>
327</div>
328
329<!-- _______________________________________________________________________ -->
Reid Spencer46d21922004-08-22 18:06:59 +0000330<div class="doc_subsection"><a name="filetypes">Configuration Files</a></div>
331<div class="doc_subsubsection"><a name="filecontents">File Contents</a></div>
Reid Spencerb1254a12004-08-09 03:08:29 +0000332<div class="doc_text">
Reid Spenceraaa3da92004-08-17 09:18:37 +0000333 <p>Each configuration file provides the details for a single source language
334 that is to be compiled. This configuration information tells <tt>llvmc</tt>
335 how to invoke the language's pre-processor, translator, optimizer, assembler
336 and linker. Note that a given source language needn't provide all these tools
337 as many of them exist in llvm currently.</p>
Reid Spencer46d21922004-08-22 18:06:59 +0000338</div>
339<div class="doc_subsubsection"><a name="dirsearch">Directory Search</a></div>
340<div class="doc_text">
Reid Spencerb1254a12004-08-09 03:08:29 +0000341 <p><tt>llvmc</tt> always looks for files of a specific name. It uses the
342 first file with the name its looking for by searching directories in the
343 following order:<br/>
344 <ol>
Reid Spencer46d21922004-08-22 18:06:59 +0000345 <li>Any directory specified by the <tt>-config-dir</tt> option will be
Reid Spencerb1254a12004-08-09 03:08:29 +0000346 checked first.</li>
347 <li>If the environment variable LLVM_CONFIG_DIR is set, and it contains
348 the name of a valid directory, that directory will be searched next.</li>
349 <li>If the user's home directory (typically <tt>/home/user</tt> contains
350 a sub-directory named <tt>.llvm</tt> and that directory contains a
351 sub-directory named <tt>etc</tt> then that directory will be tried
352 next.</li>
353 <li>If the LLVM installation directory (typically <tt>/usr/local/llvm</tt>
354 contains a sub-directory named <tt>etc</tt> then that directory will be
355 tried last.</li>
Reid Spencereefdae52004-08-21 22:37:42 +0000356 <li>A standard "system" directory will be searched next. This is typically
357 <tt>/etc/llvm</tt> on UNIX&trade; and <tt>C:\WINNT</tt> on Microsoft
358 Windows&trade;.</li>
Reid Spencerb1254a12004-08-09 03:08:29 +0000359 <li>If the configuration file sought still can't be found, <tt>llvmc</tt>
360 will print an error message and exit.</li>
361 </ol>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000362 <p>The first file found in this search will be used. Other files with the
363 same name will be ignored even if they exist in one of the subsequent search
Reid Spencerb1254a12004-08-09 03:08:29 +0000364 locations.</p>
Reid Spencer46d21922004-08-22 18:06:59 +0000365</div>
Reid Spencerb1254a12004-08-09 03:08:29 +0000366
Reid Spencer46d21922004-08-22 18:06:59 +0000367<div class="doc_subsubsection"><a name="filenames">File Names</a></div>
368<div class="doc_text">
Reid Spenceraaa3da92004-08-17 09:18:37 +0000369 <p>In the directories searched, each configuration file is given a specific
370 name to foster faster lookup (so llvmc doesn't have to do directory searches).
371 The name of a given language specific configuration file is simply the same
372 as the suffix used to identify files containing source in that language.
373 For example, a configuration file for C++ source might be named
374 <tt>cpp</tt>, <tt>C</tt>, or <tt>cxx</tt>. For languages that support multiple
375 file suffixes, multiple (probably identical) files (or symbolic links) will
376 need to be provided.</p>
Reid Spencer46d21922004-08-22 18:06:59 +0000377</div>
Reid Spencerb1254a12004-08-09 03:08:29 +0000378
Reid Spencer46d21922004-08-22 18:06:59 +0000379<div class="doc_subsubsection"><a name="whatgetsread">What Gets Read</a></div>
380<div class="doc_text">
Reid Spenceraaa3da92004-08-17 09:18:37 +0000381 <p>Which configuration files are read depends on the command line options and
382 the suffixes of the file names provided on <tt>llvmc</tt>'s command line. Note
Reid Spencer46d21922004-08-22 18:06:59 +0000383 that the <tt>-x LANGUAGE</tt> option alters the language that <tt>llvmc</tt>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000384 uses for the subsequent files on the command line. Only the configuration
385 files actually needed to complete <tt>llvmc</tt>'s task are read. Other
386 language specific files will be ignored.</p>
Reid Spencerb1254a12004-08-09 03:08:29 +0000387</div>
388
389<!-- _______________________________________________________________________ -->
390<div class="doc_subsection"><a name="syntax"></a>Syntax</div>
391<div class="doc_text">
Reid Spenceraaa3da92004-08-17 09:18:37 +0000392 <p>The syntax of the configuration files is very simple and somewhat
393 compatible with Java's property files. Here are the syntax rules:</p>
Reid Spencerb1254a12004-08-09 03:08:29 +0000394 <ul>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000395 <li>The file encoding is ASCII.</li>
Reid Spencereefdae52004-08-21 22:37:42 +0000396 <li>The file is line oriented. There should be one configuration definition
Reid Spencer46d21922004-08-22 18:06:59 +0000397 per line. Lines are terminated by the newline (0x0A) and/or carriage return
398 characters (0x0D)</li>
Reid Spencereefdae52004-08-21 22:37:42 +0000399 <li>A backslash (<tt>\</tt>) before a newline causes the newline to be
400 ignored. This is useful for line continuation of long definitions. A
401 backslash anywhere else is recognized as a backslash.</li>
Reid Spenceraaa3da92004-08-17 09:18:37 +0000402 <li>A configuration item consists of a name, an <tt>=</tt> and a value.</li>
403 <li>A name consists of a sequence of identifiers separated by period.</li>
404 <li>An identifier consists of specific keywords made up of only lower case
405 and upper case letters (e.g. <tt>lang.name</tt>).</li>
406 <li>Values come in four flavors: booleans, integers, commands and
407 strings.</li>
408 <li>Valid "false" boolean values are <tt>false False FALSE no No NO
409 off Off</tt> and <tt>OFF</tt>.</li>
410 <li>Valid "true" boolean values are <tt>true True TRUE yes Yes YES
411 on On</tt> and <tt>ON</tt>.</li>
412 <li>Integers are simply sequences of digits.</li>
413 <li>Commands start with a program name and are followed by a sequence of
414 words that are passed to that program as command line arguments. Program
Reid Spencer46d21922004-08-22 18:06:59 +0000415 arguments that begin and end with the <tt>%</tt> sign will have their value
Reid Spenceraaa3da92004-08-17 09:18:37 +0000416 substituted. Program names beginning with <tt>/</tt> are considered to be
417 absolute. Otherwise the <tt>PATH</tt> will be applied to find the program to
418 execute.</li>
419 <li>Strings are composed of multiple sequences of characters from the
420 character class <tt>[-A-Za-z0-9_:%+/\\|,]</tt> separated by white
421 space.</li>
422 <li>White space on a line is folded. Multiple blanks or tabs will be
423 reduced to a single blank.</li>
424 <li>White space before the configuration item's name is ignored.</li>
425 <li>White space on either side of the <tt>=</tt> is ignored.</li>
426 <li>White space in a string value is used to separate the individual
427 components of the string value but otherwise ignored.</li>
428 <li>Comments are introduced by the <tt>#</tt> character. Everything after a
429 <tt>#</tt> and before the end of line is ignored.</li>
430 </ul>
Reid Spencerb1254a12004-08-09 03:08:29 +0000431</div>
432
433<!-- _______________________________________________________________________ -->
Reid Spenceraaa3da92004-08-17 09:18:37 +0000434<div class="doc_subsection"><a name="items">Configuration Items</a></div>
Reid Spencerb1254a12004-08-09 03:08:29 +0000435<div class="doc_text">
Reid Spenceraaa3da92004-08-17 09:18:37 +0000436 <p>The table below provides definitions of the allowed configuration items
437 that may appear in a configuration file. Every item has a default value and
438 does not need to appear in the configuration file. Missing items will have the
439 default value. Each identifier may appear as all lower case, first letter
440 capitalized or all upper case.</p>
Reid Spencera2aa3042004-08-10 16:40:56 +0000441 <table>
Reid Spencereefdae52004-08-21 22:37:42 +0000442 <tbody>
443 <tr>
444 <th>Name</th>
445 <th>Value Type</th>
446 <th>Description</th>
447 <th>Default</th>
448 </tr>
449 <tr><td colspan="4"><h4>LANG ITEMS</h4></td></tr>
450 <tr>
451 <td><b>lang.name</b></td>
452 <td>string</td>
453 <td class="td_left">Provides the common name for a language definition.
454 For example "C++", "Pascal", "FORTRAN", etc.</td>
455 <td><i>blank</i></td>
456 </tr>
457 <tr>
458 <td><b>lang.opt1</b></td>
459 <td>string</td>
460 <td class="td_left">Specifies the parameters to give the optimizer when
461 <tt>-O1</tt> is specified on the <tt>llvmc</tt> command line.</td>
462 <td><tt>-simplifycfg -instcombine -mem2reg</tt></td>
463 </tr>
464 <tr>
465 <td><b>lang.opt2</b></td>
466 <td>string</td>
467 <td class="td_left">Specifies the parameters to give the optimizer when
468 <tt>-O2</tt> is specified on the <tt>llvmc</tt> command line.</td>
469 <td><i>TBD</i></td>
470 </tr>
471 <tr>
472 <td><b>lang.opt3</b></td>
473 <td>string</td>
474 <td class="td_left">Specifies the parameters to give the optimizer when
475 <tt>-O3</tt> is specified on the <tt>llvmc</tt> command line.</td>
476 <td><i>TBD</i></td>
477 </tr>
478 <tr>
479 <td><b>lang.opt4</b></td>
480 <td>string</td>
481 <td class="td_left">Specifies the parameters to give the optimizer when
482 <tt>-O4</tt> is specified on the <tt>llvmc</tt> command line.</td>
483 <td><i>TBD</i></td>
484 </tr>
485 <tr>
486 <td><b>lang.opt5</b></td>
487 <td>string</td>
488 <td class="td_left">Specifies the parameters to give the optimizer when
489 <tt>-O5</tt> is specified on the <tt>llvmc</tt> command line.</td>
490 <td><i>TBD</i></td>
491 </tr>
492 <tr><td colspan="4"><h4>PREPROCESSOR ITEMS</h4></td></tr>
493 <tr>
494 <td><b>preprocessor.command</b></td>
495 <td>command</td>
496 <td class="td_left">This provides the command prototype that will be used
497 to run the preprocessor. This is generally only used with the
498 <tt>-E</tt> option.</td>
499 <td>&lt;blank&gt;</td>
500 </tr>
501 <tr>
502 <td><b>preprocessor.required</b></td>
503 <td>boolean</td>
504 <td class="td_left">This item specifies whether the pre-processing phase
505 is required by the language. If the value is true, then the
506 <tt>preprocessor.command</tt> value must not be blank. With this option,
507 <tt>llvmc</tt> will always run the preprocessor as it assumes that the
508 translation and optimization phases don't know how to pre-process their
509 input.</td>
510 <td>false</td>
511 </tr>
512 <tr><td colspan="4"><h4>TRANSLATOR ITEMS</h4></td></tr>
513 <tr>
514 <td><b>translator.command</b></td>
515 <td>command</td>
516 <td class="td_left">This provides the command prototype that will be used
Reid Spencer46d21922004-08-22 18:06:59 +0000517 to run the translator. Valid substitutions are <tt>%in%</tt> for the
518 input file and <tt>%out%</tt> for the output file.</td>
Reid Spencereefdae52004-08-21 22:37:42 +0000519 <td>&lt;blank&gt;</td>
520 </tr>
521 <tr>
522 <td><b>translator.output</b></td>
523 <td><tt>native</tt>, <tt>bytecode</tt> or <tt>assembly</tt></td>
524 <td class="td_left">This item specifies the kind of output the language's
525 translator generates.</td>
526 <td><tt>bytecode</tt></td>
527 </tr>
528 <tr>
529 <td><b>translator.preprocesses</b></td>
530 <td>boolean</td>
531 <td class="td_left">Indicates that the translator also preprocesses. If
532 this is true, then <tt>llvmc</tt> will skip the pre-processing phase
533 whenever the final phase is not pre-processing.</td>
534 <td><tt>false</tt></td>
535 </tr>
536 <tr>
Reid Spencer46d21922004-08-22 18:06:59 +0000537 <td><b>translator.optimizes</b></td>
Reid Spencereefdae52004-08-21 22:37:42 +0000538 <td>boolean</td>
539 <td class="td_left">Indicates that the translator also optimizes. If
540 this is true, then <tt>llvmc</tt> will skip the optimization phase
541 whenever the final phase is optimization or later.</td>
542 <td><tt>false</tt></td>
543 </tr>
544 <tr>
545 <td><b>translator.groks_dash_o</b></td>
546 <td>boolean</td>
547 <td class="td_left">Indicates that the translator understands the
548 <i>intent</i> of the various <tt>-O</tt><i>n</i> options to
549 <tt>llvmc</tt>. This will cause the <tt>-O</tt><i>n</i> option to be
550 given to the translator instead of the equivalent options provided by
551 <tt>lang.opt</tt><i>n</i>.</td>
552 <td><tt>false</tt></td>
553 </tr>
554 <tr><td colspan="4"><h4>OPTIMIZER ITEMS</h4></td></tr>
555 <tr>
556 <td><b>optimizer.command</b></td>
557 <td>command</td>
558 <td class="td_left">This provides the command prototype that will be used
Reid Spencer46d21922004-08-22 18:06:59 +0000559 to run the optimizer. Valid substitutions are <tt>%in%</tt> for the
560 input file and <tt>%out%</tt> for the output file.</td>
Reid Spencereefdae52004-08-21 22:37:42 +0000561 <td>&lt;blank&gt;</td>
562 </tr>
563 <tr>
564 <td><b>optimizer.output</b></td>
565 <td><tt>native</tt>, <tt>bytecode</tt> or <tt>assembly</tt></td>
566 <td class="td_left">This item specifies the kind of output the language's
567 optimizer generates.</td>
568 <td><tt>bytecode</tt></td>
569 </tr>
570 <tr>
571 <td><b>optimizer.preprocesses</b></td>
572 <td>boolean</td>
573 <td class="td_left">Indicates that the optimizer also preprocesses. If
574 this is true, then <tt>llvmc</tt> will skip the pre-processing phase
575 whenever the final phase is optimization or later.</td>
576 <td><tt>false</tt></td>
577 </tr>
578 <tr>
579 <td><b>optimizer.translates</b></td>
580 <td>boolean</td>
581 <td class="td_left">Indicates that the optimizer also translates. If
582 this is true, then <tt>llvmc</tt> will skip the translation phase
583 whenever the final phase is optimization or later.</td>
584 <td><tt>false</tt></td>
585 </tr>
586 <tr>
587 <td><b>optimizer.groks_dash_o</b></td>
588 <td>boolean</td>
589 <td class="td_left">Indicates that the translator understands the
590 <i>intent</i> of the various <tt>-O</tt><i>n</i> options to
591 <tt>llvmc</tt>. This will cause the <tt>-O</tt><i>n</i> option to be
592 given to the translator instead of the equivalent options provided by
593 <tt>lang.opt</tt><i>n</i>.</td>
594 <td><tt>false</tt></td>
595 </tr>
596 <tr><td colspan="4"><h4>ASSEMBLER ITEMS</h4></td></tr>
597 <tr>
598 <td><b>assembler.command</b></td>
599 <td>command</td>
600 <td class="td_left">This provides the command prototype that will be used
Reid Spencer46d21922004-08-22 18:06:59 +0000601 to run the assembler. Valid substitutions are <tt>%in%</tt> for the
602 input file and <tt>%out%</tt> for the output file.</td>
Reid Spencereefdae52004-08-21 22:37:42 +0000603 <td>&lt;blank&gt;</td>
604 </tr>
605 <tr><td colspan="4"><h4>LINKER ITEMS</h4></td></tr>
606 <tr>
607 <td><b>linker.libs</b></td>
608 <td>library names</td>
609 <td class="td_left">This provides the list of runtime libraries that the
610 source language <i>could</i> link with. In general, the libraries
611 needed will be encoded into the LLVM Assembly or bytecode file.
612 However, this list tells <tt>llvmc</tt> the names of the ones that
613 apply to this source language. The names provided here should be
614 unadorned with no suffix and no "lib" prefix.
615 </td>
616 <td>&lt;blank&gt;</td>
617 </tr>
618 <tr>
619 <td><b>linker.lib_paths</b></td>
620 <td>Fully qualifed local path names</td>
621 <td class="td_left">This item provides a list of potential directories
622 in which the source language's runtime libraries might be located. If
623 a given object file compiled with this language's translator is linked
624 then those libraries will be given as <tt>-L</tt> options to the
625 linker.</td>
626 <td><tt>&lt;blank&gt;</tt></td>
627 </tr>
628 <tr>
629 <td><b>linker.output</b></td>
630 <td><tt>native</tt>, <tt>bytecode</tt> or <tt>assembly</tt></td>
631 <td class="td_left">This item specifies the kind of output the language's
632 translator generates.</td>
633 <td><tt>bytecode</tt></td>
634 </tr>
635 </tbody>
Reid Spencera2aa3042004-08-10 16:40:56 +0000636 </table>
Reid Spencerb1254a12004-08-09 03:08:29 +0000637</div>
638
Reid Spencereefdae52004-08-21 22:37:42 +0000639<!-- _______________________________________________________________________ -->
640<div class="doc_subsection"><a name="substitutions">Substitutions</a></div>
641<div class="doc_text">
642 <p>On any configruation item that ends in <tt>command</tt>, you must
643 specify substitution tokens. Substitution tokens begin and end with a percent
644 sign (<tt>%</tt>) and are replaced by the corresponding text. Any substitution
645 token may be given on any <tt>command</tt> line but some are more useful than
646 others. In particular each command <em>should</em> have both an <tt>%in%</tt>
647 and an <tt>%out%</tt> substittution. The table below provides definitions of
648 each of the allowed substitution tokens.</p>
649 <table>
650 <tbody>
651 <tr>
652 <th>Substitution Token</th>
653 <th>Replacement Description</th>
654 </tr>
655 <tr>
656 <td><tt>%args%</tt></td>
657 <td class="td_left">Replaced with all the tool-specific arguments given
658 to <tt>llvmc</tt> via the <tt>-T</tt> set of options. This just allows
659 you to place these arguments in the correct place on the command line.
Reid Spencer46d21922004-08-22 18:06:59 +0000660 If the <tt>%args%</tt> option does not appear on your command line,
661 then you are explicitly disallowing the <tt>-T</tt> option for your
662 tool.
Reid Spencereefdae52004-08-21 22:37:42 +0000663 </td>
664 <tr>
665 <td><tt>%in%</tt></td>
666 <td class="td_left">Replaced with the full path of the input file. You
667 needn't worry about the cascading of file names. <tt>llvmc</tt> will
668 create temporary files and ensure that the output of one phase is the
669 input to the next phase.</td>
670 </tr>
671 <tr>
672 <td><tt>%opt%</tt></td>
673 <td class="td_left">Replaced with the optimization options for the
674 tool. If the tool understands the <tt>-O</tt> options then that will
675 be passed. Otherwise, the <tt>lang.optN</tt> series of configuration
676 items will specify which arguments are to be given.</td>
677 </tr>
678 <tr>
679 <td><tt>%out%</tt></td>
680 <td class="td_left">Replaced with the full path of the output file.
681 Note that this is not necessarily the output file specified with the
682 <tt>-o</tt> option on <tt>llvmc</tt>'s command line. It might be a
683 temporary file that will be passed to a subsequent phase's input.
684 </td>
685 </tr>
686 <tr>
687 <td><tt>%stats%</tt></td>
688 <td class="td_left">If your command accepts the <tt>-stats</tt> option,
689 use this substitution token. If the user requested <tt>-stats</tt>
690 from the <tt>llvmc</tt> command line then this token will be replaced
691 with <tt>-stats</tt>, otherwise it will be ignored.
692 </td>
693 </tr>
694 <tr>
695 <td><tt>%target%</tt></td>
696 <td class="td_left">Replaced with the name of the target "machine" for
697 which code should be generated. The value used here is taken from the
698 <tt>llvmc</tt> option <tt>-march</tt>.
699 </td>
700 </tr>
701 <tr>
702 <td><tt>%time%</tt></td>
703 <td class="td_left">If your command accepts the <tt>-time-passes</tt>
704 option, use this substitution token. If the user requested
705 <tt>-time-passes</tt> from the <tt>llvmc</tt> command line then this
706 token will be replaced with <tt>-time-passes</tt>, otherwise it will
707 be ignored.
708 </td>
709 </tr>
710 </tbody>
711 </table>
712</div>
713
714<!-- _______________________________________________________________________ -->
715<div class="doc_subsection"><a name="sample">Sample Config File</a></div>
716<div class="doc_text">
717 <p>Since an example is always instructive, here's how the Stacker language
718 configuration file looks.</p>
719 <pre><tt>
720# Stacker Configuration File For llvmc
721
722##########################################################
723# Language definitions
724##########################################################
725 lang.name=Stacker
726 lang.opt1=-simplifycfg -instcombine -mem2reg
727 lang.opt2=-simplifycfg -instcombine -mem2reg -load-vn \
728 -gcse -dse -scalarrepl -sccp
729 lang.opt3=-simplifycfg -instcombine -mem2reg -load-vn \
730 -gcse -dse -scalarrepl -sccp -branch-combine -adce \
Reid Spencer46d21922004-08-22 18:06:59 +0000731 -globaldce -inline -licm
Reid Spencereefdae52004-08-21 22:37:42 +0000732 lang.opt4=-simplifycfg -instcombine -mem2reg -load-vn \
733 -gcse -dse -scalarrepl -sccp -ipconstprop \
Reid Spencer46d21922004-08-22 18:06:59 +0000734 -branch-combine -adce -globaldce -inline -licm
Reid Spencereefdae52004-08-21 22:37:42 +0000735 lang.opt5=-simplifycfg -instcombine -mem2reg --load-vn \
736 -gcse -dse scalarrepl -sccp -ipconstprop \
Reid Spencer46d21922004-08-22 18:06:59 +0000737 -branch-combine -adce -globaldce -inline -licm \
Reid Spencereefdae52004-08-21 22:37:42 +0000738 -block-placement
739
740##########################################################
741# Pre-processor definitions
742##########################################################
743
744 # Stacker doesn't have a preprocessor but the following
745 # allows the -E option to be supported
746 preprocessor.command=cp %in% %out%
747 preprocessor.required=false
748
749##########################################################
750# Translator definitions
751##########################################################
752
753 # To compile stacker source, we just run the stacker
754 # compiler with a default stack size of 2048 entries.
755 translator.command=stkrc -s 2048 %in% -o %out% %time% \
756 %stats% %args%
757
758 # stkrc doesn't preprocess but we set this to true so
759 # that we don't run the cp command by default.
760 translator.preprocesses=true
761
762 # The translator is required to run.
763 translator.required=true
764
765 # stkrc doesn't do any optimization, it just translates
766 translator.optimizes=no
767
768 # stkrc doesn't handle the -On options
769 translator.groks_dash_O=no
770
771##########################################################
772# Optimizer definitions
773##########################################################
774
775 # For optimization, we use the LLVM "opt" program
776 optimizer.command=opt %in% -o %out% %opt% %time% %stats% \
777 %args%
778
779 # opt doesn't (yet) grok -On
780 optimizer.groks_dash_O=no
781
782 # opt doesn't translate
783 optimizer.translates = no
784
785 # opt doesn't preprocess
786 optimizer.preprocesses=no
787
788##########################################################
789# Assembler definitions
790##########################################################
791 assembler.command=llc %in% -o %out% %target% \
792 "-regalloc=linearscan" %time% %stats%
793
794##########################################################
795# Linker definitions
796##########################################################
797 linker.libs=stkr_runtime
798 linker.paths=
799</tt></pre>
800
801
Reid Spencerb1254a12004-08-09 03:08:29 +0000802<!-- *********************************************************************** -->
803<div class="doc_section"><a name="glossary">Glossary</a></div>
804<!-- *********************************************************************** -->
805<div class="doc_text">
806 <p>This document uses precise terms in reference to the various artifacts and
807 concepts related to compilation. The terms used throughout this document are
808 defined below.</p>
809 <dl>
810 <dt><a name="def_assembly"><b>assembly</b></a></dt>
811 <dd>A compilation <a href="#def_phase">phase</a> in which LLVM bytecode or
812 LLVM assembly code is assembled to a native code format (either target
813 specific aseembly language or the platform's native object file format).
814 </dd>
815
816 <dt><a name="def_compiler"><b>compiler</b></a></dt>
817 <dd>Refers to any program that can be invoked by <tt>llvmc</tt> to accomplish
818 the work of one or more compilation <a href="#def_phase">phases</a>.</dd>
819
820 <dt><a name="def_driver"><b>driver</b></a></dt>
821 <dd>Refers to <tt>llvmc</tt> itself.</dd>
822
823 <dt><a name="def_linking"><b>linking</b></a></dt>
824 <dd>A compilation <a href="#def_phase">phase</a> in which LLVM bytecode files
825 and (optionally) native system libraries are combined to form a complete
826 executable program.</dd>
827
828 <dt><a name="def_optimization"><b>optimization</b></a></dt>
829 <dd>A compilation <a href="#def_phase">phase</a> in which LLVM bytecode is
830 optimized.</dd>
831
832 <dt><a name="def_phase"><b>phase</b></a></dt>
833 <dd>Refers to any one of the five compilation phases that that
834 <tt>llvmc</tt> supports. The five phases are:
835 <a href="#def_preprocessing">preprocessing</a>,
836 <a href="#def_translation">translation</a>,
837 <a href="#def_optimization">optimization</a>,
838 <a href="#def_assembly">assembly</a>,
839 <a href="#def_linking">linking</a>.</dd>
840
841 <dt><a name="def_sourcelanguage"><b>source language</b></a></dt>
842 <dd>Any common programming language (e.g. C, C++, Java, Stacker, ML,
843 FORTRAN). These languages are distinguished from any of the lower level
844 languages (such as LLVM or native assembly), by the fact that a
845 <a href="#def_translation">translation</a> <a href="#def_phase">phase</a>
846 is required before LLVM can be applied.</dd>
847
848 <dt><a name="def_tool"><b>tool</b></a></dt>
849 <dd>Refers to any program in the LLVM tool set.</dd>
850
851 <dt><a name="def_translation"><b>translation</b></a></dt>
852 <dd>A compilation <a href="#def_phase">phase</a> in which
853 <a href="#def_sourcelanguage">source language</a> code is translated into
854 either LLVM assembly language or LLVM bytecode.</dd>
855 </dl>
856</div>
857<!-- *********************************************************************** -->
858<hr>
859<address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
860 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a><a
861 href="http://validator.w3.org/check/referer"><img
862 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a><a
863 href="mailto:rspencer@x10sys.com">Reid Spencer</a><br>
864<a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
865Last modified: $Date$
866</address>
867<!-- vim: sw=2
868-->
869</body>
870</html>