There are many possible ways to do this, can you be a bit more specific
about what you're trying to do?
Here is a basic example:
Ah, ok, I see what you're trying to do. Below is some *pseudo* code for the basic idea:
unsigned int buff;
int main (void)
buff = 1;
// compile and execute code that will change buff to 2
Value *c0 = ConstantUInt::get (Type::UIntTy, 0);
Value *c2 = ConstantUInt::get (Type::UIntTy, 2);
Module *m = new Module ("test_module");
Here, create an LLVM GlobalVariable 'BuffGV' of the appropriate type, and insert it into m:
GlobalVariable *BuffGV = new GlobalVariable([4096 x uint], false, GlobalVariable::ExternalLinkage, 0, "Buff", m);
Function *f = m->getOrInsertFunction ("test_function", Type::VoidTy,
BasicBlock *b = new BasicBlock ("entry_block", f);
// Here is the problem.
// I need to get the buff pointer into variable, which I can
// pass to GetElementPtrInst
// Value *pbuff = ??
// -> %pbuff = external global [4096 x uint]
pbuff = BuffGV;
Value *ptr = new GetElementPtrInst (pbuff, c0, c0, "ptr", b);
// -> %ptr = getelementptr [4096 x uint]* %buff, int 0, int 0
new StoreInst (c2, ptr, b);
// -> store uint 2, uint* %ptr
new ReturnInst (b);
ExistingModuleProvider *mp = new ExistingModuleProvider (m);
ExecutionEngine *ee = ExecutionEngine::create (mp, false);
Tell the EE that buffGV -> buff:
Then you should be good to go!
cout << "constructed module:\n\n" << *m << "\n\n";
vector <GenericValue> args;
GenericValue ret = ee->runFunction (f, args);
printf ("buff is now: %d\n", buff);
I've been trying to do it with GlobalVariable. It seems like a
completely basic thing, but I just can't get it to work.
LLVM Developers mailing list