Skip to content

Commit

Permalink
feat!: dynamic designformat registration (#612)
Browse files Browse the repository at this point in the history
## Misc Enhancements/Bugfixes

* `openlane.state`
  * `DesignFormat`
* Now a dataclass encapsulating the information about the DesignFormat
directly.
 	 * `.factory` is a factory for retrieval of DesignFormats by ID
* `DesignFormats` may be registered to the factory using `.register()`
* Registrations for previously included `DesignFormat`s now moved to
where appropriate.
* Renamed `POWERED_NETLIST_NO_PHYSICAL_CELLS` to
`LOGICAL_POWERED_NETLIST`
* Renamed `POWERED_NETLIST_SDF_FRIENDLY` to
`SDF_FRIENDLY_POWERED_NETLIST`
  * `State`
* States initialized with keys that have values that are `None` now
remove said keys.

## API Breaks

* `openlane.steps`
  * `TclStep` now uses the IDs uppercased for `CURRENT_` and `SAVE_`.

* `openlane.state`
* `State` no longer includes all `DesignFormat`s as guaranteed keys and
`.get` must be used to avoide `KeyErrors`
* `DesignFormat` is no longer an enumeration and is not iterable.
However, to avoid massive codebase changes, you can still access
`DesignFormat`s registered to the factory using the dot notation (e.g.
`DesignFormat.NETLIST`), using either their `id` or any of their `alts`.
* Removed `DesignFormatObject`: the DesignFormat class itself is now a
dataclass incorporating these fields, except `name`, which has been
renamed to `full_name`. The enumeration's name has been added to `alts`,
while `.name` is now an alias for `.id`.
  • Loading branch information
donn authored Dec 15, 2024
1 parent df6079d commit 7959772
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 220 deletions.
39 changes: 39 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,45 @@
## Documentation
-->

# Dev

## Misc Enhancements/Bugfixes

* `openlane.state`
* `DesignFormat`
* Now a dataclass encapsulating the information about the DesignFormat
directly.
* `.factory` is a factory for retrieval of DesignFormats by ID
* `DesignFormats` may be registered to the factory using `.register()`
* Registrations for previously included `DesignFormat`s now moved to
appropriate files.
* Renamed `POWERED_NETLIST_NO_PHYSICAL_CELLS` to
`LOGICAL_POWERED_NETLIST`
* Renamed `POWERED_NETLIST_SDF_FRIENDLY` to
`SDF_FRIENDLY_POWERED_NETLIST`
* `State`
* States initialized with keys that have values that are `None` now remove
said keys.

## API Breaks

* `openlane.steps`

* `TclStep` now uses the IDs uppercased for `CURRENT_` and `SAVE_`.

* `openlane.state`

* `State` no longer includes all `DesignFormat`s as guaranteed keys and `.get`
must be used to avoide `KeyErrors`
* `DesignFormat` is no longer an enumeration and is not iterable. However, to
avoid massive codebase changes, you can still access `DesignFormat`s
registered to the factory using the dot notation (e.g.
`DesignFormat.NETLIST`), using either their `id` or any of their `alts`.
* Removed `DesignFormatObject`: the DesignFormat class itself is now a
dataclass incorporating these fields, except `name`, which has been renamed
to `full_name`. The enumeration's name has been added to `alts`, while
`.name` is now an alias for `.id`.

# 2.2.9

## Steps
Expand Down
2 changes: 1 addition & 1 deletion openlane/config/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def view_by_df(
self, df: DesignFormat
) -> Union[None, Path, List[Path], Dict[str, List[Path]]]:
try:
return getattr(self, df.value.id)
return getattr(self, df.id)
except AttributeError:
return None

Expand Down
9 changes: 3 additions & 6 deletions openlane/flows/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from openlane.common.types import Path

from ..config import Config, Variable, universal_flow_config_variables, AnyConfigs
from ..state import State, DesignFormat, DesignFormatObject
from ..state import State, DesignFormat
from ..steps import Step, StepNotFound
from ..logging import (
LevelFilter,
Expand Down Expand Up @@ -804,14 +804,11 @@ def _save_snapshot_ef(self, path: Union[str, os.PathLike]):
}

def visitor(key, value, top_key, _, __):
df = DesignFormat.by_id(top_key)
df = DesignFormat.factory.get(top_key)
assert df is not None
if df not in supported_formats:
return

dfo = df.value
assert isinstance(dfo, DesignFormatObject)

subdirectory, extension = supported_formats[df]

target_dir = os.path.join(path, subdirectory)
Expand All @@ -837,7 +834,7 @@ def visitor(key, value, top_key, _, __):
return

target_basename = os.path.basename(str(value))
target_basename = target_basename[: -len(dfo.extension)] + extension
target_basename = target_basename[: -len(df.extension)] + extension
target_path = os.path.join(target_dir, target_basename)
mkdirp(target_dir)
shutil.copyfile(value, target_path, follow_symlinks=True)
Expand Down
32 changes: 16 additions & 16 deletions openlane/scripts/openroad/common/io.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ proc read_current_netlist {args} {
flags {-powered}

if { [info exists flags(-powered)] } {
puts "Reading top-level powered netlist at '$::env(CURRENT_POWERED_NETLIST)'…"
if {[catch {read_verilog $::env(CURRENT_POWERED_NETLIST)} errmsg]} {
puts "Reading top-level powered netlist at '$::env(CURRENT_PNL)'…"
if {[catch {read_verilog $::env(CURRENT_PNL)} errmsg]} {
puts stderr $errmsg
exit 1
}
} else {
puts "Reading top-level netlist at '$::env(CURRENT_NETLIST)'…"
if {[catch {read_verilog $::env(CURRENT_NETLIST)} errmsg]} {
puts "Reading top-level netlist at '$::env(CURRENT_NL)'…"
if {[catch {read_verilog $::env(CURRENT_NL)} errmsg]} {
puts stderr $errmsg
exit 1
}
Expand Down Expand Up @@ -338,32 +338,32 @@ proc write_views {args} {
write_db $::env(SAVE_ODB)
}

if { [info exists ::env(SAVE_NETLIST)] } {
puts "Writing netlist to '$::env(SAVE_NETLIST)'…"
write_verilog $::env(SAVE_NETLIST)
if { [info exists ::env(SAVE_NL)] } {
puts "Writing netlist to '$::env(SAVE_NL)'…"
write_verilog $::env(SAVE_NL)
}

if { [info exists ::env(SAVE_POWERED_NETLIST)] } {
puts "Writing powered netlist to '$::env(SAVE_POWERED_NETLIST)'…"
write_verilog -include_pwr_gnd $::env(SAVE_POWERED_NETLIST)
if { [info exists ::env(SAVE_PNL)] } {
puts "Writing powered netlist to '$::env(SAVE_PNL)'…"
write_verilog -include_pwr_gnd $::env(SAVE_PNL)
}

if { [info exists ::env(SAVE_POWERED_NETLIST_SDF_FRIENDLY)] } {
if { [info exists ::env(SAVE_SDF_PNL)] } {
set exclude_cells "[join $::env(FILL_CELL)] [join $::env(DECAP_CELL)] [join $::env(WELLTAP_CELL)] [join $::env(ENDCAP_CELL)]"
puts "Writing nofill powered netlist to '$::env(SAVE_POWERED_NETLIST_SDF_FRIENDLY)'…"
puts "Writing nofill powered netlist to '$::env(SAVE_SDF_PNL)'…"
puts "Excluding $exclude_cells"
write_verilog -include_pwr_gnd \
-remove_cells "$exclude_cells"\
$::env(SAVE_POWERED_NETLIST_SDF_FRIENDLY)
$::env(SAVE_SDF_PNL)
}

if { [info exists ::env(SAVE_POWERED_NETLIST_NO_PHYSICAL_CELLS)] } {
if { [info exists ::env(SAVE_LOGICAL_PNL)] } {
set exclude_cells "[join [lindex [split $::env(DIODE_CELL) "/"] 0]] [join $::env(FILL_CELL)] [join $::env(DECAP_CELL)] [join $::env(WELLTAP_CELL)] [join $::env(ENDCAP_CELL)]"
puts "Writing nofilldiode powered netlist to '$::env(SAVE_POWERED_NETLIST_NO_PHYSICAL_CELLS)'…"
puts "Writing nofilldiode powered netlist to '$::env(SAVE_LOGICAL_PNL)'…"
puts "Excluding $exclude_cells"
write_verilog -include_pwr_gnd \
-remove_cells "$exclude_cells"\
$::env(SAVE_POWERED_NETLIST_NO_PHYSICAL_CELLS)
$::env(SAVE_LOGICAL_PNL)
}

if { [info exists ::env(SAVE_OPENROAD_LEF)] } {
Expand Down
2 changes: 1 addition & 1 deletion openlane/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
OpenLane step. The State is essentially a list of views in various formats in
addition to the cumulative set of metrics created by previous Steps.
"""
from .design_format import DesignFormat, DesignFormatObject
from .design_format import DesignFormat
from .state import State, InvalidState, StateElement
Loading

0 comments on commit 7959772

Please sign in to comment.