On Sun, 2006-06-25 at 17:49 -0400, Jerry Hom wrote:> This question is similar to Ryan Lefever's post on May 1, 2006 about
> printf declaration. In my case, I want to insert fprintf(stderr,
> ...) calls. I'm new to LLVM, and I don't know what's the
recipe for
> putting together the arguments. Can someone give me basic
> instructions or point me in the direction on what to do? I can't find
> any more documentation on this. Thanks!
Assumming that "PF" is a valid Function* for the fprintf function,
"BB"
is the basic block you want to insert the call into, and SE is a valid
Value* for stderr, you could just:
std::vector<Value*> args;
args.push_back(SE);
args.push_back(...);
Instruction* inst = new CallInst(PF,args,"call_to_printf",BB);
>
> Another question in reference to Ryan's post, can someone explain the
> purpose of this code, in particular the last 4 lines? Are the
> duplicate lines intentional?
>
> /* m is Module*, f is Function*, i is Instruction* */
> Constant* constStr = ConstantArray::get("test\n");
Get a constant [sbyte x 6] array of value "test\n\0"
> GlobalVariable* gv = new GlobalVariable
> (constStr->getType(), true, GlobalValue::InternalLinkage, constStr,
> "", m);
Create a new global variable of type [sbyte x 6] that is constant and
internal and initialized to constStr with no name and inserted into
module "m".
> std::vector<Constant*> geplist;
> geplist.push_back(ConstantUInt::get(Type::UIntTy,0));
> geplist.push_back(ConstantUInt::get(Type::UIntTy,0));
Set up a vector of 2 arguments for a subsequent GEP call (below).
> Constant* gep = ConstantExpr::getGetElementPtr(gv,geplist)
Create a GEP constant expression into the global variable gv, based on
the geplist arguments. This will effectively return the address of the
first byte of the string above. The type of the result is "sbyte*".
This is a very standard pattern for creating global constant strings and
accessing them. I've been doing a lot of this in HLVM recently :)
Reid.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20060625/06792ad9/attachment.sig>