cranelift_codegen_meta/cdsl/
mod.rs

1//! Cranelift DSL classes.
2//!
3//! This module defines the classes that are used to define Cranelift
4//! instructions and other entities.
5
6pub mod formats;
7pub mod instructions;
8pub mod isa;
9pub mod operands;
10pub mod settings;
11pub mod types;
12pub mod typevar;
13
14/// A macro that joins boolean settings into a list (e.g. `preset!(feature_a && feature_b)`).
15#[macro_export]
16macro_rules! preset {
17    () => {
18        vec![]
19    };
20    ($($x:tt)&&*) => {
21        {
22            let mut v = Vec::new();
23            $(
24                v.push($x.into());
25            )*
26            v
27        }
28    };
29}
30
31/// Convert the string `s` to CamelCase.
32pub fn camel_case(s: &str) -> String {
33    let mut output_chars = String::with_capacity(s.len());
34
35    let mut capitalize = true;
36    for curr_char in s.chars() {
37        if curr_char == '_' {
38            capitalize = true;
39        } else {
40            if capitalize {
41                output_chars.extend(curr_char.to_uppercase());
42            } else {
43                output_chars.push(curr_char);
44            }
45            capitalize = false;
46        }
47    }
48
49    output_chars
50}
51
52#[cfg(test)]
53mod tests {
54    use super::camel_case;
55
56    #[test]
57    fn camel_case_works() {
58        assert_eq!(camel_case("x"), "X");
59        assert_eq!(camel_case("camel_case"), "CamelCase");
60    }
61}