我正在制作一个基本的编译器,并希望将代码的源代码行放在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绑定btw,但我只想要一种适用于IR的方法)