celox_frontend_core/
error.rs1use celox_sir::verify::SirVerifyError;
2use celox_slt::{SLTNodeFactsError, scheduler::SchedulerError};
3use thiserror::Error;
4
5#[derive(Debug, Clone)]
6pub struct SourceLocation {
7 pub path: String,
8 pub text: String,
9 pub span: miette::SourceSpan,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum LoweringPhase {
14 FfLowering,
15 CombLowering,
16 SimulatorParser,
17}
18
19impl std::fmt::Display for LoweringPhase {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 match self {
22 Self::FfLowering => write!(f, "FF lowering"),
23 Self::CombLowering => write!(f, "comb lowering"),
24 Self::SimulatorParser => write!(f, "simulator parser"),
25 }
26 }
27}
28
29#[derive(Error, Debug)]
30pub enum ParserError {
31 #[error(transparent)]
32 Scheduler(SchedulerError<String>),
33 #[error("{error}")]
34 SchedulerWithLocation {
35 error: SchedulerError<String>,
36 source_locations: Vec<SourceLocation>,
37 },
38 #[error("Unsupported in {phase}: {feature} [tracking issue #{issue}] ({detail})")]
39 Unsupported {
40 issue: u32,
41 phase: LoweringPhase,
42 feature: &'static str,
43 detail: String,
44 source_location: Option<SourceLocation>,
45 },
46 #[error("Illegal in current context: {feature} ({detail})")]
47 IllegalContext {
48 feature: &'static str,
49 detail: String,
50 source_location: Option<SourceLocation>,
51 },
52 #[error("Top module `{name}` not found in IR")]
53 TopNotFound { name: String },
54 #[error("Top module `{name}` is generic and cannot be used as a top-level module")]
55 GenericTop { name: String },
56 #[error("SIR verification failed {phase} in {group} unit {unit}: {error}")]
57 SirVerify {
58 phase: &'static str,
59 group: &'static str,
60 unit: usize,
61 #[source]
62 error: SirVerifyError,
63 },
64 #[error("SLT verification failed {phase}: {error}")]
65 SltVerify {
66 phase: &'static str,
67 #[source]
68 error: SLTNodeFactsError,
69 },
70 #[error("SLT construction failed: {0}")]
71 SltConstruction(#[from] SLTNodeFactsError),
72}
73
74impl ParserError {
75 pub fn unsupported(
76 issue: u32,
77 phase: LoweringPhase,
78 feature: &'static str,
79 detail: impl Into<String>,
80 source_location: Option<SourceLocation>,
81 ) -> Self {
82 Self::Unsupported {
83 issue,
84 phase,
85 feature,
86 detail: detail.into(),
87 source_location,
88 }
89 }
90
91 pub fn illegal_context(
92 feature: &'static str,
93 detail: impl Into<String>,
94 source_location: Option<SourceLocation>,
95 ) -> Self {
96 Self::IllegalContext {
97 feature,
98 detail: detail.into(),
99 source_location,
100 }
101 }
102}