[build] Move Isa enum to the meta library;
This commit is contained in:
committed by
Dan Gohman
parent
17e88ed1c5
commit
4f2d7dd54f
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
extern crate cranelift_codegen_meta as meta;
|
extern crate cranelift_codegen_meta as meta;
|
||||||
|
|
||||||
|
use meta::isa::Isa;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
@@ -99,60 +100,6 @@ fn identify_python() -> &'static str {
|
|||||||
panic!("The Cranelift build requires Python (version 2.7 or version 3)");
|
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<Self> {
|
|
||||||
Isa::all()
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.filter(|isa| isa.name() == name)
|
|
||||||
.next()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates isa target from arch.
|
|
||||||
fn from_arch(arch: &str) -> Option<Isa> {
|
|
||||||
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.
|
/// Returns isa targets to configure conditional compilation.
|
||||||
fn isa_targets(cranelift_targets: Option<&str>, target_triple: &str) -> Result<Vec<Isa>, String> {
|
fn isa_targets(cranelift_targets: Option<&str>, target_triple: &str) -> Result<Vec<Isa>, String> {
|
||||||
match cranelift_targets {
|
match cranelift_targets {
|
||||||
|
|||||||
53
lib/codegen/meta/src/isa/mod.rs
Normal file
53
lib/codegen/meta/src/isa/mod.rs
Normal file
@@ -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<Self> {
|
||||||
|
Isa::all()
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.filter(|isa| isa.name() == name)
|
||||||
|
.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates isa target from arch.
|
||||||
|
pub fn from_arch(arch: &str) -> Option<Isa> {
|
||||||
|
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",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod gen_types;
|
pub mod gen_types;
|
||||||
|
pub mod isa;
|
||||||
|
|
||||||
mod base;
|
mod base;
|
||||||
mod cdsl;
|
mod cdsl;
|
||||||
|
|||||||
Reference in New Issue
Block a user