Frage

I have read some webpages and articles about llvm and I am quite interested in this project. (Maybe to learn something about compiler writing without the need to struggle with the complicated points of x86).

There are pages that describe how to write llvm assembly and how to assemble it, but I did not find anything on what kind of environment is needed to actually execute these. I know that I could run llvm-gcc on my files to get an object file that is executable in a C-context. But in the case that I don't want to use the C runtime environmen (libc.so and friends), what is needed to run llvm code? Is there any documentation on that?

War es hilfreich?

Lösung

There appears to be an LLVM assembler.

llvm-as is the LLVM assembler. It reads a file containing human-readable LLVM assembly language, translates it to LLVM bitcode, and writes the result into a file or to standard output.

Andere Tipps

Quick setup: (For llvm 3.4.0 .ll files on windows)

advanced text editor from https://notepad-plus-plus.org/

llvm binaries from https://github.com/CRogers/LLVM-Windows-Binaries

hello.ll as "UTF-8 without BOM" (This code is in llvm 3.4.0 format):

@msg = internal constant [13 x i8] c"Hello World!\00"
declare i32 @puts(i8*)
define i32 @main() {
    call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @msg, i32 0, i32 0))
    ret i32 0
}

In command prompt:

lli hello.ll

Quick setup: (For llvm 3.8.0 .ll files on windows)

advanced text editor from https://notepad-plus-plus.org/

clang binaries from: http://llvm.org/releases/download.html#3.8.0

hello.ll as "UTF-8 without BOM" (This code is in llvm 3.8.0 format):

@msg = internal constant [13 x i8] c"Hello World!\00"
declare i32 @puts(i8*)
define i32 @main() {
    call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @msg, i32 0, i32 0))
    ret i32 0
}

In command prompt:

clang hello.ll -o hello.exe
hello.exe

Or as a single command:

clang hello.ll -o hello.exe & hello.exe

Errors about char16_t, u16String, etc means clang needs: -fms-compatibility-version=19

The static compiler, which accepts LLVM Assembly:

http://llvm.org/docs/CommandGuide/llc.html

The LLVM Assembly Language Reference:

http://llvm.org/docs/LangRef.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top