2 Commits
Author SHA1 Message Date
stefan ea2ef1c3ec update rtd build image 2026-07-20 13:31:49 +09:00
stefan aabef17eea parse sky130 def files 2026-07-15 15:20:49 +09:00
2 changed files with 20 additions and 11 deletions

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
version: 2 version: 2
build: build:
os: "ubuntu-20.04" os: "ubuntu-24.04"
tools: tools:
python: "3.12" python: "3.12"
jobs: jobs:
+19 -10
View File
@@ -6,7 +6,7 @@ as an intermediate representation (:class:`DefFile` object).
from collections import defaultdict from collections import defaultdict
from lark import Lark, Transformer, Tree from lark import Lark, Transformer
from kyupy import readtext from kyupy import readtext
@@ -85,6 +85,8 @@ class DefFile:
self.pins = {} self.pins = {}
self.specialnets = {} self.specialnets = {}
self.nets = {} self.nets = {}
self.design = ""
self.diearea = 0
class DefTransformer(Transformer): class DefTransformer(Transformer):
@@ -140,9 +142,11 @@ class DefTransformer(Transformer):
def comp_stmt(self, args): def comp_stmt(self, args):
name = args[0].value name = args[0].value
kind = args[1].value kind = args[1].value
point = args[2] for aidx in range(2, len(args)):
orientation = args[3].value if args[aidx] in ('PLACED', 'FIXED'):
self.def_file.components[name] = (kind, point, orientation) point = args[aidx+1]
orientation = args[aidx+2].value
self.def_file.components[name] = (kind, point, orientation)
def pins_stmt(self, args): def pins_stmt(self, args):
pin = DefPin(args[0].value) pin = DefPin(args[0].value)
@@ -207,6 +211,7 @@ GRAMMAR = r"""
| /DIEAREA/ point+ ";" | /DIEAREA/ point+ ";"
| /ROW/ ID ID NUMBER NUMBER ID do_step ";" | /ROW/ ID ID NUMBER NUMBER ID do_step ";"
| /TRACKS/ /[XY]/ NUMBER "DO" NUMBER "STEP" NUMBER "LAYER" ID ";" | /TRACKS/ /[XY]/ NUMBER "DO" NUMBER "STEP" NUMBER "LAYER" ID ";"
| /GCELLGRID/ /[XY]/ NUMBER "DO" NUMBER "STEP" NUMBER ";"
| propdef | vias | nondef | comp | pins | pinprop | spnets | nets | propdef | vias | nondef | comp | pins | pinprop | spnets | nets
propdef: "PROPERTYDEFINITIONS" propdef_stmt* "END" "PROPERTYDEFINITIONS" propdef: "PROPERTYDEFINITIONS" propdef_stmt* "END" "PROPERTYDEFINITIONS"
@@ -228,7 +233,9 @@ GRAMMAR = r"""
| "+" /VIA/ ID )* ";" | "+" /VIA/ ID )* ";"
comp: "COMPONENTS" NUMBER ";" comp_stmt* "END" "COMPONENTS" comp: "COMPONENTS" NUMBER ";" comp_stmt* "END" "COMPONENTS"
comp_stmt: "-" ID ID "+" "PLACED" point ID ";" comp_stmt: "-" ID ID ( "+" /PLACED/ point ID
| "+" /FIXED/ point ID
| "+" /SOURCE/ ID )* ";"
pins: "PINS" NUMBER ";" pins_stmt* "END" "PINS" pins: "PINS" NUMBER ";" pins_stmt* "END" "PINS"
pins_stmt: "-" ID pins_opt* ";" pins_stmt: "-" ID pins_opt* ";"
@@ -239,6 +246,8 @@ GRAMMAR = r"""
| "+" /PORT/ | "+" /PORT/
| "+" /LAYER/ ID point point | "+" /LAYER/ ID point point
| "+" /PLACED/ point ID | "+" /PLACED/ point ID
| "+" /FIXED/ point ID
pinprop: "PINPROPERTIES" NUMBER ";" pinprop_stmt* "END" "PINPROPERTIES" pinprop: "PINPROPERTIES" NUMBER ";" pinprop_stmt* "END" "PINPROPERTIES"
pinprop_stmt: "-" "PIN" ID "+" "PROPERTY" ID STRING ";" pinprop_stmt: "-" "PIN" ID "+" "PROPERTY" ID STRING ";"
@@ -266,10 +275,10 @@ GRAMMAR = r"""
wire: ID wire_opt points wire: ID wire_opt points
wire_opt: ( "TAPER" | "TAPERRULE" ID )? ("STYLE" ID)? wire_opt: ( "TAPER" | "TAPERRULE" ID )? ("STYLE" ID)?
points: point ( point | points_via )+ points: point ( point | points_via_or_rect )+
points_via: ID ORIENTATION? points_via_or_rect: ID ( ORIENTATION? | "(" (NUMBER|SIGNED_NUMBER|/\*/) (NUMBER|SIGNED_NUMBER|/\*/) (NUMBER|SIGNED_NUMBER|/\*/) (NUMBER|SIGNED_NUMBER|/\*/) ")" )
point: "(" (NUMBER|/\*/) (NUMBER|/\*/) NUMBER? ")" point: "(" (NUMBER|SIGNED_NUMBER|/\*/) (NUMBER|SIGNED_NUMBER|/\*/) NUMBER? ")"
do_step: "DO" NUMBER "BY" NUMBER "STEP" (NUMBER|SIGNED_NUMBER) (NUMBER|SIGNED_NUMBER) do_step: "DO" NUMBER "BY" NUMBER "STEP" (NUMBER|SIGNED_NUMBER) (NUMBER|SIGNED_NUMBER)
@@ -284,9 +293,9 @@ GRAMMAR = r"""
""" """
def parse(text): def parse(text) -> DefFile:
"""Parses the given ``text`` and returns a :class:`DefFile` object.""" """Parses the given ``text`` and returns a :class:`DefFile` object."""
return Lark(GRAMMAR, parser="lalr", transformer=DefTransformer()).parse(text) return Lark(GRAMMAR, parser="lalr", transformer=DefTransformer()).parse(text) # type: ignore
def load(file): def load(file):