Skip to content

Commit d91cc0e

Browse files
committedJun 24, 2017
xc2bit: Refactor partdb methods
1 parent 6643e0c commit d91cc0e

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed
 

Diff for: ‎src/xc2bit/src/bin/xc2jedblank.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ fn main() {
3636
::std::process::exit(1);
3737
}
3838

39-
let device_combination = parse_part_name_string(&args[1]);
40-
if device_combination.is_none() {
41-
println!("Requested part combination {} is invalid", args[1]);
42-
::std::process::exit(1);
43-
}
44-
45-
let (part, spd, pkg) = device_combination.unwrap();
46-
let bitstream = XC2Bitstream::blank_bitstream(part, spd, pkg).expect("failed to create bitstream");
39+
let device_combination = &args[1];
40+
let bitstream = XC2Bitstream::blank_bitstream(device_combination).expect("failed to create bitstream");
4741

4842
bitstream.to_jed(&mut ::std::io::stdout()).expect("failed to write jed");
4943
}

Diff for: ‎src/xc2bit/src/bitstream.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use fusemap_logical::{fb_fuse_idx, gck_fuse_idx, gsr_fuse_idx, gts_fuse_idx, glo
3333
total_logical_fuse_count, clock_div_fuse_idx};
3434
use fusemap_physical::{fuse_array_dims, gck_fuse_coords, gsr_fuse_coords, gts_fuse_coords, global_term_fuse_coord,
3535
clock_div_fuse_coord};
36+
use partdb::{parse_part_name_string};
3637
use util::{b2s};
3738
use zia::{zia_get_row_width};
3839

@@ -251,13 +252,14 @@ impl XC2Bitstream {
251252
}
252253

253254
/// Construct a new blank bitstream of the given part
254-
pub fn blank_bitstream(device: XC2Device, speed_grade: XC2Speed, package: XC2Package)
255-
-> Result<Self, XC2BitError> {
256-
257-
if !is_valid_part_combination(device, speed_grade, package) {
258-
return Err(XC2BitError::BadDeviceName(format!("{}-{}-{}", device, speed_grade, package)));
255+
pub fn blank_bitstream(device_name: &str) -> Result<Self, XC2BitError> {
256+
let maybe_part_combination = parse_part_name_string(device_name);
257+
if maybe_part_combination.is_none() {
258+
return Err(XC2BitError::BadDeviceName(device_name.to_owned()));
259259
}
260260

261+
let (device, speed_grade, package) = maybe_part_combination.unwrap();
262+
261263
match device {
262264
XC2Device::XC2C32 => {
263265
Ok(XC2Bitstream {

Diff for: ‎src/xc2bit/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub use mc::{XC2Macrocell, XC2MCRegClkSrc, XC2MCRegResetSrc, XC2MCRegSetSrc, XC2
7676
XC2MCXorMode};
7777

7878
mod partdb;
79-
pub use partdb::{XC2Device, XC2Speed, XC2Package, is_valid_part_combination, parse_part_name_string};
79+
pub use partdb::{XC2Device, XC2Speed, XC2Package};
8080

8181
mod pla;
8282
pub use pla::{XC2PLAAndTerm, XC2PLAOrTerm};

Diff for: ‎src/xc2bit/src/partdb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl fmt::Display for XC2Package {
118118
}
119119

120120
/// Determine if the given combination of device, speed, and package is a legal combination or not.
121-
pub fn is_valid_part_combination(device: XC2Device, speed: XC2Speed, package: XC2Package) -> bool {
121+
fn is_valid_part_combination(device: XC2Device, speed: XC2Speed, package: XC2Package) -> bool {
122122
match device {
123123
XC2Device::XC2C32 => {
124124
if speed == XC2Speed::Speed4 || speed == XC2Speed::Speed6 {

0 commit comments

Comments
 (0)