from within LLVM
> How is this done? Everything logical I have tried has failed, here was
> one attempt:
Can you give a few more details about what you are doing? Are you running
the verifier before writing out bytecode? Is your code operating as a
pass? Can you send a dump of the generated LLVM code?
I'm running this as a pass from opt (even though it's not really an
optimization). What it does is go thourgh and find parts of code that is a
program fragment, these it converts to a format string for printf, that's
why I need the gep and the printf calls. I no longer have this version of
the code so I can't really send it
Right now I am just generating two
seperate instructions, i.e.
%gep_x = getelementptr... ;<sbyte* from sbyte array>
call int %printf(sbyte* %gep_x, .....
This works fine, and aside from getting this thing to make strings for every
type of instruction it works great (note: this is a cheap hack Vikram and I
came up with, using printf's to dynamically generate code is not our final
plan
)
> Constant *C = (Constant*) ConstantArray::get(inst2string(I));
//fucnction defined elsewhere
One comment about this code: you don't need to have all of these casts.
In particular, above you don't need the (Constant*) cast, and you don't
need the (Value*) casts below.
I always over-cast, it's clearer for me to read, but probably for no one
else (and static pointer casts are just noops). I'll take those out.
> //generates a correct Global string
> GlobalVariable *str = new GlobalVariable(C->getType(), true,
> GlobalValue::InternalLinkage,
> C, mkStrName( strNumber++ ), &M);
You probably don't need mkStrName here. Just use a constant name like
"debugstr" or whatever. The symbol table class will autonumber them for
you to keep them unique, and is likely to be more efficient than this
implementation.
I did not realize that, thanks 
> std::vector<Value*> params; //params to a CallInst
> std::vector<Value*> indices; //indices to gep
> indices.push_back((Value*) (ConstantInt::get(Type::IntTy, 0)));
> indices.push_back((Value*) (ConstantInt::get(Type::IntTy, 0)));
> Constant *gep = ConstantExpr::getGetElementPtr( (Constant*) str,
indices);