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 joins boolean settings into a list (e.g. `preset!(feature_a && feature_b)`). 15 #[macro_export] 16 macro_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. camel_case(s: &str) -> String32pub 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)] 53 mod tests { 54 use super::camel_case; 55 56 #[test] camel_case_works()57 fn camel_case_works() { 58 assert_eq!(camel_case("x"), "X"); 59 assert_eq!(camel_case("camel_case"), "CamelCase"); 60 } 61 } 62