[LLVMdev] How to define a global variable?
Rob Nikander
rob.nikander at gmail.com
Wed Jan 12 14:28:49 PST 2011
Hi,
I'm trying to define a mutable variable, outside functions. The code
below is trying to evaluate an expression much like "x = 1" at the
module level in Python. It appears that when it tries to JIT the
function there is an error because there is no storage allocated for
'x'. How do I do that?
thanks,
Rob
----- dumped IR -----
; ModuleID = 'repl-module'
%0 = type opaque
@x = external global %0*
define %0* @0() {
entry:
store %0* inttoptr (i64 4316154480 to %0*), %0** @x
ret %0* inttoptr (i64 4316154480 to %0*)
}
LLVM ERROR: Could not resolve external global address: x
----- C++ code -----
GlobalVariable *gvar = new GlobalVariable(*module, id_ty, false,
GlobalVariable::ExternalLinkage, 0, str.str());
Value *valv = gen_expr(val);
builder.CreateStore(valv, gvar, false);
...
engine->getPointerToFunction(thunk);
More information about the llvm-dev
mailing list