0

我正在学习 llvm 教程: http: //llvm.org/releases/3.6.0/docs/tutorial/index.html

第 8 章的代码编译得很好并发出 IR,但是我无法编译发出的 IR。代码清单是复制和粘贴的,以减少我在某处的代码中出现拼写错误的机会。我唯一修改的是 build 命令,因为 llvm-config 默认为旧版本。构建命令:

clang++ -g -O3 toy.cpp `llvm-config-3.6 --cxxflags --ldflags --system-libs --libs core mcjit native` -o toy

运行它(我从原始命令中删除了 & ,因为这似乎会引发错误):

./toy < programs/basic.ks | clang-3.6 -x ir -

输出如下所示:

; ModuleID = 'my cool jit'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

declare double @printd(double)

define double @main() {
entry:
  %calltmp = call double @printd(double 4.200000e+01), !dbg !14
  ret double %calltmp, !dbg !14
}

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

!0 = !{i32 2, !"Debug Info Version", i32 2}
!1 = !{i32 2, !"Dwarf Version", i32 2}
!2 = !{!"0x11\002\00Kaleidoscope Compiler\000\00\000\00\001", !3, !4, !4, !5, !4, !4} ; [ DW_TAG_compile_unit ] [./fib.ks] [DW_LANG_C]
!3 = !{!"fib.ks", !"."}
!4 = !{}
!5 = !{!6, !11}
!6 = !{!"0x2e\00printd\00printd\00\001\000\001\000\000\00256\000\001", !3, !7, !8, null, double (double)* @printd, null, null, !4} ; [ DW_TAG_subprogram ] [line 1] [def] [printd]
!7 = !{!"0x29", !3}                               ; [ DW_TAG_file_type ] [./fib.ks]
!8 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !9, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
!9 = !{!10, !10}
!10 = !{!"0x24\00double\000\0064\0064\000\000\004", null, null} ; [ DW_TAG_base_type ] [double] [line 0, size 64, align 64, offset 0, enc DW_ATE_float]
!11 = !{!"0x2e\00main\00main\00\002\000\001\000\000\00256\000\002", !3, !7, !12, null, double ()* @main, null, null, !4} ; [ DW_TAG_subprogram ] [line 2] [def] [main]
!12 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !13, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
!13 = !{!10}
!14 = !MDLocation(line: 2, column: 8, scope: !11)
warning: overriding the module target triple with x86_64-apple-macosx10.10.0
1 warning generated.
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
4

1 回答 1

0

dump()示例代码使用打印到 stderr 的方法打印出 IR 。您应该在管道之前将 stderr 重定向到 stdout,如下所示:

./toy < programs/basic.ks 2>&1 | clang-3.6 -x ir -
于 2015-04-27T03:13:09.063 回答