store the LLVM-bitcode from a pass

Hi Duncan,

thanks for the answer. But “opt -load …/ -dec <prog.bc> new_prog.bc”
creates an invalid file. When i use “lli”, i get “lli: error loading program ‘new_prog.bc’: Invalid bitcode signature”

I have done the followings:

  1. used “opt -p -load …/ -dec <prog.bc> new_prog.bc”
  2. copied the output from the screen and created the file “new_prog.s”
  3. used “llvm-as new_prog.s -o new_prog.bc”
  4. and then “lli new_prog.bc”

And it works.

any idea?


Hi, take a look inside the file new_prog.bc. How does
it start?



These are the contents of the generated file.

Start >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ModuleID = ‘’
target datalayout = “e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32”
target triple = “i386-pc-linux-gnu”
@.str = internal constant [12 x i8] c"hello world\00" ; <[12 x i8]*> [#uses=1]

define i32 @main() {
call void (…)* @jLLVMAnnotation(i32 2)
call void (…)* @jLLVMAnnotation(i32 3, i32 4)
%0 = tail call i32 @puts(i8* getelementptr ([12 x i8]* @.str, i32 0, i32 0)) ; [#uses=0]
ret i32 0

declare i32 @puts(i8*)

define void @jLLVMAnnotation(…) {
ret void

d Q 2" e &DH &DÆBB&90 $£¥##@ÁF J E © ¢t<°6qhvHw¨|hspzØPåÐð s z0r s mq x xÐézzmqzv qms z0r s mv@z0r v@ms z0r s mv@z0r v@mv@zt v@mq x q x q xÐá z ztÐæp s z0r ó@2B 3$ $ Àd È 2L &GÆC:]Ðe6û
º¿ål2 S" A, # EP @2A c 0c 0ÇXá@ PÍa a Á à5S q @0 ÒØÀåkjMãLÀ8¾4E&@<Ô$

End <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

It looks like you appended the bitcode to an
existing file. Did you use >> rather than >.
Or are you on (horrors!) windows? Anyway, you
can always do this:

  opt -load ..../ -dec prog.bc -o new_prog.bc



Are dumping out something in your pass? If yes, use opt's "-o" options
(optionally -f see "opt -help") instead of a redirection ">".