[LLVMdev] convert a char * to a value
Nabila ABDESSAIED
nabila.abdessaied at gmail.com
Sat May 21 04:19:47 PDT 2011
2011/5/20 John Criswell <criswell at illinois.edu>
> On 5/20/11 5:46 PM, Nabila ABDESSAIED wrote:
>
> Hi all,
>
> Please i need help, I have a method that takes 2 arguments with type char
> *:
> void branchPredict(char *b1, char *b2){
> ---
> --
> }
> i'm supposed to add this method, in an IR basic bloc:
> to add it into a basic bloc i do:
>
>
> The problem is that you are passing arrays to the function instead of
> passing pointers to arrays. Instead of making tbname and pbname arguments
> to the function, you need to create GlobalVariable's that have, as their
> initializer, the Constant's tbname and pbname.
>
i couldn't use that sollution because i repeat the process in each basic
bloc in a function.
the globalvariable could be initiallized with constants that have the same
array type but in my case the constants i get in each basic bloc haven't the
same array type
>
> You may also have to take the GlobalVariables and insert a cast instruction
> (bitcast) to cast them from pointers to arrays to pointers of i8. However,
> that is easy to do.
>
> See line 138 of lib/DebugInstrumentation/DebugInstrumentation.cpp in the
> SAFECode source tree (directions for getting it from SVN are at
> http://safecode.cs.illinois.edu under the Download link). I think it is
> similar to what you want to do.
>
ok , i will use this.
i have seen it and here is what i did
std::string fbname =i->getNameStr();
std::string tbname
= i->getPrevNode()->getNameStr();
Constant * tname =
ConstantArray::get(Context, tbname);
Constant * fname =
ConstantArray::get(Context, fbname);
Value * TBloc, *FBloc;
TBloc = new GlobalVariable(M,
tname->getType(),
true,
GlobalValue::InternalLinkage,
tname,
"tBloc");
FBloc = new GlobalVariable(M,
fname->getType(),
true,
GlobalValue::InternalLinkage,
fname,
"fBloc");
std::vector<Value*> void_43_params;
void_43_params.push_back(TBloc);
void_43_params.push_back(FBloc);
CallInst* void_43 =
CallInst::Create(func_branchPredict, void_43_params.begin(),
void_43_params.end(), "", i->getTerminator());
but i have error :
Call parameter type does not match function signature!
[3 x i8]* @tBloc
i8* call void @branchPredict([3 x i8]* @tBloc, [3 x i8]* @fBloc)
Call parameter type does not match function signature!
[4 x i8]* @tBloc3
i8* call void @branchPredict([4 x i8]* @tBloc3, [4 x i8]* @fBloc4)
Broken module found, compilation aborted!
0 libLLVM-2.8.so.1 0x014c7628
Stack dump:
0. Program arguments: opt -load
/home/inspiron/PhdWork/llvm-2.8/Release/lib/Example.so -Example6
1. Running pass 'Function Pass Manager' on module '<stdin>'.
2. Running pass 'Module Verifier' on function '@main'
Aborted
>
> -- John T.
>
>
> //i: is the basic bloc
> std::vector<Value*> void_43_params;
> Constant* tbname = ConstantArray::get(M.getContext(),i->getNameStr() ,
> true);
> Constant* pbname = ConstantArray::get(M.getContext(),
> i->getPrevNode()->getNameStr(), true);
> void_43_params.push_back(tbname);
> void_43_params.push_back(pbname);
> CallInst* void_43 = CallInst::Create(func_branchPredict,
> void_43_params.begin(), void_43_params.end(), "", i->getTerminator());
>
> when i execute the pass (opt -load ....) i get an error:
>
>
> Call parameter type does not match function signature!
> [3 x i8] c"bb\00"
> i8* call void @branchPredict([3 x i8] c"bb\00", [4 x i8] c"bb1\00")
> Call parameter type does not match function signature!
> [4 x i8] c"bb5\00"
> i8* call void @branchPredict([4 x i8] c"bb5\00", [18 x i8]
> c"bb3.bb3_crit_edge\00")
> Broken module found, compilation aborted!
> 0 libLLVM-2.8.so.1 0x01421628
> Stack dump:
> 0. Program arguments: opt -load
> /home/inspiron/PhdWork/llvm-2.8/Release/lib/Example.so -Example6
> 1. Running pass 'Function Pass Manager' on module '<stdin>'.
> 2. Running pass 'Module Verifier' on function '@main'
> Aborted
>
>
> Any help
> thanks
>
>
> _______________________________________________
> LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110521/55686f1b/attachment.html>
More information about the llvm-dev
mailing list