-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #895 from Thomasb81/python_wrapper
Python wrapper
- Loading branch information
Showing
11 changed files
with
225 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Set up swig | ||
find_package(SWIG REQUIRED) | ||
include(${SWIG_USE_FILE}) | ||
|
||
# Include python | ||
find_package(PythonLibs REQUIRED) | ||
include_directories(${PYTHON_INCLUDE_PATH} ${GENDIR}/uhdm ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
|
||
set_source_files_properties(${PROJECT_NAME}.i | ||
PROPERTIES CPLUSPLUS ON | ||
INCLUDE_DIRECTORIES ${GENDIR}/uhdm | ||
GENERATED_INCLUDE_DIRECTORIES ${GENDIR}/uhdm | ||
DEPENDS uhdm | ||
) | ||
|
||
# Add swig module | ||
swig_add_library(py_uhdm | ||
TYPE MODULE | ||
LANGUAGE python | ||
SOURCES | ||
${PROJECT_NAME}.i swig_test.cpp | ||
) | ||
target_link_libraries(py_uhdm | ||
PRIVATE uhdm ${PYTHON_LIBRARIES} | ||
) | ||
set_target_properties(py_uhdm PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ | ||
) | ||
|
||
# this figures out where to install the Python modules | ||
execute_process( | ||
COMMAND ${Python3_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" | ||
OUTPUT_VARIABLE Python_site_packages | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
install( | ||
FILES ${CMAKE_CURRENT_BINARY_DIR}/uhdm.py | ||
DESTINATION ${CMAKE_INSTALL_PREFIX}/${Python_site_packages} | ||
) | ||
install( | ||
TARGETS ${SWIG_MODULE_py_udhm_REAL_NAME} | ||
LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES} | ||
) | ||
|
||
add_test( | ||
NAME python-tests-import | ||
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" "${Python3_EXECUTABLE}" -c "import uhdm" | ||
) | ||
|
||
add_test( | ||
NAME python-tests-unit-module | ||
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_module.py | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
%module uhdm | ||
/* | ||
Everithing in the %{ ... %} block is simply copied verbatim to the resulting wraper file created by swig. | ||
It is not parsed or interpreted by swig | ||
*/ | ||
%{ | ||
#include <stdarg.h> | ||
#include "vpi_user.h" | ||
#include "sv_vpi_user.h" | ||
#include "Serializer.h" | ||
|
||
#include "swig_test.h" | ||
|
||
%} | ||
%include "std_vector.i" | ||
%include "std_string.i" | ||
|
||
/* some api function using va_list are exclude using #ifndef SWIG/#endif */ | ||
%include "vpi_user.h" | ||
%include "sv_vpi_user.h" | ||
|
||
%include "Serializer.h" | ||
%include "uhdm_types.h" | ||
%include "swig_test.h" | ||
%include stl.i | ||
|
||
namespace std { | ||
%template(vpiHandleVector) vector<vpiHandle>; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "swig_test.h" | ||
#include "uhdm.h" | ||
using namespace UHDM; | ||
|
||
std::vector<vpiHandle> buildTestDesign(Serializer* s) { | ||
std::vector<vpiHandle> designs; | ||
|
||
design* d = s->MakeDesign(); | ||
vpiHandle dh = s->MakeUhdmHandle(uhdmdesign,d); | ||
designs.push_back(dh); | ||
|
||
VectorOfmodule_inst* vm = s->MakeModule_instVec(); | ||
d->AllModules(vm); | ||
|
||
module_inst* m1 = s->MakeModule_inst(); | ||
m1->VpiName("module1"); | ||
vm->push_back(m1); | ||
|
||
module_inst* m2 = s->MakeModule_inst(); | ||
m2->VpiName("module2"); | ||
vm->push_back(m2); | ||
|
||
return designs; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "Serializer.h" | ||
std::vector<vpiHandle> buildTestDesign(UHDM::Serializer* s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import unittest | ||
import uhdm | ||
|
||
|
||
class test_module(unittest.TestCase): | ||
|
||
def test_module(self): | ||
result = [] | ||
|
||
s = uhdm.Serializer() | ||
|
||
data = uhdm.buildTestDesign(s) | ||
modit = uhdm.vpi_iterate(uhdm.uhdmallModules,data[0]) | ||
while(True): | ||
vpiObj = uhdm.vpi_scan(modit) | ||
if vpiObj is None: | ||
break | ||
result.append(uhdm.vpi_get_str(uhdm.vpiName,vpiObj)) | ||
|
||
self.assertEqual(set(result),set(["module2","module1"])) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters