aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock5
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs49
3 files changed, 25 insertions, 31 deletions
diff --git a/Cargo.lock b/Cargo.lock
index bed9a70..1883a72 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -407,10 +407,11 @@ dependencies = [
[[package]]
name = "yaxpeax-superh"
-version = "0.3.0"
+version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c8cc1c381ba557a8d7e9fdb1399c36e4d9ce5a517b3e2bb504b261012403f4f"
+checksum = "c5281091585bd676e16313291703e8724889d4076672fc7b4d0e5b1718c54e2c"
dependencies = [
+ "bitflags",
"yaxpeax-arch",
]
diff --git a/Cargo.toml b/Cargo.toml
index 2cc050c..aeb5364 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,5 +35,5 @@ yaxpeax-pic17 = { version = "0.1.0" }
yaxpeax-pic18 = { version = "0.1.0" }
yaxpeax-x86 = { version = "1.1.3", default-features = false, features = ["fmt", "std"] }
yaxpeax-ia64 = { version = "0.2.1" }
-yaxpeax-superh = { version = "0.3.0" }
+yaxpeax-superh = { version = "1.0.0" }
yaxpeax-6502 = { version = "0.0.2", features = ["std"] }
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 {