Skip to content

Commit 0851417

Browse files
committed
feat: resolve SPICE parametric expressions and sanitize numeric node names
Gap 12: Build a .param lookup table with multi-pass chained resolution so parameter references (e.g. `.param tstep=1n` used in `.tran tstep ...`) and brace expressions (`{Rval}`) resolve to concrete values during import. Gap 23: Prefix `n` to digit-leading SPICE node names (e.g. `1` → `n1`) so they form valid Cirq identifiers while preserving net identity. Adds 6 new test cases covering param resolution, brace expressions, chained params, and node name sanitization.
1 parent 3d676f5 commit 0851417

3 files changed

Lines changed: 362 additions & 93 deletions

File tree

cirq-frontend/src/lower.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
44
use cirq_ast::{
55
AnalysisDecl, AnalysisItem, Argument, Attribute, BinOp, Circuit, CircuitItem, CodeDecl,
6-
CoupledLineDecl, CoupledLineField, ElementInst, ExportDecl, Expr, FuncDecl, GlobalDecl,
7-
IcDecl, IcEntry, Ident, Import, LetDecl, ModelDef, ModelParam, ModuleDef, ModuleInst,
8-
OptionSetting, OptionsDecl, ParamDecl, PortDecl, PortDirection, QualifiedName, SaveDecl,
9-
SaveTarget, SourceFile, TempDecl, TopLevel, UnaryOp, span::Span,
6+
CoupledLineDecl, CoupledLineField, ElementInst, ExportDecl, Expr, FuncDecl, GlobalDecl, IcDecl,
7+
IcEntry, Ident, Import, LetDecl, ModelDef, ModelParam, ModuleDef, ModuleInst, OptionSetting,
8+
OptionsDecl, ParamDecl, PortDecl, PortDirection, QualifiedName, SaveDecl, SaveTarget,
9+
SourceFile, TempDecl, TopLevel, UnaryOp, span::Span,
1010
};
1111

1212
use crate::diagnostics::{Diagnostic, Severity};

cirq-frontend/src/resolve.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ fn parse_and_extract_named(
215215
let items = parse_and_resolve(source, file_path, search_paths, visited, diags);
216216

217217
let mut result = Vec::new();
218-
let wanted: std::collections::HashSet<&str> =
219-
names.iter().map(|n| n.name.as_str()).collect();
218+
let wanted: std::collections::HashSet<&str> = names.iter().map(|n| n.name.as_str()).collect();
220219
let mut found: std::collections::HashSet<&str> = std::collections::HashSet::new();
221220

222221
for item in &items {
@@ -537,14 +536,8 @@ mod tests {
537536
_ => None,
538537
})
539538
.collect();
540-
assert!(
541-
model_names.contains(&"nch"),
542-
"nch from export tt not found"
543-
);
544-
assert!(
545-
model_names.contains(&"pch"),
546-
"pch from export tt not found"
547-
);
539+
assert!(model_names.contains(&"nch"), "nch from export tt not found");
540+
assert!(model_names.contains(&"pch"), "pch from export tt not found");
548541

549542
// Should NOT have the bare model (not in any export).
550543
assert!(
@@ -687,8 +680,14 @@ mod tests {
687680
})
688681
.collect();
689682

690-
assert!(model_names.contains(&"nch_tt"), "tt export should be imported");
691-
assert!(model_names.contains(&"nch_ff"), "ff export should be imported");
683+
assert!(
684+
model_names.contains(&"nch_tt"),
685+
"tt export should be imported"
686+
);
687+
assert!(
688+
model_names.contains(&"nch_ff"),
689+
"ff export should be imported"
690+
);
692691
assert!(
693692
!model_names.contains(&"nch_ss"),
694693
"ss export should NOT be imported"

0 commit comments

Comments
 (0)