diff --git a/lib/codegen/build.rs b/lib/codegen/build.rs index 7cb20c4a14..39f6ebc62a 100644 --- a/lib/codegen/build.rs +++ b/lib/codegen/build.rs @@ -20,6 +20,7 @@ extern crate cranelift_codegen_meta as meta; +use meta::isa::Isa; use std::env; use std::process; @@ -99,60 +100,6 @@ fn identify_python() -> &'static str { panic!("The Cranelift build requires Python (version 2.7 or version 3)"); } -/// Represents known ISA target. -#[derive(Copy, Clone)] -enum Isa { - Riscv, - X86, - Arm32, - Arm64, -} - -impl Isa { - /// Creates isa target using name. - fn new(name: &str) -> Option { - Isa::all() - .iter() - .cloned() - .filter(|isa| isa.name() == name) - .next() - } - - /// Creates isa target from arch. - fn from_arch(arch: &str) -> Option { - Isa::all() - .iter() - .cloned() - .filter(|isa| isa.is_arch_applicable(arch)) - .next() - } - - /// Returns all supported isa targets. - fn all() -> [Isa; 4] { - [Isa::Riscv, Isa::X86, Isa::Arm32, Isa::Arm64] - } - - /// Returns name of the isa target. - fn name(&self) -> &'static str { - match *self { - Isa::Riscv => "riscv", - Isa::X86 => "x86", - Isa::Arm32 => "arm32", - Isa::Arm64 => "arm64", - } - } - - /// Checks if arch is applicable for the isa target. - fn is_arch_applicable(&self, arch: &str) -> bool { - match *self { - Isa::Riscv => arch == "riscv", - Isa::X86 => ["x86_64", "i386", "i586", "i686"].contains(&arch), - Isa::Arm32 => arch.starts_with("arm") || arch.starts_with("thumb"), - Isa::Arm64 => arch == "aarch64", - } - } -} - /// Returns isa targets to configure conditional compilation. fn isa_targets(cranelift_targets: Option<&str>, target_triple: &str) -> Result, String> { match cranelift_targets { diff --git a/lib/codegen/meta/src/isa/mod.rs b/lib/codegen/meta/src/isa/mod.rs new file mode 100644 index 0000000000..85141bb714 --- /dev/null +++ b/lib/codegen/meta/src/isa/mod.rs @@ -0,0 +1,53 @@ +/// Represents known ISA target. +#[derive(Copy, Clone)] +pub enum Isa { + Riscv, + X86, + Arm32, + Arm64, +} + +impl Isa { + /// Creates isa target using name. + pub fn new(name: &str) -> Option { + Isa::all() + .iter() + .cloned() + .filter(|isa| isa.name() == name) + .next() + } + + /// Creates isa target from arch. + pub fn from_arch(arch: &str) -> Option { + Isa::all() + .iter() + .cloned() + .filter(|isa| isa.is_arch_applicable(arch)) + .next() + } + + /// Returns all supported isa targets. + pub fn all() -> [Isa; 4] { + [Isa::Riscv, Isa::X86, Isa::Arm32, Isa::Arm64] + } + + /// Returns name of the isa target. + pub fn name(&self) -> &'static str { + match *self { + Isa::Riscv => "riscv", + Isa::X86 => "x86", + Isa::Arm32 => "arm32", + Isa::Arm64 => "arm64", + } + } + + /// Checks if arch is applicable for the isa target. + fn is_arch_applicable(&self, arch: &str) -> bool { + match *self { + Isa::Riscv => arch == "riscv", + Isa::X86 => ["x86_64", "i386", "i586", "i686"].contains(&arch), + Isa::Arm32 => arch.starts_with("arm") || arch.starts_with("thumb"), + Isa::Arm64 => arch == "aarch64", + } + } +} diff --git a/lib/codegen/meta/src/lib.rs b/lib/codegen/meta/src/lib.rs index f7533e9709..5bf0646f35 100644 --- a/lib/codegen/meta/src/lib.rs +++ b/lib/codegen/meta/src/lib.rs @@ -1,5 +1,6 @@ pub mod error; pub mod gen_types; +pub mod isa; mod base; mod cdsl;