Skip to content

Commit 22532a9

Browse files
authored
feat(compiler): gracefully handle missing LYP file (#111)
* feat(compiler): gracefully handle missing LYP file * handle parse failure gracefully
1 parent 887709f commit 22532a9

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
lyp = "../lyp/sky130.lyp"
1+
lyp = "../../../../pdks/sky130/sky130.lyp"
22

33
[mods]
44
sky130 = "../../../../pdks/sky130"

core/compiler/src/compile.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn dynamic_compile(
7171
}
7272
}
7373
CompileOutput::Valid(v) => (v, Vec::new()),
74-
_ => unreachable!(),
74+
o => return o,
7575
};
7676
check_layers(&data, &mut errors);
7777
if errors.is_empty() {
@@ -2023,11 +2023,22 @@ impl<'a> ExecPass<'a> {
20232023
_ => None,
20242024
}) {
20252025
let cell_id = self.execute_cell(vid, input.args, Some("TOP"));
2026-
let layers = klayout_lyp::from_reader(BufReader::new(
2027-
std::fs::File::open(input.lyp_file).unwrap(),
2028-
))
2029-
.unwrap()
2030-
.into();
2026+
let layers = if let Ok(layers) = std::fs::File::open(input.lyp_file)
2027+
.map_err(|_| ())
2028+
.and_then(|f| klayout_lyp::from_reader(BufReader::new(f)).map_err(|_| ()))
2029+
{
2030+
layers.into()
2031+
} else {
2032+
return CompileOutput::StaticErrors(StaticErrorCompileOutput {
2033+
errors: vec![StaticError {
2034+
span: Span {
2035+
path: self.ast[&vec![]].path.clone(),
2036+
span: cfgrammar::Span::new(0, 0),
2037+
},
2038+
kind: StaticErrorKind::InvalidLyp,
2039+
}],
2040+
});
2041+
};
20312042
if self.errors.is_empty() {
20322043
CompileOutput::Valid(CompiledData {
20332044
cells: self.compiled_cells,
@@ -4050,6 +4061,9 @@ pub enum StaticErrorKind {
40504061
/// Error during parsing.
40514062
#[error("error during parsing")]
40524063
ParseError,
4064+
/// Invalid LYP file.
4065+
#[error("invalid LYP file")]
4066+
InvalidLyp,
40534067
}
40544068

40554069
#[derive(Debug, Clone, Serialize, Deserialize)]

0 commit comments

Comments
 (0)