Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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>
11 changes: 11 additions & 0 deletions core/compiler/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! Pass 1: assign variable IDs/type checking
//! Pass 3: solving
use std::collections::{HashMap, VecDeque};
use std::io::BufReader;
use std::path::Path;

use enumify::enumify;
use geometry::transform::{Rotation, TransformationMatrix};
Expand All @@ -11,6 +13,7 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};

use crate::ast::{BinOp, ConstantDecl, FieldAccessExpr, FnDecl, Scope, UnaryOp};
use crate::layer::LayerProperties;
use crate::{
ast::{
ArgDecl, Ast, AstMetadata, AstTransformer, BinOpExpr, CallExpr, CellDecl, ComparisonExpr,
Expand All @@ -26,6 +29,7 @@ pub fn compile(ast: &Ast<'_, ParseMetadata>, input: CompileInput<'_>) -> Compile
let input = CompileInput {
cell: input.cell,
params: input.params,
lyp_file: input.lyp_file,
};

ExecPass::new(&ast).execute(input)
Expand Down Expand Up @@ -629,6 +633,7 @@ impl<'a> AstTransformer<'a> for VarIdTyPass<'a> {
pub struct CompileInput<'a> {
pub cell: &'a str,
pub params: Vec<f64>,
pub lyp_file: &'a Path,
}

pub type VarId = u64;
Expand Down Expand Up @@ -739,9 +744,14 @@ impl<'a> ExecPass<'a> {
pub(crate) fn execute(mut self, input: CompileInput<'a>) -> CompileOutput {
self.declare_globals();
let cell_id = self.execute_cell(input.cell, input.params);
let layers =
klayout_lyp::from_reader(BufReader::new(std::fs::File::open(input.lyp_file).unwrap()))
.unwrap()
.into();
CompileOutput::Valid(ValidCompileOutput {
cells: self.compiled_cells,
top: cell_id,
layers,
})
}

Expand Down Expand Up @@ -1912,6 +1922,7 @@ pub struct StaticErrorCompileOutput {
pub struct ValidCompileOutput {
pub cells: HashMap<CellId, CompiledCell>,
pub top: CellId,
pub layers: LayerProperties,
}

#[enumify(generics_only)]
Expand Down
31 changes: 31 additions & 0 deletions core/compiler/src/layer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use klayout_lyp::KlayoutLayerProperties;
use rgb::Rgb;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayerProperties {
pub layers: Vec<Layer>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Layer {
pub name: String,
pub fill_color: Rgb<u8>,
pub border_color: Rgb<u8>,
}

impl From<KlayoutLayerProperties> for LayerProperties {
fn from(value: KlayoutLayerProperties) -> Self {
Self {
layers: value
.layers
.into_iter()
.map(|l| Layer {
name: l.name,
fill_color: l.fill_color,
border_color: l.frame_color,
})
.collect(),
}
}
}
Loading