Inputting initial information into LLVM bitcode files for debugging compiler errors

I am doing a basic compiler and want to put the source lines of code somewhere next to the llvm code that is created for easy debugging. For instance:

proc f(a:Int, b:Int):Int { return a + b; } start { print f(1,2); return 0; } 

It should somehow annotate the source with this:

 @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 } 

Any solutions / ways to do this? (I use llvm-fs bindings by the way, but I just need a way that will work with IR)

+4
source share

Source: https://habr.com/ru/post/1441372/


All Articles