Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions crates/spar-analysis/src/bus_bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,8 @@ fn get_bandwidth_capacity(props: &spar_hir_def::properties::PropertyMap) -> Opti
.or_else(|| props.get("Communication_Properties", "Bandwidth"))
.or_else(|| props.get("", "Bandwidth"));

if let Some(val) = raw {
if let Some(bps) = parse_bandwidth(val) {
return Some(bps);
}
if let Some(bps) = raw.and_then(parse_bandwidth) {
return Some(bps);
}

// Fall back to Data_Rate.
Expand Down Expand Up @@ -253,8 +251,7 @@ fn compute_connection_demand(
// demand = Data_Size (bits) / Period (seconds)
// Period is in picoseconds, so Period_sec = period_ps / 1e12
// demand_bps = data_size_bits / (period_ps / 1e12) = data_size_bits * 1e12 / period_ps
let demand_bps = (data_size_bits as f64) * 1e12 / (period_ps as f64);
demand_bps
(data_size_bits as f64) * 1e12 / (period_ps as f64)
}

/// Get Data_Size for a component in bits.
Expand Down Expand Up @@ -342,10 +339,12 @@ fn parse_bandwidth(s: &str) -> Option<f64> {
fn parse_data_rate(s: &str) -> Option<f64> {
let s = s.trim();
for &(suffix, factor) in DATA_RATE_UNITS {
if let Some(num_str) = s.strip_suffix(suffix).map(|s| s.trim()) {
if let Ok(val) = num_str.parse::<f64>() {
return Some(val * factor);
}
if let Some(val) = s
.strip_suffix(suffix)
.map(|s| s.trim())
.and_then(|n| n.parse::<f64>().ok())
{
return Some(val * factor);
}
}
// Try plain number (assume bps).
Expand Down
22 changes: 13 additions & 9 deletions crates/spar-analysis/src/weight_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn bottom_up_order(instance: &SystemInstance) -> Vec<ComponentInstanceIdx> {
.map(|(idx, _)| (idx, component_depth(instance, idx)))
.collect();
// Sort by depth descending so leaves are processed first.
all.sort_by(|a, b| b.1.cmp(&a.1));
all.sort_by_key(|b| std::cmp::Reverse(b.1));
all.into_iter().map(|(idx, _)| idx).collect()
}

Expand Down Expand Up @@ -240,10 +240,12 @@ fn get_power_capacity_property(props: &spar_hir_def::properties::PropertyMap) ->
fn parse_weight_value(s: &str) -> Option<f64> {
let s = s.trim();
for &(suffix, factor) in WEIGHT_UNITS {
if let Some(num_str) = s.strip_suffix(suffix).map(|s| s.trim()) {
if let Ok(val) = num_str.parse::<f64>() {
return Some(val * factor);
}
if let Some(val) = s
.strip_suffix(suffix)
.map(|s| s.trim())
.and_then(|n| n.parse::<f64>().ok())
{
return Some(val * factor);
}
}
// Bare number: assume kg.
Expand All @@ -256,10 +258,12 @@ fn parse_weight_value(s: &str) -> Option<f64> {
fn parse_power_value(s: &str) -> Option<f64> {
let s = s.trim();
for &(suffix, factor) in POWER_UNITS {
if let Some(num_str) = s.strip_suffix(suffix).map(|s| s.trim()) {
if let Ok(val) = num_str.parse::<f64>() {
return Some(val * factor);
}
if let Some(val) = s
.strip_suffix(suffix)
.map(|s| s.trim())
.and_then(|n| n.parse::<f64>().ok())
{
return Some(val * factor);
}
}
// Bare number: assume mW.
Expand Down
5 changes: 5 additions & 0 deletions crates/spar-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ spar-analysis.workspace = true
spar-render.workspace = true
etch.workspace = true
rowan.workspace = true
salsa.workspace = true
serde.workspace = true
lsp-server = "0.7"
lsp-types = "0.97"
serde_json = "1"
toml.workspace = true

[dev-dependencies]
la-arena.workspace = true
rustc-hash = "2"
Loading
Loading