Skip to content

Commit 673a3d5

Browse files
committed
Added experimental feature flag for misc testing
1 parent 68d4834 commit 673a3d5

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

Cargo.toml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ categories = ["development-tools::ffi"]
1111
edition = "2018"
1212

1313
[features]
14-
default = ['target-all']
14+
default = ["target-all"]
1515
llvm3-6 = []
1616
llvm3-7 = []
1717
llvm3-8 = []
@@ -37,22 +37,23 @@ target-bpf = []
3737
target-lanai = []
3838
target-webassembly = []
3939
target-all = [
40-
'target-x86',
41-
'target-arm',
42-
'target-mips',
43-
'target-aarch64',
44-
'target-amdgpu',
45-
'target-systemz',
46-
'target-hexagon',
47-
'target-nvptx',
48-
'target-msp430',
49-
'target-xcore',
50-
'target-powerpc',
51-
'target-sparc',
52-
'target-bpf',
53-
'target-lanai',
54-
'target-webassembly'
40+
"target-x86",
41+
"target-arm",
42+
"target-mips",
43+
"target-aarch64",
44+
"target-amdgpu",
45+
"target-systemz",
46+
"target-hexagon",
47+
"target-nvptx",
48+
"target-msp430",
49+
"target-xcore",
50+
"target-powerpc",
51+
"target-sparc",
52+
"target-bpf",
53+
"target-lanai",
54+
"target-webassembly"
5555
]
56+
experimental = ["static-alloc"]
5657

5758
[dependencies]
5859
either = "1.5"
@@ -61,6 +62,7 @@ inkwell_internal_macros = { path = "./internal_macros", version = "0.1.0" }
6162
libc = "0.2"
6263
llvm-sys = "80.1"
6364
regex = "1"
65+
static-alloc = { version = "0.1", optional = true }
6466

6567
[badges]
6668
travis-ci = { repository = "TheDan64/inkwell" }

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ assert_unique_used_features!{"llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-
8080
///
8181
/// # Remarks
8282
/// See also: https://llvm.org/doxygen/NVPTXBaseInfo_8h_source.html
83-
#[repr(u32)]
8483
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
8584
pub enum AddressSpace {
8685
Generic = 0,

src/types/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pub(crate) use crate::types::traits::AsTypeRef;
3636
use llvm_sys::core::LLVMDumpType;
3737
use llvm_sys::core::{LLVMAlignOf, LLVMGetTypeContext, LLVMFunctionType, LLVMArrayType, LLVMGetUndef, LLVMPointerType, LLVMPrintTypeToString, LLVMTypeIsSized, LLVMSizeOf, LLVMVectorType, LLVMGetElementType, LLVMConstNull};
3838
use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};
39+
#[cfg(feature = "experimental")]
40+
use static_alloc::Slab;
3941

4042
use std::fmt;
4143
use std::rc::Rc;
@@ -94,7 +96,7 @@ impl Type {
9496
VectorType::new(vec_type)
9597
}
9698

97-
// REVIEW: Can you make a FunctionType from a FunctionType???
99+
#[cfg(not(feature = "experimental"))]
98100
fn fn_type(&self, param_types: &[BasicTypeEnum], is_var_args: bool) -> FunctionType {
99101
let mut param_types: Vec<LLVMTypeRef> = param_types.iter()
100102
.map(|val| val.as_type_ref())
@@ -106,6 +108,22 @@ impl Type {
106108
FunctionType::new(fn_type)
107109
}
108110

111+
#[cfg(feature = "experimental")]
112+
fn fn_type(&self, param_types: &[BasicTypeEnum], is_var_args: bool) -> FunctionType {
113+
let pool: Slab<[usize; 16]> = Slab::uninit();
114+
let mut fixed_vec = pool.fixed_vec(param_types.len()).expect("Found more than 16 params");
115+
116+
for param_type in param_types {
117+
fixed_vec.push(param_type.as_type_ref()).expect("Unexpected error");
118+
}
119+
120+
let fn_type = unsafe {
121+
LLVMFunctionType(self.type_, fixed_vec.as_mut_ptr(), fixed_vec.len() as u32, is_var_args as i32)
122+
};
123+
124+
FunctionType::new(fn_type)
125+
}
126+
109127
fn array_type(&self, size: u32) -> ArrayType {
110128
let type_ = unsafe {
111129
LLVMArrayType(self.type_, size)

0 commit comments

Comments
 (0)