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
#[cfg(feature = "use-compiled-tools")]
pub mod compiled;
#[cfg(feature = "use-installed-tools")]
pub mod tool;
#[derive(Copy, Clone, Default)]
pub struct AssemblerOptions {
pub preserve_numeric_ids: bool,
}
impl Into<u32> for AssemblerOptions {
fn into(self) -> u32 {
let mut res = 0;
if self.preserve_numeric_ids {
res |= spirv_tools_sys::assembler::BinaryOptions::PreserveNumberIds as u32;
}
res
}
}
pub trait Assembler: Default {
fn with_env(target_env: crate::TargetEnv) -> Self;
fn assemble(
&self,
text: &str,
options: AssemblerOptions,
) -> Result<crate::binary::Binary, crate::error::Error>;
}
pub fn create(te: Option<crate::TargetEnv>) -> impl Assembler {
let target_env = te.unwrap_or_default();
#[cfg(feature = "use-compiled-tools")]
{
compiled::CompiledAssembler::with_env(target_env)
}
#[cfg(all(feature = "use-installed-tools", not(feature = "use-compiled-tools")))]
{
tool::ToolAssembler::with_env(target_env)
}
}