Skip to content
Closed
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
6 changes: 6 additions & 0 deletions crates/celox-frontend-sv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ pub use lowering::{
schedule_sources,
};
pub use lowering::{InterfaceSignature, interface_signatures, interface_signatures_for};

pub use celox_sv_analyzer::AnalysisOptions;
pub use lowering::{
interface_signatures_for_with_options,
prepare_external_hierarchy_with_foreign_resolver_with_options, schedule_sources_with_options,
};
104 changes: 98 additions & 6 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ impl LoweredSvModuleKey {
fn analyze_sources(
sources: &[(&str, &Path)],
roots: &[&str],
analysis_options: sv::AnalysisOptions,
) -> Result<HashMap<String, AnalyzedSvModule>, sv::AnalyzerError> {
analyze_sources_with_requests(
sources,
&ExternalHierarchy::default(),
&[],
&[],
Some(roots),
analysis_options,
)
.map(|(modules, _)| modules)
}
Expand Down Expand Up @@ -224,9 +226,19 @@ pub fn interface_signatures_for(
sources: &[(&str, &Path)],
names: Option<&HashSet<String>>,
warnings: &mut Vec<crate::FrontendWarning>,
) -> Result<Vec<InterfaceSignature>, FrontendError> {
interface_signatures_for_with_options(sources, names, warnings, sv::AnalysisOptions::default())
}

/// Probe interface signatures with explicit language compatibility options.
pub fn interface_signatures_for_with_options(
sources: &[(&str, &Path)],
names: Option<&HashSet<String>>,
warnings: &mut Vec<crate::FrontendWarning>,
analysis_options: sv::AnalysisOptions,
) -> Result<Vec<InterfaceSignature>, FrontendError> {
let mut found = Vec::new();
let signatures = interface_signatures_collecting(sources, names, &mut found);
let signatures = interface_signatures_collecting(sources, names, &mut found, analysis_options);
append_error_warnings(&signatures, &mut found);
crate::warning::append_unique_warnings(sources, warnings, found);
signatures
Expand All @@ -245,8 +257,9 @@ fn interface_signatures_collecting(
sources: &[(&str, &Path)],
names: Option<&HashSet<String>>,
warnings: &mut Vec<crate::warning::PendingWarning>,
analysis_options: sv::AnalysisOptions,
) -> Result<Vec<InterfaceSignature>, FrontendError> {
let prototypes = sv::interface_prototypes_for(sources, names)?;
let prototypes = sv::interface_prototypes_with_options(sources, names, analysis_options)?;
if prototypes.is_empty() {
return Ok(Vec::new());
}
Expand Down Expand Up @@ -321,6 +334,7 @@ fn analyze_sources_with_requests(
declarations: &[(&str, &Path)],
requests: &[SvModuleRequest],
roots: Option<&[&str]>,
analysis_options: sv::AnalysisOptions,
) -> Result<(HashMap<String, AnalyzedSvModule>, HashMap<String, String>), sv::AnalyzerError> {
if !declarations.is_empty() {
for (code, path) in sources {
Expand All @@ -347,7 +361,11 @@ fn analyze_sources_with_requests(
.collect::<Vec<_>>()
});
let time_declarations = if declarations.iter().any(|(code, _)| !code.is_empty()) {
sv::generated_time_declarations(sources, selected_roots.as_deref())?
sv::generated_time_declarations_with_options(
sources,
selected_roots.as_deref(),
analysis_options,
)?
} else {
String::new()
};
Expand Down Expand Up @@ -433,9 +451,13 @@ fn analyze_sources_with_requests(
.unwrap_or(root)
})
.collect::<Vec<_>>();
sv::ParsedSource::analyze_packages_with_roots(&parsed, &roots)?
sv::ParsedSource::analyze_packages_with_options(
&parsed,
Some(&roots),
analysis_options,
)?
}
None => sv::ParsedSource::analyze_packages(&parsed)?,
None => sv::ParsedSource::analyze_packages_with_options(&parsed, None, analysis_options)?,
};
packages.set_interface_plan(elaboration.clone());
let packages = std::rc::Rc::new(packages);
Expand Down Expand Up @@ -1233,6 +1255,34 @@ pub fn prepare_external_hierarchy_with_foreign_resolver(
top_parameters: Option<(&str, &[(String, u64)])>,
requests: &[SvModuleRequest],
warnings: &mut Vec<crate::FrontendWarning>,
) -> Result<ExternalHierarchy, FrontendError> {
prepare_external_hierarchy_with_foreign_resolver_with_options(
sources,
root_names,
foreign,
declarations,
four_state,
resolver,
top_parameters,
requests,
warnings,
sv::AnalysisOptions::default(),
)
}

/// Prepare a mixed hierarchy with explicit language compatibility options.
#[allow(clippy::too_many_arguments)]
pub fn prepare_external_hierarchy_with_foreign_resolver_with_options(
sources: &[(&str, &Path)],
root_names: &HashSet<String>,
foreign: &ExternalHierarchy,
declarations: &[(&str, &Path)],
four_state: bool,
resolver: Option<&mut ForeignModuleResolver<'_>>,
top_parameters: Option<(&str, &[(String, u64)])>,
requests: &[SvModuleRequest],
warnings: &mut Vec<crate::FrontendWarning>,
analysis_options: sv::AnalysisOptions,
) -> Result<ExternalHierarchy, FrontendError> {
let mut found = Vec::new();
let hierarchy = prepare_external_hierarchy_collecting(
Expand All @@ -1245,6 +1295,7 @@ pub fn prepare_external_hierarchy_with_foreign_resolver(
top_parameters,
requests,
&mut found,
analysis_options,
);
append_error_warnings(&hierarchy, &mut found);
crate::warning::append_unique_warnings(sources, warnings, found);
Expand All @@ -1262,13 +1313,15 @@ fn prepare_external_hierarchy_collecting(
top_parameters: Option<(&str, &[(String, u64)])>,
requests: &[SvModuleRequest],
warnings: &mut Vec<crate::warning::PendingWarning>,
analysis_options: sv::AnalysisOptions,
) -> Result<ExternalHierarchy, FrontendError> {
let (analyzed, bound_names) = analyze_sources_with_requests(
sources,
foreign,
declarations,
requests,
Some(&root_names.iter().map(String::as_str).collect::<Vec<_>>()),
analysis_options,
)?;
package_warnings(&analyzed, warnings);
let dummy = sv::ParsedSource::parse(
Expand Down Expand Up @@ -1651,6 +1704,43 @@ pub fn schedule_sources(
trace_options: &FrontendTraceOptions,
trace: Option<&mut FrontendTrace>,
warnings: &mut Vec<crate::FrontendWarning>,
) -> Result<ScheduledRtlOutput, FrontendError> {
schedule_sources_with_options(
sources,
top,
parameter_overrides,
ignored_loops,
true_loops,
four_state,
parallel,
trace_options,
trace,
warnings,
sv::AnalysisOptions::default(),
)
}

/// Schedule a design with explicit language compatibility options.
#[allow(clippy::too_many_arguments)]
pub fn schedule_sources_with_options(
sources: &[(&str, &Path)],
top: &str,
parameter_overrides: &[(String, u64)],
ignored_loops: &[(
(Vec<(String, usize)>, Vec<String>),
(Vec<(String, usize)>, Vec<String>),
)],
true_loops: &[(
(Vec<(String, usize)>, Vec<String>),
(Vec<(String, usize)>, Vec<String>),
usize,
)],
four_state: bool,
parallel: &celox_frontend_core::ParallelScheduleOptions,
trace_options: &FrontendTraceOptions,
trace: Option<&mut FrontendTrace>,
warnings: &mut Vec<crate::FrontendWarning>,
analysis_options: sv::AnalysisOptions,
) -> Result<ScheduledRtlOutput, FrontendError> {
let mut found = Vec::new();
let scheduled = schedule_sources_collecting(
Expand All @@ -1664,6 +1754,7 @@ pub fn schedule_sources(
trace_options,
trace,
&mut found,
analysis_options,
);
append_error_warnings(&scheduled, &mut found);
crate::warning::append_unique_warnings(sources, warnings, found);
Expand All @@ -1689,8 +1780,9 @@ fn schedule_sources_collecting(
trace_options: &FrontendTraceOptions,
trace: Option<&mut FrontendTrace>,
warnings: &mut Vec<crate::warning::PendingWarning>,
analysis_options: sv::AnalysisOptions,
) -> Result<ScheduledRtlOutput, FrontendError> {
let analyzed = analyze_sources(sources, &[top])?;
let analyzed = analyze_sources(sources, &[top], analysis_options)?;
package_warnings(&analyzed, warnings);
let top = top.to_string();
let root_key = LoweredSvModuleKey {
Expand Down
10 changes: 10 additions & 0 deletions crates/celox-frontend-sv/src/warning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ impl Eq for FrontendWarning {}
/// What a [`FrontendWarning`] reports.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, thiserror::Error)]
pub enum FrontendWarningKind {
/// IEEE 1800-2023 3.14.2.3 requires consistent explicit timing declarations.
#[error("mixed explicit and default time units or precisions across design elements")]
MixedTimescale,
/// A memory file without address directives holds a different number of
/// words than the address range of `$readmemh`/`$readmemb`
/// (IEEE 1800-2023 21.4).
Expand Down Expand Up @@ -85,6 +88,9 @@ pub(crate) fn analyzer_warnings(
found: &[celox_sv_analyzer::ir::AnalyzerWarning],
) -> impl Iterator<Item = PendingWarning> + '_ {
found.iter().map(|warning| match warning {
celox_sv_analyzer::ir::AnalyzerWarning::MixedTimescale => {
(FrontendWarningKind::MixedTimescale, None)
}
celox_sv_analyzer::ir::AnalyzerWarning::ExitOutsideProgram { site } => {
(FrontendWarningKind::ExitOutsideProgram, site.clone())
}
Expand Down Expand Up @@ -134,6 +140,7 @@ pub(crate) fn append_unique_warnings(
impl miette::Diagnostic for FrontendWarning {
fn code<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
Some(Box::new(match self.kind {
FrontendWarningKind::MixedTimescale => "mixed_timescale",
FrontendWarningKind::MemoryFileWordCount { .. } => "memory_file_word_count",
FrontendWarningKind::ExitOutsideProgram => "exit_outside_program",
}))
Expand All @@ -145,6 +152,9 @@ impl miette::Diagnostic for FrontendWarning {

fn help<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
Some(Box::new(match self.kind {
FrontendWarningKind::MixedTimescale => {
"declare timeunit/timeprecision consistently; undeclared scopes use 1ns/1ps when this check is relaxed"
}
FrontendWarningKind::MemoryFileWordCount { .. } => {
"give one word per address of the range, or place the words with `@address` directives"
}
Expand Down
Loading
Loading