问题描述
我是LLVM的新手,并尝试在Linux上生成易于阅读的.ll文件.我安装了llvm-gcc,但正如我所见,它只能生成汇编代码(-S选项).有什么方法可以像llvm在线生成的内容一样编译器?
I am a newbie to LLVM and try to generate a human readable .ll file on Linux. I installed llvm-gcc but as I see it can generate only assembly code (-S option). Is there any way to get something like what is generated by llvm online compiler?
这就是我在Linux上使用-S -emit-llvm
所得到的:
That's what I get with -S -emit-llvm
on Linux:
.file "hello.c"
.ident "GCC: (Ubuntu/Linaro 4.5.1-7ubuntu2) 4.5.1 LLVM: "
.text
.globl main
.align 16, 0x90
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $.L.str, 4(%esp)
movl $1, (%esp)
call __printf_chk
xorl %eax, %eax
addl $8, %esp
popl %ebp
ret
.Ltmp0:
.size main, .Ltmp0-main
.type .L.str,@object
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "hello world\n"
.size .L.str, 13
.section .note.GNU-stack,"",@progbits
这就是我想要得到的:
; ModuleID = '/tmp/webcompile/_7829_0.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-linux-gnu"
@.str = private constant [12 x i8] c"hello world\00", align 1 ; <[12 x i8]*> [#uses=1]
define i32 @main() nounwind {
entry:
%0 = tail call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
ret i32 0
}
declare i32 @puts(i8* nocapture) nounwind
在Windows上,我使用相同的命令llvm-gcc -S -emit-llvm hello.c
成功获取了此文件.
On windows I successfully get this file with the same command: llvm-gcc -S -emit-llvm hello.c
.
推荐答案
在llvm-gcc的ubuntu包装中发生了令人震惊的破坏. llvm-gcc的版本是4.2.1,但是在这里看到的是4.5.请报告Ubuntu错误.
Something is horrible broken in ubuntu packaging of llvm-gcc. llvm-gcc's version is 4.2.1, but here we're seeing 4.5. Please report Ubuntu bug.
这篇关于Linux中的-emit-llvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!