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