@@ -5,38 +5,10 @@ version (LLVM_Load):
5
5
import std.traits ;
6
6
import std.meta ;
7
7
8
- import functions = llvm.functions.link;
8
+ import link = llvm.functions.link;
9
9
10
10
private :
11
11
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
-
40
12
version (Posix )
41
13
{
42
14
import core.sys.posix.dlfcn ;
@@ -141,9 +113,23 @@ final class SharedLibException : Exception
141
113
}
142
114
}
143
115
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
+
144
124
__gshared
145
125
{
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
+ }());
147
133
}
148
134
149
135
// / Container for holding the LLVM library and the load/unload functions.
@@ -155,10 +141,12 @@ private:
155
141
156
142
static void getSymbols ()
157
143
{
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
+ }
162
150
}
163
151
}
164
152
public :
0 commit comments