Skip to content

Commit

Permalink
B0.1.7 (#177)
Browse files Browse the repository at this point in the history
* najaeda doc in progress

* update version

* improve anonymous instance printing

* Restructure examples

* Fix README

* update code
  • Loading branch information
xtofalex authored Jan 7, 2025
1 parent 9f620e8 commit 65152f1
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 24 deletions.
5 changes: 5 additions & 0 deletions najaeda_README/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ function to transmit user-defined arguments, allowing for flexible data processi
This specific use case shows how to count the number of leaf instances in a netlist.
.. snippet:: count_leaves

DLE (Dead Logic Elimination)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This example demonstrates how to perform Dead Logic Elimination (DLE) on a netlist.
.. snippet:: dle

Documentation
-------------
Naja EDA is a work in progress, and the documentation is still under development.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
from najaeda import snl
import faulthandler

if __name__ == '__main__':
faulthandler.enable()
# Load design
netlist.load_primitives('xilinx')
instances = set()
benchmarks = path.join('..', 'benchmarks')
top = netlist.load_verilog([path.join(benchmarks, 'verilog', 'arm_core_netlist.v')])


# snippet-start: dle
def apply_dle(top):
# Trace back from design outputs
visited = set()
output_terms = top.get_flat_output_terms()
Expand All @@ -41,6 +36,18 @@
to_delete = [leaf for leaf in leaf_children if leaf not in instances]
for leaf in to_delete:
leaf.delete()
return to_delete
# snippet-end: dle

if __name__ == '__main__':
faulthandler.enable()
# Load design
netlist.load_primitives('xilinx')
instances = set()
benchmarks = path.join('..', 'benchmarks')
top = netlist.load_verilog([path.join(benchmarks, 'verilog', 'arm_core_netlist.v')])

nb_deleted = apply_dle(top)

top.dump_verilog("./", "result.v")
print("deleted", len(to_delete))
print(f'deleted {len(nb_deleted)} leaves')
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#
# SPDX-License-Identifier: Apache-2.0

# snippet-start: load_design

from os import path
import sys

Expand All @@ -19,4 +17,4 @@
for instance in top.get_child_instances():
print(f"{instance}:{instance.get_model_name()}")

sys.exit(0)
sys.exit(0)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "najaeda"
version = "0.1.6"
version = "0.1.7"
description = "Naja EDA Python package"
authors = [{name = "Naja Authors", email = "[email protected]"}]
readme = "README.rst"
Expand Down
37 changes: 37 additions & 0 deletions src/najaeda/najaeda/docs/.readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: 2024 The Naja authors <https://github.com/najaeda/naja/blob/main/AUTHORS>
#
# SPDX-License-Identifier: Apache-2.0
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
apt_packages:
- cmake
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
26 changes: 26 additions & 0 deletions src/najaeda/najaeda/docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#...
#extensions = [
# "breathe",
# 'sphinx_rtd_theme',
#]
#...

project = 'najaeda'
copyright = '2023, The Naja authors'
author = 'The Naja authors'

html_theme = "sphinx_rtd_theme"
html_title = "najaeda Documentation"

breathe_default_project = "najaeda"

#import os
#if 'IN_READ_THE_DOCS' in os.environ:
# import subprocess
# #call doxygen from cmake
# subprocess.call('mkdir build', shell=True)
# subprocess.call('cd build; cmake ../.. -DBUILD_ONLY_DOC=ON', shell=True)
# subprocess.call('cd build; make docs', shell=True)
# subprocess.call('cd build/docs; pwd; ls -all', shell=True)
#
#breathe_projects = { "najaeda" : "./build/docs/xml/" }
24 changes: 15 additions & 9 deletions src/snl/snl/kernel/SNLInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ NajaCollection<SNLInstTerm*> SNLInstance::getInstTerms() const {
NajaCollection<SNLInstTerm*> SNLInstance::getConnectedInstTerms() const {
auto filter = [](const SNLInstTerm* it) {return it and it->getNet() != nullptr; };
return NajaCollection(new NajaSTLCollection(&instTerms_)).getSubCollection(filter);

}

NajaCollection<SNLInstTerm*> SNLInstance::getInstScalarTerms() const {
Expand Down Expand Up @@ -568,21 +567,28 @@ const char* SNLInstance::getTypeName() const {

//LCOV_EXCL_START
std::string SNLInstance::getString() const {
if (not isAnonymous()) {
if (isAnonymous()) {
return "<anon:" + std::to_string(getID()) + ">";
} else {
return getName().getString();
}
return std::string();
}
//LCOV_EXCL_STOP

//LCOV_EXCL_START
std::string SNLInstance::getDescription() const {
return "<" + std::string(getTypeName())
+ " " + name_.getString()
+ " " + std::to_string(getID())
+ " " + design_->getName().getString()
+ " " + model_->getName().getString()
+ ">";
std::ostringstream description;
description << "<" << getTypeName();
if (isAnonymous()) {
description << " [anon]";
} else {
description << " " + name_.getString();
}
description << " " + std::to_string(getID());
description << " " + design_->getName().getString();
description << " " + model_->getName().getString();
description << ">";
return description.str();
}
//LCOV_EXCL_STOP

Expand Down
15 changes: 13 additions & 2 deletions src/snl/snl/kernel/SNLSharedPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,22 @@ size_t SNLSharedPath::size() const {
std::string SNLSharedPath::getString(char separator) {
if (headSharedPath_) {
if (tailInstance_) {
return headSharedPath_->getString() + separator + tailInstance_->getName().getString();
std::ostringstream stream;
stream << headSharedPath_->getString(separator) << separator;
if (tailInstance_->isAnonymous()) {
stream << "<anon:" << tailInstance_->getID() << ">";
} else {
stream << tailInstance_->getName().getString();
}
return stream.str();
}
}
if (tailInstance_) {
return tailInstance_->getName().getString();
if (tailInstance_->isAnonymous()) {
return "<anon:" + std::to_string(tailInstance_->getID()) + ">";
} else {
return tailInstance_->getName().getString();
}
}
return "";
}
Expand Down

0 comments on commit 65152f1

Please sign in to comment.