1 /**
2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved.
3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 This file contains wrappers that uses LLVM's API for IO.
7 These are generally not needed because D's stdlib provide more than adequate
8 functionality for IO.
9 
10 These functions are mostly for debugging purpose. To conveniently be able to
11 compare the output from LLVM with those in llvm_hiwrap.io.
12 */
13 module llvm_hiwrap.llvm_io;
14 
15 import llvm_hiwrap.module_;
16 
17 /** Dump a representation of the module to stderr.
18  */
19 void dumpToStdout(ref Module m) @trusted {
20     import llvm : LLVMDumpModule;
21 
22     LLVMDumpModule(m.lx);
23 }
24 
25 /// ditto
26 void dumpToFile(ref Module m, string file) @trusted {
27     import std..string : toStringz;
28     import llvm : LLVMWriteBitcodeToFile;
29 
30     const(char)* p = file.toStringz;
31     LLVMWriteBitcodeToFile(m.lx, p);
32 }
33 
34 @("shall be a dump of the module to a file (using llvm)")
35 unittest {
36     import std.file : remove;
37     import llvm_hiwrap.llvm_io;
38 
39     immutable p = "remove_me_module_dump_llvm.bc";
40     scope (exit)
41         remove(p);
42 
43     auto m = Module("as_file");
44     m.dumpToFile(p);
45 }