Skip to content

Commit 3079214

Browse files
committed
Privatise some unintendedly public stuff
1 parent 294dd24 commit 3079214

File tree

3 files changed

+112
-79
lines changed

3 files changed

+112
-79
lines changed

src/lib.rs

Lines changed: 103 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use std::sync::{Once, ONCE_INIT};
2020
type LLVMBool = libc::c_uint;
2121
const LLVMTrue: LLVMBool = 1;
2222
const LLVMFalse: LLVMBool = 0;
23-
pub enum LLVMPassRegistry_opaque {}
24-
pub type LLVMPassRegistryRef = *mut LLVMPassRegistry_opaque;
2523
#[allow(missing_copy_implementations)]
2624
enum LLVMContext_opaque {}
2725
type LLVMContextRef = *mut LLVMContext_opaque;
@@ -32,75 +30,15 @@ type LLVMMemoryBufferRef = *mut LLVMMemoryBuffer_opaque;
3230
enum LLVMModule_opaque {}
3331
type LLVMModuleRef = *mut LLVMModule_opaque;
3432
#[allow(missing_copy_implementations)]
35-
pub enum LLVMTarget_opaque {}
36-
pub type LLVMTargetRef = *mut LLVMTarget_opaque;
37-
pub enum LLVMTargetMachine_opaque {}
38-
pub type LLVMTargetMachineRef = *mut LLVMTargetMachine_opaque;
39-
pub enum LLVMArchive_opaque {}
40-
pub type LLVMArchiveRef = *mut LLVMArchive_opaque;
41-
pub enum LLVMArchiveIterator_opaque {}
42-
pub type LLVMArchiveIteratorRef = *mut LLVMArchiveIterator_opaque;
43-
pub enum LLVMArchiveChild_opaque {}
44-
pub type LLVMArchiveChildRef = *mut LLVMArchiveChild_opaque;
33+
enum LLVMTarget_opaque {}
34+
type LLVMTargetRef = *mut LLVMTarget_opaque;
35+
enum LLVMTargetMachine_opaque {}
36+
type LLVMTargetMachineRef = *mut LLVMTargetMachine_opaque;
37+
enum LLVMArchiveChild_opaque {}
38+
type LLVMArchiveChildRef = *mut LLVMArchiveChild_opaque;
4539
#[allow(missing_copy_implementations)]
46-
pub enum LLVMRustArchiveMember_opaque {}
47-
pub type LLVMRustArchiveMemberRef = *mut LLVMRustArchiveMember_opaque;
48-
49-
50-
51-
#[derive(Copy, Clone, PartialEq, Debug)]
52-
#[repr(C)]
53-
pub enum RelocMode {
54-
Default = 0,
55-
Static = 1,
56-
PIC = 2,
57-
DynamicNoPic = 3,
58-
}
59-
60-
#[repr(C)]
61-
#[derive(Copy, Clone, Debug)]
62-
pub enum CodeGenModel {
63-
Default = 0,
64-
JITDefault = 1,
65-
Small = 2,
66-
Kernel = 3,
67-
Medium = 4,
68-
Large = 5,
69-
}
70-
71-
#[derive(Copy, Clone, PartialEq, Debug)]
72-
#[repr(C)]
73-
pub enum CodeGenOptLevel {
74-
O0 = 0,
75-
O1 = 1,
76-
O2 = 2,
77-
O3 = 3,
78-
}
79-
80-
#[allow(dead_code)]
81-
#[repr(C)]
82-
enum VerifierFailureAction {
83-
AbortProcess = 0,
84-
PrintMessage = 1,
85-
ReturnStatus = 2,
86-
}
87-
88-
#[allow(dead_code)]
89-
#[repr(C)]
90-
enum CodeGenFileType {
91-
Assembly = 0,
92-
Object = 1,
93-
}
94-
95-
#[allow(dead_code)]
96-
#[repr(C)]
97-
#[derive(Copy, Clone)]
98-
pub enum ArchiveKind {
99-
K_GNU,
100-
K_MIPS64,
101-
K_BSD,
102-
K_COFF,
103-
}
40+
enum LLVMRustArchiveMember_opaque {}
41+
type LLVMRustArchiveMemberRef = *mut LLVMRustArchiveMember_opaque;
10442

10543
extern {
10644
fn LLVMContextCreate() -> LLVMContextRef;
@@ -119,9 +57,9 @@ extern {
11957
triple: *const libc::c_char,
12058
cpu: *const libc::c_char,
12159
features: *const libc::c_char,
122-
lvl: CodeGenOptLevel,
123-
reloc: RelocMode,
124-
cm: CodeGenModel) -> LLVMTargetMachineRef;
60+
lvl: Optimisation,
61+
reloc: Relocations,
62+
cm: CodegenModel) -> LLVMTargetMachineRef;
12563
fn LLVMDisposeTargetMachine(_: LLVMTargetMachineRef);
12664
fn LLVMTargetMachineEmitToFile (_: LLVMTargetMachineRef,
12765
_: LLVMModuleRef,
@@ -147,6 +85,87 @@ extern {
14785
Kind: ArchiveKind) -> libc::c_int;
14886
}
14987

88+
#[allow(dead_code)]
89+
#[repr(C)]
90+
enum VerifierFailureAction {
91+
AbortProcess = 0,
92+
PrintMessage = 1,
93+
ReturnStatus = 2,
94+
}
95+
96+
#[allow(dead_code)]
97+
#[repr(C)]
98+
enum CodeGenFileType {
99+
Assembly = 0,
100+
Object = 1,
101+
}
102+
103+
104+
/// Relocation mode
105+
///
106+
/// This option decides how relocations are handled.
107+
#[derive(Copy, Clone, PartialEq, Debug)]
108+
#[repr(C)]
109+
pub enum Relocations {
110+
/// Target default relocation model
111+
Default = 0,
112+
/// Non-relocatable code
113+
Static = 1,
114+
/// Fully relocatable, position independent code
115+
PIC = 2,
116+
/// Relocatable external references, non-relocatable code
117+
DynamicNoPic = 3,
118+
}
119+
120+
/// Codegen model
121+
#[repr(C)]
122+
#[derive(Copy, Clone, Debug)]
123+
pub enum CodegenModel {
124+
/// Target default code model
125+
Default = 0,
126+
/// Small code model
127+
Small = 2,
128+
/// Kernel code model
129+
Kernel = 3,
130+
/// Medium code model
131+
Medium = 4,
132+
/// Large code model
133+
Large = 5,
134+
}
135+
136+
/// Codegen optimisation level
137+
#[derive(Copy, Clone, PartialEq, Debug)]
138+
#[repr(C)]
139+
pub enum Optimisation {
140+
/// No codegen optimisation
141+
///
142+
/// Corresponds to the -O0 option of `llc`
143+
O0 = 0,
144+
/// Some codegen optimisations
145+
///
146+
/// Corresponds to the -O1 option of `llc`
147+
O1 = 1,
148+
/// Considerable codegen optimisations
149+
///
150+
/// Corresponds to the -O2 option of `llc`
151+
O2 = 2,
152+
/// Heavy codegen optimisations
153+
///
154+
/// Corresponds to the -O3 option of `llc`
155+
O3 = 3,
156+
}
157+
158+
/// The format of generated archive file
159+
#[allow(dead_code)]
160+
#[repr(C)]
161+
#[derive(Copy, Clone)]
162+
pub enum ArchiveKind {
163+
Gnu,
164+
Mips64,
165+
Bsd,
166+
Coff,
167+
}
168+
150169
#[derive(Debug)]
151170
pub struct BuildOptions {
152171
pub triple: String,
@@ -160,13 +179,19 @@ pub struct BuildOptions {
160179

161180
impl Default for BuildOptions {
162181
fn default() -> BuildOptions {
182+
use std::env::var;
163183
BuildOptions {
164-
triple: ::std::env::var("TARGET").unwrap_or(String::new()),
184+
triple: var("TARGET").unwrap_or(String::new()),
165185
cpu: String::new(),
166186
attr: String::new(),
167-
model: CodeGenModel::Default,
168-
reloc: RelocMode::Default,
169-
opt: CodeGenOptLevel::O0,
187+
model: CodegenModel::Default,
188+
reloc: Relocations::Default,
189+
opt: match var("OPT_LEVEL").ok().and_then(|v| v.parse().ok()).unwrap_or(0u64) {
190+
0 => Optimisation::O0,
191+
1 => Optimisation::O1,
192+
2 => Optimisation::O2,
193+
3 | _ => Optimisation::O3,
194+
},
170195
ar_section_name: String::new(),
171196
}
172197
}
@@ -311,7 +336,7 @@ where P: AsRef<Path>, I: IntoIterator<Item=&'a (P, BuildOptions)>
311336
members.len() as libc::size_t,
312337
members.as_ptr(),
313338
true,
314-
ArchiveKind::K_GNU);
339+
ArchiveKind::Gnu);
315340
fail_if!(r != 0, "{:?}", {
316341
let err = LLVMRustGetLastError();
317342
if err.is_null() {

tests/build_test.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ fn test_build() {
1313
})]).unwrap();
1414
}
1515

16+
#[test]
17+
fn test_bytecode_build() {
18+
build_archive("libtestbc.a", &[("tests/test.bc", BuildOptions {
19+
triple: String::from("x86_64-unknown-linux-gnu"),
20+
..BuildOptions::default()
21+
})]).unwrap();
22+
}
23+
1624
#[test]
1725
fn test_cpu_attr() {
1826
build_archive("librand.a", &[("tests/rdrand.ll", BuildOptions {
@@ -49,7 +57,7 @@ fn test_optimisation() {
4957
triple: String::from("x86_64-unknown-linux-gnu"),
5058
cpu: String::from("x86-64"),
5159
attr: String::from("+rdrnd"),
52-
opt: CodeGenOptLevel::O3,
60+
opt: Optimisation::O3,
5361
..BuildOptions::default()
5462
})]).unwrap();
5563
}

tests/test.bc

680 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)