From d497a404f4bcc0c2b4e5f184208f739adec1619e Mon Sep 17 00:00:00 2001 From: Meow King Date: Sun, 4 Aug 2024 11:33:38 +0800 Subject: [PATCH] doc: update --- CMakeLists.txt | 3 ++- docs/source/development.rst | 21 +++++++++++++++++++-- example/el_psy_congaroo.py | 8 ++++---- justfile | 8 ++++++++ src/llvm/Core/value.cpp | 4 ++-- src/llvmpym/support.py | 1 + 6 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/llvmpym/support.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 49f0426..f97cbc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ nanobind_add_stub( nanobind_add_stub( llvmpym_ext_stub_support - MODULE llvmpym_ext.utils + MODULE llvmpym_ext.support OUTPUT support.pyi PYTHON_PATH $ DEPENDS llvmpym_ext @@ -156,6 +156,7 @@ install(FILES ${CMAKE_BINARY_DIR}/__init__.pyi ${CMAKE_BINARY_DIR}/core.pyi ${CMAKE_BINARY_DIR}/error_handling.pyi + ${CMAKE_BINARY_DIR}/support.pyi ${CMAKE_BINARY_DIR}/utils.pyi DESTINATION ${SKBUILD_PROJECT_NAME}/llvmpym_ext) diff --git a/docs/source/development.rst b/docs/source/development.rst index 80b37cd..2389bc8 100644 --- a/docs/source/development.rst +++ b/docs/source/development.rst @@ -27,14 +27,31 @@ for example: valgrind --leak-check=full python ./example/llvmir_builder.py -Check the generated stub file ------------------------------- +Check the correctness of generated stub file +-------------------------------------------- The generated stub file is possible to contain errors like you use a Python keyword as an parameter name of a function. Run ``cd ./docs && make html`` to check it, which is handled by *sphinx-autoapi*. + +Add a python sub-module +------------------------- + +Like `core`, `support` under `llvmpym` module. + +Steps: + +#. module definition file inside ``src/llvm`` directory +#. module registry in ``src/llvmpym_ext.cpp`` +#. add module definition file as an dependency of the final extension file in ``CMakeLists.txt`` + (``nanobind_add_module``) +#. ``CMakeLists.txt`` generate stub file (i.e. ``nanobind_add_stub`` and ``install``) +#. add a python file in ``src/llvmpym`` directory to remap module from + `llvmpym.llvmpym_ext.` to `llvmpym.` + + NanoBind Pitfalls ----------------- diff --git a/example/el_psy_congaroo.py b/example/el_psy_congaroo.py index 7c28f76..dd50299 100644 --- a/example/el_psy_congaroo.py +++ b/example/el_psy_congaroo.py @@ -4,7 +4,7 @@ import llvmpym.core as core c = core.Context.get_global_context() -# s = r'target triple = "unknown-unknown-unknown"' -# mem_buf = core.MemoryBuffer.from_str(s, "") -# res = c.parse_ir(mem_buf) -# print(res) +s = r'target triple = "unknown-unknown-unknown"' +mem_buf = core.MemoryBuffer.from_str(s, "") +res = c.parse_ir(mem_buf) +print(res) diff --git a/justfile b/justfile index ad8dedd..b2878b9 100644 --- a/justfile +++ b/justfile @@ -23,6 +23,14 @@ install-dev-requirements: build-docs: cd ./docs && make html +run-all-examples: + #!/usr/bin/env bash + set -euo pipefail + for file in ./example/*.py; do + python $file > /dev/null || echo $file failed + done + echo done! + opendoc: xdg-open ./docs/build/html/index.html diff --git a/src/llvm/Core/value.cpp b/src/llvm/Core/value.cpp index e310afe..0a667df 100644 --- a/src/llvm/Core/value.cpp +++ b/src/llvm/Core/value.cpp @@ -1598,11 +1598,11 @@ void bindValueClasses(nb::module_ &m) { }, "vector"_a, "index"_a) .def_static("insert_element", - [](PyConstantVector &vector, PyConstant &value, PyConstant &index) { + [](PyConstantVector &vector, PyConstant &index, PyConstant &value) { return PyValueAuto(LLVMConstInsertElement(vector.get(), value.get(), index.get())); }, - "vector"_a, "index"_a, "index"_a) + "vector"_a, "index"_a, "value"_a) .def_static("shuffle_vector", [](PyConstantVector &vectorA, PyConstantVector &vectorB, PyConstant &mask) { diff --git a/src/llvmpym/support.py b/src/llvmpym/support.py new file mode 100644 index 0000000..5552c48 --- /dev/null +++ b/src/llvmpym/support.py @@ -0,0 +1 @@ +from .llvmpym_ext.support import *