Skip to content

Commit

Permalink
doc: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziqi-Yang committed Aug 4, 2024
1 parent ba796f0 commit d497a40
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE_DIR:llvmpym_ext>
DEPENDS llvmpym_ext
Expand All @@ -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)
21 changes: 19 additions & 2 deletions docs/source/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.<module>` to `llvmpym.<module>`


NanoBind Pitfalls
-----------------

Expand Down
8 changes: 4 additions & 4 deletions example/el_psy_congaroo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/llvm/Core/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/llvmpym/support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .llvmpym_ext.support import *

0 comments on commit d497a40

Please sign in to comment.