1 
2 module llvm.c;
3 
4 private
5 {
6 	import llvm.util.templates;
7 	import llvm.util.shlib;
8 }
9 
10 public
11 {
12 	import llvm.c.versions;
13 	import llvm.c.types;
14 	import llvm.c.constants;
15 	import llvm.c.functions;
16 }
17 
18 private void loadSymbols(SharedLib library)
19 {
20 	mixin(MixinMap(
21 		      LLVMC_Functions,
22 		      delegate string(string symbol, string[] signature)
23 		      {
24 			      if(matchVersionQualifiers(signature[1 .. $]))
25 			      {
26 				      return symbol ~ " = " ~ "library.loadSymbol!(da_"
27 					      ~ symbol ~ ")(\"" ~ symbol ~ "\");\n";
28 			      }
29 			      return "";
30 		      }));
31 }
32 
33 /++
34  + Container for holding the LLVM library and the load/unload functions.
35 ++/
36 public struct LLVM
37 {
38 	private __gshared static SharedLib library;
39 
40 	/// Returns true if the LLVM library is loaded, false if not
41 	@property
42 	static bool loaded() { return library !is null; }
43 
44 	/// Loads the LLVM library, using the default name.
45 	public static void load() {
46 		load(null);
47 	}
48 
49 	/// Loads the LLVM library, using the specified file name
50 	public static void load(string file)
51 	{
52 		loadFromPath("", file);
53 	}
54 
55 	/// Loads the LLVM library, using the specified file name and path
56 	public static void loadFromPath(string path, string file = null)
57 	{
58 		if(file is null)
59 		{
60 			file = libPrefix ~ "LLVM-" ~ LLVM_VersionString ~ "." ~ libSuffix;
61 		}
62 
63 		if((path != "") && path[$-1] != '/')
64 		{
65 			path ~= '/';
66 		}
67 
68 		if(library)
69 		{
70 			unload();
71 		}
72 		
73 		library = new SharedLib(path ~ file);
74 		library.load();
75 		loadSymbols(library);
76 	}
77 
78 	/// Unloads the LLVM library
79 	public static void unload()
80 	{
81 		library.unload();
82 		library = null;
83 	}
84 }
85 
86 version(LLVM_Autoload) {
87 	shared static this()
88 	{
89 		LLVM.load(null);
90 	}
91 
92 	shared static ~this()
93 	{
94 		LLVM.unload();
95 	}
96 }