Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Last active July 15, 2019 23:16
Show Gist options
  • Save Risto-Stevcev/926a2858d00d1ed162fb4995086dde9d to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/926a2858d00d1ed162fb4995086dde9d to your computer and use it in GitHub Desktop.
LLVM hello world
; To emit LLVM from C code (for discovery):
; clang -emit-llvm -S hello.c -o hello.ll
; Declare the printf function
declare i32 @printf(i8*, ...)
@.str = private unnamed_addr constant [14 x i8] c"hello world!\0A\00"
define i32 @main() noinline optnone {
call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i32 0, i32 0))
ret i32 0
}
llc hello.ll && gcc -o hello hello.s && ./hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment