Apply conditional compilation of isa targets
This commit is contained in:
committed by
Jakob Stoklund Olesen
parent
c057e005ce
commit
5fa991e325
@@ -27,10 +27,10 @@
|
|||||||
//! let shared_flags = settings::Flags::new(&shared_builder);
|
//! let shared_flags = settings::Flags::new(&shared_builder);
|
||||||
//!
|
//!
|
||||||
//! match isa::lookup("riscv") {
|
//! match isa::lookup("riscv") {
|
||||||
//! None => {
|
//! Err(_) => {
|
||||||
//! // The RISC-V target ISA is not available.
|
//! // The RISC-V target ISA is not available.
|
||||||
//! }
|
//! }
|
||||||
//! Some(mut isa_builder) => {
|
//! Ok(mut isa_builder) => {
|
||||||
//! isa_builder.set("supports_m", "on");
|
//! isa_builder.set("supports_m", "on");
|
||||||
//! let isa = isa_builder.finish(shared_flags);
|
//! let isa = isa_builder.finish(shared_flags);
|
||||||
//! }
|
//! }
|
||||||
@@ -51,42 +51,61 @@ use ir;
|
|||||||
use regalloc;
|
use regalloc;
|
||||||
use isa::enc_tables::Encodings;
|
use isa::enc_tables::Encodings;
|
||||||
|
|
||||||
|
#[cfg(build_riscv)]
|
||||||
pub mod riscv;
|
pub mod riscv;
|
||||||
|
|
||||||
|
#[cfg(build_intel)]
|
||||||
pub mod intel;
|
pub mod intel;
|
||||||
|
|
||||||
|
#[cfg(build_arm32)]
|
||||||
pub mod arm32;
|
pub mod arm32;
|
||||||
|
|
||||||
|
#[cfg(build_arm64)]
|
||||||
pub mod arm64;
|
pub mod arm64;
|
||||||
|
|
||||||
pub mod registers;
|
pub mod registers;
|
||||||
mod encoding;
|
mod encoding;
|
||||||
mod enc_tables;
|
mod enc_tables;
|
||||||
mod constraints;
|
mod constraints;
|
||||||
|
|
||||||
|
/// Returns a builder that can create a corresponding `TargetIsa`
|
||||||
|
/// or `Err(LookupError::Unsupported)` if not enabled.
|
||||||
|
macro_rules! isa_builder {
|
||||||
|
($module:ident, $name:ident) => {
|
||||||
|
{
|
||||||
|
#[cfg($name)]
|
||||||
|
fn $name() -> Result<Builder, LookupError> {
|
||||||
|
Ok($module::isa_builder())
|
||||||
|
};
|
||||||
|
#[cfg(not($name))]
|
||||||
|
fn $name() -> Result<Builder, LookupError> {
|
||||||
|
Err(LookupError::Unsupported)
|
||||||
|
}
|
||||||
|
$name()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Look for a supported ISA with the given `name`.
|
/// Look for a supported ISA with the given `name`.
|
||||||
/// Return a builder that can create a corresponding `TargetIsa`.
|
/// Return a builder that can create a corresponding `TargetIsa`.
|
||||||
pub fn lookup(name: &str) -> Option<Builder> {
|
pub fn lookup(name: &str) -> Result<Builder, LookupError> {
|
||||||
match name {
|
match name {
|
||||||
"riscv" => riscv_builder(),
|
"riscv" => isa_builder!(riscv, build_riscv),
|
||||||
"intel" => intel_builder(),
|
"intel" => isa_builder!(intel, build_intel),
|
||||||
"arm32" => arm32_builder(),
|
"arm32" => isa_builder!(arm32, build_arm32),
|
||||||
"arm64" => arm64_builder(),
|
"arm64" => isa_builder!(arm64, build_arm64),
|
||||||
_ => None,
|
_ => Err(LookupError::Unknown),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a builder for RISC-V.
|
/// Describes reason for target lookup failure
|
||||||
fn riscv_builder() -> Option<Builder> {
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
Some(riscv::isa_builder())
|
pub enum LookupError {
|
||||||
}
|
/// Unknown Target
|
||||||
|
Unknown,
|
||||||
|
|
||||||
fn intel_builder() -> Option<Builder> {
|
/// Target known but not built and thus not supported
|
||||||
Some(intel::isa_builder())
|
Unsupported,
|
||||||
}
|
|
||||||
|
|
||||||
fn arm32_builder() -> Option<Builder> {
|
|
||||||
Some(arm32::isa_builder())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn arm64_builder() -> Option<Builder> {
|
|
||||||
Some(arm64::isa_builder())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builder for a `TargetIsa`.
|
/// Builder for a `TargetIsa`.
|
||||||
|
|||||||
@@ -247,6 +247,7 @@ impl fmt::Display for Pressure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[cfg(build_arm32)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use isa::{TargetIsa, RegClass};
|
use isa::{TargetIsa, RegClass};
|
||||||
use regalloc::AllocatableSet;
|
use regalloc::AllocatableSet;
|
||||||
@@ -261,7 +262,7 @@ mod tests {
|
|||||||
let shared_builder = settings::builder();
|
let shared_builder = settings::builder();
|
||||||
let shared_flags = settings::Flags::new(&shared_builder);
|
let shared_flags = settings::Flags::new(&shared_builder);
|
||||||
|
|
||||||
isa::lookup("arm32").map(|b| b.finish(shared_flags))
|
isa::lookup("arm32").ok().map(|b| b.finish(shared_flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a register class by name.
|
// Get a register class by name.
|
||||||
|
|||||||
@@ -700,6 +700,7 @@ impl Solver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[cfg(build_arm32)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use entity_ref::EntityRef;
|
use entity_ref::EntityRef;
|
||||||
use ir::Value;
|
use ir::Value;
|
||||||
@@ -716,7 +717,7 @@ mod tests {
|
|||||||
let shared_builder = settings::builder();
|
let shared_builder = settings::builder();
|
||||||
let shared_flags = settings::Flags::new(&shared_builder);
|
let shared_flags = settings::Flags::new(&shared_builder);
|
||||||
|
|
||||||
isa::lookup("arm32").map(|b| b.finish(shared_flags))
|
isa::lookup("arm32").ok().map(|b| b.finish(shared_flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a register class by name.
|
// Get a register class by name.
|
||||||
|
|||||||
@@ -621,8 +621,6 @@ impl<'a> Parser<'a> {
|
|||||||
&self.loc)?;
|
&self.loc)?;
|
||||||
}
|
}
|
||||||
"isa" => {
|
"isa" => {
|
||||||
last_set_loc = None;
|
|
||||||
seen_isa = true;
|
|
||||||
let loc = self.loc;
|
let loc = self.loc;
|
||||||
// Grab the whole line so the lexer won't go looking for tokens on the
|
// Grab the whole line so the lexer won't go looking for tokens on the
|
||||||
// following lines.
|
// following lines.
|
||||||
@@ -633,9 +631,16 @@ impl<'a> Parser<'a> {
|
|||||||
Some(w) => w,
|
Some(w) => w,
|
||||||
};
|
};
|
||||||
let mut isa_builder = match isa::lookup(isa_name) {
|
let mut isa_builder = match isa::lookup(isa_name) {
|
||||||
None => return err!(loc, "unknown ISA '{}'", isa_name),
|
Err(isa::LookupError::Unknown) => {
|
||||||
Some(b) => b,
|
return err!(loc, "unknown ISA '{}'", isa_name)
|
||||||
|
}
|
||||||
|
Err(isa::LookupError::Unsupported) => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Ok(b) => b,
|
||||||
};
|
};
|
||||||
|
last_set_loc = None;
|
||||||
|
seen_isa = true;
|
||||||
// Apply the ISA-specific settings to `isa_builder`.
|
// Apply the ISA-specific settings to `isa_builder`.
|
||||||
isaspec::parse_options(words, &mut isa_builder, &self.loc)?;
|
isaspec::parse_options(words, &mut isa_builder, &self.loc)?;
|
||||||
|
|
||||||
@@ -1939,6 +1944,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(build_riscv)]
|
||||||
fn isa_spec() {
|
fn isa_spec() {
|
||||||
assert!(parse_test("isa
|
assert!(parse_test("isa
|
||||||
function %foo() {}")
|
function %foo() {}")
|
||||||
|
|||||||
Reference in New Issue
Block a user