Skip to content

Commit bcb2221

Browse files
author
Moritz Maxeiner
committed
Optimize LLVM_Load compile time
1 parent aed36b0 commit bcb2221

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

source/llvm/functions/load.d

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,10 @@ version (LLVM_Load):
55
import std.traits;
66
import std.meta;
77

8-
import functions = llvm.functions.link;
8+
import link = llvm.functions.link;
99

1010
private:
1111

12-
template isCFunction(alias scope_, string member)
13-
{
14-
static if (isFunction!(__traits(getMember, scope_, member)) &&
15-
(functionLinkage!(__traits(getMember, scope_, member)) == "C" ||
16-
functionLinkage!(__traits(getMember, scope_, member)) == "Windows")) {
17-
enum isCFunction = true;
18-
} else {
19-
enum isCFunction = false;
20-
}
21-
}
22-
23-
template CFunctions(alias mod)
24-
{
25-
alias isCFunction(string member) = .isCFunction!(mod, member);
26-
alias CFunctions = Filter!(isCFunction, __traits(allMembers, mod));
27-
}
28-
29-
string declareStubs()
30-
{
31-
import std.array : appender;
32-
auto code = appender!string;
33-
foreach (fn; CFunctions!functions) {
34-
code.put("typeof(functions."); code.put(fn);
35-
code.put(")* "); code.put(fn); code.put(";\n");
36-
}
37-
return code.data;
38-
}
39-
4012
version(Posix)
4113
{
4214
import core.sys.posix.dlfcn;
@@ -141,9 +113,23 @@ final class SharedLibException : Exception
141113
}
142114
}
143115

116+
private
117+
{
118+
bool isSym(string m) { return m != "object" && m != "llvm" && m != "orEmpty"; }
119+
120+
string declareSymPtr(string m) { return "typeof(link." ~ m ~ ")* " ~ m ~ ";"; }
121+
string getSymPtr(string m) { return m ~ " = library.getSymbol!(typeof(" ~ m ~ "))(\"" ~ m ~ "\");"; }
122+
}
123+
144124
__gshared
145125
{
146-
mixin (declareStubs);
126+
mixin ({
127+
string code;
128+
foreach (m; __traits(allMembers, link)) if (m.isSym) {
129+
code ~= m.declareSymPtr;
130+
}
131+
return code;
132+
}());
147133
}
148134

149135
/// Container for holding the LLVM library and the load/unload functions.
@@ -155,10 +141,12 @@ private:
155141

156142
static void getSymbols()
157143
{
158-
import std.stdio : stderr;
159-
foreach (fn; CFunctions!functions) {
160-
mixin(fn ~ " = library.getSymbol!(typeof(" ~ fn ~ "))(\"" ~ fn ~ "\");");
161-
debug if (!mixin(fn)) stderr.writeln("Warning, your LLVM shared library does not provide " ~ fn);
144+
foreach (m; __traits(allMembers, link)) static if (m.isSym) {
145+
mixin (m.getSymPtr);
146+
debug {
147+
import std.stdio : stderr;
148+
if (!mixin(m)) stderr.writeln("Missing LLVM symbol: " ~ m);
149+
}
162150
}
163151
}
164152
public:

0 commit comments

Comments
 (0)