| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 1 | <!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"> | 
|  | 7 | <style type="text/css"> | 
|  | 8 | TR, TD { border: 2px solid gray; padding: 4pt 4pt 2pt 2pt; } | 
|  | 9 | TH { border: 2px solid gray; font-weight: bold; font-size: 105%; } | 
|  | 10 | TABLE { text-align: center; border: 2px solid black; | 
|  | 11 | border-collapse: collapse; margin-top: 1em; margin-left: 1em; | 
|  | 12 | margin-right: 1em; margin-bottom: 1em; } | 
|  | 13 | .td_left { border: 2px solid gray; text-align: left; } | 
|  | 14 | </style> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 15 | <meta name="author" content="Reid Spencer"> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 16 | <meta name="description" | 
|  | 17 | content="A description of the use and design of the LLVM Compiler Driver."> | 
|  | 18 | </head> | 
|  | 19 | <body> | 
|  | 20 | <div class="doc_title">The LLVM Compiler Driver (llvmc)</div> | 
|  | 21 | <p class="doc_warning">NOTE: This document is a work in progress!</p> | 
|  | 22 | <ol> | 
|  | 23 | <li><a href="#abstract">Abstract</a></li> | 
|  | 24 | <li><a href="#introduction">Introduction</a> | 
|  | 25 | <ol> | 
|  | 26 | <li><a href="#purpose">Purpose</a></li> | 
|  | 27 | <li><a href="#operation">Operation</a></li> | 
|  | 28 | <li><a href="#phases">Phases</a></li> | 
|  | 29 | <li><a href="#actions">Actions</a></li> | 
|  | 30 | </ol> | 
|  | 31 | </li> | 
|  | 32 | <li><a href="#details">Details</a> | 
|  | 33 | <li><a href="#configuration">Configuration</a> | 
|  | 34 | <li><a href="#glossary">Glossary</a> | 
|  | 35 | </ol> | 
|  | 36 | <div class="doc_author"> | 
|  | 37 | <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> | 
|  | 38 | </p> | 
|  | 39 | </div> | 
|  | 40 |  | 
|  | 41 | <!-- *********************************************************************** --> | 
|  | 42 | <div class="doc_section"> <a name="abstract">Abstract</a></div> | 
|  | 43 | <!-- *********************************************************************** --> | 
|  | 44 | <div class="doc_text"> | 
|  | 45 | <p>This document describes the requirements, design, and configuration of the | 
|  | 46 | LLVM compiler driver, <tt>llvmc</tt>.  The compiler driver knows about LLVM's | 
|  | 47 | tool set and can be configured to know about a variety of compilers for | 
|  | 48 | source languages.  It uses this knowledge to execute the tools necessary | 
|  | 49 | to accomplish general compilation, optimization, and linking tasks. The main | 
|  | 50 | purpose of <tt>llvmc</tt> is to provide a simple and consistent interface to | 
|  | 51 | all compilation tasks. This reduces the burden on the end user who can just | 
|  | 52 | learn to use <tt>llvmc</tt> instead of the entire LLVM tool set and all the | 
|  | 53 | source language compilers compatible with LLVM.</p> | 
|  | 54 | </div> | 
|  | 55 | <!-- *********************************************************************** --> | 
|  | 56 | <div class="doc_section"> <a name="introduction">Introduction</a></div> | 
|  | 57 | <!-- *********************************************************************** --> | 
|  | 58 | <div class="doc_text"> | 
|  | 59 | <p>The <tt>llvmc</tt> <a href="def_tool">tool</a> is a configurable compiler | 
|  | 60 | <a href="def_driver">driver</a>. As such, it isn't the compiler, optimizer, | 
|  | 61 | or linker itself but it drives (invokes) other software that perform those | 
|  | 62 | tasks. If you are familiar with the GNU Compiler Collection's <tt>gcc</tt> | 
|  | 63 | tool, <tt>llvmc</tt> is very similar.</p> | 
|  | 64 | <p>The following introductory sections will help you understand why this tool | 
|  | 65 | is necessary and what it does.</p> | 
|  | 66 | </div> | 
|  | 67 |  | 
|  | 68 | <!-- _______________________________________________________________________ --> | 
|  | 69 | <div class="doc_subsection"><a name="purpose">Purpose</a></div> | 
|  | 70 | <div class="doc_text"> | 
|  | 71 | <p><tt>llvmc</tt> was invented to make compilation with LLVM based compilers | 
|  | 72 | easier. To accomplish this, <tt>llvmc</tt> strives to:</p> | 
|  | 73 | <ul> | 
|  | 74 | <li>Be the single point of access to most of the LLVM tool set.</li> | 
|  | 75 | <li>Hide the complexities of the LLVM tools through a single interface.</li> | 
|  | 76 | <li>Provide a consistent interface for compiling all languages.</li> | 
|  | 77 | </ul> | 
|  | 78 | <p>Additionally, <tt>llvmc</tt> makes it easier to write a compiler for use | 
|  | 79 | with LLVM, because it:</p> | 
|  | 80 | <ul> | 
|  | 81 | <li>Makes integration of existing non-LLVM tools simple.</li> | 
|  | 82 | <li>Extends the capabilities of minimal front ends by optimizing their | 
|  | 83 | output.</li> | 
|  | 84 | <li>Reduces the number of interfaces a compiler writer must know about | 
|  | 85 | before a working compiler can be completed (essentially only the VMCore | 
|  | 86 | interfaces need to be understood).</li> | 
|  | 87 | <li>Supports source language translator invocation via both dynamically | 
|  | 88 | loadable shared objects and invocation of an executable.</li> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 89 | </ul> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 90 | </div> | 
|  | 91 |  | 
|  | 92 | <!-- _______________________________________________________________________ --> | 
|  | 93 | <div class="doc_subsection"><a name="operation">Operation</a></div> | 
|  | 94 | <div class="doc_text"> | 
|  | 95 | <p>At a high level, <tt>llvmc</tt> operation is very simple.  The basic action | 
|  | 96 | taken by <tt>llvmc</tt> is to simply invoke some tool or set of tools to fill | 
|  | 97 | the user's request for compilation. Every execution of <tt>llvmc</tt>takes the | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 98 | following sequence of steps:</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 99 | <dl> | 
|  | 100 | <dt><b>Collect Command Line Options</b></dt> | 
|  | 101 | <dd>The command line options provide the marching orders to <tt>llvmc</tt> | 
|  | 102 | on what actions it should perform. This is the request the user is making | 
|  | 103 | of <tt>llvmc</tt> and it is interpreted first. See the <tt>llvmc</tt> | 
|  | 104 | <a href="CommandGuide/html/llvmc.html">manual page</a> for details on the | 
|  | 105 | options.</dd> | 
|  | 106 | <dt><b>Read Configuration Files</b></dt> | 
|  | 107 | <dd>Based on the options and the suffixes of the filenames presented, a set | 
|  | 108 | of configuration files are read to configure the actions <tt>llvmc</tt> will | 
|  | 109 | take.  Configuration files are provided by either LLVM or the front end | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 110 | compiler tools that <tt>llvmc</tt> invokes. These files determine what | 
|  | 111 | actions <tt>llvmc</tt> will take in response to the user's request. See | 
|  | 112 | the section on <a href="#configuration">configuration</a> for more details. | 
|  | 113 | </dd> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 114 | <dt><b>Determine Phases To Execute</b></dt> | 
|  | 115 | <dd>Based on the command line options and configuration files, | 
|  | 116 | <tt>llvmc</tt> determines the compilation <a href="#phases">phases</a> that | 
|  | 117 | must be executed by the user's request. This is the primary work of | 
|  | 118 | <tt>llvmc</tt>.</dd> | 
|  | 119 | <dt><b>Determine Actions To Execute</b></dt> | 
|  | 120 | <dd>Each <a href="#phases">phase</a> to be executed can result in the | 
|  | 121 | invocation of one or more <a href="#actions">actions</a>. An action is | 
|  | 122 | either a whole program or a function in a dynamically linked shared library. | 
|  | 123 | In this step, <tt>llvmc</tt> determines the sequence of actions that must be | 
|  | 124 | executed. Actions will always be executed in a deterministic order.</dd> | 
|  | 125 | <dt><b>Execute Actions</b></dt> | 
|  | 126 | <dd>The <a href="#actions">actions</a> necessary to support the user's | 
|  | 127 | original request are executed sequentially and deterministically. All | 
|  | 128 | actions result in either the invocation of a whole program to perform the | 
|  | 129 | action or the loading of a dynamically linkable shared library and invocation | 
|  | 130 | of a standard interface function within that library.</dd> | 
|  | 131 | <dt><b>Termination</b></dt> | 
|  | 132 | <dd>If any action fails (returns a non-zero result code), <tt>llvmc</tt> | 
|  | 133 | also fails and returns the result code from the failing action. If | 
|  | 134 | everything succeeds, <tt>llvmc</tt> will return a zero result code.</dd> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 135 | </dl> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 136 | <p><tt>llvmc</tt>'s operation must be simple, regular and predictable. | 
|  | 137 | Developers need to be able to rely on it to take a consistent approach to | 
|  | 138 | compilation. For example, the invocation:</p> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 139 | <code> | 
|  | 140 | llvmc -O2 x.c y.c z.c -o xyz</code> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 141 | <p>must produce <i>exactly</i> the same results as:</p> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 142 | <code> | 
|  | 143 | llvmc -O2 x.c | 
|  | 144 | llvmc -O2 y.c | 
|  | 145 | llvmc -O2 z.c | 
|  | 146 | llvmc -O2 x.o y.o z.o -o xyz</code> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 147 | <p>To accomplish this, <tt>llvmc</tt> uses a very simple goal oriented | 
|  | 148 | procedure to do its work. The overall goal is to produce a functioning | 
|  | 149 | executable. To accomplish this, <tt>llvmc</tt> always attempts to execute a | 
|  | 150 | series of compilation <a href="#def_phase">phases</a> in the same sequence. | 
|  | 151 | However, the user's options to <tt>llvmc</tt> can cause the sequence of phases | 
|  | 152 | to start in the middle or finish early.</p> | 
|  | 153 | </div> | 
|  | 154 |  | 
|  | 155 | <!-- _______________________________________________________________________ --> | 
|  | 156 | <div class="doc_subsection"><a name="phases"></a>Phases </div> | 
|  | 157 | <div class="doc_text"> | 
|  | 158 | <p><tt>llvmc</tt> breaks every compilation task into the following five | 
|  | 159 | distinct phases:</p> | 
|  | 160 | <dl><dt><b>Preprocessing</b></dt><dd>Not all languages support preprocessing; | 
|  | 161 | but for those that do, this phase can be invoked. This phase is for | 
|  | 162 | languages that provide combining, filtering, or otherwise altering with the | 
|  | 163 | source language input before the translator parses it. Although C and C++ | 
|  | 164 | are the most common users of this phase, other languages may provide their | 
|  | 165 | own preprocessor (whether its the C pre-processor or not).</dd> | 
|  | 166 | </dl> | 
|  | 167 | <dl><dt><b>Translation</b></dt><dd>The translation phase converts the source | 
|  | 168 | language input into something that LLVM can interpret and use for | 
|  | 169 | downstream phases. The translation is essentially from "non-LLVM form" to | 
|  | 170 | "LLVM form".</dd> | 
|  | 171 | </dl> | 
|  | 172 | <dl><dt><b>Optimization</b></dt><dd>Once an LLVM Module has been obtained from | 
|  | 173 | the translation phase, the program enters the optimization phase. This phase | 
|  | 174 | attempts to optimize all of the input provided on the command line according | 
|  | 175 | to the options provided.</dd> | 
|  | 176 | </dl> | 
|  | 177 | <dl><dt><b>Linking</b></dt><dd>The inputs are combined to form a complete | 
|  | 178 | program.</dd> | 
|  | 179 | </dl> | 
|  | 180 | <p>The following table shows the inputs, outputs, and command line options | 
|  | 181 | applicabe to each phase.</p> | 
|  | 182 | <table> | 
|  | 183 | <tr> | 
|  | 184 | <th style="width: 10%">Phase</th> | 
|  | 185 | <th style="width: 25%">Inputs</th> | 
|  | 186 | <th style="width: 25%">Outputs</th> | 
|  | 187 | <th style="width: 40%">Options</th> | 
|  | 188 | </tr> | 
|  | 189 | <tr><td><b>Preprocessing</b></td> | 
|  | 190 | <td class="td_left"><ul><li>Source Language File</li></ul></td> | 
|  | 191 | <td class="td_left"><ul><li>Source Language File</li></ul></td> | 
|  | 192 | <td class="td_left"><dl> | 
|  | 193 | <dt><tt>-E</tt></dt> | 
|  | 194 | <dd>Stops the compilation after preprocessing</dd> | 
|  | 195 | </dl></td> | 
|  | 196 | </tr> | 
|  | 197 | <tr> | 
|  | 198 | <td><b>Translation</b></td> | 
|  | 199 | <td class="td_left"><ul> | 
|  | 200 | <li>Source Language File</li> | 
|  | 201 | </ul></td> | 
|  | 202 | <td class="td_left"><ul> | 
|  | 203 | <li>LLVM Assembly</li> | 
|  | 204 | <li>LLVM Bytecode</li> | 
|  | 205 | <li>LLVM C++ IR</li> | 
|  | 206 | </ul></td> | 
|  | 207 | <td class="td_left"><dl> | 
|  | 208 | <dt><tt>-c</tt></dt> | 
|  | 209 | <dd>Stops the compilation after translation so that optimization and | 
|  | 210 | linking are not done.</dd> | 
|  | 211 | <dt><tt>-S</tt></dt> | 
|  | 212 | <dd>Stops the compilation before object code is written so that only | 
|  | 213 | assembly code remains.</dd> | 
|  | 214 | </dl></td> | 
|  | 215 | </tr> | 
|  | 216 | <tr> | 
|  | 217 | <td><b>Optimization</b></td> | 
|  | 218 | <td class="td_left"><ul> | 
|  | 219 | <li>LLVM Assembly</li> | 
|  | 220 | <li>LLVM Bytecode</li> | 
|  | 221 | </ul></td> | 
|  | 222 | <td class="td_left"><ul> | 
|  | 223 | <li>LLVM Bytecode</li> | 
|  | 224 | </ul></td> | 
|  | 225 | <td class="td_left"><dl> | 
|  | 226 | <dt><tt>-Ox</tt> | 
|  | 227 | <dd>This group of options affects the amount of optimization | 
|  | 228 | performed.</dd> | 
|  | 229 | </dl></td> | 
|  | 230 | </tr> | 
|  | 231 | <tr> | 
|  | 232 | <td><b>Linking</b></td> | 
|  | 233 | <td class="td_left"><ul> | 
|  | 234 | <li>LLVM Bytecode</li> | 
|  | 235 | <li>Native Object Code</li> | 
|  | 236 | <li>LLVM Library</li> | 
|  | 237 | <li>Native Library</li> | 
|  | 238 | </ul></td> | 
|  | 239 | <td class="td_left"><ul> | 
|  | 240 | <li>LLVM Bytecode Executable</li> | 
|  | 241 | <li>Native Executable</li> | 
|  | 242 | </ul></td> | 
|  | 243 | <td class="td_left"><dl> | 
|  | 244 | <dt><tt>-L</tt></dt><dd>Specifies a path for library search.</dd> | 
|  | 245 | <dt><tt>-l</tt></dt><dd>Specifies a library to link in.</dd> | 
|  | 246 | </dl></td> | 
|  | 247 | </tr> | 
|  | 248 | </table> | 
|  | 249 | </div> | 
|  | 250 |  | 
|  | 251 | <!-- _______________________________________________________________________ --> | 
|  | 252 | <div class="doc_subsection"><a name="actions"></a>Actions</div> | 
|  | 253 | <div class="doc_text"> | 
|  | 254 | <p>An action, with regard to <tt>llvmc</tt> is a basic operation that it takes | 
|  | 255 | in order to fulfill the user's request. Each phase of compilation will invoke | 
|  | 256 | zero or more actions in order to accomplish that phase.</p> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 257 | <p>Actions come in two forms:</p> | 
|  | 258 | <ul> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 259 | <li>Invokable Executables</li> | 
|  | 260 | <li>Functions in a shared library</li> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 261 | </ul> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 262 | </div> | 
|  | 263 |  | 
|  | 264 | <!-- *********************************************************************** --> | 
|  | 265 | <div class="doc_section"><a name="details">Details</a></div> | 
|  | 266 | <!-- *********************************************************************** --> | 
|  | 267 | <div class="doc_text"> | 
|  | 268 | </div> | 
|  | 269 |  | 
|  | 270 | <!-- *********************************************************************** --> | 
|  | 271 | <div class="doc_section"><a name="configuration">Configuration</a></div> | 
|  | 272 | <!-- *********************************************************************** --> | 
|  | 273 | <div class="doc_text"> | 
|  | 274 | <p>This section of the document describes the configuration files used by | 
|  | 275 | <tt>llvmc</tt>.  Configuration information is relatively static for a | 
|  | 276 | given release of LLVM and a front end compiler. However, the details may | 
|  | 277 | change from release to release of either.  Users are encouraged to simply use | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 278 | the various options of the <tt>llvmc</tt> command and ignore the configuration | 
|  | 279 | of the tool. These configuration files are for compiler writers and LLVM | 
|  | 280 | developers. Those wishing to simply use <tt>llvmc</tt> don't need to understand | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 281 | this section but it may be instructive on how the tool works.</p> | 
|  | 282 | </div> | 
|  | 283 |  | 
|  | 284 | <!-- _______________________________________________________________________ --> | 
|  | 285 | <div class="doc_subsection"><a name="overview"></a>Overview</div> | 
|  | 286 | <div class="doc_text"> | 
|  | 287 | <p><tt>llvmc</tt> is highly configurable both on the command line and in | 
|  | 288 | configuration files. The options it understands are generic, consistent and | 
|  | 289 | simple by design.  Furthermore, the <tt>llvmc</tt> options apply to the | 
|  | 290 | compilation of any LLVM enabled programming language. To be enabled as a | 
|  | 291 | supported source language compiler, a compiler writer must provide a | 
|  | 292 | configuration file that tells <tt>llvmc</tt> how to invoke the compiler | 
|  | 293 | and what its capabilities are. The purpose of the configuration files then | 
|  | 294 | is to allow compiler writers to specify to <tt>llvmc</tt> how the compiler | 
|  | 295 | should be invoked. Users may but are not advised to alter the compiler's | 
|  | 296 | <tt>llvmc</tt> configuration.</p> | 
|  | 297 |  | 
|  | 298 | <p>Because <tt>llvmc</tt> just invokes other programs, it must deal with the | 
|  | 299 | available command line options for those programs regardless of whether they | 
|  | 300 | were written for LLVM or not. Furthermore, not all compilation front ends will | 
|  | 301 | have the same capabilities. Some front ends will simply generate LLVM assembly | 
|  | 302 | code, others will be able to generate fully optimized byte code. In general, | 
|  | 303 | <tt>llvmc</tt> doesn't make any assumptions about the capabilities or command | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 304 | line options of a sub-tool. It simply uses the details found in the | 
|  | 305 | configuration files and leaves it to the compiler writer to specify the | 
|  | 306 | configuration correctly.</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 307 |  | 
|  | 308 | <p>This approach means that new compiler front ends can be up and working very | 
|  | 309 | quickly. As a first cut, a front end can simply compile its source to raw | 
|  | 310 | (unoptimized) bytecode or LLVM assembly and <tt>llvmc</tt> can be configured | 
|  | 311 | to pick up the slack (translate LLVM assembly to bytecode, optimize the | 
|  | 312 | bytecode, generate native assembly, link, etc.).   In fact, the front end need | 
|  | 313 | not use any LLVM libraries, and it could be written in any language (instead of | 
|  | 314 | C++).  The configuration data will allow the full range of optimization, | 
|  | 315 | assembly, and linking capabilities that LLVM provides to be added to these kinds | 
|  | 316 | of tools.  Enabling the rapid development of front-ends is one of the primary | 
|  | 317 | goals of <tt>llvmc</tt>.</p> | 
|  | 318 |  | 
|  | 319 | <p>As a compiler front end matures, it may utilize the LLVM libraries and tools | 
|  | 320 | to more efficiently produce optimized bytecode directly in a single compilation | 
|  | 321 | and optimization program. In these cases, multiple tools would not be needed | 
|  | 322 | and the configuration data for the compiler would change.</p> | 
|  | 323 |  | 
|  | 324 | <p>Configuring <tt>llvmc</tt> to the needs and capabilities of a source language | 
|  | 325 | compiler is relatively straight forward.  A compiler writer must provide a | 
|  | 326 | definition of what to do for each of the five compilation phases for each of | 
|  | 327 | the optimization levels. The specification consists simply of prototypical | 
|  | 328 | command lines into which <tt>llvmc</tt> can substitute command line | 
|  | 329 | arguments and file names. Note that any given phase can be completely blank if | 
|  | 330 | the source language's compiler combines multiple phases into a single program. | 
|  | 331 | For example, quite often pre-processing, translation, and optimization are | 
|  | 332 | combined into a single program. The specification for such a compiler would have | 
|  | 333 | blank entries for pre-processing and translation but a full command line for | 
|  | 334 | optimization.</p> | 
|  | 335 | </div> | 
|  | 336 |  | 
|  | 337 | <!-- _______________________________________________________________________ --> | 
|  | 338 | <div class="doc_subsection"><a name="filetypes"></a>Configuration Files</div> | 
|  | 339 | <div class="doc_text"> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 340 | <h3>File Contents</h3> | 
|  | 341 | <p>Each configuration file provides the details for a single source language | 
|  | 342 | that is to be compiled.  This configuration information tells <tt>llvmc</tt> | 
|  | 343 | how to invoke the language's pre-processor, translator, optimizer, assembler | 
|  | 344 | and linker. Note that a given source language needn't provide all these tools | 
|  | 345 | as many of them exist in llvm currently.</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 346 |  | 
|  | 347 | <h3>Directory Search</h3> | 
|  | 348 | <p><tt>llvmc</tt> always looks for files of a specific name. It uses the | 
|  | 349 | first file with the name its looking for by searching directories in the | 
|  | 350 | following order:<br/> | 
|  | 351 | <ol> | 
|  | 352 | <li>Any directory specified by the <tt>--config-dir</tt> option will be | 
|  | 353 | checked first.</li> | 
|  | 354 | <li>If the environment variable LLVM_CONFIG_DIR is set, and it contains | 
|  | 355 | the name of a valid directory, that directory will be searched next.</li> | 
|  | 356 | <li>If the user's home directory (typically <tt>/home/user</tt> contains | 
|  | 357 | a sub-directory named <tt>.llvm</tt> and that directory contains a | 
|  | 358 | sub-directory named <tt>etc</tt> then that directory will be tried | 
|  | 359 | next.</li> | 
|  | 360 | <li>If the LLVM installation directory (typically <tt>/usr/local/llvm</tt> | 
|  | 361 | contains a sub-directory named <tt>etc</tt> then that directory will be | 
|  | 362 | tried last.</li> | 
|  | 363 | <li>If the configuration file sought still can't be found, <tt>llvmc</tt> | 
|  | 364 | will print an error message and exit.</li> | 
|  | 365 | </ol> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 366 | <p>The first file found in this search will be used. Other files with the | 
|  | 367 | same name will be ignored even if they exist in one of the subsequent search | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 368 | locations.</p> | 
|  | 369 |  | 
|  | 370 | <h3>File Names</h3> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 371 | <p>In the directories searched, each configuration file is given a specific | 
|  | 372 | name to foster faster lookup (so llvmc doesn't have to do directory searches). | 
|  | 373 | The name of a given language specific configuration file is simply the same | 
|  | 374 | as the suffix used to identify files containing source in that language. | 
|  | 375 | For example, a configuration file for C++ source might be named | 
|  | 376 | <tt>cpp</tt>, <tt>C</tt>, or <tt>cxx</tt>. For languages that support multiple | 
|  | 377 | file suffixes, multiple (probably identical) files (or symbolic links) will | 
|  | 378 | need to be provided.</p> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 379 |  | 
|  | 380 | <h3>What Gets Read</h3> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 381 | <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 Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 383 | that the <tt>--x LANGUAGE</tt> option alters the language that <tt>llvmc</tt> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 384 | 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 Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 387 | </div> | 
|  | 388 |  | 
|  | 389 | <!-- _______________________________________________________________________ --> | 
|  | 390 | <div class="doc_subsection"><a name="syntax"></a>Syntax</div> | 
|  | 391 | <div class="doc_text"> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 392 | <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 Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 394 | <ul> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 395 | <li>The file encoding is ASCII.</li> | 
|  | 396 | <li>The file is line oriented. There should be one configuration item per | 
|  | 397 | line. Lines are terminated by the newline character (0x0A).</li> | 
|  | 398 | <li>A configuration item consists of a name, an <tt>=</tt> and a value.</li> | 
|  | 399 | <li>A name consists of a sequence of identifiers separated by period.</li> | 
|  | 400 | <li>An identifier consists of specific keywords made up of only lower case | 
|  | 401 | and upper case letters (e.g. <tt>lang.name</tt>).</li> | 
|  | 402 | <li>Values come in four flavors: booleans, integers, commands and | 
|  | 403 | strings.</li> | 
|  | 404 | <li>Valid "false" boolean values are <tt>false False FALSE no No NO | 
|  | 405 | off Off</tt> and <tt>OFF</tt>.</li> | 
|  | 406 | <li>Valid "true" boolean values are <tt>true True TRUE yes Yes YES | 
|  | 407 | on On</tt> and <tt>ON</tt>.</li> | 
|  | 408 | <li>Integers are simply sequences of digits.</li> | 
|  | 409 | <li>Commands start with a program name and are followed by a sequence of | 
|  | 410 | words that are passed to that program as command line arguments. Program | 
|  | 411 | arguments that begin and end with the <tt>@</tt> sign will have their value | 
|  | 412 | substituted. Program names beginning with <tt>/</tt> are considered to be | 
|  | 413 | absolute. Otherwise the <tt>PATH</tt> will be applied to find the program to | 
|  | 414 | execute.</li> | 
|  | 415 | <li>Strings are composed of multiple sequences of characters from the | 
|  | 416 | character class <tt>[-A-Za-z0-9_:%+/\\|,]</tt> separated by white | 
|  | 417 | space.</li> | 
|  | 418 | <li>White space on a line is folded. Multiple blanks or tabs will be | 
|  | 419 | reduced to a single blank.</li> | 
|  | 420 | <li>White space before the configuration item's name is ignored.</li> | 
|  | 421 | <li>White space on either side of the <tt>=</tt> is ignored.</li> | 
|  | 422 | <li>White space in a string value is used to separate the individual | 
|  | 423 | components of the string value but otherwise ignored.</li> | 
|  | 424 | <li>Comments are introduced by the <tt>#</tt> character. Everything after a | 
|  | 425 | <tt>#</tt> and before the end of line is ignored.</li> | 
|  | 426 | </ul> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 427 | </div> | 
|  | 428 |  | 
|  | 429 | <!-- _______________________________________________________________________ --> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 430 | <div class="doc_subsection"><a name="items">Configuration Items</a></div> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 431 | <div class="doc_text"> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 432 | <p>The table below provides definitions of the allowed configuration items | 
|  | 433 | that may appear in a configuration file. Every item has a default value and | 
|  | 434 | does not need to appear in the configuration file. Missing items will have the | 
|  | 435 | default value. Each identifier may appear as all lower case, first letter | 
|  | 436 | capitalized or all upper case.</p> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 437 | <table> | 
|  | 438 | <tr> | 
|  | 439 | <th>Name</th> | 
|  | 440 | <th>Value Type</th> | 
|  | 441 | <th>Description</th> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 442 | <th>Default</th> | 
|  | 443 | </tr> | 
|  | 444 | <tr><td colspan="4"><h4>LANG ITEMS</h4></td></tr> | 
|  | 445 | <tr> | 
|  | 446 | <td><b>lang.name</b></td> | 
|  | 447 | <td>string</td> | 
|  | 448 | <td class="td_left">Provides the common name for a language definition. | 
|  | 449 | For example "C++", "Pascal", "FORTRAN", etc.</td> | 
|  | 450 | <td><i>blank</i></td> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 451 | </tr> | 
|  | 452 | <tr> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 453 | <td><b>lang.opt1</b></td> | 
|  | 454 | <td>string</td> | 
|  | 455 | <td class="td_left">Specifies the parameters to give the optimizer when <tt>-O1</tt> is | 
|  | 456 | specified on the <tt>llvmc</tt> command line.</td> | 
|  | 457 | <td><tt>-simplifycfg -instcombine -mem2reg</tt></td> | 
|  | 458 | </tr> | 
|  | 459 | <tr> | 
|  | 460 | <td><b>lang.opt2</b></td> | 
|  | 461 | <td>string</td> | 
|  | 462 | <td class="td_left">Specifies the parameters to give the optimizer when <tt>-O2</tt> is | 
|  | 463 | specified on the <tt>llvmc</tt> command line.</td> | 
|  | 464 | <td><i>TBD</i></td> | 
|  | 465 | </tr> | 
|  | 466 | <tr> | 
|  | 467 | <td><b>lang.opt3</b></td> | 
|  | 468 | <td>string</td> | 
|  | 469 | <td class="td_left">Specifies the parameters to give the optimizer when <tt>-O3</tt> is | 
|  | 470 | specified on the <tt>llvmc</tt> command line.</td> | 
|  | 471 | <td><i>TBD</i></td> | 
|  | 472 | </tr> | 
|  | 473 | <tr> | 
|  | 474 | <td><b>lang.opt4</b></td> | 
|  | 475 | <td>string</td> | 
|  | 476 | <td class="td_left">Specifies the parameters to give the optimizer when <tt>-O4</tt> is | 
|  | 477 | specified on the <tt>llvmc</tt> command line.</td> | 
|  | 478 | <td><i>TBD</i></td> | 
|  | 479 | </tr> | 
|  | 480 | <tr> | 
|  | 481 | <td><b>lang.opt5</b></td> | 
|  | 482 | <td>string</td> | 
|  | 483 | <td class="td_left">Specifies the parameters to give the optimizer when <tt>-O5</tt> is | 
|  | 484 | specified on the <tt>llvmc</tt> command line.</td> | 
|  | 485 | <td><i>TBD</i></td> | 
|  | 486 | </tr> | 
|  | 487 | <tr><td colspan="4"><h4>PREPROCESSOR ITEMS</h4></td></tr> | 
|  | 488 | <tr> | 
|  | 489 | <td><b>preprocessor.command</b></td> | 
|  | 490 | <td>command</td> | 
|  | 491 | <td class="td_left">This provides the command prototype that will be used | 
|  | 492 | to run the preprocessor. Valid substitutions are <tt>@in@</tt> for the | 
|  | 493 | input file and <tt>@out@</tt> for the output file. This is generally only | 
|  | 494 | used with the <tt>-E</tt> option.</td> | 
|  | 495 | <td><blank></td> | 
|  | 496 | </tr> | 
|  | 497 | <tr> | 
|  | 498 | <td><b>preprocessor.required</b></td> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 499 | <td>boolean</td> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 500 | <td class="td_left">This item specifies whether the pre-processing phase | 
|  | 501 | is required by the language. If the value is true, then the | 
|  | 502 | <tt>preprocessor.command</tt> value must not be blank. With this option, | 
|  | 503 | <tt>llvmc</tt> will always run the preprocessor as it assumes that the | 
|  | 504 | translation and optimization phases don't know how to pre-process their | 
|  | 505 | input.</td> | 
|  | 506 | <td>false</td> | 
|  | 507 | </tr> | 
|  | 508 | <tr><td colspan="4"><h4>TRANSLATOR ITEMS</h4></td></tr> | 
|  | 509 | <tr> | 
|  | 510 | <td><b>translator.command</b></td> | 
|  | 511 | <td>command</td> | 
|  | 512 | <td class="td_left">This provides the command prototype that will be used | 
|  | 513 | to run the translator. Valid substitutions are <tt>@in@</tt> for the | 
|  | 514 | input file and <tt>@out@</tt> for the output file.</td> | 
|  | 515 | <td><blank></td> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 516 | </tr> | 
|  | 517 | <tr> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 518 | <td><b>translator.output</b></td> | 
|  | 519 | <td><tt>native</tt>, <tt>bytecode</tt> or <tt>assembly</tt></td> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 520 | <td class="td_left">This item specifies the kind of output the language's | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 521 | translator generates.</td> | 
|  | 522 | <td><tt>bytecode</tt></td> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 523 | </tr> | 
|  | 524 | <tr> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 525 | <td><b>translator.preprocesses</b></td> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 526 | <td>boolean</td> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 527 | <td class="td_left">Indicates that the translator also preprocesses. If this is true, then | 
|  | 528 | <tt>llvmc</tt> will skip the pre-processing phase whenever the final | 
|  | 529 | phase is not pre-processing.</td> | 
|  | 530 | <td><tt>false</tt></td> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 531 | </tr> | 
| Reid Spencer | aaa3da9 | 2004-08-17 09:18:37 +0000 | [diff] [blame^] | 532 | <tr> | 
|  | 533 | <td><b>translator.optimizers</b></td> | 
|  | 534 | <td>boolean</td> | 
|  | 535 | <td class="td_left">Indicates that the translator also optimizes. If this is true, then | 
|  | 536 | <tt>llvmc</tt> will skip the optimization phase whenever the final phase | 
|  | 537 | is optimization or later.</td> | 
|  | 538 | <td><tt>false</tt></td> | 
|  | 539 | </tr> | 
|  | 540 | <tr> | 
|  | 541 | <td><b>translator.groks_dash_o</b></td> | 
|  | 542 | <td>boolean</td> | 
|  | 543 | <td class="td_left">Indicates that the translator understands the <i>intent</i> of the | 
|  | 544 | various <tt>-O</tt><i>n</i> options to <tt>llvmc</tt>. This will cause the | 
|  | 545 | <tt>-O</tt><i>n</i> option to be based to the translator instead of the | 
|  | 546 | equivalent options provided by <tt>lang.opt</tt><i>n</i>.</td> | 
|  | 547 | <td><tt>false</tt></td> | 
|  | 548 | </tr> | 
|  | 549 | <tr><td colspan="4"><h4>OPTIMIZER ITEMS</h4></td></tr> | 
|  | 550 | <tr><td colspan="4"><h4>ASSEMBLER ITEMS</h4></td></tr> | 
|  | 551 | <tr><td colspan="4"><h4>LINKER ITEMS</h4></td></tr> | 
| Reid Spencer | a2aa304 | 2004-08-10 16:40:56 +0000 | [diff] [blame] | 552 | </table> | 
| Reid Spencer | b1254a1 | 2004-08-09 03:08:29 +0000 | [diff] [blame] | 553 | </div> | 
|  | 554 |  | 
|  | 555 | <!-- *********************************************************************** --> | 
|  | 556 | <div class="doc_section"><a name="glossary">Glossary</a></div> | 
|  | 557 | <!-- *********************************************************************** --> | 
|  | 558 | <div class="doc_text"> | 
|  | 559 | <p>This document uses precise terms in reference to the various artifacts and | 
|  | 560 | concepts related to compilation. The terms used throughout this document are | 
|  | 561 | defined below.</p> | 
|  | 562 | <dl> | 
|  | 563 | <dt><a name="def_assembly"><b>assembly</b></a></dt> | 
|  | 564 | <dd>A compilation <a href="#def_phase">phase</a> in which LLVM bytecode or | 
|  | 565 | LLVM assembly code is assembled to a native code format (either target | 
|  | 566 | specific aseembly language or the platform's native object file format). | 
|  | 567 | </dd> | 
|  | 568 |  | 
|  | 569 | <dt><a name="def_compiler"><b>compiler</b></a></dt> | 
|  | 570 | <dd>Refers to any program that can be invoked by <tt>llvmc</tt> to accomplish | 
|  | 571 | the work of one or more compilation <a href="#def_phase">phases</a>.</dd> | 
|  | 572 |  | 
|  | 573 | <dt><a name="def_driver"><b>driver</b></a></dt> | 
|  | 574 | <dd>Refers to <tt>llvmc</tt> itself.</dd> | 
|  | 575 |  | 
|  | 576 | <dt><a name="def_linking"><b>linking</b></a></dt> | 
|  | 577 | <dd>A compilation <a href="#def_phase">phase</a> in which LLVM bytecode files | 
|  | 578 | and (optionally) native system libraries are combined to form a complete | 
|  | 579 | executable program.</dd> | 
|  | 580 |  | 
|  | 581 | <dt><a name="def_optimization"><b>optimization</b></a></dt> | 
|  | 582 | <dd>A compilation <a href="#def_phase">phase</a> in which LLVM bytecode is | 
|  | 583 | optimized.</dd> | 
|  | 584 |  | 
|  | 585 | <dt><a name="def_phase"><b>phase</b></a></dt> | 
|  | 586 | <dd>Refers to any one of the five compilation phases that that | 
|  | 587 | <tt>llvmc</tt> supports. The five phases are: | 
|  | 588 | <a href="#def_preprocessing">preprocessing</a>, | 
|  | 589 | <a href="#def_translation">translation</a>, | 
|  | 590 | <a href="#def_optimization">optimization</a>, | 
|  | 591 | <a href="#def_assembly">assembly</a>, | 
|  | 592 | <a href="#def_linking">linking</a>.</dd> | 
|  | 593 |  | 
|  | 594 | <dt><a name="def_sourcelanguage"><b>source language</b></a></dt> | 
|  | 595 | <dd>Any common programming language (e.g. C, C++, Java, Stacker, ML, | 
|  | 596 | FORTRAN).  These languages are distinguished from any of the lower level | 
|  | 597 | languages (such as LLVM or native assembly), by the fact that a | 
|  | 598 | <a href="#def_translation">translation</a> <a href="#def_phase">phase</a> | 
|  | 599 | is required before LLVM can be applied.</dd> | 
|  | 600 |  | 
|  | 601 | <dt><a name="def_tool"><b>tool</b></a></dt> | 
|  | 602 | <dd>Refers to any program in the LLVM tool set.</dd> | 
|  | 603 |  | 
|  | 604 | <dt><a name="def_translation"><b>translation</b></a></dt> | 
|  | 605 | <dd>A compilation <a href="#def_phase">phase</a> in which | 
|  | 606 | <a href="#def_sourcelanguage">source language</a> code is translated into | 
|  | 607 | either LLVM assembly language or LLVM bytecode.</dd> | 
|  | 608 | </dl> | 
|  | 609 | </div> | 
|  | 610 | <!-- *********************************************************************** --> | 
|  | 611 | <hr> | 
|  | 612 | <address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img | 
|  | 613 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a><a | 
|  | 614 | href="http://validator.w3.org/check/referer"><img | 
|  | 615 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a><a | 
|  | 616 | href="mailto:rspencer@x10sys.com">Reid Spencer</a><br> | 
|  | 617 | <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br> | 
|  | 618 | Last modified: $Date$ | 
|  | 619 | </address> | 
|  | 620 | <!-- vim: sw=2 | 
|  | 621 | --> | 
|  | 622 | </body> | 
|  | 623 | </html> |