Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into README-restructured
Browse files Browse the repository at this point in the history
  • Loading branch information
xtofalex committed Oct 13, 2024
2 parents 93d0d15 + ca3a29b commit 86b2a80
Show file tree
Hide file tree
Showing 23 changed files with 486 additions and 42 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ jobs:
PYTHONMALLOC: malloc
run: valgrind --error-exitcode=1 --show-leak-kinds=definite --leak-check=full --errors-for-leak-kinds=definite ./snlVRLConstructorTests

- name: TestLiberty
working-directory: ${{github.workspace}}/build/test/snl/formats/liberty
run: valgrind --error-exitcode=1 --show-leak-kinds=all --leak-check=full --errors-for-leak-kinds=all ./snl_liberty_tests

- name: TestSNLVRLDumper
working-directory: ${{github.workspace}}/build/test/snl/formats/verilog/backend
run: valgrind --error-exitcode=1 --show-leak-kinds=all --leak-check=full --errors-for-leak-kinds=all ./snlVRLDumperTests
Expand All @@ -95,6 +99,22 @@ jobs:

- name: TestDLE
working-directory: ${{github.workspace}}/build/test/logic_opt
run: valgrind --error-exitcode=1 ./LoadlessLogicRemoverTests
#run: valgrind --error-exitcode=1 --show-leak-kinds=all --leak-check=full --errors-for-leak-kinds=all ./LoadlessLogicRemoverTests
run: valgrind --error-exitcode=1 ./loadlessLogicRemoverTests
#run: valgrind --error-exitcode=1 --show-leak-kinds=all --leak-check=full --errors-for-leak-kinds=all ./loadlessLogicRemoverTests

- name: TestConstantPropagation
working-directory: ${{github.workspace}}/build/test/logic_opt
run: valgrind --error-exitcode=1 --show-leak-kinds=all --leak-check=full --errors-for-leak-kinds=all ./constantPropagationTests

#- name: TestReductionOpt
# working-directory: ${{github.workspace}}/build/test/logic_opt
# env:
# PYTHONPATH: ${{env.PYTHONPATH}}:${{github.workspace}}/build/src/snl/python/snl_wrapping
# PYTHONMALLOC: malloc
# run: valgrind --error-exitcode=1 --show-leak-kinds=all --leak-check=full --errors-for-leak-kinds=all ./reductionOptTests
# #run: valgrind --error-exitcode=1 ./reductionOptTests

- name: TestBNE
working-directory: ${{github.workspace}}/build/test/bne
run: valgrind --error-exitcode=1 ./bneTests
#run: valgrind --error-exitcode=1 --show-leak-kinds=all --leak-check=full --errors-for-leak-kinds=all ./bneTests
7 changes: 4 additions & 3 deletions src/apps/naja_edit/NajaEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,9 @@ int main(int argc, char* argv[]) {
}
}
} catch (const SNLException& e) {
SPDLOG_CRITICAL("Caught SNL error: {}\n{}",
e.what(), e.trace().to_string());
//SPDLOG_CRITICAL("Caught SNL error: {}\n{}",
// e.what(), e.trace().to_string());
SPDLOG_CRITICAL("Caught SNL error: {}\n", e.what());
std::exit(EXIT_FAILURE);
}
const auto najaEditEnd{std::chrono::steady_clock::now()};
Expand All @@ -523,4 +524,4 @@ int main(int argc, char* argv[]) {
}
SPDLOG_INFO("########################################################");
std::exit(EXIT_SUCCESS);
}
}
3 changes: 2 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ set(NAJA_CORE_HEADERS
list(APPEND NAJA_CORE_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/NajaVersion.h)

add_library(naja_core SHARED ${SOURCES})
target_link_libraries(naja_core PUBLIC cpptrace::cpptrace coverage_config sanitizers_config)
#target_link_libraries(naja_core PUBLIC cpptrace::cpptrace coverage_config sanitizers_config)
target_link_libraries(naja_core PUBLIC coverage_config sanitizers_config)

target_compile_options(naja_core PRIVATE ${NAJA_CXX_WARNINGS})

Expand Down
7 changes: 4 additions & 3 deletions src/core/NajaException.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
#ifndef __NAJA_EXCEPTION_H_
#define __NAJA_EXCEPTION_H_

#include <cpptrace/cpptrace.hpp>
//#include <cpptrace/cpptrace.hpp>

namespace naja {

struct NajaException: public cpptrace::lazy_exception {
struct NajaException: public std::exception { // cpptrace::lazy_exception {
public:
NajaException() = delete;
NajaException(const NajaException&) = default;

NajaException(const std::string& reason):
cpptrace::lazy_exception(),
//cpptrace::lazy_exception(),
std::exception(),
reason_(reason)
{}

Expand Down
2 changes: 1 addition & 1 deletion src/snl/python/snl_wrapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(SOURCES
PySNLNetComponents.cpp
PySNLTerms.cpp PySNLBitTerms.cpp PySNLScalarTerms.cpp PySNLBusTerms.cpp
PySNLNets.cpp PySNLBitNets.cpp PySNLScalarNets.cpp PySNLBusNets.cpp
PySNLInstances.cpp PySNLInstTerms.cpp
PySNLInstances.cpp PySNLInstTerms.cpp PySNLPath.cpp PySNLOccurrence.cpp
)

Python3_add_library(naja_snl_python SHARED ${SOURCES})
Expand Down
82 changes: 64 additions & 18 deletions src/snl/python/snl_wrapping/PyInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ PyObject* richCompare(T left, T right, int op) {
auto otherObject = otherPyObject->ACCESS_OBJECT; \
return richCompare(selfObject, otherObject, op); \
}

#define DirectCmpByObjectMethod(PY_FUNC_NAME, PY_SELF_TYPE) \
static PyObject* PY_FUNC_NAME(PY_SELF_TYPE* self, PyObject* other, int op) { \
if (not (PyObject_TypeCheck(self, Py_TYPE(other)) or PyObject_TypeCheck(other, Py_TYPE(self)))) Py_RETURN_FALSE; \
PY_SELF_TYPE* otherPyObject = (PY_SELF_TYPE*)other; \
auto selfObject = self->ACCESS_OBJECT; \
auto otherObject = otherPyObject->ACCESS_OBJECT; \
return richCompare(*selfObject, *otherObject, op); \
}

#define DirectHashMethod(PY_FUNC_NAME,PY_SELF_TYPE) \
static int PY_FUNC_NAME(PY_SELF_TYPE *self) { \
Expand Down Expand Up @@ -129,9 +138,17 @@ PyObject* richCompare(T left, T right, int op) {
PyObject_DEL(self); \
}

#define DBoDeallocMethod(SELF_TYPE) \
static void Py##SELF_TYPE##_DeAlloc(Py##SELF_TYPE *self) { \
PyObject_DEL(self); \
#define DBoDeallocMethod(SELF_TYPE) \
static void Py##SELF_TYPE##_DeAlloc(Py##SELF_TYPE *self) { \
PyObject_DEL(self); \
}

#define ManagedTypeDeallocMethod(SELF_TYPE) \
static void Py##SELF_TYPE##_DeAlloc(Py##SELF_TYPE *self) { \
if (self->ACCESS_OBJECT) { \
delete self->ACCESS_OBJECT; \
} \
PyObject_DEL(self); \
}

#define PyTypeSNLAbstractObjectWithSNLIDLinkPyType(SELF_TYPE) \
Expand Down Expand Up @@ -175,14 +192,37 @@ PyObject* richCompare(T left, T right, int op) {
PyType##SELF_TYPE.tp_methods = Py##SELF_TYPE##_Methods; \
}

#define DBoLinkCreateMethod(SELF_TYPE) \
PyObject* Py##SELF_TYPE##_Link(SELF_TYPE* object) { \
if (not object) { \
Py_RETURN_NONE; \
} \
#define PyTypeManagedSNLObjectWithoutSNLIDLinkPyType(SELF_TYPE) \
DirectReprMethod(Py##SELF_TYPE##_Repr, Py##SELF_TYPE, SELF_TYPE) \
DirectStrMethod (Py##SELF_TYPE##_Str, Py##SELF_TYPE, SELF_TYPE) \
DirectCmpByObjectMethod (Py##SELF_TYPE##_Cmp, Py##SELF_TYPE) \
DirectHashMethod(Py##SELF_TYPE##_Hash, Py##SELF_TYPE) \
extern void Py##SELF_TYPE##_LinkPyType() { \
PyType##SELF_TYPE.tp_dealloc = (destructor) Py##SELF_TYPE##_DeAlloc; \
PyType##SELF_TYPE.tp_richcompare = (richcmpfunc) Py##SELF_TYPE##_Cmp; \
PyType##SELF_TYPE.tp_repr = (reprfunc)Py##SELF_TYPE##_Repr; \
PyType##SELF_TYPE.tp_str = (reprfunc)Py##SELF_TYPE##_Str; \
PyType##SELF_TYPE.tp_hash = (hashfunc)Py##SELF_TYPE##_Hash; \
PyType##SELF_TYPE.tp_init = (initproc)Py##SELF_TYPE##_Init; \
PyType##SELF_TYPE.tp_methods = Py##SELF_TYPE##_Methods; \
}

#define ManagedTypeLinkCreateMethod(SELF_TYPE) \
PyObject* Py##SELF_TYPE##_Link(const SELF_TYPE& object) { \
SELF_TYPE* newObject = new SELF_TYPE(object); \
Py##SELF_TYPE* pyObject = PyObject_NEW(Py##SELF_TYPE, &PyType##SELF_TYPE); \
pyObject->ACCESS_OBJECT = newObject; \
return (PyObject*)pyObject; \
}

#define DBoLinkCreateMethod(SELF_TYPE) \
PyObject* Py##SELF_TYPE##_Link(SELF_TYPE* object) { \
if (not object) { \
Py_RETURN_NONE; \
} \
Py##SELF_TYPE* pyObject = PyObject_NEW(Py##SELF_TYPE, &PyType##SELF_TYPE); \
pyObject->ACCESS_OBJECT = object; \
return (PyObject*)pyObject; \
pyObject->ACCESS_OBJECT = object; \
return (PyObject*)pyObject; \
}

#define GetObjectMethod(SELF_TYPE, OBJECT_TYPE, METHOD) \
Expand Down Expand Up @@ -210,7 +250,7 @@ PyObject* richCompare(T left, T right, int op) {
#define GetObjectByIndex(SELF_TYPE, OBJECT_TYPE, METHOD) \
static PyObject* PySNL##SELF_TYPE##_get##METHOD(PySNL##SELF_TYPE* self, PyObject* args) { \
SNL##OBJECT_TYPE* obj = nullptr; \
METHOD_HEAD("SNL##SELF_TYPE.get##OBJECT_TYPE()") \
METHOD_HEAD("SNL"#SELF_TYPE".get"#OBJECT_TYPE"()") \
int index = 0; \
if (PyArg_ParseTuple(args, "i:SNL##SELF_TYPE.get##METHOD", &index)) { \
SNLTRY \
Expand All @@ -225,7 +265,7 @@ PyObject* richCompare(T left, T right, int op) {

#define GetNameMethod(SELF_TYPE) \
static PyObject* Py##SELF_TYPE##_getName(Py##SELF_TYPE* self) { \
METHOD_HEAD(#SELF_TYPE ".getName()") \
METHOD_HEAD(#SELF_TYPE".getName()") \
SNLTRY \
return PyUnicode_FromString(selfObject->getName().getString().c_str()); \
SNLCATCH \
Expand All @@ -234,9 +274,9 @@ PyObject* richCompare(T left, T right, int op) {

#define SetNameMethod(SELF_TYPE) \
static PyObject* PySNL##SELF_TYPE##_setName(PySNL##SELF_TYPE* self, PyObject* arg) { \
METHOD_HEAD("SNL" #SELF_TYPE ".setName()") \
METHOD_HEAD("SNL"#SELF_TYPE".setName()") \
if (not PyUnicode_Check(arg)) { \
setError("SNL" #SELF_TYPE ".setName() expects a string as argument"); \
setError("SNL"#SELF_TYPE".setName() expects a string as argument"); \
return nullptr; \
} \
selfObject->setName(SNLName(PyUnicode_AsUTF8(arg))); \
Expand All @@ -245,7 +285,7 @@ PyObject* richCompare(T left, T right, int op) {

#define GetStringAttribute(SELF_TYPE, METHOD) \
static PyObject* PySNL##SELF_TYPE##_##METHOD(PySNL##SELF_TYPE* self) { \
METHOD_HEAD("SNL##SELF_TYPE.##METHOD##()") \
METHOD_HEAD("SNL"#SELF_TYPE"."#METHOD"()") \
SNLTRY \
return PyUnicode_FromString(selfObject->METHOD().c_str()); \
SNLCATCH \
Expand All @@ -254,14 +294,20 @@ PyObject* richCompare(T left, T right, int op) {

#define GetBoolAttribute(SELF_TYPE, METHOD) \
static PyObject* PySNL##SELF_TYPE##_##METHOD(PySNL##SELF_TYPE* self) { \
METHOD_HEAD("SNL##SELF_TYPE.##METHOD##()") \
METHOD_HEAD("SNL"#SELF_TYPE"."#METHOD"()") \
if (selfObject->METHOD()) Py_RETURN_TRUE; \
Py_RETURN_FALSE; \
}

#define GetSizetAttribute(SELF_TYPE, METHOD) \
static PyObject* PySNL##SELF_TYPE##_##METHOD(PySNL##SELF_TYPE* self) { \
METHOD_HEAD("SNL"#SELF_TYPE"."#METHOD"()") \
return Py_BuildValue("n", selfObject->METHOD()); \
}

#define GetBoolAttributeWithFunction(SELF_TYPE, METHOD, FUNCTION) \
static PyObject* PySNL##SELF_TYPE##_##METHOD(PySNL##SELF_TYPE* self) { \
METHOD_HEAD("SNL##SELF_TYPE.##METHOD##()") \
METHOD_HEAD("SNL"#SELF_TYPE"."#METHOD"()") \
if (FUNCTION(selfObject)) Py_RETURN_TRUE; \
Py_RETURN_FALSE; \
}
Expand Down Expand Up @@ -421,4 +467,4 @@ PyObject* richCompare(T left, T right, int op) {
setError("malformed " #OWNER_TYPE "." #GETTER " method"); \
return nullptr;

#endif /* __PY_INTERFACE_H */
#endif /* __PY_INTERFACE_H */
10 changes: 10 additions & 0 deletions src/snl/python/snl_wrapping/PySNL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "PySNLNetComponents.h"
#include "PySNLInstances.h"
#include "PySNLInstTerms.h"
#include "PySNLPath.h"
#include "PySNLOccurrence.h"

namespace PYSNL {

Expand Down Expand Up @@ -71,6 +73,8 @@ PyMODINIT_FUNC PyInit_snl(void) {
PySNLInstance_LinkPyType();
PySNLInstParameter_LinkPyType();
PySNLInstTerm_LinkPyType();
PySNLPath_LinkPyType();
PySNLOccurrence_LinkPyType();

PySNLLibraries_LinkPyType();
PySNLDesigns_LinkPyType();
Expand Down Expand Up @@ -111,6 +115,8 @@ PyMODINIT_FUNC PyInit_snl(void) {
PYTYPE_READY_SUB(SNLInstance, SNLDesignObject);
PYTYPE_READY_SUB(SNLInstTerm, SNLNetComponent);

PYTYPE_READY(SNLPath);
PYTYPE_READY(SNLOccurrence)
PYTYPE_READY(SNLLibraries);
PYTYPE_READY(SNLLibrariesIterator);
PYTYPE_READY(SNLDesigns);
Expand Down Expand Up @@ -162,6 +168,8 @@ PyMODINIT_FUNC PyInit_snl(void) {
Py_INCREF(&PyTypeSNLScalarTerm);
Py_INCREF(&PyTypeSNLBusTermBit);
Py_INCREF(&PyTypeSNLInstance);
Py_INCREF(&PyTypeSNLPath);
Py_INCREF(&PyTypeSNLOccurrence);
Py_INCREF(&PyTypeSNLInstTerm);
Py_INCREF(&PyTypeSNLLibraries);
Py_INCREF(&PyTypeSNLDesigns);
Expand Down Expand Up @@ -209,6 +217,8 @@ PyMODINIT_FUNC PyInit_snl(void) {
PyModule_AddObject(mod, "SNLInstance", (PyObject*)&PyTypeSNLInstance);
PyModule_AddObject(mod, "SNLInstParameter", (PyObject*)&PyTypeSNLInstParameter);
PyModule_AddObject(mod, "SNLInstTerm", (PyObject*)&PyTypeSNLInstTerm);
PyModule_AddObject(mod, "SNLPath", (PyObject*)&PyTypeSNLPath);
PyModule_AddObject(mod, "SNLOccurrence", (PyObject*)&PyTypeSNLOccurrence);

PySNLTerm_postModuleInit();
PySNLNet_postModuleInit();
Expand Down
2 changes: 1 addition & 1 deletion src/snl/python/snl_wrapping/PySNLDesign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ PyMethodDef PySNLDesign_Methods[] = {
{ "setTruthTable", (PyCFunction)PySNLDesign_setTruthTable, METH_VARARGS,
"set truth table of a primitive"},
{ "isConst0", (PyCFunction)PySNLDesign_isConst0, METH_NOARGS,
"Returns True if this desgin is a primitive driving a constant 0"},
"Returns True if this design is a primitive driving a constant 0"},
{ "isConst1", (PyCFunction)PySNLDesign_isConst1, METH_NOARGS,
"Returns True if this design is a primitive driving a constant 1"},
{ "isBuf", (PyCFunction)PySNLDesign_isBuf, METH_NOARGS,
Expand Down
62 changes: 62 additions & 0 deletions src/snl/python/snl_wrapping/PySNLOccurrence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-FileCopyrightText: 2023 The Naja authors
// <https://github.com/najaeda/naja/blob/main/AUTHORS>
//
// SPDX-License-Identifier: Apache-2.0

#include "PySNLOccurrence.h"
#include "PyInterface.h"
#include "SNLDesignObject.h"
#include "PySNLDesignObject.h"
#include "PySNLPath.h"
#include "SNLDesignObject.h"
#include "SNLPath.h"
#include "SNLOccurrence.h"

namespace PYSNL {

using namespace naja::SNL;

#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(SNLOccurrence, function)

static int PySNLOccurrence_Init(PySNLOccurrence* self, PyObject* args, PyObject* kwargs) {
SNLOccurrence* snlOccurrence = nullptr;
PyObject* arg0 = nullptr;
PyObject* arg1 = nullptr;

//SNLOccurrence has three types of constructors:
if (not PyArg_ParseTuple(args, "|OO:SNLOccurrence", &arg0, &arg1)) {
setError("malformed SNLOccurrence create method");
return -1;
}
if (arg0 == nullptr) {
snlOccurrence = new SNLOccurrence();
} else if (arg1 == nullptr) {
if (IsPySNLDesignObject(arg0)) {
snlOccurrence = new SNLOccurrence(PYSNLDesignObject_O(arg0));
} else {
setError("SNLOccurrence create accepts SNLDesignObject as only argument");
return -1;
}
} else if (IsPySNLPath(arg0) and IsPySNLDesignObject(arg1)) {
snlOccurrence = new SNLOccurrence(*PYSNLPath_O(arg0), PYSNLDesignObject_O(arg1));
} else {
setError("invalid number of parameters for Occurrence constructor.");
return -1;
}
self->object_ = snlOccurrence;
return 0;
}

//LCOV_EXCL_START
ManagedTypeLinkCreateMethod(SNLOccurrence)
//LCOV_EXCL_STOP
ManagedTypeDeallocMethod(SNLOccurrence)

PyMethodDef PySNLOccurrence_Methods[] = {
{NULL, NULL, 0, NULL} /* sentinel */
};

PyTypeManagedSNLObjectWithoutSNLIDLinkPyType(SNLOccurrence)
PyTypeObjectDefinitions(SNLOccurrence)

} // namespace PYSNL
32 changes: 32 additions & 0 deletions src/snl/python/snl_wrapping/PySNLOccurrence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2024 The Naja authors <https://github.com/najaeda/naja/blob/main/AUTHORS>
//
// SPDX-License-Identifier: Apache-2.0

#ifndef __PY_SNL_OCCURRENCE_H_
#define __PY_SNL_OCCURRENCE_H_

#include <Python.h>

namespace naja::SNL {
class SNLOccurrence;
}

namespace PYSNL {

typedef struct {
PyObject_HEAD
naja::SNL::SNLOccurrence* object_;
} PySNLOccurrence;

extern PyTypeObject PyTypeSNLOccurrence;

extern PyObject* PySNLOccurrence_Link(naja::SNL::SNLOccurrence* occurrence);
extern void PySNLOccurrence_LinkPyType();

#define IsPySNLOccurrence(v) (PyObject_TypeCheck(v, &PyTypeSNLOccurrence))
#define PYSNLOccurrence(v) ((PySNLOccurrence*)(v))
#define PYSNLOccurrence_O(v) (PYSNLOccurrence(v)->object_)

} // PYSNL namespace

#endif // __PY_SNL_INSTANCE_H_
Loading

0 comments on commit 86b2a80

Please sign in to comment.