Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ rust_decimal_macros = "1"
indexmap = { version = "2", features = ["serde"] }
clap = { version = "4", features = ["derive"] }
geometry = { version = "0.7", registry = "substrate" }
rgb = { version = "0.8", features = ["serde"] }
klayout-lyp = "0.1.1"

[build-dependencies]
cfgrammar = "0.13"
Expand Down
6 changes: 3 additions & 3 deletions core/compiler/examples/cell_out_of_order.ar
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ cell top() {
eq(left.y, 0.);
eq(right.x, 300.);
eq(right.y, 0.);
let met3 = rect(Layer::Met3, x0=left.met1.x0, y0=20., x1=right.met1.x1, y1=80.)!;
let met3 = rect("met3", x0=left.met1.x0, y0=20., x1=right.met1.x1, y1=80.)!;
}

cell bot() {
let met1 = rect(Layer::Met1, x0=0., y0=0., x1=100., y1=100.)!;
let met2 = rect(Layer::Met1, x0=100., y0=0., x1=200., y1=100.)!;
let met1 = rect("met1", x0=0., y0=0., x1=100., y1=100.)!;
let met2 = rect("met1", x0=100., y0=0., x1=200., y1=100.)!;
}

2 changes: 1 addition & 1 deletion core/compiler/examples/func_out_of_order.ar
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn double(x: Float) -> Float {
}

cell test() {
let shape = rect(Layer::Met1)!;
let shape = rect("met1")!;
eq(shape.x0, 0.);
eq(shape.y0, 0.);
eq(shape.y1, 100.);
Expand Down
6 changes: 3 additions & 3 deletions core/compiler/examples/hierarchy.ar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cell bot() {
let met1 = rect(Layer::Met1, x0=0., y0=0., x1=100., y1=100.)!;
let met2 = rect(Layer::Met1, x0=100., y0=0., x1=200., y1=100.)!;
let met1 = rect("met1", x0=0., y0=0., x1=100., y1=100.)!;
let met2 = rect("met1", x0=100., y0=0., x1=200., y1=100.)!;
}

cell top() {
Expand All @@ -11,6 +11,6 @@ cell top() {
eq(left.y, 0.);
eq(right.x, 300.);
eq(right.y, 0.);
let met3 = rect(Layer::Met3, x0=left.met1.x0, y0=20., x1=right.met1.x1, y1=80.)!;
let met3 = rect("met3", x0=left.met1.x0, y0=20., x1=right.met1.x1, y1=80.)!;
}

123 changes: 123 additions & 0 deletions core/compiler/examples/lyp/basic.lyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-properties>
<name>Basic Layer Properties</name>
<properties>
<frame-color>#0000ff</frame-color>
<fill-color>#0000ff</fill-color>
<frame-brightness>0</frame-brightness>
<fill-brightness>0</fill-brightness>
<dither-pattern>C7</dither-pattern>
<line-style>C0</line-style>
<valid>true</valid>
<visible>true</visible>
<transparent>false</transparent>
<width>1</width>
<marked>false</marked>
<xfill>false</xfill>
<animation>0</animation>
<name>met1</name>
<source>235/4@1</source>
</properties>
<properties>
<frame-color>#5e00e6</frame-color>
<fill-color>#5e00e6</fill-color>
<frame-brightness>0</frame-brightness>
<fill-brightness>0</fill-brightness>
<dither-pattern>C7</dither-pattern>
<line-style>C0</line-style>
<valid>true</valid>
<visible>true</visible>
<transparent>false</transparent>
<width>1</width>
<marked>false</marked>
<xfill>false</xfill>
<animation>0</animation>
<name>via1</name>
<source>235/4@1</source>
</properties>
<properties>
<frame-color>#ff00ff</frame-color>
<fill-color>#ff00ff</fill-color>
<frame-brightness>0</frame-brightness>
<fill-brightness>0</fill-brightness>
<dither-pattern>C7</dither-pattern>
<line-style>C0</line-style>
<valid>true</valid>
<visible>true</visible>
<transparent>false</transparent>
<width>1</width>
<marked>false</marked>
<xfill>false</xfill>
<animation>0</animation>
<name>met2</name>
<source>235/4@1</source>
</properties>
<properties>
<frame-color>#ff8000</frame-color>
<fill-color>#ff8000</fill-color>
<frame-brightness>0</frame-brightness>
<fill-brightness>0</fill-brightness>
<dither-pattern>C7</dither-pattern>
<line-style>C0</line-style>
<valid>true</valid>
<visible>true</visible>
<transparent>false</transparent>
<width>1</width>
<marked>false</marked>
<xfill>false</xfill>
<animation>0</animation>
<name>via2</name>
<source>235/4@1</source>
</properties>
<properties>
<frame-color>#00ffff</frame-color>
<fill-color>#00ffff</fill-color>
<frame-brightness>0</frame-brightness>
<fill-brightness>0</fill-brightness>
<dither-pattern>C7</dither-pattern>
<line-style>C0</line-style>
<valid>true</valid>
<visible>true</visible>
<transparent>false</transparent>
<width>1</width>
<marked>false</marked>
<xfill>false</xfill>
<animation>0</animation>
<name>met3</name>
<source>235/4@1</source>
</properties>
<properties>
<frame-color>#268c6b</frame-color>
<fill-color>#268c6b</fill-color>
<frame-brightness>0</frame-brightness>
<fill-brightness>0</fill-brightness>
<dither-pattern>C7</dither-pattern>
<line-style>C0</line-style>
<valid>true</valid>
<visible>true</visible>
<transparent>false</transparent>
<width>1</width>
<marked>false</marked>
<xfill>false</xfill>
<animation>0</animation>
<name>via3</name>
<source>235/4@1</source>
</properties>
<properties>
<frame-color>#5e00e6</frame-color>
<fill-color>#5e00e6</fill-color>
<frame-brightness>0</frame-brightness>
<fill-brightness>0</fill-brightness>
<dither-pattern>C7</dither-pattern>
<line-style>C0</line-style>
<valid>true</valid>
<visible>true</visible>
<transparent>false</transparent>
<width>1</width>
<marked>false</marked>
<xfill>false</xfill>
<animation>0</animation>
<name>met4</name>
<source>235/4@1</source>
</properties>
</layer-properties>
10 changes: 5 additions & 5 deletions core/compiler/examples/nested_inst.ar
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
cell bot() {
let met1 = rect(Layer::Met1, x0=0., y0=0., x1=100., y1=100.)!;
let met2 = rect(Layer::Met1, x0=100., y0=0., x1=200., y1=100.)!;
let met1 = rect("met1", x0=0., y0=0., x1=100., y1=100.)!;
let met2 = rect("met1", x0=100., y0=0., x1=200., y1=100.)!;
let met3 = make_rect()!;
let met4 = emit_rect();
}

fn make_rect() -> Rect {
rect(Layer::Met2, x0=0., y0=0., x1=200., y1=100.)
rect("met2", x0=0., y0=0., x1=200., y1=100.)
}

fn emit_rect() -> Rect {
rect(Layer::Met2, x0=0., y0=0., x1=200., y1=100.)!
rect("met2", x0=0., y0=0., x1=200., y1=100.)!
}

cell middle() {
Expand All @@ -27,7 +27,7 @@ cell top() {
eq(left.y, 0.);
eq(right.x, 300.);
eq(right.y, 0.);
let met3 = rect(Layer::Met3, x0=left.bot.met1.x0, y0=20., x1=right.bot.met1.x1, y1=80.)!;
let met3 = rect("met3", x0=left.bot.met1.x0, y0=20., x1=right.bot.met1.x1, y1=80.)!;
let duplicate_rect = left.bot.met3!;
}

2 changes: 1 addition & 1 deletion core/compiler/examples/scopes.ar
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ cell scopes() {
let tmp = z + x0;
tmp
};
rect(Layer::Met1, x0=x0, y0=y0, w=z, h=w)!;
rect("met1", x0=x0, y0=y0, w=z, h=w)!;
}
4 changes: 2 additions & 2 deletions core/compiler/examples/via.ar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cell via() {
let via = rect(Layer::Via1)!;
let met1 = rect(Layer::Met1)!;
let via = rect("via1")!;
let met1 = rect("met1")!;
eq(via.h, 40.);
eq(via.w, if met1.w < 20. {
10.
Expand Down
6 changes: 3 additions & 3 deletions core/compiler/examples/via_array.ar
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ fn max_array(r: Rect, w: Float, h: Float, xpitch: Float, ypitch: Float) -> Rect
}

cell vias() {
let met2 = rect(Layer::Met2)!;
let met1 = rect(Layer::Met1)!;
let met2 = rect("met2")!;
let met1 = rect("met1")!;

// Create via.
let via = rect(Layer::Via1);
let via = rect("via1");
eq(via.w, 10.);
eq(via.h, 10.);
eq(via.x0, 0.);
Expand Down
1 change: 1 addition & 0 deletions core/compiler/src/argon.l
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ as "AS"
[_a-zA-Z][_a-zA-Z0-9]* "IDENT"
[0-9]+\.[0-9]* "FLOATLIT"
[0-9]+ "INTLIT"
"[^"]*" "STRLIT"
//[^\r\n]* ;
\+ "+"
\* "*"
Expand Down
7 changes: 7 additions & 0 deletions core/compiler/src/argon.y
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ IntLiteral -> Result<IntLiteral, ()>
Ok(IntLiteral { span: v.span(), value: parse_int($lexer.span_str(v.span()))?, }) }
;

StringLiteral -> Result<StringLiteral, ()>
: 'STRLIT' {
let v = $1.map_err(|_| ())?;
Ok(StringLiteral { span: v.span(), value: parse_str($lexer.span_str(v.span()))?, }) }
;

EnumDecl -> Result<EnumDecl<'input, ParseMetadata>, ()>
: 'ENUM' Ident '{' EnumVariants '}'
{
Expand Down Expand Up @@ -240,6 +246,7 @@ SubFactor -> Result<Expr<'input, ParseMetadata>, ()>
| Ident { Ok(Expr::Var(VarExpr { name: $1?, metadata: (), })) }
| IntLiteral { Ok(Expr::IntLiteral($1?)) }
| FloatLiteral { Ok(Expr::FloatLiteral($1?)) }
| StringLiteral { Ok(Expr::StringLiteral($1?)) }
| SubFactor 'AS' Ident { Ok(Expr::Cast(Box::new(CastExpr { value: $1?, ty: $3?, span: $span, metadata: (), }))) }
;

Expand Down
13 changes: 13 additions & 0 deletions core/compiler/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub struct IntLiteral {
pub value: i64,
}

#[derive(Debug, Clone)]
pub struct StringLiteral {
pub span: Span,
pub value: String,
}

#[derive_where(Debug, Clone)]
pub struct EnumDecl<'a, T: AstMetadata> {
pub name: Ident<'a, T>,
Expand Down Expand Up @@ -147,6 +153,7 @@ pub enum Expr<'a, T: AstMetadata> {
Var(VarExpr<'a, T>),
FloatLiteral(FloatLiteral),
IntLiteral(IntLiteral),
StringLiteral(StringLiteral),
Scope(Box<Scope<'a, T>>),
Cast(Box<CastExpr<'a, T>>),
}
Expand Down Expand Up @@ -261,6 +268,10 @@ pub(crate) fn parse_int(s: &str) -> Result<i64, ()> {
s.parse::<i64>().map_err(|_| ())
}

pub(crate) fn parse_str(s: &str) -> Result<String, ()> {
Ok(s.trim_matches('"').to_string())
}

pub(crate) fn flatten<T>(lhs: Result<Vec<T>, ()>, rhs: Result<T, ()>) -> Result<Vec<T>, ()> {
let mut flt = lhs?;
flt.push(rhs?);
Expand All @@ -281,6 +292,7 @@ impl<'a, T: AstMetadata> Expr<'a, T> {
Self::Var(x) => x.name.span,
Self::FloatLiteral(x) => x.span,
Self::IntLiteral(x) => x.span,
Self::StringLiteral(x) => x.span,
Self::Scope(x) => x.span,
Self::Cast(x) => x.span,
}
Expand Down Expand Up @@ -760,6 +772,7 @@ pub trait AstTransformer<'a> {
Expr::Var(var_expr) => Expr::Var(self.transform_var_expr(var_expr)),
Expr::FloatLiteral(float_literal) => Expr::FloatLiteral(*float_literal),
Expr::IntLiteral(int_literal) => Expr::IntLiteral(*int_literal),
Expr::StringLiteral(string_literal) => Expr::StringLiteral(string_literal.clone()),
Expr::Scope(scope) => Expr::Scope(Box::new(self.transform_scope(scope))),
Expr::Cast(cast) => Expr::Cast(Box::new(self.transform_cast(cast))),
}
Expand Down
Loading