Skip to main content

xlsynth_codegen/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use std::fmt;
4
5/// Explains why a block cannot be represented as supported SystemVerilog.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum BlockCodegenError {
8    /// The package has no uniquely identifiable block top.
9    TopSelection(String),
10    /// The input block violates a structural code-generation requirement.
11    InvalidBlock(String),
12    /// A valid IR construct has no supported SystemVerilog representation.
13    Unsupported(String),
14    /// Register dependencies cannot form a strictly layered pipeline.
15    NotPipeline(String),
16    /// Building the SystemVerilog syntax tree failed.
17    Emission(String),
18}
19
20impl fmt::Display for BlockCodegenError {
21    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Self::TopSelection(message)
24            | Self::InvalidBlock(message)
25            | Self::Unsupported(message)
26            | Self::NotPipeline(message)
27            | Self::Emission(message) => formatter.write_str(message),
28        }
29    }
30}
31
32impl std::error::Error for BlockCodegenError {}
33
34impl From<xlsynth_vast::VastError> for BlockCodegenError {
35    fn from(error: xlsynth_vast::VastError) -> Self {
36        Self::Emission(error.to_string())
37    }
38}
39
40impl From<xlsynth::XlsynthError> for BlockCodegenError {
41    fn from(error: xlsynth::XlsynthError) -> Self {
42        Self::Emission(error.to_string())
43    }
44}
45
46impl From<xlsynth_pir::ValueError> for BlockCodegenError {
47    fn from(error: xlsynth_pir::ValueError) -> Self {
48        Self::Emission(error.to_string())
49    }
50}