1 //! This crate generates Rust sources for use by 2 //! [`cranelift_codegen`](../cranelift_codegen/index.html). 3 4 #[macro_use] 5 mod cdsl; 6 mod srcgen; 7 8 pub mod error; 9 pub mod isa; 10 11 mod gen_inst; 12 mod gen_settings; 13 mod gen_types; 14 15 mod constant_hash; 16 mod shared; 17 mod unique_table; 18 19 /// Generate an ISA from an architecture string (e.g. "x86_64"). 20 pub fn isa_from_arch(arch: &str) -> Result<isa::Isa, String> { 21 isa::Isa::from_arch(arch).ok_or_else(|| format!("no supported isa found for arch `{}`", arch)) 22 } 23 24 /// Generates all the Rust source files used in Cranelift from the meta-language. 25 pub fn generate(isas: &[isa::Isa], out_dir: &str, isle_dir: &str) -> Result<(), error::Error> { 26 // Common definitions. 27 let shared_defs = shared::define(); 28 29 gen_settings::generate( 30 &shared_defs.settings, 31 gen_settings::ParentGroup::None, 32 "settings.rs", 33 out_dir, 34 )?; 35 gen_types::generate("types.rs", out_dir)?; 36 37 gen_inst::generate( 38 &shared_defs.all_formats, 39 &shared_defs.all_instructions, 40 "opcodes.rs", 41 "inst_builder.rs", 42 "clif_opt.isle", 43 "clif_lower.isle", 44 out_dir, 45 isle_dir, 46 )?; 47 48 // Per ISA definitions. 49 for isa in isa::define(isas) { 50 gen_settings::generate( 51 &isa.settings, 52 gen_settings::ParentGroup::Shared, 53 &format!("settings-{}.rs", isa.name), 54 out_dir, 55 )?; 56 } 57 58 Ok(()) 59 } 60