我正在制作一个基本的编译器,并希望将源代码行放在为便于调试而生成的 llvm 代码附近的某个位置。例如:
proc f(a:Int, b:Int):Int {
return a + b;
}
start {
print f(1,2);
return 0;
}
应该以某种方式用源注释,如下所示:
@numFmt = internal constant [4 x i8] c"%d\0A\00"
declare i32 @printf(i8*, ...) nounwind
define i32 @main() {
entry:
%print.0 = call i32 @f(i32 1, i32 2) ; print f(1,2) maybe using a comment
%tmp.3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @numFmt, i32 0, i32 0), i32 %print.0)
"return 0 - or perhaps using a basic block":
ret i32 0
}
define i32 @f(i32 %a, i32 %b) {
entry:
"return a + b" = <or the result of some dummy operation that doesn't get stripped away"
%return.0 = add i32 %a, %b
ret i32 %return.0
}
有什么解决方案/方法吗?(顺便说一句,我正在使用 llvm-fs 绑定,但我只想要一种适用于 IR 的方法)