Question on using GlobalVariable as function pointer

Hi everyone,

  I am trying to have an call instruction that calls global variable

The first thing I do is

gv = new llvm::GlobalVariable( *(tb->getModule()),
                              fty,
                              false,GlobalValue::InternalLinkage,0,
                              "",0,0,0);

fty : i32 ({ i32, [32 x i32] }*)

I get stuck here, the fifth argument is the initializer which is a LLVM
Constant,

I do not know how to describe a function pointer as a constant.

so currently, I just pass false to it.

then I use

myjit->getOrEmitGlobalVariable(gv); // myjit is LLVM ExecutionEngine

but, I get an error

LLVM ERROR: Could not resolve external global address

However, when I modify fty to be an integer type or some primitive type,
there is no error.

Since LLVM demo page is closed, so I am not sure how to do it correctly.

Have A Nice Day

Chia Lun Liu

Hi Chia Lun Liu,

Hi everyone,

   I am trying to have an call instruction that calls global variable

The first thing I do is

gv = new llvm::GlobalVariable( *(tb->getModule()),
                              fty,
                              false,GlobalValue::InternalLinkage,0,
                              "",0,0,0);

fty : i32 ({ i32, [32 x i32] }*)

I get stuck here, the fifth argument is the initializer which is a LLVM
Constant,

I do not know how to describe a function pointer as a constant.

so currently, I just pass false to it.

If Func is the LLVM object of Function* type that represents the function you
want to call, then you can use it as the initial value. The Function class
derives from the GlobalValue class, and the GlobalValue class derives from the
Constant class, thus anything of type Function* can be used wherever a Constant*
is required.

Ciao, Duncan.