rename rtCompileProcess() to compileDynamicCode()

This commit is contained in:
Ivan 2017-09-03 18:20:03 +03:00
parent 6aa5a8e5a2
commit 5bb48d84c4
14 changed files with 21 additions and 35 deletions

View file

@ -243,7 +243,7 @@ void rtCompileProcessImplSoInternal(const RtComileModuleList* modlist_head, cons
SymMap symMap; SymMap symMap;
OptimizerSettings settings; OptimizerSettings settings;
settings.optLevel = context.optLevel; settings.optLevel = context.optLevel;
settings.sizeLeve = context.sizeLeve; settings.sizeLevel = context.sizeLevel;
while (nullptr != current) { while (nullptr != current) {
interruptPoint(context, "load IR"); interruptPoint(context, "load IR");
auto buff = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(current->irData, current->irDataSize), "", false); auto buff = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(current->irData, current->irDataSize), "", false);

View file

@ -13,7 +13,7 @@ typedef void (*DumpHandlerT)(void*, const char* str, std::size_t len);
struct Context final struct Context final
{ {
unsigned optLevel = 0; unsigned optLevel = 0;
unsigned sizeLeve = 0; unsigned sizeLevel = 0;
InterruptPointHandlerT interruptPointHandler = nullptr; InterruptPointHandlerT interruptPointHandler = nullptr;
void* interruptPointHandlerData = nullptr; void* interruptPointHandlerData = nullptr;
FatalHandlerT fatalHandler = nullptr; FatalHandlerT fatalHandler = nullptr;

View file

@ -124,7 +124,7 @@ void setupPasses(llvm::TargetMachine &targetMachine,
mpm.add(llvm::createStripDeadPrototypesPass()); mpm.add(llvm::createStripDeadPrototypesPass());
mpm.add(llvm::createStripDeadDebugInfoPass()); mpm.add(llvm::createStripDeadDebugInfoPass());
addOptimizationPasses(mpm, fpm, settings.optLevel, settings.sizeLeve); addOptimizationPasses(mpm, fpm, settings.optLevel, settings.sizeLevel);
} }
struct FuncFinalizer final { struct FuncFinalizer final {

View file

@ -16,7 +16,7 @@ struct Context;
struct OptimizerSettings final { struct OptimizerSettings final {
unsigned optLevel = 0; unsigned optLevel = 0;
unsigned sizeLeve = 0; unsigned sizeLevel = 0;
}; };
void optimizeModule(const Context &context, void optimizeModule(const Context &context,

View file

@ -6,31 +6,17 @@ version(LDC_RuntimeCompilation)
struct CompilerSettings struct CompilerSettings
{ {
uint optLevel = 0; uint optLevel = 0;
uint sizeLeve = 0; uint sizeLevel = 0;
void delegate(const char*,const char*) interruptHandler = null;
void delegate(const char*) fatalHandler = null;
void delegate(in char[]) dumpHandler = null; void delegate(in char[]) dumpHandler = null;
} }
void rtCompileProcess(in CompilerSettings settings = CompilerSettings.init) void compileDynamicCode(in CompilerSettings settings = CompilerSettings.init)
{ {
Context context; Context context;
context.optLevel = settings.optLevel; context.optLevel = settings.optLevel;
context.sizeLeve = settings.sizeLeve; context.sizeLevel = settings.sizeLevel;
if (settings.interruptHandler !is null)
{ context.fatalHandler = &defaultFatalHandler;
context.interruptPointHandler = &delegateWrapper!(const char*,const char*);
context.interruptPointHandlerData = cast(void*)&settings.interruptHandler;
}
if (settings.fatalHandler !is null)
{
context.fatalHandler = &delegateWrapper!(const char*);
context.fatalHandlerData = cast(void*)&settings.fatalHandler;
}
else
{
context.fatalHandler = &defaultFatalHandler;
}
if (settings.dumpHandler !is null) if (settings.dumpHandler !is null)
{ {
context.dumpHandler = &delegateWrapper!(const char*, size_t); context.dumpHandler = &delegateWrapper!(const char*, size_t);
@ -54,7 +40,7 @@ void delegateWrapper(T...)(void* context, T params)
void defaultFatalHandler(void*, const char* reason) void defaultFatalHandler(void*, const char* reason)
{ {
import std.conv; import std.conv;
throw new Exception(reason.text.idup); throw new Error(reason.text.idup);
} }
// must be synchronized with cpp // must be synchronized with cpp
@ -62,7 +48,7 @@ align(1) struct Context
{ {
align(1): align(1):
uint optLevel = 0; uint optLevel = 0;
uint sizeLeve = 0; uint sizeLevel = 0;
void function(void*, const char*, const char*) interruptPointHandler = null; void function(void*, const char*, const char*) interruptPointHandler = null;
void* interruptPointHandlerData = null; void* interruptPointHandlerData = null;
void function(void*, const char*) fatalHandler = null; void function(void*, const char*) fatalHandler = null;

View file

@ -22,7 +22,7 @@ __gshared int[555] arr2 = 42;
void main(string[] args) void main(string[] args)
{ {
rtCompileProcess(); compileDynamicCode();
assert(42 == foo()); assert(42 == foo());
assert(0 == bar()); assert(0 == bar());
} }

View file

@ -26,7 +26,7 @@ void main(string[] args)
auto fun = &f1.foo; auto fun = &f1.foo;
f1.val = 42; f1.val = 42;
rtCompileProcess(); compileDynamicCode();
assert(42 == f1.foo()); assert(42 == f1.foo());
assert(42 == f2.foo()); assert(42 == f2.foo());
assert(42 == fun()); assert(42 == fun());

View file

@ -15,7 +15,7 @@ void main(string[] args)
bool dumpHandlerCalled = false; bool dumpHandlerCalled = false;
CompilerSettings settings; CompilerSettings settings;
settings.dumpHandler = ((a) { dumpHandlerCalled = true; }); settings.dumpHandler = ((a) { dumpHandlerCalled = true; });
rtCompileProcess(settings); compileDynamicCode(settings);
assert(5 == foo()); assert(5 == foo());
assert(dumpHandlerCalled); assert(dumpHandlerCalled);
} }

View file

@ -13,10 +13,10 @@ import ldc.runtimecompile;
void main(string[] args) void main(string[] args)
{ {
rtCompileProcess(); compileDynamicCode();
assert(0 == foo()); assert(0 == foo());
foovar = 42; foovar = 42;
assert(0 == foo()); assert(0 == foo());
rtCompileProcess(); compileDynamicCode();
assert(42 == foo()); assert(42 == foo());
} }

View file

@ -69,7 +69,7 @@ void test(T,F)(ref T val, F fun)
void main(string[] args) void main(string[] args)
{ {
rtCompileProcess(); compileDynamicCode();
test(i8, &foo_i8); test(i8, &foo_i8);
test(i16, &foo_i16); test(i16, &foo_i16);

View file

@ -18,7 +18,7 @@ void main(string[] args)
return val1; return val1;
} }
rtCompileProcess(); compileDynamicCode();
assert(42 == foo()); assert(42 == foo());
assert(5 == bar()); assert(5 == bar());
assert(8 == val2); assert(8 == val2);

View file

@ -30,7 +30,7 @@ static assert(false, "LDC_RuntimeCompilation is not defined");
void main(string[] args) void main(string[] args)
{ {
rtCompileProcess(); compileDynamicCode();
assert(5 == foo()); assert(5 == foo());
assert(12 == bar()); assert(12 == bar());
baz(); baz();

View file

@ -20,7 +20,7 @@ void bar()
void main(string[] args) void main(string[] args)
{ {
rtCompileProcess(); compileDynamicCode();
bar(); bar();
Thread[] threads = [new Thread(&bar),new Thread(&bar),new Thread(&bar)]; Thread[] threads = [new Thread(&bar),new Thread(&bar),new Thread(&bar)];
foreach(t;threads[]) foreach(t;threads[])

View file

@ -38,7 +38,7 @@ import ldc.runtimecompile;
void main(string[] args) void main(string[] args)
{ {
rtCompileProcess(); compileDynamicCode();
assert(collectExceptionMsg(foo()) == "foo"); assert(collectExceptionMsg(foo()) == "foo");
assert(42 == bar()); assert(42 == bar());
assert(42 == baz()); assert(42 == baz());