diff options
author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2022-01-05 04:00:38 +0100 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2022-01-12 11:28:39 -0800 |
commit | 65b651155aa1e85bfa505f8c9011ca4b3eba40b2 (patch) | |
tree | 04d9ec38e466029c376c83342358060efbf38327 /src | |
parent | 0759de116479c8a6319450e1e116af39e8c844c5 (diff) |
Bump yaxpeax-superh to 1.0.0
Turns out split_inclusive() binds the separator left, rather than right,
so it's not useful here
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs index 19660b3..ab0a0a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ use std::fs::File; use std::io::{Read, Write}; use std::{fmt, io}; -use std::collections::BTreeSet; fn main() { use clap::*; @@ -18,8 +17,8 @@ fn main() { "ia64", "armv7", "armv7-t","armv8", "avr", "mips", "msp430", "pic17", "pic18", "m16c", "6502", "lc87"].contains(&&a[..]) || (["sh", "sh2", "sh3", "sh4", "j2"].contains( - &&a[0..a.find(|c| c == '+' || c == '-').unwrap_or(a.len())]) && - a.split(|c| c == '+' || c == '-').skip(1).all( + &&a[0..a.find(&['+', '-'][..]).unwrap_or(a.len())]) && + a.split(&['+', '-'][..]).skip(1).all( |f| ["be", "mmu", "fpu", "f64", "j2"].contains(&f))) { Ok(()) } else { @@ -104,32 +103,29 @@ fn main() { "lc87" => arch_02::decode_input::<yaxpeax_lc87::LC87>(&buf, &printer), // "pic24" => decode_input::<yaxpeax_pic24::PIC24>(buf), other => { - let seg_idx = arch_str.find(|c| c == '+' || c == '-').unwrap_or(arch_str.len()); - let wps = |base| with_parsed_superh(base, &arch_str[seg_idx..], - |decoder| arch_02::decode_input_with_decoder::<yaxpeax_superh::SuperH>(decoder, &buf, &printer)); + let seg_idx = arch_str.find(&['+', '-'][..]).unwrap_or(arch_str.len()); + let decode = |base| arch_02::decode_input_with_decoder::<yaxpeax_superh::SuperH>( + parse_superh(base, &arch_str[seg_idx..]), &buf, &printer); match &arch_str[0..seg_idx] { - "sh" => wps(yaxpeax_superh::SuperHDecoder::SH1), - "sh2" => wps(yaxpeax_superh::SuperHDecoder::SH2), - "sh3" => wps(yaxpeax_superh::SuperHDecoder::SH3), - "sh4" => wps(yaxpeax_superh::SuperHDecoder::SH4), - "j2" => wps(yaxpeax_superh::SuperHDecoder::J2), + "sh" => decode(yaxpeax_superh::SuperHDecoder::SH1), + "sh2" => decode(yaxpeax_superh::SuperHDecoder::SH2), + "sh3" => decode(yaxpeax_superh::SuperHDecoder::SH3), + "sh4" => decode(yaxpeax_superh::SuperHDecoder::SH4), + "j2" => decode(yaxpeax_superh::SuperHDecoder::J2), _ => println!("unsupported architecture: {}", other), } } } } -fn with_parsed_superh<F: FnOnce(yaxpeax_superh::SuperHDecoder)>( - mut based_on: yaxpeax_superh::SuperHDecoder, mut from: &str, func: F -) { - let mut features = based_on.features.iter().copied().collect::<BTreeSet<_>>(); - +fn parse_superh(mut based_on: yaxpeax_superh::SuperHDecoder, mut from: &str) + -> yaxpeax_superh::SuperHDecoder +{ while !from.is_empty() { - // This would be Not Trash if split_inclusive were stable; alas let op = from.chars().next().unwrap(); from = &from[1..]; - let next_feat_idx = from.find(|c| c == '+' || c == '-').unwrap_or(from.len()); + let next_feat_idx = from.find(&['+', '-'][..]).unwrap_or(from.len()); let feat = &from[0..next_feat_idx]; from = &from[next_feat_idx..]; @@ -139,21 +135,18 @@ fn with_parsed_superh<F: FnOnce(yaxpeax_superh::SuperHDecoder)>( ('+', "f64") => based_on.fpscr_sz = true, ('-', "f64") => based_on.fpscr_sz = false, - ('+', "mmu") => { features.insert(yaxpeax_superh::SuperHFeature::MMU); }, - ('-', "mmu") => { features.remove(&yaxpeax_superh::SuperHFeature::MMU); }, - ('+', "fpu") => { features.insert(yaxpeax_superh::SuperHFeature::FPU); }, - ('-', "fpu") => { features.remove(&yaxpeax_superh::SuperHFeature::FPU); }, - ('+', "j2") => { features.insert(yaxpeax_superh::SuperHFeature::J2); }, - ('-', "j2") => { features.remove(&yaxpeax_superh::SuperHFeature::J2); }, + ('+', "mmu") => based_on.features.insert(yaxpeax_superh::SuperHFeatures::MMU), + ('-', "mmu") => based_on.features.remove(yaxpeax_superh::SuperHFeatures::MMU), + ('+', "fpu") => based_on.features.insert(yaxpeax_superh::SuperHFeatures::FPU), + ('-', "fpu") => based_on.features.remove(yaxpeax_superh::SuperHFeatures::FPU), + ('+', "j2") => based_on.features.insert(yaxpeax_superh::SuperHFeatures::J2), + ('-', "j2") => based_on.features.remove(yaxpeax_superh::SuperHFeatures::J2), pair => panic!("Who is {:?} and why was it not caught at parse time?", pair), } } - func(yaxpeax_superh::SuperHDecoder { - features: &features.into_iter().collect::<Vec<_>>()[..], - ..based_on - }) + based_on } struct Printer { |