Skip to content

Commit

Permalink
xc2bit: Refactor partdb methods
Browse files Browse the repository at this point in the history
ArcaneNibble committed Jun 24, 2017
1 parent 6643e0c commit d91cc0e
Showing 4 changed files with 11 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/xc2bit/src/bin/xc2jedblank.rs
Original file line number Diff line number Diff line change
@@ -36,14 +36,8 @@ fn main() {
::std::process::exit(1);
}

let device_combination = parse_part_name_string(&args[1]);
if device_combination.is_none() {
println!("Requested part combination {} is invalid", args[1]);
::std::process::exit(1);
}

let (part, spd, pkg) = device_combination.unwrap();
let bitstream = XC2Bitstream::blank_bitstream(part, spd, pkg).expect("failed to create bitstream");
let device_combination = &args[1];
let bitstream = XC2Bitstream::blank_bitstream(device_combination).expect("failed to create bitstream");

bitstream.to_jed(&mut ::std::io::stdout()).expect("failed to write jed");
}
12 changes: 7 additions & 5 deletions src/xc2bit/src/bitstream.rs
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ use fusemap_logical::{fb_fuse_idx, gck_fuse_idx, gsr_fuse_idx, gts_fuse_idx, glo
total_logical_fuse_count, clock_div_fuse_idx};
use fusemap_physical::{fuse_array_dims, gck_fuse_coords, gsr_fuse_coords, gts_fuse_coords, global_term_fuse_coord,
clock_div_fuse_coord};
use partdb::{parse_part_name_string};
use util::{b2s};
use zia::{zia_get_row_width};

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

/// Construct a new blank bitstream of the given part
pub fn blank_bitstream(device: XC2Device, speed_grade: XC2Speed, package: XC2Package)
-> Result<Self, XC2BitError> {

if !is_valid_part_combination(device, speed_grade, package) {
return Err(XC2BitError::BadDeviceName(format!("{}-{}-{}", device, speed_grade, package)));
pub fn blank_bitstream(device_name: &str) -> Result<Self, XC2BitError> {
let maybe_part_combination = parse_part_name_string(device_name);
if maybe_part_combination.is_none() {
return Err(XC2BitError::BadDeviceName(device_name.to_owned()));
}

let (device, speed_grade, package) = maybe_part_combination.unwrap();

match device {
XC2Device::XC2C32 => {
Ok(XC2Bitstream {
2 changes: 1 addition & 1 deletion src/xc2bit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ pub use mc::{XC2Macrocell, XC2MCRegClkSrc, XC2MCRegResetSrc, XC2MCRegSetSrc, XC2
XC2MCXorMode};

mod partdb;
pub use partdb::{XC2Device, XC2Speed, XC2Package, is_valid_part_combination, parse_part_name_string};
pub use partdb::{XC2Device, XC2Speed, XC2Package};

mod pla;
pub use pla::{XC2PLAAndTerm, XC2PLAOrTerm};
2 changes: 1 addition & 1 deletion src/xc2bit/src/partdb.rs
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ impl fmt::Display for XC2Package {
}

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

0 comments on commit d91cc0e

Please sign in to comment.