[LLVMdev] Writing instructions to file

bhavani krishnan bhavi63 at yahoo.com
Mon Nov 17 20:30:43 PST 2008

Hello all,
I am instrumenting the code such that I write the results of some instructions to file. As you can see below, I am writing the results of add instruction to the file. The IR generated for writeToFile is also posted below. My problem is that it is writing to the file in format bytes  and it is not human-readable. How do I make it write human readable strings to the file?

define i32 @add(i32 %a, i32 %b) nounwind  {
	%tmp3 = add i32 %b, %a		; <i32> [#uses=2]
	alloca i32		; <i32*>:0 [#uses=2]
	store i32 %tmp3, i32* %0, align 4
	bitcast i32* %0 to i8*		; <i8*>:1 [#uses=1]
	tail call void @writeToFile( i8* %1 )
	ret i32 %tmp3

define void @writeToFile(i8* %str) {
	%tmp = tail call %struct.FILE* @fopen( i8* getelementptr ([8 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([2 x i8]* @.str1, i32 0, i32 0) )		; <%struct.FILE*> [#uses=3]
	%tmp2 = icmp eq %struct.FILE* %tmp, null		; <i1> [#uses=1]
	br i1 %tmp2, label %bb, label %bb5

bb:		; preds = %entry
	%tmp4 = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([20 x i8]* @.str2, i32 0, i32 0) )		; <i32> [#uses=0]
	ret void

bb5:		; preds = %entry
	%tmp8 = tail call i32 (%struct.FILE*, i8*, ...)* @fprintf( %struct.FILE* %tmp, i8* %str )		; <i32> [#uses=0]
	%tmp10 = tail call i32 @fclose( %struct.FILE* %tmp )		; <i32> [#uses=0]
	ret void

declare %struct.FILE* @fopen(i8*, i8*)

declare i32 @printf(i8*, ...)

declare i32 @fprintf(%struct.FILE*, i8*, ...)

declare i32 @fclose(%struct.FILE*)



More information about the llvm-dev mailing list