Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove #![feature(try_trait)] from a test #1142

Merged
merged 1 commit into from
Apr 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions crates/stdarch-verify/tests/mips.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Verification of MIPS MSA intrinsics
#![feature(try_trait)]
#![allow(bad_style, unused)]

// This file is obtained from
Expand Down Expand Up @@ -139,47 +138,53 @@ struct MsaIntrinsic {
instruction: String,
}

struct NoneError;

impl std::convert::TryFrom<&'static str> for MsaIntrinsic {
// The intrinsics are just C function declarations of the form:
// $ret_ty __builtin_${fn_id}($($arg_ty),*);
type Error = std::option::NoneError;
type Error = NoneError;
fn try_from(line: &'static str) -> Result<Self, Self::Error> {
let first_whitespace = line.find(char::is_whitespace)?;
let ret_ty = &line[0..first_whitespace];
let ret_ty = MsaTy::from(ret_ty);
return inner(line).ok_or(NoneError);

let first_parentheses = line.find('(')?;
assert!(first_parentheses > first_whitespace);
let id = &line[first_whitespace + 1..first_parentheses].trim();
assert!(id.starts_with("__builtin"));
let mut id_str = "_".to_string();
id_str += &id[9..];
let id = id_str;
fn inner(line: &'static str) -> Option<MsaIntrinsic> {
let first_whitespace = line.find(char::is_whitespace)?;
let ret_ty = &line[0..first_whitespace];
let ret_ty = MsaTy::from(ret_ty);

let mut arg_tys = Vec::new();
let first_parentheses = line.find('(')?;
assert!(first_parentheses > first_whitespace);
let id = &line[first_whitespace + 1..first_parentheses].trim();
assert!(id.starts_with("__builtin"));
let mut id_str = "_".to_string();
id_str += &id[9..];
let id = id_str;

let last_parentheses = line.find(')')?;
for arg in (&line[first_parentheses + 1..last_parentheses]).split(',') {
let arg = arg.trim();
arg_tys.push(MsaTy::from(arg));
}
let mut arg_tys = Vec::new();

// The instruction is the intrinsic name without the __msa_ prefix.
let instruction = &id[6..];
let mut instruction = instruction.to_string();
// With all underscores but the first one replaced with a `.`
if let Some(first_underscore) = instruction.find('_') {
let postfix = instruction[first_underscore + 1..].replace('_', ".");
instruction = instruction[0..=first_underscore].to_string();
instruction += &postfix;
}
let last_parentheses = line.find(')')?;
for arg in (&line[first_parentheses + 1..last_parentheses]).split(',') {
let arg = arg.trim();
arg_tys.push(MsaTy::from(arg));
}

Ok(MsaIntrinsic {
id,
ret_ty,
arg_tys,
instruction,
})
// The instruction is the intrinsic name without the __msa_ prefix.
let instruction = &id[6..];
let mut instruction = instruction.to_string();
// With all underscores but the first one replaced with a `.`
if let Some(first_underscore) = instruction.find('_') {
let postfix = instruction[first_underscore + 1..].replace('_', ".");
instruction = instruction[0..=first_underscore].to_string();
instruction += &postfix;
}

Some(MsaIntrinsic {
id,
ret_ty,
arg_tys,
instruction,
})
}
}
}

Expand Down