1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! A safer wrapper for the LLVM C API bindings in Rust, based on `llvm-sys`
//!
//! ## Notes on Safety
//!
//! Although there are no `unsafe` blocks needed to use this library, it does ignore some of Rust's
//! constraints on memory management. Mainly, immutable references can still be modified in order
//! to make certain programs more simple.
//!
//! To make things simple, `LLVMBuilder` and `LLVMModule` are disposed automatically when they leave
//! scope. Values and types are always created in the default global context provided by LLVM.
//!
//! If necessary, it is possible to use the `inner` function to access the wrapped value, or
//! `into_inner` to destroy the wrapper without disposing the contained value. Most types can also
//! dereference into their C equivalents. This crate is still in development and many features are
//! not fully supported, so use this if you need to use unsupported LLVM functions. Use `into_c`
//! and `from_c` to make strings easier to work with when dealing directly with the C API.
//!
//! ## Setup
//!
//! This crate relies heavily on `llvm-sys` and requires the same setup. Before using this crate,
//! be sure to install a version of LLVM 5 and add `LLVM_SYS_50_PREFIX=/path/to/llvm` to your `PATH`
//! environment variable.
//!
//! [LLVM Documentation] | [LLVM Language Reference] | [Rust Bindings]
//!
//! ## Example
//!
//! ```
//! # extern crate llvm_wrap as llvm;
//! # use llvm::*;
//! # use llvm::types::*;
//! # fn main() {
//! // Create a module
//! let module = create_module("add");
//! // Create a builder
//! let builder = create_builder();
//!
//! // Get an `i32 (i32, i32)` type
//! let ty = ty_i32().function(vec![ty_i32(); 2], false);
//! // Create the add function
//! let def = module.add_function("add", ty);
//! // Add an entry block
//! let entry = def.append_basic_block("entry");
//! // Move the builder to the end of the block
//! builder.position_at_end(entry);
//! // Add and name the two parameters
//! let result = builder.build_int_add(
//! def.param(0).name("a"),
//! def.param(1).name("b"),
//! );
//! // Return and name the result
//! builder.build_ret(result.name("tmp"));
//!
//! // Dump the contents of the module
//! module.dump();
//! # }
//! ```
//!
//! ## Output
//!
//! ```text
//! ; ModuleID = 'add'
//! source_filename = "add"
//!
//! define i32 @add(i32 %a, i32 %b) {
//! entry:
//! %tmp = add i32 %a, %b
//! ret i32 %tmp
//! }
//! ```
//!
//! [LLVM Documentation]: http://releases.llvm.org/5.0.0/docs/index.html
//! [LLVM Language Reference]: http://releases.llvm.org/5.0.0/docs/LangRef.html
//! [Rust Bindings]: http://rustdoc.taricorp.net/llvm-sys/llvm_sys
extern crate llvm_sys;
use *;
use *;
use *;
use ;
use Deref;
use ;
/// Provides functions for using the C API
pub use *;
pub use Module;
pub use Builder;
pub use Type;
pub use BasicBlock;
pub use Value;
pub use CallConv;
pub use Linkage;
/// Converts a `Vec<Value>` into a `Vec<LLVMValueRef>`
/// Converts a `Vec<Type>` into a `Vec<LLVMTypeRef>`