Hello All,
I am having a bit of trouble with inserting a function into some IR. My function takes in more than five arguments so I am trying to use the CreateCall(Value * Callee, ArrayRef<Value*> Args, const Twine & Name=””) method.
I believe where I am running into problems is the declaration part where I am using the getOrInsertFunction() method. Here is the code I have written so far:
//Function declaration for “mmap”
/*
Constant *b = M->getOrInsertFunction(“mmap”,
FunctionType::getInt8PtrTy(F.getContext()),
Type::getInt8PtrTy(F.getContext()),
Type::getInt8PtrTy(F.getContext()),
NULL);
Function *mmap = cast(b);
*/
Constant *b = M->getOrInsertFunction(“mmap”,
FunctionType::getInt8PtrTy(F.getContext()),
Type::getInt8PtrTy(F.getContext()),
Type::getInt32Ty(F.getContext()),
Type::getInt32Ty(F.getContext()),
Type::getInt32Ty(F.getContext()),
Type::getInt32Ty(F.getContext()),
Type::getInt32Ty(F.getContext()),
NULL);
Function *mmap = cast(b);
//IRBuilder responsible for inserting instructions into IR
IRBuilder<> builder(inst);
//Inserts the two variables and call for “open”
Value *strPtr = builder.CreateGlobalStringPtr(“/dev/mem”, “.str”);
ConstantInt *open_Argument = builder.getInt32(9437184);
Value *file_desc = builder.CreateCall2(open,strPtr,open_Argument);
//Inserts the 5 variables needed for “mmap”
ConstantInt *Arg1 = builder.getInt32(0);
ConstantInt *Arg2 = builder.getInt32(4096);
ConstantInt *Arg3 = builder.getInt32(3);
ConstantInt *Arg4 = builder.getInt32(1);
ConstantInt *Arg6 = builder.getInt32(1);
//Creates array of values to pass to “mmap”
std::vector<llvm::Value *> putsArgs;
putsArgs.push_back(Arg1);
putsArgs.push_back(Arg2);
putsArgs.push_back(Arg3);
putsArgs.push_back(Arg4);
putsArgs.push_back(file_desc);
putsArgs.push_back(Arg6);
llvm::ArrayRef<llvm::Value *> argsRef(putsArgs);
builder.CreateCall(mmap, putsArgs, “mmap”);
I have written two function declarations, but am unsure of which type I should use because I am passing an array as an argument. Is the function declaration supposed to accept each argument individually or will it be expecting a pointer type if I’m using an array? My assert error is just “Calling a function with a bad signature!”
Thanks for any help!
Josh