Fixes #984: Add a isa::lookup_by_name function;

This removes the explicit dependency on target-lexicon for the embedder,
which can instead use the ISA's name directly. It can simplify
dependency management, in particular avoid the need for synchronizing
the target-lexicon dependencies versions.

It also tweak the error when an ISA isn't built as part of Cranelift to
be a SupportDisabled error; this was dead code before this.
This commit is contained in:
Benjamin Bouvier
2019-09-06 11:54:17 +02:00
parent dca2e7e9a7
commit e35cf861db

View File

@@ -66,7 +66,7 @@ use crate::timing;
use core::fmt;
use failure_derive::Fail;
use std::boxed::Box;
use target_lexicon::{Architecture, PointerWidth, Triple};
use target_lexicon::{triple, Architecture, PointerWidth, Triple};
#[cfg(feature = "riscv")]
mod riscv;
@@ -97,13 +97,13 @@ macro_rules! isa_builder {
};
#[cfg(not(feature = $feature))]
fn $name(_triple: Triple) -> Result<Builder, LookupError> {
Err(LookupError::Unsupported)
Err(LookupError::SupportDisabled)
}
$name
}};
}
/// Look for a supported ISA with the given `name`.
/// Look for an ISA for the given `triple`.
/// Return a builder that can create a corresponding `TargetIsa`.
pub fn lookup(triple: Triple) -> Result<Builder, LookupError> {
match triple.architecture {
@@ -117,6 +117,13 @@ pub fn lookup(triple: Triple) -> Result<Builder, LookupError> {
}
}
/// Look for a supported ISA with the given `name`.
/// Return a builder that can create a corresponding `TargetIsa`.
pub fn lookup_by_name(name: &str) -> Result<Builder, LookupError> {
use std::str::FromStr;
lookup(triple!(name))
}
/// Describes reason for target lookup failure
#[derive(Fail, PartialEq, Eq, Copy, Clone, Debug)]
pub enum LookupError {