Skip to content

Commit

Permalink
refactor: rename class so that it can be built on python version less…
Browse files Browse the repository at this point in the history
… than 3.12 (no stable abi)
  • Loading branch information
Ziqi-Yang committed Aug 5, 2024
1 parent 7be19e0 commit 9d0d4b9
Show file tree
Hide file tree
Showing 49 changed files with 1,649 additions and 1,650 deletions.
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ nanobind_add_module(
src/llvm/Target.cpp
src/llvm/TargetMachine.cpp

src/llvm/types_priv/PyModule.cpp
src/llvm/types_priv/PyContext.cpp
src/llvm/types_priv/PyMetadataEntries.cpp
src/llvm/types_priv/PyModuleFlagEntries.cpp
src/llvm/types_priv/PyOperandBundle.cpp
src/llvm/types_priv/PyPassManagerBase.cpp
src/llvm/types_priv/PyMemoryBuffer.cpp
src/llvm/types_priv/PyModuleProvider.cpp
src/llvm/types_priv/PyTargetData.cpp
src/llvm/types_priv/PyTargetMachine.cpp
src/llvm/types_priv/PyTargetMachineOptions.cpp
src/llvm/types_priv/PymModule.cpp
src/llvm/types_priv/PymContext.cpp
src/llvm/types_priv/PymMetadataEntries.cpp
src/llvm/types_priv/PymModuleFlagEntries.cpp
src/llvm/types_priv/PymOperandBundle.cpp
src/llvm/types_priv/PymPassManagerBase.cpp
src/llvm/types_priv/PymMemoryBuffer.cpp
src/llvm/types_priv/PymModuleProvider.cpp
src/llvm/types_priv/PymTargetData.cpp
src/llvm/types_priv/PymTargetMachine.cpp
src/llvm/types_priv/PymTargetMachineOptions.cpp

${LLVM_INCLUDE_DIRS}
)
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[project]
name = "llvmpym"
version = "0.0.3"
version = "0.0.4"
description = "LLVM python binding"
readme = "README.md"
# can only be compiled for python >= 3.12
requires-python = ">=3.12"
requires-python = ">=3.8"
license = {file = "LICENSE"}
authors = [
{ name = "Meow King", email = "mr.meowking@anche.no" },
Expand All @@ -23,8 +23,7 @@ build-backend = "scikit_build_core.build"

[tool.scikit-build]
build-dir = "build/{wheel_tag}" # Setuptools-style build caching in a local directory
# since it can only be compiled for python >= 3.12, we here specify the version
# so that it will target ABI3
# Build stable ABI wheels for CPython 3.12+
wheel.py-api = "cp312"

[tool.cibuildwheel]
Expand Down
4 changes: 2 additions & 2 deletions src/llvm/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ void populateAnalysis(nb::module_ &m) {
"verifier will just return 1");

m.def("view_function_cfg",
[](PyFunction &f) {
[](PymFunction &f) {
return LLVMViewFunctionCFG(f.get());
},
"fn"_a,
"Open up a ghostview window that displays the CFG of the current function. "
"Useful for debugging.");

m.def("view_function_cfg_only",
[](PyFunction &f) {
[](PymFunction &f) {
return LLVMViewFunctionCFGOnly(f.get());
},
"fn"_a,
Expand Down
26 changes: 13 additions & 13 deletions src/llvm/Core/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ void bindEnums(nb::module_ &m) {
"However, duplicate entries in the second list are dropped during "
"the append operation.");

nb::enum_<PyAttributeIndex>(m, "AttributeIndex", "AttributeIndex")
.value("Return", PyAttributeIndex::Return)
.value("Function", PyAttributeIndex::Function);
nb::enum_<PymAttributeIndex>(m, "AttributeIndex", "AttributeIndex")
.value("Return", PymAttributeIndex::Return)
.value("Function", PymAttributeIndex::Function);

nb::enum_<LLVMTailCallKind>(m, "TailCallKind", "TailCallKind")
.value("LLVMTailCallKindNone", LLVMTailCallKind::LLVMTailCallKindNone)
Expand All @@ -387,16 +387,16 @@ void bindEnums(nb::module_ &m) {

// TODO LLVMAttributeIndex

nb::enum_<PyLLVMFastMathFlags>(m, "FastMathFlags", "FastMathFlags")
.value("AllowReassoc", PyLLVMFastMathFlags::AllowReassoc)
.value("NoNaNs", PyLLVMFastMathFlags::NoNaNs)
.value("NoInfs", PyLLVMFastMathFlags::NoInfs)
.value("NoSignedZeros", PyLLVMFastMathFlags::NoSignedZeros)
.value("AllowReciprocal", PyLLVMFastMathFlags::AllowReciprocal)
.value("AllowContract", PyLLVMFastMathFlags::AllowContract)
.value("ApproxFunc", PyLLVMFastMathFlags::ApproxFunc)
.value("None_", PyLLVMFastMathFlags::None)
.value("All", PyLLVMFastMathFlags::All);
nb::enum_<PymLLVMFastMathFlags>(m, "FastMathFlags", "FastMathFlags")
.value("AllowReassoc", PymLLVMFastMathFlags::AllowReassoc)
.value("NoNaNs", PymLLVMFastMathFlags::NoNaNs)
.value("NoInfs", PymLLVMFastMathFlags::NoInfs)
.value("NoSignedZeros", PymLLVMFastMathFlags::NoSignedZeros)
.value("AllowReciprocal", PymLLVMFastMathFlags::AllowReciprocal)
.value("AllowContract", PymLLVMFastMathFlags::AllowContract)
.value("ApproxFunc", PymLLVMFastMathFlags::ApproxFunc)
.value("None_", PymLLVMFastMathFlags::None)
.value("All", PymLLVMFastMathFlags::All);

// TODO LLVMFastMathFlags
}
2 changes: 1 addition & 1 deletion src/llvm/Core/globalFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void bindGlobalFunctions(nb::module_ &m) {
"The version components are returned via the function's three output "
"parameters or skipped if a NULL pointer was supplied.");

// NOTE these two functions seems useless in Python
// NOTE these two functions seems useless in Pymthon
// m.def("create_message", &LLVMCreateMessage, "message"_a);
// m.def("dispose_message", &LLVMDisposeMessage, "message"_a); // error, may need a wrapper for created message

Expand Down
18 changes: 9 additions & 9 deletions src/llvm/Core/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ using namespace nb::literals;


void bindIterators(nb::module_ &m) {
BIND_ITERATOR_CLASS(PyUseIterator, "UseIterator")
// BIND_ITERATOR_CLASS(PyBasicBlockIterator, "BasicBlockIterator")
// BIND_ITERATOR_CLASS(PyArgumentIterator, "ArgumentIterator")
BIND_ITERATOR_CLASS(PyInstructionIterator, "InstructionIterator")
BIND_ITERATOR_CLASS(PyGlobalVariableIterator, "GlobalVariableIterator")
BIND_ITERATOR_CLASS(PyGlobalIFuncIterator, "GlobalIFuncIterator")
BIND_ITERATOR_CLASS(PyGlobalAliasIterator, "GlobalAliasIterator")
BIND_ITERATOR_CLASS(PyNamedMDNodeIterator, "NamedMDNodeIterator")
BIND_ITERATOR_CLASS(PyFunctionIterator, "FunctionIterator")
BIND_ITERATOR_CLASS(PymUseIterator, "UseIterator")
// BIND_ITERATOR_CLASS(PymBasicBlockIterator, "BasicBlockIterator")
// BIND_ITERATOR_CLASS(PymArgumentIterator, "ArgumentIterator")
BIND_ITERATOR_CLASS(PymInstructionIterator, "InstructionIterator")
BIND_ITERATOR_CLASS(PymGlobalVariableIterator, "GlobalVariableIterator")
BIND_ITERATOR_CLASS(PymGlobalIFuncIterator, "GlobalIFuncIterator")
BIND_ITERATOR_CLASS(PymGlobalAliasIterator, "GlobalAliasIterator")
BIND_ITERATOR_CLASS(PymNamedMDNodeIterator, "NamedMDNodeIterator")
BIND_ITERATOR_CLASS(PymFunctionIterator, "FunctionIterator")
}


Loading

0 comments on commit 9d0d4b9

Please sign in to comment.