Hello,
I have a question about setting up arguments for function declarations
and calls. I have two parameters that I would like to pass to a
function. One is an integer and the other is a string of characters. I
would like to somehow associate the character string with a pointer that
I can pass to the function, just like I've shown here for the integer.
The following is the code I'm working with so far:
// Declare the function as external
vector<const Type*> runTimeFuncArgs;
runTimeFuncArgs.push_back(Type::getInt32Ty(getGlobalContext())); // int
type, first arg
runTimeFuncArgs.push_back(ArrayType::get(Type::getInt8Ty(getGlobalContext()),
str.length() + 1)); // 2nd arg as an array
FunctionType *runTimeFuncType =
FunctionType::get(Type::getInt32Ty(getGlobalContext()), runTimeFuncArgs,
false);
Function *runTimeFunc = Function::Create(runTimeFuncType,
Function::ExternalLinkage, "myfunc", F.getParent());
// Call the function
vector <Value *> params;
int num = 0;
params.push_back(ConstantInt::get(Type::getInt32Ty(getGlobalContext()),
num));
params.push_back(ConstantArray::get(getGlobalContext(), str, true));
CallInst::Create(runTimeFunc, params.begin(), params.end(), "",
instruction);
However, this doesn't quite give me what I want. Instead of passing in
the entire array by value, I would like to somehow associate "str"
with
a char* and then use that as the parameter to the function. I wasn't
able to find an example of this in the documentation and was wondering
if you could point me in the right direction. I'm guessing there's a
simple solution to this that I have somehow overlooked.
Thanks,
Matt