multiple jit modules linking fixes and test

This commit is contained in:
Ivan 2017-10-20 13:06:13 +03:00
parent a6d788cdb5
commit e55a84e846
5 changed files with 70 additions and 2 deletions

View file

@ -165,8 +165,12 @@ void fixRtModule(llvm::Module &newModule,
std::unordered_set<std::string> externalFuncs;
for (auto &&it : funcs) {
assert(nullptr != it.first);
assert(nullptr != it.second.thunkVar);
assert(nullptr != it.second.thunkFunc);
if (nullptr == it.second.thunkVar) {
// thunkVar is not available
// e.g. runtimeCompile function from other module, ignore
continue;
}
assert(!contains(thunkVar2func, it.second.thunkVar->getName()));
thunkVar2func.insert({it.second.thunkVar->getName(), it.first->getName()});
thunkFun2func.insert({it.second.thunkFunc->getName(), it.first->getName()});
@ -497,8 +501,12 @@ generateFuncList(IRState *irs, const Types &types) {
std::vector<llvm::Constant *> elements;
for (auto &&it : irs->runtimeCompiledFunctions) {
assert(nullptr != it.first);
assert(nullptr != it.second.thunkVar);
assert(nullptr != it.second.thunkFunc);
if (nullptr == it.second.thunkVar) {
// thunkVar is not available
// e.g. runtimeCompile function from other module, ignore
continue;
}
auto name = it.first->getName();
llvm::Constant *fields[] = {
createStringInitializer(irs->module, name),

View file

@ -0,0 +1,10 @@
module inputs.module1;
import inputs.module3;
import ldc.attributes;
@runtimeCompile int get()
{
return 3 + inputs.module3.get1() + inputs.module3.get2();
}

View file

@ -0,0 +1,10 @@
module inputs.module2;
import inputs.module3;
import ldc.attributes;
@runtimeCompile int get()
{
return 4 + inputs.module3.get1() + inputs.module3.get2();
}

View file

@ -0,0 +1,13 @@
module inputs.module3;
import ldc.attributes;
@runtimeCompile int get1()
{
return 3;
}
int get2()
{
return 4;
}

View file

@ -0,0 +1,27 @@
// RUN: %ldc -enable-runtime-compile -I%S %s %S/inputs/module1.d %S/inputs/module2.d %S/inputs/module3.d -run
import ldc.attributes;
import ldc.runtimecompile;
import inputs.module1;
import inputs.module2;
@runtimeCompile int foo()
{
return inputs.module1.get() + inputs.module2.get();
}
int bar()
{
return inputs.module1.get() + inputs.module2.get();
}
void main(string[] args)
{
compileDynamicCode();
assert(10 == inputs.module1.get());
assert(11 == inputs.module2.get());
assert(21 == foo());
assert(21 == bar());
}