Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing function parameters registers for load

functions are created like this:

llvm::FunctionType* FunctionTypePtr = llvm::FunctionType::get( returnTypePtr , types , false );
llvm::Function* llvmFunction = llvm::Function::Create(FunctionTypePtr,
                        llvm::GlobalValue::ExternalLinkage,
                        functionName,
                        llvmModule);

then the body of the function is created by adding instructions to the block:

llvm::BasicBlock* entryBlock = llvm::BasicBlock::Create(llvmContext, "", llvmFunction);
llvm::IRBuilder<> builder(entryBlock);

Enough context, now to the problem: I want to add load instructions for the function argument values, like:

//where do i get address??
llvm::LoadInst* load = builder.CreateLoad(address, "read");

I don't know how/where to grab the address variable for a function parameter.

like image 927
lurscher Avatar asked Mar 08 '26 11:03

lurscher


1 Answers

You should not load anything. Use Function::arg_iterator to get the Value's corresponding to the arguments.

See http://llvm.org/docs/doxygen/html/classllvm_1_1Function.html (arg_begin / arg_end) and http://llvm.org/docs/ProgrammersManual.html#Function for more information

like image 178
Anton Korobeynikov Avatar answered Mar 10 '26 09:03

Anton Korobeynikov