[llvm-dev] Need help with code generation

Bruce Hoult via llvm-dev llvm-dev at lists.llvm.org
Sat Mar 19 03:48:03 PDT 2016


If you've created a .bc or a .ll file then the simplest thing is to just
give it to clang exactly the same as you would for a .c file. Clang will
just Do The Right Thing with it.

If you don't want to link, then pass flags such as -c to clang as usual.

e.g.

---- hello.ll ----
declare i32 @puts(i8*)
@str = constant [12 x i8] c"Hello World\00"

define i32 @main() {
  %1 = call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @str, i64 0,
i64 0))
  ret i32 0
}
----------------

$ clang hello.ll -o hello && ./hello
warning: overriding the module target triple with x86_64-apple-macosx10.10.0
1 warning generated.
Hello World


On Sat, Mar 19, 2016 at 3:03 AM, Lorenzo Laneve via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I wrote my compiler and now it generates LLVM IR modules. Now i’d like to
> go ahead and make object file and then executable, just like clang does.
>
> What should I have to use to create the object files? and then how do I
> call the ld? (not llvm-ld, I want my compiler to work like Clang and I read
> that Clang doesn’t use llvm-ld).
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160319/fef015f9/attachment.html>


More information about the llvm-dev mailing list