Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/nanocoh/naja
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocoh committed Sep 27, 2024
2 parents 12a7406 + 878d9b8 commit 55c418c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
#
# SPDX-License-Identifier: Apache-2.0

cmake_policy(SET CMP0048 NEW)
cmake_minimum_required(VERSION 3.21)

project(naja
VERSION 1.0.0
HOMEPAGE_URL https://github.com/najaeda/naja
)

cmake_policy(SET CMP0048 NEW)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30")
cmake_policy(SET CMP0167 OLD)
endif()

include(GNUInstallDirs)

#RPATH settings
Expand Down
53 changes: 32 additions & 21 deletions src/apps/naja_edit/NajaEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,10 @@ int main(int argc, char* argv[]) {
const auto najaEditStart{std::chrono::steady_clock::now()};
argparse::ArgumentParser program("naja_edit");
program.add_description(
"Edit gate level netlists using python script and apply optimizations");
program.add_argument("-f", "--from_format")
.required()
.help("from/input format");
"Edit gate level netlists using python script and apply optimizations");
program.add_argument("-f", "--from_format").help("from/input format");
program.add_argument("-t", "--to_format").help("to/output format");
program.add_argument("-i", "--input")
.required()
.append()
.help("input netlist paths");
program.add_argument("-i", "--input").append().help("input netlist paths");
program.add_argument("-o", "--output").help("output netlist");
program.add_argument("-p", "--primitives")
.nargs(argparse::nargs_pattern::at_least_one)
Expand Down Expand Up @@ -186,24 +181,41 @@ int main(int argc, char* argv[]) {
SPDLOG_INFO("########################################################");

bool argError = false;
auto inputFormatArg = program.present("-f");
std::string inputFormat = *inputFormatArg;

std::string inputFormat;
if (auto inputFormatArg = program.present("-f")) {
inputFormat = *inputFormatArg;
}
FormatType inputFormatType = argToFormatType(inputFormat);
if (inputFormatType == FormatType::UNKNOWN) {
SPDLOG_CRITICAL("Unrecognized input format type: {}", inputFormat);
argError = true;
}

if (program.present("-i")) {
if (inputFormatType == FormatType::NOT_PROVIDED) {
SPDLOG_CRITICAL("output option (-f) is mandatory when the input is provided");
std::exit(EXIT_FAILURE);
}
}

std::string outputFormat;
if (auto outputFormatArg = program.present("-t")) {
outputFormat = *outputFormatArg;
} else {
if (auto output = program.is_used("-o")) {
// in case output format is not provided and output path is provided
// output format is same as input format
outputFormat = inputFormat;
if (inputFormatType == FormatType::NOT_PROVIDED) {
SPDLOG_CRITICAL("output format option (-t) is mandatory");
argError = true;
} else {
outputFormat = inputFormat;
}
}
}
FormatType inputFormatType = argToFormatType(inputFormat);
FormatType outputFormatType = argToFormatType(outputFormat);
if (inputFormatType == FormatType::UNKNOWN) {
SPDLOG_CRITICAL("Unrecognized input format type: {}", inputFormat);
argError = true;
}

if (outputFormatType == FormatType::UNKNOWN) {
SPDLOG_CRITICAL("Unrecognized output format type: {}", outputFormat);
argError = true;
Expand All @@ -225,7 +237,7 @@ int main(int argc, char* argv[]) {
}
);
} else {
if (inputFormatType != FormatType::SNL) {
if (inputFormatType != FormatType::SNL and inputFormatType != FormatType::NOT_PROVIDED) {
SPDLOG_CRITICAL("primitives option (-p) is mandatory when the input format is not 'SNL'");
argError = true;
}
Expand Down Expand Up @@ -257,10 +269,6 @@ int main(int argc, char* argv[]) {
});

std::filesystem::path outputPath;
if (inputPaths.empty()) {
SPDLOG_CRITICAL("No input path was provided");
std::exit(EXIT_FAILURE);
}
if (auto output = program.present("-o")) {
outputPath = std::filesystem::path(*output);
} else {
Expand Down Expand Up @@ -354,6 +362,9 @@ int main(int argc, char* argv[]) {
oss << "Parsing done in: " << elapsed_seconds.count() << "s";
SPDLOG_INFO(oss.str());
}
} else if (inputFormatType == FormatType::NOT_PROVIDED) {
db = SNLDB::create(SNLUniverse::get());
SNLUniverse::get()->setTopDB(db);
} else {
SPDLOG_CRITICAL("Unrecognized input format type: {}", inputFormat);
std::exit(EXIT_FAILURE);
Expand Down
18 changes: 17 additions & 1 deletion src/snl/python/snl_wrapping/PySNLUniverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ static PyObject* PySNLUniverse_get() {
return PySNLUniverse_Link(universe);
}

static PyObject* PySNLUniverse_setTopDesign(PySNLUniverse* self, PyObject* arg) {
METHOD_HEAD("SNLUniverse.setTopDesign()")
if (IsPySNLDesign(arg)) {
selfObject->setTopDesign(PYSNLDesign_O(arg));
} else {
setError("SNLUniverse setTopDesign takes SNLDesign argument");
return nullptr;
}
Py_RETURN_NONE;
}

GetObjectMethod(Universe, Design, getTopDesign)
GetObjectMethod(Universe, DB, getTopDB)
GetObjectByIndex(Universe, DB, DB)

DBoDestroyAttribute(PySNLUniverse_destroy, PySNLUniverse)
Expand All @@ -43,6 +55,10 @@ PyMethodDef PySNLUniverse_Methods[] = {
"get the SNL Universe (static object)"},
{ "getTopDesign", (PyCFunction)PySNLUniverse_getTopDesign, METH_NOARGS,
"get the top SNLDesign"},
{ "setTopDesign", (PyCFunction)PySNLUniverse_setTopDesign, METH_O,
"set the top SNLDesign"},
{ "getTopDB", (PyCFunction)PySNLUniverse_getTopDB, METH_NOARGS,
"get the Top SNLDB"},
{ "getDB", (PyCFunction)PySNLUniverse_getDB, METH_VARARGS,
"get the SNLDB with the given index"},
{NULL, NULL, 0, NULL} /* sentinel */
Expand All @@ -54,4 +70,4 @@ DBoLinkCreateMethod(SNLUniverse)
PyTypeSNLObjectWithoutSNLIDLinkPyType(SNLUniverse)
PyTypeObjectDefinitions(SNLUniverse)

}
}
11 changes: 11 additions & 0 deletions test/snl/python/snl_wrapping/test_snldesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def test0(self):
self.assertEqual(i2, terms[2])
self.assertEqual(i3, terms[3])
self.assertEqual(o, terms[4])

self.assertIsNotNone(snl.SNLUniverse.get())
self.assertIsNone(snl.SNLUniverse.get().getTopDB())
self.assertIsNone(snl.SNLUniverse.get().getTopDesign())
snl.SNLUniverse.get().setTopDesign(design)
self.assertEqual(design, snl.SNLUniverse.get().getTopDesign())
self.assertEqual(design.getDB(), snl.SNLUniverse.get().getTopDB())
with self.assertRaises(RuntimeError) as context: snl.SNLUniverse.get().setTopDesign(self.lib)

def test1(self):
self.assertIsNotNone(self.lib)
Expand Down Expand Up @@ -218,6 +226,9 @@ def testParameterClashErrors(self):
with self.assertRaises(RuntimeError) as context: snl.SNLParameter.create_string(design, "MODE", "DEFAULT")
with self.assertRaises(RuntimeError) as context: snl.SNLParameter.create_boolean(design, "INVERTED", True)

def testSetTopErrors(self):
with self.assertRaises(RuntimeError) as context: snl.SNLUniverse.get().setTopDesign(self.lib)

def testDumpVerilogError(self):
self.assertIsNotNone(self.lib)
design = snl.SNLDesign.create(self.lib, "DESIGN")
Expand Down

0 comments on commit 55c418c

Please sign in to comment.