transfer type to 'local' context

Hi all,

is there an easy way to get a 'copy' of a type living in another context
into the local context?

Background:
when calling a function residing in a different module (context2) from a
module (context1), we first need to introduce a function declaration of
the function with empty body.

However, in order to do so, we need the function type.
pFuncInContext2->getType gives us the type in context2.
The returnType or argument type might refer to some types yet only
defined in context2 (e.g. special structs).

In order to get the functin declaration right, I would need to find out
if we have in context 1every necessary type referred to by the function
(in context2) and introduce it if not.

Is there an elegant way wrapping all this?
E.G. getTypeinLocalcontext(context1, pFuncTypeInContext2)?

Thx
Alex

Hi all,

is there an easy way to get a 'copy' of a type living in another context
into the local context?

No, as far as I know. (Probably not hard to write, if you really need it, though; the LLVM type system is pretty simple.)

Background:
when calling a function residing in a different module (context2) from a
module (context1), we first need to introduce a function declaration of
the function with empty body.

However, in order to do so, we need the function type.
pFuncInContext2->getType gives us the type in context2.
The returnType or argument type might refer to some types yet only
defined in context2 (e.g. special structs).

In order to get the functin declaration right, I would need to find out
if we have in context 1every necessary type referred to by the function
(in context2) and introduce it if not.

Is there an elegant way wrapping all this?
E.G. getTypeinLocalcontext(context1, pFuncTypeInContext2)?

Why are your modules in different contexts? IR linking normally involves loading all of the relevant modules into the same context.

-Eli

Hi Eli,

indeed, there is no need to use separate contexts for different modules,
my mistake. That solved it for me. Thanks!