Browse Source

parse sky130 def files

devel
Nosaka Naoya 2 weeks ago
parent
commit
aabef17eea
  1. 29
      src/kyupy/def_file.py

29
src/kyupy/def_file.py

@ -6,7 +6,7 @@ as an intermediate representation (:class:`DefFile` object). @@ -6,7 +6,7 @@ as an intermediate representation (:class:`DefFile` object).
from collections import defaultdict
from lark import Lark, Transformer, Tree
from lark import Lark, Transformer
from kyupy import readtext
@ -85,6 +85,8 @@ class DefFile: @@ -85,6 +85,8 @@ class DefFile:
self.pins = {}
self.specialnets = {}
self.nets = {}
self.design = ""
self.diearea = 0
class DefTransformer(Transformer):
@ -140,9 +142,11 @@ class DefTransformer(Transformer): @@ -140,9 +142,11 @@ class DefTransformer(Transformer):
def comp_stmt(self, args):
name = args[0].value
kind = args[1].value
point = args[2]
orientation = args[3].value
self.def_file.components[name] = (kind, point, orientation)
for aidx in range(2, len(args)):
if args[aidx] in ('PLACED', 'FIXED'):
point = args[aidx+1]
orientation = args[aidx+2].value
self.def_file.components[name] = (kind, point, orientation)
def pins_stmt(self, args):
pin = DefPin(args[0].value)
@ -207,6 +211,7 @@ GRAMMAR = r""" @@ -207,6 +211,7 @@ GRAMMAR = r"""
| /DIEAREA/ point+ ";"
| /ROW/ ID ID NUMBER NUMBER ID do_step ";"
| /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: "PROPERTYDEFINITIONS" propdef_stmt* "END" "PROPERTYDEFINITIONS"
@ -228,7 +233,9 @@ GRAMMAR = r""" @@ -228,7 +233,9 @@ GRAMMAR = r"""
| "+" /VIA/ ID )* ";"
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_stmt: "-" ID pins_opt* ";"
@ -239,6 +246,8 @@ GRAMMAR = r""" @@ -239,6 +246,8 @@ GRAMMAR = r"""
| "+" /PORT/
| "+" /LAYER/ ID point point
| "+" /PLACED/ point ID
| "+" /FIXED/ point ID
pinprop: "PINPROPERTIES" NUMBER ";" pinprop_stmt* "END" "PINPROPERTIES"
pinprop_stmt: "-" "PIN" ID "+" "PROPERTY" ID STRING ";"
@ -266,10 +275,10 @@ GRAMMAR = r""" @@ -266,10 +275,10 @@ GRAMMAR = r"""
wire: ID wire_opt points
wire_opt: ( "TAPER" | "TAPERRULE" ID )? ("STYLE" ID)?
points: point ( point | points_via )+
points_via: ID ORIENTATION?
points: point ( point | points_via_or_rect )+
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)
@ -284,9 +293,9 @@ GRAMMAR = r""" @@ -284,9 +293,9 @@ GRAMMAR = r"""
"""
def parse(text):
def parse(text) -> DefFile:
"""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):

Loading…
Cancel
Save