mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-10 04:45:56 +03:00
multiple jit modules linking fixes and test
This commit is contained in:
parent
a6d788cdb5
commit
e55a84e846
5 changed files with 70 additions and 2 deletions
|
@ -165,8 +165,12 @@ void fixRtModule(llvm::Module &newModule,
|
||||||
std::unordered_set<std::string> externalFuncs;
|
std::unordered_set<std::string> externalFuncs;
|
||||||
for (auto &&it : funcs) {
|
for (auto &&it : funcs) {
|
||||||
assert(nullptr != it.first);
|
assert(nullptr != it.first);
|
||||||
assert(nullptr != it.second.thunkVar);
|
|
||||||
assert(nullptr != it.second.thunkFunc);
|
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()));
|
assert(!contains(thunkVar2func, it.second.thunkVar->getName()));
|
||||||
thunkVar2func.insert({it.second.thunkVar->getName(), it.first->getName()});
|
thunkVar2func.insert({it.second.thunkVar->getName(), it.first->getName()});
|
||||||
thunkFun2func.insert({it.second.thunkFunc->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;
|
std::vector<llvm::Constant *> elements;
|
||||||
for (auto &&it : irs->runtimeCompiledFunctions) {
|
for (auto &&it : irs->runtimeCompiledFunctions) {
|
||||||
assert(nullptr != it.first);
|
assert(nullptr != it.first);
|
||||||
assert(nullptr != it.second.thunkVar);
|
|
||||||
assert(nullptr != it.second.thunkFunc);
|
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();
|
auto name = it.first->getName();
|
||||||
llvm::Constant *fields[] = {
|
llvm::Constant *fields[] = {
|
||||||
createStringInitializer(irs->module, name),
|
createStringInitializer(irs->module, name),
|
||||||
|
|
10
tests/runtimecompile/inputs/module1.d
Normal file
10
tests/runtimecompile/inputs/module1.d
Normal 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();
|
||||||
|
}
|
10
tests/runtimecompile/inputs/module2.d
Normal file
10
tests/runtimecompile/inputs/module2.d
Normal 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();
|
||||||
|
}
|
13
tests/runtimecompile/inputs/module3.d
Normal file
13
tests/runtimecompile/inputs/module3.d
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module inputs.module3;
|
||||||
|
|
||||||
|
import ldc.attributes;
|
||||||
|
|
||||||
|
@runtimeCompile int get1()
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get2()
|
||||||
|
{
|
||||||
|
return 4;
|
||||||
|
}
|
27
tests/runtimecompile/multiple_modules.d
Normal file
27
tests/runtimecompile/multiple_modules.d
Normal 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());
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue