llvm.org GIT mirror llvm / 03c993a
Validation fixes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42226 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 13 years ago
1 changed file(s) with 75 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
8585
8686
8787
  • Read the documentation.
  • 88
  • Read the documentation.
  • 88
  • Seriously, read the documentation.
  • 8989
  • Remember that you were warned twice about reading the documentation.
  • 9090
    9191
  • Get the Source Code
  • 202202 All these paths are absolute:

    203203
    204204
    205
    SRC_ROOT
    206
    207 This is the top level directory of the LLVM source tree.
    208

    209
    210
    OBJ_ROOT
    211
    212 This is the top level directory of the LLVM object tree (i.e. the
    213 tree where object files and compiled programs will be placed. It
    214 is fixed at SRC_ROOT/win32).
    215 <p>
    205 <dt>SRC_ROOT>
    206

    This is the top level directory of the LLVM source tree.

    207
    208
    OBJ_ROOT
    209

    This is the top level directory of the LLVM object tree (i.e. the

    210 tree where object files and compiled programs will be placed. It is
    211 fixed at SRC_ROOT/win32).

    216212
    217213
    218214
    226222
    227223

    The object files are placed under OBJ_ROOT/Debug for debug builds

    228224 and OBJ_ROOT/Release for release (optimized) builds. These include
    229 both executables and libararies that your application can link against.
    225 both executables and libararies that your application can link against.

    230226
    231227

    The files that configure would create when building on Unix are

    232228 created by the Configure project and placed in
    233229 OBJ_ROOT/llvm. You application must have OBJ_ROOT in its include
    234 search path just before SRC_ROOT/include.
    230 search path just before SRC_ROOT/include.

    235231
    236232
    237233
    244240
    245241
    246242
    247
  • First, create a simple C file, name it 'hello.c':
  • 248
    
                      
                    
    249 #include <stdio.h>
    250 int main() {
    251 printf("hello world\n");
    252 return 0;
    253 }
    254 >
    243
  • First, create a simple C file, name it 'hello.c':>

  • 244
    245
    246
    
                      
                    
    247 #include <stdio.h>
    248 int main() {
    249 printf("hello world\n");
    250 return 0;
    251 }
    252
    255253
    256254
  • Next, compile the C file into a LLVM bitcode file:

  • 257

    % llvm-gcc -c hello.c -emit-llvm -o hello.bc

    258
    259

    This will create the result file hello.bc which is the LLVM

    260 bitcode that corresponds the the compiled program and the library
    261 facilities that it required. You can execute this file directly using
    262 lli tool, compile it to native assembly with the llc,
    263 optimize or analyze it further with the opt tool, etc.

    255
    256
    257
    
                      
                    
    258 % llvm-gcc -c hello.c -emit-llvm -o hello.bc
    259
    260
    261
    262

    This will create the result file hello.bc which is the LLVM

    263 bitcode that corresponds the the compiled program and the library
    264 facilities that it required. You can execute this file directly using
    265 lli tool, compile it to native assembly with the llc,
    266 optimize or analyze it further with the opt tool, etc.

    264267
    265268

    Note: while you cannot do this step on Windows, you can do it on a

    266 Unix system and transfer hello.bc to Windows. Important:
    267 transfer as a binary file!

    269 Unix system and transfer hello.bc to Windows. Important:
    270 transfer as a binary file!

    268271
    269272
  • Run the program using the just-in-time compiler:

  • 270273
    271

    % lli hello.bc

    >
    274
    >
    275
    
                      
                    
    276 % lli hello.bc
    277
    278
    279
    280

    Note: this will only work for trivial C programs. Non-trivial programs

    281 (and any C++ program) will have dependencies on the GCC runtime that
    282 won't be satisfied by the Microsoft runtime libraries.

    283
    284
  • Use the llvm-dis utility to take a look at the LLVM assembly

  • 285 code:

    286
    287
    288
    
                      
                    
    289 % llvm-dis < hello.bc | more
    290
    291
    292
    293
  • Compile the program to C using the LLC code generator:

  • 294
    295
    296
    
                      
                    
    297 % llc -march=c hello.bc
    298
    299
    300
    301
  • Compile to binary using Microsoft C:

  • 302
    303
    304
    
                      
                    
    305 % cl hello.cbe.c
    306
    307
    272308
    273309

    Note: this will only work for trivial C programs. Non-trivial programs

    274310 (and any C++ program) will have dependencies on the GCC runtime that
    275 won't be satisfied by the Microsoft runtime libraries.

    276
    277
  • Use the llvm-dis utility to take a look at the LLVM assembly

  • 278 code:

    279
    280

    % llvm-dis < hello.bc | more

    281
    282
  • Compile the program to C using the LLC code generator:

  • 283
    284

    % llc -march=c hello.bc

    285
    286
  • Compile to binary using Microsoft C:

  • 287
    288

    % cl hello.cbe.c

    289
    290

    Note: this will only work for trivial C programs. Non-trivial programs

    291 (and any C++ program) will have dependencies on the GCC runtime that
    292 won't be satisfied by the Microsoft runtime libraries.

    311 won't be satisfied by the Microsoft runtime libraries.

    293312
    294313
  • Execute the native code program:

  • 295314
    296

    % hello.cbe.exe

    297
    315
    316
    
                      
                    
    317 % hello.cbe.exe
    318
    319
    298320
    299321
    300322
    331353
  • LLVM homepage
  • 332354
  • LLVM doxygen tree
  • 333355
  • Starting a Project
  • 334 that Uses LLVM
    356 that Uses LLVM
    335357
    336358
    337359