Skip to content

Commit e36d8b2

Browse files
authored
Merge branch 'main' into any-type
2 parents e088faf + 5a3c340 commit e36d8b2

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ vim.cmd([[autocmd BufRead,BufNewFile *.ar setfiletype argon]])
5858
To open an example Argon workspace, run the following from the root directory of your Argon clone:
5959

6060
```
61-
vim pdks/sky130/lib.ar
61+
nvim pdks/sky130/lib.ar
6262
```
6363

6464
Start the GUI by running `:Argon gui`.

core/compiler/src/compile.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,12 +1291,10 @@ impl<'a> AstTransformer for VarIdTyPass<'a> {
12911291
) -> <Self::OutputMetadata as AstMetadata>::UnaryOpExpr {
12921292
match input.op {
12931293
UnaryOp::Not => {
1294-
if operand.ty() != Ty::Bool {
1295-
self.errors.push(StaticError {
1296-
span: self.span(operand.span()),
1297-
kind: StaticErrorKind::UnaryOpInvalidType,
1298-
});
1299-
}
1294+
self.errors.push(StaticError {
1295+
span: self.span(input.span),
1296+
kind: StaticErrorKind::Unimplemented,
1297+
});
13001298
Ty::Bool
13011299
}
13021300
UnaryOp::Neg => {
@@ -1881,6 +1879,7 @@ struct ExecScope {
18811879
struct FallbackConstraint {
18821880
priority: i32,
18831881
constraint: LinearExpr,
1882+
span: Span,
18841883
}
18851884

18861885
impl PartialEq for FallbackConstraint {
@@ -1916,6 +1915,7 @@ struct CellState {
19161915
fallback_constraints: BinaryHeap<FallbackConstraint>,
19171916
fallback_constraints_used: Vec<LinearExpr>,
19181917
unsolved_vars: Option<IndexSet<Var>>,
1918+
constraint_span_map: IndexMap<ConstraintId, Span>,
19191919
}
19201920

19211921
struct ExecPass<'a> {
@@ -2154,6 +2154,7 @@ impl<'a> ExecPass<'a> {
21542154
root_scope: root_scope_id,
21552155
unsolved_vars: Default::default(),
21562156
objects: Default::default(),
2157+
constraint_span_map: IndexMap::new(),
21572158
}
21582159
)
21592160
.is_none()
@@ -2234,16 +2235,18 @@ impl<'a> ExecPass<'a> {
22342235
}
22352236
let mut constraint_added = false;
22362237
let state = self.cell_state_mut(cell_id);
2237-
while let Some(FallbackConstraint { constraint, .. }) =
2238-
state.fallback_constraints.pop()
2238+
while let Some(FallbackConstraint {
2239+
constraint, span, ..
2240+
}) = state.fallback_constraints.pop()
22392241
{
22402242
if constraint
22412243
.coeffs
22422244
.iter()
22432245
.any(|(c, v)| c.abs() > 1e-6 && !state.solver.is_solved(*v))
22442246
{
22452247
state.fallback_constraints_used.push(constraint.clone());
2246-
state.solver.constrain_eq0(constraint);
2248+
let constraint_id = state.solver.constrain_eq0(constraint);
2249+
state.constraint_span_map.insert(constraint_id, span);
22472250
constraint_added = true;
22482251
break;
22492252
}
@@ -2262,18 +2265,25 @@ impl<'a> ExecPass<'a> {
22622265
require_progress = true;
22632266
}
22642267
}
2268+
22652269
let state = self.cell_state_mut(cell_id);
22662270
if progress {
22672271
state.solve_iters += 1;
22682272
state.solver.solve();
22692273
}
22702274
for constraint in state.solver.inconsistent_constraints().clone() {
2275+
let span = self
2276+
.cell_state(cell_id)
2277+
.constraint_span_map
2278+
.get(&constraint)
2279+
.cloned();
22712280
self.errors.push(ExecError {
2272-
span: None,
2281+
span,
22732282
cell: cell_id,
22742283
kind: ExecErrorKind::InconsistentConstraint(constraint),
22752284
});
22762285
}
2286+
22772287
self.partial_cells
22782288
.pop_back()
22792289
.expect("failed to pop cell id");
@@ -2917,6 +2927,7 @@ impl<'a> ExecPass<'a> {
29172927
}
29182928
x => unreachable!("unsupported kwarg `{x}`"),
29192929
};
2930+
let span = self.span(&vref.loc, kwarg.span);
29202931
let defer = self.value_id();
29212932
self.values.insert(
29222933
defer,
@@ -2926,6 +2937,7 @@ impl<'a> ExecPass<'a> {
29262937
rhs: *rhs,
29272938
fallback: kwarg.name.name.ends_with('i'),
29282939
priority,
2940+
span,
29292941
}),
29302942
loc: vref.loc,
29312943
}),
@@ -3065,7 +3077,15 @@ impl<'a> ExecPass<'a> {
30653077
) {
30663078
let expr = vl.as_ref().unwrap_linear().clone()
30673079
- vr.as_ref().unwrap_linear().clone();
3068-
state.solver.constrain_eq0(expr);
3080+
let constraint = state.solver.constrain_eq0(expr);
3081+
3082+
state.constraint_span_map.insert(
3083+
constraint,
3084+
Span {
3085+
path: state.scopes[&vref.loc.scope].span.path.clone(),
3086+
span: c.expr.span,
3087+
},
3088+
);
30693089
self.values.insert(vid, Defer::Ready(Value::Nil));
30703090
true
30713091
} else {
@@ -3174,6 +3194,7 @@ impl<'a> ExecPass<'a> {
31743194
constraint,
31753195
span: Some(span.clone()),
31763196
};
3197+
state.constraint_span_map.insert(constraint, span.clone());
31773198
state.object_emit.push(ObjectEmit {
31783199
scope: vref.loc.scope,
31793200
object: dim.id,
@@ -3304,6 +3325,7 @@ impl<'a> ExecPass<'a> {
33043325
}
33053326
_ => continue,
33063327
};
3328+
let span = self.span(&vref.loc, kwarg.span);
33073329
let defer = self.value_id();
33083330
self.values.insert(
33093331
defer,
@@ -3313,6 +3335,7 @@ impl<'a> ExecPass<'a> {
33133335
rhs: *rhs,
33143336
fallback: kwarg.name.name.ends_with('i'),
33153337
priority,
3338+
span,
33163339
}),
33173340
loc: vref.loc,
33183341
}),
@@ -3773,9 +3796,11 @@ impl<'a> ExecPass<'a> {
37733796
state.fallback_constraints.push(FallbackConstraint {
37743797
priority: c.priority,
37753798
constraint: expr,
3799+
span: c.span.clone(),
37763800
});
37773801
} else {
3778-
state.solver.constrain_eq0(expr);
3802+
let constraint = state.solver.constrain_eq0(expr);
3803+
state.constraint_span_map.insert(constraint, c.span.clone());
37793804
}
37803805
self.values.insert(vid, DeferValue::Ready(Value::Nil));
37813806
true
@@ -4241,6 +4266,9 @@ pub enum StaticErrorKind {
42414266
/// Invalid LYP file.
42424267
#[error("invalid LYP file")]
42434268
InvalidLyp,
4269+
/// Unimplemented.
4270+
#[error("unimplemented")]
4271+
Unimplemented,
42444272
}
42454273

42464274
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -4348,6 +4376,7 @@ struct PartialConstraint {
43484376
rhs: ValueId,
43494377
fallback: bool,
43504378
priority: i32,
4379+
span: Span,
43514380
}
43524381

43534382
#[derive(Debug, Clone)]

core/compiler/src/gds.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{io::BufReader, ops::Deref, path::Path};
33
use anyhow::{Result, anyhow};
44
use gds21::{
55
GdsBoundary, GdsElement, GdsLayerSpec, GdsLibrary, GdsPoint, GdsStrans, GdsStruct,
6-
GdsStructRef, GdsTextElem,
6+
GdsStructRef, GdsTextElem, GdsUnits,
77
};
88
use indexmap::IndexMap;
99
use regex::Regex;
@@ -23,13 +23,19 @@ struct GdsExporter {
2323
}
2424

2525
impl GdsExporter {
26-
fn new(name: impl Into<String>, map: GdsMap) -> Self {
26+
fn new(name: impl Into<String>, map: GdsMap, units: GdsUnits) -> Self {
27+
let mut lib = GdsLibrary::new(name);
28+
lib.units = units;
2729
Self {
28-
lib: GdsLibrary::new(name),
30+
lib,
2931
map,
3032
names: Names::new(),
3133
}
3234
}
35+
36+
fn coord_to_gds(&self, coord: f64) -> i32 {
37+
(coord * 1e-9 / self.lib.units.db_unit()) as i32
38+
}
3339
}
3440

3541
impl FromIterator<(String, GdsLayerSpec)> for GdsMap {
@@ -55,7 +61,7 @@ impl GdsMap {
5561
lyp.layers
5662
.into_iter()
5763
.map(|layer_prop| {
58-
let re = Regex::new(r"(\d*)/(\d*)@\d*")?;
64+
let re = Regex::new(r"(\d*)/(\d*)(@\d*)?")?;
5965
let caps = re
6066
.captures(&layer_prop.source)
6167
.ok_or_else(|| anyhow!("parse error"))?;
@@ -83,10 +89,10 @@ impl GdsMap {
8389
}
8490

8591
impl CompileOutput {
86-
pub fn to_gds(&self, map: GdsMap, out_path: impl AsRef<Path>) -> Result<()> {
92+
pub fn to_gds(&self, map: GdsMap, units: GdsUnits, out_path: impl AsRef<Path>) -> Result<()> {
8793
let out_path = out_path.as_ref();
8894
trace!("Exporting to gds at {out_path:?}");
89-
let mut exporter = GdsExporter::new("TOP", map);
95+
let mut exporter = GdsExporter::new("TOP", map, units);
9096
if let CompileOutput::Valid(output)
9197
| CompileOutput::ExecErrors(ExecErrorCompileOutput {
9298
errors: _,
@@ -125,10 +131,10 @@ impl CompiledData {
125131
layer,
126132
xtype: datatype,
127133
} = exporter.map[layer];
128-
let x0 = rect.x0.0 as i32;
129-
let x1 = rect.x1.0 as i32;
130-
let y0 = rect.y0.0 as i32;
131-
let y1 = rect.y1.0 as i32;
134+
let x0 = exporter.coord_to_gds(rect.x0.0);
135+
let x1 = exporter.coord_to_gds(rect.x1.0);
136+
let y0 = exporter.coord_to_gds(rect.y0.0);
137+
let y1 = exporter.coord_to_gds(rect.y1.0);
132138
ocell.elems.push(GdsElement::GdsBoundary(GdsBoundary {
133139
layer,
134140
datatype,
@@ -161,7 +167,7 @@ impl CompiledData {
161167
self.cell_to_gds(exporter, i.cell)?;
162168
ocell.elems.push(GdsElement::GdsStructRef(GdsStructRef {
163169
name: exporter.names.name(&i.cell).unwrap().to_string(),
164-
xy: GdsPoint::new(i.x as i32, i.y as i32),
170+
xy: GdsPoint::new(exporter.coord_to_gds(i.x), exporter.coord_to_gds(i.y)),
165171
strans: Some(GdsStrans {
166172
reflected: i.reflect,
167173
abs_mag: false,

core/lang-server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl StateMut {
134134
.unwrap_or_else(|| {
135135
PathBuf::from(concat!(
136136
env!("CARGO_MANIFEST_DIR"),
137-
"/../../core/compiler/examples/lyp/basic.lyp"
137+
"/../../pdks/sky130/sky130.lyp"
138138
))
139139
});
140140
let parse_output = parse::parse_workspace_with_std(root_dir.join("lib.ar"));

0 commit comments

Comments
 (0)